Skip to content

Commit

Permalink
Merge 46366ac into 1c1765e
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique committed Aug 3, 2017
2 parents 1c1765e + 46366ac commit 0655a3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 45 deletions.
57 changes: 13 additions & 44 deletions correios/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import logging
from io import BytesIO

import requests
from suds.client import Client
from suds.transport import Reply
from suds.transport.http import HttpAuthenticated
from requests import Session
from zeep import Client, Transport


logger = logging.getLogger(__name__)


class RequestsTransport(HttpAuthenticated):
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)
class SoapClient(Client):

def open(self, request):
self.addcredentials(request)
logger.debug("request.open: %s", request)
resp = self._requests_session.get(
request.url,
data=request.message,
headers=request.headers,
cert=self.cert,
verify=self.verify,
timeout=self.timeout,
)
result = BytesIO(resp.content)
return result
def __init__(self, wsdl, cert=None, verify=True, timeout=8, **kwargs):
session = Session()
session.cert = cert
session.verify = verify
session.timeout = timeout
session.headers.update({'Content-Type': 'text/xml;charset=UTF-8'})

def send(self, request):
self.addcredentials(request)
logger.debug("request.send: %s", request)
resp = self._requests_session.post(
request.url,
data=request.message,
headers=request.headers,
cert=self.cert,
verify=self.verify,
timeout=self.timeout,
transport = Transport(
operation_timeout=timeout,
session=session
)
result = Reply(resp.status_code, resp.headers, resp.content)
return result


class SoapClient(Client):
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"}
super().__init__(url, transport=transport, headers=headers, **kwargs)
super().__init__(wsdl=wsdl, transport=transport, **kwargs)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ hubarcode

# api
requests
suds-jurko
zeep
lxml

0 comments on commit 0655a3d

Please sign in to comment.