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


Python calendar.timegm方法代碼示例

本文整理匯總了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
        ) 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:24,代碼來源:api_jwt.py

示例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 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:20,代碼來源:ta_helper.py

示例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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:httputil.py

示例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 
開發者ID:jmarth,項目名稱:plugin.video.kmediatorrent,代碼行數:27,代碼來源:requests.py

示例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 
開發者ID:impak-finance,項目名稱:django-oidc-rp,代碼行數:20,代碼來源:test_backends.py

示例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',
        } 
開發者ID:impak-finance,項目名稱:django-oidc-rp,代碼行數:18,代碼來源:test_middleware.py

示例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 
開發者ID:obsrvbl,項目名稱:flowlogs-reader,代碼行數:21,代碼來源:flowlogs_reader.py

示例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)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_timestamp.py

示例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)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_timestamp.py

示例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 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:23,代碼來源:appcfg.py

示例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) 
開發者ID:Gurux,項目名稱:Gurux.DLMS.Python,代碼行數:11,代碼來源:GXDateTime.py

示例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))) 
開發者ID:jumpserver,項目名稱:jumpserver-python-sdk,代碼行數:5,代碼來源:utils.py

示例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,
        } 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:34,代碼來源:sessiondemo.py

示例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) 
開發者ID:ManiacalLabs,項目名稱:BiblioPixelAnimations,代碼行數:12,代碼來源:BinaryEpochClock.py

示例15: _epoch

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import timegm [as 別名]
def _epoch(dt_tuple):
    return calendar.timegm(dt_tuple.timetuple()) 
開發者ID:chubin,項目名稱:rate.sx,代碼行數:4,代碼來源:interval.py


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