当前位置: 首页>>代码示例>>Python>>正文


Python Response.fields['Content-Type']方法代码示例

本文整理汇总了Python中wpull.http.request.Response.fields['Content-Type']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.fields['Content-Type']方法的具体用法?Python Response.fields['Content-Type']怎么用?Python Response.fields['Content-Type']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wpull.http.request.Response的用法示例。


在下文中一共展示了Response.fields['Content-Type']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_html_detect

# 需要导入模块: from wpull.http.request import Response [as 别名]
# 或者: from wpull.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.new('example.com/index.html'))
        )
        self.assertFalse(
            HTMLReader.is_request(Request.new('example.com/image.jpg'))
        )

        response = Response('HTTP/1.0', '200', 'OK')
        response.fields['Content-Type'] = 'text/html'
        self.assertTrue(HTMLReader.is_response(response))

        response = Response('HTTP/1.0', '200', 'OK')
        response.fields['Content-Type'] = 'image/png'
        self.assertFalse(HTMLReader.is_response(response))
开发者ID:lowks,项目名称:wpull,代码行数:52,代码来源:document_test.py

示例2: test_css_detect

# 需要导入模块: from wpull.http.request import Response [as 别名]
# 或者: from wpull.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))
开发者ID:Willianvdv,项目名称:wpull,代码行数:41,代码来源:css_test.py

示例3: test_xml_detect

# 需要导入模块: from wpull.http.request import Response [as 别名]
# 或者: from wpull.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))
开发者ID:Willianvdv,项目名称:wpull,代码行数:39,代码来源:xml_test.py

示例4: test_js_detect

# 需要导入模块: from wpull.http.request import Response [as 别名]
# 或者: from wpull.http.request.Response import fields['Content-Type'] [as 别名]
    def test_js_detect(self):
        self.assertTrue(JavaScriptReader.is_file(
            io.BytesIO('var a = 1;'.encode('utf-16le'))
        ))
        self.assertTrue(JavaScriptReader.is_file(
            io.BytesIO('setTimeout('.encode('utf-16le'))
        ))
        self.assertFalse(JavaScriptReader.is_file(
            io.BytesIO('hello world!'.encode('utf-16le'))
        ))
        self.assertFalse(JavaScriptReader.is_file(
            io.BytesIO(b'<html><body>hello')
        ))
        self.assertTrue(JavaScriptReader.is_file(
            io.BytesIO(b'<html><body>hello')
        ) is VeryFalse)

        response = Response(200, 'OK')
        response.fields['Content-Type'] = 'application/javascript'
        self.assertTrue(JavaScriptReader.is_response(response))

        response = Response(200, 'OK')
        response.fields['Content-Type'] = 'image/png'
        self.assertFalse(JavaScriptReader.is_response(response))
开发者ID:Willianvdv,项目名称:wpull,代码行数:26,代码来源:javascript_test.py


注:本文中的wpull.http.request.Response.fields['Content-Type']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。