Changeset 6:3c70a7d2f35b in documentViewer
- Timestamp:
- Jun 16, 2010, 6:27:04 PM (14 years ago)
- Branch:
- modularisierung
- Files:
-
- 3 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
__init__.py
r0 r6 1 1 import documentViewer 2 2 import MpdlXmlTextServer 3 3 4 4 def initialize(context): … … 11 11 ) 12 12 ) 13 14 context.registerClass( 15 documentViewer.DocumentViewerTemplate, 16 constructors = ( 17 documentViewer.manage_addDocumentViewerTemplateForm, 18 documentViewer.manage_addDocumentViewerTemplate 19 ) 20 ) 21 22 context.registerClass( 23 MpdlXmlTextServer.MpdlXmlTextServer, 24 constructors = ( 25 MpdlXmlTextServer.manage_addMpdlXmlTextServerForm, 26 MpdlXmlTextServer.manage_addMpdlXmlTextServer 27 ) 28 ) 29 -
documentViewer.py
r4 r6 67 67 68 68 69 import socket 70 71 def urlopen(url,timeout=2): 72 """urlopen mit timeout""" 73 socket.setdefaulttimeout(timeout) 74 ret=urllib.urlopen(url) 75 socket.setdefaulttimeout(5) 76 return ret 69 def getHttpData(url, data=None, num_tries=3, timeout=10): 70 """returns result from url+data HTTP request""" 71 # we do GET (by appending data to url) 72 if isinstance(data, str) or isinstance(data, unicode): 73 # if data is string then append 74 url = "%s?%s"%(url,data) 75 elif isinstance(data, dict) or isinstance(data, list) or isinstance(data, tuple): 76 # urlencode 77 url = "%s?%s"%(url,urllib.urlencode(data)) 78 79 response = None 80 errmsg = None 81 for cnt in range(num_tries): 82 try: 83 logging.debug("getHttpData(#%s %ss) url=%s"%(cnt+1,timeout,url)) 84 if sys.version_info < (2, 6): 85 # set timeout on socket -- ugly :-( 86 import socket 87 socket.setdefaulttimeout(timeout) 88 response = urllib2.urlopen(url) 89 else: 90 response = urllib2.urlopen(url,timeout=float(timeout)) 91 # check result? 92 break 93 except urllib2.HTTPError, e: 94 logging.error("getHttpData: HTTP error(%s): %s"%(e.code,e)) 95 errmsg = str(e) 96 # stop trying 97 break 98 except urllib2.URLError, e: 99 logging.error("getHttpData: URLLIB error(%s): %s"%(e.reason,e)) 100 errmsg = str(e) 101 # stop trying 102 #break 103 104 if response is not None: 105 data = response.read() 106 response.close() 107 return data 108 109 raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg)) 110 #return None 111 77 112 78 113 … … 80 115 ## documentViewer class 81 116 ## 82 class documentViewer(Folder , extraFunction):117 class documentViewer(Folder): 83 118 """document viewer""" 84 #textViewerUrl="http://127.0.0.1:8080/HFQP/testXSLT/getPage?"85 86 119 meta_type="Document viewer" 87 120 … … 124 157 self._setObject('template',templateFolder) # old style 125 158 try: 126 from Products.XMLRpcTools.XMLRpcTools import XMLRpcServerProxy127 xmlRpcClient = XMLRpcServerProxy(id='fulltextclient', serverUrl=textServerName, use_xmlrpc=False)159 import MpdlXmlTextServer 160 textServer = MpdlXmlTextServer(id='fulltextclient') 128 161 #templateFolder['fulltextclient'] = xmlRpcClient 129 templateFolder._setObject('fulltextclient', xmlRpcClient)162 templateFolder._setObject('fulltextclient',textServer) 130 163 except Exception, e: 131 logging.error("Unable to create XMLRpcToolsfor fulltextclient: "+str(e))164 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) 132 165 try: 133 166 from Products.zogiLib.zogiLib import zogiLib … … 138 171 logging.error("Unable to create zogiLib for zogilib: "+str(e)) 139 172 140 173 174 # proxy text server methods to fulltextclient 175 def getTextPage(self, **args): 176 """get page""" 177 return self.template.fulltextclient.getTextPage(**args) 178 179 def getQuery(self, **args): 180 """get query""" 181 return self.template.fulltextclient.getQuery(**args) 182 183 def getSearch(self, **args): 184 """get search""" 185 return self.template.fulltextclient.getSearch(**args) 186 187 def getNumPages(self, **args): 188 """get numpages""" 189 return self.template.fulltextclient.getNumPages(**args) 190 191 def getTranslate(self, **args): 192 """get translate""" 193 return self.template.fulltextclient.getTranslate(**args) 194 195 def getLemma(self, **args): 196 """get lemma""" 197 return self.template.fulltextclient.getLemma(**args) 198 199 def getToc(self, **args): 200 """get toc""" 201 return self.template.fulltextclient.getToc(**args) 202 203 def getTocPage(self, **args): 204 """get tocpage""" 205 return self.template.fulltextclient.getTocPage(**args) 206 207 141 208 security.declareProtected('View','thumbs_rss') 142 209 def thumbs_rss(self,mode,url,viewMode="auto",start=None,pn=1): … … 305 372 def getDirinfoFromDigilib(self,path,docinfo=None,cut=0): 306 373 """gibt param von dlInfo aus""" 307 num_retries = 3308 374 if docinfo is None: 309 375 docinfo = {} … … 317 383 logging.debug("documentViewer (getparamfromdigilib) dirInfo from %s"%(infoUrl)) 318 384 319 for cnt in range(num_retries): 320 try: 321 # dom = NonvalidatingReader.parseUri(imageUrl) 322 txt=urllib.urlopen(infoUrl).read() 323 dom = Parse(txt) 324 break 325 except: 326 logging.error("documentViewer (getdirinfofromdigilib) error reading %s (try %d)"%(infoUrl,cnt)) 327 else: 385 txt = getHttpData(infoUrl) 386 if txt is None: 328 387 raise IOError("Unable to get dir-info from %s"%(infoUrl)) 329 388 389 dom = Parse(txt) 330 390 sizes=dom.xpath("//dir/size") 331 391 logging.debug("documentViewer (getparamfromdigilib) dirInfo:size"%sizes) … … 343 403 def getIndexMeta(self, url): 344 404 """returns dom of index.meta document at url""" 345 num_retries = 3346 405 dom = None 347 406 metaUrl = None … … 355 414 if not metaUrl.endswith("index.meta"): 356 415 metaUrl += "/index.meta" 357 logging.debug("METAURL: %s"%metaUrl)358 for cnt in range(num_retries):359 try:360 # patch dirk encoding fehler treten dann nicht mehr auf361 # dom = NonvalidatingReader.parseUri(metaUrl)362 txt=urllib.urlopen(metaUrl).read()363 dom = Parse(txt)364 break365 except:366 logging.error("ERROR documentViewer (getIndexMeta) %s (%s)"%sys.exc_info()[0:2])367 416 368 if dom is None: 417 logging.debug("(getIndexMeta): METAURL: %s"%metaUrl) 418 txt=getHttpData(metaUrl) 419 if txt is None: 369 420 raise IOError("Unable to read index meta from %s"%(url)) 370 421 422 dom = Parse(txt) 371 423 return dom 372 424 373 425 def getPresentationInfoXML(self, url): 374 426 """returns dom of info.xml document at url""" 375 num_retries = 3376 427 dom = None 377 428 metaUrl = None … … 384 435 metaUrl=server+url.replace("/mpiwg/online","") 385 436 386 for cnt in range(num_retries): 387 try: 388 # patch dirk encoding fehler treten dann nicht mehr auf 389 # dom = NonvalidatingReader.parseUri(metaUrl) 390 txt=urllib.urlopen(metaUrl).read() 391 dom = Parse(txt) 392 break 393 except: 394 logging.error("ERROR documentViewer (getPresentationInfoXML) %s (%s)"%sys.exc_info()[0:2]) 395 396 if dom is None: 437 txt=getHttpData(metaUrl) 438 if txt is None: 397 439 raise IOError("Unable to read infoXMLfrom %s"%(url)) 398 440 441 dom = Parse(txt) 399 442 return dom 400 443 -
version.txt
r5 r6 1 DocumentViewer 0. 4.01 DocumentViewer 0.5.1
Note: See TracChangeset
for help on using the changeset viewer.