[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[minion-cvs] Fix a base64 bug on python2.0
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv5000/lib/mixminion
Modified Files:
Common.py
Log Message:
Fix a base64 bug on python2.0
Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- Common.py 17 Feb 2003 16:14:36 -0000 1.64
+++ Common.py 20 Feb 2003 01:54:44 -0000 1.65
@@ -14,6 +14,7 @@
'previousMidnight', 'readPossiblyGzippedFile', 'secureDelete',
'stringContains', 'succeedingMidnight', 'waitForChildren' ]
+import base64
import binascii
import bisect
import calendar
@@ -120,11 +121,17 @@
"""Remove all whitespace from s."""
return s.translate(_ALLCHARS, space)
-def formatBase64(s):
- """Convert 's' to a one-line base-64 representation."""
- return binascii.b2a_base64(s).strip()
-
-def encodeBase64(s, lineWidth=64):
+if sys.version_info[0:3] >= (2,1,0):
+ def formatBase64(s):
+ """Convert 's' to a one-line base-64 representation."""
+ return binascii.b2a_base64(s).strip()
+else:
+ # Python 2.0 didin't allow a binascii to return more than one line.
+ def formatBase64(s):
+ """Convert 's' to a one-line base-64 representation."""
+ return encodeBase64(s, 64, 1)
+
+def encodeBase64(s, lineWidth=64, oneline=0):
"""Convert 's' to a multiline base-64 representation. Improves upon
base64.encodestring by having a variable line width. Implementation
is based upon that function.
@@ -135,7 +142,10 @@
for i in xrange(0, len(s), bytesPerLine):
chunk = s[i:i+bytesPerLine]
pieces.append(binascii.b2a_base64(chunk))
- return "".join(pieces)
+ if oneline:
+ return "".join([ s.strip() for s in pieces ])
+ else:
+ return "".join(pieces)
#----------------------------------------------------------------------
def createPrivateDir(d, nocreate=0):