Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Private Attributes
validation.validators.RegexValidator.RegexValidator Class Reference

List of all members.

Public Member Functions

def __init__
def compileRegex
def __getstate__
def __setstate__
def __call__

Public Attributes

 name
 title
 description
 errmsg
 regex_strings
 ignore
 regex

Static Private Attributes

 __implements__ = IValidator

Detailed Description

Definition at line 16 of file RegexValidator.py.


Constructor & Destructor Documentation

def validation.validators.RegexValidator.RegexValidator.__init__ (   self,
  name,
  args,
  kw 
)

Definition at line 19 of file RegexValidator.py.

00019 
00020     def __init__(self, name, *args, **kw):
00021         self.name = name
00022         self.title = kw.get('title', name)
00023         self.description = kw.get('description', '')
00024         self.errmsg = kw.get('errmsg', 'fails tests of %s' % name)
00025         self.regex_strings = args
00026         self.ignore = kw.get('ignore', None)
00027         self.regex = []
00028         self.compileRegex()


Member Function Documentation

def validation.validators.RegexValidator.RegexValidator.__call__ (   self,
  value,
  args,
  kwargs 
)

Definition at line 45 of file RegexValidator.py.

00045 
00046     def __call__(self, value, *args, **kwargs):
00047         if type(value) != StringType:
00048             return ("Validation failed(%(name)s): %(value)s of type %(type)s, expected 'string'" %
00049                     { 'name' : self.name, 'value': value, 'type' : type(value)})
00050 
00051         ignore = kwargs.get('ignore', None)
00052         if ignore:
00053             value = ignoreRE(value, ignore)
00054         elif self.ignore:
00055             value = ignoreRE(value, self.ignore)
00056 
00057 
00058         for r in self.regex:
00059             m = r.match(value)
00060             if not m:
00061                 return ("Validation failed(%(name)s): '%(value)s' %(errmsg)s" % 
00062                         { 'name' : self.name, 'value': value, 'errmsg' : self.errmsg})
00063         return 1

Here is the call graph for this function:

Because copy.deepcopy and pickle.dump cannot pickle a regex pattern
I'm using the getstate/setstate hooks to set self.regex to []

Definition at line 33 of file RegexValidator.py.

00033 
00034     def __getstate__(self):
00035         """Because copy.deepcopy and pickle.dump cannot pickle a regex pattern
00036         I'm using the getstate/setstate hooks to set self.regex to []
00037         """
00038         d = self.__dict__.copy()
00039         d['regex'] = []
00040         return d
    

Definition at line 41 of file RegexValidator.py.

00041 
00042     def __setstate__(self, dict):
00043         self.__dict__.update(dict)
00044         self.compileRegex()

Here is the call graph for this function:

Definition at line 29 of file RegexValidator.py.

00029 
00030     def compileRegex(self):
00031         for r in self.regex_strings:
00032             self.regex.append(re.compile(r))        
    

Here is the caller graph for this function:


Member Data Documentation

Definition at line 17 of file RegexValidator.py.

Definition at line 22 of file RegexValidator.py.

Definition at line 23 of file RegexValidator.py.

Definition at line 25 of file RegexValidator.py.

Definition at line 20 of file RegexValidator.py.

Definition at line 26 of file RegexValidator.py.

Definition at line 24 of file RegexValidator.py.

Definition at line 21 of file RegexValidator.py.


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