<s> """<STR_LIT>""" <EOL> import re <EOL> from google . appengine . api import appinfo_errors <EOL> from google . appengine . api import validation <EOL> from google . appengine . api import yaml_listener <EOL> from google . appengine . api import yaml_builder <EOL> from google . appengine . api import yaml_object <EOL> _URL_REGEX = r'<STR_LIT>' <EOL> _FILES_REGEX = r'<STR_LIT>' <EOL> _DELTA_REGEX = r'<STR_LIT>' <EOL> _EXPIRATION_REGEX = r'<STR_LIT>' % ( _DELTA_REGEX , _DELTA_REGEX ) <EOL> APP_ID_MAX_LEN = <NUM_LIT:100> <EOL> MAJOR_VERSION_ID_MAX_LEN = <NUM_LIT:100> <EOL> MAX_URL_MAPS = <NUM_LIT:100> <EOL> APPLICATION_RE_STRING = r'<STR_LIT>' % APP_ID_MAX_LEN <EOL> VERSION_RE_STRING = r'<STR_LIT>' % MAJOR_VERSION_ID_MAX_LEN <EOL> HANDLER_STATIC_FILES = '<STR_LIT>' <EOL> HANDLER_STATIC_DIR = '<STR_LIT>' <EOL> HANDLER_SCRIPT = '<STR_LIT>' <EOL> LOGIN_OPTIONAL = '<STR_LIT>' <EOL> LOGIN_REQUIRED = '<STR_LIT>' <EOL> LOGIN_ADMIN = '<STR_LIT>' <EOL> RUNTIME_PYTHON = '<STR_LIT>' <EOL> DEFAULT_SKIP_FILES = ( r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" <EOL> r"<STR_LIT>" ) <EOL> LOGIN = '<STR_LIT>' <EOL> URL = '<STR_LIT:url>' <EOL> STATIC_FILES = '<STR_LIT>' <EOL> UPLOAD = '<STR_LIT>' <EOL> STATIC_DIR = '<STR_LIT>' <EOL> MIME_TYPE = '<STR_LIT>' <EOL> SCRIPT = '<STR_LIT>' <EOL> EXPIRATION = '<STR_LIT>' <EOL> APPLICATION = '<STR_LIT>' <EOL> VERSION = '<STR_LIT:version>' <EOL> RUNTIME = '<STR_LIT>' <EOL> API_VERSION = '<STR_LIT>' <EOL> HANDLERS = '<STR_LIT>' <EOL> DEFAULT_EXPIRATION = '<STR_LIT>' <EOL> SKIP_FILES = '<STR_LIT>' <EOL> class URLMap ( validation . Validated ) : <EOL> """<STR_LIT>""" <EOL> ATTRIBUTES = { <EOL> URL : validation . Optional ( _URL_REGEX ) , <EOL> LOGIN : validation . Options ( LOGIN_OPTIONAL , <EOL> LOGIN_REQUIRED , <EOL> LOGIN_ADMIN , <EOL> default = LOGIN_OPTIONAL ) , <EOL> HANDLER_STATIC_FILES : validation . Optional ( _FILES_REGEX ) , <EOL> UPLOAD : validation . Optional ( _FILES_REGEX ) , <EOL> HANDLER_STATIC_DIR : validation . Optional ( _FILES_REGEX ) , <EOL> MIME_TYPE : validation . Optional ( str ) , <EOL> EXPIRATION : validation . Optional ( _EXPIRATION_REGEX ) , <EOL> HANDLER_SCRIPT : validation . Optional ( _FILES_REGEX ) , <EOL> } <EOL> COMMON_FIELDS = set ( [ URL , LOGIN ] ) <EOL> ALLOWED_FIELDS = { <EOL> HANDLER_STATIC_FILES : ( MIME_TYPE , UPLOAD , EXPIRATION ) , <EOL> HANDLER_STATIC_DIR : ( MIME_TYPE , EXPIRATION ) , <EOL> HANDLER_SCRIPT : ( ) , <EOL> } <EOL> def GetHandler ( self ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self , self . GetHandlerType ( ) ) <EOL> def GetHandlerType ( self ) : <EOL> """<STR_LIT>""" <EOL> for id_field in URLMap . ALLOWED_FIELDS . iterkeys ( ) : <EOL> if getattr ( self , id_field ) is not None : <EOL> mapping_type = id_field <EOL> break <EOL> else : <EOL> raise appinfo_errors . UnknownHandlerType ( <EOL> '<STR_LIT>' % str ( self ) ) <EOL> allowed_fields = URLMap . ALLOWED_FIELDS [ mapping_type ] <EOL> for attribute in self . ATTRIBUTES . iterkeys ( ) : <EOL> if ( getattr ( self , attribute ) is not None and <EOL> not ( attribute in allowed_fields or <EOL> attribute in URLMap . COMMON_FIELDS or <EOL> attribute == mapping_type ) ) : <EOL> raise appinfo_errors . UnexpectedHandlerAttribute ( <EOL> '<STR_LIT>' % <EOL> ( attribute , mapping_type ) ) <EOL> if mapping_type == HANDLER_STATIC_FILES and not self . upload : <EOL> raise appinfo_errors . MissingHandlerAttribute ( <EOL> '<STR_LIT>' % ( UPLOAD , self . url ) ) <EOL> return mapping_type <EOL> def CheckInitialized ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( URLMap , self ) . CheckInitialized ( ) <EOL> self . GetHandlerType ( ) <EOL> class AppInfoExternal ( validation . Validated ) : <EOL> """<STR_LIT>""" <EOL> ATTRIBUTES = { <EOL> APPLICATION : APPLICATION_RE_STRING , <EOL> VERSION : VERSION_RE_STRING , <EOL> RUNTIME : validation . Options ( RUNTIME_PYTHON ) , <EOL> API_VERSION : validation . Options ( '<STR_LIT:1>' , '<STR_LIT>' ) , <EOL> HANDLERS : validation . Optional ( validation . Repeated ( URLMap ) ) , <EOL> DEFAULT_EXPIRATION : validation . Optional ( _EXPIRATION_REGEX ) , <EOL> SKIP_FILES : validation . RegexStr ( default = DEFAULT_SKIP_FILES ) <EOL> } <EOL> def CheckInitialized ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( AppInfoExternal , self ) . CheckInitialized ( ) <EOL> if not self . handlers : <EOL> raise appinfo_errors . MissingURLMapping ( <EOL> '<STR_LIT>' ) <EOL> if len ( self . handlers ) > MAX_URL_MAPS : <EOL> raise appinfo_errors . TooManyURLMappings ( <EOL> '<STR_LIT>' % <EOL> MAX_URL_MAPS ) <EOL> def LoadSingleAppInfo ( app_info ) : <EOL> """<STR_LIT>""" <EOL> builder = yaml_object . ObjectBuilder ( AppInfoExternal ) <EOL> handler = yaml_builder . BuilderHandler ( builder ) <EOL> listener = yaml_listener . EventListener ( handler ) <EOL> listener . Parse ( app_info ) <EOL> app_infos = handler . GetResults ( ) <EOL> if len ( app_infos ) < <NUM_LIT:1> : <EOL> raise appinfo_errors . EmptyConfigurationFile ( ) <EOL> if len ( app_infos ) > <NUM_LIT:1> : <EOL> raise appinfo_errors . MultipleConfigurationFile ( ) <EOL> return app_infos [ <NUM_LIT:0> ] <EOL> _file_path_positive_re = re . compile ( r'<STR_LIT>' ) <EOL> _file_path_negative_1_re = re . compile ( r'<STR_LIT>' ) <EOL> _file_path_negative_2_re = re . compile ( r'<STR_LIT>' ) <EOL> _file_path_negative_3_re = re . compile ( r'<STR_LIT>' ) <EOL> def ValidFilename ( filename ) : <EOL> """<STR_LIT>""" <EOL> if _file_path_positive_re . match ( filename ) is None : <EOL> return '<STR_LIT>' % filename <EOL> if _file_path_negative_1_re . search ( filename ) is not None : <EOL> return ( '<STR_LIT>' % <EOL> filename ) <EOL> if _file_path_negative_2_re . search ( filename ) is not None : <EOL> return '<STR_LIT>' % filename <EOL> if _file_path_negative_3_re . search ( filename ) is not None : <EOL> return '<STR_LIT>' % filename <EOL> return '<STR_LIT>' </s>
