##// END OF EJS Templates
py3: ditch email.parser.BytesParser which appears to be plain crap...
Yuya Nishihara -
r38354:7b12a2d2 default
parent child Browse files
Show More
@@ -203,6 +203,7 b' test-http.t'
203 test-hybridencode.py
203 test-hybridencode.py
204 test-identify.t
204 test-identify.t
205 test-import-bypass.t
205 test-import-bypass.t
206 test-import-eol.t
206 test-import-merge.t
207 test-import-merge.t
207 test-import-unknown.t
208 test-import-unknown.t
208 test-import.t
209 test-import.t
@@ -11,6 +11,8 b' import email'
11 import email.charset
11 import email.charset
12 import email.header
12 import email.header
13 import email.message
13 import email.message
14 import email.parser
15 import io
14 import os
16 import os
15 import smtplib
17 import smtplib
16 import socket
18 import socket
@@ -322,6 +324,23 b' def mimeencode(ui, s, charsets=None, dis'
322 s, cs = _encode(ui, s, charsets)
324 s, cs = _encode(ui, s, charsets)
323 return mimetextqp(s, 'plain', cs)
325 return mimetextqp(s, 'plain', cs)
324
326
327 if pycompat.ispy3:
328 def parse(fp):
329 ep = email.parser.Parser()
330 # disable the "universal newlines" mode, which isn't binary safe.
331 # I have no idea if ascii/surrogateescape is correct, but that's
332 # what the standard Python email parser does.
333 fp = io.TextIOWrapper(fp, encoding=r'ascii',
334 errors=r'surrogateescape', newline=chr(10))
335 try:
336 return ep.parse(fp)
337 finally:
338 fp.detach()
339 else:
340 def parse(fp):
341 ep = email.parser.Parser()
342 return ep.parse(fp)
343
325 def headdecode(s):
344 def headdecode(s):
326 '''Decodes RFC-2047 header'''
345 '''Decodes RFC-2047 header'''
327 uparts = []
346 uparts = []
@@ -112,7 +112,7 b' def split(stream):'
112 cur.append(line)
112 cur.append(line)
113 c = chunk(cur)
113 c = chunk(cur)
114
114
115 m = pycompat.emailparser().parse(c)
115 m = mail.parse(c)
116 if not m.is_multipart():
116 if not m.is_multipart():
117 yield msgfp(m)
117 yield msgfp(m)
118 else:
118 else:
@@ -230,7 +230,7 b' def _extract(ui, fileobj, tmpname, tmpfp'
230
230
231 data = {}
231 data = {}
232
232
233 msg = pycompat.emailparser().parse(fileobj)
233 msg = mail.parse(fileobj)
234
234
235 subject = msg[r'Subject'] and mail.headdecode(msg[r'Subject'])
235 subject = msg[r'Subject'] and mail.headdecode(msg[r'Subject'])
236 data['user'] = msg[r'From'] and mail.headdecode(msg[r'From'])
236 data['user'] = msg[r'From'] and mail.headdecode(msg[r'From'])
@@ -295,10 +295,6 b' if ispy3:'
295 ret = shlex.split(s.decode('latin-1'), comments, posix)
295 ret = shlex.split(s.decode('latin-1'), comments, posix)
296 return [a.encode('latin-1') for a in ret]
296 return [a.encode('latin-1') for a in ret]
297
297
298 def emailparser(*args, **kwargs):
299 import email.parser
300 return email.parser.BytesParser(*args, **kwargs)
301
302 else:
298 else:
303 import cStringIO
299 import cStringIO
304
300
@@ -371,10 +367,6 b' else:'
371 rawinput = raw_input
367 rawinput = raw_input
372 getargspec = inspect.getargspec
368 getargspec = inspect.getargspec
373
369
374 def emailparser(*args, **kwargs):
375 import email.parser
376 return email.parser.Parser(*args, **kwargs)
377
378 isjython = sysplatform.startswith('java')
370 isjython = sysplatform.startswith('java')
379
371
380 isdarwin = sysplatform == 'darwin'
372 isdarwin = sysplatform == 'darwin'
General Comments 0
You need to be logged in to leave comments. Login now