Skip to content

Commit 728dd46

Browse files
nicolasunravelAutomatedTester
authored andcommitted
replaced mutable default values with None
Signed-off-by: AutomatedTester <[email protected]>
1 parent d7f00b6 commit 728dd46

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ build/
66
*.egg-info/
77
.cache/
88
bmp.log
9+
.idea/

browsermobproxy/client.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import requests
22

33
try:
4-
from urllib.parse import urlencode, unquote
4+
from urllib.parse import urlencode, unquote
55
except ImportError:
6-
from urllib import urlencode, unquote
6+
from urllib import urlencode, unquote
77
import json
88

99

1010
class Client(object):
11-
def __init__(self, url, params={}, options={}):
11+
def __init__(self, url, params=None, options=None):
1212
"""
1313
Initialises a new Client object
1414
@@ -18,6 +18,8 @@ def __init__(self, url, params={}, options={}):
1818
:param options: Dictionary that can contain the port of an existing
1919
proxy to use (for example 'existing_proxy_port_to_use')
2020
"""
21+
params = params if params is not None else {}
22+
options = options if options is not None else {}
2123
self.host = "http://" + url
2224
if params:
2325
urlparams = "?" + unquote(urlencode(params))
@@ -97,7 +99,7 @@ def har(self):
9799
return r.json()
98100

99101

100-
def new_har(self, ref=None, options={}):
102+
def new_har(self, ref=None, options=None):
101103
"""
102104
This sets a new HAR to be recorded
103105
@@ -109,6 +111,8 @@ def new_har(self, ref=None, options={}):
109111
captureContent - Boolean, capture content bodies \
110112
captureBinaryContent - Boolean, capture binary content
111113
"""
114+
options = options if options is not None else {}
115+
112116
if ref:
113117
payload = {"initialPageRef": ref}
114118
else:
@@ -281,15 +285,15 @@ def timeouts(self, options):
281285
params)
282286
return r.status_code
283287

284-
def remap_hosts(self, address=None, ip_address=None, hostmap={}):
288+
def remap_hosts(self, address=None, ip_address=None, hostmap=None):
285289
"""
286290
Remap the hosts for a specific URL
287291
288292
:param address: url that you wish to remap
289293
:param ip_address: IP Address that will handle all traffic for the address passed in
290294
:param **hostmap: Other hosts to be added as keyword arguments
291295
"""
292-
296+
hostmap = hostmap if hostmap is not None else {}
293297
if (address is not None and ip_address is not None):
294298
hostmap[address] = ip_address
295299

browsermobproxy/server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ def url(self):
2727
"""
2828
return "http://%s:%d" % (self.host, self.port)
2929

30-
def create_proxy(self, params={}):
30+
def create_proxy(self, params=None):
3131
"""
3232
Gets a client class that allow to set all the proxy details that you
3333
may need to.
3434
:param params: Dictionary where you can specify params \
3535
like httpProxy and httpsProxy
3636
"""
37+
params = params if params is not None else {}
3738
client = Client(self.url[7:], params)
3839
return client
3940

@@ -50,7 +51,7 @@ def _is_listening(self):
5051

5152
class Server(RemoteServer):
5253

53-
def __init__(self, path='browsermob-proxy', options={}):
54+
def __init__(self, path='browsermob-proxy', options=None):
5455
"""
5556
Initialises a Server object
5657
@@ -59,6 +60,8 @@ def __init__(self, path='browsermob-proxy', options={}):
5960
More items will be added in the future. \
6061
This defaults to an empty dictionary
6162
"""
63+
options = options if options is not None else {}
64+
6265
path_var_sep = ':'
6366
if platform.system() == 'Windows':
6467
path_var_sep = ';'

browsermobproxy/webdriver_event_listener.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
class WebDriverEventListener(AbstractEventListener):
44

5-
def __init__(self, client, refs={}):
5+
def __init__(self, client, refs=None):
6+
refs = refs if refs is not None else {}
67
self.client = client
78
self.hars = []
89
self.refs = refs

0 commit comments

Comments
 (0)