Home | History | Annotate | Download | only in encodings
      1 # -*- coding: iso-8859-1 -*-
      2 """ Python 'escape' Codec
      3 
      4 
      5 Written by Martin v. Lwis (martin (at] v.loewis.de).
      6 
      7 """
      8 import codecs
      9 
     10 class Codec(codecs.Codec):
     11 
     12     encode = codecs.escape_encode
     13     decode = codecs.escape_decode
     14 
     15 class IncrementalEncoder(codecs.IncrementalEncoder):
     16     def encode(self, input, final=False):
     17         return codecs.escape_encode(input, self.errors)[0]
     18 
     19 class IncrementalDecoder(codecs.IncrementalDecoder):
     20     def decode(self, input, final=False):
     21         return codecs.escape_decode(input, self.errors)[0]
     22 
     23 class StreamWriter(Codec,codecs.StreamWriter):
     24     pass
     25 
     26 class StreamReader(Codec,codecs.StreamReader):
     27     pass
     28 
     29 def getregentry():
     30     return codecs.CodecInfo(
     31         name='string-escape',
     32         encode=Codec.encode,
     33         decode=Codec.decode,
     34         incrementalencoder=IncrementalEncoder,
     35         incrementaldecoder=IncrementalDecoder,
     36         streamwriter=StreamWriter,
     37         streamreader=StreamReader,
     38     )
     39