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

Python html.DynamicHtml类代码示例

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

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



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

示例1: testReloadImportedModules

    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)
开发者ID:seecr,项目名称:meresco-html,代码行数:26,代码来源:dynamichtmltest.py


示例2: testFileNotFound2

 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)
开发者ID:seecr,项目名称:meresco-html,代码行数:7,代码来源:dynamichtmltest.py


示例3: testObservability

    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)
开发者ID:seecr,项目名称:meresco-html,代码行数:33,代码来源:dynamichtmltest.py


示例4: testMoreDirectories

 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)
开发者ID:seecr,项目名称:meresco-html,代码行数:7,代码来源:dynamichtmltest.py


示例5: testImportForeignModules

    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)
开发者ID:seecr,项目名称:meresco-html,代码行数:25,代码来源:dynamichtmltest.py


示例6: testImportFromFirstPath

 def testImportFromFirstPath(self):
     path1, path2 = self.createTwoPaths()
     open(join(path2, 'page.sf'), 'w').write('import one\ndef main(*args,**kwargs):\n yield one.main(*args,**kwargs)')
     open(join(path1, 'one.sf'), 'w').write('def main(*args,**kwargs):\n yield "one"')
     d = DynamicHtml([path1, path2], reactor=CallTrace('Reactor'))
     result = ''.join(d.handleRequest(path='/page'))
     header, body = result.split('\r\n\r\n')
     self.assertEquals('one', body)
开发者ID:seecr,项目名称:meresco-html,代码行数:8,代码来源:dynamichtmltest.py


示例7: processTemplate

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
开发者ID:seecr,项目名称:meresco-html,代码行数:8,代码来源:htmltotagtest.py


示例8: testRedirect

    def testRedirect(self):
        open(self.tempdir + '/page.sf', 'w').write(r"""
def main(*args, **kwargs):
    yield http.redirect('/here')
""")
        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\nLocation: /here\r\n\r\n', result)
开发者ID:seecr,项目名称:meresco-html,代码行数:9,代码来源:dynamichtmltest.py


示例9: testRedirectWithAdditionalHeaders

    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)
开发者ID:seecr,项目名称:meresco-html,代码行数:9,代码来源:dynamichtmltest.py


示例10: testChangingFileBeforeRetrievingFirstPage

 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)
开发者ID:seecr,项目名称:meresco-html,代码行数:9,代码来源:dynamichtmltest.py


示例11: testCreateFileCausesReload

    def testCreateFileCausesReload(self):
        reactor = Reactor()

        d = DynamicHtml([self.tempdir], reactor=reactor)
        open(self.tempdir+'/file1.sf', 'w').write('def main(*args, **kwargs): \n  yield "one"')
        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))
开发者ID:seecr,项目名称:meresco-html,代码行数:9,代码来源:dynamichtmltest.py


示例12: testIgnoreNonSFExtensions

    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)
开发者ID:seecr,项目名称:meresco-html,代码行数:9,代码来源:dynamichtmltest.py


示例13: testSimpleGenerator

    def testSimpleGenerator(self):
        open(self.tempdir+'/testSimple.sf', 'w').write("""
def main(*args, **kwargs):
  for n in ('aap', 'noot', 'mies'):
    yield str(n)
"""
        )
        s = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
        result = ''.join(s.handleRequest(scheme='http', netloc='host.nl', path='/testSimple', 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\naapnootmies', result)
开发者ID:seecr,项目名称:meresco-html,代码行数:10,代码来源:dynamichtmltest.py


示例14: testUseModuleLocals

    def testUseModuleLocals(self):
        open(self.tempdir+'/testSimple.sf', 'w').write("""
moduleLocal = "local is available"
def main(*args, **kwargs):
    yield moduleLocal
"""
            )
        s = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
        result = ''.join(s.handleRequest(scheme='http', netloc='host.nl', path='/testSimple', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
        self.assertTrue('local is available' in result, result)
开发者ID:seecr,项目名称:meresco-html,代码行数:10,代码来源:dynamichtmltest.py


示例15: testCustomFileNotFound_path_is_originalPath

    def testCustomFileNotFound_path_is_originalPath(self):
        open(join(self.tempdir, "not_found_template.sf"), 'w').write("""
def main(path, **kwargs):
    yield path
""")
        d = DynamicHtml([self.tempdir], notFoundPage="/not_found_template", reactor=CallTrace('Reactor'))
        result = asString(d.handleRequest(scheme='http', netloc='host.nl', path='/a/path', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
        headers, body = result.split('\r\n\r\n')
        self.assertEquals('HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8', headers)
        self.assertEquals('/a/path', body)
开发者ID:seecr,项目名称:meresco-html,代码行数:10,代码来源:dynamichtmltest.py


示例16: testPathTailDoesNotExist

    def testPathTailDoesNotExist(self):
        open(self.tempdir + '/page.sf', 'w').write("""
def main(**kwargs):
    yield "nopipe"
""")
        reactor = Reactor()
        d = DynamicHtml([self.tempdir], reactor=reactor)
        result = d.handleRequest(scheme='http', netloc='host.nl', path='/page/doesnotexist')
        headers, message = ''.join(result).split('\r\n\r\n')
        self.assertEquals('nopipe', message)
开发者ID:seecr,项目名称:meresco-html,代码行数:10,代码来源:dynamichtmltest.py


示例17: testRuntimeError

    def testRuntimeError(self):
        open(self.tempdir+'/testSimple.sf', 'w').write("""
def main(*args, **kwargs):
  yield 1/0
  yield "should not get here"
"""
        )
        s = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
        result = ''.join(s.handleRequest(scheme='http', netloc='host.nl', path='/testSimple', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
        self.assertTrue("HTTP/1.0 500 Internal Server Error\r\n\r\n" in result, result)
        self.assertTrue("integer division or modulo by zero" in result, result)
开发者ID:seecr,项目名称:meresco-html,代码行数:11,代码来源:dynamichtmltest.py


示例18: testCanCreateClassesInTemplate

    def testCanCreateClassesInTemplate(self):
        open(self.tempdir+'/afile.sf', 'w').write('''\
def main(*args, **kwargs):
    class A(object):
        def __init__(self):
            self.b = 'result'

    yield A().b''')
        d = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
        head, body = ''.join(d.handleRequest(path='/afile')).split('\r\n\r\n')
        self.assertEquals('result', body)
开发者ID:seecr,项目名称:meresco-html,代码行数:11,代码来源:dynamichtmltest.py


示例19: testHeaders

    def testHeaders(self):
        reactor = Reactor()

        d = DynamicHtml([self.tempdir], reactor=reactor)
        open(self.tempdir+'/file.sf', 'w').write("""
def main(Headers={}, *args, **kwargs):
    yield str(Headers)
""")
        reactor.step()

        result = d.handleRequest(scheme='http', netloc='host.nl', path='/file', query='?query=something', fragments='#fragments', arguments={'query': 'something'}, Headers={'key': 'value'})
        self.assertEquals("""HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n{'key': 'value'}""", ''.join(result))
开发者ID:seecr,项目名称:meresco-html,代码行数:12,代码来源:dynamichtmltest.py


示例20: testHandlePOSTRequest

    def testHandlePOSTRequest(self):
        open(self.tempdir + '/page.sf', 'w').write(r"""
def main(Headers={}, Body=None, Method=None, *args, **kwargs):
    yield 'Content-Type: %s\n' % Headers.get('Content-Type')
    yield 'Body: %s\n' % Body
    yield 'Method: %s\n' % Method
"""
        )
        reactor = Reactor()
        d = DynamicHtml([self.tempdir], reactor=reactor)
        result = ''.join(d.handleRequest(scheme='http', netloc='host.nl', path='/page', arguments={}, RequestURI='http://host.nl/page', Method='POST', Body='label=value&otherlabel=value', Headers={'Content-Type':'application/x-www-form-urlencoded'}))

        self.assertTrue('Content-Type: application/x-www-form-urlencoded\nBody: label=value&otherlabel=value\nMethod: POST\n' in result, result)
开发者ID:seecr,项目名称:meresco-html,代码行数:13,代码来源:dynamichtmltest.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python composedquery.ComposedQuery类代码示例发布时间:2022-05-27
下一篇:
Python core.Observable类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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