diff options
Diffstat (limited to 'Lib/email/Encoders.py')
-rw-r--r-- | Lib/email/Encoders.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/Lib/email/Encoders.py b/Lib/email/Encoders.py index f09affa..c369a24 100644 --- a/Lib/email/Encoders.py +++ b/Lib/email/Encoders.py @@ -5,15 +5,34 @@ """ import base64 -from quopri import encodestring as _encodestring # Helpers -def _qencode(s): - enc = _encodestring(s, quotetabs=1) - # Must encode spaces, which quopri.encodestring() doesn't do - return enc.replace(' ', '=20') +try: + from quopri import encodestring as _encodestring + + def _qencode(s): + enc = _encodestring(s, quotetabs=1) + # Must encode spaces, which quopri.encodestring() doesn't do + return enc.replace(' ', '=20') +except ImportError: + # Python 2.1 doesn't have quopri.encodestring() + from cStringIO import StringIO + import quopri as _quopri + + def _qencode(s): + if not s: + return s + hasnewline = (s[-1] == '\n') + infp = StringIO(s) + outfp = StringIO() + _quopri.encode(infp, outfp, quotetabs=1) + # Python 2.x's encode() doesn't encode spaces even when quotetabs==1 + value = outfp.getvalue().replace(' ', '=20') + if not hasnewline and value[-1] == '\n': + return value[:-1] + return value def _bencode(s): |