diff options
Diffstat (limited to 'Lib/encodings/rot_13.py')
-rwxr-xr-x[-rw-r--r--] | Lib/encodings/rot_13.py | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/Lib/encodings/rot_13.py b/Lib/encodings/rot_13.py index 52b6431cf30..3140c1432dc 100644..100755 --- a/Lib/encodings/rot_13.py +++ b/Lib/encodings/rot_13.py @@ -1,31 +1,30 @@ #!/usr/bin/env python """ Python Character Mapping Codec for ROT13. - See http://ucsub.colorado.edu/~kominek/rot13/ for details. +This codec de/encodes from str to str and is therefore usable with +str.transform() and str.untransform(). - Written by Marc-Andre Lemburg (mal@lemburg.com). - -"""#" +Written by Marc-Andre Lemburg (mal@lemburg.com). +""" import codecs ### Codec APIs class Codec(codecs.Codec): + def encode(self, input, errors='strict'): + return (input.translate(rot13_map), len(input)) - def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) - - def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_map) + def decode(self, input, errors='strict'): + return (input.translate(rot13_map), len(input)) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return input.translate(rot13_map) class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): - return codecs.charmap_decode(input,self.errors,decoding_map)[0] + return input.translate(rot13_map) class StreamWriter(Codec,codecs.StreamWriter): pass @@ -46,10 +45,10 @@ def getregentry(): streamreader=StreamReader, ) -### Decoding Map +### Map -decoding_map = codecs.make_identity_dict(range(256)) -decoding_map.update({ +rot13_map = codecs.make_identity_dict(range(256)) +rot13_map.update({ 0x0041: 0x004e, 0x0042: 0x004f, 0x0043: 0x0050, @@ -104,10 +103,6 @@ decoding_map.update({ 0x007a: 0x006d, }) -### Encoding Map - -encoding_map = codecs.make_encoding_map(decoding_map) - ### Filter API def rot13(infile, outfile): |