<s> """<STR_LIT>""" <EOL> import logging <EOL> import sys <EOL> import traceback <EOL> try : <EOL> import pytz <EOL> except ImportError : <EOL> pytz = None <EOL> from google . appengine . cron import groc <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> _URL_REGEX = r'<STR_LIT>' <EOL> _TIMEZONE_REGEX = r'<STR_LIT>' <EOL> _DESCRIPTION_REGEX = r'<STR_LIT>' <EOL> class GrocValidator ( validation . Validator ) : <EOL> """<STR_LIT>""" <EOL> def Validate ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> raise validation . MissingAttribute ( '<STR_LIT>' ) <EOL> if not isinstance ( value , basestring ) : <EOL> raise TypeError ( '<STR_LIT>' % type ( value ) ) <EOL> schedule = groc . CreateParser ( value ) <EOL> try : <EOL> schedule . timespec ( ) <EOL> except groc . GrocException , e : <EOL> raise validation . ValidationError ( '<STR_LIT>' % ( <EOL> value , e . args [ <NUM_LIT:0> ] ) ) <EOL> return value <EOL> class TimezoneValidator ( validation . Validator ) : <EOL> """<STR_LIT>""" <EOL> def Validate ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> return <EOL> if not isinstance ( value , basestring ) : <EOL> raise TypeError ( '<STR_LIT>' % type ( value ) ) <EOL> if pytz is None : <EOL> return value <EOL> try : <EOL> pytz . timezone ( value ) <EOL> except pytz . UnknownTimeZoneError : <EOL> raise validation . ValidationError ( '<STR_LIT>' % value ) <EOL> except IOError : <EOL> return value <EOL> except : <EOL> unused_e , v , t = sys . exc_info ( ) <EOL> logging . warning ( '<STR_LIT>' % ( v ) + <EOL> '<STR_LIT>' + '<STR_LIT:\n>' . join ( traceback . format_tb ( t ) ) ) <EOL> raise <EOL> return value <EOL> CRON = '<STR_LIT>' <EOL> URL = '<STR_LIT:url>' <EOL> SCHEDULE = '<STR_LIT>' <EOL> TIMEZONE = '<STR_LIT>' <EOL> DESCRIPTION = '<STR_LIT:description>' <EOL> class MalformedCronfigurationFile ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class CronEntry ( validation . Validated ) : <EOL> """<STR_LIT>""" <EOL> ATTRIBUTES = { <EOL> URL : _URL_REGEX , <EOL> SCHEDULE : GrocValidator ( ) , <EOL> TIMEZONE : TimezoneValidator ( ) , <EOL> DESCRIPTION : validation . Optional ( _DESCRIPTION_REGEX ) <EOL> } <EOL> class CronInfoExternal ( validation . Validated ) : <EOL> """<STR_LIT>""" <EOL> ATTRIBUTES = { <EOL> CRON : validation . Optional ( validation . Repeated ( CronEntry ) ) <EOL> } <EOL> def LoadSingleCron ( cron_info ) : <EOL> """<STR_LIT>""" <EOL> builder = yaml_object . ObjectBuilder ( CronInfoExternal ) <EOL> handler = yaml_builder . BuilderHandler ( builder ) <EOL> listener = yaml_listener . EventListener ( handler ) <EOL> listener . Parse ( cron_info ) <EOL> cron_info = handler . GetResults ( ) <EOL> if len ( cron_info ) < <NUM_LIT:1> : <EOL> raise MalformedCronfigurationFile ( '<STR_LIT>' ) <EOL> if len ( cron_info ) > <NUM_LIT:1> : <EOL> raise MalformedCronfigurationFile ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return cron_info [ <NUM_LIT:0> ] </s>
