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


Python Response.content_type方法代码示例

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


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

示例1: test_content_type

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
def test_content_type():
    r = Response()
    # default ctype and charset
    eq_(r.content_type, 'text/html')
    eq_(r.charset, 'UTF-8')
    # setting to none, removes the header
    r.content_type = None
    eq_(r.content_type, None)
    eq_(r.charset, None)
    # can set missing ctype
    r.content_type = None
    eq_(r.content_type, None)
开发者ID:perey,项目名称:webob,代码行数:14,代码来源:test_response.py

示例2: test_content_type

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
def test_content_type():
    r = Response()
    # default ctype and charset
    assert r.content_type == 'text/html'
    assert r.charset == 'UTF-8'
    # setting to none, removes the header
    r.content_type = None
    assert r.content_type is None
    assert r.charset is None
    # can set missing ctype
    r.content_type = None
    assert r.content_type is None
开发者ID:doulbekill,项目名称:webob,代码行数:14,代码来源:test_response.py

示例3: display_test

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
    def display_test(self, request):
        '''This method handles **/dummy/route/loader/test route**. It is expected to receive a response with status code 400.
        We do this for being able to test rendering and also avoid false positive security scans messages.'''

        response = Response(status_code=400)

        if "text/html" in request.content_type:
            response.content_type = "application/html; charset=UTF-8"
        else:
            response.content_type = request.content_type or "application/html; charset=UTF-8"

        response.text = "Hello world."

        return response
开发者ID:rcosnita,项目名称:fantastico,代码行数:16,代码来源:dummy_routeloader.py

示例4: generate_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
    def generate_response(self, environ, start_response):
        if self.content_length is not None:
            del self.content_length
        headerlist = list(self.headerlist)
        accept_value = environ.get('HTTP_ACCEPT', '')
        accept = MIMEAccept(accept_value)
        match = accept.best_match(['text/html', 'application/json'])

        if match == 'text/html':
            content_type = 'text/html'
            body = self.html_body(environ)
        elif match == 'application/json':
            content_type = 'application/json'
            body = self.json_body(environ)
        else:
            content_type = 'text/plain'
            body = self.plain_body(environ)
        extra_kw = {}
        if isinstance(body, text_type):
            extra_kw.update(charset='utf-8')
        resp = Response(body,
                        status=self.status,
                        headerlist=headerlist,
                        content_type=content_type,
                        **extra_kw
                        )
        resp.content_type = content_type
        return resp(environ, start_response)
开发者ID:doulbekill,项目名称:webob,代码行数:30,代码来源:exc.py

示例5: say_hello

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
 def say_hello(self, request):
     tpl = self.load_template("/say_hello.html")
     
     response = Response(tpl)
     response.content_type = "text/html"
     
     return response
开发者ID:rcosnita,项目名称:fantastico,代码行数:9,代码来源:test_base_controller.py

示例6: generate_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
    def generate_response(self, environ, start_response):
        if self.content_length is not None:
            del self.content_length
        headerlist = list(self.headerlist)
        accept_value = environ.get("HTTP_ACCEPT", "")
        accept_header = create_accept_header(header_value=accept_value)
        acceptable_offers = accept_header.acceptable_offers(
            offers=["text/html", "application/json"]
        )
        match = acceptable_offers[0][0] if acceptable_offers else None

        if match == "text/html":
            content_type = "text/html"
            body = self.html_body(environ)
        elif match == "application/json":
            content_type = "application/json"
            body = self.json_body(environ)
        else:
            content_type = "text/plain"
            body = self.plain_body(environ)
        resp = Response(
            body, status=self.status, headerlist=headerlist, content_type=content_type
        )
        resp.content_type = content_type

        return resp(environ, start_response)
开发者ID:Pylons,项目名称:webob,代码行数:28,代码来源:exc.py

示例7: test_exec_controller_ok

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
    def test_exec_controller_ok(self):
        '''This test case ensures that requested route is executed - success scenario.'''

        global_headers = {"X-Custom-Header1": "header1",
                          "X-Custom-Header2": "header2"}

        def get(key):
            if key == "installed_middleware":
                return ["fantastico.middleware.tests.test_fantastico_app.MockedMiddleware"]
            
            if key == "global_response_headers":
                return global_headers
                
        self._settings_facade.get = get
                
        app_middleware = FantasticoApp(self._settings_facade_cls)
        
        response = Response()
        response.content_type = "text/html"
        response.text = "Hello world"
        
        self._controller.exec_logic = lambda request: response
        
        self.assertEqual([b"Hello world"], app_middleware(self._environ, Mock()))
        self.assertTrue(self._environ["test_wrapped_ok"])
        
        self.assertEqual(global_headers["X-Custom-Header1"], response.headers["X-Custom-Header1"])
        self.assertEqual(global_headers["X-Custom-Header2"], response.headers["X-Custom-Header2"])
开发者ID:rcosnita,项目名称:fantastico,代码行数:30,代码来源:test_fantastico_app.py

示例8: generate_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
 def generate_response(self, environ, start_response):
     if self.content_length is not None:
         del self.content_length
     headerlist = list(self.headerlist)
     content_type = 'application/json'
     body = '{"error": "%s"}' % self.detail
     resp = Response(
         body,
         status=self.status,
         headerlist=headerlist,
         content_type=content_type
     )
     resp.content_type = content_type
     return resp(environ, start_response)
开发者ID:ktdreyer,项目名称:pecan-notario,代码行数:16,代码来源:exceptions.py

示例9: test_mistmatch_content_headers

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
    def test_mistmatch_content_headers(self):
        '''This test case makes sure an exception is raised whenever client browser does not accept response
        content type.'''
        
        self._settings_facade.get = Mock(return_value=["fantastico.middleware.tests.test_fantastico_app.MockedMiddleware"])        

        response = Response()
        response.content_type = "not supported"
        response.text = "Hello world"
        
        self._controller.exec_logic = lambda request: response
        
        app_middleware = FantasticoApp(self._settings_facade_cls)
        
        self.assertRaises(FantasticoContentTypeError, app_middleware, *[self._environ, Mock()])            
        self.assertTrue(self._environ["test_wrapped_ok"])
开发者ID:rcosnita,项目名称:fantastico,代码行数:18,代码来源:test_fantastico_app.py

示例10: generate_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
 def generate_response(self, environ, start_response):
     if self.content_length is not None:
         del self.content_length
     headerlist = list(self.headerlist)
     accept = environ.get("HTTP_ACCEPT", "")
     if accept and "html" in accept or "*/*" in accept:
         content_type = "text/html"
         body = self.html_body(environ)
     else:
         content_type = "text/plain"
         body = self.plain_body(environ)
     extra_kw = {}
     if isinstance(body, text_type):
         extra_kw.update(charset="utf-8")
     resp = Response(body, status=self.status, headerlist=headerlist, content_type=content_type, **extra_kw)
     resp.content_type = content_type
     return resp(environ, start_response)
开发者ID:jagleeso,项目名称:telemetry,代码行数:19,代码来源:exc.py

示例11: generate_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
 def generate_response(self, environ, start_response):
     if self.content_length is not None:
         del self.content_length
     headerlist = list(self.headerlist)
     accept = environ.get('HTTP_ACCEPT', '')
     if accept and 'json' in accept or '*/*' in accept:
         content_type = 'application/json'
         body = self.html_body(environ)
     else:
         content_type = 'text/plain'
         body = self.plain_body(environ)
     extra_kw = {}
     resp = Response(body,
                     status=self.status,
                     headerlist=headerlist,
                     content_type=content_type,
                     **extra_kw)
     resp.content_type = content_type
     return resp(environ, start_response)
开发者ID:archsh,项目名称:tg2ext.express,代码行数:21,代码来源:exceptions.py

示例12: generate_response

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
 def generate_response(self, environ, start_response):
     if self.content_length is not None:
         del self.content_length
     headerlist = list(self.headerlist)
     accept = environ.get('HTTP_ACCEPT', '')
     if accept and 'html' in accept or '*/*' in accept:
         content_type = 'text/html'
         body = self.html_body(environ)
     else:
         content_type = 'text/plain'
         body = self.plain_body(environ)
     extra_kw = {}
     if isinstance(body, text_type):
         extra_kw.update(charset='utf-8')
     resp = Response(body,
         status=self.status,
         headerlist=headerlist,
         content_type=content_type,
         **extra_kw
     )
     resp.content_type = content_type
     return resp(environ, start_response)
开发者ID:rdebliek,项目名称:oscar,代码行数:24,代码来源:exc.py

示例13: test_response_ok

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
    def test_response_ok(self):
        '''Test case that ensures response object behaves as expected. If this pass it guarantees webob version does not
        break fantastico functionality.'''
        
        response = Response()
        
        self.assertEqual(200, response.status_code)
        self.assertEqual("text/html", response.content_type)
        
        response.charset = "utf8"
        self.assertEqual("utf8", response.charset)
        
        response.text = "test content"
        self.assertEqual(b"test content", response.body)

        response.body = b"test content"
        self.assertEqual(b"test content", response.body)
        
        response.status = 404
        self.assertEqual(404, response.status_code)
        
        response.content_type = "application/json"
        self.assertEqual("application/json", response.content_type)
开发者ID:rcosnita,项目名称:fantastico,代码行数:25,代码来源:test_response.py

示例14: test_content_type_not_binary

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
def test_content_type_not_binary():
    content_type = b"text/html"
    resp = Response()

    with pytest.raises(TypeError):
        resp.content_type = content_type
开发者ID:Pylons,项目名称:webob,代码行数:8,代码来源:test_response.py

示例15: test_content_type_supports_unicode

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import content_type [as 别名]
def test_content_type_supports_unicode():
    content_type = u"text/html"
    resp = Response()
    resp.content_type = content_type
    assert isinstance(resp.headers["Content-Type"], str)
开发者ID:Pylons,项目名称:webob,代码行数:7,代码来源:test_response.py


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