regexp spec
mario ruggier <[email protected]>
| Newsgroups | gmane.comp.web.quixote.user |
|---|---|
| Message-ID | <[email protected]> |
Would this be a good way to define a regexp (dulcinea) ?
mario
class regexp(SpecOperator):
def __init__(self, pattern='^[-A-Za-z0-9_@.]*$'):
import re
self.re = re.compile(pattern)
self.args = (self.re,)
def __call__(self, value):
try:
if self.re.match(value):
return True
return False
except TypeError:
return False
def __str__(self):
return "string matching pattern '%s'" % (self.re.pattern)