Kaydet (Commit) bfcbfa7c authored tarafından Skip Montanaro's avatar Skip Montanaro

move imports in Binary class to top level to avoid repeated imports.

use cStringIO if available.
üst fa012610
...@@ -386,6 +386,12 @@ def _datetime(data): ...@@ -386,6 +386,12 @@ def _datetime(data):
# #
# @param data An 8-bit string containing arbitrary data. # @param data An 8-bit string containing arbitrary data.
import base64
try:
import cStringIO as StringIO
except ImportError:
import StringIO
class Binary: class Binary:
"""Wrapper for binary data.""" """Wrapper for binary data."""
...@@ -406,11 +412,9 @@ class Binary: ...@@ -406,11 +412,9 @@ class Binary:
return cmp(self.data, other) return cmp(self.data, other)
def decode(self, data): def decode(self, data):
import base64
self.data = base64.decodestring(data) self.data = base64.decodestring(data)
def encode(self, out): def encode(self, out):
import base64, StringIO
out.write("<value><base64>\n") out.write("<value><base64>\n")
base64.encode(StringIO.StringIO(self.data), out) base64.encode(StringIO.StringIO(self.data), out)
out.write("</base64></value>\n") out.write("</base64></value>\n")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment