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


Python Client.set_cookie方法代码示例

本文整理汇总了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('/')
开发者ID:btubbs,项目名称:spa,代码行数:28,代码来源:test_session.py

示例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)))
开发者ID:MartinHeisig,项目名称:euratel-addons,代码行数:57,代码来源:controllers.py

示例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)))
开发者ID:shivam1111,项目名称:jjuice_addons,代码行数:55,代码来源:main.py

示例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)))
开发者ID:0967697922,项目名称:odoo,代码行数:54,代码来源:main.py

示例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)))
开发者ID:kevin8909,项目名称:pdf_print,代码行数:54,代码来源:pdf_print.py

示例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
开发者ID:btubbs,项目名称:spa,代码行数:15,代码来源:test_csrf.py

示例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
开发者ID:btubbs,项目名称:spa,代码行数:15,代码来源:test_csrf.py

示例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)))
开发者ID:Padmahas,项目名称:odoo,代码行数:47,代码来源:main.py

示例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))
开发者ID:Alan1590,项目名称:odoo-1,代码行数:46,代码来源:main.py

示例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'
开发者ID:btubbs,项目名称:spa,代码行数:22,代码来源:test_session.py

示例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']
开发者ID:0xJCG,项目名称:dubtrack-technical-test,代码行数:7,代码来源:test.py

示例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)))
开发者ID:straga,项目名称:odoo_vik_main,代码行数:100,代码来源:report_file_name.py

示例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"])
开发者ID:pallets,项目名称:werkzeug,代码行数:7,代码来源:test_test.py

示例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']
开发者ID:Fak3,项目名称:werkzeug,代码行数:8,代码来源:test_test.py

示例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'])
开发者ID:poffdeluxe,项目名称:werkzeug,代码行数:7,代码来源:test.py


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