当前位置: 首页>>代码示例>>Python>>正文


Python DynamicHtml.addObserver方法代码示例

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


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

示例1: testObservability

# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import addObserver [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)
开发者ID:seecr,项目名称:meresco-html,代码行数:35,代码来源:dynamichtmltest.py

示例2: testObservabilityOutsideMainOnModuleLevel

# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import addObserver [as 别名]
    def testObservabilityOutsideMainOnModuleLevel(self):
        class X(object):
            def getX(*args, **kwargs):
                return "eks"

        open(self.tempdir+'/afile.sf', 'w').write("""#
x = observable.call.getX()
def main(*args, **kwargs):
  yield x
""")
        d = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
        d.addObserver(X())
        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\neks', ''.join(result))
开发者ID:seecr,项目名称:meresco-html,代码行数:16,代码来源:dynamichtmltest.py

示例3: testShouldExposeLoadedModulesForTestingPurposes

# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import addObserver [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

示例4: LuceneRemoteService

# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import addObserver [as 别名]
class LuceneRemoteService(Observable):
    def __init__(self, reactor, conversion=None, **kwargs):
        Observable.__init__(self, **kwargs)
        self._conversion = Conversion() if conversion is None else conversion
        self._dynamicHtml = DynamicHtml([dynamicPath],
                reactor=reactor,
                notFoundPage='notFound',
                additionalGlobals={
                    'VERSION': version,
                    'allCoreInfo': self._allCoreInfo,
                    'parseCql': parseString,
                    'cqlToExpression': cqlToExpression,
                    'cql2string': cql2string,
                    'dumps': dumps,
                }
            )
        self._internalTree = be((Observable(),
            (PathFilter('/', excluding=['/static', '/version']),
                (self._dynamicHtml,)
            ),
            (PathFilter('/static'),
                (PathRename(lambda path: path[len('/static'):]),
                    (FileServer(staticPath),)
                )
            ),
            (PathFilter('/version'),
                (StringServer("Meresco Lucene version %s" % version, ContentTypePlainText),)
            ),
        ))

    def addObserver(self, *args, **kwargs):
        Observable.addObserver(self, *args, **kwargs)
        self._dynamicHtml.addObserver(*args, **kwargs)

    def addStrand(self, *args, **kwargs):
        Observable.addStrand(self, *args, **kwargs)
        self._dynamicHtml.addStrand(*args, **kwargs)

    def handleRequest(self, path, Method, Body=None, **kwargs):
        if Method == 'POST' and path.endswith('/__lucene_remote__'):
            yield self._handleQuery(Body)
        elif '/info' in path:
            originalPath = path
            _, _, path = path.partition('/info')
            yield self._internalTree.all.handleRequest(path=path or '/', originalPath=originalPath, Method=Method, Body=Body, **kwargs)

    def _handleQuery(self, Body):
        try:
            message, kwargs = self._conversion.jsonLoadMessage(Body)
            if message not in _ALLOWED_METHODS:
                raise ValueError('Expected %s' % (' or '.join('"%s"' % m for m in _ALLOWED_METHODS)))
            response = yield self.any.unknown(message=message, **kwargs)
        except Exception, e:
            print_exc()
            x = format_exc() # returns 'None' if e is a Java Error
            yield serverErrorPlainText
            yield x if x and x.strip() != 'None' else repr(e)
            return
        yield Ok
        yield ContentTypeHeader + 'application/json' + CRLF
        yield CRLF
        yield response.asJson()
开发者ID:seecr,项目名称:meresco-lucene,代码行数:64,代码来源:_service.py


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