<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import re <EOL> from . api import FancyValidator <EOL> from . compound import Any <EOL> from . validators import Regex , Invalid , _ <EOL> import six <EOL> try : <EOL> import pycountry <EOL> except ImportError : <EOL> pycountry = None <EOL> try : <EOL> from turbogears . i18n import format as tgformat <EOL> except ImportError : <EOL> tgformat = None <EOL> if pycountry or tgformat : <EOL> no_country = False <EOL> else : <EOL> import warnings <EOL> no_country = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> country_additions = [ <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ] <EOL> fuzzy_countrynames = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ] <EOL> if tgformat : <EOL> def get_countries ( ) : <EOL> c1 = tgformat . get_countries ( '<STR_LIT>' ) <EOL> c2 = tgformat . get_countries ( ) <EOL> if len ( c1 ) > len ( c2 ) : <EOL> d = dict ( country_additions ) <EOL> d . update ( dict ( c1 ) ) <EOL> d . update ( dict ( c2 ) ) <EOL> else : <EOL> d = dict ( country_additions ) <EOL> d . update ( dict ( c2 ) ) <EOL> ret = list ( d . items ( ) ) + fuzzy_countrynames <EOL> return ret <EOL> def get_country ( code ) : <EOL> return dict ( get_countries ( ) ) [ code ] <EOL> def get_languages ( ) : <EOL> c1 = tgformat . get_languages ( '<STR_LIT>' ) <EOL> c2 = tgformat . get_languages ( ) <EOL> if len ( c1 ) > len ( c2 ) : <EOL> d = dict ( c1 ) <EOL> d . update ( dict ( c2 ) ) <EOL> return list ( d . items ( ) ) <EOL> else : <EOL> return c2 <EOL> def get_language ( code ) : <EOL> try : <EOL> return tgformat . get_language ( code ) <EOL> except KeyError : <EOL> return tgformat . get_language ( code , '<STR_LIT>' ) <EOL> elif pycountry : <EOL> import gettext <EOL> gettext . bindtextdomain ( '<STR_LIT>' , pycountry . LOCALES_DIR ) <EOL> _c = lambda t : gettext . dgettext ( '<STR_LIT>' , t ) <EOL> gettext . bindtextdomain ( '<STR_LIT>' , pycountry . LOCALES_DIR ) <EOL> _l = lambda t : gettext . dgettext ( '<STR_LIT>' , t ) <EOL> def get_countries ( ) : <EOL> c1 = set ( [ ( e . alpha2 , _c ( e . name ) ) for e in pycountry . countries ] ) <EOL> ret = c1 . union ( country_additions + fuzzy_countrynames ) <EOL> return ret <EOL> def get_country ( code ) : <EOL> return _c ( pycountry . countries . get ( alpha2 = code ) . name ) <EOL> try : <EOL> if not pycountry . languages . get ( iso639_1_code = '<STR_LIT>' ) : <EOL> raise KeyError <EOL> except KeyError : <EOL> def get_languages ( ) : <EOL> return [ ( e . alpha2 , _l ( e . name ) ) for e in pycountry . languages <EOL> if e . name and getattr ( e , '<STR_LIT>' , None ) ] <EOL> def get_language ( code ) : <EOL> return _l ( pycountry . languages . get ( alpha2 = code ) . name ) <EOL> else : <EOL> def get_languages ( ) : <EOL> return [ ( e . iso639_1_code , _l ( e . name ) ) for e in pycountry . languages <EOL> if e . name and getattr ( e , '<STR_LIT>' , None ) ] <EOL> def get_language ( code ) : <EOL> return _l ( pycountry . languages . get ( iso639_1_code = code ) . name ) <EOL> class DelimitedDigitsPostalCode ( Regex ) : <EOL> """<STR_LIT>""" <EOL> strip = True <EOL> def assembly_formatstring ( self , partition_lengths , delimiter ) : <EOL> if len ( partition_lengths ) == <NUM_LIT:1> : <EOL> return _ ( '<STR_LIT>' ) % partition_lengths [ <NUM_LIT:0> ] <EOL> else : <EOL> return delimiter . join ( '<STR_LIT:n>' * l for l in partition_lengths ) <EOL> def assembly_regex ( self , partition_lengths , delimiter , strict ) : <EOL> mg = [ r'<STR_LIT>' % l for l in partition_lengths ] <EOL> rd = r'<STR_LIT>' % delimiter <EOL> regex = rd . join ( mg ) <EOL> if strict : <EOL> regex = "<STR_LIT>" + regex + "<STR_LIT:$>" <EOL> return regex <EOL> def __init__ ( self , partition_lengths , delimiter = None , strict = False , <EOL> * args , ** kw ) : <EOL> if isinstance ( partition_lengths , six . integer_types ) : <EOL> partition_lengths = [ partition_lengths ] <EOL> if not delimiter : <EOL> delimiter = '<STR_LIT>' <EOL> self . format = self . assembly_formatstring ( partition_lengths , delimiter ) <EOL> self . regex = self . assembly_regex ( partition_lengths , delimiter , strict ) <EOL> self . partition_lengths , self . delimiter = partition_lengths , delimiter <EOL> Regex . __init__ ( self , * args , ** kw ) <EOL> messages = dict ( <EOL> invalid = _ ( '<STR_LIT>' ) ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . regex . search ( value ) <EOL> if not match : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state , format = self . format ) , <EOL> value , state ) <EOL> return self . delimiter . join ( match . groups ( ) ) <EOL> def USPostalCode ( * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> return Any ( DelimitedDigitsPostalCode ( <NUM_LIT:5> , None , * args , ** kw ) , <EOL> DelimitedDigitsPostalCode ( [ <NUM_LIT:5> , <NUM_LIT:4> ] , '<STR_LIT:->' , * args , ** kw ) ) <EOL> def GermanPostalCode ( * args , ** kw ) : <EOL> return DelimitedDigitsPostalCode ( <NUM_LIT:5> , None , * args , ** kw ) <EOL> def FourDigitsPostalCode ( * args , ** kw ) : <EOL> return DelimitedDigitsPostalCode ( <NUM_LIT:4> , None , * args , ** kw ) <EOL> def PolishPostalCode ( * args , ** kw ) : <EOL> return DelimitedDigitsPostalCode ( [ <NUM_LIT:2> , <NUM_LIT:3> ] , '<STR_LIT:->' , * args , ** kw ) <EOL> class ArgentinianPostalCode ( Regex ) : <EOL> """<STR_LIT>""" <EOL> format = _ ( '<STR_LIT>' ) <EOL> regex = re . compile ( r'<STR_LIT>' ) <EOL> strip = True <EOL> messages = dict ( <EOL> invalid = _ ( '<STR_LIT>' ) ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . regex . search ( value ) <EOL> if not match : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state , format = self . format ) , <EOL> value , state ) <EOL> return '<STR_LIT>' % ( match . group ( <NUM_LIT:1> ) . upper ( ) , <EOL> match . group ( <NUM_LIT:2> ) , <EOL> match . group ( <NUM_LIT:3> ) . upper ( ) ) <EOL> class CanadianPostalCode ( Regex ) : <EOL> """<STR_LIT>""" <EOL> format = _ ( '<STR_LIT>' ) <EOL> regex = re . compile ( r'<STR_LIT>' ) <EOL> strip = True <EOL> messages = dict ( <EOL> invalid = _ ( '<STR_LIT>' ) ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . regex . search ( value ) <EOL> if not match : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state , format = self . format ) , <EOL> value , state ) <EOL> return '<STR_LIT>' % ( match . group ( <NUM_LIT:1> ) . upper ( ) , match . group ( <NUM_LIT:2> ) . upper ( ) ) <EOL> class DutchPostalCode ( Regex ) : <EOL> """<STR_LIT>""" <EOL> format = _ ( '<STR_LIT>' ) <EOL> regex = re . compile ( r'<STR_LIT>' ) <EOL> strip = True <EOL> messages = dict ( <EOL> invalid = _ ( '<STR_LIT>' ) ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . regex . search ( value ) <EOL> if not match : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state , format = self . format ) , <EOL> value , state ) <EOL> return '<STR_LIT>' % ( match . group ( <NUM_LIT:1> ) , match . group ( <NUM_LIT:2> ) . upper ( ) ) <EOL> class UKPostalCode ( Regex ) : <EOL> """<STR_LIT>""" <EOL> regex = re . compile ( r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , re . I ) <EOL> strip = True <EOL> messages = dict ( <EOL> invalid = _ ( '<STR_LIT>' ) ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . regex . search ( value ) <EOL> if not match : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state ) , <EOL> value , state ) <EOL> value = match . group ( <NUM_LIT:1> ) . upper ( ) <EOL> if not value . startswith ( '<STR_LIT>' ) : <EOL> value = value . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> value = '<STR_LIT>' % ( value [ : - <NUM_LIT:3> ] , value [ - <NUM_LIT:3> : ] ) <EOL> return value <EOL> class CountryValidator ( FancyValidator ) : <EOL> """<STR_LIT>""" <EOL> key_ok = True <EOL> messages = dict ( <EOL> valueNotFound = _ ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , * args , ** kw ) : <EOL> FancyValidator . __init__ ( self , * args , ** kw ) <EOL> if no_country : <EOL> warnings . warn ( no_country , Warning , <NUM_LIT:2> ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> upval = value . upper ( ) <EOL> if self . key_ok : <EOL> try : <EOL> get_country ( upval ) <EOL> except Exception : <EOL> pass <EOL> else : <EOL> return upval <EOL> for k , v in get_countries ( ) : <EOL> if v . upper ( ) == upval : <EOL> return k <EOL> raise Invalid ( self . message ( '<STR_LIT>' , state ) , value , state ) <EOL> def _convert_from_python ( self , value , state ) : <EOL> try : <EOL> return get_country ( value . upper ( ) ) <EOL> except KeyError : <EOL> return value <EOL> class PostalCodeInCountryFormat ( FancyValidator ) : <EOL> """<STR_LIT>""" <EOL> country_field = '<STR_LIT>' <EOL> zip_field = '<STR_LIT>' <EOL> __unpackargs__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = dict ( <EOL> badFormat = _ ( "<STR_LIT>" ) ) <EOL> _vd = { <EOL> '<STR_LIT>' : ArgentinianPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : CanadianPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:7> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:6> ) , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : GermanPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : UKPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( [ <NUM_LIT:2> , <NUM_LIT:3> ] , '<STR_LIT:U+0020>' ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:3> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( [ <NUM_LIT:3> , <NUM_LIT:4> ] , '<STR_LIT:->' ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( [ <NUM_LIT:3> , <NUM_LIT:3> ] , '<STR_LIT:->' ) , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> ] , '<STR_LIT:->' ) , <EOL> '<STR_LIT>' : DutchPostalCode , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : PolishPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( [ <NUM_LIT:4> , <NUM_LIT:3> ] , '<STR_LIT:->' ) , <EOL> '<STR_LIT>' : FourDigitsPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:6> ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( [ <NUM_LIT:3> , <NUM_LIT:2> ] , '<STR_LIT:U+0020>' ) , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:6> ) , <EOL> '<STR_LIT>' : USPostalCode , <EOL> '<STR_LIT>' : lambda : DelimitedDigitsPostalCode ( <NUM_LIT:5> ) , <EOL> } <EOL> def _validate_python ( self , fields_dict , state ) : <EOL> if fields_dict [ self . country_field ] in self . _vd : <EOL> zip_validator = self . _vd [ fields_dict [ self . country_field ] ] ( ) <EOL> try : <EOL> fields_dict [ self . zip_field ] = zip_validator . to_python ( <EOL> fields_dict [ self . zip_field ] , state = state ) <EOL> except Invalid as e : <EOL> message = self . message ( '<STR_LIT>' , state ) <EOL> raise Invalid ( message , fields_dict , state , <EOL> error_dict = { self . zip_field : e . msg , <EOL> self . country_field : message } ) <EOL> class USStateProvince ( FancyValidator ) : <EOL> """<STR_LIT>""" <EOL> states = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:OK>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> extra_states = [ ] <EOL> __unpackargs__ = ( '<STR_LIT>' , ) <EOL> messages = dict ( <EOL> empty = _ ( '<STR_LIT>' ) , <EOL> wrongLength = _ ( '<STR_LIT>' ) , <EOL> invalid = _ ( '<STR_LIT>' ) ) <EOL> def _validate_python ( self , value , state ) : <EOL> value = str ( value ) . strip ( ) . upper ( ) <EOL> if not value : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state ) , <EOL> value , state ) <EOL> if not value or len ( value ) != <NUM_LIT:2> : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state ) , <EOL> value , state ) <EOL> if value not in self . states and not ( <EOL> self . extra_states and value in self . extra_states ) : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state ) , <EOL> value , state ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> return str ( value ) . strip ( ) . upper ( ) <EOL> class USPhoneNumber ( FancyValidator ) : <EOL> """<STR_LIT>""" <EOL> _phoneRE = re . compile ( r'<STR_LIT>' <EOL> '<STR_LIT>' , re . I ) <EOL> messages = dict ( <EOL> phoneFormat = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . _phoneRE . search ( value ) <EOL> if not match : <EOL> raise Invalid ( <EOL> self . message ( '<STR_LIT>' , state ) , <EOL> value , state ) <EOL> return value <EOL> def _convert_from_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> match = self . _phoneRE . search ( value ) <EOL> if not match : <EOL> raise Invalid ( self . message ( '<STR_LIT>' , state ) , <EOL> value , state ) <EOL> result = '<STR_LIT>' % ( match . group ( <NUM_LIT:1> ) , match . group ( <NUM_LIT:2> ) , match . group ( <NUM_LIT:3> ) ) <EOL> if match . group ( <NUM_LIT:4> ) : <EOL> result += "<STR_LIT>" % match . group ( <NUM_LIT:4> ) <EOL> return result <EOL> class InternationalPhoneNumber ( FancyValidator ) : <EOL> """<STR_LIT>""" <EOL> strip = True <EOL> default_cc = None <EOL> _mark_chars_re = re . compile ( r"<STR_LIT>" ) <EOL> _preTransformations = [ <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ] <EOL> _ccIncluder = [ <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ] <EOL> _postTransformations = [ <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ] <EOL> _phoneIsSane = re . compile ( r'<STR_LIT>' ) <EOL> messages = dict ( <EOL> phoneFormat = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> def _perform_rex_transformation ( self , value , transformations ) : <EOL> for rex , trf in transformations : <EOL> match = rex . search ( value ) <EOL> if match : <EOL> value = trf % match . groups ( ) <EOL> return value <EOL> def _prepend_country_code ( self , value , transformations , country_code ) : <EOL> for rex , trf in transformations : <EOL> match = rex . search ( value ) <EOL> if match : <EOL> return trf % ( ( country_code , ) + match . groups ( ) ) <EOL> return value <EOL> def _convert_to_python ( self , value , state ) : <EOL> self . assert_string ( value , state ) <EOL> try : <EOL> value = value . encode ( '<STR_LIT:ascii>' , '<STR_LIT:strict>' ) <EOL> except UnicodeEncodeError : <EOL> raise Invalid ( self . message ( '<STR_LIT>' , state ) , value , state ) <EOL> if six . text_type is str : <EOL> value = value . decode ( '<STR_LIT:ascii>' ) <EOL> value = self . _mark_chars_re . sub ( '<STR_LIT:->' , value ) <EOL> for f , t in [ ( '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:->' ) , ( '<STR_LIT>' , '<STR_LIT:->' ) , ( '<STR_LIT>' , '<STR_LIT:->' ) , ( '<STR_LIT>' , '<STR_LIT:->' ) ] : <EOL> value = value . replace ( f , t ) <EOL> value = self . _perform_rex_transformation ( <EOL> value , self . _preTransformations ) <EOL> if self . default_cc : <EOL> if callable ( self . default_cc ) : <EOL> cc = self . default_cc ( ) <EOL> else : <EOL> cc = self . default_cc <EOL> value = self . _prepend_country_code ( value , self . _ccIncluder , cc ) <EOL> value = self . _perform_rex_transformation ( <EOL> value , self . _postTransformations ) <EOL> value = value . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> if not self . _phoneIsSane . search ( value ) : <EOL> raise Invalid ( self . message ( '<STR_LIT>' , state ) , value , state ) <EOL> return value <EOL> class LanguageValidator ( FancyValidator ) : <EOL> """<STR_LIT>""" <EOL> key_ok = True <EOL> messages = dict ( <EOL> valueNotFound = _ ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , * args , ** kw ) : <EOL> FancyValidator . __init__ ( self , * args , ** kw ) <EOL> if no_country : <EOL> warnings . warn ( no_country , Warning , <NUM_LIT:2> ) <EOL> def _convert_to_python ( self , value , state ) : <EOL> upval = value . upper ( ) <EOL> if self . key_ok : <EOL> try : <EOL> get_language ( value ) <EOL> except Exception : <EOL> pass <EOL> else : <EOL> return value <EOL> for k , v in get_languages ( ) : <EOL> if v . upper ( ) == upval : <EOL> return k <EOL> raise Invalid ( self . message ( '<STR_LIT>' , state ) , value , state ) <EOL> def _convert_from_python ( self , value , state ) : <EOL> try : <EOL> return get_language ( value . lower ( ) ) <EOL> except KeyError : <EOL> return value <EOL> def validators ( ) : <EOL> """<STR_LIT>""" <EOL> return [ name for name , value in list ( globals ( ) . items ( ) ) <EOL> if isinstance ( value , type ) and issubclass ( value , FancyValidator ) ] <EOL> __all__ = [ '<STR_LIT>' ] + validators ( ) </s>
