From 75063a4f49b369b65253bdb2755ee32c8923617f Mon Sep 17 00:00:00 2001 From: gfawcett Date: Tue, 24 Mar 2009 02:38:47 +0000 Subject: [PATCH] more robust yaz_search. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@213 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/libsystems/z3950/yaz_search.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/conifer/libsystems/z3950/yaz_search.py b/conifer/libsystems/z3950/yaz_search.py index 0b85621..1daf6ed 100644 --- a/conifer/libsystems/z3950/yaz_search.py +++ b/conifer/libsystems/z3950/yaz_search.py @@ -13,7 +13,7 @@ import sys loc_to_unicode = marctools.locToUTF8().replace -LOG = None # for pexpect debugging, try LOG = sys.stderr +LOG = sys.stderr #None # for pexpect debugging, try LOG = sys.stderr YAZ_CLIENT = 'yaz-client' GENERAL_TIMEOUT = 10 PRESENT_TIMEOUT = 30 @@ -50,12 +50,10 @@ def search(host, database, query, start=1, limit=None): return [] raw_records = [] - for x in range(to_show): - server.expect(r'Record type: XML', timeout=PRESENT_TIMEOUT) - server.expect('') - raw_records.append(server.match.group(0)) - + err = None server.expect('nextResultSetPosition') + pat = re.compile('', re.M) + raw_records = pat.findall(server.before) server.expect('Z>') server.sendline('quit') server.close() @@ -64,7 +62,10 @@ def search(host, database, query, start=1, limit=None): for rec in raw_records: dct = {} parsed.append(dct) - tree = ElementTree.fromstring(rec) + try: + tree = ElementTree.fromstring(rec) + except: + raise rec for df in tree.findall('{http://www.loc.gov/MARC21/slim}datafield'): t = df.attrib['tag'] for sf in df.findall('{http://www.loc.gov/MARC21/slim}subfield'): -- 2.11.0