equal
deleted
inserted
replaced
801 self.func = func |
801 self.func = func |
802 self.name = func.__name__ |
802 self.name = func.__name__ |
803 return self |
803 return self |
804 |
804 |
805 def __get__(self, obj, type=None): |
805 def __get__(self, obj, type=None): |
|
806 # do we need to check if the file changed? |
|
807 if self.name in obj.__dict__: |
|
808 return obj.__dict__[self.name] |
|
809 |
806 entry = obj._filecache.get(self.name) |
810 entry = obj._filecache.get(self.name) |
807 |
811 |
808 if entry: |
812 if entry: |
809 if entry.changed(): |
813 if entry.changed(): |
810 entry.obj = self.func(obj) |
814 entry.obj = self.func(obj) |
816 entry = filecacheentry(path) |
820 entry = filecacheentry(path) |
817 entry.obj = self.func(obj) |
821 entry.obj = self.func(obj) |
818 |
822 |
819 obj._filecache[self.name] = entry |
823 obj._filecache[self.name] = entry |
820 |
824 |
821 setattr(obj, self.name, entry.obj) |
825 obj.__dict__[self.name] = entry.obj |
822 return entry.obj |
826 return entry.obj |
|
827 |
|
828 def __set__(self, obj, value): |
|
829 if self.name in obj._filecache: |
|
830 obj._filecache[self.name].obj = value # update cached copy |
|
831 obj.__dict__[self.name] = value # update copy returned by obj.x |
|
832 |
|
833 def __delete__(self, obj): |
|
834 try: |
|
835 del obj.__dict__[self.name] |
|
836 except KeyError: |
|
837 raise AttributeError, self.name |