|
8 | 8 |
|
9 | 9 | __author__ = "Patrick K. O'Brien <[email protected]>" |
10 | 10 |
|
11 | | -import sys |
| 11 | +import io |
12 | 12 | import inspect |
13 | 13 | import tokenize |
14 | | -import types |
15 | | -from six import BytesIO, PY3, string_types |
16 | 14 |
|
17 | 15 | def getAutoCompleteList(command='', locals=None, includeMagic=1, |
18 | 16 | includeSingle=1, includeDouble=1): |
@@ -179,7 +177,7 @@ def getCallTip(command='', locals=None): |
179 | 177 | pass |
180 | 178 | elif inspect.isfunction(obj): |
181 | 179 | # tip1 is a string like: "getCallTip(command='', locals=None)" |
182 | | - argspec = inspect.getargspec(obj) if not PY3 else inspect.getfullargspec(obj) |
| 180 | + argspec = inspect.getfullargspec(obj) |
183 | 181 | argspec = inspect.formatargspec(*argspec) |
184 | 182 | if dropSelf: |
185 | 183 | # The first parameter to a method is a reference to an |
@@ -226,8 +224,6 @@ def getRoot(command, terminator=None): |
226 | 224 | '.'. The terminator and anything after the terminator will be |
227 | 225 | dropped.""" |
228 | 226 | command = command.split('\n')[-1] |
229 | | - #if command.startswith(sys.ps2): |
230 | | - # command = command[len(sys.ps2):] |
231 | 227 | command = command.lstrip() |
232 | 228 | command = rtrimTerminus(command, terminator) |
233 | 229 | if terminator == '.': |
@@ -265,7 +261,7 @@ def getRoot(command, terminator=None): |
265 | 261 | line = token[4] |
266 | 262 | if tokentype in (tokenize.ENDMARKER, tokenize.NEWLINE): |
267 | 263 | continue |
268 | | - if PY3 and tokentype is tokenize.ENCODING: |
| 264 | + if tokentype is tokenize.ENCODING: |
269 | 265 | line = lastline |
270 | 266 | break |
271 | 267 | if tokentype in (tokenize.NAME, tokenize.STRING, tokenize.NUMBER) \ |
@@ -311,27 +307,22 @@ def getTokens(command): |
311 | 307 | """Return list of token tuples for command.""" |
312 | 308 |
|
313 | 309 | # In case the command is unicode try encoding it |
314 | | - if isinstance(command, string_types): |
| 310 | + if isinstance(command, str): |
315 | 311 | try: |
316 | 312 | command = command.encode('utf-8') |
317 | 313 | except UnicodeEncodeError: |
318 | 314 | pass # otherwise leave it alone |
319 | 315 |
|
320 | | - f = BytesIO(command) |
| 316 | + f = io.BytesIO(command) |
321 | 317 | # tokens is a list of token tuples, each looking like: |
322 | 318 | # (type, string, (srow, scol), (erow, ecol), line) |
323 | 319 | tokens = [] |
324 | 320 | # Can't use list comprehension: |
325 | 321 | # tokens = [token for token in tokenize.generate_tokens(f.readline)] |
326 | 322 | # because of need to append as much as possible before TokenError. |
327 | 323 | try: |
328 | | - if not PY3: |
329 | | - def eater(*args): |
330 | | - tokens.append(args) |
331 | | - tokenize.tokenize_loop(f.readline, eater) |
332 | | - else: |
333 | | - for t in tokenize.tokenize(f.readline): |
334 | | - tokens.append(t) |
| 324 | + for t in tokenize.tokenize(f.readline): |
| 325 | + tokens.append(t) |
335 | 326 | except tokenize.TokenError: |
336 | 327 | # This is due to a premature EOF, which we expect since we are |
337 | 328 | # feeding in fragments of Python code. |
|
0 commit comments