On Thu, 16 Jul 2020 23:05:19 +0300, Александр Литягин wrote: > # HG changeset patch > # User alexrayne <alexraynepe...@gmail.com> > # Date 1557358579 -10800 > # Thu May 09 02:36:19 2019 +0300 > # Node ID 856cea175acabd5b8f87319001067a7785c15279 > # Parent 33b512aa8dba0cbe523188fbb62d30ae2125a236 > !popen:py3 - #6065 subprocess.Popen uses strings args. so, py2 normaly
> +def encodes(s, name_or_codec, *args, **kwargs): > + if s is None: > + return []; > + if (isinstance(name_or_codec, string_types)): > + codec = codecs.lookup(name_or_codec) > + else: > + codec = name_or_codec > + r = [] > + for arg in s: > + if (isinstance(arg, string_types)): > + rv, length = codec.encode(arg, *args, **kwargs) > + r.append(rv) > + else: > + r.append(arg) > + return r Unused. > +def decodes(s, name_or_codec, *args, **kwargs): > + if (isinstance(name_or_codec, string_types)): > + codec = codecs.lookup(name_or_codec) > + else: > + codec = name_or_codec > + if s is None: > + return []; > + r = [] > + for arg in s: > + if (isinstance(arg, bytes)): > + rv, length = codec.decode(arg, *args, **kwargs) > + if not isinstance(rv, (str, bytes, bytearray)): > + raise TypeError('Not a string or byte codec') > + r.append(rv) > + else: > + r.append(arg) > + return r > + > +if (sys.version_info[0] >= 3) and (os.name == 'nt') : > + def _fix_encoding_args(a): > + #py3 Popen accepts str args > + encoding = get_encoding() or 'UTF-8' > + argcodec = codecs.lookup(encoding) I think there's no need to look up codec object. > + return decodes( a, argcodec ) #get_encoding() > +else: > + def _fix_encoding_args(a): > + #py2 Popen accepts binary_str args > + return a #encodes(a, argcodec) #a; > + > def popen(args, env=None): > environ = None > if env: > environ = dict(os.environ) > environ.update(env) > > - return subprocess.Popen(args, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, > + return subprocess.Popen(_fix_encoding_args(args), The encoding of user arguments is unknown, but maybe using a.decode("mbcs") is better since the other hgclient APIs would expect an MBCS-encoded bytes on Windows. https://www.mercurial-scm.org/repo/hg/file/5.4/mercurial/pycompat.py#l174 And we might also want to leverage the encoding parameter if specified: def init(dest=None, ssh=None, remotecmd=None, insecure=False, encoding=None, configs=None): args = util.cmdbuilder('init', ...) args = util.tonativeargs(args, encoding=encoding) ... proc = util.popen(args) _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel