本文整理汇总了Python中bottle.BaseRequest类的典型用法代码示例。如果您正苦于以下问题:Python BaseRequest类的具体用法?Python BaseRequest怎么用?Python BaseRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseRequest类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remote_addr
def test_remote_addr(self):
ips = ['1.2.3.4', '2.3.4.5', '3.4.5.6']
r = BaseRequest({})
self.assertEqual(r.remote_addr, None)
r.environ['HTTP_X_FORWARDED_FOR'] = ', '.join(ips)
self.assertEqual(r.remote_addr, ips[0])
r.environ['REMOTE_ADDR'] = ips[1]
self.assertEqual(r.remote_addr, ips[0])
del r.environ['HTTP_X_FORWARDED_FOR']
self.assertEqual(r.remote_addr, ips[1])
示例2: test_auth
def test_auth(self):
user, pwd = 'marc', 'secret'
basic = touni(base64.b64encode(tob('%s:%s' % (user, pwd))))
r = BaseRequest({})
self.assertEqual(r.auth, None)
r.environ['HTTP_AUTHORIZATION'] = 'basic %s' % basic
self.assertEqual(r.auth, (user, pwd))
r.environ['REMOTE_USER'] = user
self.assertEqual(r.auth, (user, pwd))
del r.environ['HTTP_AUTHORIZATION']
self.assertEqual(r.auth, (user, None))
示例3: test_maxparam
def test_maxparam(self):
ips = ['1.2.3.4', '2.3.4.5', '3.4.5.6']
e = {}
wsgiref.util.setup_testing_defaults(e)
e['wsgi.input'].write(tob('a=a&b=b&c=c'))
e['wsgi.input'].seek(0)
e['CONTENT_LENGTH'] = '11'
e['REQUEST_METHOD'] = "POST"
e['HTTP_COOKIE'] = 'a=1,b=1,c=1;d=1'
e['QUERY_STRING'] = 'a&b&c&d'
r = BaseRequest(e)
r.MAX_PARAMS = 2
self.assertEqual(len(list(r.query.allitems())), 2)
self.assertEqual(len(list(r.cookies.allitems())), 2)
self.assertEqual(len(list(r.forms.allitems())), 2)
self.assertEqual(len(list(r.params.allitems())), 4)