當前位置: 首頁>>代碼示例>>Python>>正文


Python DynamicHtml.getModule方法代碼示例

本文整理匯總了Python中meresco.html.DynamicHtml.getModule方法的典型用法代碼示例。如果您正苦於以下問題:Python DynamicHtml.getModule方法的具體用法?Python DynamicHtml.getModule怎麽用?Python DynamicHtml.getModule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在meresco.html.DynamicHtml的用法示例。


在下文中一共展示了DynamicHtml.getModule方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testShouldExposeLoadedModulesForTestingPurposes

# 需要導入模塊: from meresco.html import DynamicHtml [as 別名]
# 或者: from meresco.html.DynamicHtml import getModule [as 別名]
    def testShouldExposeLoadedModulesForTestingPurposes(self):
        open(self.tempdir + '/one.sf', 'w').write(r"""
attr = 'attr'
def sync():
    return 'aye'
def asyncReturn():
    raise StopIteration('aye')
    yield
def observableDownward():
    yield observable.all.something('arg', kw='kw')
def main(*args, **kwargs):
    yield "Hoi"
""")
        open(self.tempdir + '/two.sf', 'w').write(r"""

import one

def parameterized(arg, *args, **kwargs):
    return arg, args, kwargs

def main(*args, **kwargs):
    yield one.observableDownward()
""")
        reactor = Reactor()
        d = DynamicHtml([self.tempdir], reactor=reactor)
        t1 = CallTrace('t1')
        t2 = CallTrace('t2')
        d.addObserver(t1)
        d.addObserver(t2)
        one = d.getModule(name='one')
        two = d.getModule('two')

        self.assertEquals(None, d.getModule('does-not-exist'))

        self.assertEquals('attr', one.attr)
        self.assertEquals('aye', one.sync())
        try:
            g = compose(one.asyncReturn())
            g.next()
        except StopIteration, e:
            self.assertEquals(('aye',), e.args)
開發者ID:seecr,項目名稱:meresco-html,代碼行數:43,代碼來源:dynamichtmltest.py

示例2: test

# 需要導入模塊: from meresco.html import DynamicHtml [as 別名]
# 或者: from meresco.html.DynamicHtml import getModule [as 別名]
        def test():
            additionalGlobals = {
                'util_reloaded_id': howOften("util-reloaded"),
                'using_util_reloaded_id': howOften("using-util-reloaded"),
                'orphan_reloaded_id': howOften("orphan-reloaded"),
            }
            d = DynamicHtml([self.tempdir], reactor=reactor(), additionalGlobals=additionalGlobals)

            # Allow cleanup of directoryWatcherReadFD (whitebox)
            _reactorFdsKeys = reactor()._fds.keys()
            self.assertEquals(1, len(_reactorFdsKeys))
            directoryWatcherReadFD = _reactorFdsKeys[0]

            yield zleep(0.01)   # Allow DirectoryWatcher some reactor time

            # Initialized once
            util, orphan, using_util = d.getModule('util'), d.getModule('orphan'), d.getModule('using-util')
            self.assertEquals(
                ['util-reloaded:1',
                 'orphan-reloaded:1',
                 'using-util-reloaded:1'],
                [util.reloaded, orphan.reloaded, using_util.reloaded])
            self.assertEquals('using-util-reloaded:1 - util-reloaded:1', using_util.using())

            # Touch & **all** reloaded
            with open(fp_util, 'w') as f:
                f.write(util_contents)
            yield zleep(0.02)   # Allow DirectoryWatcher some reactor time

            util, orphan, using_util = d.getModule('util'), d.getModule('orphan'), d.getModule('using-util')
            self.assertEquals(
                ['util-reloaded:2',
                 'orphan-reloaded:2',
                 'using-util-reloaded:2'],
                [util.reloaded, orphan.reloaded, using_util.reloaded])
            self.assertEquals('using-util-reloaded:2 - util-reloaded:2', using_util.using())

            # Remove file - nothing happens
            remove(fp_orphan)
            yield zleep(0.02)   # Allow DirectoryWatcher some reactor time

            util, orphan, using_util = d.getModule('util'), d.getModule('orphan'), d.getModule('using-util')
            self.assertNotEqual(None, orphan)
            self.assertEquals(
                ['util-reloaded:2',
                 'orphan-reloaded:2',
                 'using-util-reloaded:2'],
                [util.reloaded, orphan.reloaded, using_util.reloaded])

            # Modify util - reload **and** remove of deleted happens
            with open(fp_util, 'w') as f:
                f.write(util_contents)
            yield zleep(0.02)   # Allow DirectoryWatcher some reactor time

            util, orphan, using_util = d.getModule('util'), d.getModule('orphan'), d.getModule('using-util')
            self.assertEquals(None, orphan)
            self.assertEquals(
                ['util-reloaded:3',
                 'using-util-reloaded:3'],
                [util.reloaded, using_util.reloaded])
            self.assertEquals('using-util-reloaded:3 - util-reloaded:3', using_util.using())

            # cleanup
            reactor().removeReader(sok=directoryWatcherReadFD)
開發者ID:seecr,項目名稱:meresco-html,代碼行數:66,代碼來源:dynamichtmltest.py


注:本文中的meresco.html.DynamicHtml.getModule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。