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


Python Domain.set_on_globals方法代码示例

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


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

示例1: test_prefer

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
 def test_prefer(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     t = td.get_template('raw_nested.html')
     self.assertEqual(t.prefer, dict(raw=False, quoting="xml"))
     def upper(s): 
         return s.upper()
     td.set_on_globals("upper", upper)
     p = td.get_template('raw_nested.html#preferences')
     self.assertEqual(p.raw, True)
     self.assertEqual(p.qsclass, unistr)
开发者ID:DamnWidget,项目名称:goliat,代码行数:12,代码来源:test_evoque.py

示例2: evoque_mq

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
def evoque_mq(dirname, verbose=False):
    DEFAULT_DIR = os.path.join(BASEPATH, 'evoque')
    from evoque.domain import Domain
    td = Domain(DEFAULT_DIR, restricted=False, quoting="str")
    import cgi
    td.set_on_globals("quote", cgi.escape) 
    t = td.get_template('template_mq.html')
    t.test()
    def render():
        return t.evoque(DATA.copy())
    if verbose:
        pr(t.ts, render())
    return render
开发者ID:DamnWidget,项目名称:goliat,代码行数:15,代码来源:basic.py

示例3: test_prefer_with_overrides

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
 def test_prefer_with_overrides(self):
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     def upper(s): 
         return s.upper()
     def trim(s): 
         return s.strip()
     td.set_on_globals("upper", upper)
     td.set_on_globals("trim", upper)
     p = td.get_template('raw_nested.html#preferences', raw=False, filters=[trim, upper])
     self.assertEqual(p.raw, False)
     self.assertEqual(p.qsclass, unistr)
     r = 'SHOULD REFRESH [QUOTING: NONE OR !="STR"] WHEN TEMPLATE IS LOADED'
     self.assertEqual(r, p.evoque())
     r = 'SHOULD REFRESH [QUOTING: NONE OR !="STR"] WHEN CHANGED TEMPLATE IS LOADED'
     self.assertEqual(r, p.evoque(what="changed template"))
开发者ID:DamnWidget,项目名称:goliat,代码行数:17,代码来源:test_evoque.py

示例4: setup_domain

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
def setup_domain():
    import logging
    domain = Domain(
        # root folder for the default template collection, must be abspath
        "/tmp",
        # whether evaluation namespace is restricted or not 
        restricted=True,
        # how should any evaluation errors be rendered
        # int 0 to 4, for: [silent, zero, name, render, raise]
        errors=3, 
        # domain logger; additional settings should be specified via the 
        # app's config ini file, just as for any other logger. E.g:
        # [logger_notifications]
        # level = DEBUG
        # handlers =
        # qualname = notifications
        log=logging.getLogger("notifications"),
        # [collections] int, max loaded templates in a collection
        cache_size=0,
        # [collections] int, min seconds to wait between checks for
        # whether a template needs reloading
        auto_reload=0,
        # [collections] bool, consume all whitespace trailing a directive
        slurpy_directives=True,
        # [collections/templates] str or class, to specify the *escaped* 
        # string class that should be used i.e. if any str input is not of 
        # this type, then cast it to this type). 
        # Builtin str key values are: "xml" -> qpy.xml, "str" -> unicode
        quoting="str",
        # [collections/templates] str, preferred encoding to be tried 
        # first when decoding template source. Evoque decodes template
        # strings heuristically, i.e. guesses the input encoding.
        input_encoding="utf-8",
        # [collections/templates] list of filter functions, each having 
        # the following signature: filter_func(s:basestring) -> basestring
        # The functions will be called, in a left-to-right order, after 
        # template is rendered. NOTE: not settable from the conf ini.
        filters=[]
    )
    # add "site" settings on globals
    domain.set_on_globals("site", TemplateNamespaceSite())
    return domain
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:44,代码来源:notification.py

示例5: test_filter_markdown

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
 def test_filter_markdown(self):
     try:
         from markdown import markdown
     except ImportError:
         pr("Can't import markdown, skipping test [filter_markdown]")
         return
     td = Domain(DEFAULT_DIR, restricted=RESTRICTED, errors=ERRORS)
     td.set_on_globals("markdown", markdown)
     import logging
     logging.getLogger("MARKDOWN").setLevel(logging.INFO) # hide markdown DEBUG logging
     t = td.get_template('markdown.html')
     sub_out = "item two <xml/>"
     self.failIf(t.evoque().find(sub_out) == -1)
     # Test direct evoque'ation of inner my-markdown-template -- that should
     # now be already loaded with quoting="xml" --- with different quoting.
     # We retrieve it, and evoque it overriding the quoting (as well as 
     # supplying the needed param="<xml/>")
     m = td.get_template('markdown.html#my-markdown-template')
     self.failUnless(m.evoque(quoting="str", param="<xml/>"
             ).find(sub_out) == -1)
开发者ID:DamnWidget,项目名称:goliat,代码行数:22,代码来源:test_evoque.py

示例6: SitePublisher

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
class SitePublisher(Publisher):

    configuration = dict(
        http_address=('', 8001),
        as_https_address=('localhost', 9001),
        https_address=('localhost', 10001),
        scgi_address=('localhost', 11001),
    )
    
    def __init__(self, **kwargs):
        super(SitePublisher, self).__init__(**kwargs)
        self.set_domain()
    
    def set_domain(self):
        default_dir = abspath(join(dirname(__file__), 'evoque'))
        # create template domain instance 
        # here restating all defaults, for doc convenience
        self.domain = Domain(default_dir, 
            restricted=False, errors=3, log=logging.getLogger("evoque"),
            cache_size=0, auto_reload=60, slurpy_directives=True, 
            quoting="xml", input_encoding="utf-8", filters=[]
        )
        # extensions to global namespace
        self.domain.set_on_globals("pformat", pformat)
        # preload a default template, e.g. for error pages
        self.domain.get_collection().get_template("", "base.html")
        # other setup e.g. adding other collections, template aliases
        # see: http://evoque.gizmojo.org/usage/
        
    def page(self, title, *content, **kwargs):
        """(title, *content, **kwargs) -> qpy.xml
        Return a page formatted according to the site-standard.
        """
        # we make use of only the "template" kwarg -- there are 
        # other possibilities, see: domain.get_template()
        template = kwargs.get("template", "")
        return self.domain.get_template(template).evoque(
                        title=title, content=content, **kwargs)
开发者ID:DamnWidget,项目名称:goliat,代码行数:40,代码来源:slash.py

示例7: evoque_mq

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
def evoque_mq(verbose=False):
    from evoque.domain import Domain
    DEFAULT_DIR = os.path.join(BASEDIR, 'evoque')
    td = Domain(DEFAULT_DIR)
    import cgi
    td.set_on_globals("quote", cgi.escape) 
    template_string = """<table>
$for{ row in table }
<tr>$for{ col in row }<td>${quote(col)}</td>$rof</tr>
$rof
</table>
$test{ table=[("a","b","c","d","<escape-me/>","f","g","h","i","j")] }
"""
    td.set_template("bigtable", src=template_string, quoting="str", 
            from_string=True)
    t = td.get_template("bigtable")
    def render():
        return t.evoque({'table':TABLE_DATA})
    if verbose:
        pr(t.ts)
        pr('--------------------------------------------------------')
        pr(render()[:300] + "...")
    return render
开发者ID:DamnWidget,项目名称:goliat,代码行数:25,代码来源:bigtable.py

示例8: abspath

# 需要导入模块: from evoque.domain import Domain [as 别名]
# 或者: from evoque.domain.Domain import set_on_globals [as 别名]
# to add to global namespace
from django.core.paginator import ObjectPaginator
from my_site import formatting_utils

# default template collection root directory
DEFAULT_DIR = abspath(join(dirname(__file__), 'templates'))

# create template domain instance 
# here restating all defaults, for doc convenience
domain = Domain(DEFAULT_DIR,
    restricted=False, errors=3, log=logging.getLogger("evoque"),
    cache_size=0, auto_reload=60, slurpy_directives=True,
    quoting="xml", input_encoding="utf-8", filters=[] )

# adjust global namespace as needed by application
domain.set_on_globals("ObjectPaginator", ObjectPaginator)
domain.set_on_globals("site_name", "mysite.net")
domain.set_namespace_on_globals("formatting_utils", formatting_utils)

# set up any other collection, as needed by application 
# here restating all defaults -- when None, domain's value is used
domain.set_collection("custom", "/home/me/custom_collection/",
    cache_size=None, auto_reload=None, slurpy_directives=None, 
    quoting=None, input_encoding=None, filters=None)


# here we would do any other domain setup we might need
# e.g. set a template default for a given collection
# for details see: http://evoque.gizmojo.org/usage/
# or the source of the evoque.domain module.
开发者ID:DamnWidget,项目名称:goliat,代码行数:32,代码来源:evoque_django.py


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