コード例 #1
0
ファイル: http.py プロジェクト: paltman/braintree_python
    def __http_do(self, http_verb, path, params=None):
        if self.environment.is_ssl:
            self.__verify_ssl()
            conn = httplib.HTTPSConnection(self.environment.server, self.environment.port)
        else:
            conn = httplib.HTTPConnection(self.environment.server, self.environment.port)

        conn.request(
            http_verb,
            self.config.base_merchant_path() + path,
            XmlUtil.xml_from_dict(params) if params else "",
            self.__headers(),
        )
        response = conn.getresponse()
        status = response.status

        if Http.is_error_status(status):
            conn.close()
            Http.raise_exception_from_status(status)
        else:
            data = response.read()
            conn.close()
            if len(data.strip()) == 0:
                return {}
            else:
                return XmlUtil.dict_from_xml(data)
コード例 #2
0
ファイル: http.py プロジェクト: tewks/braintree_python
    def __http_do(self, http_verb, path, params=None):
        # self.__verify_ssl()
        conn = HttpsClient(self.environment.server, self.environment.port)
        # conn.ssl_ctx.set_client_ca_list([self.environment.ssl_certificate])
        print "##############"
        print self.environment.server
        print self.environment.port
        print http_verb
        path = self.config.base_merchant_path() + path
        print path
        headers = self.__headers()
        for k in headers._headers:
            print "%s - %s" % (k, headers.get(k))
        base = XmlUtil.xml_from_dict(params) if params else ""
        print base
        print "##############"
        code, heads, data = conn.request(http_verb, self.config.base_merchant_path() + path, self.__headers(), base)
        print code
        for k in heads._headers:
            print "%s - %s" % (k, headers.get(k))
        print data

        if Http.is_error_status(code):
            Http.raise_exception_from_status(code)
        else:
            if len(data.strip()) == 0:
                return {}
            else:
                return XmlUtil.dict_from_xml(data)
コード例 #3
0
ファイル: http.py プロジェクト: Getaround/braintree_python
    def __http_do(self, http_verb, path, params=None):

        try:

            from google.appengine.api import urlfetch

            if self.environment.is_ssl:
                self.__verify_ssl()

            url = self.environment.protocol + self.environment.server + self.config.base_merchant_path() + path
            payload = params and XmlUtil.xml_from_dict(params)
            response = urlfetch.fetch(
                url=url,
                payload=payload,
                method=http_verb,
                headers=self.__headers(),
                deadline=Configuration.request_timeout,
            )

            status = response.status_code
            if Http.is_error_status(status):
                Http.raise_exception_from_status(status)
            else:
                data = response.content
                if len(data.strip()) == 0:
                    return {}
                else:
                    return XmlUtil.dict_from_xml(data)

        except ImportError:

            if self.environment.is_ssl:
                self.__verify_ssl()
                conn = httplib.HTTPSConnection(self.environment.server, self.environment.port)
            else:
                conn = httplib.HTTPConnection(self.environment.server, self.environment.port)

            conn.request(
                http_verb,
                self.config.base_merchant_path() + path,
                params and XmlUtil.xml_from_dict(params),
                self.__headers(),
            )
            response = conn.getresponse()
            status = response.status

            if Http.is_error_status(status):
                conn.close()
                Http.raise_exception_from_status(status)
            else:
                data = response.read()
                conn.close()
                if len(data.strip()) == 0:
                    return {}
                else:
                    return XmlUtil.dict_from_xml(data)
コード例 #4
0
ファイル: http.py プロジェクト: quantm/custom_django_oscar
    def __http_do(self, http_verb, path, params=None):
        http_strategy = self.config.http_strategy()
        request_body = XmlUtil.xml_from_dict(params) if params else ''
        full_path = self.config.base_merchant_path() + path
        status, response_body = http_strategy.http_do(http_verb, full_path, self.__headers(), request_body)

        if Http.is_error_status(status):
            Http.raise_exception_from_status(status)
        else:
            if len(response_body.strip()) == 0:
                return {}
            else:
                return XmlUtil.dict_from_xml(response_body)
コード例 #5
0
ファイル: http.py プロジェクト: braintree/braintree_python
    def _make_request(self, http_verb, path, content_type, params=None, files=None, header_overrides=None):
        http_strategy = self.config.http_strategy()
        headers = self.__headers(content_type, header_overrides)
        request_body = self.__request_body(content_type, params, files)

        full_path = path if path.startswith(self.config.base_url()) or path.startswith(self.config.graphql_base_url()) else (self.config.base_url() + path)

        try:
            status, response_body = http_strategy.http_do(http_verb, full_path, headers, request_body)
        except Exception as e:
            if self.config.wrap_http_exceptions:
                http_strategy.handle_exception(e)
            else:
                raise

        if Http.is_error_status(status):
            Http.raise_exception_from_status(status)
        else:
            if len(response_body.strip()) == 0:
                return {}
            else:
                if content_type == Http.ContentType.Json:
                    return json.loads(response_body)
                else:
                    return XmlUtil.dict_from_xml(response_body)
コード例 #6
0
ファイル: http.py プロジェクト: braintree/braintree_python
 def __request_body(self, content_type, params, files):
     if content_type == Http.ContentType.Xml:
         request_body = XmlUtil.xml_from_dict(params) if params else ''
         return request_body
     elif files == None:
         return params
     else:
         return (params, files)
コード例 #7
0
 def parse(self, signature, payload):
     if isinstance(payload, text_type):
         payload = payload.encode('ascii')
     if re.search(b"[^A-Za-z0-9+=/\n]", payload):
         raise InvalidSignatureError("payload contains illegal characters")
     self.__validate_signature(signature, payload)
     attributes = XmlUtil.dict_from_xml(base64.decodestring(payload))
     return WebhookNotification(self.gateway, attributes['notification'])
コード例 #8
0
ファイル: http.py プロジェクト: LikeALocal/braintree_python
    def __http_do(self, http_verb, path, params=None):
        http_strategy = self.config.http_strategy()
        request_body = bytes(XmlUtil.xml_from_dict(params) if params else '')

        full_path = path if path.startswith(self.config.base_url()) else (self.config.base_url() + path)

        try:
            status, response_body = http_strategy.http_do(http_verb, full_path, self.__headers(), request_body)
        except Exception as e:
            if self.config.wrap_http_exceptions:
                http_strategy.handle_exception(e)
            else:
                raise

        if Http.is_error_status(status):
            Http.raise_exception_from_status(status)
        else:
            if len(response_body.strip()) == 0:
                return {}
            else:
                return XmlUtil.dict_from_xml(response_body)
コード例 #9
0
ファイル: webhook.py プロジェクト: WilliamRen/solitude
def parse(request):
    form = WebhookParseForm(request.DATA)
    if not form.is_valid():
        raise FormError(form.errors)

    # Parse the gateway without doing a validation on this server.
    # The validation has happened on the solitude-auth server.
    gateway = get_client().Configuration.instantiate().gateway()
    payload = base64.decodestring(form.cleaned_data['bt_payload'])
    attributes = XmlUtil.dict_from_xml(payload)
    parsed = WebhookNotification(gateway, attributes['notification'])

    log.info('Received webhook: {p.kind}.'.format(p=parsed))
    debug_log.debug(parsed)
    Processor(parsed).process()
    return Response(status=204)
コード例 #10
0
 def parse(self, signature, payload):
     if re.search("[^A-Za-z0-9+=/\n]", payload):
         raise InvalidSignatureError("payload contains illegal characters")
     self.__validate_signature(signature, payload)
     attributes = XmlUtil.dict_from_xml(base64.decodestring(payload))
     return WebhookNotification(self.gateway, attributes['notification'])
コード例 #11
0
 def parse(self, signature, payload):
     self.__validate_signature(signature, payload)
     attributes = XmlUtil.dict_from_xml(base64.decodestring(payload))
     return WebhookNotification(self.gateway, attributes['notification'])
コード例 #12
0
 def parse(self, signature, payload):
     self.__validate_signature(signature, payload)
     attributes = XmlUtil.dict_from_xml(base64.decodestring(payload))
     return WebhookNotification(self.gateway, attributes['notification'])