Example #1
0
def parse_header_value(name, val):
    if parametrized.is_parametrized(name, val):
        val, params = parametrized.decode(val)
        if name == 'Content-Type':
            main, sub = parametrized.fix_content_type(val)
            return ContentType(main, sub, params)
        else:
            return WithParams(val, params)
    else:
        return val if is_pure_ascii(val) else to_unicode(val)
Example #2
0
def parse_header_value(name, val):
    if not is_pure_ascii(val):
        val = to_unicode(val)
    if parametrized.is_parametrized(name, val):
        val, params = parametrized.decode(val)
        if val is not None and not is_pure_ascii(val):
            raise DecodingError('Non-ascii content header value')
        if name == 'Content-Type':
            main, sub = parametrized.fix_content_type(val)
            return ContentType(main, sub, params)

        return WithParams(val, params)

    return val
Example #3
0
def parse_header_value(name, val):
    if not is_pure_ascii(val):
        if parametrized.is_parametrized(name, val):
            raise DecodingError("Unsupported value in content- header")
        return to_unicode(val)
    else:
        if parametrized.is_parametrized(name, val):
            val, params = parametrized.decode(val)
            if name == 'Content-Type':
                main, sub = parametrized.fix_content_type(val)
                return ContentType(main, sub, params)
            else:
                return WithParams(val, params)
        else:
            return val
Example #4
0
def charset_test():
    c = ContentType('text', 'plain')
    eq_('ascii', c.get_charset())

    c = ContentType('application', 'pdf')
    eq_(None, c.get_charset())
Example #5
0
def charset_test():
    c = ContentType('text', 'plain')
    eq_('ascii', c.get_charset())

    c = ContentType('application', 'pdf')
    eq_(None, c.get_charset())