Changeset 411

Show
Ignore:
Timestamp:
05/07/07 02:06:32 (2 years ago)
Author:
athomas
Message:

cly:

  • Fixed some propagation of positional arguments up the constructor chain.
  • Added var_name argument to Validator constructor. This allows the variable name
    assigned to the node to be overridden.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/cly/__init__.py

    r408 r411  
    379379                     posixpath.join(self.path(), self._alias))) 
    380380 
    381     def __init__(self, alias, **options): 
    382         Node.__init__(self, "<alias for '%s'>" % alias, **options) 
     381    def __init__(self, alias, *args, **kwargs): 
     382        Node.__init__(self, "<alias for '%s'>" % alias, *args, **kwargs) 
    383383        self._alias = alias 
    384384 
     
    428428    with_context = False 
    429429 
    430     def __init__(self, help, callback=None, **kwargs): 
     430    def __init__(self, help, callback=None, *args, **kwargs): 
    431431        if isinstance(help, basestring): 
    432432            help_string = help 
    433433            help = lambda ctx: (('<eol>', help_string),) 
    434         Node.__init__(self, help, callback=callback, **kwargs) 
     434        Node.__init__(self, help, callback=callback, *args, **kwargs) 
    435435 
    436436    def help(self, context): 
     
    460460    """Validate and record the users input in the vars member of the context. 
    461461 
    462     The Node name is used as the variable name. 
     462    The Node name is used as the variable name unless var_name is provided to 
     463    the constructor. 
    463464 
    464465    If traversals is > 1 the validator will accumulate values into a list. 
     
    466467 
    467468    pattern = r'\w+' 
     469 
     470    def __init__(self, help, var_name=None, *args, **kwargs): 
     471        Node.__init__(self, help, *args, **kwargs) 
     472        self._var_name = var_name 
     473 
     474    def _get_var_name(self): 
     475        """Get the var name for this validator. Will use `var_name` if provided 
     476        to the constructor, otherwise it will use the node name.""" 
     477        if self._var_name is not None: 
     478            return self._var_name 
     479        return self.name 
     480 
     481    var_name = property(_get_var_name) 
    468482 
    469483    def valid(self, context): 
     
    492506                                  exception=unicode(e)) 
    493507        if self.traversals > 1: 
    494             context.vars.setdefault(self.name, []).append(value) 
     508            context.vars.setdefault(self.var_name, []).append(value) 
    495509        else: 
    496             context.vars[self.name] = value 
     510            context.vars[self.var_name] = value 
    497511        return Node.selected(self, context, match) 
    498512