PyXR

c:\python24\lib \ encodings \ hex_codec.py



0001 """ Python 'hex_codec' Codec - 2-digit hex content transfer encoding
0002 
0003     Unlike most of the other codecs which target Unicode, this codec
0004     will return Python string objects for both encode and decode.
0005 
0006     Written by Marc-Andre Lemburg (mal@lemburg.com).
0007 
0008 """
0009 import codecs, binascii
0010 
0011 ### Codec APIs
0012 
0013 def hex_encode(input,errors='strict'):
0014 
0015     """ Encodes the object input and returns a tuple (output
0016         object, length consumed).
0017 
0018         errors defines the error handling to apply. It defaults to
0019         'strict' handling which is the only currently supported
0020         error handling for this codec.
0021 
0022     """
0023     assert errors == 'strict'
0024     output = binascii.b2a_hex(input)
0025     return (output, len(input))
0026 
0027 def hex_decode(input,errors='strict'):
0028 
0029     """ Decodes the object input and returns a tuple (output
0030         object, length consumed).
0031 
0032         input must be an object which provides the bf_getreadbuf
0033         buffer slot. Python strings, buffer objects and memory
0034         mapped files are examples of objects providing this slot.
0035 
0036         errors defines the error handling to apply. It defaults to
0037         'strict' handling which is the only currently supported
0038         error handling for this codec.
0039 
0040     """
0041     assert errors == 'strict'
0042     output = binascii.a2b_hex(input)
0043     return (output, len(input))
0044 
0045 class Codec(codecs.Codec):
0046 
0047     def encode(self, input,errors='strict'):
0048         return hex_encode(input,errors)
0049     def decode(self, input,errors='strict'):
0050         return hex_decode(input,errors)
0051 
0052 class StreamWriter(Codec,codecs.StreamWriter):
0053     pass
0054 
0055 class StreamReader(Codec,codecs.StreamReader):
0056     pass
0057 
0058 ### encodings module API
0059 
0060 def getregentry():
0061 
0062     return (hex_encode,hex_decode,StreamReader,StreamWriter)
0063 

Generated by PyXR 0.9.4
SourceForge.net Logo