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.
This commit is contained in:
Rapptz
2015-12-16 22:03:16 -05:00
parent f484a5c023
commit de1c74a399
5 changed files with 34 additions and 19 deletions

View File

@ -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', ''))))