##// END OF EJS Templates
py3: use email parser that operates on bytes...
Gregory Szorc -
r36062:04984f2e default
parent child Browse files
Show More
@@ -12,7 +12,6 b' import collections'
12 import copy
12 import copy
13 import difflib
13 import difflib
14 import email
14 import email
15 import email.parser as emailparser
16 import errno
15 import errno
17 import hashlib
16 import hashlib
18 import os
17 import os
@@ -109,7 +108,7 b' def split(stream):'
109 cur.append(line)
108 cur.append(line)
110 c = chunk(cur)
109 c = chunk(cur)
111
110
112 m = emailparser.Parser().parse(c)
111 m = pycompat.emailparser().parse(c)
113 if not m.is_multipart():
112 if not m.is_multipart():
114 yield msgfp(m)
113 yield msgfp(m)
115 else:
114 else:
@@ -218,7 +217,7 b' def extract(ui, fileobj):'
218 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
217 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
219 tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
218 tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
220 try:
219 try:
221 msg = emailparser.Parser().parse(fileobj)
220 msg = pycompat.emailparser().parse(fileobj)
222
221
223 subject = msg['Subject'] and mail.headdecode(msg['Subject'])
222 subject = msg['Subject'] and mail.headdecode(msg['Subject'])
224 data['user'] = msg['From'] and mail.headdecode(msg['From'])
223 data['user'] = msg['From'] and mail.headdecode(msg['From'])
@@ -267,6 +267,10 b' if ispy3:'
267 ret = shlex.split(s.decode('latin-1'))
267 ret = shlex.split(s.decode('latin-1'))
268 return [a.encode('latin-1') for a in ret]
268 return [a.encode('latin-1') for a in ret]
269
269
270 def emailparser(*args, **kwargs):
271 import email.parser
272 return email.parser.BytesParser(*args, **kwargs)
273
270 else:
274 else:
271 import cStringIO
275 import cStringIO
272
276
@@ -327,6 +331,10 b' else:'
327 ziplist = zip
331 ziplist = zip
328 rawinput = raw_input
332 rawinput = raw_input
329
333
334 def emailparser(*args, **kwargs):
335 import email.parser
336 return email.parser.Parser(*args, **kwargs)
337
330 isjython = sysplatform.startswith('java')
338 isjython = sysplatform.startswith('java')
331
339
332 isdarwin = sysplatform == 'darwin'
340 isdarwin = sysplatform == 'darwin'
General Comments 0
You need to be logged in to leave comments. Login now