コード例 #1
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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
    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)
コード例 #5
0
ファイル: http.py プロジェクト: chandra270490/frappe-bench
 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)
コード例 #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
ファイル: 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)
コード例 #8
0
    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)
コード例 #9
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)
コード例 #10
0
ファイル: http.py プロジェクト: glosoftgroup/ecommerce2
    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 = 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 e

        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)