--- cdli/cdli_files.py 2007/03/23 17:15:36 1.75 +++ cdli/cdli_files.py 2007/08/31 14:22:52 1.79 @@ -26,6 +26,30 @@ import logging import transaction import copy import codecs +import sys + +def unicodify(s): + """decode str (utf-8 or latin-1 representation) into unicode object""" + if not s: + return u"" + if isinstance(s, str): + try: + return s.decode('utf-8') + except: + return s.decode('latin-1') + else: + return s + +def utf8ify(s): + """encode unicode object or string into byte string in utf-8 representation. + assumes string objects to be utf-8""" + if not s: + return "" + if isinstance(s, str): + return s + else: + return s.encode('utf-8') + def generateXMLReturn(hash): """erzeugt das xml file als returnwert fuer uploadATFRPC""" @@ -132,7 +156,7 @@ def unique(s): class BasketContent(SimpleItem): """classe fuer den Inhalt eines Baskets""" - + def __init__(self,content=[]): """content""" self.contentList=content[0:] @@ -530,6 +554,7 @@ class CDLIBasketContainer(OrderedFolder) return ret + security.declareProtected('manage','getBasketAsOneFile') def getBasketAsOneFile(self,basketName,current="no"): """returns all files of the basket combined in one file @param basketName: Name of the basket @@ -553,6 +578,7 @@ class CDLIBasketContainer(OrderedFolder) ret+=str(founds[0].getObject().getLastVersion().getData())+"\n" return ret + security.declareProtected('manage','upDateBaskets') def upDateBaskets(self): """update content in to objects""" @@ -623,7 +649,7 @@ class CDLIBasketContainer(OrderedFolder) return pt(basketId=basketId,basketName=basketName) - security.declareProtected('View','index_html') + security.declareProtected('manage','index_html') def index_html(self): """stanadard ansicht""" @@ -827,7 +853,7 @@ class CDLIBasketContainer(OrderedFolder) """get name of the actualuser""" return str(self.REQUEST['AUTHENTICATED_USER']) - + security.declareProtected('manage','addBasket') def addBasket(self,newBasketName): """add a new basket""" @@ -886,11 +912,12 @@ class CDLIBasket(Folder,CatalogAware): def searchInBasket(self,indexName,searchStr,regExp=False): """searchInBasket""" - lst=self.searchInLineIndexDocs(indexName,searchStr,uniq=True,regExp=False) + lst=self.searchInLineIndexDocs(indexName,searchStr,uniq=True,regExp=regExp) ret={} lv=self.getLastVersion() - logging.info("searching") + + for obj in lv.content.getContent(): id=obj[1].getId().split(".")[0] if id in lst: @@ -1239,7 +1266,7 @@ class CDLIBasketVersion(Implicit,Persist self.REQUEST.RESPONSE.setHeader("Content-Length",length) self.REQUEST.RESPONSE.write(ret) - security.declareProtected('View','downloadObjectsAsOneFile') + security.declareProtected('manage','downloadObjectsAsOneFile') def downloadObjectsAsOneFile(self,lock=None,procedure=None,REQUEST=None,check="yes",current="no"): """download all selected files in one file""" @@ -1371,7 +1398,7 @@ class CDLIBasketVersion(Implicit,Persist """get Comment""" return self.comment - security.declareProtected('View','index_html') + security.declareProtected('manage','index_html') def index_html(self): """view the basket""" @@ -1426,6 +1453,7 @@ class CDLIFileObject(CatalogAware,extVer security.declarePublic('makeThisVersionCurrent') + security.declareProtected('manage','index_html') def PrincipiaSearchSource(self): """Return cataloguable key for ourselves.""" return str(self) @@ -1534,9 +1562,10 @@ def manage_addCDLIFileObject(self,id,vC= class CDLIFile(extVersionedFile,CatalogAware): """CDLI file""" + security=ClassSecurityInfo() meta_type="CDLI file" default_catalog='CDLICatalog' - + security.declareProtected('manage','index_html') #security.declarePublic('history') def getLastVersionData(self): """get last version data""" @@ -1988,7 +2017,7 @@ class CDLIFileFolder(extVersionedFileFol return ret - security.declareProtected('View','index_html') + security.declareProtected('manage','index_html') def index_html(self): """main""" ext=self.ZopeFind(self,obj_ids=["index.html"]) @@ -2083,10 +2112,14 @@ class CDLIRoot(Folder): words=self.findWordRegExp(indexName,searchTerm) # suche nach allen Treffern logging.info("wd:%s"%words) for word in words: + ret+=self.searchInLineIndexDocs(indexName,word) - - return unique(ret) - + + + x= unique(ret) + logging.info("words_done") + return x + def showInLineIndex(self): """get the index for debug purposes""" print "show" @@ -2209,7 +2242,7 @@ class CDLIRoot(Folder): """get lines with word fromFileId""" file=self.showFile(fileId) - + logging.info("regEXP %s"%regExp) ret=[] if regExp: # wenn regexp dann generiere alle worte aus der list die der regexp entsprechen wordlist=self.findWordRegExp(indexName,word) @@ -2219,7 +2252,8 @@ class CDLIRoot(Folder): for line in file.split("\n"): found=False for word in wordlist: - if line.find(word)>-1: + try: # just a hack because of possible unicode errors in line + if line.find(word)>-1: if lineList: #liste of moeglichen Zeilennummern num=line.split(".")[0] #Zeilenummer ist alles vor dem . in der Zeile @@ -2230,13 +2264,15 @@ class CDLIRoot(Folder): ret.append(line) break; + except: + pass return ret def tagWordInFile(self,fileId,word,lineList=None,regExp=True,indexName=""): """get lines with word fromFileId""" file=self.showFile(fileId) - tagStr="""%s""" + tagStr=u'%s' ret=[] if regExp: # wenn regexp dann generiere alle worte aus der list die der regexp entsprechen @@ -2245,6 +2281,7 @@ class CDLIRoot(Folder): wordlist=[word] for line in file.split("\n"): + line = unicodify(line) found=False for word in wordlist: if line.find(word)>-1: #word ist gefunden dann makiere und breche die Schleife ab @@ -2262,7 +2299,7 @@ class CDLIRoot(Folder): if not found: #word wurde nicht gefunden keine makierung ret.append(line) - return "
\n".join(ret) + return u'
\n'.join(ret) def URLquote(self,str): """quote url"""