Utilities/__init__.py

changeset 682
91114a975eda
parent 565
21191e634b47
child 753
e19a516f0a97
--- a/Utilities/__init__.py	Sat Oct 16 19:18:43 2010 +0200
+++ b/Utilities/__init__.py	Sat Oct 16 20:28:00 2010 +0200
@@ -39,8 +39,8 @@
 
 from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32
 
-from PyQt4.QtCore import QRegExp, QDir, QProcess, Qt, \
-    qVersion, PYQT_VERSION_STR, QCoreApplication
+from PyQt4.QtCore import QRegExp, QDir, QProcess, Qt, QByteArray, \
+    qVersion, PYQT_VERSION_STR, QCoreApplication, QCryptographicHash
 from PyQt4.Qsci import QSCINTILLA_VERSION_STR, QsciScintilla
 
 from Globals import isWindowsPlatform   # import this method into the Utilities namespace
@@ -152,6 +152,21 @@
     f.close()
     return decode(text)
 
+def readEncodedFileWithHash(filename):
+    """
+    Function to read a file, calculate a hash value and decode it's contents
+    into proper text.
+    
+    @param filename name of the file to read (string)
+    @return tuple of decoded text, encoding and hash value (string, string, string)
+    """
+    f = open(filename, "rb")
+    text = f.read()
+    f.close()
+    hash = str(QCryptographicHash.hash(QByteArray(text), QCryptographicHash.Md5).toHex(), 
+               encoding = "ASCII")
+    return decode(text) + (hash, )
+
 def decode(text):
     """
     Function to decode some byte text into a string.

eric ide

mercurial