本文整理汇总了Python中meresco.html.DynamicHtml.handleRequest方法的典型用法代码示例。如果您正苦于以下问题:Python DynamicHtml.handleRequest方法的具体用法?Python DynamicHtml.handleRequest怎么用?Python DynamicHtml.handleRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meresco.html.DynamicHtml
的用法示例。
在下文中一共展示了DynamicHtml.handleRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReloadImportedModules
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testReloadImportedModules(self):
reactor = Reactor()
open(self.tempdir + '/file1.sf', 'w').write("""
def main(value, *args, **kwargs):
return "original template %s" % value
""")
open(self.tempdir + '/file2.sf', 'w').write("""
import file1
def main(*args, **kwargs):
yield file1.main(value='word!', *args, **kwargs)
""")
d = DynamicHtml([self.tempdir], reactor=reactor)
result = ''.join(d.handleRequest(scheme='http', netloc='host.nl', path='/file2'))
self.assertTrue('original template word!' in result, result)
open(self.tempdir + '/file1.sf', 'w').write("""
def main(value, *args, **kwargs):
return "changed template %s" % value
""")
reactor.step()
result = ''.join(d.handleRequest(scheme='http', netloc='host.nl', path='/file2'))
self.assertTrue('changed template word!' in result, result)
示例2: testImportForeignModules
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testImportForeignModules(self):
reactor = Reactor()
open(self.tempdir + '/file1.sf', 'w').write("""
import sys
def main(headers={}, *args, **kwargs):
yield str(sys)
""")
d = DynamicHtml([self.tempdir], reactor=reactor, allowedModules=['sys'])
result = d.handleRequest(scheme='http', netloc='host.nl', path='/file1', query='?query=something', fragments='#fragments', arguments={'query': 'something'})
resultText = ''.join(result)
self.assertTrue("<module 'sys' (built-in)>" in resultText, resultText)
open(self.tempdir + '/file1.sf', 'w').write("""
import sys
def main(headers={}, *args, **kwargs):
yield sys.__doc__
""")
reactor.step()
result = ''.join(d.handleRequest(scheme='http', netloc='host.nl', path='/file1', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
self.assertTrue('This module provides access to some objects' in result, result)
示例3: testFileMovedIntoDirectoryCausesReload
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testFileMovedIntoDirectoryCausesReload(self):
reactor = Reactor()
open('/tmp/file1.sf', 'w').write('def main(*args, **kwargs): \n yield "one"')
d = DynamicHtml([self.tempdir], reactor=reactor)
result = asString(d.handleRequest(scheme='http', netloc='host.nl', path='/file1', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
self.assertEquals('HTTP/1.0 404 Not Found\r\nContent-Type: text/html; charset=utf-8\r\n\r\nFile "file1" does not exist.', result)
rename('/tmp/file1.sf', self.tempdir+'/file1.sf')
reactor.step()
result = d.handleRequest(scheme='http', netloc='host.nl', path='/file1', query='?query=something', fragments='#fragments', arguments={'query': 'something'})
self.assertEquals('HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\none', ''.join(result))
示例4: testModifyFileCausesReload
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testModifyFileCausesReload(self):
reactor = Reactor()
open(self.tempdir+'/file1.sf', 'w').write('def main(*args, **kwargs): \n yield "one"')
d = DynamicHtml([self.tempdir], reactor=reactor)
result = d.handleRequest(scheme='http', netloc='host.nl', path='/file1', query='?query=something', fragments='#fragments', arguments={'query': 'something'})
self.assertEquals('HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\none', ''.join(result))
open(self.tempdir+'/file1.sf', 'w').write('def main(*args, **kwargs): \n yield "two"')
reactor.step()
result = d.handleRequest(scheme='http', netloc='host.nl', path='/file1', query='?query=something', fragments='#fragments', arguments={'query': 'something'})
self.assertEquals('HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\ntwo', ''.join(result))
示例5: testImportFromSecondPath
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testImportFromSecondPath(self):
reactor = Reactor()
path1, path2 = self.createTwoPaths()
open(join(path2, 'one.sf'), 'w').write('def main(*args,**kwargs):\n yield "one"')
open(join(path1, 'page.sf'), 'w').write('import one\ndef main(*args,**kwargs):\n yield one.main(*args,**kwargs)')
d = DynamicHtml([path1, path2], reactor=reactor)
result = ''.join(d.handleRequest(path='/page'))
header, body = result.split('\r\n\r\n')
self.assertEquals('one', body)
open(join(path2, 'one.sf'), 'w').write('def main(*args,**kwargs):\n yield "two"')
reactor.step()
result = ''.join(d.handleRequest(path='/page'))
header, body = result.split('\r\n\r\n')
self.assertEquals('two', body)
示例6: testFirstDirectoryHasTheRightFileButSecondFileChanges
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testFirstDirectoryHasTheRightFileButSecondFileChanges(self):
reactor = Reactor()
path1, path2 = self.createTwoPaths()
open(join(path1, 'page.sf'), 'w').write('def main(*args,**kwargs):\n yield "one"')
open(join(path2, 'page.sf'), 'w').write('def main(*args,**kwargs):\n yield "two"')
d = DynamicHtml([path1, path2], reactor=reactor)
result = ''.join(d.handleRequest(path='/page'))
header, body = result.split('\r\n\r\n')
self.assertEquals('one', body)
open(join(path2, 'page.sf'), 'w').write('def main(*args,**kwargs):\n yield "three"')
reactor.step()
result = ''.join(d.handleRequest(path='/page'))
header, body = result.split('\r\n\r\n')
self.assertEquals('one', body)
示例7: testMoreDirectories
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testMoreDirectories(self):
path1, path2 = self.createTwoPaths()
open(join(path2, 'page.sf'), 'w').write('def main(*args,**kwargs):\n yield "page"')
d = DynamicHtml([path1, path2], reactor=CallTrace('Reactor'))
result = ''.join(d.handleRequest(path='/page'))
header, body = result.split('\r\n\r\n')
self.assertEquals('page', body)
示例8: testObservability
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testObservability(self):
onces = []
dos = []
class Something(object):
def callSomething(self, *args, **kwargs):
return "call"
def allSomething(self, *args, **kwargs):
yield "all"
def anySomething(self, *args, **kwargs):
yield "any"
raise StopIteration('retval')
def doSomething(self, *args, **kwargs):
dos.append(True)
def onceSomething(self, *args, **kwargs):
onces.append(True)
open(self.tempdir+'/afile.sf', 'w').write("""#
def main(*args, **kwargs):
result = observable.call.callSomething()
yield result
yield observable.all.allSomething()
result = yield observable.any.anySomething()
assert result == 'retval'
observable.do.doSomething()
yield observable.once.onceSomething()
""")
d = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
d.addObserver(Something())
result = d.handleRequest(scheme='http', netloc='host.nl', path='/afile', query='?query=something', fragments='#fragments', arguments={'query': 'something'})
self.assertEquals('HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\ncallallany', ''.join(result))
self.assertEquals([True], dos)
self.assertEquals([True], onces)
示例9: testFileNotFound2
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testFileNotFound2(self):
with open(join(self.tempdir, 'a.sf'), 'w') as f:
f.write('def main(pipe, **kwargs):\n yield pipe')
d = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
result = asString(d.handleRequest(scheme='http', netloc='host.nl', path='/a/path', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
self.assertTrue(result.startswith('HTTP/1.0 404 Not Found'), result)
self.assertTrue('File "path" does not exist.' in result, result)
示例10: processTemplate
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def processTemplate(self, template):
# print '>>>', template
open(self.tempdir+'/afile.sf', 'w').write(template)
d = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
header, body = parseResponse(asString(d.handleRequest(path='/afile')))
if header['StatusCode'] != '200':
print body
return body
示例11: testIndexPage
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testIndexPage(self):
reactor = Reactor()
d = DynamicHtml([self.tempdir], reactor=reactor)
result = asString(d.handleRequest(path='/'))
headers, message = result.split('\r\n\r\n')
self.assertEquals('File "" does not exist.', message)
reactor = Reactor()
d = DynamicHtml([self.tempdir], reactor=reactor, indexPage='/page')
result = asString(d.handleRequest(path='/'))
headers, message = result.split('\r\n\r\n')
self.assertEquals('HTTP/1.0 302 Found\r\nLocation: /page', headers)
reactor = Reactor()
d = DynamicHtml([self.tempdir], reactor=reactor, indexPage='/page')
result = asString(d.handleRequest(path='/', arguments={'a':['1']}))
headers, message = result.split('\r\n\r\n')
self.assertEquals('HTTP/1.0 302 Found\r\nLocation: /page?a=1', headers)
示例12: testNotFound_HeadExistButHasNoMain
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testNotFound_HeadExistButHasNoMain(self):
open(self.tempdir + '/page.sf', 'w').write("""""")
open(self.tempdir + '/_missing.sf', 'w').write("""
def main(**kw):
yield 'not-found'
""")
reactor = Reactor()
# /page
d = DynamicHtml([self.tempdir], reactor=reactor, notFoundPage='/_missing')
result = d.handleRequest(scheme='http', netloc='host.nl', path='/page')
headers, message = ''.join(result).split('\r\n\r\n')
self.assertEquals('not-found', message)
# /page/does-not-exist
d = DynamicHtml([self.tempdir], reactor=reactor, notFoundPage='/_missing')
result = d.handleRequest(scheme='http', netloc='host.nl', path='/page/does-not-exist')
headers, message = ''.join(result).split('\r\n\r\n')
self.assertEquals('not-found', message)
示例13: testRedirectWithAdditionalHeaders
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testRedirectWithAdditionalHeaders(self):
open(self.tempdir + '/page.sf', 'w').write(r"""
def main(*args, **kwargs):
yield http.redirect('/here', additionalHeaders={'Pragma': 'no-cache', 'Expires': '0'})
""")
reactor = Reactor()
d = DynamicHtml([self.tempdir], reactor=reactor)
result = ''.join(d.handleRequest(scheme='http', netloc='host.nl', path='/page'))
self.assertEquals('HTTP/1.0 302 Found\r\nExpires: 0\r\nLocation: /here\r\nPragma: no-cache\r\n\r\n', result)
示例14: testChangingFileBeforeRetrievingFirstPage
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testChangingFileBeforeRetrievingFirstPage(self):
reactor = Reactor()
open(join(self.tempdir, 'one.sf'), 'w').write('def main(*args,**kwargs):\n yield "one"')
open(join(self.tempdir, 'two.sf'), 'w').write('def main(*args,**kwargs):\n yield "two"')
d = DynamicHtml([self.tempdir], reactor=reactor)
open(join(self.tempdir, 'one.sf'), 'w').write('def main(*args,**kwargs):\n yield "one++"')
reactor.step()
header, body = ''.join(d.handleRequest(path='/two')).split('\r\n'*2)
self.assertEquals('two', body)
示例15: testIgnoreNonSFExtensions
# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import handleRequest [as 别名]
def testIgnoreNonSFExtensions(self):
open(self.tempdir + '/page.otherextension.sf', 'w').write("""
def main(*args, **kwargs):
yield "should not happen"
""")
reactor = Reactor()
d = DynamicHtml([self.tempdir], reactor=reactor)
result = asString(d.handleRequest(scheme='http', netloc='host.nl', path='/page'))
self.assertTrue('should not happen' not in result, result)