code: def query(self, query, param=None):
          
  
          with self.conn.cursor() as curs:
              print 'XXX QUERY', curs.mogrify(query, param)
              try:
                  curs.execute(query, param)
              except BaseException as exc:
                  msg = 'query: {}, param: {}, exc: {}'.format(query, param, exc)
  
                  if hasattr(exc, 'pgcode'):
                      msg = '{}, exc code: {}'.format(msg, exc.pgcode)
  
                  print msg
                  handle_exc(exc)
  
              result = curs.fetchall()
  
          return result
docs: Perform a SQL based query
  
          This will abort on a failure to communicate with
          the database.
  
          :query: string query
          :params: parameters for the query
          :return: RecordList from psycopg2