當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。