--- cdli/cdli_files.py 2007/04/27 14:22:33 1.77 +++ 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""" @@ -1430,7 +1453,7 @@ class CDLIFileObject(CatalogAware,extVer security.declarePublic('makeThisVersionCurrent') - security.declareProtected('manage','index.html') + security.declareProtected('manage','index_html') def PrincipiaSearchSource(self): """Return cataloguable key for ourselves.""" return str(self) @@ -1514,35 +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""" @@ -2249,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 @@ -2258,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 @@ -2275,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"""