def findStoredTicket(bridge):
 assert bridge
 ticketFile = (const.STATE_LOCATION + const.CLIENT_TICKET_FILE)
 log.debug(("Attempting to read master key and ticket from file `%s'." % ticketFile))
 yamlBlurb = util.readFromFile(ticketFile)
 if ((yamlBlurb is None) or (len(yamlBlurb) == 0)):
  return None
 tickets = yaml.safe_load(yamlBlurb)
 try:
  (timestamp, masterKey, ticket) = tickets[str(bridge)]
 except KeyError:
  log.info(("Found no ticket for bridge `%s'." % str(bridge)))
  return None
 log.debug('Deleting ticket since it is about to be redeemed.')
 del tickets[str(bridge)]
 util.writeToFile(yaml.dump(tickets), ticketFile)
 ticketAge = (int(time.time()) - timestamp)
 if (ticketAge > const.SESSION_TICKET_LIFETIME):
  log.warning(('We did have a ticket but it already expired %s ago.' % str(datetime.timedelta(seconds=(ticketAge - const.SESSION_TICKET_LIFETIME)))))
  return None
 return (masterKey, ticket)

def findStoredTicket ( bridge ) : assert bridge ticketFile = ( const . STATE_LOCATION + const . CLIENT_TICKET_FILE ) log . debug ( ( "Attempting to read master key and ticket from file `%s'." % ticketFile ) ) yamlBlurb = util . readFromFile ( ticketFile ) if ( ( yamlBlurb is None ) or ( len ( yamlBlurb ) == 0 ) ) : return None tickets = yaml . safe_load ( yamlBlurb ) try : ( timestamp , masterKey , ticket ) = tickets [ str ( bridge ) ] except KeyError : log . info ( ( "Found no ticket for bridge `%s'." % str ( bridge ) ) ) return None log . debug ( 'Deleting ticket since it is about to be redeemed.' ) del tickets [ str ( bridge ) ] util . writeToFile ( yaml . dump ( tickets ) , ticketFile ) ticketAge = ( int ( time . time ( ) ) - timestamp ) if ( ticketAge > const . SESSION_TICKET_LIFETIME ) : log . warning ( ( 'We did have a ticket but it already expired %s ago.' % str ( datetime . timedelta ( seconds = ( ticketAge - const . SESSION_TICKET_LIFETIME ) ) ) ) ) return None return ( masterKey , ticket )
retrieve a previously stored ticket from the ticket dictionary .