]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/Lib/encodings/base64_codec.py
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 4/5.
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / encodings / base64_codec.py
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Lib/encodings/base64_codec.py b/AppPkg/Applications/Python/Python-2.7.10/Lib/encodings/base64_codec.py
new file mode 100644 (file)
index 0000000..2092637
--- /dev/null
@@ -0,0 +1,79 @@
+""" Python 'base64_codec' Codec - base64 content transfer encoding\r
+\r
+    Unlike most of the other codecs which target Unicode, this codec\r
+    will return Python string objects for both encode and decode.\r
+\r
+    Written by Marc-Andre Lemburg (mal@lemburg.com).\r
+\r
+"""\r
+import codecs, base64\r
+\r
+### Codec APIs\r
+\r
+def base64_encode(input,errors='strict'):\r
+\r
+    """ Encodes the object input and returns a tuple (output\r
+        object, length consumed).\r
+\r
+        errors defines the error handling to apply. It defaults to\r
+        'strict' handling which is the only currently supported\r
+        error handling for this codec.\r
+\r
+    """\r
+    assert errors == 'strict'\r
+    output = base64.encodestring(input)\r
+    return (output, len(input))\r
+\r
+def base64_decode(input,errors='strict'):\r
+\r
+    """ Decodes the object input and returns a tuple (output\r
+        object, length consumed).\r
+\r
+        input must be an object which provides the bf_getreadbuf\r
+        buffer slot. Python strings, buffer objects and memory\r
+        mapped files are examples of objects providing this slot.\r
+\r
+        errors defines the error handling to apply. It defaults to\r
+        'strict' handling which is the only currently supported\r
+        error handling for this codec.\r
+\r
+    """\r
+    assert errors == 'strict'\r
+    output = base64.decodestring(input)\r
+    return (output, len(input))\r
+\r
+class Codec(codecs.Codec):\r
+\r
+    def encode(self, input,errors='strict'):\r
+        return base64_encode(input,errors)\r
+    def decode(self, input,errors='strict'):\r
+        return base64_decode(input,errors)\r
+\r
+class IncrementalEncoder(codecs.IncrementalEncoder):\r
+    def encode(self, input, final=False):\r
+        assert self.errors == 'strict'\r
+        return base64.encodestring(input)\r
+\r
+class IncrementalDecoder(codecs.IncrementalDecoder):\r
+    def decode(self, input, final=False):\r
+        assert self.errors == 'strict'\r
+        return base64.decodestring(input)\r
+\r
+class StreamWriter(Codec,codecs.StreamWriter):\r
+    pass\r
+\r
+class StreamReader(Codec,codecs.StreamReader):\r
+    pass\r
+\r
+### encodings module API\r
+\r
+def getregentry():\r
+    return codecs.CodecInfo(\r
+        name='base64',\r
+        encode=base64_encode,\r
+        decode=base64_decode,\r
+        incrementalencoder=IncrementalEncoder,\r
+        incrementaldecoder=IncrementalDecoder,\r
+        streamwriter=StreamWriter,\r
+        streamreader=StreamReader,\r
+    )\r