comparison mercurial/pycompat.py @ 36045:04984f2e50ae

py3: use email parser that operates on bytes email.parser.Parser() operates on str in both Python 2 and 3. Python 3.2 introduced the email.parser.BytesParser(), which works like Parser except it accepts bytes. We implement the pycompat helper as a function so we lazily import the "email" module. Differential Revision: https://phab.mercurial-scm.org/D2147
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 11 Feb 2018 14:17:23 -0800
parents fc44c2657dc5
children 646002338365
comparison
equal deleted inserted replaced
36044:3b4d14beac3d 36045:04984f2e50ae
265 Python 3 compatibility as shelx.split() don't accept bytes on Python 3. 265 Python 3 compatibility as shelx.split() don't accept bytes on Python 3.
266 """ 266 """
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
273 bytechr = chr 277 bytechr = chr
274 bytestr = str 278 bytestr = str
325 stringio = cStringIO.StringIO 329 stringio = cStringIO.StringIO
326 maplist = map 330 maplist = map
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'
333 isposix = osname == 'posix' 341 isposix = osname == 'posix'
334 iswindows = osname == 'nt' 342 iswindows = osname == 'nt'