Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add XMLparser recover option for client; keep default behavior same: recover=False #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/oaipmh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ class BaseClient(common.OAIPMH):
'expected-errcodes': {503},
}

def __init__(self, metadata_registry=None, custom_retry_policy=None):
def __init__(self, metadata_registry=None, custom_retry_policy=None, recover=False):
self._metadata_registry = (
metadata_registry or metadata.global_metadata_registry)
self._ignore_bad_character_hack = 0
self._day_granularity = False
self.retry_policy = self.default_retry_policy.copy()
if custom_retry_policy is not None:
self.retry_policy.update(custom_retry_policy)
self.XMLParser = etree.XMLParser(recover=recover)

def updateGranularity(self):
"""Update the granularity setting dependent on that the server says.
Expand Down Expand Up @@ -122,7 +123,7 @@ def parse(self, xml):
if hasattr(xml, "encode"):
xml = xml.encode("utf-8")
# xml = xml.encode("utf-8")
return etree.XML(xml)
return etree.XML(xml, parser=self.XMLParser)

# implementation of the various methods, delegated here by
# handleVerb method
Expand Down Expand Up @@ -328,9 +329,10 @@ def makeRequest(self, **kw):
class Client(BaseClient):

def __init__(self, base_url, metadata_registry=None, credentials=None,
local_file=False, force_http_get=False, custom_retry_policy=None):
local_file=False, force_http_get=False, custom_retry_policy=None,
recover=False):
BaseClient.__init__(self, metadata_registry,
custom_retry_policy=custom_retry_policy)
custom_retry_policy=custom_retry_policy, recover=recover)
self._base_url = base_url
self._local_file = local_file
self._force_http_get = force_http_get
Expand Down