fixed xml() again

This commit is contained in:
mdipierro
2012-08-26 10:41:26 -05:00
parent 294d7583d2
commit 0ac105840e
2 changed files with 16 additions and 6 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-08-26 09:32:05) dev Version 2.00.0 (2012-08-26 10:41:21) dev
+15 -5
View File
@@ -6288,6 +6288,8 @@ class Row(object):
a dictionary that lets you do d['a'] as well as d.a a dictionary that lets you do d['a'] as well as d.a
this is only used to store a Row this is only used to store a Row
""" """
def __init__(self,*args,**kwargs):
self.__dict__.update(*args,**kwargs)
def __getitem__(self, key): def __getitem__(self, key):
key=str(key) key=str(key)
@@ -6320,13 +6322,16 @@ class Row(object):
def values(self): def values(self):
return self.__dict__.values() return self.__dict__.values()
def __iter__(self):
return self.__dict__.__iter__()
def __str__(self): def __str__(self):
### this could be made smarter ### this could be made smarter
return '<Row %s>' % dict.__repr__(self) return '<Row %s>' % self.__dict__
def __repr__(self): def __repr__(self):
return '<Row %s>' % dict.__repr__(self) return '<Row %s>' % self.__dict__
def __int__(self): def __int__(self):
return dict.__getitem__(self,'id') return dict.__getitem__(self,'id')
@@ -6367,7 +6372,6 @@ class Row(object):
del d[k] del d[k]
return d return d
def Row_unpickler(data): def Row_unpickler(data):
return Row(cPickle.loads(data)) return Row(cPickle.loads(data))
@@ -8903,10 +8907,11 @@ class Rows(object):
""" """
serializes the table using sqlhtml.SQLTABLE (if present) serializes the table using sqlhtml.SQLTABLE (if present)
""" """
alphanumeric = re.compile('[a-zA-Z]\w*')
if strict: if strict:
ncols = len(self.colnames) ncols = len(self.colnames)
def f(row,field,indent=' '): def f(row,field,indent=' '):
if isinstance(row,dict): if isinstance(row,Row):
spc = indent+' \n' spc = indent+' \n'
items = [f(row[x],x,indent+' ') for x in row] items = [f(row[x],x,indent+' ') for x in row]
return '%s<%s>\n%s\n%s</%s>' % ( return '%s<%s>\n%s\n%s</%s>' % (
@@ -8916,7 +8921,12 @@ class Rows(object):
indent, indent,
field) field)
elif not callable(row): elif not callable(row):
return '%s<%s>%s</%s>' % (indent,field,row,field) if alphanumeric.match(field):
return '%s<%s>%s</%s>' % \
(indent,field,row,field)
else:
return '%s<extra name="%s">%s</extra>' % \
(indent,field,row)
else: else:
return None return None
return '<%s>\n%s\n</%s>' % ( return '<%s>\n%s\n</%s>' % (