コード例 #1
0
 def info(self):
     aClass = self.aClass
     if type(aClass) is not str:
         aClass = aClass.__name__
     result = class_of(aClass)
     if self.or_none is None:
         return result + ' or None'
     return result
コード例 #2
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def info ( self ):
     aClass = self.aClass
     if type( aClass ) is not str:
         aClass = aClass.__name__
     result = class_of( aClass )
     if self.or_none is None:
         return result + ' or None'
     return result
コード例 #3
0
ファイル: trait_errors.py プロジェクト: jtomase/matplotlib
 def set_args ( self ):
     if self.desc is None:
        extra = ''
     else:
        extra = ' specifies %s and' % self.desc
     obj = getattr( self, 'object', None )
     if obj is not None:
         self.args = ( "%s '%s' trait of %s instance%s must be %s, "
                       "but a value of %s was specified." % (
                       self.prefix, self.name, class_of( obj ), extra,
                       self.info, self.value ) )
     else:
         self.args = ( "%s '%s' trait%s must be %s, but a value of %s was "
                       "specified." % ( self.prefix, self.name, extra, 
                                        self.info, self.value ) )
コード例 #4
0
    def validate(self, object, name, value):

        # If the value is already the desired type, then return it:
        if type(value) is self.aType:
            return value

        # Else try to cast it to the specified type:
        try:
            return self.aType(value)
        except:
            # Otherwise, raise an exception:
            tv = type(value)
            if tv is InstanceType:
                kind = class_of(value)
            else:
                kind = repr(value)
            self.error(object, name, '%s (i.e. %s)' % (str(tv)[1:-1], kind))
コード例 #5
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def validate ( self, object, name, value ):
     
     # If the value is already the desired type, then return it:
     if type( value ) is self.aType:
         return value
         
     # Else try to cast it to the specified type:
     try:
         return self.aType( value )
     except:
         # Otherwise, raise an exception:
         tv = type( value )
         if tv is InstanceType:
             kind = class_of( value )
         else:
             kind = repr( value )
         self.error( object, name, '%s (i.e. %s)' % ( 
                                   str( tv )[1:-1], kind ) )
コード例 #6
0
ファイル: trait_errors.py プロジェクト: jtomase/matplotlib
    def set_args(self):
        if self.desc is None:
            extra = ''
        else:
            extra = ' specifies %s and' % self.desc
        obj = getattr(self, 'object', None)

        # Note: self.args must be a tuple so be sure to leave the trailing
        # commas.
        if obj is not None:
            self.args = ("%s '%s' trait of %s instance%s must be %s, "
                         "but a value of %s was specified." %
                         (self.prefix, self.name, class_of(obj), extra,
                          self.info, self.value)),
        else:
            self.args = (
                "%s '%s' trait%s must be %s, but a value of %s was "
                "specified." %
                (self.prefix, self.name, extra, self.info, self.value)),
コード例 #7
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def validate ( self, object, name, value ):
     fv = self.fast_validate
     tv = type( value )
     
     # If the value is already the desired type, then return it:
     if tv is fv[1]:
         return value
         
     # Else see if it is one of the coercable types:
     for typei in fv[2:]:
         if tv is typei:
             # Return the coerced value:
             return fv[1]( value )
             
     # Otherwise, raise an exception:
     if tv is InstanceType:
         kind = class_of( value )
     else:
         kind = repr( value )
     self.error( object, name, '%s (i.e. %s)' % ( str( tv )[1:-1], kind ) )
コード例 #8
0
    def validate(self, object, name, value):
        fv = self.fast_validate
        tv = type(value)

        # If the value is already the desired type, then return it:
        if tv is fv[1]:
            return value

        # Else see if it is one of the coercable types:
        for typei in fv[2:]:
            if tv is typei:
                # Return the coerced value:
                return fv[1](value)

        # Otherwise, raise an exception:
        if tv is InstanceType:
            kind = class_of(value)
        else:
            kind = repr(value)
        self.error(object, name, '%s (i.e. %s)' % (str(tv)[1:-1], kind))
コード例 #9
0
ファイル: traits.py プロジェクト: pv/matplotlib-cvs
def _write_only ( object, name ):
    raise TraitError, "The '%s' trait of %s instance is 'write only'." % ( 
                      name, class_of( object ) )
コード例 #10
0
def _read_only(object, name, value):
    raise TraitError, "The '%s' trait of %s instance is 'read only'." % (
        name, class_of(object))
コード例 #11
0
def _undefined_get(object, name):
    raise TraitError, ("The '%s' trait of %s instance is a property that has "
                       "no 'get' or 'set' method") % (name, class_of(object))
コード例 #12
0
 def keyword_error(self, method, object, name, value):
     raise TraitError, (
         "The '%s' keyword argument of the %s method of "
         "%s instance must be %s, but a value of %s was "
         "specified." %
         (name, method.tm_name, class_of(object), self.info(), value))
コード例 #13
0
def _write_only(object, name):
    raise TraitError, "The '%s' trait of %s instance is 'write only'." % (
        name, class_of(object))
コード例 #14
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def return_error ( self, method, object, value ):
     raise TraitError, ("The result of the %s method of %s instance must "
                        "be %s, but a value of %s was returned." % ( 
                        method.tm_name, class_of( object ), self.info(), 
                        value ) )
コード例 #15
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def keyword_error ( self, method, object, name, value ):
     raise TraitError, ("The '%s' keyword argument of the %s method of "
                        "%s instance must be %s, but a value of %s was "
                        "specified." % ( name, method.tm_name,
                        class_of( object ), self.info(), value ) )
コード例 #16
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def validate ( self, object, name, value ):
     raise TraitError, ( 
           "The '%s' trait of %s instance has an unknown type. "
           "Contact the developer to correct the problem." % (
           name, class_of( object ) ) )
コード例 #17
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def len_error ( self, len ):
     raise TraitError, ( "The '%s' trait of %s instance must be %s, "
               "but you attempted to change its length to %d element%s." % (
               self.name, class_of( self.object ), self.trait.info(),
               len, 's'[ len == 1: ] ) )
コード例 #18
0
 def len_error(self, len):
     raise TraitError, (
         "The '%s' trait of %s instance must be %s, "
         "but you attempted to change its length to %d element%s." %
         (self.name, class_of(
             self.object), self.trait.info(), len, 's'[len == 1:]))
コード例 #19
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def dup_arg_error ( self, method, arg_num, object, name ):
     raise TraitError, ("The '%s' parameter (argument %d) of the %s method "
                        "of %s instance was specified as both a positional "
                        "and keyword value."
                        % ( name, arg_num, method.tm_name, 
                            class_of( object ) ) )
コード例 #20
0
 def return_error(self, method, object, value):
     raise TraitError, (
         "The result of the %s method of %s instance must "
         "be %s, but a value of %s was returned." %
         (method.tm_name, class_of(object), self.info(), value))
コード例 #21
0
 def dup_arg_error(self, method, arg_num, object, name):
     raise TraitError, ("The '%s' parameter (argument %d) of the %s method "
                        "of %s instance was specified as both a positional "
                        "and keyword value." %
                        (name, arg_num, method.tm_name, class_of(object)))
コード例 #22
0
 def missing_arg_error(self, method, arg_num, object, name):
     raise TraitError, (
         "The '%s' parameter (argument %d) of the %s method "
         "of %s instance must be specified, but was omitted." %
         (name, arg_num, method.tm_name, class_of(object)))
コード例 #23
0
ファイル: traits.py プロジェクト: pv/matplotlib-cvs
def _read_only ( object, name, value ):
    raise TraitError, "The '%s' trait of %s instance is 'read only'." % ( 
                      name, class_of( object ) )
コード例 #24
0
 def validate(self, object, name, value):
     raise TraitError, (
         "The '%s' trait of %s instance has an unknown type. "
         "Contact the developer to correct the problem." %
         (name, class_of(object)))
コード例 #25
0
ファイル: traits.py プロジェクト: pv/matplotlib-cvs
def _undefined_get ( object, name ):
    raise TraitError, ("The '%s' trait of %s instance is a property that has "
                       "no 'get' or 'set' method") % ( 
                       name, class_of( object ) )
コード例 #26
0
 def arg_error(self, method, arg_num, object, name, value):
     raise TraitError, ("The '%s' parameter (argument %d) of the %s method "
                        "of %s instance must be %s, but a value of %s was "
                        "specified." %
                        (name, arg_num, method.tm_name, class_of(object),
                         self.info(), value))
コード例 #27
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def missing_arg_error ( self, method, arg_num, object, name ):
     raise TraitError, ("The '%s' parameter (argument %d) of the %s method "
                        "of %s instance must be specified, but was omitted."
                        % ( name, arg_num, method.tm_name, 
                            class_of( object ) ) )
コード例 #28
0
ファイル: trait_handlers.py プロジェクト: pv/matplotlib-cvs
 def arg_error ( self, method, arg_num, object, name, value ):
     raise TraitError, ("The '%s' parameter (argument %d) of the %s method "
                        "of %s instance must be %s, but a value of %s was "
                        "specified." % ( name, arg_num, method.tm_name,
                        class_of( object ), self.info(), value ) )