本文整理汇总了Python中calendar.timegm方法的典型用法代码示例。如果您正苦于以下问题:Python calendar.timegm方法的具体用法?Python calendar.timegm怎么用?Python calendar.timegm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar
的用法示例。
在下文中一共展示了calendar.timegm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def encode(self, payload, key, algorithm='HS256', headers=None,
json_encoder=None):
# Check that we get a mapping
if not isinstance(payload, Mapping):
raise TypeError('Expecting a mapping object, as JWT only supports '
'JSON objects as payloads.')
# Payload
for time_claim in ['exp', 'iat', 'nbf']:
# Convert datetime to a intDate value in known time-format claims
if isinstance(payload.get(time_claim), datetime):
payload[time_claim] = timegm(payload[time_claim].utctimetuple())
json_payload = json.dumps(
payload,
separators=(',', ':'),
cls=json_encoder
).encode('utf-8')
return super(PyJWT, self).encode(
json_payload, key, algorithm, headers, json_encoder
)
示例2: utc2timestamp
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def utc2timestamp(human_time):
regex1 = "\d{4}-\d{2}-\d{2}.\d{2}:\d{2}:\d{2}"
match = re.search(regex1, human_time)
if match:
formated = match.group()
else:
return None
strped_time = datetime.strptime(formated, c.time_fmt)
timestamp = timegm(strped_time.utctimetuple())
regex2 = "\d{4}-\d{2}-\d{2}.\d{2}:\d{2}:\d{2}(\.\d+)"
match = re.search(regex2, human_time)
if match:
timestamp += float(match.group(1))
else:
timestamp += float("0.000000")
return timestamp
示例3: format_timestamp
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def format_timestamp(ts):
"""Formats a timestamp in the format used by HTTP.
The argument may be a numeric timestamp as returned by `time.time`,
a time tuple as returned by `time.gmtime`, or a `datetime.datetime`
object.
>>> format_timestamp(1359312200)
'Sun, 27 Jan 2013 18:43:20 GMT'
"""
if isinstance(ts, numbers.Real):
pass
elif isinstance(ts, (tuple, time.struct_time)):
ts = calendar.timegm(ts)
elif isinstance(ts, datetime.datetime):
ts = calendar.timegm(ts.utctimetuple())
else:
raise TypeError("unknown timestamp type: %r" % ts)
return email.utils.formatdate(ts, usegmt=True)
示例4: build_cookie_parameters
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def build_cookie_parameters(self, params):
domain_hash = self._generate_domain_hash()
params._utma = "%s.%s.%s.%s.%s.%s" % (
domain_hash,
self.visitor.unique_id,
calendar.timegm(self.visitor.first_visit_time.timetuple()),
calendar.timegm(self.visitor.previous_visit_time.timetuple()),
calendar.timegm(self.visitor.current_visit_time.timetuple()),
self.visitor.visit_count
)
params._utmb = '%s.%s.10.%s' % (
domain_hash,
self.session.track_count,
calendar.timegm(self.session.start_time.timetuple()),
)
params._utmc = domain_hash
cookies = []
cookies.append('__utma=%s;' % params._utma)
if params._utmz:
cookies.append('__utmz=%s;' % params._utmz)
if params._utmv:
cookies.append('__utmv=%s;' % params._utmv)
params.utmcc = '+'.join(cookies)
return params
示例5: generate_jws_dict
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def generate_jws_dict(self, **kwargs):
client_key = kwargs.get('client_key', oidc_rp_settings.CLIENT_ID)
now_dt = dt.datetime.utcnow()
expiration_dt = kwargs.get('expiration_dt', (now_dt + dt.timedelta(seconds=30)))
issue_dt = kwargs.get('issue_dt', now_dt)
nonce = kwargs.get('nonce', 'nonce')
ret = kwargs
ret.update({
'iss': kwargs.get('iss', oidc_rp_settings.PROVIDER_ENDPOINT),
'nonce': nonce,
'aud': kwargs.get('aud', client_key),
'azp': kwargs.get('azp', client_key),
'exp': timegm(expiration_dt.utctimetuple()),
'iat': timegm(issue_dt.utctimetuple()),
'nbf': timegm(kwargs.get('nbf', now_dt).utctimetuple()),
'sub': '1234',
})
return ret
示例6: generate_jws_dict
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def generate_jws_dict(self, **kwargs):
client_key = kwargs.get('client_key', oidc_rp_settings.CLIENT_ID)
now_dt = dt.datetime.utcnow()
expiration_dt = kwargs.get('expiration_dt', (now_dt + dt.timedelta(seconds=30)))
issue_dt = kwargs.get('issue_dt', now_dt)
nonce = kwargs.get('nonce', 'nonce')
return {
'iss': kwargs.get('iss', oidc_rp_settings.PROVIDER_ENDPOINT),
'nonce': nonce,
'aud': kwargs.get('aud', client_key),
'azp': kwargs.get('azp', client_key),
'exp': timegm(expiration_dt.utctimetuple()),
'iat': timegm(issue_dt.utctimetuple()),
'nbf': timegm(kwargs.get('nbf', now_dt).utctimetuple()),
'sub': '1234',
}
示例7: __init__
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def __init__(
self,
log_group_name,
filter_pattern=DEFAULT_FILTER_PATTERN,
thread_count=0,
**kwargs
):
super().__init__('logs', **kwargs)
self.log_group_name = log_group_name
self.paginator_kwargs = {}
if filter_pattern is not None:
self.paginator_kwargs['filterPattern'] = filter_pattern
self.thread_count = thread_count
self.start_ms = timegm(self.start_time.utctimetuple()) * 1000
self.end_ms = timegm(self.end_time.utctimetuple()) * 1000
示例8: test_class_ops_pytz
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def test_class_ops_pytz(self):
def compare(x, y):
assert (int(Timestamp(x).value / 1e9) ==
int(Timestamp(y).value / 1e9))
compare(Timestamp.now(), datetime.now())
compare(Timestamp.now('UTC'), datetime.now(timezone('UTC')))
compare(Timestamp.utcnow(), datetime.utcnow())
compare(Timestamp.today(), datetime.today())
current_time = calendar.timegm(datetime.now().utctimetuple())
compare(Timestamp.utcfromtimestamp(current_time),
datetime.utcfromtimestamp(current_time))
compare(Timestamp.fromtimestamp(current_time),
datetime.fromtimestamp(current_time))
date_component = datetime.utcnow()
time_component = (date_component + timedelta(minutes=10)).time()
compare(Timestamp.combine(date_component, time_component),
datetime.combine(date_component, time_component))
示例9: test_class_ops_dateutil
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def test_class_ops_dateutil(self):
def compare(x, y):
assert (int(np.round(Timestamp(x).value / 1e9)) ==
int(np.round(Timestamp(y).value / 1e9)))
compare(Timestamp.now(), datetime.now())
compare(Timestamp.now('UTC'), datetime.now(tzutc()))
compare(Timestamp.utcnow(), datetime.utcnow())
compare(Timestamp.today(), datetime.today())
current_time = calendar.timegm(datetime.now().utctimetuple())
compare(Timestamp.utcfromtimestamp(current_time),
datetime.utcfromtimestamp(current_time))
compare(Timestamp.fromtimestamp(current_time),
datetime.fromtimestamp(current_time))
date_component = datetime.utcnow()
time_component = (date_component + timedelta(minutes=10)).time()
compare(Timestamp.combine(date_component, time_component),
datetime.combine(date_component, time_component))
示例10: IsPacificDST
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def IsPacificDST(now):
"""Helper for PacificTime to decide whether now is Pacific DST (PDT).
Args:
now: A pseudo-posix timestamp giving current time in PST.
Returns:
True if now falls within the range of DST, False otherwise.
"""
pst = time.gmtime(now)
year = pst[0]
assert year >= 2007
begin = calendar.timegm((year, 3, 8, 2, 0, 0, 0, 0, 0))
while time.gmtime(begin).tm_wday != SUNDAY:
begin += DAY
end = calendar.timegm((year, 11, 1, 2, 0, 0, 0, 0, 0))
while time.gmtime(end).tm_wday != SUNDAY:
end += DAY
return begin <= now < end
示例11: __toLocal
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def __toLocal(cls, value):
#Convert current time to local.
if value.tzinfo is None:
#If meter is not use time zone.
return value
timestamp = calendar.timegm(value.utctimetuple())
local_dt = datetime.datetime.fromtimestamp(timestamp)
assert value.resolution >= datetime.timedelta(microseconds=1)
return local_dt.replace(microsecond=value.microsecond)
示例12: to_unixtime
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def to_unixtime(time_string, format_string):
with _STRPTIME_LOCK:
return int(calendar.timegm(time.strptime(str(time_string), format_string)))
示例13: page
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def page(self):
changemsg = []
if cherrypy.session.id != cherrypy.session.originalid:
if cherrypy.session.originalid is None:
changemsg.append(
'Created new session because no session id was given.')
if cherrypy.session.missing:
changemsg.append(
'Created new session due to missing '
'(expired or malicious) session.')
if cherrypy.session.regenerated:
changemsg.append('Application generated a new session.')
try:
expires = cherrypy.response.cookie['session_id']['expires']
except KeyError:
expires = ''
return page % {
'sessionid': cherrypy.session.id,
'changemsg': '<br>'.join(changemsg),
'respcookie': cherrypy.response.cookie.output(),
'reqcookie': cherrypy.request.cookie.output(),
'sessiondata': list(cherrypy.session.items()),
'servertime': (
datetime.utcnow().strftime('%Y/%m/%d %H:%M') + ' UTC'
),
'serverunixtime': calendar.timegm(datetime.utcnow().timetuple()),
'cpversion': cherrypy.__version__,
'pyversion': sys.version,
'expires': expires,
}
示例14: step
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def step(self, amt=1):
z = calendar.timegm(time.gmtime(time.time()))
for i in range(32):
color = self.palette((z & (1 << i)) > 0)
if self._reverse:
i = 31 - i
start = (self._bitSpace + self._bitWidth) * i
self.layout.fill(color, start, start + self._bitWidth)
示例15: _epoch
# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import timegm [as 别名]
def _epoch(dt_tuple):
return calendar.timegm(dt_tuple.timetuple())