[Python-checkins] python/dist/src/Lib/email Utils.py,1.17,1.18

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Tue, 10 Sep 2002 19:22:51 -0700


Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv20461

Modified Files:
	Utils.py 
Log Message:
rfc822.unquote() doesn't properly de-backslash-ify in Python prior to
2.3.  This patch (adapted from Quinn Dunkan's SF patch #573204) fixes
the problem and should get ported to rfc822.py.


Index: Utils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Utils.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** Utils.py	29 Jun 2002 05:58:04 -0000	1.17
--- Utils.py	11 Sep 2002 02:22:48 -0000	1.18
***************
*** 14,18 ****
  from types import ListType
  
! from rfc822 import unquote, quote
  from rfc822 import AddressList as _AddressList
  from rfc822 import mktime_tz
--- 14,18 ----
  from types import ListType
  
! from rfc822 import quote
  from rfc822 import AddressList as _AddressList
  from rfc822 import mktime_tz
***************
*** 259,262 ****
--- 259,273 ----
          return '', ''
      return addrs[0]
+ 
+ 
+ # rfc822.unquote() doesn't properly de-backslash-ify in Python pre-2.3.
+ def unquote(str):
+     """Remove quotes from a string."""
+     if len(str) > 1:
+         if str.startswith('"') and str.endswith('"'):
+             return str[1:-1].replace('\\\\', '\\').replace('\\"', '"')
+         if str.startswith('<') and str.endswith('>'):
+             return str[1:-1]
+     return str