property compatibility python 2.5

This commit is contained in:
David Halter
2012-05-17 10:49:52 +02:00
parent 2aa4a1cf8c
commit 21a5825e6e
2 changed files with 25 additions and 1 deletions

View File

@@ -24,3 +24,27 @@ try:
from ast import literal_eval from ast import literal_eval
except ImportError: except ImportError:
literal_eval = eval literal_eval = eval
# properties in 2.5
try:
property.setter
except AttributeError:
import sys
class property(property):
def __init__(self, fget, *args, **kwargs):
self.__doc__ = fget.__doc__
super(property, self).__init__(fget, *args, **kwargs)
def setter(self, fset):
cls_ns = sys._getframe(1).f_locals
for k, v in cls_ns.iteritems():
if v == self:
propname = k
break
cls_ns[propname] = property(self.fget, fset,
self.fdel, self.__doc__)
return cls_ns[propname]
else:
property = property

View File

@@ -13,7 +13,7 @@ TODO class decorators
TODO annotations ? how ? type evaluation and return? TODO annotations ? how ? type evaluation and return?
TODO nonlocal statement TODO nonlocal statement
""" """
from _compatibility import next from _compatibility import next, property
import itertools import itertools
import copy import copy