Null commit with -f option to force an uprev and put HEADs firmly on the trunk.
[python/dscho.git] / Lib / encodings / base64_codec.py
blobce21b1a4b298888114c8c0d4b2817018e287b382
1 """ Python 'base64_codec' Codec - base64 content transfer encoding
3 Unlike most of the other codecs which target Unicode, this codec
4 will return Python string objects for both encode and decode.
6 Written by Marc-Andre Lemburg (mal@lemburg.com).
8 """
9 import codecs, base64
11 ### Codec APIs
13 def base64_encode(input,errors='strict'):
15 """ Encodes the object input and returns a tuple (output
16 object, length consumed).
18 errors defines the error handling to apply. It defaults to
19 'strict' handling which is the only currently supported
20 error handling for this codec.
22 """
23 assert errors == 'strict'
24 output = base64.encodestring(input)
25 return (output, len(input))
27 def base64_decode(input,errors='strict'):
29 """ Decodes the object input and returns a tuple (output
30 object, length consumed).
32 input must be an object which provides the bf_getreadbuf
33 buffer slot. Python strings, buffer objects and memory
34 mapped files are examples of objects providing this slot.
36 errors defines the error handling to apply. It defaults to
37 'strict' handling which is the only currently supported
38 error handling for this codec.
40 """
41 assert errors == 'strict'
42 output = base64.decodestring(input)
43 return (output, len(input))
45 class Codec(codecs.Codec):
47 encode = base64_encode
48 decode = base64_decode
50 class StreamWriter(Codec,codecs.StreamWriter):
51 pass
53 class StreamReader(Codec,codecs.StreamReader):
54 pass
56 ### encodings module API
58 def getregentry():
60 return (base64_encode,base64_decode,StreamReader,StreamWriter)