Ejemplo n.º 1
0
def parse_header(header):
    """ Accepts a raw header with name, colons and newlines
    and returns it's parsed value
    """
    name, val = split2(header)
    if not is_pure_ascii(name):
        raise DecodingError("Non-ascii header name")
    return name, parse_header_value(name, encodedword.unfold(val))
Ejemplo n.º 2
0
def parse_header(header):
    """ Accepts a raw header with name, colons and newlines
    and returns it's parsed value
    """
    name, val = split2(header)
    if not is_pure_ascii(name):
        raise DecodingError("Non-ascii header name")
    return name, parse_header_value(name, encodedword.unfold(val))
Ejemplo n.º 3
0
def decode(header):
    """Accepts parameterized header value (encoded in accordance to
     rfc2231 (new style) or rfc1342 (old style)
     and returns tuple:
         value, {'key': u'val'}
     returns None in case of any failure
    """
    value, rest = split(encodedword.unfold(header))
    if value is None:
        return None, {}
    elif value:
        return value, decode_parameters(rest)
Ejemplo n.º 4
0
def decode(header):
    """Accepts parameterized header value (encoded in accordance to
     rfc2231 (new style) or rfc1342 (old style)
     and returns tuple:
         value, {'key': u'val'}
     returns None in case of any failure
    """
    value, rest = split(encodedword.unfold(header))
    if value is None:
        return None, {}
    elif value:
        return value, decode_parameters(rest)
Ejemplo n.º 5
0
def decode(header):
    """Accepts parameterized header value (encoded in accordance to
     rfc2231 (new style) or rfc1342 (old style)
     and returns tuple:
         value, {'key': u'val'}
     returns None in case of any failure
    """
    if six.PY3 and isinstance(header, six.binary_type):
        header = header.decode('utf-8')

    value, rest = split(encodedword.unfold(header))
    if value is None:
        return None, {}

    return value, decode_parameters(rest)