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

Pulkit Goyal 7895pulkit at gmail.com
Fri Dec 23 13:11:53 EST 2016


I am now confused as why we have this block as it must not be there.
Digging into the ProxyHandler class, it takes proxy values from the
environment if we pass proxies as None. And in url.py, its sure that
we don't pass proxies as None.
Look for bug 2451, whose resolution resulted into the current state.
https://bz.mercurial-scm.org/show_bug.cgi?id=2451.
Comment 6 explains my feelings. :)

On Thu, Dec 22, 2016 at 6:43 PM, Yuya Nishihara <yuya at tcha.org> wrote:
> 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