Home | Trees | Indices | Help |
---|
|
object --+ | basevalidator.BaseValidator --+ | ToCanonical
Reduce strings to a canonical form.
A common problem in cleaning user input is to catch trivial variants, e.g. how to recognise 'foo-bar', 'Foo-bar', ' foo-bar ' and 'foo_bar' as being the same value. This function achieves that by stripping flanking spaces, converting letters to uppercase and converting internal stretches of spaces, underscores and hyphens to a single underscore. Thus, all of the previous values would be converted to 'FOO_BAR'.
For example:
>>> v = ToCanonical() >>> v ('aBcD') 'ABCD' >>> v (' ab cd_') 'AB_CD_' >>> v ('AB-_ CD') 'AB_CD'
|
|||
|
|||
Inherited from Inherited from |
|
|||
Inherited from |
|
Transform a value to the desired form. This is the workhorse method that is called by convert to transform passed values. As such, errors are signalled by throwing a meaningful exception. This is one of the obvious and easiest places to customize behaviour by overriding in a subclass.
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jul 22 15:13:46 2011 | http://epydoc.sourceforge.net |