Skip to content

Commit 124c883

Browse files
committed
pep8 --ignore=E501
1 parent a6c95df commit 124c883

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

browsermobproxy/client.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
#from httplib2 import Http
21
import requests
32
from urllib import urlencode
43
import json
54

5+
66
class Client(object):
7-
87
def __init__(self, url):
98
"""
109
Initialises a new Client object
1110
:Args:
1211
- url: This is where the BrowserMob Proxy lives
1312
"""
14-
self.host = url
13+
self.host = url
1514
resp = requests.post('%s/proxy' % self.host, urlencode(''))
1615
jcontent = json.loads(resp.content)
1716
self.port = jcontent['port']
1817
url_parts = self.host.split(":")
19-
self.proxy = url_parts[0] + ":" + url_parts[1] + ":" + str(self.port)
18+
self.proxy = url_parts[0] + ":" + url_parts[1] + ":" + str(self.port)
2019

2120
def headers(self, headers):
2221
"""
@@ -29,7 +28,7 @@ def headers(self, headers):
2928

3029
r = requests.post(url='%s/proxy/%s/headers' % (self.host, self.port),
3130
data=json.dumps(headers),
32-
headers = {'content-type': 'application/json'})
31+
headers={'content-type': 'application/json'})
3332
return r.status_code
3433

3534
def new_har(self, ref=None):
@@ -55,24 +54,25 @@ def new_page(self, ref=None):
5554
payload = {"pageRef": ref}
5655
else:
5756
payload = {}
58-
r = requests.put('%s/proxy/%s/har/pageRef' % (self.host, self.port), payload)
57+
r = requests.put('%s/proxy/%s/har/pageRef' % (self.host, self.port),
58+
payload)
5959
return r.status_code
60-
60+
6161
@property
6262
def har(self):
6363
"""
6464
Gets the HAR that has been recorded
6565
"""
6666
r = requests.get('%s/proxy/%s/har' % (self.host, self.port))
67-
67+
6868
return r.json
6969

7070
def selenium_proxy(self):
7171
"""
7272
Returns a Selenium WebDriver Proxy class with details of the HTTP Proxy
7373
"""
7474
from selenium import webdriver
75-
return webdriver.Proxy({"httpProxy":self.proxy})
75+
return webdriver.Proxy({"httpProxy": self.proxy})
7676

7777
def webdriver_proxy(self):
7878
"""
@@ -82,7 +82,8 @@ def webdriver_proxy(self):
8282

8383
def add_to_webdriver_capabilities(self, capabilities):
8484
"""
85-
Adds an 'proxy' entry to a desired capabilities dictionary with the BrowserMob proxy information
85+
Adds an 'proxy' entry to a desired capabilities dictionary with the
86+
BrowserMob proxy information
8687
"""
8788
capabilities['proxy'] = {'proxyType': 'manual',
8889
'httpProxy': self.proxy}
@@ -92,34 +93,31 @@ def whitelist(self, regexp, status_code):
9293
Sets a list of URL patterns to whitelist
9394
:Args:
9495
- regex: a comma separated list of regular expressions
95-
- status_code: the HTTP status code to return for URLs that do not match the whitelist
96-
96+
- status_code: the HTTP status code to return for URLs that do not
97+
match the whitelist
9798
"""
98-
r = requests.put('%s/proxy/%s/whitelist' % (self.host, self.port),
99-
urlencode({ 'regex': regexp, 'status': status_code
100-
}))
99+
r = requests.put('%s/proxy/%s/whitelist' % (self.host, self.port),
100+
urlencode({'regex': regexp, 'status': status_code}))
101101
return r.status_code
102102

103-
104103
def blacklist(self, regexp, status_code):
105104
"""
106-
Sets a list of URL patterns to blacklist
105+
Sets a list of URL patterns to blacklist
107106
:Args:
108107
- regex: a comma separated list of regular expressions
109-
- status_code: the HTTP status code to return for URLs that do not match the blacklist
108+
- status_code: the HTTP status code to return for URLs that do not
109+
match the blacklist
110110
111111
"""
112-
r = requests.put('%s/proxy/%s/blacklist' % (self.host, self.port),
113-
urlencode({ 'regex': regexp, 'status': status_code
114-
}))
112+
r = requests.put('%s/proxy/%s/blacklist' % (self.host, self.port),
113+
urlencode({'regex': regexp, 'status': status_code}))
115114
return r.status_code
116115

117116
LIMITS = {
118-
'upstream_kbps' : 'upstreamKbps',
119-
'downstream_kbps' : 'downstreamKbps',
120-
'latency' : 'latency'
121-
}
122-
117+
'upstream_kbps': 'upstreamKbps',
118+
'downstream_kbps': 'downstreamKbps',
119+
'latency': 'latency'
120+
}
123121

124122
def limits(self, options):
125123
"""
@@ -133,16 +131,16 @@ def limits(self, options):
133131
params = {}
134132

135133
for (k, v) in options.items():
136-
if not self.LIMITS.has_key(k):
134+
if k not in self.LIMITS:
137135
raise KeyError('invalid key: %s' % k)
138136

139137
params[self.LIMITS[k]] = int(v)
140138

141139
if len(params.items()) == 0:
142140
raise KeyError("You need to specify one of the valid Keys")
143-
144-
r = requests.put('%s/proxy/%s/limit' % (self.host, self.port),
145-
urlencode(params))
141+
142+
r = requests.put('%s/proxy/%s/limit' % (self.host, self.port),
143+
urlencode(params))
146144
return r.status_code
147145

148146
def close(self):

test/test_client.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
import pytest
33
import sys
44

5+
56
def setup_module(module):
67
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
78

9+
810
class TestClient(object):
911
def setup_method(self, method):
1012
from browsermobproxy.client import Client
1113
self.client = Client("http://localhost:9090")
12-
14+
1315
def teardown_method(self, method):
1416
self.client.close()
15-
17+
1618
def test_headers_type(self):
1719
"""
1820
/proxy/:port/headers needs to take a dictionary
@@ -36,7 +38,7 @@ def test_new_har(self):
3638
"""
3739
status_code, har = self.client.new_har()
3840
assert(status_code == 204)
39-
assert(har == None)
41+
assert(har is None)
4042
status_code, har = self.client.new_har()
4143
assert(status_code == 200)
4244
assert('log' in har)
@@ -49,7 +51,7 @@ def test_new_har(self):
4951
"""
5052
status_code, har = self.client.new_har("elephants")
5153
assert(status_code == 204)
52-
assert(har == None)
54+
assert(har is None)
5355
status_code, har = self.client.new_har("elephants")
5456
assert(status_code == 200)
5557
assert('elephants' == har["log"]["pages"][0]['id'])
@@ -83,15 +85,15 @@ def test_single_whitelist(self):
8385
"""
8486
status_code = self.client.whitelist("http://www\\.facebook\\.com/.*", 200)
8587
assert(status_code == 200)
86-
88+
8789
def test_multiple_whitelists(self):
8890
"""
8991
/proxy/:port/whitelist
9092
adds a whitelist
9193
"""
9294
status_code = self.client.whitelist("http://www\\.facebook\\.com/.*,http://cdn\\.twitter\\.com", 200)
9395
assert(status_code == 200)
94-
96+
9597
def test_blacklist(self):
9698
"""
9799
/proxy/:port/blacklist
@@ -124,7 +126,7 @@ def test_limits_key_no_value(self):
124126
limits = {"upstream_kbps": 320, "downstream_kbps": 560, "latency": 30}
125127
status_code = self.client.limits(limits)
126128
assert(status_code == 200)
127-
129+
128130
def test_close(self):
129131
"""
130132
/proxy/:port

0 commit comments

Comments
 (0)