# HG changeset patch # User casties # Date 1369311407 -7200 # Node ID 55294833888f8fc118bc72d8d4fe299e9f052da3 # Parent 69a2f0b8a93228879f732f2be3778b6fcd6dd6f9 fix error without network connection. diff -r 69a2f0b8a932 -r 55294833888f zopePubmanConnector.py --- a/zopePubmanConnector.py Sun May 05 17:10:22 2013 +0200 +++ b/zopePubmanConnector.py Thu May 23 14:16:47 2013 +0200 @@ -106,7 +106,6 @@ def search(self,values={},exact=False,limit=None,contexts=None): - """search pubman @values map mit field->value @return map mit escidocId -> XML-formatted snippeds @@ -122,9 +121,6 @@ if limit: cn+="&maximumRecords=%s"%limit - - - querys = [] for field in values.keys(): @@ -134,7 +130,6 @@ logging.debug("search, don't know field: %s"%field) continue - value = values[field] try: value=unicodedata.normalize('NFKD', value).encode('ASCII', 'ignore') @@ -145,14 +140,11 @@ logging.debug("%s=%s"%(field,value)) if not exact: value=value+"*" - querys.append("%s=%%22%s%%22"%(searchField,value)) - query="%20AND%20".join(querys) - if contexts: # einscbraenken auf contexte if isinstance(contexts, str): @@ -169,10 +161,13 @@ else: query="(%s)"%ctxquery - h = httplib2.Http(cacheFolder) - - logging.debug(cn%query) - resp, content = h.request(cn%query) + try: + h = httplib2.Http(cacheFolder) + logging.debug("search: "+cn%query) + resp, content = h.request(cn%query) + except: + logging.error("Unable to get data from PubMan!") + return {} ET.register_namespace("dcterms", "http://purl.org/dc/terms/") @@ -191,12 +186,8 @@ ret={} for citation in citations: objId = citation.get('objid') - text = citation.find(citationxpath) - ret[objId]=text.text - - return ret @@ -291,14 +282,19 @@ cn+="&maximumRecords=%s"%limit startTime = time.time() - logging.debug("getPublicationsFromContext: getting %s"%cn) - resp, content = h.request(cn) - logging.debug("getPublicationsFromContext: got data in %ss"%(time.time()-startTime)) + try: + logging.debug("getPublicationsFromContext: getting %s"%cn) + resp, content = h.request(cn) + logging.debug("getPublicationsFromContext: got data in %ss"%(time.time()-startTime)) - ET.register_namespace("dcterms", "http://purl.org/dc/terms/") + ET.register_namespace("dcterms", "http://purl.org/dc/terms/") - root = ET.fromstring(content) - + root = ET.fromstring(content) + + except Exception, e: + logging.error("Unable to read and parse data! %s"%e) + return [] + #