<s> """<STR_LIT>""" <EOL> import re <EOL> import google <EOL> import ipaddr <EOL> from google . appengine . api import appinfo <EOL> from google . appengine . api import validation <EOL> from google . appengine . api import yaml_builder <EOL> from google . appengine . api import yaml_listener <EOL> from google . appengine . api import yaml_object <EOL> _DESCRIPTION_REGEX = r'<STR_LIT>' <EOL> BLACKLIST = '<STR_LIT>' <EOL> DESCRIPTION = '<STR_LIT:description>' <EOL> SUBNET = '<STR_LIT>' <EOL> class SubnetValidator ( validation . Validator ) : <EOL> """<STR_LIT>""" <EOL> def Validate ( self , value , unused_key = None ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> raise validation . MissingAttribute ( '<STR_LIT>' ) <EOL> if not isinstance ( value , basestring ) : <EOL> raise validation . ValidationError ( '<STR_LIT>' % <EOL> type ( value ) ) <EOL> try : <EOL> ipaddr . IPNetwork ( value ) <EOL> except ValueError : <EOL> raise validation . ValidationError ( '<STR_LIT>' % <EOL> value ) <EOL> parts = value . split ( '<STR_LIT:/>' ) <EOL> if len ( parts ) == <NUM_LIT:2> and not re . match ( '<STR_LIT>' , parts [ <NUM_LIT:1> ] ) : <EOL> raise validation . ValidationError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % value ) <EOL> return value <EOL> class MalformedDosConfiguration ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class BlacklistEntry ( validation . Validated ) : <EOL> """<STR_LIT>""" <EOL> ATTRIBUTES = { <EOL> DESCRIPTION : validation . Optional ( _DESCRIPTION_REGEX ) , <EOL> SUBNET : SubnetValidator ( ) , <EOL> } <EOL> class DosInfoExternal ( validation . Validated ) : <EOL> """<STR_LIT>""" <EOL> ATTRIBUTES = { <EOL> appinfo . APPLICATION : validation . Optional ( appinfo . APPLICATION_RE_STRING ) , <EOL> BLACKLIST : validation . Optional ( validation . Repeated ( BlacklistEntry ) ) , <EOL> } <EOL> def LoadSingleDos ( dos_info , open_fn = None ) : <EOL> """<STR_LIT>""" <EOL> builder = yaml_object . ObjectBuilder ( DosInfoExternal ) <EOL> handler = yaml_builder . BuilderHandler ( builder ) <EOL> listener = yaml_listener . EventListener ( handler ) <EOL> listener . Parse ( dos_info ) <EOL> parsed_yaml = handler . GetResults ( ) <EOL> if not parsed_yaml : <EOL> return DosInfoExternal ( ) <EOL> if len ( parsed_yaml ) > <NUM_LIT:1> : <EOL> raise MalformedDosConfiguration ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return parsed_yaml [ <NUM_LIT:0> ] </s>
