aboutsummaryrefslogtreecommitdiff
path: root/discord/utils.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-12-16 22:03:16 -0500
committerRapptz <[email protected]>2015-12-16 22:03:16 -0500
commitde1c74a399a5286cd707c6ebc3892e168d628ac0 (patch)
tree5345ed742be917325f0612cdf52e5bc03d9018b6 /discord/utils.py
parentChannel.is_default_channel is now a property named is_default. (diff)
downloaddiscord.py-de1c74a399a5286cd707c6ebc3892e168d628ac0.tar.xz
discord.py-de1c74a399a5286cd707c6ebc3892e168d628ac0.zip
Make more things into properties.
A lot of the expensive getters were transformed into cached properties instead. A lot of things that were properties were transformed into properties as well.
Diffstat (limited to 'discord/utils.py')
-rw-r--r--discord/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py
index 2662b4a1..9e230262 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -31,6 +31,21 @@ from base64 import b64encode
import asyncio
import json
+
+class cached_property:
+ def __init__(self, function):
+ self.function = function
+ self.__doc__ = getattr(function, '__doc__')
+
+ def __get__(self, instance, owner):
+ if instance is None:
+ return self
+
+ value = self.function(instance)
+ setattr(instance, self.function.__name__, value)
+
+ return value
+
def parse_time(timestamp):
if timestamp:
return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', ''))))