本文整理汇总了Python中pyasn1.type.useful.GeneralizedTime方法的典型用法代码示例。如果您正苦于以下问题:Python useful.GeneralizedTime方法的具体用法?Python useful.GeneralizedTime怎么用?Python useful.GeneralizedTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasn1.type.useful
的用法示例。
在下文中一共展示了useful.GeneralizedTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updatetimestampsserverticket
# 需要导入模块: from pyasn1.type import useful [as 别名]
# 或者: from pyasn1.type.useful import GeneralizedTime [as 别名]
def updatetimestampsserverticket(ticket, authtime=None, starttime=None, endtime=None, renewtiltime=None):
now = datetime.datetime.now()
# yes, this regex isn't perfect, but neither are you
if not authtime or not re.match(r'^20\d\d[0-1]\d[0-3]\d[0-2]\d[0-6]\d[0-6]\dZ$', authtime):
authtime = now.strftime('%Y%m%d%H%M%SZ')
if not starttime or not re.match(r'^20\d\d[0-1]\d[0-3]\d[0-2]\d[0-6]\d[0-6]\dZ$', starttime):
starttime = now.strftime('%Y%m%d%H%M%SZ')
if not endtime or not re.match(r'^20\d\d[0-1]\d[0-3]\d[0-2]\d[0-6]\d[0-6]\dZ$', endtime):
endtime = (now + datetime.timedelta(hours=10)).strftime('%Y%m%d%H%M%SZ')
if not renewtiltime or not re.match(r'^20\d\d[0-1]\d[0-3]\d[0-2]\d[0-6]\d[0-6]\dZ$', renewtiltime):
renewtiltime = (now + datetime.timedelta(hours=24)).strftime('%Y%m%d%H%M%SZ')
# Dear, pyasn1
# Why do I have to use a _ method to update a value. You expect me to write
# an entire spec, I don't want to. Because of this I HATE YOU. Please
# DIAF
# -Tim
# P.S. Suck it
ticket.getComponentByPosition(5)._value = useful.GeneralizedTime(authtime)
ticket.getComponentByPosition(6)._value = useful.GeneralizedTime(starttime)
ticket.getComponentByPosition(7)._value = useful.GeneralizedTime(endtime)
ticket.getComponentByPosition(8)._value = useful.GeneralizedTime(renewtiltime)
return ticket
示例2: extract_dates
# 需要导入模块: from pyasn1.type import useful [as 别名]
# 或者: from pyasn1.type.useful import GeneralizedTime [as 别名]
def extract_dates(self):
validity = self.tbs.getComponentByName('validity')
not_before = validity.getComponentByName('notBefore')
not_before = str(not_before.getComponent())
not_after = validity.getComponentByName('notAfter')
not_after = str(not_after.getComponent())
if isinstance(not_before, GeneralizedTime):
not_before = datetime.strptime(not_before, '%Y%m%d%H%M%SZ')
else:
not_before = datetime.strptime(not_before, '%y%m%d%H%M%SZ')
if isinstance(not_after, GeneralizedTime):
not_after = datetime.strptime(not_after, '%Y%m%d%H%M%SZ')
else:
not_after = datetime.strptime(not_after, '%y%m%d%H%M%SZ')
return not_before, not_after
示例3: walk
# 需要导入模块: from pyasn1.type import useful [as 别名]
# 或者: from pyasn1.type.useful import GeneralizedTime [as 别名]
def walk(t):
if type(t) == str:
print('String: %s' % t)
else:
print('Length: %i' % len(t))
for i in range(len(t)):
print('---%i---' % i)
print(t[i])
#Sequence().setComponentByPosition(0, BitString("'01000000101000010000000000000000'B")).setComponentByPosition(1, Sequence().setComponentByPosition(0, Integer(23)).setComponentByPosition(1, OctetString(hexValue='dfa121845d72f43271bbb33cd9e69443'))).setComponentByPosition(2, GeneralString('MEDIN.LOCAL')).setComponentByPosition(3, Sequence().setComponentByPosition(0, Integer(1)).setComponentByPosition(1, Sequence().setComponentByPosition(0, GeneralString('tm')))).setComponentByPosition(4, Sequence().setComponentByPosition(0, Integer(1)).setComponentByPosition(1, OctetString(''))).setComponentByPosition(5, GeneralizedTime('20140403172846Z')).setComponentByPosition(6, GeneralizedTime('20140403173119Z'))