Lines Matching refs:charset

20 from email import charset as _charset
34 # Match encoded-word strings in the form =?charset?q?Hello_World?=
37 (?P<charset>[^?]*?) # non-greedy up to the next ? is the charset
64 """Decode a message header value without converting charset.
66 Returns a list of (string, charset) pairs containing each of the decoded
79 return [(_charset._encode(string, str(charset)), str(charset))
80 for string, charset in header._chunks]
81 # If no encoding, just return the header with no charset.
85 # (encoded_string, encoding, charset). For unencoded strings, the last
99 charset = parts.pop(0).lower()
102 words.append((encoded, encoding, charset))
114 # form (decoded_word, charset).
116 for encoded_string, encoding, charset in words:
119 decoded_words.append((encoded_string, charset))
122 decoded_words.append((word, charset))
132 decoded_words.append((word, charset))
139 for word, charset in decoded_words:
144 last_charset = charset
145 elif charset != last_charset:
148 last_charset = charset
164 pairs of the format (decoded_string, charset) where charset is the string
173 for s, charset in decoded_seq:
175 if charset is not None and not isinstance(charset, Charset):
176 charset = Charset(charset)
177 h.append(s, charset)
184 def __init__(self, s=None, charset=None,
194 Optional charset serves two purposes: it has the same meaning as the
195 charset argument to the .append() method. It also sets the default
196 character set for all subsequent .append() calls that omit the charset
197 argument. If charset is not provided in the constructor, the us-ascii
198 charset is used both as s's initial charset and as the default for
213 if charset is None:
214 charset = USASCII
215 elif not isinstance(charset, Charset):
216 charset = Charset(charset)
217 self._charset = charset
221 self.append(s, charset, errors)
237 for string, charset in self._chunks:
240 # from a charset to None/us-ascii, or from None/us-ascii to a
241 # charset. Only do this for the second and subsequent chunks.
244 nextcs = charset
269 def append(self, s, charset=None, errors='strict'):
272 Optional charset, if given, should be a Charset instance or the name
274 value of None (the default) means that the charset given in the
278 (i.e. isinstance(s, str) is false), then charset is the encoding of
280 cannot be decoded with that charset. If s is a Unicode string, then
281 charset is a hint specifying the character set of the characters in
284 output codec of the charset. If the string cannot be encoded to the
290 if charset is None:
291 charset = self._charset
292 elif not isinstance(charset, Charset):
293 charset = Charset(charset)
295 input_charset = charset.input_codec or 'us-ascii'
302 output_charset = charset.output_codec or 'us-ascii'
309 charset = UTF8
310 self._chunks.append((s, charset))
362 for string, charset in self._chunks:
366 if not hasspace or charset not in (None, 'us-ascii'):
368 elif charset not in (None, 'us-ascii') and not lastspace:
371 lastcs = charset
375 formatter.feed('', lines[0], charset)
377 formatter.feed('', '', charset)
380 if charset.header_encoding is not None:
382 charset)
386 formatter.feed(fws, sline, charset)
403 for string, charset in self._chunks:
404 if charset == last_charset:
410 last_charset = charset
448 def feed(self, fws, string, charset):
449 # If the charset has no header encoding (i.e. it is an ASCII encoding)
454 if charset.header_encoding is None:
464 encoded_lines = charset.header_encode_lines(string, self._maxlengths())