changeset 12:55294833888f

fix error without network connection.
author casties
date Thu, 23 May 2013 14:16:47 +0200
parents 69a2f0b8a932
children 43849c9cc08b
files zopePubmanConnector.py
diffstat 1 files changed, 18 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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 []
+
         #<escidocItem:item objid="escidoc:630782" 
         
         citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"