6262# noinspection PyUnresolvedReferences
6363from six .moves .urllib .request import urlopen
6464
65+ # Prefer statically linked gnureadline if available (for Mac OS X compatibility due to issues with libedit)
66+ try :
67+ import gnureadline as readline
68+ except ImportError :
69+ try :
70+ import readline
71+ except ImportError :
72+ pass
73+
6574# Python 3 compatibility hack due to no built-in file keyword in Python 3
6675# Due to one occurrence of isinstance(<foo>, file) checking to see if something is of file type
6776try :
@@ -1111,9 +1120,8 @@ def pseudo_raw_input(self, prompt):
11111120 if not len (line ):
11121121 line = 'EOF'
11131122 else :
1114- if line [- 1 ] == '\n ' : # this was always true in Cmd
1115- line = line [:- 1 ]
1116- return line
1123+ line = line .rstrip ('\r \n ' )
1124+ return line .strip ()
11171125
11181126 def _cmdloop (self ):
11191127 """Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -1128,12 +1136,10 @@ def _cmdloop(self):
11281136 # has been split out so that it can be called separately
11291137 if self .use_rawinput and self .completekey :
11301138 try :
1131- # noinspection PyUnresolvedReferences
1132- import readline
11331139 self .old_completer = readline .get_completer ()
11341140 readline .set_completer (self .complete )
11351141 readline .parse_and_bind (self .completekey + ": complete" )
1136- except ImportError :
1142+ except NameError :
11371143 pass
11381144 stop = None
11391145 try :
@@ -1149,10 +1155,8 @@ def _cmdloop(self):
11491155 finally :
11501156 if self .use_rawinput and self .completekey :
11511157 try :
1152- # noinspection PyUnresolvedReferences
1153- import readline
11541158 readline .set_completer (self .old_completer )
1155- except ImportError :
1159+ except NameError :
11561160 pass
11571161 return stop
11581162
0 commit comments