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('%')
if len(s) > 1:
t = s[0]
keys=rec.keys()
tags=[k for k in keys if k.startswith(t)]
for tag in tags:
fields = rec[tag]
for field in fields:
if field[3] != "":
tmp.append(field[3])
else:
for subfield in field[0]:
tmp.append(subfield[1])
else:
if rec.has_key(tag):
fields = rec[tag]
for field in fields:
if field[1]==ind1 and field[2]==ind2:
if field[3] != "":
tmp.append(field[3])
else:
for subfield in field[0]:
if subfield[0]==code:
tmp.append(subfield[1])
return tmp
def print_rec(rec,format=1):
"""prints a record
format = 1 -- XML
format = 2 -- HTML (not implemented)
"""
if format==1:
text = record_xml_output(rec)
else:
return ''
return text
def print_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 = ""
if type(listofrec).__name__ !='list':
return ""
else:
for rec in listofrec:
text = "%s\n%s" % (text,print_rec(rec,format))
return text
def record_xml_output(rec):
"""generates the XML for record 'rec' and returns it as a string"""