From e19393799efb9d5dbee0c023f0a17291f7cb4c06 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 5 Jul 2009 16:12:48 +0200 Subject: [PATCH] Py3 fixes --- Cython/Compiler/Scanning.py | 2 +- Cython/Compiler/TreeFragment.py | 7 +++++-- Cython/Plex/Transitions.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index 5644f186..9a8e674e 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -65,7 +65,7 @@ def hash_source_file(path): # tabs by a single space. import re text = re.sub("[ \t]+", " ", text) - hash = new_md5(text).hexdigest() + hash = new_md5(text.encode("ASCII")).hexdigest() return hash def open_pickled_lexicon(expected_hash): diff --git a/Cython/Compiler/TreeFragment.py b/Cython/Compiler/TreeFragment.py index 47e98b7f..28f9f8d4 100644 --- a/Cython/Compiler/TreeFragment.py +++ b/Cython/Compiler/TreeFragment.py @@ -3,7 +3,10 @@ # import re -from cStringIO import StringIO +try: + from cStringIO import BytesIO # Py3 mangled by 2to3 ... +except ImportError: + from cStringIO import StringIO as BytesIO # Py3 mangled by 2to3 ... from Scanning import PyrexScanner, StringSourceDescriptor from Symtab import BuiltinScope, ModuleScope import Symtab @@ -54,7 +57,7 @@ def parse_from_strings(name, code, pxds={}, level=None, initial_pos=None): context = StringParseContext([], name) scope = context.find_module(module_name, pos = initial_pos, need_pxd = 0) - buf = StringIO(code.encode(encoding)) + buf = BytesIO(code.encode(encoding)) scanner = PyrexScanner(buf, code_source, source_encoding = encoding, scope = scope, context = context, initial_pos = initial_pos) diff --git a/Cython/Plex/Transitions.py b/Cython/Plex/Transitions.py index 6caff5ed..add3b448 100644 --- a/Cython/Plex/Transitions.py +++ b/Cython/Plex/Transitions.py @@ -131,7 +131,7 @@ class TransitionMap(object): # loop invariant: map[lo] <= code < map[hi] and hi - lo >= 2 while hi - lo >= 4: # Find midpoint truncated to even index - mid = ((lo + hi) / 2) & ~1 + mid = ((lo + hi) // 2) & ~1 if code < map[mid]: hi = mid else: -- 2.26.2