3838hqre = re .compile (r'[^-a-zA-Z0-9!*+/ ]' )
3939bqre = re .compile (r'[^ !-<>-~\t]' )
4040
41+ try :
42+ True , False
43+ except NameError :
44+ True = 1
45+ False = 0
46+
4147
4248
4349# Helpers
4450def header_quopri_check (c ):
45- """Return true if the character should be escaped with header quopri."""
46- return hqre .match (c ) and 1
51+ """Return True if the character should be escaped with header quopri."""
52+ return hqre .match (c ) and True
4753
4854
4955def body_quopri_check (c ):
50- """Return true if the character should be escaped with body quopri."""
51- return bqre .match (c ) and 1
56+ """Return True if the character should be escaped with body quopri."""
57+ return bqre .match (c ) and True
5258
5359
5460def header_quopri_len (s ):
@@ -92,8 +98,8 @@ def quote(c):
9298
9399
94100
95- def header_encode (header , charset = "iso-8859-1" , keep_eols = 0 , maxlinelen = 76 ,
96- eol = NL ):
101+ def header_encode (header , charset = "iso-8859-1" , keep_eols = False ,
102+ maxlinelen = 76 , eol = NL ):
97103 """Encode a single header line with quoted-printable (like) encoding.
98104
99105 Defined in RFC 2045, this `Q' encoding is similar to quoted-printable, but
@@ -114,7 +120,7 @@ def header_encode(header, charset="iso-8859-1", keep_eols=0, maxlinelen=76,
114120
115121 End-of-line characters (\\ r, \\ n, \\ r\\ n) will be automatically converted
116122 to the canonical email line separator \\ r\\ n unless the keep_eols
117- parameter is set to true (the default is false ).
123+ parameter is True (the default is False ).
118124
119125 Each line of the header will be terminated in the value of eol, which
120126 defaults to "\\ n". Set this to "\\ r\\ n" if you are using the result of
@@ -151,10 +157,10 @@ def header_encode(header, charset="iso-8859-1", keep_eols=0, maxlinelen=76,
151157
152158
153159
154- def encode (body , binary = 0 , maxlinelen = 76 , eol = NL ):
160+ def encode (body , binary = False , maxlinelen = 76 , eol = NL ):
155161 """Encode with quoted-printable, wrapping at maxlinelen characters.
156162
157- If binary is false (the default), end-of-line characters will be converted
163+ If binary is False (the default), end-of-line characters will be converted
158164 to the canonical email end-of-line sequence \\ r\\ n. Otherwise they will
159165 be left verbatim.
160166
@@ -213,7 +219,7 @@ def encode(body, binary=0, maxlinelen=76, eol=NL):
213219 # Now at end of line..
214220 if prev and prev in ' \t ' :
215221 # Special case for whitespace at end of file
216- if lineno + 1 == len (lines ):
222+ if lineno + 1 == len (lines ):
217223 prev = quote (prev )
218224 if len (encoded_line ) + len (prev ) > maxlinelen :
219225 encoded_body += encoded_line + '=' + eol + prev
@@ -283,7 +289,7 @@ def decode(encoded, eol=NL):
283289 if i == n :
284290 decoded += eol
285291 # Special case if original string did not end with eol
286- if encoded [ - 1 ] <> eol and decoded [ - 1 ] == eol :
292+ if not encoded . endswith ( eol ) and decoded . endswith ( eol ) :
287293 decoded = decoded [:- 1 ]
288294 return decoded
289295
0 commit comments