本文整理汇总了Python中requests.Response.headers['Location']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers['Location']方法的具体用法?Python Response.headers['Location']怎么用?Python Response.headers['Location']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.Response
的用法示例。
在下文中一共展示了Response.headers['Location']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_download
# 需要导入模块: from requests import Response [as 别名]
# 或者: from requests.Response import headers['Location'] [as 别名]
def test_check_download(self):
tracker = LostFilmPlugin()
response = Response()
response.status_code = 200
self.assertEqual(tracker.check_download(response), Status.Ok)
response.status_code = 302
response.headers['Location'] = '/'
self.assertEqual(tracker.check_download(response), Status.NotFound)
response.status_code = 500
response.headers['Location'] = '/'
self.assertEqual(tracker.check_download(response), Status.Error)
示例2: test_check_download
# 需要导入模块: from requests import Response [as 别名]
# 或者: from requests.Response import headers['Location'] [as 别名]
def test_check_download(self):
plugin = RutorOrgPlugin()
plugin.init(self.tracker_settings)
response = Response()
response.status_code = 200
response.headers['Content-Type'] = 'application/bittorrent'
self.assertEqual(plugin.check_download(response), Status.Ok)
response.status_code = 302
response.headers['Location'] = '/d.php'
self.assertEqual(plugin.check_download(response), Status.NotFound)
response.status_code = 500
response.headers['Location'] = '/d.php'
self.assertEqual(plugin.check_download(response), Status.Error)
示例3: request
# 需要导入模块: from requests import Response [as 别名]
# 或者: from requests.Response import headers['Location'] [as 别名]
def request(self, method, url, **kwargs):
"""
Returns a Response object that we would expect return from Cosm.
We don't want to actually hit Cosm's API during our tests so instead we
intercept requests and return the responses that we would expect
depending on what arguments we were given.
"""
response = Response()
response.status_code = 200
if url == 'http://api.cosm.com/v2/feeds.json':
response.headers['Location'] = 'http://api.cosm.com/v2/feeds/504'
return response
示例4: send
# 需要导入模块: from requests import Response [as 别名]
# 或者: from requests.Response import headers['Location'] [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'
#.........这里部分代码省略.........