Skip to content

Commit

Permalink
Add timeout argument in Correios client
Browse files Browse the repository at this point in the history
  • Loading branch information
osantana committed Jul 29, 2016
1 parent b01e85d commit 0da696f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions correios/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,19 @@ class Correios:
}
websro_url = "https://webservice.correios.com.br/service/rastro/Rastro.wsdl"

def __init__(self, username, password, environment="production"):
def __init__(self, username, password, timeout=8, environment="production"):
self.username = username
self.password = password
self.timeout = timeout

url, verify = self.sigep_urls[environment]
self.sigep_url = url
self.sigep_verify = verify

self.sigep_client = SoapClient(self.sigep_url, verify=self.sigep_verify)
self.sigep_client = SoapClient(self.sigep_url, verify=self.sigep_verify, timeout=self.timeout)
self.sigep = self.sigep_client.service

self.websro_client = SoapClient(self.websro_url)
self.websro_client = SoapClient(self.websro_url, timeout=self.timeout)
self.websro = self.websro_client.service

self.model_builder = ModelBuilder()
Expand Down
13 changes: 9 additions & 4 deletions correios/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, **kwargs):
self._requests_session = requests.Session()
self.cert = kwargs.pop('cert', None)
self.verify = kwargs.pop('verify', True)
self.timeout = kwargs.pop('timeout', 8)
HttpAuthenticated.__init__(self, **kwargs)

def open(self, request):
Expand All @@ -40,7 +41,9 @@ def open(self, request):
data=request.message,
headers=request.headers,
cert=self.cert,
verify=self.verify)
verify=self.verify,
timeout=self.timeout,
)
result = BytesIO(resp.content)
return result

Expand All @@ -52,13 +55,15 @@ def send(self, request):
data=request.message,
headers=request.headers,
cert=self.cert,
verify=self.verify)
verify=self.verify,
timeout=self.timeout,
)
result = Reply(resp.status_code, resp.headers, resp.content)
return result


class SoapClient(Client):
def __init__(self, url, cert=None, verify=True, *args, **kwargs):
transport = RequestsTransport(cert=cert, verify=verify)
def __init__(self, url, cert=None, verify=True, timeout=8, *args, **kwargs):
transport = RequestsTransport(cert=cert, verify=verify, timeout=timeout)
headers = {"Content-Type": "text/xml;charset=UTF-8", "SOAPAction": ""}
super().__init__(url, transport=transport, headers=headers, **kwargs)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name="correios",
version="0.4.0",
version="0.4.1",
url="https://github.com/osantana/correios",

author="Osvaldo Santana Neto",
Expand Down

0 comments on commit 0da696f

Please sign in to comment.