2001-09-20 14:56:14 +02:00
|
|
|
""" Python 'utf-7' Codec
|
|
|
|
|
|
|
|
Written by Brian Quinlan (brian@sweetapp.com).
|
|
|
|
"""
|
|
|
|
import codecs
|
|
|
|
|
|
|
|
### Codec APIs
|
|
|
|
|
2007-11-21 00:38:09 +01:00
|
|
|
encode = codecs.utf_7_encode
|
2001-09-20 14:56:14 +02:00
|
|
|
|
2007-11-21 00:38:09 +01:00
|
|
|
def decode(input, errors='strict'):
|
|
|
|
return codecs.utf_7_decode(input, errors, True)
|
2001-09-20 14:56:14 +02:00
|
|
|
|
2006-04-21 11:43:23 +02:00
|
|
|
class IncrementalEncoder(codecs.IncrementalEncoder):
|
|
|
|
def encode(self, input, final=False):
|
|
|
|
return codecs.utf_7_encode(input, self.errors)[0]
|
|
|
|
|
|
|
|
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
2007-11-21 00:38:09 +01:00
|
|
|
_buffer_decode = codecs.utf_7_decode
|
2006-04-21 11:43:23 +02:00
|
|
|
|
2007-11-21 00:38:09 +01:00
|
|
|
class StreamWriter(codecs.StreamWriter):
|
|
|
|
encode = codecs.utf_7_encode
|
2002-08-08 22:19:19 +02:00
|
|
|
|
2007-11-21 00:38:09 +01:00
|
|
|
class StreamReader(codecs.StreamReader):
|
|
|
|
decode = codecs.utf_7_decode
|
2001-09-20 14:56:14 +02:00
|
|
|
|
|
|
|
### encodings module API
|
|
|
|
|
|
|
|
def getregentry():
|
2006-04-21 11:43:23 +02:00
|
|
|
return codecs.CodecInfo(
|
|
|
|
name='utf-7',
|
2007-11-21 00:38:09 +01:00
|
|
|
encode=encode,
|
|
|
|
decode=decode,
|
2006-04-21 11:43:23 +02:00
|
|
|
incrementalencoder=IncrementalEncoder,
|
|
|
|
incrementaldecoder=IncrementalDecoder,
|
|
|
|
streamreader=StreamReader,
|
|
|
|
streamwriter=StreamWriter,
|
|
|
|
)
|