1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
4 # This file is part of OpenAnno.
6 # OpenAnno is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # ###################################################
22 class livingProperty(object):
26 def __get__(self
, obj
, cls
=None):
27 return self
.values
.get(obj
, None)
29 def __set__(self
, obj
, value
):
30 if obj
in self
.values
and hasattr(self
.values
[obj
], 'end'):
31 self
.values
[obj
].end()
35 self
.values
[obj
] = value
36 if hasattr(value
, 'begin'):
37 print 'Beginning:', value
38 tmp1
, tmp2
= value
._livingObject
_args
, value
._livingObject
_kwargs
39 del value
._livingObject
_args
40 del value
._livingObject
_kwargs
41 value
.begin(*tmp1
, **tmp2
)
43 def __delete__(self
, obj
):
44 self
.__set
__(obj
, None)
46 class livingObject(object):
47 def __init__(self
, *args
, **kwargs
):
48 print 'Initing:', self
49 super(livingObject
, self
).__init
__()
50 self
._livingObject
_args
= args
51 self
._livingObject
_kwargs
= kwargs
57 for p
in self
.__dict
__.keys()[:]:
62 if not (hasattr(self
, '_is_ended') and self
._is
_ended
):
63 print "Warning: Object %s is not ended but no reference is left." % (repr(self
),)