summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/identity.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/identity.py')
-rw-r--r--lib/sqlalchemy/orm/identity.py126
1 files changed, 0 insertions, 126 deletions
diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py
index e8e39346e..e4795a92d 100644
--- a/lib/sqlalchemy/orm/identity.py
+++ b/lib/sqlalchemy/orm/identity.py
@@ -7,7 +7,6 @@
import weakref
-from . import attributes
from . import util as orm_util
from .. import exc as sa_exc
from .. import util
@@ -239,128 +238,3 @@ class WeakInstanceDict(IdentityMap):
if st is state:
self._dict.pop(state.key, None)
self._manage_removed_state(state)
-
- def prune(self):
- return 0
-
-
-class StrongInstanceDict(IdentityMap):
- """A 'strong-referencing' version of the identity map.
-
- .. deprecated 1.1::
- The strong
- reference identity map is legacy. See the
- recipe at :ref:`session_referencing_behavior` for
- an event-based approach to maintaining strong identity
- references.
-
-
- """
-
- if util.py2k:
-
- def itervalues(self):
- return self._dict.itervalues()
-
- def iteritems(self):
- return self._dict.iteritems()
-
- def __iter__(self):
- return iter(self.dict_)
-
- def __getitem__(self, key):
- return self._dict[key]
-
- def __contains__(self, key):
- return key in self._dict
-
- def get(self, key, default=None):
- return self._dict.get(key, default)
-
- def values(self):
- return self._dict.values()
-
- def items(self):
- return self._dict.items()
-
- def all_states(self):
- return [attributes.instance_state(o) for o in self.values()]
-
- def contains_state(self, state):
- return (
- state.key in self
- and attributes.instance_state(self[state.key]) is state
- )
-
- def replace(self, state):
- if state.key in self._dict:
- existing = self._dict[state.key]
- existing = attributes.instance_state(existing)
- if existing is not state:
- self._manage_removed_state(existing)
- else:
- return
- else:
- existing = None
-
- self._dict[state.key] = state.obj()
- self._manage_incoming_state(state)
- return existing
-
- def add(self, state):
- if state.key in self:
- if attributes.instance_state(self._dict[state.key]) is not state:
- raise sa_exc.InvalidRequestError(
- "Can't attach instance "
- "%s; another instance with key %s is already "
- "present in this session."
- % (orm_util.state_str(state), state.key)
- )
- return False
- else:
- self._dict[state.key] = state.obj()
- self._manage_incoming_state(state)
- return True
-
- def _add_unpresent(self, state, key):
- # inlined form of add() called by loading.py
- self._dict[key] = state.obj()
- state._instance_dict = self._wr
-
- def _fast_discard(self, state):
- # used by InstanceState for state being
- # GC'ed, inlines _managed_removed_state
- try:
- obj = self._dict[state.key]
- except KeyError:
- # catch gc removed the key after we just checked for it
- pass
- else:
- if attributes.instance_state(obj) is state:
- self._dict.pop(state.key, None)
-
- def discard(self, state):
- self.safe_discard(state)
-
- def safe_discard(self, state):
- if state.key in self._dict:
- obj = self._dict[state.key]
- st = attributes.instance_state(obj)
- if st is state:
- self._dict.pop(state.key, None)
- self._manage_removed_state(state)
-
- def prune(self):
- """prune unreferenced, non-dirty states."""
-
- ref_count = len(self)
- dirty = [s.obj() for s in self.all_states() if s.modified]
-
- # work around http://bugs.python.org/issue6149
- keepers = weakref.WeakValueDictionary()
- keepers.update(self)
-
- self._dict.clear()
- self._dict.update(keepers)
- self.modified = bool(dirty)
- return ref_count - len(self)