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


Python decorators.Decoration类代码示例

本文整理汇总了Python中tg.decorators.Decoration的典型用法代码示例。如果您正苦于以下问题:Python Decoration类的具体用法?Python Decoration怎么用?Python Decoration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: __init__

    def __init__(self, *args, **kw):
        super(RoutedController, self).__init__(*args, **kw)

        routes = []
        for name in dir(self):
            value = getattr(self.__class__, name, None)
            if value is None:
                continue

            deco = None
            if inspect.ismethod(value):  # pragma: no cover
                # PY2
                deco = Decoration.get_decoration(value.__func__)
            elif inspect.isfunction(value):  # pragma: no cover
                # PY3
                deco = Decoration.get_decoration(value)

            if deco is None:
                continue

            if hasattr(deco, '_tgext_routes'):
                routes.extend(deco._tgext_routes)

        if routes:
            instance_mapper = Mapper()
            if self.mapper is not None:
                instance_mapper.extend(self.mapper.matchlist)
            instance_mapper.extend(routes)
            self.mapper = instance_mapper
开发者ID:TurboGears,项目名称:tgext.routes,代码行数:29,代码来源:dispatch.py

示例2: test_backward_compatibility_decorator

    def test_backward_compatibility_decorator(self):
        deco = Decoration.get_decoration(BasicTGController.two_validators)

        validated_params = sorted(list(deco.validation.validators.keys()))
        assert validated_params == ["a", "someemail"], validated_params

        deco = Decoration.get_decoration(BasicTGController.tw2form_error_handler)
        assert deco.validation is None, deco.validation
开发者ID:984958198,项目名称:tg2,代码行数:8,代码来源:test_validation.py

示例3: __call__

    def __call__(self):
        log.debug("Registering %s for hook %s on controller %s",
                  self.func, self.hook_name, self.controller)

        if self.hook_name == 'controller_wrapper':
            deco = Decoration.get_decoration(self.controller)
            deco._register_controller_wrapper(self.func)
        else:
            deco = Decoration.get_decoration(self.controller)
            deco._register_hook(self.hook_name, self.func)
开发者ID:garrettmc,项目名称:TGWikiTutorial,代码行数:10,代码来源:hooks.py

示例4: notify_with_value

    def notify_with_value(self, hook_name, value, controller=None, context_config=None):
        """Notifies a TurboGears hook which is expected to return a value.

        hooks with values are expected to accept an input value an return
        a replacement for it. Each registered function will receive as input
        the value returned by the previous function in chain.

        The resulting value will be returned by the ``notify_with_value``
        call itself::

            app = tg.hooks.notify_with_value('before_config', app)

        """
        if context_config is None: #pragma: no cover
            context_config = tg.config._current_obj()

        try:
            syswide_hooks = context_config['hooks'][hook_name]
            for func in syswide_hooks:
                value = func(value)
        except KeyError: #pragma: no cover
            pass

        if controller is not None:
            controller = default_im_func(controller)
            deco = Decoration.get_decoration(controller)
            for func in deco.hooks[hook_name]:
                value = func(value)

        return value
开发者ID:Shamefox,项目名称:tg2,代码行数:30,代码来源:hooks.py

示例5: notify

    def notify(self, hook_name, args=None, kwargs=None, controller=None, context_config=None):
        """Notifies a TurboGears hook.

        Each function registered for the given hook will be executed,
        ``args`` and ``kwargs`` will be passed to the registered functions
        as arguments.

        It permits to notify both application hooks::

            tg.hooks.notify('custom_global_hook')

        Or controller hooks::

            tg.hooks.notify('before_render', args=(remainder, params, output),
                            controller=RootController.index)

        """
        if context_config is None: #pragma: no cover
            context_config = tg.config._current_obj()

        args = args or []
        kwargs = kwargs or {}

        try:
            syswide_hooks = context_config['hooks'][hook_name]
            for func in syswide_hooks:
                func(*args, **kwargs)
        except KeyError: #pragma: no cover
            pass

        if controller is not None:
            controller = default_im_func(controller)
            deco = Decoration.get_decoration(controller)
            for func in deco.hooks.get(hook_name, []):
                func(*args, **kwargs)
开发者ID:Shamefox,项目名称:tg2,代码行数:35,代码来源:hooks.py

示例6: plugin

    def plugin(f, *args, **kw):
        results_dict = f(*args, **kw)
        user = args[0].user
        residence_var = "residence"
       
        plugins_templates = list()

        # un plugin est defini pour le scope et residence est defini 
        if scope in plugins_config.mappings and residence_var in results_dict:
            residence_dn = Residences.get_dn_by_name(user, results_dict[residence_var])

            scope_mappings = plugins_config.mappings[scope]
            
            for function in scope_mappings:
                plugin_name = plugin_name_from_function(function)

                plugin_activated = Plugins.get_by_name(user, residence_dn, plugin_name)

                if plugin_activated is None:
                    continue
                #end if

                template_name = None

                # obtenir le nom du template à partir du decorator "expose"
                deco = Decoration.get_decoration(function)
                try:
                    template_name = deco.engines["text/html"][1]
                except:
                    pass

                if template_name is not None:
                    # transformer le nom de template en chemin fichier
                    template_path = (
                        tg.config['pylons.app_globals']
                          .dotted_filename_finder
                          .get_dotted_filename(template_name, template_extension='.html')
                    )

                    # ajouter dans les plugin templates
                    plugins_templates.append(template_path)
                #end if

                # executer la fonction du plugin
                mapping_results = function(results_dict)

                # constuire le nom de regroupement des variable de ce plugin
                method_name = function.__name__
                plugin_section = str.lower(plugin_name + "_" + method_name)

                # ajout du groupe au dictionnaire de la methode du controlleur
                results_dict[plugin_section] = PluginVars(mapping_results)
            #end for

        #end if

        # ajout des templates dans un champs spécial du dictionnaire pour le rendu
        results_dict["_plugins_templates"] = plugins_templates

        return results_dict
开发者ID:Rbeuque74,项目名称:brie-aurore,代码行数:60,代码来源:plugins.py

示例7: test_no_requirements_backward_compatibility

 def test_no_requirements_backward_compatibility(self):
     deco = Decoration.get_decoration(RootController.force_commit)
     reqs = deco.requirements
     deco.requirements = []
     requirement = deco.requirement
     deco.requirements = reqs
     assert requirement is None, requirement
开发者ID:garrettmc,项目名称:TGWikiTutorial,代码行数:7,代码来源:test_authz.py

示例8: __call__

    def __call__(self, path, **params):
        config = tg.config._current_obj()
        try:
            func = config['_pluggable_partials_cache'][path]
        except:
            func = config['_pluggable_partials_cache'][path] = self.resolve(path)

        result = func(**params)
        
        if not isinstance(result, dict):
            return result

        #Expect partials not to expose more than one template
        available_engines = list(Decoration.get_decoration(func).engines.values())
        engine_name, template_name, exclude_names = available_engines[0][:3]
        replaced_template = config.get('_pluggable_templates_replacements', {}).get(template_name)
        if replaced_template:
            engine_name, template_name = replaced_template.split(':', 1)

        #Avoid placing the doctype declaration in genshi templates
        render_params = {}
        if engine_name == 'genshi':
            render_params['doctype'] = None

        return tg_render(template_vars=result, template_engine=engine_name, template_name=template_name,
                         **render_params)
开发者ID:RobertSudwarts,项目名称:tgext.pluggable,代码行数:26,代码来源:utils.py

示例9: test_lazy_inheritance_with_3nested_template

    def test_lazy_inheritance_with_3nested_template(self):
        milestones.renderers_ready._reset()

        class BaseController(tg.TGController):
            @tg.expose('template.html')
            @tg.expose('template.html', content_type='text/plain')
            @tg.expose('template.html', content_type='text/javascript')
            def func(self):
                pass

        class SubController(BaseController):
            @tg.expose('new_template.html', inherit=True)
            @tg.expose('new_template.html', content_type='text/plain')
            @tg.expose('new_template.html', content_type='text/javascript')
            def func(self):
                pass

        class SubSubController(SubController):
            @tg.expose('new2_template.html', inherit=True)
            @tg.expose('new2_template.html', content_type='text/javascript')
            def func(self):
                pass

        class SubSubSubController(SubSubController):
            @tg.expose('new3_template.html', inherit=True)
            def func(self):
                pass

        milestones.renderers_ready.reach()

        deco = Decoration.get_decoration(SubSubSubController.func)
        assert len(deco.engines) == 3, deco.engines
        assert deco.engines['text/html'][1] == 'new3_template.html', deco.engines
        assert deco.engines['text/plain'][1] == 'new_template.html', deco.engines
        assert deco.engines['text/javascript'][1] == 'new2_template.html', deco.engines
开发者ID:984958198,项目名称:tg2,代码行数:35,代码来源:test_decorators.py

示例10: __call__

 def __call__(self, func):
     deco = decorator(self.wrap, func)
     exposed = Decoration.get_decoration(deco)
     deco.signatures = self.signatures
     deco.helpstr = self.helpstr
     exposed.register_template_engine(\
         'text/xml', config.get('default_renderer', ['mako'])[0],
         '', [], {})
     return deco
开发者ID:TurboGears,项目名称:tgext.xmlrpc,代码行数:9,代码来源:controllers.py

示例11: __call__

 def __call__(self, func):
     deco = Decoration.get_decoration(func)
     if not hasattr(deco, '_tgext_routes'):
         deco._tgext_routes = []
     deco._tgext_routes.append(Route(func.__name__,
                                     self.routing_path,
                                     controller=route.CURRENT_CONTROLLER,
                                     action=func.__name__,
                                     **self.routing_args))
     return func
开发者ID:TurboGears,项目名称:tgext.routes,代码行数:10,代码来源:decorators.py

示例12: __call__

    def __call__(self):
        log.debug("Registering %s for hook %s on controller %s",
                  self.func, self.hook_name, self.controller)

        if self.hook_name == 'controller_wrapper':
            config = tg.config._current_obj()
            dedicated_wrappers = config['dedicated_controller_wrappers']
            dedicated_wrappers.setdefault(self.controller, []).append(self.func)
        else:
            deco = Decoration.get_decoration(self.controller)
            deco._register_hook(self.hook_name, self.func)
开发者ID:Shamefox,项目名称:tg2,代码行数:11,代码来源:hooks.py

示例13: render_widget

def render_widget(mount_point, widget_name):
    app = c.project.app_instance(mount_point)
    method = getattr(app.widget(app), widget_name)
    with push_config(c, app=app):
        result = method()
    if isinstance(result, dict):
        deco = Decoration.get_decoration(method)
        content_type, engine, template, exclude_names = \
            deco.lookup_template_engine(request)
        template_vars = dict((k,v) for k,v in result.iteritems()
                             if k not in exclude_names)
        return render(template_vars, engine, template)
    return result
开发者ID:pombredanne,项目名称:SourceForge-Allura,代码行数:13,代码来源:dashboard.py

示例14: test_decoration_run_hooks_backward_compatibility

    def test_decoration_run_hooks_backward_compatibility(self):
        # TODO: Remove test when Decoration.run_hooks gets removed

        def func(*args, **kw):
            pass

        def hook(*args, **kw):
            hook.did_run = True
        hook.did_run = False

        milestones.renderers_ready.reach()
        tg.hooks.register('before_call', hook, controller=func)

        deco = Decoration.get_decoration(func)
        deco.run_hooks(Bunch(config=None), 'before_call')

        assert hook.did_run is True
开发者ID:Shamefox,项目名称:tg2,代码行数:17,代码来源:test_decorated_controller.py

示例15: test_lazy_inheritance

    def test_lazy_inheritance(self):
        milestones.renderers_ready._reset()

        class BaseController(tg.TGController):
            @tg.expose('template.html')
            def func(self):
                pass

        class SubController(BaseController):
            @tg.expose(inherit=True)
            def func(self):
                pass

        milestones.renderers_ready.reach()

        deco = Decoration.get_decoration(SubController.func)
        assert len(deco.engines) == 1, deco.engines
        assert deco.engines['text/html'][1] == 'template.html', deco.engines
开发者ID:984958198,项目名称:tg2,代码行数:18,代码来源:test_decorators.py


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