[PATCH] py3: handle os.environ case

Yuya Nishihara yuya at tcha.org
Wed Sep 28 11:42:30 EDT 2016


On Wed, 28 Sep 2016 17:01:29 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1475062024 -19800
> #      Wed Sep 28 16:57:04 2016 +0530
> # Node ID cc742296eaad5b54c81003b691897087c4a5d8fe
> # Parent  85bd31515225e7fdf9bd88edde054db2c74a33f8
> py3: handle os.environ case

> --- a/mercurial/pycompat.py	Sun Aug 21 13:16:21 2016 +0900
> +++ b/mercurial/pycompat.py	Wed Sep 28 16:57:04 2016 +0530
> @@ -10,6 +10,7 @@
>  
>  from __future__ import absolute_import
>  
> +import os
>  import sys
>  
>  if sys.version_info[0] < 3:
> @@ -164,3 +165,11 @@
>          "SimpleHTTPRequestHandler",
>          "CGIHTTPRequestHandler",
>      ))
> +
> +if sys.version_info[0] < 3:
> +    osenviron = os.environ
> +else:
> +    try:
> +        osenviron = os.environb
> +    except AttributeError: #Windows OS
> +        pass #TODO Handle windows case

I tried to implement this TODO. We need encoding.tolocal() to build a bytes
dict from unicode os.environ without losing round-trip utf-8 data, but
pycompat.py shouldn't import mercurial.* modules. So I'm thinking of adding
encoding.environ instead of pycompat.environ.

We'll also need to fix a couple of str/unicode issues in encoding.py to
make that actually work.


More information about the Mercurial-devel mailing list