def get_lobject(self, session=None, mode=None): """Return an open file bounded to the represented large object. This is a context manager, so it should be used with the `with' clause this way: with fsobject.get_lobject() as lo: session (session object): the session to use, or None to use the one associated with the FSObject. mode (string): how to open the file (r -> read, w -> write, b -> binary). If None, use `rb'. """ if mode is None: mode = 'rb' if session is None: session = self.sa_session # Here we relay on the fact that we're using psycopg2 as # PostgreSQL backend lo = lobject(session.connection().connection.connection, self.loid) if self.loid == 0: self.loid = lo.oid try: yield lo finally: lo.close()
def get_lobject(self, session=None, mode=None): """Return an open file bounded to the represented large object. This is a context manager, so it should be used with the `with' clause this way: with fsobject.get_lobject() as lo: session (session object): the session to use, or None to use the one associated with the FSObject. mode (string): how to open the file (r -> read, w -> write, b -> binary). If None, use `rb'. """ if mode is None: mode = 'rb' if session is None: session = self.get_session() # Here we relay on the fact that we're using psycopg2 as # PostgreSQL backend lo = lobject(session.connection().connection.connection, self.loid) if self.loid == 0: self.loid = lo.oid try: yield lo finally: lo.close()
def check_lobject(self): """Check that the referenced large object is actually available in the database. """ try: lo = lobject(self.sa_session.connection().connection.connection, self.loid) lo.close() return True except OperationalError: return False
def check_lobject(self): """Check that the referenced large object is actually available in the database. """ try: lo = lobject(self.get_session().connection().connection.connection, self.loid) lo.close() return True except OperationalError: return False