本文整理汇总了Python中requests.Response.headers['Last-Modified']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers['Last-Modified']方法的具体用法?Python Response.headers['Last-Modified']怎么用?Python Response.headers['Last-Modified']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.Response
的用法示例。
在下文中一共展示了Response.headers['Last-Modified']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from requests import Response [as 别名]
# 或者: from requests.Response import headers['Last-Modified'] [as 别名]
def send(self, request, stream=False, verify=None, cert=None, proxies=None,
timeout=None):
"""issue request"""
data = url_unquote(request.url[len('data:'):])
if ',' not in data:
raise InvalidURL('data URL missing comma')
mime, content = data.split(',', 1)
content = content.strip()
base64 = False
charset = None
while ';' in mime:
mime, encoding_spec = mime.rsplit(';', 1)
encoding_spec = encoding_spec.strip()
if encoding_spec == 'base64':
base64 = True
elif not encoding_spec.startswith('charset='):
raise InvalidURL(
'unrecognized encoding parameter: %r' % encoding_spec
)
else:
charset = encoding_spec[len('charset='):]
try:
if base64:
content = a2b_base64(content)
content_type = mime.strip()
if charset:
content_type += "; charset=" + charset
response = Response()
response.url = request.url
response.headers['Date'] = formatdate(timeval=None, localtime=True)
if request.method in ('GET', 'HEAD'):
response.status_code = 200
response.headers['Content-Length'] = len(content)
response.headers['Last-Modified'] = formatdate()
response.headers['Content-Type'] = content_type
if charset:
response.encoding = charset
response.raw = StringIO(str(content))
else:
response.status_code = 405
response.headers['Status'] = '405 Method Not Allowed'
except Exception:
response.status_code = 500
response.headers['Status'] = '500 Internal Server Error'
response.raw = StringIO(format_exc())
# context
response.request = request
response.connection = self
# hooks
response = dispatch_hook('response', request.hooks, response)
# streaming
if not stream:
response.content
return response
示例2: send
# 需要导入模块: from requests import Response [as 别名]
# 或者: from requests.Response import headers['Last-Modified'] [as 别名]
def send(
self, request, stream=False, verify=None, cert=None, proxies=None,
timeout=None
):
"""issue request"""
fname = url_unquote(request.url[len('file://'):])
if not fname:
raise InvalidURL('missing file name')
if '/' not in fname:
raise InvalidURL(
'hostname without filename (perhaps missing a /?)'
)
host, fname = fname.split('/', 1)
fname = self.resolve_host(host, fname)
response = Response()
response.url = request.url
response.headers['Date'] = formatdate(timeval=None, localtime=True)
try:
if request.method in ('GET', 'HEAD'):
statdata = stat(fname)
etag = '"%s/%s/%s' \
% (statdata.st_dev, statdata.st_ino, statdata.st_mtime)
if S_ISLNK(statdata.st_mode):
# handle relative symlinks!
target_file = abspath(readlink(fname))
response.status_code = 302
response.headers['Status'] = '302 Found'
response.headers['Location'] = \
url_quote('file://' + target_file)
elif S_ISDIR(statdata.st_mode):
response.status_code = 200
response.headers['Status'] = '200 Ok'
body = \
"""<html><head><title>%s</title></head><body><ul>""" \
% fname
for subfname in sorted(listdir(fname)):
body += '<li><a href="file://' + \
url_quote(subfname) + '">' + \
html_escape(fname) + '</a></li>'
body += '</body></html>'
response.headers['ETag'] = 'W/' + etag
response.raw = StringIO(body)
elif S_ISREG(statdata.st_mode):
response.status_code = 200
response.headers['Content-Length'] = statdata.st_size
response.headers['Last-Modified'] = formatdate(
timeval=statdata.st_mtime,
localtime=True
)
mt, enc = guess_mime_type(request.url, strict=False)
if mt is None:
mt = 'application/octet-stream'
if enc is not None:
response.headers['Content-Encoding'] = enc
response.headers['Content-Type'] = mt
response.headers['ETag'] = etag
if request.method == 'GET':
response.raw = open(fname, 'r')
else:
response.status_code = 500
response.headers['Status'] = '500 Internal Server Error'
elif request.method == 'PUT':
open(fname, 'w').write(request.body) # FIXME: Is this right?
response.status_code = 200
response.headers['Status'] = '200 Ok'
elif request.method == 'POST':
if exists(fname): # FIXME: Is this right?
response.status_code = 409
response.headers['Status'] = '409 Conflict'
else:
open(fname, 'w').write(request.body)
elif request.method == 'DELETE':
unlink(fname)
response.status_code = 200
response.headers['Status'] = '200 Ok'
else:
response.status_code = 405
response.headers['Status'] = '405 Method Not Allowed'
except OSError as e:
if e.errno == errno.ENOENT:
if request.method == 'DELETE':
response.status_code = 410
response.headers['Status'] = '410 Gone'
else:
response.status_code = 404
response.headers['Status'] = '404 Not Found'
elif e.errno == errno.EISDIR:
response.status_code = 405
response.headers['Status'] = '405 Method Not Allowed'
response.raw = StringIO('Cannot %r a directory...'
% request.method)
elif e.errno == errno.EACCES:
response.status_code = 403
response.headers['Status'] = '403 Forbidden'
else:
response.status_code = 500
response.headers['Status'] = '500 Internal Server Error'
#.........这里部分代码省略.........