Some PEP8 fixes
This commit is contained in:
parent
1ff07273b3
commit
61e7b93779
2 changed files with 26 additions and 24 deletions
|
|
@ -79,7 +79,8 @@ class Firefox(Profile):
|
||||||
# Replace all base requests headers
|
# Replace all base requests headers
|
||||||
# https://developer.mozilla.org/en/Gecko_user_agent_string_reference
|
# https://developer.mozilla.org/en/Gecko_user_agent_string_reference
|
||||||
# https://bugzilla.mozilla.org/show_bug.cgi?id=572650
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=572650
|
||||||
session.config['base_headers'] = {'Accept-Language': 'en-us,en;q=0.5',
|
session.config['base_headers'] = {
|
||||||
|
'Accept-Language': 'en-us,en;q=0.5',
|
||||||
'Accept-Encoding': 'gzip, deflate',
|
'Accept-Encoding': 'gzip, deflate',
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0.3) Gecko/20100101 Firefox/10.0.3',
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0.3) Gecko/20100101 Firefox/10.0.3',
|
||||||
|
|
@ -100,7 +101,8 @@ class Wget(Profile):
|
||||||
def setup_session(self, session):
|
def setup_session(self, session):
|
||||||
# Don't remove base headers, if websites want to block fake browsers,
|
# Don't remove base headers, if websites want to block fake browsers,
|
||||||
# they will probably block any wget user agent anyway.
|
# they will probably block any wget user agent anyway.
|
||||||
session.config['base_headers'].update({'Accept': '*/*',
|
session.config['base_headers'].update({
|
||||||
|
'Accept': '*/*',
|
||||||
'User-Agent': 'Wget/%s' % self.version})
|
'User-Agent': 'Wget/%s' % self.version})
|
||||||
session.config['keep_alive'] = True
|
session.config['keep_alive'] = True
|
||||||
|
|
||||||
|
|
@ -188,8 +190,8 @@ class BaseBrowser(object):
|
||||||
# Later python-request versions do it that way, but to stay
|
# Later python-request versions do it that way, but to stay
|
||||||
# compatible with older versions, we use this.
|
# compatible with older versions, we use this.
|
||||||
while request.allow_redirects is False \
|
while request.allow_redirects is False \
|
||||||
and response.status_code in requests.models.REDIRECT_STATI \
|
and response.status_code in requests.models.REDIRECT_STATI \
|
||||||
and 'location' in response.headers:
|
and 'location' in response.headers:
|
||||||
## This is from requests.models._build_response
|
## This is from requests.models._build_response
|
||||||
response.content # Consume socket so it can be released
|
response.content # Consume socket so it can be released
|
||||||
|
|
||||||
|
|
@ -210,7 +212,7 @@ class BaseBrowser(object):
|
||||||
# Do the same as Google Chrome.
|
# Do the same as Google Chrome.
|
||||||
# http://git.chromium.org/gitweb/?p=chromium/src/net.git;a=blob;f=url_request/url_request.cc;h=8597917f0cbf49c84b3bdae3a7bebacbc264f1e0;hb=HEAD#l673
|
# http://git.chromium.org/gitweb/?p=chromium/src/net.git;a=blob;f=url_request/url_request.cc;h=8597917f0cbf49c84b3bdae3a7bebacbc264f1e0;hb=HEAD#l673
|
||||||
if (response.status_code == 303 and request.method != 'HEAD') \
|
if (response.status_code == 303 and request.method != 'HEAD') \
|
||||||
or (response.status_code in (requests.codes.moved, requests.codes.found) and request.method == 'POST'):
|
or (response.status_code in (requests.codes.moved, requests.codes.found) and request.method == 'POST'):
|
||||||
# Once we use GET, all next requests will use GET.
|
# Once we use GET, all next requests will use GET.
|
||||||
orig_args['method'] = 'GET'
|
orig_args['method'] = 'GET'
|
||||||
orig_args['data'] = None
|
orig_args['data'] = None
|
||||||
|
|
@ -254,8 +256,8 @@ class BaseBrowser(object):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def location(self, url, data=None,
|
def location(self, url, data=None,
|
||||||
allow_redirects=True, referrer=None,
|
allow_redirects=True, referrer=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""
|
"""
|
||||||
Like open() but also changes the current URL and response.
|
Like open() but also changes the current URL and response.
|
||||||
This is the most common method to request web pages.
|
This is the most common method to request web pages.
|
||||||
|
|
@ -268,8 +270,8 @@ class BaseBrowser(object):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def open(self, url, data=None,
|
def open(self, url, data=None,
|
||||||
allow_redirects=True, referrer=None,
|
allow_redirects=True, referrer=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""
|
"""
|
||||||
Make an HTTP request like a browser does:
|
Make an HTTP request like a browser does:
|
||||||
* follow redirects (unless disabled)
|
* follow redirects (unless disabled)
|
||||||
|
|
|
||||||
|
|
@ -83,15 +83,15 @@ def test_redirects():
|
||||||
assert r.history[1].request.url == HTTPBIN + 'redirect/3'
|
assert r.history[1].request.url == HTTPBIN + 'redirect/3'
|
||||||
assert r.history[1].request.headers.get('Referer') == HTTPBIN + 'redirect/4'
|
assert r.history[1].request.headers.get('Referer') == HTTPBIN + 'redirect/4'
|
||||||
assert r.history[0].request.url == HTTPBIN + 'redirect/4'
|
assert r.history[0].request.url == HTTPBIN + 'redirect/4'
|
||||||
assert r.history[0].request.headers.get('Referer') == None
|
assert r.history[0].request.headers.get('Referer') is None
|
||||||
assert r.url == HTTPBIN + 'get'
|
assert r.url == HTTPBIN + 'get'
|
||||||
|
|
||||||
# Disable all referers
|
# Disable all referers
|
||||||
r = b.location(HTTPBIN + 'redirect/2', referrer=False)
|
r = b.location(HTTPBIN + 'redirect/2', referrer=False)
|
||||||
assert json.loads(r.text)['headers'].get('Referer') == None
|
assert json.loads(r.text)['headers'].get('Referer') is None
|
||||||
assert len(r.history) == 2
|
assert len(r.history) == 2
|
||||||
assert r.history[1].request.headers.get('Referer') == None
|
assert r.history[1].request.headers.get('Referer') is None
|
||||||
assert r.history[0].request.headers.get('Referer') == None
|
assert r.history[0].request.headers.get('Referer') is None
|
||||||
assert r.url == HTTPBIN + 'get'
|
assert r.url == HTTPBIN + 'get'
|
||||||
|
|
||||||
# Only overrides first referer
|
# Only overrides first referer
|
||||||
|
|
@ -315,25 +315,25 @@ def test_cookiepolicy():
|
||||||
|
|
||||||
# security for received cookies
|
# security for received cookies
|
||||||
assert policy.can_set(bc('k=v; domain=www.example.com'),
|
assert policy.can_set(bc('k=v; domain=www.example.com'),
|
||||||
'http://www.example.com/')
|
'http://www.example.com/')
|
||||||
assert policy.can_set(bc('k=v; domain=sub.example.com'),
|
assert policy.can_set(bc('k=v; domain=sub.example.com'),
|
||||||
'http://www.example.com/')
|
'http://www.example.com/')
|
||||||
assert policy.can_set(bc('k=v; domain=sub.example.com'),
|
assert policy.can_set(bc('k=v; domain=sub.example.com'),
|
||||||
'http://example.com/')
|
'http://example.com/')
|
||||||
assert policy.can_set(bc('k=v; domain=.example.com'),
|
assert policy.can_set(bc('k=v; domain=.example.com'),
|
||||||
'http://example.com/')
|
'http://example.com/')
|
||||||
assert policy.can_set(bc('k=v; domain=www.example.com'),
|
assert policy.can_set(bc('k=v; domain=www.example.com'),
|
||||||
'http://example.com/')
|
'http://example.com/')
|
||||||
assert not policy.can_set(bc('k=v; domain=example.com'),
|
assert not policy.can_set(bc('k=v; domain=example.com'),
|
||||||
'http://example.net/')
|
'http://example.net/')
|
||||||
assert not policy.can_set(bc('k=v; domain=.net'),
|
assert not policy.can_set(bc('k=v; domain=.net'),
|
||||||
'http://example.net/')
|
'http://example.net/')
|
||||||
assert not policy.can_set(bc('k=v; domain=www.example.net'),
|
assert not policy.can_set(bc('k=v; domain=www.example.net'),
|
||||||
'http://www.example.com/')
|
'http://www.example.com/')
|
||||||
assert not policy.can_set(bc('k=v; domain=wwwexample.com'),
|
assert not policy.can_set(bc('k=v; domain=wwwexample.com'),
|
||||||
'http://example.com/')
|
'http://example.com/')
|
||||||
assert not policy.can_set(bc('k=v; domain=.example.com'),
|
assert not policy.can_set(bc('k=v; domain=.example.com'),
|
||||||
'http://wwwexample.com/')
|
'http://wwwexample.com/')
|
||||||
|
|
||||||
# pattern matching domains
|
# pattern matching domains
|
||||||
assert not policy.domain_match('example.com', 's.example.com')
|
assert not policy.domain_match('example.com', 's.example.com')
|
||||||
|
|
@ -564,7 +564,7 @@ def test_cookie_srv2():
|
||||||
|
|
||||||
def cookienum(self):
|
def cookienum(self):
|
||||||
return int(re.search('Number of cookies received: (\d+)',
|
return int(re.search('Number of cookies received: (\d+)',
|
||||||
self.response.text).groups()[0])
|
self.response.text).groups()[0])
|
||||||
|
|
||||||
def mypost(self, **data):
|
def mypost(self, **data):
|
||||||
return self.location('', data)
|
return self.location('', data)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue