summaryrefslogtreecommitdiff
path: root/devel/py-pyrepl/files/patch-2to3
blob: afdeccca2b3b7f2871f2c5c19f7fa81960db5c65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
--- pyrepl/cmdrepl.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/cmdrepl.py
@@ -33,7 +33,7 @@ It was designed to let you do this:
 which is in fact done by the `pythoni' script that comes with
 pyrepl."""
 
-from __future__ import print_function
+
 
 from pyrepl import completer
 from pyrepl.completing_reader import CompletingReader as CR
--- pyrepl/completer.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/completer.py
@@ -18,7 +18,7 @@
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 try:
-    import __builtin__ as builtins
+    import builtins as builtins
     builtins  # silence broken pyflakes
 except ImportError:
     import builtins
@@ -44,8 +44,8 @@ class Completer(object):
         import keyword
         matches = []
         for list in [keyword.kwlist,
-                     builtins.__dict__.keys(),
-                     self.ns.keys()]:
+                     list(builtins.__dict__.keys()),
+                     list(self.ns.keys())]:
             for word in list:
                 if word.startswith(text) and word != "__builtins__":
                     matches.append(word)
--- pyrepl/completing_reader.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/completing_reader.py
@@ -64,7 +64,7 @@ def build_menu(cons, wordlist, start, use_brackets, so
     else:
         item = "%s  "
         padding = 2
-    maxlen = min(max(map(real_len, wordlist)), cons.width - padding)
+    maxlen = min(max(list(map(real_len, wordlist))), cons.width - padding)
     cols = cons.width / (maxlen + padding)
     rows = (len(wordlist) - 1)/cols + 1
 
--- pyrepl/historical_reader.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/historical_reader.py
@@ -23,7 +23,7 @@ from pyrepl.reader import Reader as R
 isearch_keymap = tuple(
     [('\\%03o'%c, 'isearch-end') for c in range(256) if chr(c) != '\\'] + \
     [(c, 'isearch-add-character')
-     for c in map(chr, range(32, 127)) if c != '\\'] + \
+     for c in map(chr, list(range(32, 127))) if c != '\\'] + \
     [('\\%03o'%c, 'isearch-add-character')
      for c in range(256) if chr(c).isalpha() and chr(c) != '\\'] + \
     [('\\\\', 'self-insert'),
@@ -292,7 +292,7 @@ class HistoricalReader(R):
     def finish(self):
         super(HistoricalReader, self).finish()
         ret = self.get_unicode()
-        for i, t in self.transient_history.items():
+        for i, t in list(self.transient_history.items()):
             if i < len(self.history) and i != self.historyi:
                 self.history[i] = t
         if ret:
--- pyrepl/input.py.orig	2019-04-16 13:00:52 UTC
+++ pyrepl/input.py
@@ -32,11 +32,11 @@
 # executive, temporary decision: [tab] and [C-i] are distinct, but
 # [meta-key] is identified with [esc key].  We demand that any console
 # class does quite a lot towards emulating a unix terminal.
-from __future__ import print_function
+
 import unicodedata
 from collections import deque
 import pprint
-from trace import trace
+from .trace import trace
 
 
 class InputTranslator(object):
--- pyrepl/keymap.py.orig	2019-04-16 13:00:52 UTC
+++ pyrepl/keymap.py
@@ -174,17 +174,17 @@ def parse_keys(key):
 
 def compile_keymap(keymap, empty=b''):
     r = {}
-    for key, value in keymap.items():
+    for key, value in list(keymap.items()):
         if isinstance(key, bytes):
             first = key[:1]
         else:
             first = key[0]
         r.setdefault(first, {})[key[1:]] = value
-    for key, value in r.items():
+    for key, value in list(r.items()):
         if empty in value:
             if len(value) != 1:
                 raise KeySpecError(
-                      "key definitions for %s clash"%(value.values(),))
+                      "key definitions for %s clash"%(list(value.values()),))
             else:
                 r[key] = value[empty]
         else:
--- pyrepl/keymaps.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/keymaps.py
@@ -62,9 +62,9 @@ reader_emacs_keymap = tuple(
      (r'\M-\n', 'self-insert'),
      (r'\<backslash>', 'self-insert')] + \
     [(c, 'self-insert')
-     for c in map(chr, range(32, 127)) if c <> '\\'] + \
+     for c in map(chr, list(range(32, 127))) if c != '\\'] + \
     [(c, 'self-insert')
-     for c in map(chr, range(128, 256)) if c.isalpha()] + \
+     for c in map(chr, list(range(128, 256))) if c.isalpha()] + \
     [(r'\<up>', 'up'),
      (r'\<down>', 'down'),
      (r'\<left>', 'left'),
@@ -101,9 +101,9 @@ python_emacs_keymap = comp_emacs_keymap + (
     
 reader_vi_insert_keymap = tuple(
     [(c, 'self-insert')
-     for c in map(chr, range(32, 127)) if c <> '\\'] + \
+     for c in map(chr, list(range(32, 127))) if c != '\\'] + \
     [(c, 'self-insert')
-     for c in map(chr, range(128, 256)) if c.isalpha()] + \
+     for c in map(chr, list(range(128, 256))) if c.isalpha()] + \
     [(r'\C-d', 'delete'),
      (r'\<backspace>', 'backspace'),
      ('')])
--- pyrepl/pygame_console.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/pygame_console.py
@@ -72,7 +72,7 @@ class FakeStdin:
         # argh!
         raise NotImplementedError
     def readline(self, n=None):
-        from reader import Reader
+        from .reader import Reader
         try:
             # this isn't quite right: it will clobber any prompt that's
             # been printed.  Not sure how to get around this...
@@ -130,7 +130,8 @@ class PyGameConsole(Console):
         s.fill(c, [0, 600 - bmargin, 800, bmargin])
         s.fill(c, [800 - rmargin, 0, lmargin, 600])
 
-    def refresh(self, screen, (cx, cy)):
+    def refresh(self, screen, xxx_todo_changeme):
+        (cx, cy) = xxx_todo_changeme
         self.screen = screen
         self.pygame_screen.fill(colors.bg,
                                 [0, tmargin + self.cur_top + self.scroll,
@@ -211,12 +212,12 @@ class PyGameConsole(Console):
         meta = bool(pyg_event.mod & (KMOD_ALT|KMOD_META))
 
         try:
-            return self.k[(pyg_event.unicode, meta, ctrl)], pyg_event.unicode
+            return self.k[(pyg_event.str, meta, ctrl)], pyg_event.str
         except KeyError:
             try:
-                return self.k[(pyg_event.key, meta, ctrl)], pyg_event.unicode
+                return self.k[(pyg_event.key, meta, ctrl)], pyg_event.str
             except KeyError:
-                return "invalid-key", pyg_event.unicode
+                return "invalid-key", pyg_event.str
 
     def get_event(self, block=1):
         """Return an Event instance.  Returns None if |block| is false
@@ -239,7 +240,7 @@ class PyGameConsole(Console):
             self.cmd_buf += c.encode('ascii', 'replace')
             self.k = k
 
-            if not isinstance(k, types.DictType):
+            if not isinstance(k, dict):
                 e = Event(k, self.cmd_buf, [])
                 self.k = self.keymap
                 self.cmd_buf = ''
@@ -282,7 +283,7 @@ class PyGameConsole(Console):
 
     def forgetinput(self):
         """Forget all pending, but not yet processed input."""
-        while pygame.event.poll().type <> NOEVENT:
+        while pygame.event.poll().type != NOEVENT:
             pass
     
     def getpending(self):
@@ -299,7 +300,7 @@ class PyGameConsole(Console):
 
     def wait(self):
         """Wait for an event."""
-        raise Exception, "erp!"
+        raise Exception("erp!")
 
     def repaint(self):
         # perhaps we should consolidate grobs?
--- pyrepl/pygame_keymap.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/pygame_keymap.py
@@ -85,27 +85,25 @@ def _parse_key1(key, s):
     while not ret and s < len(key):
         if key[s] == '\\':
             c = key[s+1].lower()
-            if _escapes.has_key(c):
+            if c in _escapes:
                 ret = _escapes[c]
                 s += 2
             elif c == "c":
                 if key[s + 2] != '-':
-                    raise KeySpecError, \
-                              "\\C must be followed by `-' (char %d of %s)"%(
-                        s + 2, repr(key))
+                    raise KeySpecError("\\C must be followed by `-' (char %d of %s)"%(
+                        s + 2, repr(key)))
                 if ctrl:
-                    raise KeySpecError, "doubled \\C- (char %d of %s)"%(
-                        s + 1, repr(key))
+                    raise KeySpecError("doubled \\C- (char %d of %s)"%(
+                        s + 1, repr(key)))
                 ctrl = 1
                 s += 3
             elif c == "m":
                 if key[s + 2] != '-':
-                    raise KeySpecError, \
-                              "\\M must be followed by `-' (char %d of %s)"%(
-                        s + 2, repr(key))
+                    raise KeySpecError("\\M must be followed by `-' (char %d of %s)"%(
+                        s + 2, repr(key)))
                 if meta:
-                    raise KeySpecError, "doubled \\M- (char %d of %s)"%(
-                        s + 1, repr(key))
+                    raise KeySpecError("doubled \\M- (char %d of %s)"%(
+                        s + 1, repr(key)))
                 meta = 1
                 s += 3
             elif c.isdigit():
@@ -119,28 +117,25 @@ def _parse_key1(key, s):
             elif c == '<':
                 t = key.find('>', s)
                 if t == -1:
-                    raise KeySpecError, \
-                              "unterminated \\< starting at char %d of %s"%(
-                        s + 1, repr(key))
+                    raise KeySpecError("unterminated \\< starting at char %d of %s"%(
+                        s + 1, repr(key)))
                 try:
                     ret = _keynames[key[s+2:t].lower()]
                     s = t + 1
                 except KeyError:
-                    raise KeySpecError, \
-                              "unrecognised keyname `%s' at char %d of %s"%(
-                        key[s+2:t], s + 2, repr(key))
+                    raise KeySpecError("unrecognised keyname `%s' at char %d of %s"%(
+                        key[s+2:t], s + 2, repr(key)))
                 if ret is None:
                     return None, s
             else:
-                raise KeySpecError, \
-                          "unknown backslash escape %s at char %d of %s"%(
-                    `c`, s + 2, repr(key))
+                raise KeySpecError("unknown backslash escape %s at char %d of %s"%(
+                    repr(c), s + 2, repr(key)))
         else:
             if ctrl:
                 ret = chr(ord(key[s]) & 0x1f)   # curses.ascii.ctrl()
-                ret = unicode(ret)
+                ret = str(ret)
             else:
-                ret = unicode(key[s])
+                ret = str(key[s])
             s += 1
     return (ret, meta, ctrl), s
 
@@ -156,13 +151,12 @@ def parse_keys(key):
 
 def _compile_keymap(keymap):
     r = {}
-    for key, value in keymap.items():
+    for key, value in list(keymap.items()):
         r.setdefault(key[0], {})[key[1:]] = value
-    for key, value in r.items():
-        if value.has_key(()):
-            if len(value) <> 1:
-                raise KeySpecError, \
-                          "key definitions for %s clash"%(value.values(),)
+    for key, value in list(r.items()):
+        if () in value:
+            if len(value) != 1:
+                raise KeySpecError("key definitions for %s clash"%(list(value.values()),))
             else:
                 r[key] = value[()]
         else:
@@ -173,7 +167,7 @@ def compile_keymap(keymap):
     r = {}
     for key, value in keymap:
         k = parse_keys(key)
-        if value is None and r.has_key(k):
+        if value is None and k in r:
             del r[k]
         if k is not None:
             r[k] = value
@@ -182,7 +176,7 @@ def compile_keymap(keymap):
 def keyname(key):
     longest_match = ''
     longest_match_name = ''
-    for name, keyseq in keyset.items():
+    for name, keyseq in list(keyset.items()):
         if keyseq and key.startswith(keyseq) and \
                len(keyseq) > len(longest_match):
             longest_match = keyseq
@@ -202,7 +196,7 @@ def unparse_key(keyseq):
         return ''
     name, s = keyname(keyseq)
     if name:
-        if name <> 'escape' or s == len(keyseq):
+        if name != 'escape' or s == len(keyseq):
             return '\\<' + name + '>' + unparse_key(keyseq[s:])
         else:
             return '\\M-' + unparse_key(keyseq[1:])
@@ -211,7 +205,7 @@ def unparse_key(keyseq):
         r = keyseq[1:]
         if c == '\\':
             p = '\\\\'
-        elif _unescapes.has_key(c):
+        elif c in _unescapes:
             p = _unescapes[c]
         elif ord(c) < ord(' '):
             p = '\\C-%s'%(chr(ord(c)+96),)
@@ -226,7 +220,7 @@ def _unparse_keyf(keyseq):
         return []
     name, s = keyname(keyseq)
     if name:
-        if name <> 'escape' or s == len(keyseq):
+        if name != 'escape' or s == len(keyseq):
             return [name] + _unparse_keyf(keyseq[s:])
         else:
             rest = _unparse_keyf(keyseq[1:])
@@ -236,7 +230,7 @@ def _unparse_keyf(keyseq):
         r = keyseq[1:]
         if c == '\\':
             p = '\\'
-        elif _unescapes.has_key(c):
+        elif c in _unescapes:
             p = _unescapes[c]
         elif ord(c) < ord(' '):
             p = 'C-%s'%(chr(ord(c)+96),)
--- pyrepl/python_reader.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/python_reader.py
@@ -20,8 +20,8 @@
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 # one impressive collections of imports:
-from __future__ import print_function
-from __future__ import unicode_literals
+
+
 from pyrepl.completing_reader import CompletingReader
 from pyrepl.historical_reader import HistoricalReader
 from pyrepl import completing_reader, reader
@@ -31,9 +31,9 @@ import imp, sys, os, re, code, traceback
 import atexit, warnings
 
 try:
-    unicode
+    str
 except:
-    unicode = str
+    str = str
 
 try:
     imp.find_module("twisted")
@@ -179,7 +179,7 @@ class ReaderConsole(code.InteractiveInterpreter):
         else:
             return
         try:
-            execfile(initfile, self.locals, self.locals)
+            exec(compile(open(initfile, "rb").read(), initfile, 'exec'), self.locals, self.locals)
         except:
             etype, value, tb = sys.exc_info()
             traceback.print_exception(etype, value, tb.tb_next)
@@ -203,7 +203,7 @@ class ReaderConsole(code.InteractiveInterpreter):
                         # can't have warnings spewed onto terminal
                         sv = warnings.showwarning
                         warnings.showwarning = eat_it
-                        l = unicode(self.reader.readline(), 'utf-8')
+                        l = str(self.reader.readline(), 'utf-8')
                     finally:
                         warnings.showwarning = sv
                 except KeyboardInterrupt:
@@ -301,7 +301,7 @@ class ReaderConsole(code.InteractiveInterpreter):
                     self.prepare()
                     try:
                         while 1:
-                            if sys.modules.has_key("_tkinter"):
+                            if "_tkinter" in sys.modules:
                                 self.really_tkinteract()
                                 # really_tkinteract is not expected to
                                 # return except via an exception, but:
--- pyrepl/reader.py.orig	2019-04-16 13:00:52 UTC
+++ pyrepl/reader.py
@@ -19,32 +19,32 @@
 # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-from __future__ import unicode_literals
+
 import unicodedata
 from pyrepl import commands
 from pyrepl import input
 try:
-    unicode
+    str
 except NameError:
-    unicode = str
-    unichr = chr
-    basestring = bytes, str
+    str = str
+    chr = chr
+    str = bytes, str
 
 
 def _make_unctrl_map():
     uc_map = {}
-    for c in map(unichr, range(256)):
+    for c in map(chr, list(range(256))):
         if unicodedata.category(c)[0] != 'C':
             uc_map[c] = c
     for i in range(32):
-        c = unichr(i)
-        uc_map[c] = '^' + unichr(ord('A') + i - 1)
+        c = chr(i)
+        uc_map[c] = '^' + chr(ord('A') + i - 1)
     uc_map[b'\t'] = '    '  # display TABs as 4 characters
-    uc_map[b'\177'] = unicode('^?')
+    uc_map[b'\177'] = str('^?')
     for i in range(256):
-        c = unichr(i)
+        c = chr(i)
         if c not in uc_map:
-            uc_map[c] = unicode('\\%03o') % i
+            uc_map[c] = str('\\%03o') % i
     return uc_map
 
 
@@ -87,17 +87,17 @@ del _make_unctrl_map
 
 [SYNTAX_WHITESPACE,
  SYNTAX_WORD,
- SYNTAX_SYMBOL] = range(3)
+ SYNTAX_SYMBOL] = list(range(3))
 
 
 def make_default_syntax_table():
     # XXX perhaps should use some unicodedata here?
     st = {}
-    for c in map(unichr, range(256)):
+    for c in map(chr, list(range(256))):
         st[c] = SYNTAX_SYMBOL
-    for c in [a for a in map(unichr, range(256)) if a.isalpha()]:
+    for c in [a for a in map(chr, list(range(256))) if a.isalpha()]:
         st[c] = SYNTAX_WORD
-    st[unicode('\n')] = st[unicode(' ')] = SYNTAX_WHITESPACE
+    st[str('\n')] = st[str(' ')] = SYNTAX_WHITESPACE
     return st
 
 default_keymap = tuple(
@@ -145,9 +145,9 @@ default_keymap = tuple(
      #(r'\M-\n', 'insert-nl'),
      ('\\\\', 'self-insert')] +
     [(c, 'self-insert')
-     for c in map(chr, range(32, 127)) if c != '\\'] +
+     for c in map(chr, list(range(32, 127))) if c != '\\'] +
     [(c, 'self-insert')
-     for c in map(chr, range(128, 256)) if c.isalpha()] +
+     for c in map(chr, list(range(128, 256))) if c.isalpha()] +
     [(r'\<up>', 'up'),
      (r'\<down>', 'down'),
      (r'\<left>', 'left'),
@@ -245,7 +245,7 @@ feeling more loquacious than I am now."""
         self.console = console
         self.commands = {}
         self.msg = ''
-        for v in vars(commands).values():
+        for v in list(vars(commands).values()):
             if (isinstance(v, type) and
                     issubclass(v, commands.Command) and
                     v.__name__[0].islower()):
@@ -273,7 +273,7 @@ feeling more loquacious than I am now."""
         screeninfo = []
         w = self.console.width - 1
         p = self.pos
-        for ln, line in zip(range(len(lines)), lines):
+        for ln, line in zip(list(range(len(lines))), lines):
             ll = len(line)
             if 0 <= p <= ll:
                 if self.msg and not self.msg_at_bottom:
@@ -523,7 +523,7 @@ feeling more loquacious than I am now."""
 
     def do_cmd(self, cmd):
         #print cmd
-        if isinstance(cmd[0], basestring):
+        if isinstance(cmd[0], str):
             #XXX: unify to text
             cmd = self.commands.get(cmd[0],
                                     commands.invalid_command)(self, *cmd)
@@ -619,11 +619,11 @@ feeling more loquacious than I am now."""
     def get_buffer(self, encoding=None):
         if encoding is None:
             encoding = self.console.encoding
-        return unicode('').join(self.buffer).encode(self.console.encoding)
+        return str('').join(self.buffer).encode(self.console.encoding)
 
     def get_unicode(self):
         """Return the current buffer as a unicode string."""
-        return unicode('').join(self.buffer)
+        return str('').join(self.buffer)
 
 
 def test():
--- pyrepl/readline.py.orig	2019-04-16 14:11:33 UTC
+++ pyrepl/readline.py
@@ -248,16 +248,16 @@ class _ReadlineWrapper(object):
         self.config.completer_delims = dict.fromkeys(string)
 
     def get_completer_delims(self):
-        chars = self.config.completer_delims.keys()
+        chars = list(self.config.completer_delims.keys())
         chars.sort()
         return ''.join(chars)
 
     def _histline(self, line):
         line = line.rstrip('\n')
         try:
-            return unicode(line, ENCODING)
+            return str(line, ENCODING)
         except UnicodeDecodeError:   # bah, silently fall back...
-            return unicode(line, 'utf-8', 'replace')
+            return str(line, 'utf-8', 'replace')
 
     def get_history_length(self):
         return self.saved_history_length
@@ -293,7 +293,7 @@ class _ReadlineWrapper(object):
         history = self.get_reader().get_trimmed_history(maxlength)
         f = open(os.path.expanduser(filename), 'w')
         for entry in history:
-            if isinstance(entry, unicode):
+            if isinstance(entry, str):
                 try:
                     entry = entry.encode(ENCODING)
                 except UnicodeEncodeError:   # bah, silently fall back...
@@ -340,7 +340,7 @@ class _ReadlineWrapper(object):
     def _get_idxs(self):
         start = cursor = self.get_reader().pos
         buf = self.get_line_buffer()
-        for i in xrange(cursor - 1, -1, -1):
+        for i in range(cursor - 1, -1, -1):
             if buf[i] in self.get_completer_delims():
                 break
             start = i
@@ -396,7 +396,7 @@ def _make_stub(_name, _ret):
     def stub(*args, **kwds):
         import warnings
         warnings.warn("readline.%s() not implemented" % _name, stacklevel=2)
-    stub.func_name = _name
+    stub.__name__ = _name
     globals()[_name] = stub
 
 for _name, _ret in [
@@ -438,14 +438,14 @@ def _setup():
                 del sys.__raw_input__
             except AttributeError:
                 pass
-            return raw_input(prompt)
+            return input(prompt)
         sys.__raw_input__ = _wrapper.raw_input
 
     else:
         # this is not really what readline.c does.  Better than nothing I guess
-        import __builtin__
-        _old_raw_input = __builtin__.raw_input
-        __builtin__.raw_input = _wrapper.raw_input
+        import builtins
+        _old_raw_input = builtins.raw_input
+        builtins.raw_input = _wrapper.raw_input
 
 _old_raw_input = None
 _setup()
--- pyrepl/unix_console.py.orig	2015-12-06 11:35:46 UTC
+++ pyrepl/unix_console.py
@@ -40,9 +40,9 @@ class InvalidTerminal(RuntimeError):
     pass
 
 try:
-    unicode
+    str
 except NameError:
-    unicode = str
+    str = str
 
 _error = (termios.error, curses.error, InvalidTerminal)
 
@@ -221,7 +221,7 @@ class UnixConsole(Console):
 
         self.__offset = offset
 
-        for y, oldline, newline, in zip(range(offset, offset + height),
+        for y, oldline, newline, in zip(list(range(offset, offset + height)),
                                         oldscr,
                                         newscr):
             if oldline != newline:
@@ -533,7 +533,7 @@ class UnixConsole(Console):
             amount = struct.unpack(
                 "i", ioctl(self.input_fd, FIONREAD, "\0\0\0\0"))[0]
             data = os.read(self.input_fd, amount)
-            raw = unicode(data, self.encoding, 'replace')
+            raw = str(data, self.encoding, 'replace')
             #XXX: something is wrong here
             e.data += raw
             e.raw += raw
@@ -549,7 +549,7 @@ class UnixConsole(Console):
 
             amount = 10000
             data = os.read(self.input_fd, amount)
-            raw = unicode(data, self.encoding, 'replace')
+            raw = str(data, self.encoding, 'replace')
             #XXX: something is wrong here
             e.data += raw
             e.raw += raw
--- pyrepl/unix_eventqueue.py.orig	2019-04-16 13:00:52 UTC
+++ pyrepl/unix_eventqueue.py
@@ -30,9 +30,9 @@ from .trace import trace
 from termios import tcgetattr, VERASE
 import os
 try:
-    unicode
+    str
 except NameError:
-    unicode = str
+    str = str
 
 
 _keynames = {
@@ -74,7 +74,7 @@ CTRL_ARROW_KEYCODE = {
 
 def general_keycodes():
     keycodes = {}
-    for key, tiname in _keynames.items():
+    for key, tiname in list(_keynames.items()):
         keycode = curses.tigetstr(tiname)
         trace('key {key} tiname {tiname} keycode {keycode!r}', **locals())
         if keycode:
@@ -87,7 +87,7 @@ def EventQueue(fd, encoding):
     keycodes = general_keycodes()
     if os.isatty(fd):
         backspace = tcgetattr(fd)[6][VERASE]
-        keycodes[backspace] = unicode('backspace')
+        keycodes[backspace] = str('backspace')
     k = keymap.compile_keymap(keycodes)
     trace('keymap {k!r}', k=k)
     return EncodedQueue(k, encoding)
@@ -133,7 +133,7 @@ class EncodedQueue(object):
                 self.insert(Event('key', k, self.flush_buf()))
                 self.k = self.ck
 
-        elif self.buf and self.buf[0] == 033: # 033 == escape
+        elif self.buf and self.buf[0] == 0o33: # 033 == escape
             # escape sequence not recognized by our keymap: propagate it
             # outside so that i can be recognized as an M-... key (see also
             # the docstring in keymap.py, in particular the line \\E.
--- testing/infrastructure.py.orig	2015-12-06 11:35:46 UTC
+++ testing/infrastructure.py
@@ -17,7 +17,7 @@
 # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-from __future__ import print_function
+
 from pyrepl.reader import Reader
 from pyrepl.console import Console, Event
 
--- testing/test_readline.py.orig	2015-12-06 11:35:46 UTC
+++ testing/test_readline.py
@@ -5,7 +5,7 @@ import sys
 
 if sys.version_info < (3, ):
     bytes_type = str
-    unicode_type = unicode
+    unicode_type = str
 else:
     bytes_type = bytes
     unicode_type = str
--- testing/test_unix_reader.py.orig	2019-04-16 13:00:52 UTC
+++ testing/test_unix_reader.py
@@ -1,11 +1,11 @@
-from __future__ import unicode_literals
+
 from pyrepl.unix_eventqueue import EncodedQueue, Event
 
 
 def test_simple():
     q = EncodedQueue({}, 'utf-8')
 
-    a = u'\u1234'
+    a = '\u1234'
     b = a.encode('utf-8')
     for c in b:
         q.push(c)