retrieves the value of the first field containing tag 'tag' and indicators 'ind1' and 'ind2'
inside record 'rec'. Returns the found value as a string. If no matching field is found
returns the empty string.
if the tag has a '%', it will retrieve the value of first field containg tag, which first characters are those before '%' in tag. The ind1, ind2 and code parameters will be ignored
retrieves the values of all the fields containing tag 'tag' and indicators 'ind1' and 'ind2'
inside record 'rec'. Returns the found values as a list. If no matching field is found
returns an empty list.
if the tag has a '%', it will retrieve the value of all fields containg tag, which first characters are those before '%' in tag. The ind1, ind2 and code parameters will be ignored
"""
tmp=[]
s=tag.split('%')
iflen(s)>1:
t=s[0]
keys=rec.keys()
tags=[kforkinkeysifk.startswith(t)]
fortagintags:
fields=rec[tag]
forfieldinfields:
iffield[3]!="":
tmp.append(field[3])
else:
forsubfieldinfield[0]:
tmp.append(subfield[1])
else:
ifrec.has_key(tag):
fields=rec[tag]
forfieldinfields:
iffield[1]==ind1andfield[2]==ind2:
iffield[3]!="":
tmp.append(field[3])
else:
forsubfieldinfield[0]:
ifsubfield[0]==code:
tmp.append(subfield[1])
returntmp
defprint_rec(rec,format=1):
"""prints a record
format = 1 -- XML
format = 2 -- HTML (not implemented)
"""
ifformat==1:
text=record_xml_output(rec)
else:
return''
returntext
defprint_recs(listofrec,format=1):
"""prints a list of records
format = 1 -- XML
format = 2 -- HTML (not implemented)
if 'listofrec' is not a list it returns empty string
"""
text=""
iftype(listofrec).__name__!='list':
return""
else:
forrecinlistofrec:
text="%s\n%s"%(text,print_rec(rec,format))
returntext
defrecord_xml_output(rec):
"""generates the XML for record 'rec' and returns it as a string"""