Changeset 760

Show
Ignore:
Timestamp:
02/13/06 04:04:08 (3 years ago)
Author:
simon
Message:

Changed bind_args to transform the handler not registrant.
Since this makes it completely generic, moved to util.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/turbogears/errorhandling.py

    r756 r760  
    77 
    88import turbogears.util as tg_util 
    9 from turbogears.decorator import decorator 
    109 
    1110 
     
    139138    return registrant 
    140139 
    141 def bind_args(**add): 
    142     """ Call with additional arguments.  """ 
    143     def entagle(registrant): 
    144         def call(handler, rules=None): 
    145             def newhandler(handler, *args, **kw): 
    146                 kw.update(add) 
    147                 return handler(*args, **kw) 
    148             return registrant(decorator(newhandler)(handler), rules) 
    149         return call 
    150     return entagle 
    151  
    152140__all__ = ["dispatch_error", "dispatch_error_adaptor", "try_call", 
    153            "run_with_errors", "default", "register_handler", "bind_args"
     141           "run_with_errors", "default", "register_handler"
  • trunk/turbogears/tests/test_errorhandling.py

    r756 r760  
    66from turbogears.controllers import error_handler, exception_handler, \ 
    77                                   expose, validate 
    8 from turbogears.errorhandling import bind_args 
     8from turbogears.util import bind_args 
    99from turbogears import validators 
    1010from turbogears import testutil 
     
    134134    def bindargs(self, bar=""): 
    135135        return dict(title="Bind arguments to error handler") 
    136     bindargs = bind_args(baz=123)(error_handler)(simpleerrorhandler)(bindargs) 
     136    bindargs = error_handler(bind_args(baz=123)(simpleerrorhandler))(bindargs) 
    137137    bindargs = validate(validators={"bar":validators.Int()})(bindargs) 
    138138    bindargs = expose()(bindargs) 
  • trunk/turbogears/util.py

    r753 r760  
    88import pkg_resources 
    99import setuptools 
     10 
     11from turbogears.decorator import decorator 
    1012 
    1113 
     
    225227    return args, kw 
    226228 
     229def bind_args(**add): 
     230    """ Call with arguments set to a predefined value.  """ 
     231    def entagle(func): 
     232        def call(func, *args, **kw): 
     233            kw.update(add) 
     234            return func(*args, **kw) 
     235        return decorator(call)(func) 
     236    return entagle 
     237 
    227238__all__ = ["Enum", "setlike", "get_package_name", "get_model", 
    228239           "DictObj", "DictWrapper", "url", "ensure_sequence", 
    229240           "to_kw", "from_kw", "remove_excess_args", "infinite_recursion", 
    230            "arg_pos", "inject_arg"
     241           "arg_pos", "inject_arg", "bind_args"