def get_by_xid(db, host, xid, graceful=False):
"""Returns the passages that correspond to the xid
Optional:
graceful: True if no excpetions are to be raised
excpetion raised if xid does no exist
"""
# precaution for bad input e.g. 101->'101'
xid = str(xid)
cur = get_cursor(db, host)
cur.execute("SELECT xml FROM xmls WHERE id" + "=" +
PLACE_HOLDER, (int(xid),))
raw_xml = cur.fetchone()
if not raw_xml and not graceful:
raise Exception("The xid " + xid + " does not exist")
elif raw_xml:
return fromstring(raw_xml[0])
评论列表
文章目录