Commits

Amaury Forgeot d'Arc  committed f216ad2

Use "from hashlib import md5" when possible.
Now "from pypy.tool.compat import md5" returns a function, not a module.
This silences a warning when using python 2.6.

  • Participants
  • Parent commits 37316da

Comments (0)

Files changed (5)

File pypy/interpreter/gateway.py

 
         from pypy.translator.geninterplevel import translate_as_module
         import marshal
-        scramble = md5.new(cls.seed)
+        scramble = md5(cls.seed)
         scramble.update(marshal.dumps(self.code))
         key = scramble.hexdigest()
         initfunc = cls.known_code.get(key)
         except ImportError:
             GI_VERSION_RENDERED = 0
         from pypy.translator.geninterplevel import GI_VERSION
-        cls.seed = md5.new(str(GI_VERSION)).digest()
+        cls.seed = md5(str(GI_VERSION)).digest()
         if GI_VERSION != GI_VERSION_RENDERED or GI_VERSION is None:
             for pth in p.listdir():
                 if pth.check(file=1):

File pypy/tool/compat.py

 
 try:
-    import md5
+    # Preferred way since python 2.6
+    from hashlib import md5
 except ImportError:
-    # no _md5 module on this platform
-    from pypy.lib import md5
+    try:
+        from md5 import md5
+    except ImportError:
+        # no _md5 module on this platform
+        from pypy.lib.md5 import md5

File pypy/tool/gcc_cache.py

     cache_dir = cache_dir_root.join(cachename).ensure(dir=1)
     filecontents = [c_file.read() for c_file in c_files]
     key = repr((filecontents, eci))
-    hash = md5.md5(key).hexdigest()
+    hash = md5(key).hexdigest()
     return cache_dir.join(hash)
 
 def build_executable_cache(c_files, eci):

File pypy/translator/backendopt/stat.py

                 code = graph.func.func_code.co_code
             except AttributeError:
                 code = "None"
-            hash = md5.new(code).hexdigest()
+            hash = md5(code).hexdigest()
             details.append((hash, graph.name, nblocks, nops))
         details.sort()
         f = open(save_per_graph_details, "w")

File pypy/translator/backendopt/support.py

     from pypy.tool.compat import md5
     graph2digest = {}
     for graph in translator.graphs:
-        m = md5.new()
+        m = md5()
         for op in graph_operations(graph):
             m.update(op.opname + str(op.result))
             for a in op.args: