Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes
validation.chain.ValidationChain Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def __len__
def __iter__
def __cmp__
def __getitem__
def append
def appendRequired
def appendSufficient
def insert
def insertRequired
def insertSufficient
def setMode
def setValidator
def __call__

Public Attributes

 name
 title
 description

Private Attributes

 _v_mode
 _chain

Static Private Attributes

 __implements__ = IValidationChain

Detailed Description

Definition at line 21 of file chain.py.


Constructor & Destructor Documentation

def validation.chain.ValidationChain.__init__ (   self,
  name,
  title = '',
  description = '',
  validators = (),
  register = False 
)

Definition at line 27 of file chain.py.

00027 
00028                  register=False):
00029         self.name = name
00030         self.title = title or name
00031         self.description = description
00032         self._v_mode = []
00033         self._chain = []
00034 
00035         if type(validators) not in (TupleType, ListType):
00036             validators = (validators, )
00037         for validator in validators:
00038             if type(validator) in (TupleType, ListType):
00039                 self.append(validator[0], validator[1])
00040             else:
00041                 self.appendRequired(validator)
00042 
00043         if register:
00044             validationService.register(self)
                

Member Function Documentation

def validation.chain.ValidationChain.__call__ (   self,
  value,
  args,
  kwargs 
)
Do validation

Definition at line 135 of file chain.py.

00135 
00136     def __call__(self, value, *args, **kwargs):
00137         """Do validation
00138         """
00139         results = {}
00140         failed = False
00141         for validator, mode in self:
00142             name = validator.name
00143             result = validator(value, *args, **kwargs)
00144             if result == True:
00145                 if mode == V_SUFFICIENT:
00146                     return True # validation was successful
00147                 elif mode == V_REQUIRED:
00148                     continue    # go on
00149                 else:
00150                     raise ValidatorError, 'Unknown mode %s' % mode
00151             else:
00152                 if mode == V_SUFFICIENT:
00153                     if type(result) in StringTypes:
00154                         # don't log if validator doesn't return an error msg
00155                         results[name] = result
00156                     continue # no fatal error, go on
00157                 elif mode == V_REQUIRED:
00158                     if type(result) in StringTypes:
00159                         # don't log if validator doesn't return an error msg
00160                         results[name] = result
00161                     failed = True
00162                     break    # fatal error, stop and fail
00163                 else:
00164                     raise ValidatorError, 'Unknown mode %s' % mode
00165         
00166         if failed:
00167             return '\n'.join([
00168                               #'%s: %s' % (name, res)
00169                               '%s' % res
00170                               for name, res in results.items()]
00171                             )
00172         else:
00173             return True
00174 

def validation.chain.ValidationChain.__cmp__ (   self,
  key 
)

Definition at line 67 of file chain.py.

00067 
00068     def __cmp__(self, key):
00069         if isinstance(key, ValidationChain):
00070             str = repr(key)
00071         else:
00072             str = key
00073         return cmp(repr(self), str)
    
self[idx] support and Python 2.1 for i in x support

Definition at line 74 of file chain.py.

00074 
00075     def __getitem__(self, idx):
00076         """self[idx] support and Python 2.1 for i in x support
00077         """
00078         assert(len(self._chain), len(self._v_mode))
00079         return self._chain[idx], self._v_mode[idx]
        

Here is the caller graph for this function:

Python 2.3 for i in x support

Definition at line 61 of file chain.py.

00061 
00062     def __iter__(self):
00063         """Python 2.3 for i in x support
00064         """
00065         assert(len(self._chain), len(self._v_mode))
00066         return iter(zip(self._chain, self._v_mode))
    
len(obj) suppor

Definition at line 55 of file chain.py.

00055 
00056     def __len__(self):
00057         """len(obj) suppor
00058         """
00059         assert(len(self._chain), len(self._v_mode))
00060         return len(self._chain)
    
print obj support

Definition at line 45 of file chain.py.

00045 
00046     def __repr__(self):
00047         """print obj support
00048         """
00049         map = { V_REQUIRED : 'V_REQUIRED', V_SUFFICIENT : 'V_SUFFICIENT' }
00050         val = []
00051         for validator, mode in self:
00052             name = validator.name
00053             val.append("('%s', %s)" % (name, map.get(mode)))
00054         return '(%s)' % ', '.join(val)

def validation.chain.ValidationChain.append (   self,
  id_or_obj,
  mode = V_REQUIRED 
)
Appends a validator

Definition at line 80 of file chain.py.

00080 
00081     def append(self, id_or_obj, mode=V_REQUIRED):
00082         """Appends a validator
00083         """
00084         validator = self.setValidator(id_or_obj)
00085         self.setMode(validator, mode)
    

Here is the call graph for this function:

Here is the caller graph for this function:

def validation.chain.ValidationChain.appendRequired (   self,
  id_or_obj 
)
Appends a validator as required

Definition at line 86 of file chain.py.

00086 
00087     def appendRequired(self, id_or_obj):
00088         """Appends a validator as required
00089         """
00090         self.append(id_or_obj, mode=V_REQUIRED)

Here is the call graph for this function:

def validation.chain.ValidationChain.appendSufficient (   self,
  id_or_obj 
)
Appends a validator as sufficient

Definition at line 91 of file chain.py.

00091 
00092     def appendSufficient(self, id_or_obj):
00093         """Appends a validator as sufficient
00094         """
00095         self.append(id_or_obj, mode=V_SUFFICIENT)
    

Here is the call graph for this function:

def validation.chain.ValidationChain.insert (   self,
  id_or_obj,
  mode = V_REQUIRED,
  position = 0 
)
Inserts a validator at position (default 0)

Definition at line 96 of file chain.py.

00096 
00097     def insert(self, id_or_obj, mode=V_REQUIRED, position=0):
00098         """Inserts a validator at position (default 0)
00099         """
00100         validator = self.setValidator(id_or_obj, position=position)
00101         self.setMode(validator, mode, position=position)

Here is the call graph for this function:

Here is the caller graph for this function:

def validation.chain.ValidationChain.insertRequired (   self,
  id_or_obj,
  position = 0 
)
Inserts a validator as required at position (default 0)

Definition at line 102 of file chain.py.

00102 
00103     def insertRequired(self, id_or_obj, position=0):
00104         """Inserts a validator as required at position (default 0)
00105         """
00106         self.insert(id_or_obj, mode=V_REQUIRED, position=0)

Here is the call graph for this function:

def validation.chain.ValidationChain.insertSufficient (   self,
  id_or_obj,
  position = 0 
)
Inserts a validator as required at position (default 0)

Definition at line 107 of file chain.py.

00107 
00108     def insertSufficient(self, id_or_obj, position=0):
00109         """Inserts a validator as required at position (default 0)
00110         """
00111         self.insert(id_or_obj, mode=V_SUFFICIENT, position=0)

Here is the call graph for this function:

def validation.chain.ValidationChain.setMode (   self,
  validator,
  mode,
  position = None 
)
Set mode

Definition at line 112 of file chain.py.

00112 
00113     def setMode(self, validator, mode, position=None):
00114         """Set mode
00115         """
00116         assert(mode in (V_REQUIRED, V_SUFFICIENT))
00117         # validator not required
00118         if position is None:
00119             self._v_mode.append(mode)
00120         else:
00121             self._v_mode.insert(position, mode)
00122         assert(len(self._chain), len(self._v_mode))

Here is the caller graph for this function:

def validation.chain.ValidationChain.setValidator (   self,
  id_or_obj,
  position = None 
)
Set validator

Definition at line 123 of file chain.py.

00123 
00124     def setValidator(self, id_or_obj, position=None):
00125         """Set validator
00126         """
00127         validator = validationService.validatorFor(id_or_obj)
00128  
00129         if position is None:
00130             self._chain.append(validator)
00131         else:
00132             self._chain.insert(position, validator)
00133 
00134         return validator

Here is the caller graph for this function:


Member Data Documentation

validation.chain.ValidationChain.__implements__ = IValidationChain [static, private]

Definition at line 24 of file chain.py.

Definition at line 32 of file chain.py.

Definition at line 31 of file chain.py.

Definition at line 30 of file chain.py.

Definition at line 28 of file chain.py.

Definition at line 29 of file chain.py.


The documentation for this class was generated from the following file: