62
62
# noinspection PyUnresolvedReferences
63
63
from six .moves .urllib .request import urlopen
64
64
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
+
65
74
# Python 3 compatibility hack due to no built-in file keyword in Python 3
66
75
# Due to one occurrence of isinstance(<foo>, file) checking to see if something is of file type
67
76
try :
@@ -1111,9 +1120,8 @@ def pseudo_raw_input(self, prompt):
1111
1120
if not len (line ):
1112
1121
line = 'EOF'
1113
1122
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 ()
1117
1125
1118
1126
def _cmdloop (self ):
1119
1127
"""Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -1128,12 +1136,10 @@ def _cmdloop(self):
1128
1136
# has been split out so that it can be called separately
1129
1137
if self .use_rawinput and self .completekey :
1130
1138
try :
1131
- # noinspection PyUnresolvedReferences
1132
- import readline
1133
1139
self .old_completer = readline .get_completer ()
1134
1140
readline .set_completer (self .complete )
1135
1141
readline .parse_and_bind (self .completekey + ": complete" )
1136
- except ImportError :
1142
+ except NameError :
1137
1143
pass
1138
1144
stop = None
1139
1145
try :
@@ -1149,10 +1155,8 @@ def _cmdloop(self):
1149
1155
finally :
1150
1156
if self .use_rawinput and self .completekey :
1151
1157
try :
1152
- # noinspection PyUnresolvedReferences
1153
- import readline
1154
1158
readline .set_completer (self .old_completer )
1155
- except ImportError :
1159
+ except NameError :
1156
1160
pass
1157
1161
return stop
1158
1162
0 commit comments