comparison mercurial/pycompat.py @ 38341:7b12a2d2eedc

py3: ditch email.parser.BytesParser which appears to be plain crap As I said before, BytesParser is a thin wrapper over the unicode Parser, and it's too thin to return bytes back. Today, I found it does normalize newline characters to '\n's thanks to the careless use of TextIOWrapper. So, this patch replaces BytesParser with Parser + TextIOWrapper, and fix newline handling. Since I don't know what's the least bad encoding strategy here, I just copied it from BytesParser. I've moved new parse() function from pycompat, as it is no longer a trivial wrapper.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 16 Jun 2018 19:31:07 +0900
parents 79dd61a4554f
children 152f4822d210
comparison
equal deleted inserted replaced
38340:cf59de802883 38341:7b12a2d2eedc
292 shlex.split(), convert the returned value to bytes and return that for 292 shlex.split(), convert the returned value to bytes and return that for
293 Python 3 compatibility as shelx.split() don't accept bytes on Python 3. 293 Python 3 compatibility as shelx.split() don't accept bytes on Python 3.
294 """ 294 """
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
298 def emailparser(*args, **kwargs):
299 import email.parser
300 return email.parser.BytesParser(*args, **kwargs)
301 297
302 else: 298 else:
303 import cStringIO 299 import cStringIO
304 300
305 unicode = unicode 301 unicode = unicode
369 rangelist = range 365 rangelist = range
370 ziplist = zip 366 ziplist = zip
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'
381 isposix = osname == 'posix' 373 isposix = osname == 'posix'
382 iswindows = osname == 'nt' 374 iswindows = osname == 'nt'