本文整理汇总了Python中wpull.protocol.http.request.Response.fields['Content-Type']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.fields['Content-Type']方法的具体用法?Python Response.fields['Content-Type']怎么用?Python Response.fields['Content-Type']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wpull.protocol.http.request.Response
的用法示例。
在下文中一共展示了Response.fields['Content-Type']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_html_detect
# 需要导入模块: from wpull.protocol.http.request import Response [as 别名]
# 或者: from wpull.protocol.http.request.Response import fields['Content-Type'] [as 别名]
def test_html_detect(self):
self.assertTrue(HTMLReader.is_file(
io.BytesIO('<html><body>hi</body></html>'.encode('utf-16le'))
))
self.assertFalse(HTMLReader.is_file(
io.BytesIO('hello world!'.encode('utf-16le'))
))
self.assertTrue(HTMLReader.is_file(
io.BytesIO(b'<title>hello</title>hi')
))
self.assertTrue(HTMLReader.is_file(
io.BytesIO(b'<html><body>hello')
))
self.assertTrue(HTMLReader.is_file(
io.BytesIO(
b'The document has moved <a href="somewhere.html">here</a>'
)
))
self.assertTrue(
HTMLReader.is_url(URLInfo.parse('example.com/index.htm'))
)
self.assertTrue(
HTMLReader.is_url(URLInfo.parse('example.com/index.html'))
)
self.assertTrue(
HTMLReader.is_url(URLInfo.parse('example.com/index.dhtm'))
)
self.assertTrue(
HTMLReader.is_url(URLInfo.parse('example.com/index.xhtml'))
)
self.assertTrue(
HTMLReader.is_url(URLInfo.parse('example.com/index.xht'))
)
self.assertFalse(
HTMLReader.is_url(URLInfo.parse('example.com/image.jpg'))
)
self.assertTrue(
HTMLReader.is_request(Request('example.com/index.html'))
)
self.assertFalse(
HTMLReader.is_request(Request('example.com/image.jpg'))
)
response = Response(200, 'OK')
response.fields['Content-Type'] = 'text/html'
self.assertTrue(HTMLReader.is_response(response))
response = Response(200, 'OK')
response.fields['Content-Type'] = 'image/png'
self.assertFalse(HTMLReader.is_response(response))
示例2: test_adjust_extension
# 需要导入模块: from wpull.protocol.http.request import Response [as 别名]
# 或者: from wpull.protocol.http.request.Response import fields['Content-Type'] [as 别名]
def test_adjust_extension(self):
writer = AntiClobberFileWriter(self.get_path_namer(), adjust_extension=True)
test_data = [
('text/html', '/mordor', 'mordor.html'),
('text/html', '/mordor?ring.asp', 'mordor?ring.asp.html'),
('text/html', '/mordor?ring.htm', 'mordor?ring.htm'),
('text/plain', '/static/my_file.txt', 'static/my_file.txt'),
('text/css', '/static/style.css', 'static/style.css'),
('text/css', '/static/style.css?hamster.exe', 'static/style.css?hamster.exe.css'),
('text/html', '/static/mojibake.html', 'static/mojibake.html'),
('text/html', '/static/mojibake.html?dolphin.png', 'static/mojibake.html?dolphin.png.html'),
]
for mime_type, path, filename in test_data:
session = writer.session()
request = HTTPRequest('http://example.com' + path)
response = HTTPResponse(status_code=200, reason='OK', request=request)
response.fields['Content-Type'] = mime_type
session.process_request(request)
session.process_response(response)
session.save_document(response)
print(filename, list(os.walk('.')))
self.assertTrue(os.path.exists(filename))
示例3: test_css_detect
# 需要导入模块: from wpull.protocol.http.request import Response [as 别名]
# 或者: from wpull.protocol.http.request.Response import fields['Content-Type'] [as 别名]
def test_css_detect(self):
self.assertTrue(CSSReader.is_file(
io.BytesIO('body { color: white }'.encode('utf-16le'))
))
self.assertFalse(CSSReader.is_file(
io.BytesIO('hello world!'.encode('utf-16le'))
))
self.assertFalse(CSSReader.is_file(
io.BytesIO(b'<html><body>hello')
))
self.assertTrue(CSSReader.is_file(
io.BytesIO(b'<html><body>hello')
) is VeryFalse)
self.assertTrue(CSSReader.is_file(
io.BytesIO(b'h1 { background-color: red }')
))
self.assertTrue(CSSReader.is_file(
io.BytesIO(b'@import url.css;')
))
self.assertTrue(
CSSReader.is_url(URLInfo.parse('example.com/index.css'))
)
self.assertFalse(
CSSReader.is_url(URLInfo.parse('example.com/image.jpg'))
)
self.assertTrue(
CSSReader.is_request(Request('example.com/index.css'))
)
self.assertFalse(
CSSReader.is_request(Request('example.com/image.jpg'))
)
response = Response(200, 'OK')
response.fields['Content-Type'] = 'text/css'
self.assertTrue(CSSReader.is_response(response))
response = Response(200, 'OK')
response.fields['Content-Type'] = 'image/png'
self.assertFalse(CSSReader.is_response(response))
示例4: test_xml_detect
# 需要导入模块: from wpull.protocol.http.request import Response [as 别名]
# 或者: from wpull.protocol.http.request.Response import fields['Content-Type'] [as 别名]
def test_xml_detect(self):
self.assertTrue(XMLDetector.is_file(
io.BytesIO('<?xml version='.encode('utf-16le'))
))
self.assertFalse(XMLDetector.is_file(
io.BytesIO('<!DOCTYPE html><html><body>'.encode('utf-16le'))
))
self.assertFalse(XMLDetector.is_file(
io.BytesIO(b'<html><body>hello')
))
self.assertTrue(XMLDetector.is_file(
io.BytesIO(b'<?xml version')
))
self.assertTrue(
XMLDetector.is_url(URLInfo.parse('example.com/index.xml'))
)
self.assertFalse(
XMLDetector.is_url(URLInfo.parse('example.com/image.jpg'))
)
self.assertTrue(
XMLDetector.is_request(Request('example.com/index.xml'))
)
self.assertFalse(
XMLDetector.is_request(Request('example.com/image.jpg'))
)
response = Response(200, 'OK')
response.fields['Content-Type'] = 'text/xml'
self.assertTrue(XMLDetector.is_response(response))
response = Response(200, 'OK')
response.fields['Content-Type'] = 'application/xml'
self.assertTrue(XMLDetector.is_response(response))
response = Response(200, 'OK')
response.fields['Content-Type'] = 'image/png'
self.assertFalse(XMLDetector.is_response(response))