PluginToolGenerateHash.py

changeset 11
75b2e663fe71
parent 10
4e1e5853c0c7
child 12
62102ad23820
--- a/PluginToolGenerateHash.py	Wed Jan 01 14:47:57 2014 +0100
+++ b/PluginToolGenerateHash.py	Wed Jan 01 16:56:24 2014 +0100
@@ -7,6 +7,8 @@
 Module implementing the 'Generate Hash' tool plug-in.
 """
 
+from __future__ import unicode_literals
+
 import os
 import hashlib
 
@@ -275,6 +277,13 @@
                 )
             else:
                 editor = e5App().getObject("ViewManager").activeWindow()
+                if (editor.getLanguage() in ['Python', 'Python2'] and
+                        "from __future__ import unicode_literals"
+                        not in editor.text()):
+                    prefix = 'u'
+                else:
+                    prefix = ''
+                
                 line, index = editor.getCursorPosition()
                 indLevel = (editor.indentation(line) //
                             editor.indentationWidth())
@@ -284,8 +293,9 @@
                     indString = editor.indentationWidth() * ' '
                 indent = (indLevel + 1) * indString
                 code = ["["]
-                for hash in hashes:
-                    code.append("{0}{1},".format(indent, str(hash)))
+                for name, hash in hashes:
+                    code.append("{0}({1}'{2}', '{3}'),".format(
+                        indent, prefix, name, hash))
                 code.append("{0}]".format(indLevel * indString))
                 
                 self.__insertHash(os.linesep.join(code))

eric ide

mercurial