def convert_to_unicode(charset, value): #in case of unicode we have nothing to do if isinstance(value, unicode): return value charset = _translate_charset(charset) return to_unicode(value, charset=charset)
def convert_to_unicode(charset, value): if isinstance(value, six.text_type): return value charset = _ensure_charset(charset) value = to_unicode(value, charset) return value
def convert_to_unicode(charset, value): if isinstance(value, six.text_type): if six.PY2: return value value = value.encode('ascii') charset = _ensure_charset(charset) value = to_unicode(value, charset) return value
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 scan(string): """Scanner that uses 1 pass to scan the entire message and build a message tree""" if six.PY2: if not isinstance(string, six.binary_type): raise DecodingError('Scanner works with binary only') else: if isinstance(string, six.binary_type): string = to_unicode(string) if not isinstance(string, six.text_type): raise DecodingError('Cannot scan type %s' % type(string)) tokens = tokenize(string) if not tokens: tokens = [default_content_type()] try: return traverse(Start(), TokensIterator(tokens, string)) except DecodingError: raise except Exception as cause: raise six.raise_from(DecodingError("Malformed MIME message"), cause)