Skip to content

Commit

Permalink
Restore cached_property
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jun 26, 2015
1 parent be367ae commit 86a2a01
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions pygal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def decorate(svg, node, metadata):


def alter(node, metadata):
if node and metadata and 'node' in metadata:
if node is not None and metadata and 'node' in metadata:
node.attrib.update(
dict((k, str(v)) for k, v in metadata['node'].items()))

Expand All @@ -269,21 +269,25 @@ def truncate(string, index):
string = string[:index - 1] + u('…')
return string

cached_property = property

# # Stolen from brownie http://packages.python.org/Brownie/
# class cached_property(object):
# """Optimize a static property"""
# def __init__(self, getter, doc=None):
# self.getter = getter
# self.__module__ = getter.__module__
# self.__name__ = getter.__name__
# self.__doc__ = doc or getter.__doc__

# def __get__(self, obj, type_=None):
# if obj is None:
# return self
# value = obj.__dict__[self.__name__] = self.getter(obj)
# return value
class cached_property(object):
"""Optimize a static property"""
def __init__(self, getter, doc=None):
self.getter = getter
self.__module__ = getter.__module__
self.__name__ = getter.__name__
self.__doc__ = doc or getter.__doc__

def __get__(self, obj, type_=None):
if obj is None:
return self
value = self.getter(obj)
if hasattr(obj, 'state'):
setattr(obj.state, self.__name__, value)
else:
obj.__dict__[self.__name__] = self.getter(obj)
return value

css_comments = re.compile(r'/\*.*?\*/', re.MULTILINE | re.DOTALL)

Expand Down

0 comments on commit 86a2a01

Please sign in to comment.