6363from pygments import format
6464from pygments .formatters import TerminalFormatter
6565from pygments .lexers import Python3Lexer
66- from ._py3compat import py3
6766from pygments .token import Token
6867from .formatter import BPythonFormatter
6968
8584from .pager import page
8685from .args import parse as argsparse
8786
88- if not py3 :
89- import inspect
90-
9187
9288# --- module globals ---
9389stdscr = None
@@ -220,10 +216,7 @@ def readline(self, size=-1):
220216 self .buffer .append (rest )
221217 buffer = buffer [:size ]
222218
223- if py3 :
224- return buffer
225- else :
226- return buffer .encode (getpreferredencoding ())
219+ return buffer
227220
228221 def read (self , size = None ):
229222 if size == 0 :
@@ -536,9 +529,6 @@ def echo(self, s, redraw=True):
536529 uses the formatting method as defined in formatter.py to parse the
537530 srings. It won't update the screen if it's reevaluating the code (as it
538531 does with undo)."""
539- if not py3 and isinstance (s , unicode ):
540- s = s .encode (getpreferredencoding ())
541-
542532 a = get_colpair (self .config , "output" )
543533 if "\x01 " in s :
544534 rx = re .search ("\x01 ([A-Za-z])([A-Za-z]?)" , s )
@@ -629,14 +619,11 @@ def get_key(self):
629619 while True :
630620 try :
631621 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 ())
640627 self .scr .nodelay (False )
641628 except UnicodeDecodeError :
642629 # 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):
726713 _args = topline .argspec .varargs
727714 _kwargs = topline .argspec .varkwargs
728715 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 ()
732718 max_w = int (self .scr .getmaxyx ()[1 ] * 0.6 )
733719 self .list_win .erase ()
734720 self .list_win .resize (3 , max_w )
@@ -776,13 +762,7 @@ def mkargspec(self, topline, in_arg, down):
776762 if k == in_arg or i == in_arg :
777763 color |= curses .A_BOLD
778764
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 )
786766 if kw is not None :
787767 self .list_win .addstr ("=" , punctuation_colpair )
788768 self .list_win .addstr (kw , get_colpair (self .config , "token" ))
@@ -796,7 +776,7 @@ def mkargspec(self, topline, in_arg, down):
796776 "*%s" % (_args ,), get_colpair (self .config , "token" )
797777 )
798778
799- if py3 and kwonly :
779+ if kwonly :
800780 if not _args :
801781 if args :
802782 self .list_win .addstr (", " , punctuation_colpair )
@@ -816,7 +796,7 @@ def mkargspec(self, topline, in_arg, down):
816796 )
817797
818798 if _kwargs :
819- if args or _args or ( py3 and kwonly ) :
799+ if args or _args or kwonly :
820800 self .list_win .addstr (", " , punctuation_colpair )
821801 self .list_win .addstr (
822802 "**%s" % (_kwargs ,), get_colpair (self .config , "token" )
@@ -1094,21 +1074,15 @@ def prompt(self, more):
10941074 self .echo (
10951075 "\x01 %s\x03 %s" % (self .config .color_scheme ["prompt" ], self .ps1 )
10961076 )
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
11011078 self .screen_hist .append (
11021079 "\x01 %s\x03 %s\x04 "
11031080 % (self .config .color_scheme ["prompt" ], self .ps1 )
11041081 )
11051082 else :
11061083 prompt_more_color = self .config .color_scheme ["prompt_more" ]
11071084 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
11121086 self .screen_hist .append (
11131087 "\x01 %s\x03 %s\x04 " % (prompt_more_color , self .ps2 )
11141088 )
@@ -1175,10 +1149,7 @@ def repl(self):
11751149
11761150 self .history .append (inp )
11771151 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 "
11821153 stdout_position = len (self .stdout_hist )
11831154 self .more = self .push (inp )
11841155 if not self .more :
@@ -1241,10 +1212,7 @@ def reevaluate(self):
12411212
12421213 self .iy , self .ix = self .scr .getyx ()
12431214 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 "
12481216 self .print_line (line )
12491217 self .screen_hist [- 1 ] += self .f_string
12501218 # I decided it was easier to just do this manually
@@ -1278,9 +1246,6 @@ def write(self, s):
12781246 else :
12791247 t = s
12801248
1281- if not py3 and isinstance (t , unicode ):
1282- t = t .encode (getpreferredencoding ())
1283-
12841249 if not self .stdout_hist :
12851250 self .stdout_hist = t
12861251 else :
@@ -1390,25 +1355,19 @@ def lsize():
13901355 if v_items :
13911356 self .list_win .addstr ("\n " )
13921357
1393- if not py3 :
1394- encoding = getpreferredencoding ()
13951358 for ix , i in enumerate (v_items ):
13961359 padding = (wl - len (i )) * " "
13971360 if i == current_item :
13981361 color = get_colpair (self .config , "operator" )
13991362 else :
14001363 color = get_colpair (self .config , "main" )
1401- if not py3 :
1402- i = i .encode (encoding )
14031364 self .list_win .addstr (i + padding , color )
14041365 if (cols == 1 or (ix and not (ix + 1 ) % cols )) and ix + 1 < len (
14051366 v_items
14061367 ):
14071368 self .list_win .addstr ("\n " )
14081369
14091370 if self .docstring is not None :
1410- if not py3 and isinstance (docstring_string , unicode ):
1411- docstring_string = docstring_string .encode (encoding , "ignore" )
14121371 self .list_win .addstr (
14131372 "\n " + docstring_string , get_colpair (self .config , "comment" )
14141373 )
@@ -1544,10 +1503,7 @@ def send_current_line_to_editor(self):
15441503 self .iy , self .ix = self .scr .getyx ()
15451504 self .evaluating = True
15461505 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 "
15511507 self .history .append (line )
15521508 self .print_line (line )
15531509 self .screen_hist [- 1 ] += self .f_string
@@ -1705,9 +1661,6 @@ def settext(self, s, c=None, p=False):
17051661 self .c = c
17061662
17071663 if s :
1708- if not py3 and isinstance (s , unicode ):
1709- s = s .encode (getpreferredencoding ())
1710-
17111664 if self .c :
17121665 self .win .addstr (s , self .c )
17131666 else :
@@ -1996,15 +1949,6 @@ def main_curses(scr, args, config, interactive=True, locals_=None, banner=None):
19961949 )
19971950 clirepl .write ("\n " )
19981951
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-
20081952 exit_value = clirepl .repl ()
20091953 if hasattr (sys , "exitfunc" ):
20101954 sys .exitfunc ()
0 commit comments