eric6/DebugClients/Python/DebugUtilities.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8228
772103b14c18
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
78 78
79 nargs += nkwargs 79 nargs += nkwargs
80 varargs = None 80 varargs = None
81 if co.co_flags & CO_VARARGS: 81 if co.co_flags & CO_VARARGS:
82 varargs = co.co_varnames[nargs] 82 varargs = co.co_varnames[nargs]
83 nargs = nargs + 1 83 nargs += 1
84 varkw = None 84 varkw = None
85 if co.co_flags & CO_VARKEYWORDS: 85 if co.co_flags & CO_VARKEYWORDS:
86 varkw = co.co_varnames[nargs] 86 varkw = co.co_varnames[nargs]
87 return args, varargs, kwonlyargs, varkw 87 return args, varargs, kwonlyargs, varkw
88 88
191 if os.path.exists(program): 191 if os.path.exists(program):
192 with open(program) as f: 192 with open(program) as f:
193 for line in f: 193 for line in f:
194 line = line.strip() 194 line = line.strip()
195 if line: 195 if line:
196 for name in PYTHON_NAMES: 196 for name in PYTHON_NAMES: # __IGNORE_WARNING_Y110__
197 if line.startswith( 197 if (
198 '#!/usr/bin/env {0}'.format(name) 198 line.startswith(
199 '#!/usr/bin/env {0}'.format(name)) or
200 (line.startswith('#!') and name in line)
199 ): 201 ):
200 return True
201 elif line.startswith('#!') and name in line:
202 return True 202 return True
203 return False 203 return False
204 else: 204 else:
205 return False 205 return False
206 except UnicodeDecodeError: 206 except UnicodeDecodeError:
222 """ 222 """
223 if not program: 223 if not program:
224 return False 224 return False
225 225
226 prog = os.path.basename(program).lower() 226 prog = os.path.basename(program).lower()
227 for pyname in PYTHON_NAMES: 227 if any(pyname in prog for pyname in PYTHON_NAMES):
228 if pyname in prog: 228 return True
229 return True
230 229
231 return ( 230 return (
232 not isWindowsPlatform() and 231 not isWindowsPlatform() and
233 isExecutable(program) and 232 isExecutable(program) and
234 startsWithShebang(program) 233 startsWithShebang(program)
307 program = os.path.basename(args[0]).lower() 306 program = os.path.basename(args[0]).lower()
308 for pyname in PYTHON_NAMES: 307 for pyname in PYTHON_NAMES:
309 if pyname in program: 308 if pyname in program:
310 break 309 break
311 else: 310 else:
312 if not isWindowsPlatform() and startsWithShebang(args[0]): 311 if (
313 # insert our interpreter as first argument 312 (not isWindowsPlatform() and startsWithShebang(args[0])) or
314 args.insert(0, sys.executable) 313 (isWindowsPlatform() and args[0].lower().endswith(".py"))
315 elif isWindowsPlatform() and args[0].lower().endswith(".py"): 314 ):
316 # it is a Python script; insert our interpreter as first argument 315 # 1. insert our interpreter as first argument if not Windows
316 # 2. insert our interpreter as first argument if on Windows and
317 # it is a Python script
317 args.insert(0, sys.executable) 318 args.insert(0, sys.executable)
318 319
319 # extract list of interpreter arguments, i.e. all arguments before the 320 # extract list of interpreter arguments, i.e. all arguments before the
320 # first one not starting with '-'. 321 # first one not starting with '-'.
321 interpreter = args.pop(0) 322 interpreter = args.pop(0)
442 state = DEFAULT 443 state = DEFAULT
443 result.append(buf) 444 result.append(buf)
444 buf = '' 445 buf = ''
445 continue 446 continue
446 447
447 if state in (DEFAULT, ARG): 448 if state not in (DEFAULT, ARG, IN_DOUBLE_QUOTE):
448 if ch == '"': 449 raise RuntimeError('Illegal condition')
449 state = IN_DOUBLE_QUOTE
450 else:
451 state = ARG
452 buf += ch
453 450
454 elif state == IN_DOUBLE_QUOTE: 451 if state == IN_DOUBLE_QUOTE:
455 if ch == '"': 452 if ch == '"':
456 if i + 1 < argsLen and args[i + 1] == '"': 453 if i + 1 < argsLen and args[i + 1] == '"':
457 # Undocumented feature in Windows: 454 # Undocumented feature in Windows:
458 # Two consecutive double quotes inside a double-quoted 455 # Two consecutive double quotes inside a double-quoted
459 # argument are interpreted as a single double quote. 456 # argument are interpreted as a single double quote.
466 state = ARG 463 state = ARG
467 else: 464 else:
468 buf += ch 465 buf += ch
469 466
470 else: 467 else:
471 raise RuntimeError('Illegal condition') 468 if ch == '"':
469 state = IN_DOUBLE_QUOTE
470 else:
471 state = ARG
472 buf += ch
472 473
473 if len(buf) > 0 or state != DEFAULT: 474 if len(buf) > 0 or state != DEFAULT:
474 result.append(buf) 475 result.append(buf)
475 476
476 return result 477 return result

eric ide

mercurial