Skip to content

Conversation

@schlamar
Copy link
Contributor

See #3976

@codecov-io
Copy link

codecov-io commented Apr 20, 2017

Codecov Report

Merging #3979 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3979      +/-   ##
==========================================
- Coverage   89.76%   89.74%   -0.03%     
==========================================
  Files          15       15              
  Lines        1955     1940      -15     
==========================================
- Hits         1755     1741      -14     
+ Misses        200      199       -1
Impacted Files Coverage Δ
requests/structures.py 100% <ø> (ø) ⬆️
requests/compat.py 100% <100%> (ø) ⬆️
requests/utils.py 86.25% <100%> (+1.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26ab951...5c389cf. Read the comment docs.

@schlamar
Copy link
Contributor Author

As first step I added tests to check the current behavior (they take around 30 seconds to run on my system) so we can detect regressions in the new implementation.

Tested with Python 2.7 and 3.5.

@schlamar schlamar changed the title [WIP] improve proxy bypass on Windows improve proxy bypass on Windows Apr 20, 2017
@schlamar
Copy link
Contributor Author

Well coverage drops obviously as these tests are only run on Windows :-/

From my POV this is ready to get merged, please review.

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, we may need to enable appveyor to ensure that this stuff actually works.

'ProxyEnable')[0]
proxyOverride = str(winreg.QueryValueEx(internetSettings,
'ProxyOverride')[0])
# ^^^^ Returned as Unicode but problems if not converted to ASCII
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is confusing: what is it trying to say?

for val in host:
if re.match(test, val, re.I):
return 1
return 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may as well just use booleans.


# try to make a host list from name and IP address.
rawHost, port = splitport(host)
host = [rawHost]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

# canonical entry.
proxyOverride = proxyOverride.split(';')
# now check if we match one of the registry values.
for test in proxyOverride:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably unify these two lines.

if compat.is_py3:
import winreg
else:
import _winreg as winreg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well just import this directly from compat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we would need a platform check in compat and winreg could be None on non Windows platforms...

@schlamar
Copy link
Contributor Author

The code is copy pasted from Python 3.5's urlib/request.py with the lines doing DNS lookups (and appending to host) removed. I would recommend leaving it as is (maybe add a clarifying comment about this).

@Lukasa
Copy link
Member

Lukasa commented Apr 20, 2017

I'm a bit disinclined to do that unless we think this is going to be temporary code (which it won't be until we drop 2.7 support at least). If we are going to support it I'd like the code to be sensible and comprehensible. 😃

@schlamar
Copy link
Contributor Author

schlamar commented May 2, 2017

@Lukasa Please give me a note when AppVeyor tests are working. Then I'll udpate this PR.

@schlamar
Copy link
Contributor Author

schlamar commented May 3, 2017

@Lukasa Should I revert c121b98? With this PR there is no reason anymore for caching the results...

@Lukasa
Copy link
Member

Lukasa commented May 3, 2017

@schlamar Yeah, might be worth doing.

@schlamar schlamar force-pushed the bypass-proxy branch 2 times, most recently from 7d563d4 to db57972 Compare May 3, 2017 14:23
@kennethreitz kennethreitz reopened this May 3, 2017
@kennethreitz
Copy link
Contributor

close/reopened to get appveyor to re-run

@Lukasa
Copy link
Member

Lukasa commented May 3, 2017

It'll need to be rebased on top of master.

Copy link
Member

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good start @schlamar! I left a couple notes with some outstanding questions from my end. A couple are just stylistic nits but the others are on functionality.

for test in proxyOverride:
if test == '<local>':
if '.' not in host:
return 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is 1 and not True like the other return values? If so, we should probably add a comment explaining why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I forgot this one 🙈


if is_py2:
from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass
from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass, \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to follow something closer to the import convention of the other modules, rather than use \.

from urllib import (
    quote, unquote, quote_plus, unquote_plus, urlencode, getproxies,
    proxy_bypass, proxy_bypass_environment, getproxies_environment)

Returns settings gathered from the environment, if specified,
or the registry.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this extra line here.

if getproxies_environment():
return proxy_bypass_environment(host)
else:
return proxy_bypass_registry(host)
Copy link
Member

@nateprewitt nateprewitt May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to return a boolean but the docstring states it returns a dictionary of scheme to proxy mappings. It may be a good idea to clarify this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I copied the wrong docstring, I'll fix this :)

@schlamar
Copy link
Contributor Author

schlamar commented May 4, 2017

@Lukasa @nateprewitt Updated, please review again.

@schlamar
Copy link
Contributor Author

schlamar commented May 4, 2017

BTW, coverage drops because reverting 8e6e47a and c121b98 removes a lot of covered lines. My changes alone do not negatively affect coverage.

@Lukasa
Copy link
Member

Lukasa commented May 4, 2017

@schlamar Based on codecov's output the actual reason you're reducing coverage is that the diff isn't covered enough to avoid regressing it. To match coverage you'd need to cover 90% of the diff, but only 86% is covered. You can see the lines we're missing here: what are the odds that we can write tests that appropriately cover them?

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, so this is looking really good! I'd love to see if we can get the test coverage up a bit higher, and I've left a note in the diff. 😄

DEFAULT_CA_BUNDLE_PATH = certs.where()


if os.name == 'nt':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use os.name, might it be better to use platform.system?

import _winreg as winreg

except ImportError:
# Std modules, so should be around - but you never know!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lukasa Should I remove this one, I don't think this is really necessary...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's do that: there's no need to tolerate this ImportError I don't think.

@schlamar schlamar closed this May 4, 2017
@schlamar schlamar reopened this May 4, 2017
@schlamar
Copy link
Contributor Author

schlamar commented May 4, 2017

@Lukasa Updated, please review again :)

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I'm happy. Time to see what @nateprewitt thinks.

Copy link
Member

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then, one last request. Can you add notes to the changelog to note that a) we've changed our strategy for looking up proxy bypass information on Windows, and b) we've removed the proxy bypass cache as it's no longer needed? Just want to make sure we have a good reference in case these things have unforseen bugs, and I bet I'll forget that there were two things in this PR when it comes to writing the changelog later. 😁

@schlamar
Copy link
Contributor Author

schlamar commented May 4, 2017

When was the proxy bypass cache introduced? I'd like to make a reference but can't find anything in the changelog :)

@nateprewitt
Copy link
Member

@schlamar, I believe it was only a couple months ago (#3885).

@schlamar
Copy link
Contributor Author

schlamar commented May 4, 2017

Ah yes, this wasn't even released yet. @Lukasa in this case I would ignore this?!

@Lukasa
Copy link
Member

Lukasa commented May 4, 2017

Yeah, you would. =)

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's do it!

@Lukasa Lukasa merged commit 216aee4 into psf:master May 4, 2017
@sethmlarson
Copy link
Member

🎉

@schlamar schlamar deleted the bypass-proxy branch May 5, 2017 13:38
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants