<s> from gtfsobjectbase import GtfsObjectBase <EOL> from problems import default_problem_reporter <EOL> import util <EOL> class FareAttribute ( GtfsObjectBase ) : <EOL> """<STR_LIT>""" <EOL> _REQUIRED_FIELD_NAMES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> _FIELD_NAMES = _REQUIRED_FIELD_NAMES + [ '<STR_LIT>' ] <EOL> _TABLE_NAME = "<STR_LIT>" <EOL> def __init__ ( self , <EOL> fare_id = None , price = None , currency_type = None , <EOL> payment_method = None , transfers = None , transfer_duration = None , <EOL> field_dict = None ) : <EOL> self . _schedule = None <EOL> ( self . fare_id , self . price , self . currency_type , self . payment_method , <EOL> self . transfers , self . transfer_duration ) = ( fare_id , price , currency_type , payment_method , <EOL> transfers , transfer_duration ) <EOL> if field_dict : <EOL> if isinstance ( field_dict , FareAttribute ) : <EOL> for k , v in field_dict . iteritems ( ) : <EOL> self . __dict__ [ k ] = v <EOL> else : <EOL> self . __dict__ . update ( field_dict ) <EOL> self . rules = [ ] <EOL> try : <EOL> self . price = float ( self . price ) <EOL> except ( TypeError , ValueError ) : <EOL> pass <EOL> try : <EOL> self . payment_method = int ( self . payment_method ) <EOL> except ( TypeError , ValueError ) : <EOL> pass <EOL> if self . transfers == None or self . transfers == "<STR_LIT>" : <EOL> self . transfers = None <EOL> else : <EOL> try : <EOL> self . transfers = int ( self . transfers ) <EOL> except ( TypeError , ValueError ) : <EOL> pass <EOL> if self . transfer_duration == None or self . transfer_duration == "<STR_LIT>" : <EOL> self . transfer_duration = None <EOL> else : <EOL> try : <EOL> self . transfer_duration = int ( self . transfer_duration ) <EOL> except ( TypeError , ValueError ) : <EOL> pass <EOL> def GetFareRuleList ( self ) : <EOL> return self . rules <EOL> def ClearFareRules ( self ) : <EOL> self . rules = [ ] <EOL> def GetFieldValuesTuple ( self ) : <EOL> return [ getattr ( self , fn ) for fn in self . _FIELD_NAMES ] <EOL> def __getitem__ ( self , name ) : <EOL> return getattr ( self , name ) <EOL> def __eq__ ( self , other ) : <EOL> if not other : <EOL> return False <EOL> if id ( self ) == id ( other ) : <EOL> return True <EOL> if self . GetFieldValuesTuple ( ) != other . GetFieldValuesTuple ( ) : <EOL> return False <EOL> self_rules = [ r . GetFieldValuesTuple ( ) for r in self . GetFareRuleList ( ) ] <EOL> self_rules . sort ( ) <EOL> other_rules = [ r . GetFieldValuesTuple ( ) for r in other . GetFareRuleList ( ) ] <EOL> other_rules . sort ( ) <EOL> return self_rules == other_rules <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def ValidateFareId ( self , problems ) : <EOL> if util . IsEmpty ( self . fare_id ) : <EOL> problems . MissingValue ( "<STR_LIT>" ) <EOL> def ValidatePrice ( self , problems ) : <EOL> if self . price == None : <EOL> problems . MissingValue ( "<STR_LIT>" ) <EOL> elif not isinstance ( self . price , float ) and not isinstance ( self . price , int ) : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . price ) <EOL> elif self . price < <NUM_LIT:0> : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . price ) <EOL> def ValidateCurrencyType ( self , problems ) : <EOL> if util . IsEmpty ( self . currency_type ) : <EOL> problems . MissingValue ( "<STR_LIT>" ) <EOL> elif self . currency_type not in util . ISO4217 . codes : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . currency_type ) <EOL> def ValidatePaymentMethod ( self , problems ) : <EOL> if self . payment_method == "<STR_LIT>" or self . payment_method == None : <EOL> problems . MissingValue ( "<STR_LIT>" ) <EOL> elif ( not isinstance ( self . payment_method , int ) or <EOL> self . payment_method not in range ( <NUM_LIT:0> , <NUM_LIT:2> ) ) : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . payment_method ) <EOL> def ValidateTransfers ( self , problems ) : <EOL> if not ( ( self . transfers == None ) or <EOL> ( isinstance ( self . transfers , int ) and <EOL> self . transfers in range ( <NUM_LIT:0> , <NUM_LIT:3> ) ) ) : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . transfers ) <EOL> def ValidateTransferDuration ( self , problems ) : <EOL> if ( ( self . transfer_duration != None ) and <EOL> not isinstance ( self . transfer_duration , int ) ) : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . transfer_duration ) <EOL> if self . transfer_duration and ( self . transfer_duration < <NUM_LIT:0> ) : <EOL> problems . InvalidValue ( "<STR_LIT>" , self . transfer_duration ) <EOL> def Validate ( self , problems = default_problem_reporter ) : <EOL> self . ValidateFareId ( problems ) <EOL> self . ValidatePrice ( problems ) <EOL> self . ValidateCurrencyType ( problems ) <EOL> self . ValidatePaymentMethod ( problems ) <EOL> self . ValidateTransfers ( problems ) <EOL> self . ValidateTransferDuration ( problems ) <EOL> def ValidateBeforeAdd ( self , problems ) : <EOL> return True <EOL> def ValidateAfterAdd ( self , problems ) : <EOL> return <EOL> def AddToSchedule ( self , schedule = None , problems = None ) : <EOL> if schedule : <EOL> schedule . AddFareAttributeObject ( self , problems ) <EOL> self . _schedule = schedule </s>
