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


Python DynamicHtml.addStrand方法代码示例

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


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

示例1: LuceneRemoteService

# 需要导入模块: from meresco.html import DynamicHtml [as 别名]
# 或者: from meresco.html.DynamicHtml import addStrand [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.addStrand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。