* a makepath function, opposite of splitpath

* fix: path splitting in last tag, but encode is still wrong. u-uh!
This commit is contained in:
Eray Özkural
2005-11-02 02:41:08 +00:00
parent 175e4618a2
commit 5f6698c997
2 changed files with 16 additions and 6 deletions
+9 -1
View File
@@ -82,7 +82,7 @@ def unzip(seq):
def concat(l):
'''concatenate a list of lists'''
return reduce( lambda x,y: x+y, l )
return reduce( operator.concat, l )
def strlist(l):
"""concatenate string reps of l's elements"""
@@ -169,6 +169,14 @@ def splitpath(a):
comps.pop()
return comps
def makepath(comps, relative = False, sep = os.path.sep):
"""reconstruct a path from components"""
path = reduce(lambda x,y: x + sep + y, comps, '')
if relative:
return path[len(sep):]
else:
return path
# I'm not sure how necessary this is. Ahem.
def commonprefix(l):
"""an improved version of os.path.commonprefix,
+7 -5
View File
@@ -591,11 +591,10 @@ class autoxml(oo.autosuper):
def gen_list_tag(cls, tag, spec):
"""generate a list datatype. stores comps in tag/comp_tag"""
name, tag_type, req, path = cls.parse_spec(tag, spec)
#head, last = cls.tagpath_head_last(path)
pathcomps = path.split('/')
list_tagpath = path[:path.rfind('/')]
comp_tag = pathcomps[len(pathcomps)-1]
#TODO: make default path ... tag + '/' + comp_tag when comp is class!
comp_tag = pathcomps.pop()
list_tagpath = util.makepath(pathcomps, sep='/', relative=True)
if len(tag_type) != 1:
raise Error(_('List type must contain only one element'))
@@ -623,7 +622,10 @@ class autoxml(oo.autosuper):
dom = node.ownerDocument
if l and len(l) > 0:
for item in l:
listnode = addNode(dom, node, list_tagpath)
if list_tagpath:
listnode = addNode(dom, node, list_tagpath)
else:
listnode = node
encode_item(xml, listnode, item, errs)
else:
if req is mandatory: