當前位置: 首頁>>代碼示例>>Python>>正文


Python service.AWSServiceEndpoint類代碼示例

本文整理匯總了Python中txaws.service.AWSServiceEndpoint的典型用法代碼示例。如果您正苦於以下問題:Python AWSServiceEndpoint類的具體用法?Python AWSServiceEndpoint怎麽用?Python AWSServiceEndpoint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AWSServiceEndpoint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_canonical_host_with_non_default_port

 def test_get_canonical_host_with_non_default_port(self):
     """
     If the port is not the default, the canonical host includes it.
     """
     uri = "http://my.service:99/endpoint"
     endpoint = AWSServiceEndpoint(uri=uri)
     self.assertEquals("my.service:99", endpoint.get_canonical_host())
開發者ID:oubiwann,項目名稱:txaws,代碼行數:7,代碼來源:test_service.py

示例2: test_get_canonical_host_is_lower_case

 def test_get_canonical_host_is_lower_case(self):
     """
     The canonical host is guaranteed to be lower case.
     """
     uri = "http://MY.SerVice:99/endpoint"
     endpoint = AWSServiceEndpoint(uri=uri)
     self.assertEquals("my.service:99", endpoint.get_canonical_host())
開發者ID:oubiwann,項目名稱:txaws,代碼行數:7,代碼來源:test_service.py

示例3: test_set_canonical_host

 def test_set_canonical_host(self):
     """
     The canonical host is converted to lower case.
     """
     endpoint = AWSServiceEndpoint()
     endpoint.set_canonical_host("My.Service")
     self.assertEquals("my.service", endpoint.host)
     self.assertIdentical(None, endpoint.port)
開發者ID:oubiwann,項目名稱:txaws,代碼行數:8,代碼來源:test_service.py

示例4: test_get_canonical_host

 def test_get_canonical_host(self):
     """
     If the port is not specified the canonical host is the same as
     the host.
     """
     uri = "http://my.service/endpoint"
     endpoint = AWSServiceEndpoint(uri=uri)
     self.assertEquals("my.service", endpoint.get_canonical_host())
開發者ID:oubiwann,項目名稱:txaws,代碼行數:8,代碼來源:test_service.py

示例5: test_set_canonical_host_with_empty_port

 def test_set_canonical_host_with_empty_port(self):
     """
     The canonical host can also have no port.
     """
     endpoint = AWSServiceEndpoint()
     endpoint.set_canonical_host("my.service:")
     self.assertEquals("my.service", endpoint.host)
     self.assertIdentical(None, endpoint.port)
開發者ID:oubiwann,項目名稱:txaws,代碼行數:8,代碼來源:test_service.py

示例6: test_set_canonical_host_with_port

 def test_set_canonical_host_with_port(self):
     """
     The canonical host can optionally have a port.
     """
     endpoint = AWSServiceEndpoint()
     endpoint.set_canonical_host("my.service:99")
     self.assertEquals("my.service", endpoint.host)
     self.assertEquals(99, endpoint.port)
開發者ID:oubiwann,項目名稱:txaws,代碼行數:8,代碼來源:test_service.py

示例7: AWSServiceEndpointTestCase

class AWSServiceEndpointTestCase(TXAWSTestCase):

    def setUp(self):
        self.endpoint = AWSServiceEndpoint(uri="http://my.service/da_endpoint")

    def test_simple_creation(self):
        endpoint = AWSServiceEndpoint()
        self.assertEquals(endpoint.scheme, "http")
        self.assertEquals(endpoint.host, "")
        self.assertEquals(endpoint.port, 80)
        self.assertEquals(endpoint.path, "/")
        self.assertEquals(endpoint.method, "GET")

    def test_custom_method(self):
        endpoint = AWSServiceEndpoint(
            uri="http://service/endpoint", method="PUT")
        self.assertEquals(endpoint.method, "PUT")

    def test_parse_uri(self):
        self.assertEquals(self.endpoint.scheme, "http")
        self.assertEquals(self.endpoint.host, "my.service")
        self.assertEquals(self.endpoint.port, 80)
        self.assertEquals(self.endpoint.path, "/da_endpoint")

    def test_parse_uri_https_and_custom_port(self):
        endpoint = AWSServiceEndpoint(uri="https://my.service:8080/endpoint")
        self.assertEquals(endpoint.scheme, "https")
        self.assertEquals(endpoint.host, "my.service")
        self.assertEquals(endpoint.port, 8080)
        self.assertEquals(endpoint.path, "/endpoint")

    def test_get_uri(self):
        uri = self.endpoint.get_uri()
        self.assertEquals(uri, "http://my.service/da_endpoint")

    def test_get_uri_custom_port(self):
        uri = "https://my.service:8080/endpoint"
        endpoint = AWSServiceEndpoint(uri=uri)
        new_uri = endpoint.get_uri()
        self.assertEquals(new_uri, uri)

    def test_set_host(self):
        self.assertEquals(self.endpoint.host, "my.service")
        self.endpoint.set_host("newhost.com")
        self.assertEquals(self.endpoint.host, "newhost.com")

    def test_get_host(self):
        self.assertEquals(self.endpoint.host, self.endpoint.get_host())

    def test_set_path(self):
        self.endpoint.set_path("/newpath")
        self.assertEquals(
            self.endpoint.get_uri(),
            "http://my.service/newpath")

    def test_set_method(self):
        self.assertEquals(self.endpoint.method, "GET")
        self.endpoint.set_method("PUT")
        self.assertEquals(self.endpoint.method, "PUT")
開發者ID:lzimm,項目名稱:360io,代碼行數:59,代碼來源:test_service.py

示例8: get_queue

 def get_queue(self, owner_id, queue):
     """
         @param owner_id: required, C{str}.
         @param queue: required, C{str}:
         If owner_id and queue name is known, there is no need to do
         request for queue url. You should call this method to get queue
         and make operations on it.
     """
     endpoint = AWSServiceEndpoint(uri=self.endpoint.get_uri())
     endpoint.set_path('/{}/{}/'.format(owner_id, queue))
     query_factory = QuerysSignatureV4(self.creds, endpoint,
                                       self.query_factory.agent)
     return Queue(self.creds, endpoint, query_factory)
開發者ID:lud4ik,項目名稱:txAWS,代碼行數:13,代碼來源:client.py

示例9: _validate_signature

 def _validate_signature(self, request, principal, args, params):
     """Validate the signature."""
     creds = AWSCredentials(principal.access_key, principal.secret_key)
     endpoint = AWSServiceEndpoint()
     endpoint.set_method(request.method)
     endpoint.set_canonical_host(request.getHeader("Host"))
     path = request.path
     if self.path is not None:
         path = "%s/%s" % (self.path.rstrip("/"), path.lstrip("/"))
     endpoint.set_path(path)
     signature = Signature(
         creds,
         endpoint,
         params,
         signature_method=args["signature_method"],
         signature_version=args["signature_version"],
     )
     if signature.compute() != args["signature"]:
         raise APIError(
             403,
             "SignatureDoesNotMatch",
             "The request signature we calculated does not "
             "match the signature you provided. Check your "
             "key and signing method.",
         )
開發者ID:antisvin,項目名稱:txAWS,代碼行數:25,代碼來源:resource.py

示例10: __init__

 def __init__(self, bucket=None, object_name=None, data="",
              content_type=None, metadata={}, *args, **kwargs):
     super(Query, self).__init__(*args, **kwargs)
     self.bucket = bucket
     self.object_name = object_name
     self.data = data
     self.content_type = content_type
     self.metadata = metadata
     self.date = datetimeToString()
     if not self.endpoint or not self.endpoint.host:
         self.endpoint = AWSServiceEndpoint(S3_ENDPOINT)
     self.endpoint.set_method(self.action)
開發者ID:lzimm,項目名稱:360io,代碼行數:12,代碼來源:client.py

示例11: __init__

    def __init__(self, bucket=None, object_name=None, data="",
                 content_type=None, metadata={}, amz_headers={},
                 body_producer=None, *args, **kwargs):
        super(Query, self).__init__(*args, **kwargs)

        # data might be None or "", alas.
        if data and body_producer is not None:
            raise ValueError("data and body_producer are mutually exclusive.")

        self.bucket = bucket
        self.object_name = object_name
        self.data = data
        self.body_producer = body_producer
        self.content_type = content_type
        self.metadata = metadata
        self.amz_headers = amz_headers
        self._date = datetimeToString()
        if not self.endpoint or not self.endpoint.host:
            self.endpoint = AWSServiceEndpoint(S3_ENDPOINT)
        self.endpoint.set_method(self.action)
開發者ID:mithrandi,項目名稱:txaws,代碼行數:20,代碼來源:client.py

示例12: Query

class Query(BaseQuery):
    """A query for submission to the S3 service."""

    def __init__(self, bucket=None, object_name=None, data="",
                 content_type=None, metadata={}, amz_headers={}, *args,
                 **kwargs):
        super(Query, self).__init__(*args, **kwargs)
        self.bucket = bucket
        self.object_name = object_name
        self.data = data
        self.content_type = content_type
        self.metadata = metadata
        self.amz_headers = amz_headers
        self.date = datetimeToString()
        if not self.endpoint or not self.endpoint.host:
            self.endpoint = AWSServiceEndpoint(S3_ENDPOINT)
        self.endpoint.set_method(self.action)

    def set_content_type(self):
        """
        Set the content type based on the file extension used in the object
        name.
        """
        if self.object_name and not self.content_type:
            # XXX nothing is currently done with the encoding... we may
            # need to in the future
            self.content_type, encoding = mimetypes.guess_type(
                self.object_name, strict=False)

    def get_headers(self):
        """
        Build the list of headers needed in order to perform S3 operations.
        """
        headers = {"Content-Length": len(self.data),
                   "Content-MD5": calculate_md5(self.data),
                   "Date": self.date}
        for key, value in self.metadata.iteritems():
            headers["x-amz-meta-" + key] = value
        for key, values in self.amz_headers.iteritems():
            if isinstance(values, tuple):
                headers["x-amz-" + key] = ",".join(values)
            else:
                headers["x-amz-" + key] = values
        # Before we check if the content type is set, let's see if we can set
        # it by guessing the the mimetype.
        self.set_content_type()
        if self.content_type is not None:
            headers["Content-Type"] = self.content_type
        if self.creds is not None:
            signature = self.sign(headers)
            headers["Authorization"] = "AWS %s:%s" % (
                self.creds.access_key, signature)
        return headers

    def get_canonicalized_amz_headers(self, headers):
        """
        Get the headers defined by Amazon S3.
        """
        headers = [
            (name.lower(), value) for name, value in headers.iteritems()
            if name.lower().startswith("x-amz-")]
        headers.sort()
        # XXX missing spec implementation:
        # txAWS doesn't currently unfold long headers
        def represent(n, vs):
            if isinstance(vs, tuple):
                return "".join(["%s:%s\n" % (n, vs) for v in vs])
            else:
                return "%s:%s\n" % (n, vs)

        return "".join([represent(name, value) for name, value in headers])

    def get_canonicalized_resource(self):
        """
        Get an S3 resource path.
        """
        path = "/"
        if self.bucket is not None:
            path += self.bucket
        if self.bucket is not None and self.object_name:
            if not self.object_name.startswith("/"):
                path += "/"
            path += self.object_name
        elif self.bucket is not None and not path.endswith("/"):
            path += "/"
        return path

    def sign(self, headers):
        """Sign this query using its built in credentials."""
        text = (self.action + "\n" +
                headers.get("Content-MD5", "") + "\n" +
                headers.get("Content-Type", "") + "\n" +
                headers.get("Date", "") + "\n" +
                self.get_canonicalized_amz_headers(headers) +
                self.get_canonicalized_resource())
        return self.creds.sign(text, hash_type="sha1")

    def submit(self, url_context=None):
        """Submit this query.

#.........這裏部分代碼省略.........
開發者ID:ArtRichards,項目名稱:leastauthority.com,代碼行數:101,代碼來源:client.py

示例13: test_get_uri_custom_port

 def test_get_uri_custom_port(self):
     uri = "https://my.service:8080/endpoint"
     endpoint = AWSServiceEndpoint(uri=uri)
     new_uri = endpoint.get_uri()
     self.assertEquals(new_uri, uri)
開發者ID:oubiwann,項目名稱:txaws,代碼行數:5,代碼來源:test_service.py

示例14: setUp

 def setUp(self):
     self.endpoint = AWSServiceEndpoint(uri="http://my.service/da_endpoint")
開發者ID:oubiwann,項目名稱:txaws,代碼行數:2,代碼來源:test_service.py

示例15: AWSServiceEndpointTestCase

class AWSServiceEndpointTestCase(TestCase):

    def setUp(self):
        self.endpoint = AWSServiceEndpoint(uri="http://my.service/da_endpoint")

    def test_warning_when_verification_disabled(self):
        """
        L{AWSServiceEndpoint} emits a warning when told not to perform
        certificate verification.
        """
        self.assertWarns(
            UserWarning,
            "Operating with certificate verification disabled!",
            __file__,
            lambda: AWSServiceEndpoint(ssl_hostname_verification=False),
        )

    def test_simple_creation(self):
        endpoint = AWSServiceEndpoint()
        self.assertEquals(endpoint.scheme, "http")
        self.assertEquals(endpoint.host, "")
        self.assertEquals(endpoint.port, None)
        self.assertEquals(endpoint.path, "/")
        self.assertEquals(endpoint.method, "GET")

    def test_custom_method(self):
        endpoint = AWSServiceEndpoint(
            uri="http://service/endpoint", method="PUT")
        self.assertEquals(endpoint.method, "PUT")

    def test_parse_uri(self):
        self.assertEquals(self.endpoint.scheme, "http")
        self.assertEquals(self.endpoint.host, "my.service")
        self.assertIdentical(self.endpoint.port, None)
        self.assertEquals(self.endpoint.path, "/da_endpoint")

    def test_parse_uri_https_and_custom_port(self):
        endpoint = AWSServiceEndpoint(uri="https://my.service:8080/endpoint")
        self.assertEquals(endpoint.scheme, "https")
        self.assertEquals(endpoint.host, "my.service")
        self.assertEquals(endpoint.port, 8080)
        self.assertEquals(endpoint.path, "/endpoint")

    def test_get_uri(self):
        uri = self.endpoint.get_uri()
        self.assertEquals(uri, "http://my.service/da_endpoint")

    def test_get_uri_custom_port(self):
        uri = "https://my.service:8080/endpoint"
        endpoint = AWSServiceEndpoint(uri=uri)
        new_uri = endpoint.get_uri()
        self.assertEquals(new_uri, uri)

    def test_set_host(self):
        self.assertEquals(self.endpoint.host, "my.service")
        self.endpoint.set_host("newhost.com")
        self.assertEquals(self.endpoint.host, "newhost.com")

    def test_get_host(self):
        self.assertEquals(self.endpoint.host, self.endpoint.get_host())

    def test_get_canonical_host(self):
        """
        If the port is not specified the canonical host is the same as
        the host.
        """
        uri = "http://my.service/endpoint"
        endpoint = AWSServiceEndpoint(uri=uri)
        self.assertEquals("my.service", endpoint.get_canonical_host())

    def test_get_canonical_host_with_non_default_port(self):
        """
        If the port is not the default, the canonical host includes it.
        """
        uri = "http://my.service:99/endpoint"
        endpoint = AWSServiceEndpoint(uri=uri)
        self.assertEquals("my.service:99", endpoint.get_canonical_host())

    def test_get_canonical_host_is_lower_case(self):
        """
        The canonical host is guaranteed to be lower case.
        """
        uri = "http://MY.SerVice:99/endpoint"
        endpoint = AWSServiceEndpoint(uri=uri)
        self.assertEquals("my.service:99", endpoint.get_canonical_host())

    def test_set_canonical_host(self):
        """
        The canonical host is converted to lower case.
        """
        endpoint = AWSServiceEndpoint()
        endpoint.set_canonical_host("My.Service")
        self.assertEquals("my.service", endpoint.host)
        self.assertIdentical(None, endpoint.port)

    def test_set_canonical_host_with_port(self):
        """
        The canonical host can optionally have a port.
        """
        endpoint = AWSServiceEndpoint()
#.........這裏部分代碼省略.........
開發者ID:oubiwann,項目名稱:txaws,代碼行數:101,代碼來源:test_service.py


注:本文中的txaws.service.AWSServiceEndpoint類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。