Exemplo n.º 1
0
def Broken(self, oid, pair):
    broken_klasses_lock.acquire()
    try:
        if pair in broken_klasses:
            klass = broken_klasses[pair]
        else:
            module, klassname = pair
            d = {'BrokenClass': BrokenClass}
            exec(
                "class %s(BrokenClass): ' '; __module__=%r" %
                (klassname, module), d)
            klass = broken_klasses[pair] = d[klassname]
            module = module.split('.')
            if len(module) > 2 and module[0] == 'Products':
                klass.product_name = module[1]
            klass.title = ('This object from the %s product '
                           'is broken!' % klass.product_name)
            klass.info = ('This object\'s class was %s in module %s.' %
                          (klass.__name__, klass.__module__))
            klass = persistentBroken(klass)
            LOG.warning('Could not import class %r '
                        'from module %r' % (klass.__name__, klass.__module__))
    finally:
        broken_klasses_lock.release()
    if oid is None:
        return klass
    i = klass()
    i._p_oid = oid
    i._p_jar = self
    return i
Exemplo n.º 2
0
    def load_persistent(self, oid, klass):
        # Quick instance reference.  We know all we need to know
        # to create the instance w/o hitting the db, so go for it!

        if not isinstance(oid, bytes):
            assert isinstance(oid, str)
            # this happens on Python 3 when all bytes in the oid are < 0x80
            oid = oid.encode("ascii")

        obj = self._cache.get(oid, None)
        if obj is not None:
            return obj

        if isinstance(klass, tuple):
            klass = self._get_class(*klass)

        if issubclass(klass, broken.Broken):
            # We got a broken class. We might need to make it
            # PersistentBroken
            if not issubclass(klass, broken.PersistentBroken):
                klass = broken.persistentBroken(klass)

        try:
            obj = klass.__new__(klass)
        except TypeError:
            # Couldn't create the instance.  Maybe there's more
            # current data in the object's actual record!
            return self._conn.get(oid)

        # TODO: should be done by connection
        self._cache.new_ghost(oid, obj)
        return obj
Exemplo n.º 3
0
    def getGhost(self, pickle):
        unpickler = self._get_unpickler(pickle)
        klass = unpickler.load()
        if isinstance(klass, tuple):
            # Here we have a separate class and args.
            # This could be an old record, so the class module ne a named
            # refernce
            klass, args = klass
            if isinstance(klass, tuple):
                # Old module_name, class_name tuple
                klass = self._get_class(*klass)

            if args is None:
                args = ()
        else:
            # Definitely new style direct class reference
            args = ()

        if issubclass(klass, broken.Broken):
            # We got a broken class. We might need to make it
            # PersistentBroken
            if not issubclass(klass, broken.PersistentBroken):
                klass = broken.persistentBroken(klass)

        return klass.__new__(klass, *args)
Exemplo n.º 4
0
    def load_persistent(self, oid, klass):
        # Quick instance reference.  We know all we need to know
        # to create the instance w/o hitting the db, so go for it!

        obj = self._cache.get(oid, None)
        if obj is not None:
            return obj

        if isinstance(klass, tuple):
            klass = self._get_class(*klass)

        if issubclass(klass, Broken):
            # We got a broken class. We might need to make it
            # PersistentBroken
            if not issubclass(klass, broken.PersistentBroken):
                klass = broken.persistentBroken(klass)

        try:
            obj = klass.__new__(klass)
        except TypeError:
            # Couldn't create the instance.  Maybe there's more
            # current data in the object's actual record!
            return self._conn.get(oid)

        # TODO: should be done by connection
        self._cache.new_ghost(oid, obj)
        return obj
Exemplo n.º 5
0
    def getGhost(self, pickle):
        unpickler = self._get_unpickler(pickle)
        klass = unpickler.load()
        if isinstance(klass, tuple):
            # Here we have a separate class and args.
            # This could be an old record, so the class module ne a named
            # refernce
            klass, args = klass
            if isinstance(klass, tuple):
                # Old module_name, class_name tuple
                klass = self._get_class(*klass)

            if args is None:
                args = ()
        else:
            # Definitely new style direct class reference
            args = ()

        if issubclass(klass, Broken):
            # We got a broken class. We might need to make it
            # PersistentBroken
            if not issubclass(klass, broken.PersistentBroken):
                klass = broken.persistentBroken(klass)

        return klass.__new__(klass, *args)
Exemplo n.º 6
0
def Broken(self, oid, pair):
    broken_klasses_lock.acquire()
    try:
        if pair in broken_klasses:
            klass = broken_klasses[pair]
        else:
            module, klassname = pair
            d = {'BrokenClass': BrokenClass}
            exec_("class %s(BrokenClass): ' '; __module__=%r" %
                  (klassname, module), d)
            klass = broken_klasses[pair] = d[klassname]
            module = module.split('.')
            if len(module) > 2 and module[0] == 'Products':
                klass.product_name = module[1]
            klass.title = (
                'This object from the %s product '
                'is broken!' %
                klass.product_name)
            klass.info = (
                'This object\'s class was %s in module %s.' %
                (klass.__name__, klass.__module__))
            klass = persistentBroken(klass)
            LOG.warning(
                'Could not import class %r '
                'from module %r' % (klass.__name__, klass.__module__))
    finally:
        broken_klasses_lock.release()
    if oid is None:
        return klass
    i = klass()
    i._p_oid = oid
    i._p_jar = self
    return i
Exemplo n.º 7
0
    def load_persistent(self, oid, klass):
        # Quick instance reference.  We know all we need to know
        # to create the instance w/o hitting the db, so go for it!

        obj = self._cache.get(oid, None)
        if obj is not None:
            return obj

        if isinstance(klass, tuple):
            klass = self._get_class(*klass)

        if issubclass(klass, Broken):
            # We got a broken class. We might need to make it
            # PersistentBroken
            if not issubclass(klass, broken.PersistentBroken):
                klass = broken.persistentBroken(klass)

        try:
            obj = klass.__new__(klass)
        except TypeError:
            # Couldn't create the instance.  Maybe there's more
            # current data in the object's actual record!
            return self._conn.get(oid)

        # TODO: should be done by connection
        obj._p_oid = oid
        obj._p_jar = self._conn
        # When an object is created, it is put in the UPTODATE
        # state.  We must explicitly deactivate it to turn it into
        # a ghost.
        obj._p_changed = None

        self._cache[oid] = obj
        return obj
Exemplo n.º 8
0
 def Broken(self, oid, pair):
   with lock:
     cached = pair in cache
     result = Uninstalled_Broken(self, oid, pair)
     if not cached:
       klass = cache.pop(pair)
       assert not issubclass(klass, PersistentBroken), \
         "This monkey-patch is not useful anymore"
       cache[pair] = persistentBroken(klass)
   return result
Exemplo n.º 9
0
 def Broken(self, oid, pair):
     with lock:
         cached = pair in cache
         result = Uninstalled_Broken(self, oid, pair)
         if not cached:
             klass = cache.pop(pair)
             assert not issubclass(klass, PersistentBroken), \
               "This monkey-patch is not useful anymore"
             cache[pair] = persistentBroken(klass)
     return result
Exemplo n.º 10
0
 def Broken(self, oid, pair):
   lock.acquire()
   try:
     cached = pair in cache
     result = Uninstalled_Broken(self, oid, pair)
     if not cached:
       klass = cache.pop(pair)
       assert not issubclass(klass, PersistentBroken), \
         "This monkey-patch is not useful anymore"
       cache[pair] = persistentBroken(klass)
   finally:
     lock.release()
   return result
Exemplo n.º 11
0
def load_persistent(self, oid, klass):
    # Quick instance reference.  We know all we need to know
    # to create the instance w/o hitting the db, so go for it!
    try:
        if getattr(STATS, 'stats', None) is None:
            init_stats()
        stats_cached = STATS.stats['zodb-cached']
        stats_uncached = STATS.stats['zodb-uncached']
    except:
        stats_cached = []
        stats_uncached = []

    t1 = datetime.now()

    obj = self._cache.get(oid, None)
    if obj is not None:
        stats_cached.append(datetime.now() - t1)
        return obj

    if isinstance(klass, tuple):
        klass = self._get_class(*klass)

    if issubclass(klass, Broken):
        # We got a broken class. We might need to make it
        # PersistentBroken
        if not issubclass(klass, broken.PersistentBroken):
            klass = broken.persistentBroken(klass)

    try:
        obj = klass.__new__(klass)
    except TypeError:
        # Couldn't create the instance.  Maybe there's more
        # current data in the object's actual record!
        stats_uncached.append(datetime.now() - t1)

        return self._conn.get(oid)

    if has_new_ghost:
        self._cache.new_ghost(oid, obj)
    else:
        obj._p_oid = oid
        obj._p_jar = self._conn
        obj._p_changed = None
        self._cache[oid] = obj

    stats_uncached.append(datetime.now() - t1)
    return obj