示例#1
0
文件: photo.py 项目: bchoward/homehub
    def get_lobject(self, 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:

        mode (string): how to open the file (r -> read, w -> write,
                       b -> binary). If None, use `rb'.

        """
        if mode is None:
            mode = 'rb'

        # Here we rely on the fact that we're using psycopg2 as
        # PostgreSQL backend
        lo = session.connection().connection.lobject(self.loid, mode)

        if self.loid == 0:
            self.loid = lo.oid

        try:
            yield lo
        finally:
            lo.close()
示例#2
0
文件: photo.py 项目: bchoward/homehub
    def check_lobject(self):
        """Check that the referenced large object is actually
        available in the database.

        """
        try:
            lo = session.connection().connection.lobject(self.loid)
            lo.close()
            return True
        except OperationalError:
            return False