[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/utils/qsr
From:       Aurélien Gâteau <aurelien.gateau () free ! fr>
Date:       2007-04-01 21:08:45
Message-ID: 1175461725.003107.10978.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 649007 by gateau:

Convert file content to unicode when loading and saving.
For now, utf8 charset is hardcoded.


 M  +5 -2      Worker.py  


--- trunk/playground/utils/qsr/Worker.py #649006:649007
@@ -154,13 +154,14 @@
 
     def _search(self, filename):
         try:
-            fl=file(filename)
+            content = file(filename).read()
+            content = unicode(content, "utf8")
         except Exception, exc:
             print "Error reading file %s" % filename
             print exc
             return
         lineNum=1
-        for line in fl.xreadlines():
+        for line in content.split("\n"):
             if self._src.search(line)!=None:
                 self._matches.append( (filename, lineNum, line.strip()) )
             lineNum+=1
@@ -169,6 +170,7 @@
     def _replace(self, filename):
         try:
             content=file(filename).read()
+            content = unicode(content, "utf8")
         except Exception, exc:
             print "Error reading file %s" % filename
             print exc
@@ -180,6 +182,7 @@
         newFilename=filename+".qsrnew"
         bakFilename=filename+".bak"
         try:
+            content = content.encode("utf8")
             file(newFilename, 'w').write(content)
             shutil.copymode(filename, newFilename)
         except Exception, exc:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic