from site import Site from retrieval import Retrieval, Factory from tools import convert import string, re class Serials(Site): def __init__(self, name, database, location): self.edbmdb = None Site.__init__(self, name, database, location) return def edbminit(self, path, force=0): if self.edbmdb == None or force: self.edbmdb = Retrieval(path) return def edbmopen(self, name, format=''): return self.edbmdb.open(name, format, self.Factory) def edbmquery(self, form, db): query = [] for idx in db.schema['indexinfo'].keys(): if form.has_key(idx) and form[idx]: what = convert.utf82ascii(form[idx]) what = re.sub(r'[Ii][Ss][Ss][Nn]', '', what) what = string.strip(re.sub(r'\s+', ' ', what)) what = string.replace(what, "'", '"') what = re.sub(r'[^a-zA-Z0-9*" -]', '', what) what = re.sub(r'" *(.*?) *"', r'<\1>', what) what = re.sub(r'" *(.*)$', r'<\1>', what) quots = string.split(what, '<') list = [quots[0]] for quot in quots[1:]: (q,s) = string.split(quot, '>') list.append(string.replace(q, ' ', '-')) list.append(s) what = string.strip(string.join(list, '')) what = string.replace(what, ' ', ' & ') what = string.replace(what, '-', ' ') query.append('%s=(%s)' % (idx, what)) query = string.join(query, ' & ') return query def edbmfind(self, db, query, first, last): try: return db.find(query, first, last) except Exception: return None class Factory(Factory): def make_ti_iso(self, item, name, value): return convert.tex2utf8(item[name[:-4]]) make_st_iso = make_pu_iso = make_rm_iso = make_ti_iso def make_sc_iso(self, item, name, value): if item[name[:-4]].startswith('<'): list = [] for it in item[name[:-4]].split(';'): it = convert.tex2utf8(it.strip()) it = it.replace('<', '') it += '' list.append(it) return string.join(list, '; ') else: return item[name[:-4]] make_pr_iso = make_sb_iso = make_tr_iso = make_or_iso = make_sc_iso