--- cdli/cdli_files.py 2007/04/27 14:42:28 1.78
+++ cdli/cdli_files.py 2007/08/31 14:22:52 1.79
@@ -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"""
@@ -2249,7 +2272,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 +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
@@ -2275,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"""