当前位置: 首页>>代码示例>>Python>>正文


Python time_util.str_to_time函数代码示例

本文整理汇总了Python中saml2.time_util.str_to_time函数的典型用法代码示例。如果您正苦于以下问题:Python str_to_time函数的具体用法?Python str_to_time怎么用?Python str_to_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了str_to_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_str_to_time

def test_str_to_time():
    t = calendar.timegm(str_to_time("2000-01-12T00:00:00Z"))
    # TODO: Find all instances of time.mktime(.....)
    # t = time.mktime(str_to_time("2000-01-12T00:00:00Z"))
    # assert t == 947631600.0
    # TODO: add something to show how this time was arrived at
    # do this as an external method in the
    assert t == 947635200
    # some IdPs omit the trailing Z, and SAML spec is unclear if it is actually required
    t = calendar.timegm(str_to_time("2000-01-12T00:00:00"))
    assert t == 947635200
开发者ID:blenderbox,项目名称:pysaml2,代码行数:11,代码来源:test_10_time_util.py

示例2: test_construct_AttributeAuthorityDescriptor

def test_construct_AttributeAuthorityDescriptor():
    aad = make_instance(
        md.AttributeAuthorityDescriptor,
        {
            "valid_until": time_util.in_a_while(30),  # 30 days from now
            "id": "aad.example.com",
            "protocol_support_enumeration": SAML2_NAMESPACE,
            "attribute_service": {"binding": BINDING_SOAP, "location": "http://example.com:6543/saml2/aad"},
            "name_id_format": [NAMEID_FORMAT_TRANSIENT],
            "key_descriptor": {"use": "signing", "key_info": {"key_name": "example.com"}},
        },
    )

    print aad
    assert _eq(
        aad.keyswv(),
        ["valid_until", "id", "attribute_service", "name_id_format", "key_descriptor", "protocol_support_enumeration"],
    )
    assert time_util.str_to_time(aad.valid_until)
    assert aad.id == "aad.example.com"
    assert aad.protocol_support_enumeration == SAML2_NAMESPACE
    assert len(aad.attribute_service) == 1
    atsr = aad.attribute_service[0]
    assert _eq(atsr.keyswv(), ["binding", "location"])
    assert atsr.binding == BINDING_SOAP
    assert atsr.location == "http://example.com:6543/saml2/aad"
    assert len(aad.name_id_format) == 1
    nif = aad.name_id_format[0]
    assert nif.text.strip() == NAMEID_FORMAT_TRANSIENT
    assert len(aad.key_descriptor) == 1
    kdesc = aad.key_descriptor[0]
    assert kdesc.use == "signing"
    assert kdesc.key_info.key_name[0].text.strip() == "example.com"
开发者ID:paulftw,项目名称:pysaml2,代码行数:33,代码来源:test_30_metadata.py

示例3: test_SAML_sign_with_pkcs11

    def test_SAML_sign_with_pkcs11(self):
        """
        Test signing a SAML assertion using PKCS#11 and then verifying it.
        """
        os.environ['SOFTHSM_CONF'] = self.softhsm_conf

        ass = self._assertion
        print ass
        sign_ass = self.sec.sign_assertion("%s" % ass, node_id=ass.id)
        #print sign_ass
        sass = saml.assertion_from_string(sign_ass)
        #print sass
        assert _eq(sass.keyswv(), ['attribute_statement', 'issue_instant',
                                   'version', 'signature', 'id'])
        assert sass.version == "2.0"
        assert sass.id == "11111"
        assert time_util.str_to_time(sass.issue_instant)

        print "Crypto version : %s" % (self.sec.crypto.version())

        item = self.sec.check_signature(sass, class_name(sass), sign_ass)

        assert isinstance(item, saml.Assertion)

        print "Test PASSED"
开发者ID:peopledoc,项目名称:pysaml2,代码行数:25,代码来源:test_80_p11_backend.py

示例4: test_str_to_time

def test_str_to_time():
    t = calendar.timegm(str_to_time("2000-01-12T00:00:00Z"))
    #TODO: Find all instances of time.mktime(.....)
    #t = time.mktime(str_to_time("2000-01-12T00:00:00Z"))
    #assert t == 947631600.0
    #TODO: add something to show how this time was arrived at
    # do this as an external method in the 
    assert t == 947635200
开发者ID:lvanderree,项目名称:pysaml2-3,代码行数:8,代码来源:test_10_time_util.py

示例5: validate_before

def validate_before(not_before, slack):
    if not_before:
        now = time_util.utc_now()
        nbefore = calendar.timegm(time_util.str_to_time(not_before))
        if nbefore > now + slack:
            raise ToEarly("Can't use it yet %d <= %d" % (now + slack, nbefore))

    return True
开发者ID:Amli,项目名称:pysaml2,代码行数:8,代码来源:validate.py

示例6: issue_instant_ok

 def issue_instant_ok(self):
     """ Check that the response was issued at a reasonable time """
     upper = time_util.shift_time(time_util.time_in_a_while(days=1), self.timeslack).timetuple()
     lower = time_util.shift_time(time_util.time_a_while_ago(days=1), -self.timeslack).timetuple()
     # print("issue_instant: %s" % self.response.issue_instant)
     # print("%s < x < %s" % (lower, upper))
     issued_at = str_to_time(self.response.issue_instant)
     return lower < issued_at < upper
开发者ID:blenderbox,项目名称:pysaml2,代码行数:8,代码来源:response.py

示例7: validate_on_or_after

def validate_on_or_after(not_on_or_after, slack):
    if not_on_or_after:
        now = time_util.utc_now()
        nooa = calendar.timegm(time_util.str_to_time(not_on_or_after))
        if now > nooa + slack:
            raise ResponseLifetimeExceed("Can't use it, it's too old %d > %d".format(now - slack, nooa))
        return nooa
    else:
        return False
开发者ID:knaperek,项目名称:pysaml2,代码行数:9,代码来源:validate.py

示例8: add_derek_info

def add_derek_info(sp):
    not_on_or_after = str_to_time(in_a_while(days=1))
    session_info = SESSION_INFO_PATTERN.copy()
    session_info["ava"] = {"givenName":["Derek"], "umuselin":["deje0001"]}
    session_info["issuer"] = "https://toylan3.umdc.umu.se/shibboleth"
    session_info["name_id"] = "abcdefgh"
    session_info["not_on_or_after"] = not_on_or_after
    # subject_id, entity_id, info, timestamp
    sp.users.add_information_about_person(session_info)
开发者ID:paulftw,项目名称:pysaml2,代码行数:9,代码来源:test_62_vo.py

示例9: test_add_duration_2

def test_add_duration_2():
    #2000-01-12 PT33H   2000-01-13
    t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "PT33H")
    assert t.tm_year == 2000
    assert t.tm_mon == 1
    assert t.tm_mday == 14
    assert t.tm_hour == 9
    assert t.tm_min == 0
    assert t.tm_sec == 0
开发者ID:lvanderree,项目名称:pysaml2-3,代码行数:9,代码来源:test_10_time_util.py

示例10: add_derek_info

def add_derek_info(sp):
    not_on_or_after = str_to_time(in_a_while(days=1))
    session_info = SESSION_INFO_PATTERN.copy()
    session_info["ava"] = {"givenName": ["Derek"], "umuselin": ["deje0001"]}
    session_info["issuer"] = "urn:mace:example.com:saml:idp"
    session_info["name_id"] = nid
    session_info["not_on_or_after"] = not_on_or_after
    # subject_id, entity_id, info, timestamp
    sp.users.add_information_about_person(session_info)
开发者ID:5monkeys,项目名称:pysaml2,代码行数:9,代码来源:test_62_vo.py

示例11: validate_before

def validate_before(not_before, slack):
    if not_before:
        now = time_util.utc_now()
        nbefore = calendar.timegm(time_util.str_to_time(not_before))
        if nbefore > now + slack:
            now_str = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(now))
            raise ToEarly("Can't use response yet: (now=%s + slack=%d) "
                          "<= notbefore=%s" % (now_str, slack, not_before))
    return True
开发者ID:SUNET,项目名称:pysaml2,代码行数:9,代码来源:validate.py

示例12: test_add_duration_1

def test_add_duration_1():
    #2000-01-12T12:13:14Z	P1Y3M5DT7H10M3S	2001-04-17T19:23:17Z    
    t = add_duration(str_to_time("2000-01-12T12:13:14Z"), "P1Y3M5DT7H10M3S")
    assert t.tm_year == 2001
    assert t.tm_mon == 4
    assert t.tm_mday == 17
    assert t.tm_hour == 19
    assert t.tm_min == 23
    assert t.tm_sec == 17
开发者ID:lvanderree,项目名称:pysaml2-3,代码行数:9,代码来源:test_10_time_util.py

示例13: test_set

    def test_set(self):
        not_on_or_after = str_to_time(in_a_while(days=1))
        session_info = SESSION_INFO_PATTERN.copy()
        session_info["ava"] = {"givenName": ["Derek"]}
        self.cache.set(nid[0], "abcd", session_info, not_on_or_after)

        (ava, inactive) = self.cache.get_identity(nid[0])
        assert inactive == []
        assert list(ava.keys()) == ["givenName"]
        assert ava["givenName"] == ["Derek"]
开发者ID:Amli,项目名称:pysaml2,代码行数:10,代码来源:test_32_cache.py

示例14: issue_instant_ok

 def issue_instant_ok(self):
     """ Check that the request was issued at a reasonable time """
     upper = time_util.shift_time(time_util.time_in_a_while(days=1),
                                 self.timeslack).timetuple()
     lower = time_util.shift_time(time_util.time_a_while_ago(days=1),
                                 -self.timeslack).timetuple()
     # print "issue_instant: %s" % self.message.issue_instant
     # print "%s < x < %s" % (lower, upper)
     issued_at = time_util.str_to_time(self.message.issue_instant)
     return issued_at > lower and issued_at < upper
开发者ID:GSA,项目名称:pysaml2,代码行数:10,代码来源:request.py

示例15: validate_on_or_after

def validate_on_or_after(not_on_or_after, slack):
    if not_on_or_after:
        now = time_util.utc_now()
        nooa = calendar.timegm(time_util.str_to_time(not_on_or_after))
        if now > nooa + slack:
            raise Exception("Can't use it, it's too old %d > %d" %
                            (nooa, now))
        return nooa
    else:
        return False
开发者ID:SpamapS,项目名称:pysaml2,代码行数:10,代码来源:validate.py


注:本文中的saml2.time_util.str_to_time函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。