本文整理汇总了Python中werkzeug.test.Client.set_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python Client.set_cookie方法的具体用法?Python Client.set_cookie怎么用?Python Client.set_cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.test.Client
的用法示例。
在下文中一共展示了Client.set_cookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_jwtsession_expire_days
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_jwtsession_expire_days():
class A(spa.Handler):
def get(self):
return spa.Response(self.request.environ['jwtsession']['foo'])
routes = (
('/', 'a', A),
)
app = spa.App(routes)
secret = 'foobar'
app = JWTSessionMiddleware(app, secret_key=secret, expire_days=1)
c = Client(app, spa.Response)
tok = jwt.encode({
'foo': 'bar',
'iat': utc.now() - datetime.timedelta(days=1)
}, secret)
c.set_cookie('localhost', 'session', tok)
with pytest.raises(KeyError):
# The handler should fail to read 'foo' from the session, because it
# will have been dropped when the middleware saw that its 'iat'
# timestamp was too old.
c.get('/')
示例2: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = simplejson.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
if docids:
# Generic report:
response = super(Extension, self).report_routes(reportname, docids=docids, converter='pdf')
# response = self.report_routes(reportname, docids=docids, converter='pdf')
##### FIX START: switch reportname with the evaluated attachment attribute of the action if available
docids = [int(i) for i in docids.split(',')]
report_obj = request.registry['report']
cr, uid, context = request.cr, request.uid, request.context
report = report_obj._get_report_from_name(cr, uid, reportname)
obj = report_obj.pool[report.model].browse(cr, uid, docids[0])
if hasattr(obj, 'name') and obj.name:
reportname = obj.name
##### FIX END
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = super(Extension, self).report_routes(reportname, converter='pdf', **dict(data))
# response = self.report_routes(reportname, converter='pdf', **dict(data))
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname)
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(html_escape(simplejson.dumps(error)))
示例3: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data,token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = simplejson.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter='pdf')
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter='pdf', **dict(data))
if reportname == 'jjuice_fedex.report_print_label':
cr, context = request.cr, request.context
info = request.registry('create.shipment.fedex').read(cr,SUPERUSER_ID,int(docids),['to_person_name','tracking_number'])
str_list = []
str_list.append(time.strftime("%Y-%m-%d"))
str_list.append(info.get('to_person_name','unavailable') or 'unavailable')
str_list.append(info.get('tracking_number','unavailable') or 'unavailable')
label_name = '_'.join(str_list)
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % label_name)
else:
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname)
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(html_escape(simplejson.dumps(error)))
示例4: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = json.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter='pdf')
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter='pdf', **dict(data))
cr, uid = request.cr, request.uid
report = request.registry['report']._get_report_from_name(cr, uid, reportname)
filename = "%s.%s" % (report.name, "pdf")
if docids:
ids = [int(x) for x in docids.split(",")]
obj = request.env[report.model].browse(ids)
if report.print_report_name and not len(obj) > 1:
filename = eval(report.print_report_name, {'object': obj, 'time': time})
response.headers.add('Content-Disposition', content_disposition(filename))
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(html_escape(json.dumps(error)))
示例5: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = simplejson.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
print docids,reportname
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter='pdf')
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter='pdf', **dict(data))
#Rename the pdf's name make it looks kindly.
report_ids = request.registry.get('ir.actions.report.xml').search(request.cr,openerp.SUPERUSER_ID,[('report_name','=',reportname)])
if len(report_ids):
report_obj = request.registry.get('ir.actions.report.xml').browse(request.cr,openerp.SUPERUSER_ID,report_ids[0])
docids = [int(x) for x in docids.split(',')]
reports = request.registry.get(report_obj.model).browse(request.cr,openerp.SUPERUSER_ID,docids)
filename = reports[0].name
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % filename)
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(html_escape(simplejson.dumps(error)))
示例6: test_empty_header_blocked
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_empty_header_blocked():
class A(spa.Handler):
def post(self):
return spa.Response('hello world')
routes = (
('/', 'a', A),
)
app = ApiCSRFMiddleware(spa.App(routes))
c = Client(app, spa.Response)
c.set_cookie('localhost', 'api_csrf', 'foobar')
resp = c.post('/')
assert resp.status_code == 403
示例7: test_mismatched_tokens_blocked
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_mismatched_tokens_blocked():
class A(spa.Handler):
def post(self):
return spa.Response('hello world')
routes = (
('/', 'a', A),
)
app = ApiCSRFMiddleware(spa.App(routes))
c = Client(app, spa.Response)
c.set_cookie('localhost', 'api_csrf', 'foobar')
resp = c.post('/', headers={'X-Api-CSRF': 'barfoo'})
assert resp.status_code == 403
示例8: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = json.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == "qweb-pdf":
reportname = url.split("/report/pdf/")[1].split("?")[0]
docids = None
if "/" in reportname:
reportname, docids = reportname.split("/")
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter="pdf")
else:
# Particular report:
data = url_decode(url.split("?")[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter="pdf", **dict(data))
cr, uid = request.cr, request.uid
report = request.registry["report"]._get_report_from_name(cr, uid, reportname)
filename = "%s.%s" % (report.name, "pdf")
response.headers.add("Content-Disposition", content_disposition(filename))
response.set_cookie("fileToken", token)
return response
elif type == "controller":
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(
url, headers=reqheaders, follow_redirects=True
)
response.set_cookie("fileToken", token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {"code": 200, "message": "Odoo Server Error", "data": se}
return request.make_response(html_escape(json.dumps(error)))
示例9: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = simplejson.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter='pdf')
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter='pdf', **dict(data))
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname)
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except osv.except_osv, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(simplejson.dumps(error))
示例10: test_read_session_cookie
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_read_session_cookie():
class A(spa.Handler):
def get(self):
return spa.Response(self.request.environ['jwtsession']['foo'])
routes = (
('/', 'a', A),
)
app = spa.App(routes)
secret = 'foobar'
app = JWTSessionMiddleware(app, secret_key=secret)
c = Client(app, spa.Response)
c.set_cookie('localhost', 'session', jwt.encode({'foo': 'bar',
'iat': utc.now()}, secret))
resp = c.get('/')
assert resp.data == b'bar'
示例11: test_cookie_forging
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_cookie_forging(self):
c = Client(cookie_app)
c.set_cookie('localhost', 'foo', 'bar')
appiter, code, headers = c.open()
assert list(appiter) == ['foo=bar']
示例12: report_download
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = simplejson.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter='pdf')
#switch reportname with the evaluated attachment attribute of the action if available
docids = [int(i) for i in docids.split(',')]
report_obj = request.registry['report']
cr, uid, context = request.cr, request.uid, request.context
report = report_obj._get_report_from_name(cr, uid, reportname)
report_ename = "%s_" % (report.name)
obj = report_obj.pool[report.model].browse(cr, uid, docids[0])
if len(docids) > 1: # if more than one reports for printing
prefex = "(time.strftime('%d/%m/%Y')) + ('.pdf')"
else:
prefex_name = ""
try:
if obj.name:
prefex_name = "(object.name)+'_'"
except:
pass
prefex_state = ""
try:
if obj.state:
prefex_state = "'_'+(object.state)+'_'"
except:
pass
prefex = prefex_name + prefex_state + " + (time.strftime('%d/%m/%Y')) + ('.pdf')"
#_logger.warning("prefex : %s", prefex )
try:
reportname = eval(prefex, {'object': obj, 'time': time}).split('.pdf')[0]
except:
pass
reportname = report_ename
reportname = report_ename+reportname
# Remove all non-word characters (everything except numbers and letters)
reportname = re.sub(r"[^\w\s]", '', reportname)
# Replace all runs of whitespace with a single dash
reportname = re.sub(r"\s+", '-', reportname)
#_logger.warning("reportname-1 : %s", reportname )
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter='pdf', **dict(data))
#_logger.warning("reportname-2 : %s", reportname )
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname)
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(html_escape(simplejson.dumps(error)))
示例13: test_cookie_forging
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_cookie_forging():
c = Client(cookie_app)
c.set_cookie("localhost", "foo", "bar")
appiter, code, headers = c.open()
strict_eq(list(appiter), [b"foo=bar"])
示例14: test_cookie_forging
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_cookie_forging():
"""Test that cookie forging works."""
c = Client(cookie_app)
c.set_cookie('localhost', 'foo', 'bar')
appiter, code, headers = c.open()
assert list(appiter) == ['foo=bar']
示例15: test_cookie_forging
# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import set_cookie [as 别名]
def test_cookie_forging(self):
c = Client(cookie_app)
c.set_cookie('localhost', 'foo', 'bar')
appiter, code, headers = c.open()
self.assert_strict_equal(list(appiter), [b'foo=bar'])