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


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

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


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

示例1: switch_mode

# 需要导入模块: from globals import Response [as 别名]
# 或者: from globals.Response import headers['Content-Type'] [as 别名]
 def switch_mode(self):
     settings, request, response, T = self.settings, current.request, current.response, current.T
     
     _arg0 = request.args(0)
     if not (_arg0 and (EDIT_MODE in _arg0 or PREVIEW_MODE in _arg0 or  REFERENCE_MODE in _arg0)):
         self.view_mode = LIVE_MODE
         return
     else:
         self.view_mode = _arg0
         current_device = None
         for device in self.settings.devices:
             suffix = '_managed_html_%s'%device['name']
             if suffix in _arg0:
                 request.update(**device.get('request_updator', {}))
                 current_device = device
                 break
         
         if request.args and request.args[-1] == 'managed_html.js':
             # Return javascript
             
             from globals import Response, Storage
             _response = Response()
             _response._view_environment = current.globalenv.copy()
             _response._view_environment.update(
                 request=Storage(folder=os.path.join(os.path.dirname(os.path.dirname(request.folder)), APP)),
                 response=_response,
             )
             
             _device_url_base = self.view_mode
             for device in self.settings.devices:
                 _device_url_base = _device_url_base.replace('_managed_html_%s' % device['name'], '')
             for device in self.settings.devices:
                 device.update({'url':self.settings.URL(args=[_device_url_base + '_managed_html_%s' % device['name']] + request.args[1:-1], vars=request.vars)})
             
             _response.headers['Content-Type'] = 'text/javascript; charset=utf-8;'
             raise HTTP(200, _response.render('plugin_managed_html/managed_html_ajax.js',
                         dict(
                             home_url=settings.home_url,
                             home_label=settings.home_label,
                             edit_url=settings.URL(args=[self.view_mode.replace(PREVIEW_MODE, EDIT_MODE).replace(REFERENCE_MODE, EDIT_MODE)] +
                                                         request.args[1:-1], vars=request.vars)
                                         if PREVIEW_MODE in self.view_mode or REFERENCE_MODE in self.view_mode else '',
                             preview_url=settings.URL(args=[self.view_mode.replace(EDIT_MODE, PREVIEW_MODE).replace(REFERENCE_MODE, PREVIEW_MODE)] +
                                                              request.args[1:-1], vars=request.vars)
                                         if EDIT_MODE in self.view_mode or REFERENCE_MODE in self.view_mode else '',
                             reference_url=settings.URL(args=[self.view_mode.replace(EDIT_MODE, REFERENCE_MODE).replace(PREVIEW_MODE, REFERENCE_MODE).replace('_managed_html_%s' % current_device['name'] if current_device else '', '')] +
                                                              request.args[1:-1], vars=request.vars)
                                         if EDIT_MODE in self.view_mode or PREVIEW_MODE in self.view_mode else '',
                             live_url=self.settings.URL(args=request.args[1:-1], vars=request.vars, scheme='http'),
                             show_page_grid=self._show_page_grid_js() if settings.page_grid else '',
                             devices=self.settings.devices,
                             current_device=current_device,
                             is_edit_mode=EDIT_MODE in self.view_mode,
                             is_preview_mode=PREVIEW_MODE in self.view_mode,
                         )),
                        **_response.headers)
         
         response.files.append(URL(args=((request.args or []) + ['managed_html.js'])))
         self.use_grid(args=request.args[:2])
开发者ID:lightdot,项目名称:sqlabs,代码行数:61,代码来源:plugin_managed_html.py

示例2: switch_mode

# 需要导入模块: from globals import Response [as 别名]
# 或者: from globals.Response import headers['Content-Type'] [as 别名]
 def switch_mode(self):
     settings, request, response, T = self.settings, current.request, current.response, current.T
     
     _arg0 = request.args(0)
     if not (_arg0 and (EDIT_MODE in _arg0 or PREVIEW_MODE in _arg0)):
         self.view_mode = LIVE_MODE
         return
     else:
         self.view_mode = _arg0
         if request.args and request.args[-1] == 'managed_html.js':
             # Return javascript
             
             from globals import Response, Storage
             _response = Response()
             _response._view_environment = current.globalenv.copy()
             _response._view_environment.update(
                 request=Storage(folder=os.path.join(os.path.dirname(os.path.dirname(request.folder)), APP)),
                 response=_response,
             )
             
             _response.headers['Content-Type'] = 'text/javascript; charset=utf-8;'
             raise HTTP(200, _response.render('plugin_managed_html/managed_html_ajax.js',
                         dict(
                             home_url=settings.home_url,
                             home_label=settings.home_label,
                             edit_url=settings.URL(args=[self.view_mode.replace(PREVIEW_MODE, EDIT_MODE)] +
                                                         request.args[1:-1], vars=request.vars)
                                         if PREVIEW_MODE in self.view_mode else '',
                             preview_url=settings.URL(args=[self.view_mode.replace(EDIT_MODE, PREVIEW_MODE)] +
                                                              request.args[1:-1], vars=request.vars)
                                         if EDIT_MODE in self.view_mode else '',
                             live_url=self.settings.URL(args=request.args[1:-1], vars=request.vars, scheme='http'),
                             show_page_grid=self._show_page_grid_js() if settings.page_grid else '',
                         )),
                        **_response.headers)
                        
         response.files.append(URL(args=((request.args or []) + ['managed_html.js'])))
                       
         self.use_grid(args=request.args[:2])
开发者ID:aurukas,项目名称:sqlabs,代码行数:41,代码来源:plugin_managed_html.py

示例3: wsgibase

# 需要导入模块: from globals import Response [as 别名]
# 或者: from globals.Response import headers['Content-Type'] [as 别名]

#.........这里部分代码省略.........

                # ##################################################
                # expose wsgi hooks for convenience
                # ##################################################

                request.wsgi.environ = environ_aux(environ,request)
                request.wsgi.start_response = \
                    lambda status='200', headers=[], \
                    exec_info=None, response=response: \
                    start_response_aux(status, headers, exec_info, response)
                request.wsgi.middleware = \
                    lambda *a: middleware_aux(request,response,*a)

                # ##################################################
                # load cookies
                # ##################################################

                if request.env.http_cookie:
                    try:
                        request.cookies.load(request.env.http_cookie)
                    except Cookie.CookieError, e:
                        pass # invalid cookies

                # ##################################################
                # try load session or create new session file
                # ##################################################

                session.connect(request, response)

                # ##################################################
                # set no-cache headers
                # ##################################################

                response.headers['Content-Type'] = \
                    contenttype('.'+request.extension)
                response.headers['Cache-Control'] = \
                    'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
                response.headers['Expires'] = \
                    time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
                response.headers['Pragma'] = 'no-cache'

                # ##################################################
                # run controller
                # ##################################################

                if global_settings.debugging and request.application != "admin":
                    import gluon.debug
                    # activate the debugger and wait to reach application code
                    gluon.debug.dbg.do_debug(mainpyfile=request.folder)

                serve_controller(request, response, session)

            except HTTP, http_response:
                if static_file:
                    return http_response.to(responder)

                if request.body:
                    request.body.close()

                # ##################################################
                # on success, try store session in database
                # ##################################################
                session._try_store_in_db(request, response)

                # ##################################################
                # on success, commit database
开发者ID:,项目名称:,代码行数:70,代码来源:

示例4: wsgibase

# 需要导入模块: from globals import Response [as 别名]
# 或者: from globals.Response import headers['Content-Type'] [as 别名]

#.........这里部分代码省略.........
                    path =  os.path.join(request.folder,subfolder)
                    if not os.path.exists(path):
                        os.mkdir(path)

            # ##################################################
            # get the GET and POST data
            # ##################################################

            parse_get_post_vars(request, environ)

            # ##################################################
            # expose wsgi hooks for convenience
            # ##################################################

            request.wsgi.environ = environ_aux(environ,request)
            request.wsgi.start_response = lambda status='200', headers=[], \
                exec_info=None, response=response: \
                start_response_aux(status, headers, exec_info, response)
            request.wsgi.middleware = lambda *a: middleware_aux(request,response,*a)

            # ##################################################
            # load cookies
            # ##################################################

            if request.env.http_cookie:
                try:
                    request.cookies.load(request.env.http_cookie)
                except Cookie.CookieError, e:
                    pass # invalid cookies

            # ##################################################
            # try load session or create new session file
            # ##################################################

            session.connect(request, response)

            # ##################################################
            # set no-cache headers
            # ##################################################

            response.headers['Content-Type'] = contenttype('.'+request.extension)
            response.headers['Cache-Control'] = \
                'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
            response.headers['Expires'] = \
                time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
            response.headers['Pragma'] = 'no-cache'

            # ##################################################
            # run controller
            # ##################################################

            serve_controller(request, response, session)

        except HTTP, http_response:
            if static_file:
                return http_response.to(responder)

            if request.body:
                request.body.close()

            # ##################################################
            # on success, try store session in database
            # ##################################################
            session._try_store_in_db(request, response)

            # ##################################################
            # on success, commit database
            # ##################################################

            if response._custom_commit:
                response._custom_commit()
            else:
                BaseAdapter.close_all_instances(BaseAdapter.commit)

            # ##################################################
            # if session not in db try store session on filesystem
            # this must be done after trying to commit database!
            # ##################################################

            session._try_store_on_disk(request, response)

            # ##################################################
            # store cookies in headers
            # ##################################################
            
            if request.cid:
                if response.flash and not 'web2py-component-flash' in http_response.headers:
                    http_response.headers['web2py-component-flash'] = \
                        str(response.flash).replace('\n','')
                if response.js and not 'web2py-component-command' in http_response.headers:
                    http_response.headers['web2py-component-command'] = \
                        str(response.js).replace('\n','')
            if session._forget:
                del response.cookies[response.session_id_name]
            elif session._secure:
                response.cookies[response.session_id_name]['secure'] = True            
            if len(response.cookies)>0:
                http_response.headers['Set-Cookie'] = \
                    [str(cookie)[11:] for cookie in response.cookies.values()]
            ticket=None
开发者ID:fmobus,项目名称:forca-inf,代码行数:104,代码来源:main.py

示例5: wsgibase

# 需要导入模块: from globals import Response [as 别名]
# 或者: from globals.Response import headers['Content-Type'] [as 别名]

#.........这里部分代码省略.........

                parse_get_post_vars(request, environ)

                # ##################################################
                # expose wsgi hooks for convenience
                # ##################################################

                request.wsgi.environ = environ_aux(environ,request)
                request.wsgi.start_response = lambda status='200', headers=[], \
                    exec_info=None, response=response: \
                    start_response_aux(status, headers, exec_info, response)
                request.wsgi.middleware = lambda *a: middleware_aux(request,response,*a)

                # ##################################################
                # load cookies
                # ##################################################

                if request.env.http_cookie:
                    try:
                        request.cookies.load(request.env.http_cookie)
                    except Cookie.CookieError, e:
                        pass # invalid cookies

                # ##################################################
                # try load session or create new session file
                # ##################################################

                session.connect(request, response)

                # ##################################################
                # set no-cache headers
                # ##################################################

                response.headers['Content-Type'] = contenttype('.'+request.extension)
                response.headers['Cache-Control'] = \
                    'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
                response.headers['Expires'] = \
                    time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
                response.headers['Pragma'] = 'no-cache'

                # ##################################################
                # run controller
                # ##################################################

                serve_controller(request, response, session)

            except HTTP, http_response:
                if static_file:
                    return http_response.to(responder)

                if request.body:
                    request.body.close()

                # ##################################################
                # on success, try store session in database
                # ##################################################
                session._try_store_in_db(request, response)

                # ##################################################
                # on success, commit database
                # ##################################################

                if response._custom_commit:
                    response._custom_commit()
                else:
                    BaseAdapter.close_all_instances('commit')
开发者ID:unyo,项目名称:uhpackage,代码行数:70,代码来源:main.py

示例6: wsgibase

# 需要导入模块: from globals import Response [as 别名]
# 或者: from globals.Response import headers['Content-Type'] [as 别名]

#.........这里部分代码省略.........
            request.url = URL(r=request,args=request.args,
                                   extension=raw_extension)

            # ##################################################
            # build missing folder
            # ##################################################
            
            if not request.env.web2py_runtime_gae:
                for subfolder in ['models','views','controllers',
                                  'modules','cron','errors','sessions',
                                  'languages','static','private','uploads']:
                    path =  os.path.join(request.folder,subfolder)
                    if not os.path.exists(path):
                        os.mkdir(path)
                        
            # ##################################################
            # get the GET and POST data
            # ##################################################

            parse_get_post_vars(request, environ)

            # ##################################################
            # expose wsgi hooks for convenience
            # ##################################################

            request.wsgi.environ = environ_aux(environ,request)
            request.wsgi.start_response = lambda status='200', headers=[], \
                exec_info=None, response=response: \
                start_response_aux(status, headers, exec_info, response)
            request.wsgi.middleware = lambda *a: middleware_aux(request,response,*a)

            # ##################################################
            # load cookies
            # ##################################################

            if request.env.http_cookie:
                try:
                    request.cookies.load(request.env.http_cookie)
                except Cookie.CookieError, e:
                    pass # invalid cookies

            # ##################################################
            # try load session or create new session file
            # ##################################################

            session.connect(request, response)

            # ##################################################
            # set no-cache headers
            # ##################################################

            response.headers['Content-Type'] = contenttype('.'+request.extension)
            response.headers['Cache-Control'] = \
                'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
            response.headers['Expires'] = \
                time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
            response.headers['Pragma'] = 'no-cache'

            # ##################################################
            # run controller
            # ##################################################

            serve_controller(request, response, session)

        except HTTP, http_response:

            if request.body:
                request.body.close()

            # ##################################################
            # on success, try store session in database
            # ##################################################
            session._try_store_in_db(request, response)

            # ##################################################
            # on success, commit database
            # ##################################################

            if response._custom_commit:
                response._custom_commit()
            else:
                BaseAdapter.close_all_instances(BaseAdapter.commit)

            # ##################################################
            # if session not in db try store session on filesystem
            # this must be done after trying to commit database!
            # ##################################################

            session._try_store_on_disk(request, response)

            # ##################################################
            # store cookies in headers
            # ##################################################

            if session._secure:
                response.cookies[response.session_id_name]['secure'] = \
                    True
            http_response.headers['Set-Cookie'] = [str(cookie)[11:]
                    for cookie in response.cookies.values()]
            ticket=None
开发者ID:greenscar,项目名称:scripts,代码行数:104,代码来源:main.py


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