--- cdli/cdli_files.py 2007/04/23 13:07:10 1.76 +++ cdli/cdli_files.py 2007/09/03 11:10:04 1.80 @@ -28,6 +28,29 @@ 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""" @@ -133,7 +156,7 @@ def unique(s): class BasketContent(SimpleItem): """classe fuer den Inhalt eines Baskets""" - + def __init__(self,content=[]): """content""" self.contentList=content[0:] @@ -531,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 @@ -554,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""" @@ -624,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""" @@ -828,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""" @@ -1241,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""" @@ -1373,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""" @@ -1428,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) @@ -1511,34 +1537,37 @@ def manage_addCDLIFileObject(self,id,vC= # First, we create the file without data: self._setObject(id, CDLIFileObject(id,title,'',content_type, precondition)) - self._getOb(id).versionComment=str(vC) - self._getOb(id).time=time.localtime() - - setattr(self._getOb(id),'author',author) - + fob = self._getOb(id) + fob.versionComment=str(vC) + fob.time=time.localtime() + setattr(fob,'author',author) # Now we "upload" the data. By doing this in two steps, we # can use a database trick to make the upload more efficient. if file and not from_tmp: - self._getOb(id).manage_upload(file) + fob.manage_upload(file) elif file and from_tmp: - self._getOb(id).manage_upload_from_tmp(file) + fob.manage_upload_from_tmp(file) if content_type: - self._getOb(id).content_type=content_type + fob.content_type=content_type + logging.debug("reindex1: %s"%repr(self)) self.reindex_object() - self._getOb(id).reindex_object() + logging.debug("reindex2: %s in %s"%(repr(fob), repr(fob.default_catalog))) + fob.reindex_object() if REQUEST is not None: REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main') + 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""" @@ -1990,7 +2019,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"]) @@ -2245,7 +2274,7 @@ class CDLIRoot(Folder): """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 @@ -2254,6 +2283,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 @@ -2271,7 +2301,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"""