Skip to content

Commit

Permalink
Expand timeout and proxies parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mstuttgart committed Nov 24, 2024
1 parent b0f433b commit 676fa96
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions brazilcep/apicep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions brazilcep/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions brazilcep/opencep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions brazilcep/viacep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 676fa96

Please sign in to comment.