From 92e06d7fd9fe8e2e0d7ac5c4b3c86e6c01f53955 Mon Sep 17 00:00:00 2001 From: John Whitman Date: Thu, 16 May 2024 12:56:28 -0400 Subject: [PATCH] Removes mutable defaults. --- interfax/client.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/interfax/client.py b/interfax/client.py index feac1e4..76b5d93 100644 --- a/interfax/client.py +++ b/interfax/client.py @@ -65,14 +65,25 @@ def account(self): def deliver(self): return self.outbound.deliver - def get(self, path, params={}, valid_keys=[], **kwargs): + def get(self, path, params=None, valid_keys=None, **kwargs): """Make a HTTP GET request.""" + if params is None: + params = {} + + if valid_keys is None: + valid_keys = [] url = self._url_for(path, params, valid_keys) return self._request('GET', url, **kwargs) - def post(self, path, params={}, valid_keys=[], **kwargs): + def post(self, path, params=None, valid_keys=None, **kwargs): """Make a HTTP POST request.""" + if params is None: + params = {} + + if valid_keys is None: + valid_keys = [] + url = self._url_for(path, params, valid_keys) return self._request('POST', url, **kwargs) @@ -89,8 +100,14 @@ def _request(self, method, url, **kwargs): return self._parse_response(request(method, url, **kwargs)) - def _url_for(self, path, params={}, keys=[]): + def _url_for(self, path, params=None, keys=None): """Validate query params and return fully qualified url.""" + if params is None: + params = {} + + if keys is None: + keys = [] + invalid = [k for k in params if k not in keys] message = 'unexpected keyword argument "{0}", expecting: {1}'