Пример #1
0
        def parsestr(self, text, headersonly=False):
            if isinstance(text, unicode):
                # difference with vanilla is we encode using utf-8, not ascii
                ret = self.parse(StringIO(utf8only_encode(text)),
                                 headersonly=headersonly)
            else:
                ret = _Parser.parsestr(self, text, headersonly)

            # homogeneous return type with py3
            ret._headers = [(utf8only_decode(i), utf8only_decode(j))
                            for i, j in ret._headers]

            return ret
Пример #2
0
    def parse(self, data):
        """Parses the given string to populate the :attr:`headers` and
        :attr:`message` attributes.

        :param data: The complete message, headers and message body.
        :type data: :py:obj:`bytes`

        """
        check_argtype(data, bytes, 'data')

        match = re.search(_HEADER_BOUNDARY, data)
        if not match:
            header_data = data
            payload = b''
        else:
            header_data = data[:match.end(0)]
            payload = data[match.end(0):]

        header_data_decoded = utf8only_decode(header_data)
        self.headers = Parser().parsestr(header_data_decoded, True)
        self.message = self.headers.get_payload().encode('ascii') + payload
        self.headers.set_payload('')
Пример #3
0
    def parse(self, data):
        """Parses the given string to populate the :attr:`headers` and
        :attr:`message` attributes.

        :param data: The complete message, headers and message body.
        :type data: :py:obj:`bytes`

        """
        check_argtype(data, bytes, 'data')

        match = re.search(_HEADER_BOUNDARY, data)
        if not match:
            header_data = data
            payload = b''
        else:
            header_data = data[:match.end(0)]
            payload = data[match.end(0):]

        header_data_decoded = utf8only_decode(header_data)
        self.headers = Parser().parsestr(header_data_decoded, True)
        self.message = self.headers.get_payload().encode('ascii') + payload
        self.headers.set_payload('')