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)
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
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
def charset_test(): c = ContentType('text', 'plain') eq_('ascii', c.get_charset()) c = ContentType('application', 'pdf') eq_(None, c.get_charset())