From b405cce663ad0e245ff020b142e4af6f37389034 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Thu, 21 Jul 2016 15:22:27 -0700 Subject: [PATCH] fix: kill mutable default arguments closes #541 --- autopush/exceptions.py | 4 ++-- autopush/router/interface.py | 8 ++++---- autopush/settings.py | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/autopush/exceptions.py b/autopush/exceptions.py index 377984a9..d20df7ae 100644 --- a/autopush/exceptions.py +++ b/autopush/exceptions.py @@ -12,8 +12,8 @@ class InvalidTokenException(Exception): class InvalidRequest(AutopushException): """Invalid request exception, may include custom status_code and message to write for the error""" - def __init__(self, message, status_code=400, errno=None, headers={}): + def __init__(self, message, status_code=400, errno=None, headers=None): super(AutopushException, self).__init__(message) self.status_code = status_code self.errno = errno - self.headers = headers + self.headers = {} if headers is None else headers diff --git a/autopush/router/interface.py b/autopush/router/interface.py index 5cca664d..2fac6228 100644 --- a/autopush/router/interface.py +++ b/autopush/router/interface.py @@ -8,12 +8,12 @@ class RouterException(AutopushException): """ def __init__(self, message, status_code=500, response_body="", - router_data=None, headers={}, log_exception=True, + router_data=None, headers=None, log_exception=True, errno=None, logged_status=None): """Create a new RouterException""" super(AutopushException, self).__init__(message) self.status_code = status_code - self.headers = headers + self.headers = {} if headers is None else headers self.log_exception = log_exception self.response_body = response_body or message self.errno = errno @@ -29,12 +29,12 @@ class RouterResponse(object): """ def __init__(self, status_code=200, response_body="", router_data=None, - headers={}, errno=None, logged_status=None): + headers=None, errno=None, logged_status=None): """Create a new RouterResponse""" self.status_code = status_code self.response_body = response_body self.router_data = router_data - self.headers = headers + self.headers = {} if headers is None else headers self.errno = errno self.logged_status = logged_status diff --git a/autopush/settings.py b/autopush/settings.py index b67f438c..105a7fcf 100644 --- a/autopush/settings.py +++ b/autopush/settings.py @@ -66,7 +66,7 @@ def __init__(self, endpoint_scheme=None, endpoint_hostname=None, endpoint_port=None, - router_conf={}, + router_conf=None, router_tablename="router", router_read_throughput=5, router_write_throughput=5, @@ -84,7 +84,7 @@ def __init__(self, wake_timeout=0, env='development', enable_cors=False, - senderid_list={}, + senderid_list=None, hello_timeout=0, bear_hash_key=None, preflight_uaid="deadbeef00000000deadbeef000000000", @@ -138,6 +138,8 @@ def __init__(self, self.endpoint_hostname = endpoint_hostname or self.hostname self.router_hostname = router_hostname or self.hostname + if router_conf is None: + router_conf = {} self.router_conf = router_conf self.router_url = canonical_url( router_scheme or 'http',