• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python webapp2.Request类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webapp2.Request的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_expr_variable

 def test_expr_variable(self):
     route = Route(r"/<year:\d{4}>", None)
     self.assertEqual(route.match(Request.blank("/bar")), None)
     self.assertEqual(route.match(Request.blank("/2010")), (None, (), {"year": "2010"}))
     self.assertEqual(route.match(Request.blank("/1900")), (None, (), {"year": "1900"}))
     url = route.build(Request.blank("/"), (), dict(year="2010"))
     self.assertEqual(url, "/2010")
开发者ID:strogo,项目名称:webapp-improved,代码行数:7,代码来源:test_routing.py


示例2: test_build_missing_argument

    def test_build_missing_argument(self):
        route = Route(r'/<:\d{4}>', None)
        self.assertRaises(KeyError, route.build, Request.blank('/'), (), {})

        route = Route(r'/<:\d{4}>/<:\d{2}>', None)
        self.assertRaises(
            KeyError, route.build, Request.blank('/'), (2010,), {})
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:7,代码来源:routing_test.py


示例3: test_build_extra_keyword

 def test_build_extra_keyword(self):
     route = Route(r'/<year:\d{4}>', None)
     url = route.build(Request.blank('/'), (), dict(year='2010', foo='bar'))
     self.assertEqual(url, '/2010?foo=bar')
     # Arguments are sorted.
     url = route.build(Request.blank('/'), (), dict(year='2010', foo='bar', baz='ding'))
     self.assertEqual(url, '/2010?baz=ding&foo=bar')
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:7,代码来源:test_router.py


示例4: test_build_default_keyword

    def test_build_default_keyword(self):
        route = Route(r"/<year:\d{4}>/<month:\d{2}>", None, defaults={"month": 10})
        url = route.build(Request.blank("/"), (), dict(year="2010"))
        self.assertEqual(url, "/2010/10")

        route = Route(r"/<year:\d{4}>/<month:\d{2}>", None, defaults={"year": 1900})
        url = route.build(Request.blank("/"), (), dict(month="07"))
        self.assertEqual(url, "/1900/07")
开发者ID:strogo,项目名称:webapp-improved,代码行数:8,代码来源:test_routing.py


示例5: test_simple_variable

 def test_simple_variable(self):
     route = Route(r'/<foo>', None)
     self.assertEqual(
         route.match(Request.blank('/bar')),
         (route, (), {'foo': 'bar'})
     )
     url = route.build(Request.blank('/'), (), dict(foo='baz'))
     self.assertEqual(url, '/baz')
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:8,代码来源:routing_test.py


示例6: test_build_with_unnamed_variable

    def test_build_with_unnamed_variable(self):
        route = Route(r"/<:\d{4}>/<month:\d{2}>", None)

        url = route.build(Request.blank("/"), (2010,), dict(month=10))
        self.assertEqual(url, "/2010/10")

        url = route.build(Request.blank("/"), ("1999",), dict(month="07"))
        self.assertEqual(url, "/1999/07")
开发者ID:strogo,项目名称:webapp-improved,代码行数:8,代码来源:test_routing.py


示例7: test_router_build_error

    def test_router_build_error(self):
        router = Router()
        router.add(Route('/<year:\d{4}>', None, name='year-page'))

        url = router.build('year-page', Request.blank('/'), (), dict(year='2010'))
        self.assertEqual(url, '/2010')

        self.assertRaises(KeyError, router.build, 'i-dont-exist', Request.blank('/'), (), dict(year='2010'))
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:8,代码来源:test_router.py


示例8: test_build_extra_positional_keyword

    def test_build_extra_positional_keyword(self):
        route = Route(r'/<year:\d{4}>/<:\d{2}>', None)

        url = route.build(Request.blank('/'), ('08', 'i-should-be-ignored', 'me-too'), dict(year='2010', foo='bar'))
        self.assertEqual(url, '/2010/08?foo=bar')

        url = route.build(Request.blank('/'), ('08', 'i-should-be-ignored', 'me-too'), dict(year='2010', foo='bar', baz='ding'))
        self.assertEqual(url, '/2010/08?baz=ding&foo=bar')
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:8,代码来源:test_router.py


示例9: test_router_build_error

    def test_router_build_error(self):
        router = Router(None)
        router.add(Route("/<year:\d{4}>", None, name="year-page"))

        url = router.build("year-page", Request.blank("/"), (), dict(year="2010"))
        self.assertEqual(url, "/2010")

        self.assertRaises(KeyError, router.build, "i-dont-exist", Request.blank("/"), (), dict(year="2010"))
开发者ID:strogo,项目名称:webapp-improved,代码行数:8,代码来源:test_routing.py


示例10: test_repetition_operator

    def test_repetition_operator(self):
        route = Route(r'/<:\d>', None)
        self.assertEqual(route.match(Request.blank('/1')), (None, ('1',), {}))
        self.assertEqual(route.match(Request.blank('/2')), (None, ('2',), {}))

        route = Route(r'/<:\d{2,3}>', None)
        self.assertEqual(route.match(Request.blank('/11')), (None, ('11',), {}))
        self.assertEqual(route.match(Request.blank('/111')), (None, ('111',), {}))
        self.assertEqual(route.match(Request.blank('/1111')), None)
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:9,代码来源:test_router.py


示例11: test_build_default_keyword

    def test_build_default_keyword(self):
        route = Route(r'/<year:\d{4}>/<month:\d{2}>', None,
            defaults={'month': 10})
        url = route.build(Request.blank('/'), (), dict(year='2010'))
        self.assertEqual(url, '/2010/10')

        route = Route(r'/<year:\d{4}>/<month:\d{2}>', None,
            defaults={'year': 1900})
        url = route.build(Request.blank('/'), (), dict(month='07'))
        self.assertEqual(url, '/1900/07')
开发者ID:Arachnid,项目名称:webapp-improved,代码行数:10,代码来源:test_router.py


示例12: test_build_extra_positional_keyword

    def test_build_extra_positional_keyword(self):
        route = Route(r"/<year:\d{4}>/<:\d{2}>", None)

        url = route.build(Request.blank("/"), ("08", "i-should-be-ignored", "me-too"), dict(year="2010", foo="bar"))
        self.assertEqual(url, "/2010/08?foo=bar")

        url = route.build(
            Request.blank("/"), ("08", "i-should-be-ignored", "me-too"), dict(year="2010", foo="bar", baz="ding")
        )
        self.assertEqual(url, "/2010/08?baz=ding&foo=bar")
开发者ID:strogo,项目名称:webapp-improved,代码行数:10,代码来源:test_routing.py


示例13: test_c_post_count

    def test_c_post_count(self):
        self._create_config()

        memcache.set('already_donated', 0)
        memcache.set('already_clicked', 0)
        memcache.set('eur_goal', 1)

        # all values should still be 0 after request from inside
        uri = '/c?domain=' + self.domain + '&from=inside'
        body = '{"clicks":0, "donated":0.0, "unlocked": 0.0, "percent":0.0, "increment": %f}' % EUR_INCREMENT
        self._test_c_post(uri, body)

        # from == outside, no previous visit, with current timestamp increases counter
        now = int(time.time() * 1000)
        current_time = "%d" % now
        uri = '/c?domain=' + self.domain + '&from=outside&pt=&ct=' + current_time
        body = '{"clicks":1, "donated":0.0, "unlocked": %f, "percent":%f, "increment": %f}' % (EUR_INCREMENT, EUR_INCREMENT, EUR_INCREMENT)
        self._test_c_post(uri, body)

        # from == outside, previous visit 1 second before current timestamp does not increase counter
        uri = '/c?domain=' + self.domain + '&from=outside&pt=' + ("%s" % (now - 1)) + '&ct=' + current_time
        self._test_c_post(uri, body)

        # from == outside, previous visit before current timestamp increases counter
        uri = '/c?domain=' + self.domain + '&from=outside&pt=' + (
            "%s" % (now - COUNT_THRESHOLD)) + '&ct=' + current_time
        body = '{"clicks":2, "donated":0.0, "unlocked": %f, "percent":%f, "increment": %f}' % (2 * EUR_INCREMENT, 2 * EUR_INCREMENT, EUR_INCREMENT)
        self._test_c_post(uri, body)

        self.assertEquals(2, memcache.get('clicks_total'))
        d = models.Domain()
        d.name = self.domain
        self.assertEquals(2, memcache.get(jobs.get_cache_key(d)))

        # Pre-cron
        domain = models.Domain.query(models.Domain.name == str(self.domain)).get()
        self.assertEquals(0, domain.clickcount)
        count = models.ClickcountDate.query().get()
        self.assertTrue(count is None)

        # Execute memcount cron
        request = Request.blank('/task/counter/persist', headers=[('X-AppEngine-Cron', 'true')])
        request.method = 'GET'
        request.get_response(application)
        domain = models.Domain.query(models.Domain.name == str(self.domain)).get()
        self.assertEquals(2, domain.clickcount)

        # Execute total cron
        request = Request.blank('/task/total/persist', headers=[('X-AppEngine-Cron', 'true')])
        request.method = 'GET'
        request.get_response(application)
        count = models.ClickcountDate.query().get()
        self.assertEquals(2, count.clickcount)
        self.assertEquals(datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"), count.time.strftime("%Y-%m-%dT%H:%M:%S"))
开发者ID:dothiv,项目名称:clickcounter-backend,代码行数:54,代码来源:tests.py


示例14: test_no_variable

    def test_no_variable(self):
        route = Route(r"/hello", None)
        handler, args, kwargs = route.match(Request.blank("/hello"))
        self.assertEqual(kwargs, {})
        url = route.build(Request.blank("/"), (), {})
        self.assertEqual(url, "/hello")

        route = Route(r"/hello/world/", None)
        handler, args, kwargs = route.match(Request.blank("/hello/world/"))
        self.assertEqual(kwargs, {})
        url = route.build(Request.blank("/"), (), {})
        self.assertEqual(url, "/hello/world/")
开发者ID:strogo,项目名称:webapp-improved,代码行数:12,代码来源:test_routing.py


示例15: test_schemes

    def test_schemes(self):
        route = Route(r'/', schemes=['http'])
        req = Request.blank('http://mydomain.com/')
        self.assertTrue(route.match(req) is not None)
        req = Request.blank('https://mydomain.com/')
        self.assertTrue(route.match(req) is None)

        route = Route(r'/', schemes=['https'])
        req = Request.blank('https://mydomain.com/')
        self.assertTrue(route.match(req) is not None)
        req = Request.blank('http://mydomain.com/')
        self.assertTrue(route.match(req) is None)
开发者ID:karlwmacmillan,项目名称:webapp2,代码行数:12,代码来源:routing_test.py


示例16: testRequestParser_type_is_bool

    def testRequestParser_type_is_bool(self):
        import decimal

        parser = RequestParser()
        parser.add_argument("foo", type=bool)

        args = parser.parse_args(Request.blank('/stam?foo=true'))
        self.assertEquals(args['foo'], True)

        args = parser.parse_args(Request.blank('/stam?foo=True'))
        self.assertEquals(args['foo'], True)

        args = parser.parse_args(Request.blank('/stam?foo=t'))
        self.assertEquals(args['foo'], True)

        args = parser.parse_args(Request.blank('/stam?foo=1'))
        self.assertEquals(args['foo'], True)

        args = parser.parse_args(Request.blank('/stam?foo=f'))
        self.assertEquals(args['foo'], False)

        args = parser.parse_args(Request.blank('/stam?foo=0'))
        self.assertEquals(args['foo'], False)

        args = parser.parse_args(Request.blank('/stam?foo=false'))
        self.assertEquals(args['foo'], False)

        args = parser.parse_args(Request.blank('/stam?foo=False'))
        self.assertEquals(args['foo'], False)
开发者ID:ekampf,项目名称:webapp2_restful,代码行数:29,代码来源:test_request_parser.py


示例17: test_int_range_choice_types

    def test_int_range_choice_types(self):
        parser = RequestParser()
        parser.add_argument("foo", type=int, choices=range(100), location='json')

        req = Request.blank('/stam', POST=json.dumps(dict(foo=101)), environ={
            'CONTENT_TYPE': 'application/json;"',
        })
        self.assertRaises(InvalidParameterValue, parser.parse_args, req)

        req = Request.blank('/stam', POST=json.dumps(dict(foo=99)), environ={
            'CONTENT_TYPE': 'application/json;"',
        })
        args = parser.parse_args(req)
        self.assertEqual(99, args.get('foo'))
开发者ID:ekampf,项目名称:webapp2_restful,代码行数:14,代码来源:test_request_parser.py


示例18: testRequestParser_choices

    def testRequestParser_choices(self):
        req = Request.blank("/bubble?foo=bar")

        parser = RequestParser()
        parser.add_argument("foo", choices=["bat"]),

        self.assertRaises(InvalidParameterValue, lambda: parser.parse_args(req))
开发者ID:ekampf,项目名称:webapp2_restful,代码行数:7,代码来源:test_request_parser.py


示例19: _test_c_post

 def _test_c_post(self, uri, body):
   """Helper to actually test posting to /c, depending on uri and body."""
   request = Request.blank(uri, headers=[self.auth_header])
   request.method = 'POST'
   response = request.get_response(application)
   self.assertEqual(response.status_int, 200)
   self.assertEqual(response.body, body)
开发者ID:sebtesobe,项目名称:clickcounter-backend,代码行数:7,代码来源:tests.py


示例20: testFormWithPOSTData

	def testFormWithPOSTData(self):
		request = Request.blank('/', POST={'id_twitter_user':'twitter_user_value', 'id_delicious_user':'delicious_user_value','id_delicious_password':'delicious_password_value'})
		form = self.UserSettingsForm(request.POST)

		formContents = form.render()
		self.assertTrue(form.clean_data['twitter_user'], 'twitter_user_value')
		self.assertTrue(form.clean_data['delicious_user'], 'delicious_user_value')
开发者ID:oscarrenalias,项目名称:parklife,代码行数:7,代码来源:forms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python webapp2.Route类代码示例发布时间:2022-05-26
下一篇:
Python webapp2.Config类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap