Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pycompat.py @ 30681:caf7e1c5efe4
py3: have a bytes version of shlex.split()
shlex.split() only accepts unicodes on Python 3. After this patch we will be
using pycompat.shlexsplit(). This patch also replaces existing occurences of
shlex.split with pycompat.shlexsplit.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sun, 25 Dec 2016 03:06:55 +0530 |
parents | 3fcaf0f660ce |
children | 6a70cf94d1b5 |
line wrap: on
line diff
--- a/mercurial/pycompat.py Fri Dec 23 16:26:40 2016 +0000 +++ b/mercurial/pycompat.py Sun Dec 25 03:06:55 2016 +0530 @@ -12,6 +12,7 @@ import getopt import os +import shlex import sys ispy3 = (sys.version_info[0] >= 3) @@ -122,6 +123,14 @@ dic = dict((k.encode('latin-1'), v) for k, v in dic.iteritems()) return dic + # shlex.split() accepts unicodes on Python 3. This function takes bytes + # argument, convert it into unicodes, pass into shlex.split(), convert the + # returned value to bytes and return that. + # TODO: handle shlex.shlex(). + def shlexsplit(s): + ret = shlex.split(s.decode('latin-1')) + return [a.encode('latin-1') for a in ret] + else: def sysstr(s): return s @@ -162,6 +171,7 @@ getcwd = os.getcwd osgetenv = os.getenv sysexecutable = sys.executable + shlexsplit = shlex.split stringio = io.StringIO empty = _queue.Empty