def get_postgres_connection(host, port, database=None):
 def connect_to_postgres():
  try:
   return connect(host=host, user=u'postgres', port=port, database=database)
  except (InterfaceError, ProgrammingError) as e:
   Message.new(message_type=u'acceptance:integration:postgres_connect', exception=unicode(e.__class__), reason=unicode(e)).write()
   return False
 d = loop_until(reactor, connect_to_postgres)
 return d

def get_postgres_connection ( host , port , database = None ) : def connect_to_postgres ( ) : try : return connect ( host = host , user = u'postgres' , port = port , database = database ) except ( InterfaceError , ProgrammingError ) as e : Message . new ( message_type = u'acceptance:integration:postgres_connect' , exception = unicode ( e . __class__ ) , reason = unicode ( e ) ) . write ( ) return False d = loop_until ( reactor , connect_to_postgres ) return d
returns a deferred which fires with a pg8000 connection when one has been created .