[pypy-svn] r10054 - in pypy/dist/pypy: lib module/sys2
jacob at codespeak.net
jacob at codespeak.net
Tue Mar 22 03:38:21 CET 2005
Author: jacob
Date: Tue Mar 22 03:38:20 2005
New Revision: 10054
Modified:
pypy/dist/pypy/lib/binascii.py
pypy/dist/pypy/module/sys2/state.py
Log:
Work on quoted printable.
Modified: pypy/dist/pypy/lib/binascii.py
==============================================================================
--- pypy/dist/pypy/lib/binascii.py (original)
+++ pypy/dist/pypy/lib/binascii.py Tue Mar 22 03:38:20 2005
@@ -196,9 +196,34 @@
-#print b2a_uu('1234567')
-#print b2a_uu('123456789012345678901234567890123456789012345')
-#print b2a_uu('1234567890123456789012345678901234567890123456')
-#print '"%s"' % a2b_uu(b2a_uu('1234567'))
-#print '"%s"' % a2b_uu(b2a_uu('123456789012345678901234567890123456789012345'))
+def a2b_qp(s):
+ pass
+def b2a_qp(s):
+ def f(c):
+ if '!' <= c <= '<' or '>' <= c <= '~':
+ return c
+ return '=' + str(hex(ord(c)))
+ return ''.join([ f(c) for c in s])
+
+hex_numbers = '0123456789ABCDEF'
+def hex(n):
+ if n == 0:
+ return '0'
+
+ if n < 0:
+ n = -n
+ sign = '-'
+ else:
+ sign = ''
+ arr = []
+ for nibble in hexgen(n):
+ arr = [hex_numbers[nibble]] + arr
+ return sign + ''.join(arr)
+
+def hexgen(n):
+ """ Yield a nibble at a time. """
+ while n:
+ remainder = n % 0x10
+ n = n / 0x10
+ yield remainder
Modified: pypy/dist/pypy/module/sys2/state.py
==============================================================================
--- pypy/dist/pypy/module/sys2/state.py (original)
+++ pypy/dist/pypy/module/sys2/state.py Tue Mar 22 03:38:20 2005
@@ -27,7 +27,7 @@
for fn in ['posix', 'nt', 'os2', 'mac', 'ce', 'riscos',
'math', '_codecs', 'array', 'select',
'_random', '_sre', 'time', '_socket', 'errno',
- 'binascii', 'parser']:
+ 'parser']:
if fn not in builtin_modules:
try:
builtin_modules[fn] = hack_cpython_module(fn)
More information about the Pypy-commit
mailing list