From 676fa960945204ead495f626e3a38ad22ce51d70 Mon Sep 17 00:00:00 2001 From: Michell Stuttgart Date: Sun, 24 Nov 2024 09:53:51 -0300 Subject: [PATCH] Expand timeout and proxies parameters --- brazilcep/apicep.py | 4 ++-- brazilcep/client.py | 10 +--------- brazilcep/opencep.py | 4 ++-- brazilcep/viacep.py | 4 ++-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/brazilcep/apicep.py b/brazilcep/apicep.py index e1fca79..a590282 100644 --- a/brazilcep/apicep.py +++ b/brazilcep/apicep.py @@ -17,7 +17,7 @@ URL = "https://ws.apicep.com/cep/{}.json" -def fetch_address(cep, **kwargs): +def fetch_address(cep, timeout, proxies): """Fetch VIACEP webservice for CEP address. VIACEP provide a REST API to query CEP requests. @@ -30,7 +30,7 @@ def fetch_address(cep, **kwargs): address (dict): respective address data from CEP. """ - response = requests.get(URL.format(cep), **kwargs) # pylint = missing-timeout + response = requests.get(URL.format(cep), timeout=timeout, proxies=proxies) if response.status_code == 200: address = json.loads(response.text) diff --git a/brazilcep/client.py b/brazilcep/client.py index d5caccf..d0f40f0 100644 --- a/brazilcep/client.py +++ b/brazilcep/client.py @@ -73,15 +73,7 @@ def get_address_from_cep(cep, webservice=WebService.APICEP, timeout=None, proxie """Invalid webservice. Please use this options: WebService.VIACEP, WebService.APICEP or WebService.OPENCEP""" ) - kwargs = {} - - if timeout and isinstance(timeout, int): - kwargs["timeout"] = timeout - - if proxies and isinstance(proxies, dict): - kwargs["proxies"] = proxies - - return services[webservice](_format_cep(cep), **kwargs) + return services[webservice](_format_cep(cep), timeout=timeout, proxies=proxies) def _format_cep(cep): diff --git a/brazilcep/opencep.py b/brazilcep/opencep.py index 867f2be..e9b8a56 100644 --- a/brazilcep/opencep.py +++ b/brazilcep/opencep.py @@ -17,7 +17,7 @@ URL = "https://opencep.com/v1/{}" -def fetch_address(cep, **kwargs): +def fetch_address(cep, timeout=None, proxies=None): """Fetch OpenCEP webservice for CEP address. OpenCEP provide a REST API to query CEP requests. @@ -30,7 +30,7 @@ def fetch_address(cep, **kwargs): address (dict): respective address data from CEP. """ - response = requests.get(URL.format(cep), **kwargs) # pylint = missing-timeout + response = requests.get(URL.format(cep), timeout=timeout, proxies=proxies) if response.status_code == 200: address = json.loads(response.text) diff --git a/brazilcep/viacep.py b/brazilcep/viacep.py index 1d275fd..02cb864 100644 --- a/brazilcep/viacep.py +++ b/brazilcep/viacep.py @@ -17,7 +17,7 @@ URL = "http://www.viacep.com.br/ws/{}/json" -def fetch_address(cep, **kwargs): +def fetch_address(cep, timeout, proxies): """Fetch APICEP webservice for CEP address. APICEP provide a REST API to query CEP requests. @@ -31,7 +31,7 @@ def fetch_address(cep, **kwargs): address (dict): respective address data from CEP. """ - response = requests.get(URL.format(cep), **kwargs) # pylint = missing-timeout + response = requests.get(URL.format(cep), timeout=timeout, proxies=proxies) if response.status_code == 200: # Transforma o objeto requests em um dict