Skip to content

Commit 53e806d

Browse files
committed
1 parent 1f8221e commit 53e806d

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

pyrepl/completing_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def build_menu(cons, wordlist, start, use_brackets, sort_in_column):
6565
item = "%s "
6666
padding = 2
6767
maxlen = min(max(map(real_len, wordlist)), cons.width - padding)
68-
cols = cons.width / (maxlen + padding)
69-
rows = (len(wordlist) - 1)/cols + 1
68+
cols = int(cons.width / (maxlen + padding))
69+
rows = int((len(wordlist) - 1)/cols + 1)
7070

7171
if sort_in_column:
7272
# sort_in_column=False (default) sort_in_column=True

pyrepl/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import unicodedata
3737
from collections import deque
3838
import pprint
39-
from trace import trace
39+
from .trace import trace
4040

4141

4242
class InputTranslator(object):

pyrepl/readline.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
from pyrepl.historical_reader import HistoricalReader
3333
from pyrepl.completing_reader import CompletingReader
3434
from pyrepl.unix_console import UnixConsole, _error
35+
try:
36+
unicode
37+
except NameError:
38+
unicode = str
39+
unichr = chr
40+
basestring = bytes, str
3541

3642

3743
ENCODING = sys.getfilesystemencoding() or 'latin1' # XXX review
@@ -199,7 +205,9 @@ def raw_input(self, prompt=''):
199205
except _error:
200206
return _old_raw_input(prompt)
201207
reader.ps1 = prompt
202-
return reader.readline(startup_hook=self.startup_hook)
208+
# Unicode/str is required for Python 3 (3.5.2).
209+
return unicode(reader.readline(startup_hook=self.startup_hook),
210+
ENCODING)
203211

204212
def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
205213
"""Read an input on possibly multiple lines, asking for more
@@ -229,7 +237,7 @@ def set_completer_delims(self, string):
229237
self.config.completer_delims = dict.fromkeys(string)
230238

231239
def get_completer_delims(self):
232-
chars = self.config.completer_delims.keys()
240+
chars = list(self.config.completer_delims.keys())
233241
chars.sort()
234242
return ''.join(chars)
235243

@@ -423,9 +431,14 @@ def _old_raw_input(prompt=''):
423431

424432
else:
425433
# this is not really what readline.c does. Better than nothing I guess
426-
import __builtin__
427-
_old_raw_input = __builtin__.raw_input
428-
__builtin__.raw_input = _wrapper.raw_input
434+
try:
435+
import __builtin__
436+
_old_raw_input = __builtin__.raw_input
437+
__builtin__.raw_input = _wrapper.raw_input
438+
except ImportError:
439+
import builtins
440+
_old_raw_input = builtins.input
441+
builtins.input = _wrapper.raw_input
429442

430443
_old_raw_input = None
431444
_setup()

pyrepl/simple_interact.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ def run_multiline_interactive_console(mainmodule=None, future_flags=0):
4444
console.compile.compiler.flags |= future_flags
4545

4646
def more_lines(unicodetext):
47-
# ooh, look at the hack:
48-
src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
47+
if sys.version_info < (3, ):
48+
# ooh, look at the hack:
49+
src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
50+
else:
51+
src = unicodetext
4952
try:
5053
code = console.compile(src, '<stdin>', 'single')
5154
except (OverflowError, SyntaxError, ValueError):

pyrepl/unix_eventqueue.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
#
6666
CTRL_ARROW_KEYCODE = {
6767
# for xterm, gnome-terminal, xfce terminal, etc.
68-
'\033[1;5D': 'ctrl left',
69-
'\033[1;5C': 'ctrl right',
68+
b'\033[1;5D': 'ctrl left',
69+
b'\033[1;5C': 'ctrl right',
7070
# for rxvt
71-
'\033Od': 'ctrl left',
72-
'\033Oc': 'ctrl right',
71+
b'\033Od': 'ctrl left',
72+
b'\033Oc': 'ctrl right',
7373
}
7474

7575
def general_keycodes():
@@ -120,6 +120,7 @@ def insert(self, event):
120120

121121
def push(self, char):
122122
ord_char = char if isinstance(char, int) else ord(char)
123+
char = bytes(bytearray((ord_char,)))
123124
self.buf.append(ord_char)
124125
if char in self.k:
125126
if self.k is self.ck:
@@ -133,13 +134,13 @@ def push(self, char):
133134
self.insert(Event('key', k, self.flush_buf()))
134135
self.k = self.ck
135136

136-
elif self.buf and self.buf[0] == 033: # 033 == escape
137+
elif self.buf and self.buf[0] == 27: # escape
137138
# escape sequence not recognized by our keymap: propagate it
138139
# outside so that i can be recognized as an M-... key (see also
139140
# the docstring in keymap.py, in particular the line \\E.
140141
trace('unrecognized escape sequence, propagating...')
141142
self.k = self.ck
142-
self.insert(Event('key', '\033', '\033'))
143+
self.insert(Event('key', '\033', bytearray(b'\033')))
143144
for c in self.flush_buf()[1:]:
144145
self.push(chr(c))
145146

0 commit comments

Comments
 (0)