From f3e38db3b3c328f59adf63121d1d093d5afa2f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Sun, 22 Jan 2006 12:25:36 +0000 Subject: [PATCH] * 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 --- pisi/pxml/autoxml.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index 56b656ac..e90e8323 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -12,6 +12,7 @@ # # Authors: Eray Ozkural # Gurer Ozen +# Bahadir Kandemir # Baris Metin @@ -278,9 +279,32 @@ class autoxml(oo.autosuper, oo.autoprop): encoders = [] errorss = [] formatters = [] - order = dict.keys() - order.sort() - #TODO: there should be at most one str member, and it should be the first + #order = dict.keys() + #order.sort() + + # 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: if var.startswith('t_') or var.startswith('a_') or var.startswith('s_'): name = var[2:]