From 6b760cb3d3dcbc89df5d2eb9a3c249fda22effa0 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 11 Aug 2008 13:13:18 +0200 Subject: [PATCH] Py2.6/3.0 import fixes --- Cython/Compiler/Code.py | 5 ++++- Cython/Compiler/Scanning.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index a07b640a..1cbde366 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -10,7 +10,10 @@ from PyrexTypes import py_object_type, typecast from TypeSlots import method_coexist from Scanning import SourceDescriptor from Cython.StringIOTree import StringIOTree -from sets import Set as set +try: + set +except NameError: + from sets import Set as set class FunctionContext(object): # Not used for now, perhaps later diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index 32c833a3..9737f977 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -38,7 +38,10 @@ def hash_source_file(path): # Try to calculate a hash code for the given source file. # Returns an empty string if the file cannot be accessed. #print "Hashing", path ### - import md5 + try: + from hashlib import md5 as new_md5 + except ImportError: + from md5 import new as new_md5 try: try: f = open(path, "rU") @@ -54,7 +57,7 @@ def hash_source_file(path): # tabs by a single space. import re text = re.sub("[ \t]+", " ", text) - hash = md5.new(text).hexdigest() + hash = new_md5(text).hexdigest() return hash def open_pickled_lexicon(expected_hash): -- 2.26.2