Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Smith <mrdoctorwho@gmail.com>2016-12-25 14:27:34 +0300
committerJohn Smith <mrdoctorwho@gmail.com>2016-12-25 14:27:34 +0300
commita5354a9f365dd3e18f10314d25dd36609671d640 (patch)
tree73ffaa31150b01a659c949f78662be8b456f387d /library
parent291eadf050602bc27ff9addbdf89bcc6d90e4304 (diff)
Make roster check xmpp-based
Diffstat (limited to 'library')
-rw-r--r--library/utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/library/utils.py b/library/utils.py
index ef00d39..42d0711 100644
--- a/library/utils.py
+++ b/library/utils.py
@@ -200,4 +200,40 @@ def TimeMachine(text):
time += int(current[:-1]) * TIME_VALUES[x]
return time
+
+class ExpiringObject(object):
+ def __init__(self, obj, lifetime):
+ self.obj = obj
+ self.created = time.time()
+ self.lifetime = lifetime
+
+ def hasExpired(self):
+ return (time.time() >= (self.created + self.lifetime))
+
+ def __getattr__(self, attr):
+ try:
+ result = object.__getattribute__(self, attr)
+ except AttributeError:
+ result = getattr(self.obj, attr)
+ return result
+
+ def __iter__(self):
+ if hasattr(self.obj, "__iter__"):
+ return self.obj.__iter__()
+ raise TypeError("Not iterable")
+
+ def next(self):
+ if hasattr(self.obj, "next"):
+ return self.obj.next()
+ raise TypeError("Not iterable")
+
+ # TODO what if our object isn't iterable?
+ def __str__(self):
+ result = ""
+ for num, i in enumerate(self.obj):
+ result += str(i)
+ if num < (len(self.obj) -1):
+ result += ", "
+ return result
+
# Yay!