Пример #1
0
 def wrapper(func):
     def newfunc(*args, **kwargs):
         data=func(*args, **kwargs)
         if not isinstance(data, dict):
             # you decided not to use a template, bye-bye
             return data
         tmpl=(template or
               Configuration.defaultControllerTemplate or
               Configuration.defaultTemplate)
         if not tmpl:
             raise ValueError('no template specified or found in configuration')
         t=tmpl.split(':', 1)
         if len(t)==1:
             enginename=Configuration.defaultTemplatingEngine
         else:
             enginename, tmpl=t
         del t
         log.debug("engine: %s, template: %s", enginename, tmpl)
         engineclass=TEMPLATING_ENGINES[enginename]
         extra_vars_func=template_opts.pop('extra_vars_func', None)
         format=template_opts.pop('format', None)
         fragment=template_opts.pop('fragment', None)
         tmplopts=Configuration.templateEngineOptions.get(enginename)
         if tmplopts:
             tmplopts=tmplopts.copy()
             tmplopts.update(template_opts)
         else:
             tmplopts=template_opts
         log.debug('template options: %s', tmplopts)
         engine=engineclass(extra_vars_func, **tmplopts)
         log.debug("engine instance attributes: %s", vars(engine))
         return engine.render(data, format, fragment, tmpl)
     return rewrap(func, newfunc)
Пример #2
0
 def wrapper(fn):
     if hasattr(fn, 'expiration') and def_exp:
         expiration1=fn.expiration
     else:
         expiration1=expiration
     def newfunc(*args, **kwargs):
         policy2=kwargs.pop('cache', policy)
         expiration2=kwargs.pop('expiration', expiration1)
         ondefer2=kwargs.pop('ondefer', ondefer)
         res=self.cache.call(fn, (args, kwargs), policy2, expiration2, ondefer2)
         return res.value
     return rewrap(fn, newfunc)