本文整理匯總了Python中cherrypy.org方法的典型用法代碼示例。如果您正苦於以下問題:Python cherrypy.org方法的具體用法?Python cherrypy.org怎麽用?Python cherrypy.org使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cherrypy
的用法示例。
在下文中一共展示了cherrypy.org方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: response_namespace
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def response_namespace(k, v):
"""Attach response attributes declared in config."""
# Provides config entries to set default response headers
# http://cherrypy.org/ticket/889
if k[:8] == 'headers.':
cherrypy.serving.response.headers[k.split('.', 1)[1]] = v
else:
setattr(cherrypy.serving.response, k, v)
示例2: testAbsoluteURIPathInfo
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def testAbsoluteURIPathInfo(self):
# http://cherrypy.org/ticket/1061
self.getPage('http://localhost/pathinfo/foo/bar')
self.assertBody('/pathinfo/foo/bar')
示例3: testAbsoluteURIPathInfo
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def testAbsoluteURIPathInfo(self):
# http://cherrypy.org/ticket/1061
self.getPage("http://localhost/pathinfo/foo/bar")
self.assertBody("/pathinfo/foo/bar")
示例4: test_repeated_headers
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def test_repeated_headers(self):
# Test that two request headers are collapsed into one.
# See http://www.cherrypy.org/ticket/542.
self.getPage("/headers/Accept-Charset",
headers=[("Accept-Charset", "iso-8859-5"),
("Accept-Charset", "unicode-1-1;q=0.8")])
self.assertBody("iso-8859-5, unicode-1-1;q=0.8")
# Tests that each header only appears once, regardless of case.
self.getPage("/headers/doubledheaders")
self.assertBody("double header test")
hnames = [name.title() for name, val in self.headers]
for key in ['Content-Length', 'Content-Type', 'Date',
'Expires', 'Location', 'Server']:
self.assertEqual(hnames.count(key), 1, self.headers)
示例5: testParams
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def testParams(self):
self.getPage('/params/?thing=a')
self.assertBody(repr(ntou('a')))
self.getPage('/params/?thing=a&thing=b&thing=c')
self.assertBody(repr([ntou('a'), ntou('b'), ntou('c')]))
# Test friendly error message when given params are not accepted.
cherrypy.config.update({'request.show_mismatched_params': True})
self.getPage('/params/?notathing=meeting')
self.assertInBody('Missing parameters: thing')
self.getPage('/params/?thing=meeting¬athing=meeting')
self.assertInBody('Unexpected query string parameters: notathing')
# Test ability to turn off friendly error messages
cherrypy.config.update({'request.show_mismatched_params': False})
self.getPage('/params/?notathing=meeting')
self.assertInBody('Not Found')
self.getPage('/params/?thing=meeting¬athing=meeting')
self.assertInBody('Not Found')
# Test "% HEX HEX"-encoded URL, param keys, and values
self.getPage('/params/%d4%20%e3/cheese?Gruy%E8re=Bulgn%e9ville')
self.assertBody('args: %s kwargs: %s' %
(('\xd4 \xe3', 'cheese'),
[('Gruy\xe8re', ntou('Bulgn\xe9ville'))]))
# Make sure that encoded = and & get parsed correctly
self.getPage(
'/params/code?url=http%3A//cherrypy.org/index%3Fa%3D1%26b%3D2')
self.assertBody('args: %s kwargs: %s' %
(('code',),
[('url', ntou('http://cherrypy.org/index?a=1&b=2'))]))
# Test coordinates sent by <img ismap>
self.getPage('/params/ismap?223,114')
self.assertBody('Coordinates: 223, 114')
# Test "name[key]" dict-like params
self.getPage('/params/dictlike?a[1]=1&a[2]=2&b=foo&b[bar]=baz')
self.assertBody('args: %s kwargs: %s' %
(('dictlike',),
[('a[1]', ntou('1')), ('a[2]', ntou('2')),
('b', ntou('foo')), ('b[bar]', ntou('baz'))]))
示例6: testParams
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def testParams(self):
self.getPage("/params/?thing=a")
self.assertBody(repr(ntou("a")))
self.getPage("/params/?thing=a&thing=b&thing=c")
self.assertBody(repr([ntou('a'), ntou('b'), ntou('c')]))
# Test friendly error message when given params are not accepted.
cherrypy.config.update({"request.show_mismatched_params": True})
self.getPage("/params/?notathing=meeting")
self.assertInBody("Missing parameters: thing")
self.getPage("/params/?thing=meeting¬athing=meeting")
self.assertInBody("Unexpected query string parameters: notathing")
# Test ability to turn off friendly error messages
cherrypy.config.update({"request.show_mismatched_params": False})
self.getPage("/params/?notathing=meeting")
self.assertInBody("Not Found")
self.getPage("/params/?thing=meeting¬athing=meeting")
self.assertInBody("Not Found")
# Test "% HEX HEX"-encoded URL, param keys, and values
self.getPage("/params/%d4%20%e3/cheese?Gruy%E8re=Bulgn%e9ville")
self.assertBody("args: %s kwargs: %s" %
(('\xd4 \xe3', 'cheese'),
{'Gruy\xe8re': ntou('Bulgn\xe9ville')}))
# Make sure that encoded = and & get parsed correctly
self.getPage("/params/code?url=http%3A//cherrypy.org/index%3Fa%3D1%26b%3D2")
self.assertBody("args: %s kwargs: %s" %
(('code',),
{'url': ntou('http://cherrypy.org/index?a=1&b=2')}))
# Test coordinates sent by <img ismap>
self.getPage("/params/ismap?223,114")
self.assertBody("Coordinates: 223, 114")
# Test "name[key]" dict-like params
self.getPage("/params/dictlike?a[1]=1&a[2]=2&b=foo&b[bar]=baz")
self.assertBody("args: %s kwargs: %s" %
(('dictlike',),
{'a[1]': ntou('1'), 'b[bar]': ntou('baz'),
'b': ntou('foo'), 'a[2]': ntou('2')}))
示例7: testHeaderElements
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import org [as 別名]
def testHeaderElements(self):
# Accept-* header elements should be sorted, with most preferred first.
h = [('Accept', 'audio/*; q=0.2, audio/basic')]
self.getPage("/headerelements/get_elements?headername=Accept", h)
self.assertStatus(200)
self.assertBody("audio/basic\n"
"audio/*;q=0.2")
h = [('Accept', 'text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c')]
self.getPage("/headerelements/get_elements?headername=Accept", h)
self.assertStatus(200)
self.assertBody("text/x-c\n"
"text/html\n"
"text/x-dvi;q=0.8\n"
"text/plain;q=0.5")
# Test that more specific media ranges get priority.
h = [('Accept', 'text/*, text/html, text/html;level=1, */*')]
self.getPage("/headerelements/get_elements?headername=Accept", h)
self.assertStatus(200)
self.assertBody("text/html;level=1\n"
"text/html\n"
"text/*\n"
"*/*")
# Test Accept-Charset
h = [('Accept-Charset', 'iso-8859-5, unicode-1-1;q=0.8')]
self.getPage("/headerelements/get_elements?headername=Accept-Charset", h)
self.assertStatus("200 OK")
self.assertBody("iso-8859-5\n"
"unicode-1-1;q=0.8")
# Test Accept-Encoding
h = [('Accept-Encoding', 'gzip;q=1.0, identity; q=0.5, *;q=0')]
self.getPage("/headerelements/get_elements?headername=Accept-Encoding", h)
self.assertStatus("200 OK")
self.assertBody("gzip;q=1.0\n"
"identity;q=0.5\n"
"*;q=0")
# Test Accept-Language
h = [('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7')]
self.getPage("/headerelements/get_elements?headername=Accept-Language", h)
self.assertStatus("200 OK")
self.assertBody("da\n"
"en-gb;q=0.8\n"
"en;q=0.7")
# Test malformed header parsing. See http://www.cherrypy.org/ticket/763.
self.getPage("/headerelements/get_elements?headername=Content-Type",
# Note the illegal trailing ";"
headers=[('Content-Type', 'text/html; charset=utf-8;')])
self.assertStatus(200)
self.assertBody("text/html;charset=utf-8")