コード例 #1
0
 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)
コード例 #2
0
ファイル: basic.py プロジェクト: DamnWidget/goliat
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
コード例 #3
0
ファイル: subs.py プロジェクト: adibossiseu/goliat
def evoque_mq(dirname, verbose=False):
    DEFAULT_DIR = os.path.join(BASEPATH, 'evoque')
    name = 'subs_mq.html'
    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(name)
    def render():
        return t.evoque(DATA.copy())
    if verbose:
        pr(t.ts, render())
    return render
コード例 #4
0
 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"))
コード例 #5
0
ファイル: slash.py プロジェクト: adibossiseu/goliat
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)
コード例 #6
0
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
コード例 #7
0
 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)
コード例 #8
0
ファイル: slash.py プロジェクト: DamnWidget/goliat
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)
コード例 #9
0
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
コード例 #10
0
ファイル: evoque_django.py プロジェクト: DamnWidget/goliat
# 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.
コード例 #11
0
# 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