本文整理汇总了Python中werkzeug.http.parse_date函数的典型用法代码示例。如果您正苦于以下问题:Python parse_date函数的具体用法?Python parse_date怎么用?Python parse_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: finance_information
def finance_information(self):
return FinanceInformation(
balance=self.user_data.finance_balance,
transactions=((parse_date(t.valid_on), t.amount) for t in
self.user_data.finance_history),
last_update=parse_date(self.user_data.last_finance_update)
)
开发者ID:agdsn,项目名称:sipa,代码行数:7,代码来源:user.py
示例2: test_parse_date_overflows
def test_parse_date_overflows(self):
assert http.parse_date(" Sun 02 Feb 1343 08:49:37 GMT") == datetime(
1343, 2, 2, 8, 49, 37
)
assert http.parse_date("Thu, 01 Jan 1970 00:00:00 GMT") == datetime(
1970, 1, 1, 0, 0
)
assert http.parse_date("Thu, 33 Jan 1970 00:00:00 GMT") is None
开发者ID:pallets,项目名称:werkzeug,代码行数:8,代码来源:test_http.py
示例3: test_parse_date
def test_parse_date(self):
assert http.parse_date("Sun, 06 Nov 1994 08:49:37 GMT ") == datetime(
1994, 11, 6, 8, 49, 37
)
assert http.parse_date("Sunday, 06-Nov-94 08:49:37 GMT") == datetime(
1994, 11, 6, 8, 49, 37
)
assert http.parse_date(" Sun Nov 6 08:49:37 1994") == datetime(
1994, 11, 6, 8, 49, 37
)
assert http.parse_date("foo") is None
开发者ID:pallets,项目名称:werkzeug,代码行数:11,代码来源:test_http.py
示例4: get_info
def get_info(self, request, ident, base_uri):
r = LorisResponse()
r.set_acao(request, self.cors_regex)
try:
info, last_mod = self._get_info(ident,request,base_uri)
except ResolverException as re:
return NotFoundResponse(re.message)
except ImageInfoException as ie:
return ServerSideErrorResponse(ie.message)
except IOError as e:
# 500
msg = '%s \n(This is likely a permissions problem)' % (str(e),)
return ServerSideErrorResponse(msg)
else:
ims_hdr = request.headers.get('If-Modified-Since')
ims = parse_date(ims_hdr)
last_mod = parse_date(http_date(last_mod)) # see note under get_img
if ims and ims >= last_mod:
logger.debug('Sent 304 for %s ' % (ident,))
r.status_code = 304
else:
if last_mod:
r.last_modified = last_mod
# r.automatically_set_content_length
callback = request.args.get('callback', None)
if callback:
r.mimetype = 'application/javascript'
r.data = '%s(%s);' % (callback, info.to_json())
else:
if request.headers.get('accept') == 'application/ld+json':
r.content_type = 'application/ld+json'
else:
r.content_type = 'application/json'
l = '<http://iiif.io/api/image/2/context.json>;rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json"'
r.headers['Link'] = '%s,%s' % (r.headers['Link'], l)
# If interpolation is not allowed, we have to remove this
# value from info.json - but only if exists (cached ImageInfo might miss this)
if self.max_size_above_full <= 100:
try:
info.profile[1]['supports'].remove('sizeAboveFull')
except ValueError:
pass
r.data = info.to_json()
finally:
return r
开发者ID:kebe,项目名称:loris,代码行数:48,代码来源:webapp.py
示例5: traffic_history
def traffic_history(self):
return [{
'day': parse_date(entry.timestamp).weekday(),
'input': to_kib(entry.ingress),
'output': to_kib(entry.egress),
'throughput': to_kib(entry.ingress) + to_kib(entry.egress),
} for entry in self.user_data.traffic_history]
开发者ID:agdsn,项目名称:sipa,代码行数:7,代码来源:user.py
示例6: test_session_expiration
def test_session_expiration(self):
permanent = True
app = flask.Flask(__name__)
app.secret_key = "testkey"
@app.route("/")
def index():
flask.session["test"] = 42
flask.session.permanent = permanent
return ""
@app.route("/test")
def test():
return unicode(flask.session.permanent)
client = app.test_client()
rv = client.get("/")
self.assert_("set-cookie" in rv.headers)
match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])
expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime
self.assert_equal(expires.year, expected.year)
self.assert_equal(expires.month, expected.month)
self.assert_equal(expires.day, expected.day)
rv = client.get("/test")
self.assert_equal(rv.data, "True")
permanent = False
rv = app.test_client().get("/")
self.assert_("set-cookie" in rv.headers)
match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])
self.assert_(match is None)
开发者ID:RONNCC,项目名称:Heroku_sghose,代码行数:33,代码来源:basic.py
示例7: _get_retry_after
def _get_retry_after(self):
value = self.headers.get('retry-after')
if value is None:
return
elif value.isdigit():
return datetime.utcnow() + timedelta(seconds=int(value))
return parse_date(value)
开发者ID:danaspiegel,项目名称:softball_stat_manager,代码行数:7,代码来源:wrappers.py
示例8: test_session_expiration
def test_session_expiration():
permanent = True
app = flask.Flask(__name__)
app.secret_key = 'testkey'
@app.route('/')
def index():
flask.session['test'] = 42
flask.session.permanent = permanent
return ''
@app.route('/test')
def test():
return text_type(flask.session.permanent)
client = app.test_client()
rv = client.get('/')
assert 'set-cookie' in rv.headers
match = re.search(r'\bexpires=([^;]+)(?i)', rv.headers['set-cookie'])
expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime
assert expires.year == expected.year
assert expires.month == expected.month
assert expires.day == expected.day
rv = client.get('/test')
assert rv.data == b'True'
permanent = False
rv = app.test_client().get('/')
assert 'set-cookie' in rv.headers
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
assert match is None
开发者ID:LianYun,项目名称:flask,代码行数:33,代码来源:test_basic.py
示例9: test_session_expiration
def test_session_expiration(self):
permanent = True
app = flask.Flask(__name__)
app.secret_key = 'testkey'
@app.route('/')
def index():
flask.session['test'] = 42
flask.session.permanent = permanent
return ''
@app.route('/test')
def test():
return unicode(flask.session.permanent)
client = app.test_client()
rv = client.get('/')
self.assert_('set-cookie' in rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime
self.assert_equal(expires.year, expected.year)
self.assert_equal(expires.month, expected.month)
self.assert_equal(expires.day, expected.day)
rv = client.get('/test')
self.assert_equal(rv.data, 'True')
permanent = False
rv = app.test_client().get('/')
self.assert_('set-cookie' in rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
self.assert_(match is None)
开发者ID:wouterhassing,项目名称:flask,代码行数:32,代码来源:basic.py
示例10: test_session_expiration
def test_session_expiration():
permanent = True
app = flask.Flask(__name__)
app.secret_key = "testkey"
@app.route("/")
def index():
flask.session["test"] = 42
flask.session.permanent = permanent
return ""
@app.route("/test")
def test():
return text_type(flask.session.permanent)
client = app.test_client()
rv = client.get("/")
assert "set-cookie" in rv.headers
match = re.search(r"\bexpires=([^;]+)(?i)", rv.headers["set-cookie"])
expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime
assert expires.year == expected.year
assert expires.month == expected.month
assert expires.day == expected.day
rv = client.get("/test")
assert rv.data == b"True"
permanent = False
rv = app.test_client().get("/")
assert "set-cookie" in rv.headers
match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])
assert match is None
开发者ID:ehamiter,项目名称:flask,代码行数:33,代码来源:test_basic.py
示例11: check_modified
def check_modified(self, file_path, environ):
if environ.get('HTTP_IF_MODIFIED_SINCE'):
date1 = parse_date(environ['HTTP_IF_MODIFIED_SINCE'])
date2 = datetime.datetime.utcfromtimestamp(os.path.getmtime(file_path)).replace(microsecond=0)
if date1 != date2:
try:
os.utime(file_path, None)
except:
pass
开发者ID:jam-py,项目名称:jam-py,代码行数:9,代码来源:wsgi.py
示例12: get_ff_cache
def get_ff_cache(profile_dir, store_body=False):
cache_dir = os.path.join(profile_dir, "Cache")
if not os.path.isdir(cache_dir):
return [] # Firefox updated the cache dir structure since our study
cache_map = os.path.join(cache_dir, "_CACHE_MAP_")
cache_dump = os.path.join(BASE_TMP_DIR, append_timestamp("cache") +
rand_str())
create_dir(cache_dump)
subprocess.call([PERL_PATH, CACHE_PERL_SCRIPT, cache_map, "--recover=" +
cache_dump])
cache_items = []
db_items = ("Etag", "Request String", "Expires", "Cache-Control")
for fname in glob(os.path.join(cache_dump, "*_metadata")):
item = {}
try:
with open(fname) as f:
metadata = f.read()
item = parse_metadata(metadata)
for db_item in db_items:
if db_item not in item:
item[db_item] = ""
# If a response includes both an Expires header and a max-age
# directive, the max-age directive overrides the Expires header
# (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)
expiry_delta_sec = 0
if "Expires" in item:
# parse expiry date
expiry = parse_date(item["Expires"])
if expiry:
expiry_delta = expiry - datetime.now()
expiry_delta_sec = expiry_delta.total_seconds()
if "Cache-Control:" in item:
# parse max-age directive
cache_directives =\
parse_cache_control_header(item["Cache-Control"],
cls=ResponseCacheControl)
if "max-age" in cache_directives:
expiry_delta_sec = cache_directives["max-age"]
if expiry_delta_sec < DELTA_MONTH:
continue
item["Expiry-Delta"] = expiry_delta_sec
with open(fname[:-9]) as f:
data = f.read()
item["Body"] = data if store_body else "" # store as BLOB
item["Hash"] = hash_text(base64.b64encode(data))
except IOError as exc:
print "Error processing cache: %s: %s" % (exc,
traceback.format_exc())
cache_items.append(item)
if os.path.isdir(cache_dump):
shutil.rmtree(cache_dump)
return cache_items
开发者ID:4sp1r3,项目名称:TheWebNeverForgets,代码行数:55,代码来源:cache.py
示例13: object_hook
def object_hook(obj):
if len(obj) != 1:
return obj
the_key, the_value = obj.iteritems().next()
if the_key == ' t':
return tuple(the_value)
elif the_key == ' m':
return Markup(the_value)
elif the_key == ' d':
return parse_date(the_value)
return obj
开发者ID:showlovel,项目名称:flask,代码行数:11,代码来源:sessions.py
示例14: __call__
def __call__(self, environ, start_response):
"""Respond to a request when called in the usual WSGI way."""
if environ['REQUEST_METHOD'] not in ('GET', 'HEAD'):
headers = [('Allow', 'GET, HEAD')]
return self.method_not_allowed(environ, start_response, headers)
path_info = environ.get('PATH_INFO', '')
full_path = self._full_path(path_info)
if not self._is_under_root(full_path):
return self.not_found(environ, start_response)
if path.isdir(full_path):
if full_path[-1] != '/' or full_path == self.root:
location = util.request_uri(environ, include_query=False) + '/'
if environ.get('QUERY_STRING'):
location += '?' + environ.get('QUERY_STRING')
headers = [('Location', location)]
return self.moved_permanently(environ, start_response, headers)
else:
full_path = self._full_path(path_info + self.index_file)
content_type = self._guess_type(full_path)
try:
etag, last_modified = self._conditions(full_path, environ)
headers = [('Date', http_date(time.time())),
('Last-Modified', last_modified),
('ETag', etag)]
if_modified = environ.get('HTTP_IF_MODIFIED_SINCE')
if if_modified and (parse_date(if_modified)
>= parse_date(last_modified)):
return self.not_modified(environ, start_response, headers)
if_none = environ.get('HTTP_IF_NONE_MATCH')
if if_none and (if_none == '*' or etag in if_none):
return self.not_modified(environ, start_response, headers)
file_like = self._file_like(full_path)
headers.append(('Content-Type', content_type))
start_response("200 OK", headers)
if environ['REQUEST_METHOD'] == 'GET':
return self._body(full_path, environ, file_like)
else:
return ['']
except (IOError, OSError) as e:
print(e)
return self.not_found(environ, start_response)
开发者ID:pydanny,项目名称:staticserve,代码行数:41,代码来源:static.py
示例15: get_info
def get_info(self, request, ident, base_uri):
r = LorisResponse()
try:
info, last_mod = self._get_info(ident,request,base_uri)
except ResolverException as re:
return NotFoundResponse(re.message)
except ImageInfoException as ie:
return ServerSideErrorResponse(ie.message)
except IOError as e:
# 500
msg = '%s \n(This is likely a permissions problem)' % (str(e),)
return ServerSideErrorResponse(msg)
else:
ims_hdr = request.headers.get('If-Modified-Since')
ims = parse_date(ims_hdr)
last_mod = parse_date(http_date(last_mod)) # see note under get_img
if ims and ims >= last_mod:
logger.debug('Sent 304 for %s ' % (ident,))
r.status_code = 304
else:
if last_mod:
r.last_modified = last_mod
# r.automatically_set_content_length
callback = request.args.get('callback', None)
if callback:
r.mimetype = 'application/javascript'
r.data = '%s(%s);' % (callback, info.to_json())
else:
if request.headers.get('accept') == 'application/ld+json':
r.content_type = 'application/ld+json'
else:
r.content_type = 'application/json'
l = '<http://iiif.io/api/image/2/context.json>;rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json"'
r.headers['Link'] = '%s,%s' % (r.headers['Link'], l)
r.data = info.to_json()
finally:
return r
开发者ID:bodleian,项目名称:buildout.loris,代码行数:40,代码来源:webapp_2.0.0-beta1.py
示例16: object_hook
def object_hook(obj):
if len(obj) != 1:
return obj
the_key, the_value = next(iteritems(obj))
if the_key == ' t':
return tuple(the_value)
elif the_key == ' u':
return uuid.UUID(the_value)
elif the_key == ' m':
return Markup(the_value)
elif the_key == ' d':
return parse_date(the_value)
return obj
开发者ID:Contextualist,项目名称:Quip4AHA-GAE-legacy,代码行数:13,代码来源:sessions.py
示例17: get_info
def get_info(self, request, ident):
r = LorisResponse()
if self.enable_cors:
if self.cors_whitelist[0] == "*":
r.headers['Access-Control-Allow-Origin'] = "*"
elif request.headers.get("origin") in self.cors_whitelist:
r.headers['Access-Control-Allow-Origin'] = request.headers.get('origin')
try:
info, last_mod = self._get_info(ident,request)
except (ImageInfoException,resolver.ResolverException) as e:
r.response = e
r.status_code = e.http_status
r.mimetype = 'text/plain'
else:
ims_hdr = request.headers.get('If-Modified-Since')
ims = parse_date(ims_hdr)
last_mod = parse_date(http_date(last_mod)) # see note under get_img
if ims and ims >= last_mod:
logger.debug('Sent 304 for %s ' % (ident,))
r.status_code = 304
else:
if last_mod:
r.last_modified = last_mod
r.automatically_set_content_length
# r.headers['Cache-control'] = 'public'
callback = request.args.get('callback', None)
if callback:
r.mimetype = 'application/javascript'
r.data = '%s(%s);' % (callback, info.to_json())
else:
r.content_type = 'application/json'
r.data = info.to_json()
finally:
return r
开发者ID:bodleian,项目名称:buildout.loris,代码行数:39,代码来源:webapp_1.2.3.py
示例18: test_setting_headers
def test_setting_headers(self):
"""
Making a request for pixel.gif should set the Set-Cookie, P3P,
X-Uri-Query, and X-User-Agent headers
"""
response = self.client.get('/pixel.gif',
environ_base={'HTTP_USER_AGENT': 'User Agent'})
# parse_cookie discards the expires portion, which we need to check;
# split the cookie manually
aguid_cookie = self.get_cookie(response, 'aguid').split('; ')
aguid, domain, expires, path = aguid_cookie
# aguid portion should be in the form "aguid=uuid";
# Split on '=' and parse the second part as a uuid
# to check if it is valid
uuid.UUID(aguid.split('=')[1])
self.assertTrue(domain.endswith('=.localhost'))
# These two datetimes are not guaranteed to be exactly equal;
# if we check the date portion (year, month, day), we can be
# reasonably certain that the expiration is set correctly
expiration = parse_date(expires.split('=')[1])
expected_expiration = datetime.utcnow() + timedelta(days=365)
self.assertEqual(expiration.date(), expected_expiration.date())
self.assertEqual(response.headers['P3P'], 'CP="ALL DSP COR CURa IND PHY UNR"')
# Ensure header exists
self.assertEqual(response.headers['X-User-Agent'], 'User+Agent')
self.assertTrue(aguid in response.headers['X-Uri-Query'])
# If myguid is not provided or is invalid, we should not include
# it in the header
for myguid in ['',
'invalid_myguid']:
self.client.set_cookie('localhost', 'myguid',
myguid)
response = self.client.get('/pixel.gif')
self.assertFalse('myguid=' in response.headers['X-Uri-Query'])
myguid = '1234567890abcdef' * 2
self.client.set_cookie('localhost', 'myguid',
myguid)
response = self.client.get('/pixel.gif')
self.assertTrue('='.join(['myguid',myguid]) in
response.headers['X-Uri-Query'])
开发者ID:DirectEmployers,项目名称:MyJobs-pixel,代码行数:50,代码来源:pixel_tests.py
示例19: sync_tweets
def sync_tweets(developer):
"""Finds new tweets for the given developer"""
logger.info('Checking tweets of @%s', developer.twitter_name)
tweets = get_tweets(developer.twitter_name)
for tweet in tweets:
hidden = bool(tweet.get('in_reply_to_user_id'))
msg = Message.query.filter_by(
source='twitter', reference_id=tweet['id_str']).first()
if msg is not None:
continue
logger.info('Found new tweet #%s' % tweet['id_str'])
msg = Message(developer, tweet['text'], 'twitter',
parse_date(tweet['created_at']), tweet['id_str'],
hidden)
db.session.add(msg)
开发者ID:Mondego,项目名称:pyreco,代码行数:15,代码来源:allPythonContent.py
示例20: object_hook
def object_hook(obj):
if len(obj) != 1:
return obj
the_key, the_value = next(iteritems(obj))
if the_key == " t":
return tuple(the_value)
elif the_key == " u":
return uuid.UUID(the_value)
elif the_key == " b":
return b64decode(the_value)
elif the_key == " m":
return Markup(the_value)
elif the_key == " d":
return parse_date(the_value)
return obj
开发者ID:42only,项目名称:flask,代码行数:15,代码来源:sessions.py
注:本文中的werkzeug.http.parse_date函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论