本文整理汇总了Python中pyramid.response.Response.headers方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers方法的具体用法?Python Response.headers怎么用?Python Response.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.headers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_cheat
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers [as 别名]
def login_cheat(request): # TODO: test
next = request.params.get('next') or request.route_url('dashboard')
login = request.json_body.get('login', '')
passwordhash = request.json_body.get('passwordhash', '')
log.debug("Logging in with cheat method:" + login)
user = DBSession.query(User).filter_by(login=login).first()
if user and user.password.hash == passwordhash:
log.debug("Login successful")
client = Client(user_id=user.id)
user.clients.append(client)
DBSession.add(client)
DBSession.flush()
headers = remember(request, principal=client.id)
response = Response()
response.headers = headers
locale_id = user.default_locale_id
if not locale_id:
locale_id = 1
response.set_cookie(key='locale_id', value=str(locale_id))
response.set_cookie(key='client_id', value=str(client.id))
headers = remember(request, principal=client.id)
return response
log.debug("Login unsuccessful for " + login)
return HTTPUnauthorized(location=request.route_url('login'))
示例2: signin
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers [as 别名]
def signin(request):
req = request.json_body
login = req['login']
password = req['password']
# login = request.POST.get('login', '')
# password = request.POST.get('password', '')
user = DBSession.query(User).filter_by(login=login).first()
if user and user.check_password(password):
client = Client(user_id=user.id)
user.clients.append(client)
DBSession.add(client)
DBSession.flush()
headers = remember(request, principal=client.id)
response = Response()
response.headers = headers
locale_id = user.default_locale_id
if not locale_id:
locale_id = 1
response.set_cookie(key='locale_id', value=str(locale_id))
response.set_cookie(key='client_id', value=str(client.id))
result = dict()
result['client_id'] = client.id
request.response.status = HTTPOk.code
# request.response.headers = headers
# return response
return HTTPOk(headers=response.headers, json_body=result)
# return result
return HTTPUnauthorized(location=request.route_url('login'))
示例3: login_post
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers [as 别名]
def login_post(request): # tested
next = request.params.get('next') or request.route_url('home')
login = request.POST.get('login', '')
password = request.POST.get('password', '')
# print(login)
log.debug(login)
user = DBSession.query(User).filter_by(login=login).first()
if user and user.check_password(password):
client = Client(user_id=user.id)
user.clients.append(client)
DBSession.add(client)
DBSession.flush()
headers = remember(request, principal=client.id)
response = Response()
response.headers = headers
locale_id = user.default_locale_id
if not locale_id:
locale_id = 1
response.set_cookie(key='locale_id', value=str(locale_id))
response.set_cookie(key='client_id', value=str(client.id))
headers = remember(request, principal=client.id)
# return HTTPFound(location=next, headers=response.headers)
return HTTPOk(headers=response.headers, json_body={})
# return {}
return HTTPUnauthorized(location=request.route_url('login'))
示例4: set_language
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers [as 别名]
def set_language(request):
if request.POST:
local_name = negotiate_locale_name(request)
resp = Response()
resp.headers = {'Location': request.referrer}
resp.status = '302'
resp.set_cookie('language', local_name)
return resp
else:
return HTTPInternalServerError()
示例5: connector
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers [as 别名]
def connector(request):
# init connector and pass options
root = request.registry.settings['pyramid_elfinder_root']
options = {
'root': os.path.abspath(root),
'URL': request.registry.settings['pyramid_elfinder_url']
}
elf = elfinder.connector(options)
# fetch only needed GET/POST parameters
httpRequest = {}
form = request.params
for field in elf.httpAllowedParameters:
if field in form:
# Russian file names hack
if field == 'name':
httpRequest[field] = form.getone(field).encode('utf-8')
elif field == 'targets[]':
httpRequest[field] = form.getall(field)
# handle CGI upload
elif field == 'upload[]':
upFiles = {}
cgiUploadFiles = form.getall(field)
for up in cgiUploadFiles:
if isinstance(up, FieldStorage):
# pack dict(filename: filedescriptor)
upFiles[up.filename.encode('utf-8')] = up.file
httpRequest[field] = upFiles
else:
httpRequest[field] = form.getone(field)
# run connector with parameters
status, header, response = elf.run(httpRequest)
# get connector output and print it out
result = Response(status=status)
try:
del header['Connection']
except Exception:
pass
result.headers = header
result.charset = 'utf8'
if response is not None and status == 200:
# send file
if 'file' in response and hasattr(response['file'], 'read'):
result.body = response['file'].read()
response['file'].close()
# output json
else:
result.text = json.dumps(response)
return result
示例6: connector
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers [as 别名]
def connector(request):
# init connector and pass options
elf = elFinder.connector(_opts)
# fetch only needed GET/POST parameters
httpRequest = {}
form=request.params
for field in elf.httpAllowedParameters:
if field in form:
# Russian file names hack
if field == 'name':
httpRequest[field] = form.getone(field).encode('utf-8')
elif field == 'targets[]':
httpRequest[field] = form.getall(field)
# handle CGI upload
elif field == 'upload[]':
upFiles = {}
cgiUploadFiles = form.getall(field)
for up in cgiUploadFiles:
if isinstance(up, FieldStorage):
upFiles[up.filename.encode('utf-8')] = up.file # pack dict(filename: filedescriptor)
httpRequest[field] = upFiles
else:
httpRequest[field] = form.getone(field)
# run connector with parameters
status, header, response = elf.run(httpRequest)
# get connector output and print it out
result=Response(status=status)
try:
del header['Connection']
except:
pass
result.headers=header
if not response is None and status == 200:
# send file
if 'file' in response and isinstance(response['file'], file):
result.body=response['file'].read()
response['file'].close()
# output json
else:
result.body=json.dumps(response)
return result