本文整理汇总了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])
示例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])
示例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
示例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
示例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')
示例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