* read/write attributes in declaration order, thanks to

contribution by Bahadir Kandemir
* check the condition that only a single string attribute
  must be present, and process the string attribute first
This commit is contained in:
Eray Özkural
2006-01-22 12:25:36 +00:00
parent ef60a21327
commit f3e38db3b3
+27 -3
View File
@@ -12,6 +12,7 @@
# #
# Authors: Eray Ozkural <eray@uludag.org.tr> # Authors: Eray Ozkural <eray@uludag.org.tr>
# Gurer Ozen <gurer@uludag.org.tr> # Gurer Ozen <gurer@uludag.org.tr>
# Bahadir Kandemir <bahadir@haftalik.net>
# Baris Metin <baris@uludag.org.tr> # Baris Metin <baris@uludag.org.tr>
@@ -278,9 +279,32 @@ class autoxml(oo.autosuper, oo.autoprop):
encoders = [] encoders = []
errorss = [] errorss = []
formatters = [] formatters = []
order = dict.keys() #order = dict.keys()
order.sort() #order.sort()
#TODO: there should be at most one str member, and it should be the first
# read declaration order from source
# code contributed by bahadir kandemir
from inspect import getsourcelines
from itertools import ifilter
import re
fn = re.compile('\s*([tas]_[a-zA-Z]+).*').findall
lines = filter(fn, getsourcelines(cls)[0])
decl_order = map(lambda x:x.split()[0], lines)
# there should be at most one str member, and it should be
# the first to process
order = filter(lambda x: not x.startswith('s_'), decl_order)
# find string member
str_members = filter(lambda x:x.startswith('s_'), decl_order)
if len(str_members)>1:
raise Error('Only one str member can be defined')
elif len(str_members)==1:
order.insert(0, str_members[0])
for var in order: for var in order:
if var.startswith('t_') or var.startswith('a_') or var.startswith('s_'): if var.startswith('t_') or var.startswith('a_') or var.startswith('s_'):
name = var[2:] name = var[2:]