46 |
|
|
47 |
# if a dictionary with instance data is given, populate the cache |
# if a dictionary with instance data is given, populate the cache |
48 |
if objData: |
if objData: |
49 |
self.objectId = objData['gnue_id'] |
self.objectId = objData ['gnue_id'] |
50 |
|
|
51 |
# transfer all data from objData to the initial cache |
# transfer all data from objData to the initial cache |
52 |
for key in objData.keys (): |
for key in objData.keys (): |
53 |
self._cache[key] = objData[key] |
self._cache [key] = objData [key] |
54 |
|
|
55 |
# ------------------------------------------------------------------------- |
# ------------------------------------------------------------------------- |
56 |
# Return an attribute's value; if not available in cache load from server |
# Return an attribute's value; if not available in cache load from server |
57 |
# ------------------------------------------------------------------------- |
# ------------------------------------------------------------------------- |
58 |
def __getattr__ (self, attr): |
def __getattr__ (self, attr): |
59 |
if not self._cache.has_key (attr): |
if not self._cache.has_key (attr): |
60 |
try: |
if self._attrIsValid (attr): |
61 |
if self._attrIsValid (attr): |
res = self._server.load (self._session_id, self._class, |
62 |
res = self._server.load (self._session_id, self._class, |
[self.objectId], [attr]) [0] |
63 |
[self.objectId], [attr]) [0] |
self._cache [attr] = res [0] |
64 |
self._cache[attr] = res[attr] |
else: |
65 |
else: |
raise AttributeError, attr |
|
raise AttributeError, attr |
|
66 |
|
|
67 |
except: |
return self._cache [attr] |
|
raise AttributeError, attr |
|
|
|
|
|
return self._cache[attr] |
|
68 |
|
|
69 |
|
|
70 |
# ------------------------------------------------------------------------- |
# ------------------------------------------------------------------------- |
72 |
# ------------------------------------------------------------------------- |
# ------------------------------------------------------------------------- |
73 |
def __setattr__ (self, attr, value): |
def __setattr__ (self, attr, value): |
74 |
if self.__dict__.has_key (attr): |
if self.__dict__.has_key (attr): |
75 |
self.__dict__[attr] = value |
self.__dict__ [attr] = value |
76 |
else: |
else: |
77 |
if not self._attrIsValid (attr): |
if not self._attrIsValid (attr): |
78 |
raise AttributeError, attr |
raise AttributeError, attr |
79 |
|
|
80 |
self._cache[attr] = value |
self._cache [attr] = value |
81 |
|
|
82 |
# ------------------------------------------------------------------------- |
# ------------------------------------------------------------------------- |
83 |
# Check if 'attr' is a valid attribute of this class |
# Check if 'attr' is a valid attribute of this class |
105 |
|
|
106 |
res = self._server.store (self._session_id, self._class, [self.objectId], |
res = self._server.store (self._session_id, self._class, [self.objectId], |
107 |
prop, [data]) |
prop, [data]) |
108 |
self.objectId = res[0] |
self.objectId = res [0] |
109 |
|
|
110 |
# ------------------------------------------------------------------------- |
# ------------------------------------------------------------------------- |
111 |
# Delete instance and clear object-id |
# Delete instance and clear object-id |