Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfcbfa7

Browse files
author
Skip Montanaro
committed
move imports in Binary class to top level to avoid repeated imports.
use cStringIO if available.
1 parent fa01261 commit bfcbfa7

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/xmlrpclib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ def _datetime(data):
386386
#
387387
# @param data An 8-bit string containing arbitrary data.
388388

389+
import base64
390+
try:
391+
import cStringIO as StringIO
392+
except ImportError:
393+
import StringIO
394+
389395
class Binary:
390396
"""Wrapper for binary data."""
391397

@@ -406,11 +412,9 @@ def __cmp__(self, other):
406412
return cmp(self.data, other)
407413

408414
def decode(self, data):
409-
import base64
410415
self.data = base64.decodestring(data)
411416

412417
def encode(self, out):
413-
import base64, StringIO
414418
out.write("<value><base64>\n")
415419
base64.encode(StringIO.StringIO(self.data), out)
416420
out.write("</base64></value>\n")

0 commit comments

Comments
 (0)