| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1ef1776 commit 02b4d6b
16 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,13 +37,9 @@ | |||
| 37 | 37 | from . import importcompletion | |
| 38 | 38 | from . import line as lineparts | |
| 39 | 39 | from .line import LinePart | |
| 40 | - from ._py3compat import py3 | ||
| 41 | 40 | from .lazyre import LazyReCompile | |
| 42 | 41 | from .simpleeval import safe_eval, evaluate_current_expression, EvaluationError | |
| 43 | 42 | ||
| 44 | - if not py3: | ||
| 45 | - from types import InstanceType, ClassType | ||
| 46 | - | ||
| 47 | 43 | ||
| 48 | 44 | # Autocomplete modes | |
| 49 | 45 | SIMPLE = "simple" | |
@@ -109,10 +105,7 @@ | |||
| 109 | 105 | ) | |
| 110 | 106 | ) | |
| 111 | 107 | ||
| 112 | - if py3: | ||
| 113 | - KEYWORDS = frozenset(keyword.kwlist) | ||
| 114 | - else: | ||
| 115 | - KEYWORDS = frozenset(name.decode("ascii") for name in keyword.kwlist) | ||
| 108 | + KEYWORDS = frozenset(keyword.kwlist) | ||
| 116 | 109 | ||
| 117 | 110 | ||
| 118 | 111 | def after_last_dot(name): | |
@@ -253,19 +246,8 @@ class FilenameCompletion(BaseCompletionType): | |||
| 253 | 246 | def __init__(self, mode=SIMPLE): | |
| 254 | 247 | super(FilenameCompletion, self).__init__(False, mode) | |
| 255 | 248 | ||
| 256 | - if py3: | ||
| 257 | - | ||
| 258 | - def safe_glob(self, pathname): | ||
| 259 | - return glob.iglob(glob.escape(pathname) + "*") | ||
| 260 | - | ||
| 261 | - else: | ||
| 262 | - | ||
| 263 | - def safe_glob(self, pathname): | ||
| 264 | - try: | ||
| 265 | - return glob.glob(pathname + "*") | ||
| 266 | - except re.error: | ||
| 267 | - # see #491 | ||
| 268 | - return tuple() | ||
| 249 | + def safe_glob(self, pathname): | ||
| 250 | + return glob.iglob(glob.escape(pathname) + "*") | ||
| 269 | 251 | ||
| 270 | 252 | def matches(self, cursor_offset, line, **kwargs): | |
| 271 | 253 | cs = lineparts.current_string(cursor_offset, line) | |
@@ -366,39 +348,18 @@ def attr_lookup(self, obj, expr, attr): | |||
| 366 | 348 | except ValueError: | |
| 367 | 349 | pass | |
| 368 | 350 | ||
| 369 | - if not py3 and isinstance(obj, (InstanceType, ClassType)): | ||
| 370 | - # Account for the __dict__ in an old-style class. | ||
| 371 | - words.append("__dict__") | ||
| 372 | - | ||
| 373 | 351 | matches = [] | |
| 374 | 352 | n = len(attr) | |
| 375 | 353 | for word in words: | |
| 376 | 354 | if self.method_match(word, n, attr) and word != "__builtins__": | |
| 377 | 355 | matches.append("%s.%s" % (expr, word)) | |
| 378 | 356 | return matches | |
| 379 | 357 | ||
| 380 | - if py3: | ||
| 381 | - | ||
| 382 | - def list_attributes(self, obj): | ||
| 383 | - # TODO: re-implement dir using getattr_static to avoid using | ||
| 384 | - # AttrCleaner here? | ||
| 385 | - with inspection.AttrCleaner(obj): | ||
| 386 | - return dir(obj) | ||
| 387 | - | ||
| 388 | - else: | ||
| 389 | - | ||
| 390 | - def list_attributes(self, obj): | ||
| 391 | - with inspection.AttrCleaner(obj): | ||
| 392 | - if isinstance(obj, InstanceType): | ||
| 393 | - try: | ||
| 394 | - return dir(obj) | ||
| 395 | - except Exception: | ||
| 396 | - # This is a case where we can not prevent user code from | ||
| 397 | - # running. We return a default list attributes on error | ||
| 398 | - # instead. (#536) | ||
| 399 | - return ["__doc__", "__module__"] | ||
| 400 | - else: | ||
| 401 | - return dir(obj) | ||
| 358 | + def list_attributes(self, obj): | ||
| 359 | + # TODO: re-implement dir using getattr_static to avoid using | ||
| 360 | + # AttrCleaner here? | ||
| 361 | + with inspection.AttrCleaner(obj): | ||
| 362 | + return dir(obj) | ||
| 402 | 363 | ||
| 403 | 364 | ||
| 404 | 365 | class DictKeyCompletion(BaseCompletionType): | |
@@ -501,12 +462,11 @@ def matches(self, cursor_offset, line, **kwargs): | |||
| 501 | 462 | for name in argspec[1][0] | |
| 502 | 463 | if isinstance(name, string_types) and name.startswith(r.word) | |
| 503 | 464 | ) | |
| 504 | - if py3: | ||
| 505 | - matches.update( | ||
| 506 | - name + "=" | ||
| 507 | - for name in argspec[1][4] | ||
| 508 | - if name.startswith(r.word) | ||
| 509 | - ) | ||
| 465 | + matches.update( | ||
| 466 | + name + "=" | ||
| 467 | + for name in argspec[1][4] | ||
| 468 | + if name.startswith(r.word) | ||
| 469 | + ) | ||
| 510 | 470 | return matches if matches else None | |
| 511 | 471 | ||
| 512 | 472 | def locate(self, current_offset, line): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,7 +63,6 @@ | |||
| 63 | 63 | from pygments import format | |
| 64 | 64 | from pygments.formatters import TerminalFormatter | |
| 65 | 65 | from pygments.lexers import Python3Lexer | |
| 66 | - from ._py3compat import py3 | ||
| 67 | 66 | from pygments.token import Token | |
| 68 | 67 | from .formatter import BPythonFormatter | |
| 69 | 68 | ||
@@ -85,9 +84,6 @@ | |||
| 85 | 84 | from .pager import page | |
| 86 | 85 | from .args import parse as argsparse | |
| 87 | 86 | ||
| 88 | - if not py3: | ||
| 89 | - import inspect | ||
| 90 | - | ||
| 91 | 87 | ||
| 92 | 88 | # --- module globals --- | |
| 93 | 89 | stdscr = None | |
@@ -220,10 +216,7 @@ def readline(self, size=-1): | |||
| 220 | 216 | self.buffer.append(rest) | |
| 221 | 217 | buffer = buffer[:size] | |
| 222 | 218 | ||
| 223 | - if py3: | ||
| 224 | - return buffer | ||
| 225 | - else: | ||
| 226 | - return buffer.encode(getpreferredencoding()) | ||
| 219 | + return buffer | ||
| 227 | 220 | ||
| 228 | 221 | def read(self, size=None): | |
| 229 | 222 | if size == 0: | |
@@ -536,9 +529,6 @@ def echo(self, s, redraw=True): | |||
| 536 | 529 | uses the formatting method as defined in formatter.py to parse the | |
| 537 | 530 | srings. It won't update the screen if it's reevaluating the code (as it | |
| 538 | 531 | does with undo).""" | |
| 539 | - if not py3 and isinstance(s, unicode): | ||
| 540 | - s = s.encode(getpreferredencoding()) | ||
| 541 | - | ||
| 542 | 532 | a = get_colpair(self.config, "output") | |
| 543 | 533 | if "\x01" in s: | |
| 544 | 534 | rx = re.search("\x01([A-Za-z])([A-Za-z]?)", s) | |
@@ -629,14 +619,11 @@ def get_key(self): | |||
| 629 | 619 | while True: | |
| 630 | 620 | try: | |
| 631 | 621 | key += self.scr.getkey() | |
| 632 | - if py3: | ||
| 633 | - # Seems like we get a in the locale's encoding | ||
| 634 | - # encoded string in Python 3 as well, but of | ||
| 635 | - # type str instead of bytes, hence convert it to | ||
| 636 | - # bytes first and decode then | ||
| 637 | - key = key.encode("latin-1").decode(getpreferredencoding()) | ||
| 638 | - else: | ||
| 639 | - key = key.decode(getpreferredencoding()) | ||
| 622 | + # Seems like we get a in the locale's encoding | ||
| 623 | + # encoded string in Python 3 as well, but of | ||
| 624 | + # type str instead of bytes, hence convert it to | ||
| 625 | + # bytes first and decode then | ||
| 626 | + key = key.encode("latin-1").decode(getpreferredencoding()) | ||
| 640 | 627 | self.scr.nodelay(False) | |
| 641 | 628 | except UnicodeDecodeError: | |
| 642 | 629 | # Yes, that actually kind of sucks, but I don't see another way to get | |
@@ -726,9 +713,8 @@ def mkargspec(self, topline, in_arg, down): | |||
| 726 | 713 | _args = topline.argspec.varargs | |
| 727 | 714 | _kwargs = topline.argspec.varkwargs | |
| 728 | 715 | is_bound_method = topline.is_bound_method | |
| 729 | - if py3: | ||
| 730 | - kwonly = topline.argspec.kwonly | ||
| 731 | - kwonly_defaults = topline.argspec.kwonly_defaults or dict() | ||
| 716 | + kwonly = topline.argspec.kwonly | ||
| 717 | + kwonly_defaults = topline.argspec.kwonly_defaults or dict() | ||
| 732 | 718 | max_w = int(self.scr.getmaxyx()[1] * 0.6) | |
| 733 | 719 | self.list_win.erase() | |
| 734 | 720 | self.list_win.resize(3, max_w) | |
@@ -776,13 +762,7 @@ def mkargspec(self, topline, in_arg, down): | |||
| 776 | 762 | if k == in_arg or i == in_arg: | |
| 777 | 763 | color |= curses.A_BOLD | |
| 778 | 764 | ||
| 779 | - if not py3: | ||
| 780 | - # See issue #138: We need to format tuple unpacking correctly | ||
| 781 | - # We use the undocumented function inspection.strseq() for | ||
| 782 | - # that. Fortunately, that madness is gone in Python 3. | ||
| 783 | - self.list_win.addstr(inspect.strseq(i, str), color) | ||
| 784 | - else: | ||
| 785 | - self.list_win.addstr(str(i), color) | ||
| 765 | + self.list_win.addstr(str(i), color) | ||
| 786 | 766 | if kw is not None: | |
| 787 | 767 | self.list_win.addstr("=", punctuation_colpair) | |
| 788 | 768 | self.list_win.addstr(kw, get_colpair(self.config, "token")) | |
@@ -796,7 +776,7 @@ def mkargspec(self, topline, in_arg, down): | |||
| 796 | 776 | "*%s" % (_args,), get_colpair(self.config, "token") | |
| 797 | 777 | ) | |
| 798 | 778 | ||
| 799 | - if py3 and kwonly: | ||
| 779 | + if kwonly: | ||
| 800 | 780 | if not _args: | |
| 801 | 781 | if args: | |
| 802 | 782 | self.list_win.addstr(", ", punctuation_colpair) | |
@@ -816,7 +796,7 @@ def mkargspec(self, topline, in_arg, down): | |||
| 816 | 796 | ) | |
| 817 | 797 | ||
| 818 | 798 | if _kwargs: | |
| 819 | - if args or _args or (py3 and kwonly): | ||
| 799 | + if args or _args or kwonly: | ||
| 820 | 800 | self.list_win.addstr(", ", punctuation_colpair) | |
| 821 | 801 | self.list_win.addstr( | |
| 822 | 802 | "**%s" % (_kwargs,), get_colpair(self.config, "token") | |
@@ -1094,21 +1074,15 @@ def prompt(self, more): | |||
| 1094 | 1074 | self.echo( | |
| 1095 | 1075 | "\x01%s\x03%s" % (self.config.color_scheme["prompt"], self.ps1) | |
| 1096 | 1076 | ) | |
| 1097 | - if py3: | ||
| 1098 | - self.stdout_hist += self.ps1 | ||
| 1099 | - else: | ||
| 1100 | - self.stdout_hist += self.ps1.encode(getpreferredencoding()) | ||
| 1077 | + self.stdout_hist += self.ps1 | ||
| 1101 | 1078 | self.screen_hist.append( | |
| 1102 | 1079 | "\x01%s\x03%s\x04" | |
| 1103 | 1080 | % (self.config.color_scheme["prompt"], self.ps1) | |
| 1104 | 1081 | ) | |
| 1105 | 1082 | else: | |
| 1106 | 1083 | prompt_more_color = self.config.color_scheme["prompt_more"] | |
| 1107 | 1084 | self.echo("\x01%s\x03%s" % (prompt_more_color, self.ps2)) | |
| 1108 | - if py3: | ||
| 1109 | - self.stdout_hist += self.ps2 | ||
| 1110 | - else: | ||
| 1111 | - self.stdout_hist += self.ps2.encode(getpreferredencoding()) | ||
| 1085 | + self.stdout_hist += self.ps2 | ||
| 1112 | 1086 | self.screen_hist.append( | |
| 1113 | 1087 | "\x01%s\x03%s\x04" % (prompt_more_color, self.ps2) | |
| 1114 | 1088 | ) | |
@@ -1175,10 +1149,7 @@ def repl(self): | |||
| 1175 | 1149 | ||
| 1176 | 1150 | self.history.append(inp) | |
| 1177 | 1151 | self.screen_hist[-1] += self.f_string | |
| 1178 | - if py3: | ||
| 1179 | - self.stdout_hist += inp + "\n" | ||
| 1180 | - else: | ||
| 1181 | - self.stdout_hist += inp.encode(getpreferredencoding()) + "\n" | ||
| 1152 | + self.stdout_hist += inp + "\n" | ||
| 1182 | 1153 | stdout_position = len(self.stdout_hist) | |
| 1183 | 1154 | self.more = self.push(inp) | |
| 1184 | 1155 | if not self.more: | |
@@ -1241,10 +1212,7 @@ def reevaluate(self): | |||
| 1241 | 1212 | ||
| 1242 | 1213 | self.iy, self.ix = self.scr.getyx() | |
| 1243 | 1214 | for line in self.history: | |
| 1244 | - if py3: | ||
| 1245 | - self.stdout_hist += line + "\n" | ||
| 1246 | - else: | ||
| 1247 | - self.stdout_hist += line.encode(getpreferredencoding()) + "\n" | ||
| 1215 | + self.stdout_hist += line + "\n" | ||
| 1248 | 1216 | self.print_line(line) | |
| 1249 | 1217 | self.screen_hist[-1] += self.f_string | |
| 1250 | 1218 | # I decided it was easier to just do this manually | |
@@ -1278,9 +1246,6 @@ def write(self, s): | |||
| 1278 | 1246 | else: | |
| 1279 | 1247 | t = s | |
| 1280 | 1248 | ||
| 1281 | - if not py3 and isinstance(t, unicode): | ||
| 1282 | - t = t.encode(getpreferredencoding()) | ||
| 1283 | - | ||
| 1284 | 1249 | if not self.stdout_hist: | |
| 1285 | 1250 | self.stdout_hist = t | |
| 1286 | 1251 | else: | |
@@ -1390,25 +1355,19 @@ def lsize(): | |||
| 1390 | 1355 | if v_items: | |
| 1391 | 1356 | self.list_win.addstr("\n ") | |
| 1392 | 1357 | ||
| 1393 | - if not py3: | ||
| 1394 | - encoding = getpreferredencoding() | ||
| 1395 | 1358 | for ix, i in enumerate(v_items): | |
| 1396 | 1359 | padding = (wl - len(i)) * " " | |
| 1397 | 1360 | if i == current_item: | |
| 1398 | 1361 | color = get_colpair(self.config, "operator") | |
| 1399 | 1362 | else: | |
| 1400 | 1363 | color = get_colpair(self.config, "main") | |
| 1401 | - if not py3: | ||
| 1402 | - i = i.encode(encoding) | ||
| 1403 | 1364 | self.list_win.addstr(i + padding, color) | |
| 1404 | 1365 | if (cols == 1 or (ix and not (ix + 1) % cols)) and ix + 1 < len( | |
| 1405 | 1366 | v_items | |
| 1406 | 1367 | ): | |
| 1407 | 1368 | self.list_win.addstr("\n ") | |
| 1408 | 1369 | ||
| 1409 | 1370 | if self.docstring is not None: | |
| 1410 | - if not py3 and isinstance(docstring_string, unicode): | ||
| 1411 | - docstring_string = docstring_string.encode(encoding, "ignore") | ||
| 1412 | 1371 | self.list_win.addstr( | |
| 1413 | 1372 | "\n" + docstring_string, get_colpair(self.config, "comment") | |
| 1414 | 1373 | ) | |
@@ -1544,10 +1503,7 @@ def send_current_line_to_editor(self): | |||
| 1544 | 1503 | self.iy, self.ix = self.scr.getyx() | |
| 1545 | 1504 | self.evaluating = True | |
| 1546 | 1505 | for line in lines: | |
| 1547 | - if py3: | ||
| 1548 | - self.stdout_hist += line + "\n" | ||
| 1549 | - else: | ||
| 1550 | - self.stdout_hist += line.encode(getpreferredencoding()) + "\n" | ||
| 1506 | + self.stdout_hist += line + "\n" | ||
| 1551 | 1507 | self.history.append(line) | |
| 1552 | 1508 | self.print_line(line) | |
| 1553 | 1509 | self.screen_hist[-1] += self.f_string | |
@@ -1705,9 +1661,6 @@ def settext(self, s, c=None, p=False): | |||
| 1705 | 1661 | self.c = c | |
| 1706 | 1662 | ||
| 1707 | 1663 | if s: | |
| 1708 | - if not py3 and isinstance(s, unicode): | ||
| 1709 | - s = s.encode(getpreferredencoding()) | ||
| 1710 | - | ||
| 1711 | 1664 | if self.c: | |
| 1712 | 1665 | self.win.addstr(s, self.c) | |
| 1713 | 1666 | else: | |
@@ -1996,15 +1949,6 @@ def main_curses(scr, args, config, interactive=True, locals_=None, banner=None): | |||
| 1996 | 1949 | ) | |
| 1997 | 1950 | clirepl.write("\n") | |
| 1998 | 1951 | ||
| 1999 | - if not py3: | ||
| 2000 | - # XXX these deprecation warnings need to go at some point | ||
| 2001 | - clirepl.write( | ||
| 2002 | - _( | ||
| 2003 | - "WARNING: You are using `bpython` on Python 2. Support for Python 2 has been deprecated in version 0.19 and might disappear in a future version." | ||
| 2004 | - ) | ||
| 2005 | - ) | ||
| 2006 | - clirepl.write("\n") | ||
| 2007 | - | ||
| 2008 | 1952 | exit_value = clirepl.repl() | |
| 2009 | 1953 | if hasattr(sys, "exitfunc"): | |
| 2010 | 1954 | sys.exitfunc() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,6 @@ | |||
| 19 | 19 | from .curtsiesfrontend import events as bpythonevents | |
| 20 | 20 | from . import inspection | |
| 21 | 21 | from .repl import extract_exit_value | |
| 22 | - from ._py3compat import py3 | ||
| 23 | 22 | ||
| 24 | 23 | logger = logging.getLogger(__name__) | |
| 25 | 24 | ||
@@ -199,14 +198,6 @@ def main(args=None, locals_=None, banner=None, welcome_message=None): | |||
| 199 | 198 | if banner is not None: | |
| 200 | 199 | print(banner) | |
| 201 | 200 | ||
| 202 | - if not py3: | ||
| 203 | - # XXX these deprecation warnings need to go at some point | ||
| 204 | - print( | ||
| 205 | - _( | ||
| 206 | - "WARNING: You are using `bpython` on Python 2. Support for Python 2 has been deprecated in version 0.19 and might disappear in a future version." | ||
| 207 | - ) | ||
| 208 | - ) | ||
| 209 | - | ||
| 210 | 201 | global repl | |
| 211 | 202 | repl = FullCurtsiesRepl(config, locals_, welcome_message, interp) | |
| 212 | 203 | try: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments