diff --git a/sru/almasru.py b/sru/almasru.py index eeda6572329732887dc8f368e6169603c6f5c021..1226453cf2c9fb622493312b2adbd3687bbccad5 100644 --- a/sru/almasru.py +++ b/sru/almasru.py @@ -38,6 +38,10 @@ class NotUnique(SruException): pass +class TooManyRecords(SruException): + pass + + class SruDiagnostics(SruException): pass @@ -111,6 +115,7 @@ class RecordRetriever: num_recs = sru_xml.find("srw:numberOfRecords", self.namespaces) self._raise_error_no_match(num_recs) self._raise_error_sru(sru_xml) + self._raise_error_too_many_recs(num_recs) num_pages = int(num_recs.text)//10 @@ -121,6 +126,8 @@ class RecordRetriever: startrecord = (i+1)*10+1 sru_url = self._create_url(alma_query, startrecord) sru_xml = self._response_to_xml(sru_url) + + self._raise_error_sru() xml_list.extend(self._extract_marc_xml(sru_xml)) return xml_list @@ -147,16 +154,23 @@ class RecordRetriever: def _raise_error_unique(num_recs: Element): if (num_recs is not None and - num_recs.text > '1'): + int(num_recs.text) > 1): raise NotUnique('More than one record found' - 'while exactly one was expected!') + 'while exactly one was expected.') @staticmethod def _raise_error_no_match(num_recs: Element): if (num_recs is not None and num_recs.text == '0'): - raise NoRecord('No matching records found!') + raise NoRecord('No matching records found.') + + @staticmethod + def _raise_error_too_many_recs(num_recs: Element): + + if int(num_recs.text) > 10000: + raise TooManyRecords('SRU searches are limited to 10.000 ' + 'records.') def _raise_error_sru(self, sru_xml: Element):