~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/orm/state.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from . import base
21
21
 
22
22
class InstanceState(interfaces._InspectionAttr):
23
 
    """tracks state information at the instance level."""
 
23
    """tracks state information at the instance level.
 
24
 
 
25
    The :class:`.InstanceState` is a key object used by the
 
26
    SQLAlchemy ORM in order to track the state of an object;
 
27
    it is created the moment an object is instantiated, typically
 
28
    as a result of :term:`instrumentation` which SQLAlchemy applies
 
29
    to the ``__init__()`` method of the class.
 
30
 
 
31
    :class:`.InstanceState` is also a semi-public object,
 
32
    available for runtime inspection as to the state of a
 
33
    mapped instance, including information such as its current
 
34
    status within a particular :class:`.Session` and details
 
35
    about data on individual attributes.  The public API
 
36
    in order to acquire a :class:`.InstanceState` object
 
37
    is to use the :func:`.inspect` system::
 
38
 
 
39
        >>> from sqlalchemy import inspect
 
40
        >>> insp = inspect(some_mapped_object)
 
41
 
 
42
    .. seealso::
 
43
 
 
44
        :ref:`core_inspection_toplevel`
 
45
 
 
46
    """
24
47
 
25
48
    session_id = None
26
49
    key = None
50
73
        and history.
51
74
 
52
75
        The returned object is an instance of :class:`.AttributeState`.
 
76
        This object allows inspection of the current data
 
77
        within an attribute as well as attribute history
 
78
        since the last flush.
53
79
 
54
80
        """
55
81
        return util.ImmutableProperties(
61
87
 
62
88
    @property
63
89
    def transient(self):
64
 
        """Return true if the object is transient."""
 
90
        """Return true if the object is :term:`transient`.
 
91
 
 
92
        .. seealso::
 
93
 
 
94
            :ref:`session_object_states`
 
95
 
 
96
        """
65
97
        return self.key is None and \
66
98
            not self._attached
67
99
 
68
100
    @property
69
101
    def pending(self):
70
 
        """Return true if the object is pending."""
 
102
        """Return true if the object is :term:`pending`.
 
103
 
 
104
 
 
105
        .. seealso::
 
106
 
 
107
            :ref:`session_object_states`
 
108
 
 
109
        """
71
110
        return self.key is None and \
72
111
            self._attached
73
112
 
74
113
    @property
75
114
    def persistent(self):
76
 
        """Return true if the object is persistent."""
 
115
        """Return true if the object is :term:`persistent`.
 
116
 
 
117
        .. seealso::
 
118
 
 
119
            :ref:`session_object_states`
 
120
 
 
121
            """
77
122
        return self.key is not None and \
78
123
            self._attached
79
124
 
80
125
    @property
81
126
    def detached(self):
82
 
        """Return true if the object is detached."""
 
127
        """Return true if the object is :term:`detached`.
 
128
 
 
129
        .. seealso::
 
130
 
 
131
            :ref:`session_object_states`
 
132
 
 
133
        """
83
134
        return self.key is not None and \
84
135
            not self._attached
85
136
 
180
231
 
181
232
    @property
182
233
    def dict(self):
 
234
        """Return the instance dict used by the object.
 
235
 
 
236
        Under normal circumstances, this is always synonymous
 
237
        with the ``__dict__`` attribute of the mapped object,
 
238
        unless an alternative instrumentation system has been
 
239
        configured.
 
240
 
 
241
        In the case that the actual object has been garbage
 
242
        collected, this accessor returns a blank dictionary.
 
243
 
 
244
        """
183
245
        o = self.obj()
184
246
        if o is not None:
185
247
            return base.instance_dict(o)