Use self.nname in descriptor to store preformated

master
pictuga 2013-11-16 19:05:57 +01:00
parent 03884be1bd
commit 610334dca9
1 changed files with 6 additions and 5 deletions

View File

@ -121,22 +121,23 @@ class FeedDescriptor(object):
""" """
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
self.nname = name[0].upper() + name[1:]
def __get__(self, instance, owner): def __get__(self, instance, owner):
getter = getattr(instance, 'get%s' % self.name.title()) getter = getattr(instance, 'get%s' % self.nname)
return getter() return getter()
def __set__(self, instance, value): def __set__(self, instance, value):
setter = getattr(instance, 'set%s' % self.name.title()) setter = getattr(instance, 'set%s' % self.nname)
return setter(value) return setter(value)
def __delete__(self, instance): def __delete__(self, instance):
deleter = getattr(instance, 'del%s' % self.name.title()) deleter = getattr(instance, 'del%s' % self.nname)
return deleter() return deleter()
class FeedTime(FeedDescriptor): class FeedTime(FeedDescriptor):
def __get__(self, instance, owner): def __get__(self, instance, owner):
getter = getattr(instance, 'get%s' % self.name.title()) getter = getattr(instance, 'get%s' % self.nname)
raw = getter() raw = getter()
try: try:
time = parseTime(raw) time = parseTime(raw)
@ -148,7 +149,7 @@ class FeedTime(FeedDescriptor):
try: try:
time = parseTime(value) time = parseTime(value)
raw = time.strftime(instance.timeFormat) raw = time.strftime(instance.timeFormat)
setter = getattr(instance, 'set%s' % self.name.title()) setter = getattr(instance, 'set%s' % self.nname)
return setter(raw) return setter(raw)
except ValueError: except ValueError:
pass pass