本文整理汇总了Python中tools.tob函数的典型用法代码示例。如果您正苦于以下问题:Python tob函数的具体用法?Python tob怎么用?Python tob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
def tearDown(self):
while self.p.poll() is None:
os.kill(self.p.pid, signal.SIGINT)
time.sleep(0.1)
if self.p.poll() is None:
os.kill(self.p.pid, signal.SIGTERM)
for stream in (self.p.stdout, self.p.stderr):
for line in stream:
if tob('Warning') in line \
or tob('Error') in line or True:
print line.strip().decode('utf8')
示例2: test_default
def test_default(self):
""" WSGI: default routes """
@bottle.route('/')
def test2(): return 'test'
self.assertEqual(404, self.urlopen('/not/found').code)
self.assertEqual(200, self.urlopen('/').code)
self.assertEqual(tob('test'), self.urlopen('/').read())
@bottle.default()
def test(): return 'default'
self.assertEqual(200, self.urlopen('/not/found').code)
self.assertEqual(tob('default'), self.urlopen('/not/found').read())
self.assertEqual(200, self.urlopen('/').code)
self.assertEqual(tob('test'), self.urlopen('/').read())
示例3: test_headget
def test_headget(self):
""" WSGI: HEAD routes and GET fallback"""
@bottle.route('/get')
def test(): return 'test'
@bottle.route('/head', method='HEAD')
def test2(): return 'test'
# GET -> HEAD
self.assertEqual(404, self.urlopen('/head').code)
# HEAD -> HEAD
self.assertEqual(200, self.urlopen('/head', method='HEAD').code)
self.assertEqual(tob(''), self.urlopen('/head', method='HEAD').read())
# HEAD -> GET
self.assertEqual(200, self.urlopen('/get', method='HEAD').code)
self.assertEqual(tob(''), self.urlopen('/get', method='HEAD').read())
示例4: tearDown
def tearDown(self):
if self.skip: return
if self.p.poll() == None:
os.kill(self.p.pid, signal.SIGINT)
time.sleep(0.5)
while self.p.poll() == None:
os.kill(self.p.pid, signal.SIGTERM)
time.sleep(1)
for stream in (self.p.stdout, self.p.stderr):
for line in stream:
if tob('warning') in line.lower():
tools.warn(line.strip().decode('utf8'))
elif tob('error') in line.lower():
raise AssertionError(line.strip().decode('utf8'))
示例5: tearDown
def tearDown(self):
if self.skip: return
for i in range(10):
if self.p.poll() != None: break
os.kill(self.p.pid, signal.SIGINT)
time.sleep(0.1*i)
for i in range(10):
if self.p.poll() != None: break
os.kill(self.p.pid, signal.SIGINT)
time.sleep(i)
for stream in (self.p.stdout, self.p.stderr):
for line in stream:
if tob('warning') in line.lower():
tools.warn(line.strip().decode('utf8'))
elif tob('error') in line.lower():
raise AssertionError(line.strip().decode('utf8'))
示例6: test_post
def test_post(self):
""" WSGI: POST routes"""
@bottle.route('/', method='POST')
def test(): return 'test'
self.assertEqual(404, self.urlopen('/not/found').code)
self.assertEqual(404, self.urlopen('/').code)
self.assertEqual(tob('test'), self.urlopen('/', post="var=value").read())
示例7: test_303
def test_303(self):
""" WSGI: redirect (HTTP 303) """
@bottle.route('/')
def test(): bottle.redirect('/yes')
@bottle.route('/yes')
def test2(): return 'yes'
self.assertEqual(200, self.urlopen('/').code)
self.assertEqual(tob('yes'), self.urlopen('/').read())
示例8: testWithBottle
def testWithBottle(self):
bottle.app.push()
bottle.response.bind()
bottle.response.set_cookie('key', dict(value=5), secret=tob('1234'))
cheader = [v for k, v in bottle.response.wsgiheader() if k == 'Set-Cookie'][0]
bottle.request.bind({'HTTP_COOKIE': cheader.split(';')[0]})
self.assertEqual(repr(dict(value=5)), repr(bottle.request.get_cookie('key', secret=tob('1234'))))
bottle.app.pop()
示例9: test_casting
def test_casting(self):
""" WSGI: Output Casting (strings an lists) """
@bottle.route('/str')
def test(): return 'test'
self.assertEqual(tob('test'), self.urlopen('/str').read())
@bottle.route('/list')
def test2(): return ['t','e','st']
self.assertEqual(tob('test'), self.urlopen('/list').read())
@bottle.route('/empty')
def test3(): return []
self.assertEqual(tob(''), self.urlopen('/empty').read())
@bottle.route('/none')
def test4(): return None
self.assertEqual(tob(''), self.urlopen('/none').read())
@bottle.route('/bad')
def test5(): return 12345
self.assertEqual(500, self.urlopen('/bad').code)
示例10: test_view
def test_view(self):
""" WSGI: Test view-decorator (should override autojson) """
@bottle.route('/tpl')
@bottle.view('stpl_t2main')
def test():
return dict(content='1234')
result = tob('+base+\n+main+\n!1234!\n+include+\n-main-\n+include+\n-base-\n')
self.assertEqual('text/html; charset=UTF-8', self.urlopen('/tpl').info().get('Content-Type',''))
self.assertEqual(result, self.urlopen('/tpl').read())
示例11: test_validate
def test_validate(self):
""" WSGI: Test validate-decorator"""
@bottle.route('/:var')
@bottle.route('/')
@bottle.validate(var=int)
def test(var): return 'x' * var
self.assertEqual(403, self.urlopen('/noint').code)
self.assertEqual(403, self.urlopen('/').code)
self.assertEqual(200, self.urlopen('/5').code)
self.assertEqual(tob('xxx'), self.urlopen('/3').read())
示例12: test_401
def test_401(self):
""" WSGI: abort(401, '') (HTTP 401) """
@bottle.route('/')
def test(): bottle.abort(401)
self.assertEqual(401, self.urlopen('/').code)
@bottle.error(401)
def err(e):
bottle.response.status = 200
return str(type(e))
self.assertEqual(200, self.urlopen('/').code)
self.assertEqual(tob("<class 'bottle.HTTPError'>"), self.urlopen('/').read())
示例13: test_params
def test_params(self):
""" Environ: GET and POST are combined in request.param """
e = {}
wsgiref.util.setup_testing_defaults(e)
e['wsgi.input'].write(tob('b=b&c=p'))
e['wsgi.input'].seek(0)
e['CONTENT_LENGTH'] = '7'
e['QUERY_STRING'] = 'a=a&c=g'
e['REQUEST_METHOD'] = "POST"
request.bind(e, None)
self.assertEqual(['a','b','c'], sorted(request.params.keys()))
self.assertEqual('p', request.params['c'])
示例14: tearDown
def tearDown(self):
if self.skip: return
if self.p.poll() == None:
os.kill(self.p.pid, signal.SIGINT)
time.sleep(0.5)
if self.p.poll() == None:
os.kill(self.p.pid, signal.SIGTERM)
time.sleep(0.5)
while self.p.poll() == None:
tools.warn("Trying to kill server %r with pid %d." %
(self.server, self.p.pid))
os.kill(self.p.pid, signal.SIGKILL)
time.sleep(1)
lines = [line for stream in (self.p.stdout, self.p.stderr) for line in stream]
for line in lines:
if tob('warning') in line.lower():
tools.warn(line.strip().decode('utf8'))
elif tob('error') in line.lower():
raise AssertionError(line.strip().decode('utf8'))
示例15: setUp
def setUp(self):
self.data = dict(a=5, b=u'unicode', c=[1,2,3,4,tob('bytestring')])
self.key = tob('secret')