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
68
+ except ImportError :
69
+ import readline
70
+
65
71
# Python 3 compatibility hack due to no built-in file keyword in Python 3
66
72
# Due to one occurrence of isinstance(<foo>, file) checking to see if something is of file type
67
73
try :
@@ -1111,9 +1117,8 @@ def pseudo_raw_input(self, prompt):
1111
1117
if not len (line ):
1112
1118
line = 'EOF'
1113
1119
else :
1114
- if line [- 1 ] == '\n ' : # this was always true in Cmd
1115
- line = line [:- 1 ]
1116
- return line
1120
+ line = line .rstrip ('\r \n ' )
1121
+ return line .strip ()
1117
1122
1118
1123
def _cmdloop (self ):
1119
1124
"""Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -1127,14 +1132,9 @@ def _cmdloop(self):
1127
1132
# An almost perfect copy from Cmd; however, the pseudo_raw_input portion
1128
1133
# has been split out so that it can be called separately
1129
1134
if self .use_rawinput and self .completekey :
1130
- try :
1131
- # noinspection PyUnresolvedReferences
1132
- import readline
1133
- self .old_completer = readline .get_completer ()
1134
- readline .set_completer (self .complete )
1135
- readline .parse_and_bind (self .completekey + ": complete" )
1136
- except ImportError :
1137
- pass
1135
+ self .old_completer = readline .get_completer ()
1136
+ readline .set_completer (self .complete )
1137
+ readline .parse_and_bind (self .completekey + ": complete" )
1138
1138
stop = None
1139
1139
try :
1140
1140
while not stop :
@@ -1148,12 +1148,7 @@ def _cmdloop(self):
1148
1148
stop = self .onecmd_plus_hooks (line )
1149
1149
finally :
1150
1150
if self .use_rawinput and self .completekey :
1151
- try :
1152
- # noinspection PyUnresolvedReferences
1153
- import readline
1154
- readline .set_completer (self .old_completer )
1155
- except ImportError :
1156
- pass
1151
+ readline .set_completer (self .old_completer )
1157
1152
return stop
1158
1153
1159
1154
# noinspection PyUnusedLocal
0 commit comments