我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug._internal._date_to_unix()。
def serialize(self, expires=None): """Serialize the secure cookie into a string. If expires is provided, the session will be automatically invalidated after expiration when you unseralize it. This provides better protection against session cookie theft. :param expires: an optional expiration date for the cookie (a :class:`datetime.datetime` object) """ if self.secret_key is None: raise RuntimeError('no secret key defined') if expires: self['_expires'] = _date_to_unix(expires) result = [] mac = hmac(self.secret_key, None, self.hash_method) for key, value in sorted(self.items()): result.append(('%s=%s' % ( url_quote_plus(key), self.quote(value).decode('ascii') )).encode('ascii')) mac.update(b'|' + result[-1]) return b'?'.join([ base64.b64encode(mac.digest()).strip(), b'&'.join(result) ])
def test_date_to_unix(self): assert internal._date_to_unix(datetime(1970, 1, 1)) == 0 assert internal._date_to_unix(datetime(1970, 1, 1, 1, 0, 0)) == 3600 assert internal._date_to_unix(datetime(1970, 1, 1, 1, 1, 1)) == 3661 x = datetime(2010, 2, 15, 16, 15, 39) assert internal._date_to_unix(x) == 1266250539