-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwrapme.py
41 lines (31 loc) · 1.06 KB
/
twrapme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
from time import time, ctime
class TimedWrapMe(object):
def __init__(self, obj):
self.__data = obj
self.__ctime = self.__mtime = \
self.__atime = time()
def set(self, obj):
self.__data = obj
self.__mtime = self.__atime = time()
def get(self):
self.__atime = time()
return self.__data
def gettimeval(self, t_type):
if type(t_type) != type('') or \
t_type[0] not in 'cma':
raise TypeError, \
"argument of 'c', 'm', or 'a' req'd"
return eval('self._%s__%stime' % \
(self.__class__.__name__, t_type[0]))
def gettimestr(self, t_type):
return ctime(self.gettimeval(t_type))
def __repr__(self):
self.__atime = time()
return `self.__data`
def __str__(self):
self.__atime = time()
return str(self.__data)
def __getattr__(self, attr): # delegation
self.__atime = time()
return getattr(self.__data, attr)