[PATCH 3 of 9] py3: replace os.environ with encoding.environ (part 3 of 5)

Yuya Nishihara yuya at tcha.org
Thu Dec 22 08:13:04 EST 2016


On Wed, 21 Dec 2016 22:25:25 +0530, Pulkit Goyal wrote:
> >>          if ui.config("http_proxy", "host"):
> >>              for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
> >>                  try:
> >> -                    if env in os.environ:
> >> -                        del os.environ[env]
> >> +                    if env in encoding.environ:
> >> +                        del encoding.environ[env]
> >>                  except OSError:
> >>                      pass
> >
> > Here we have to pass new environ dict to urllib2 over the global os.environ
> > dict. So we'll need to revisit this part later since encoding.environ can be
> > a read-only copy of os.environ on Python 3.
> 
> We have two possible options,
> 
> 1.  for env in [u"HTTP_PROXY", u"http_proxy", u"no_proxy"]:
>                  try:
>                     if env in os.environ:
>                         del os.environ[env]
> 
> 2. for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
>                  try:
>                     if py3:
>                         if env in os.environb:
>                             del os.environb[env]
>                     else:
>                         if env in os.environ:
>                             del os.environ[env]
> 
> IIUC encoding.environ everytimes goes into encoding.py, check those
> conditions and returns a dictionary by reading os.environ or
> os.environb. Or is it like every time we are reading(getting by
> calling encoding.environ) the same dictionary.
> 
> If first argument is correct than any of these will work because
> os.environ and os.environb are synchronised in python 3.

Perhaps a better option is to prevent the use of http_proxy in some way other
than modifying the environ dict. Updating the environ here is theoretically
wrong since ui may have per-repository values.

https://docs.python.org/2/library/urllib2.html#urllib2.ProxyHandler


More information about the Mercurial-devel mailing list