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


Python Response.headers['content-type']方法代码示例

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


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

示例1: hello_app

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers['content-type'] [as 别名]
def hello_app(request, name=''):
    content = []
    content.append('Hello %s' % name)

    response = Response(body='\n'.join(content))
    response.headers['content-type'] = 'text/plain'
    return response
开发者ID:wujbj,项目名称:mytest,代码行数:9,代码来源:controller.py

示例2: send_error

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers['content-type'] [as 别名]
def send_error(code, req, result):
    content = None

    resp = Response()
    resp.headers['content-type'] = None
    resp.status = code

    if result:
        if is_xml_response(req):
            content = result.to_xml()
            resp.headers['content-type'] = "application/xml"
        else:
            content = result.to_json()
            resp.headers['content-type'] = "application/json"

        resp.content_type_params = {'charset': 'UTF-8'}
        resp.unicode_body = content.decode('UTF-8')

    return resp
开发者ID:Cerberus98,项目名称:keystone,代码行数:21,代码来源:utils.py

示例3: hello_world_app

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers['content-type'] [as 别名]
def hello_world_app(request):  
    content = []
    content.append('Hello %s' % request.GET['name'])
    
    for key, value in request.environ.items():
        content.append('%s: %s' % (key, value))

    response = Response(body='\n'.join(content))
    response.headers['content-type'] = 'text/plain'
    return response
开发者ID:wujbj,项目名称:mytest,代码行数:12,代码来源:simple2.py

示例4: index

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers['content-type'] [as 别名]
    def index(self, req):
        """ Handle GET and HEAD requests for static files. Directory requests are not allowed"""
        static_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../static/'))

        # filter out ..
        try:
            static_path = req.urlvars['path'].replace('/..', '')
        except:
            return HTTPForbidden()

        path = os.path.join(static_dir, static_path) 
        if os.path.isdir(path):
            return HTTPForbidden()

        if req.method == 'GET' or req.method == 'HEAD':
            if os.path.isfile(path):
                etag, modified, mime_type, size = self._get_stat(path)

                res = Response()
                res.headers['content-type'] = mime_type
                res.date = rfc822.formatdate(time.time())
                res.last_modified = modified
                res.etag = etag

                if_modified_since = req.headers.get('HTTP_IF_MODIFIED_SINCE')
                if if_modified_since:
                    if rfc822.parsedate(if_modified_since) >= rfc822.parsedate(last_modified):
                        return HTTPNotModified()

                if_none_match = req.headers.get('HTTP_IF_NONE_MATCH')
                if if_none_match:
                    if if_none_match == '*' or etag in if_none_match:
                        return HTTPNotModified()

                # set the response body
                if req.method == 'GET':
                    fd = open(path, 'rb')
                    if 'wsgi.file_wrapper' in req.environ:
                        res.app_iter = req.environ['wsgi.file_wrapper'](fd)
                        res.content_length = size
                    else:
                        res.app_iter = iter(lambda: fd.read(8192), '')
                        res.content_length = size
                else:
                    res.body = ''

                return res
            else:
                return None
        else:
            return None
开发者ID:sizzlelab,项目名称:pysmsd,代码行数:53,代码来源:static.py

示例5: _read_container

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headers['content-type'] [as 别名]
    def _read_container(self, env, start_response, headers, children):

        # Build the response message body according to CDMI specification
        res = Response()
        res.headers['content-type'] = 'application/json; charset=UTF-8'

        body = {}

        # Setup required attributes for response body
        body['objectType'] = Consts.CDMI_APP_CONTAINER
        if self.object_name:
            body['objectName'] = self.object_name + '/'
            if self.parent_name != '':
                body['parentURI'] = '/'.join(['', self.cdmi_root,
                                          self.account_name,
                                          self.container_name,
                                          self.parent_name, ''])
            else:
                body['parentURI'] = '/'.join(['', self.cdmi_root,
                                          self.account_name,
                                          self.container_name, ''])
        else:
            body['objectName'] = self.container_name + '/'
            body['parentURI'] = '/'.join(['', self.cdmi_root,
                                          self.account_name, ''])

        body['capabilitiesURI'] = '/'.join(['', self.cdmi_root,
                                            self.account_name,
                                            self.cdmi_capability_id,
                                            'container/'])
        body['completionStatus'] = 'Complete'
        body['metadata'] = {}

        #Get CDMI metadata from the header and add to the body
        for header, value in headers.iteritems():
            key = header.lower()
            if key.startswith(self.metadata_prefix):
                key, value = get_pair_from_header(value)
                if key != '' and value != '':
                    body['metadata'][key] = value

        body['children'] = []
        if children:
            string_to_cut = concat_parts(self.parent_name, self.object_name)
            size = len(string_to_cut)
            if size > 0:
                size += 1
            tracking_device = {}
            for child in children:
                if child.get('name', False):
                    child_name = child.get('name')
                else:
                    child_name = child.get('subdir', False)
                if child_name:
                    child_name = child_name[size:]
                    if not child_name.endswith('/'):
                        content_type = child.get('content_type', '')
                        if content_type.find('directory') >= 0:
                            child_name += '/'
                    if tracking_device.get(child_name) is None:
                        tracking_device[child_name] = child_name
                        body['children'].append(child_name)
        body['childrenRange'] = '0-' + str(len(body['children']))
        res.body = json.dumps(body, indent=2)
        res.status_int = 200

        return res
开发者ID:gwdg,项目名称:cdmi,代码行数:69,代码来源:cdmicommoncontroller.py


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