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


Python utils.datetime2timestamp方法代碼示例

本文整理匯總了Python中botocore.utils.datetime2timestamp方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.datetime2timestamp方法的具體用法?Python utils.datetime2timestamp怎麽用?Python utils.datetime2timestamp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在botocore.utils的用法示例。


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

示例1: generate_presigned_url

# 需要導入模塊: from botocore import utils [as 別名]
# 或者: from botocore.utils import datetime2timestamp [as 別名]
def generate_presigned_url(self, url, date_less_than=None, policy=None):
        """Creates a signed CloudFront URL based on given parameters.

        :type url: str
        :param url: The URL of the protected object

        :type date_less_than: datetime
        :param date_less_than: The URL will expire after that date and time

        :type policy: str
        :param policy: The custom policy, possibly built by self.build_policy()

        :rtype: str
        :return: The signed URL.
        """
        if (date_less_than is not None and policy is not None or
                date_less_than is None and policy is None):
            e = 'Need to provide either date_less_than or policy, but not both'
            raise ValueError(e)
        if date_less_than is not None:
            # We still need to build a canned policy for signing purpose
            policy = self.build_policy(url, date_less_than)
        if isinstance(policy, six.text_type):
            policy = policy.encode('utf8')
        if date_less_than is not None:
            params = ['Expires=%s' % int(datetime2timestamp(date_less_than))]
        else:
            params = ['Policy=%s' % self._url_b64encode(policy).decode('utf8')]
        signature = self.rsa_signer(policy)
        params.extend([
            'Signature=%s' % self._url_b64encode(signature).decode('utf8'),
            'Key-Pair-Id=%s' % self.key_id,
            ])
        return self._build_url(url, params) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:36,代碼來源:signers.py

示例2: build_policy

# 需要導入模塊: from botocore import utils [as 別名]
# 或者: from botocore.utils import datetime2timestamp [as 別名]
def build_policy(self, resource, date_less_than,
                     date_greater_than=None, ip_address=None):
        """A helper to build policy.

        :type resource: str
        :param resource: The URL or the stream filename of the protected object

        :type date_less_than: datetime
        :param date_less_than: The URL will expire after the time has passed

        :type date_greater_than: datetime
        :param date_greater_than: The URL will not be valid until this time

        :type ip_address: str
        :param ip_address: Use 'x.x.x.x' for an IP, or 'x.x.x.x/x' for a subnet

        :rtype: str
        :return: The policy in a compact string.
        """
        # Note:
        # 1. Order in canned policy is significant. Special care has been taken
        #    to ensure the output will match the order defined by the document.
        #    There is also a test case to ensure that order.
        #    SEE: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-canned-policy.html#private-content-canned-policy-creating-policy-statement
        # 2. Albeit the order in custom policy is not required by CloudFront,
        #    we still use OrderedDict internally to ensure the result is stable
        #    and also matches canned policy requirement.
        #    SEE: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-custom-policy.html
        moment = int(datetime2timestamp(date_less_than))
        condition = OrderedDict({"DateLessThan": {"AWS:EpochTime": moment}})
        if ip_address:
            if '/' not in ip_address:
                ip_address += '/32'
            condition["IpAddress"] = {"AWS:SourceIp": ip_address}
        if date_greater_than:
            moment = int(datetime2timestamp(date_greater_than))
            condition["DateGreaterThan"] = {"AWS:EpochTime": moment}
        ordered_payload = [('Resource', resource), ('Condition', condition)]
        custom_policy = {"Statement": [OrderedDict(ordered_payload)]}
        return json.dumps(custom_policy, separators=(',', ':')) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:42,代碼來源:signers.py

示例3: filter_log_events

# 需要導入模塊: from botocore import utils [as 別名]
# 或者: from botocore.utils import datetime2timestamp [as 別名]
def filter_log_events(self,
                          log_group_name,   # type: str
                          start_time=None,  # type: Optional[datetime]
                          next_token=None,  # type: Optional[str]
                          ):
        # type: (...) -> LogEventsResponse
        logs = self._client('logs')
        kwargs = {
            'logGroupName': log_group_name,
            'interleaved': True,
        }
        if start_time is not None:
            kwargs['startTime'] = int(datetime2timestamp(start_time) * 1000)
        if next_token is not None:
            kwargs['nextToken'] = next_token
        try:
            response = logs.filter_log_events(**kwargs)
        except logs.exceptions.ResourceNotFoundException:
            # If there's no log messages yet then we'll just return
            # an empty response.
            return {'events': []}
        # We want to convert the individual events that have integer
        # types over to datetime objects so it's easier for us to
        # work with.
        self._convert_types_on_response(response)
        return response 
開發者ID:aws,項目名稱:chalice,代碼行數:28,代碼來源:awsclient.py

示例4: test_can_provide_optional_start_time_iter_logs

# 需要導入模塊: from botocore import utils [as 別名]
# 或者: from botocore.utils import datetime2timestamp [as 別名]
def test_can_provide_optional_start_time_iter_logs(stubbed_session):
    timestamp = int(datetime2timestamp(datetime.datetime.utcnow()) * 1000)
    # We need to convert back from timestamp instead of using utcnow() directly
    # because the loss of precision in sub ms time.
    datetime_now = datetime.datetime.utcfromtimestamp(timestamp / 1000.0)
    stubbed_session.stub('logs').filter_log_events(
        logGroupName='loggroup', interleaved=True).returns({
            "events": [{
                "logStreamName": "logStreamName",
                "timestamp": timestamp,
                "message": "message",
                "ingestionTime": timestamp,
                "eventId": "eventId"
            }],
        })

    stubbed_session.activate_stubs()

    awsclient = TypedAWSClient(stubbed_session)
    logs = list(awsclient.iter_log_events('loggroup', start_time=datetime_now))
    assert logs == [
        {'logStreamName': 'logStreamName',
         'timestamp': datetime_now,
         'message': 'message',
         'ingestionTime': datetime_now,
         'eventId': 'eventId'}
    ]

    stubbed_session.verify_stubs() 
開發者ID:aws,項目名稱:chalice,代碼行數:31,代碼來源:test_awsclient.py


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