1 """Codec for quoted-printable encoding.
3 Like base64 and rot13, this returns Python strings, not Unicode.
8 from cStringIO
import StringIO
10 from StringIO
import StringIO
12 def quopri_encode(input, errors
='strict'):
13 """Encode the input, returning a tuple (output object, length consumed).
15 errors defines the error handling to apply. It defaults to
16 'strict' handling which is the only currently supported
17 error handling for this codec.
20 assert errors
== 'strict'
21 # using str() because of cStringIO's Unicode undesired Unicode behavior.
22 f
= StringIO(str(input))
24 quopri
.encode(f
, g
, 1)
26 return (output
, len(input))
28 def quopri_decode(input, errors
='strict'):
29 """Decode the input, returning a tuple (output object, length consumed).
31 errors defines the error handling to apply. It defaults to
32 'strict' handling which is the only currently supported
33 error handling for this codec.
36 assert errors
== 'strict'
37 f
= StringIO(str(input))
41 return (output
, len(input))
43 class Codec(codecs
.Codec
):
45 def encode(self
, input,errors
='strict'):
46 return quopri_encode(input,errors
)
47 def decode(self
, input,errors
='strict'):
48 return quopri_decode(input,errors
)
50 class IncrementalEncoder(codecs
.IncrementalEncoder
):
51 def encode(self
, input, final
=False):
52 return quopri_encode(input, self
.errors
)[0]
54 class IncrementalDecoder(codecs
.IncrementalDecoder
):
55 def decode(self
, input, final
=False):
56 return quopri_decode(input, self
.errors
)[0]
58 class StreamWriter(Codec
, codecs
.StreamWriter
):
61 class StreamReader(Codec
,codecs
.StreamReader
):
64 # encodings module API
67 return codecs
.CodecInfo(
71 incrementalencoder
=IncrementalEncoder
,
72 incrementaldecoder
=IncrementalDecoder
,
73 streamwriter
=StreamWriter
,
74 streamreader
=StreamReader
,