partition
stringclasses 3
values | func_name
stringlengths 1
134
| docstring
stringlengths 1
46.9k
| path
stringlengths 4
223
| original_string
stringlengths 75
104k
| code
stringlengths 75
104k
| docstring_tokens
listlengths 1
1.97k
| repo
stringlengths 7
55
| language
stringclasses 1
value | url
stringlengths 87
315
| code_tokens
listlengths 19
28.4k
| sha
stringlengths 40
40
|
|---|---|---|---|---|---|---|---|---|---|---|---|
test
|
LokyManager.start
|
Spawn a server process for this manager object
|
loky/backend/managers.py
|
def start(self, initializer=None, initargs=()):
'''Spawn a server process for this manager object'''
assert self._state.value == State.INITIAL
if (initializer is not None
and not hasattr(initializer, '__call__')):
raise TypeError('initializer must be a callable')
# pipe over which we will retrieve address of server
reader, writer = mp.Pipe(duplex=False)
# spawn process which runs a server
self._process = Process(
target=type(self)._run_server,
args=(self._registry, self._address, bytes(self._authkey),
self._serializer, writer, initializer, initargs),
)
ident = ':'.join(str(i) for i in self._process._identity)
self._process.name = type(self).__name__ + '-' + ident
self._process.start()
# get address of server
writer.close()
self._address = reader.recv()
reader.close()
# register a finalizer
self._state.value = State.STARTED
self.shutdown = mp.util.Finalize(
self, type(self)._finalize_manager,
args=(self._process, self._address, self._authkey,
self._state, self._Client),
exitpriority=0
)
|
def start(self, initializer=None, initargs=()):
'''Spawn a server process for this manager object'''
assert self._state.value == State.INITIAL
if (initializer is not None
and not hasattr(initializer, '__call__')):
raise TypeError('initializer must be a callable')
# pipe over which we will retrieve address of server
reader, writer = mp.Pipe(duplex=False)
# spawn process which runs a server
self._process = Process(
target=type(self)._run_server,
args=(self._registry, self._address, bytes(self._authkey),
self._serializer, writer, initializer, initargs),
)
ident = ':'.join(str(i) for i in self._process._identity)
self._process.name = type(self).__name__ + '-' + ident
self._process.start()
# get address of server
writer.close()
self._address = reader.recv()
reader.close()
# register a finalizer
self._state.value = State.STARTED
self.shutdown = mp.util.Finalize(
self, type(self)._finalize_manager,
args=(self._process, self._address, self._authkey,
self._state, self._Client),
exitpriority=0
)
|
[
"Spawn",
"a",
"server",
"process",
"for",
"this",
"manager",
"object"
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/managers.py#L18-L51
|
[
"def",
"start",
"(",
"self",
",",
"initializer",
"=",
"None",
",",
"initargs",
"=",
"(",
")",
")",
":",
"assert",
"self",
".",
"_state",
".",
"value",
"==",
"State",
".",
"INITIAL",
"if",
"(",
"initializer",
"is",
"not",
"None",
"and",
"not",
"hasattr",
"(",
"initializer",
",",
"'__call__'",
")",
")",
":",
"raise",
"TypeError",
"(",
"'initializer must be a callable'",
")",
"# pipe over which we will retrieve address of server",
"reader",
",",
"writer",
"=",
"mp",
".",
"Pipe",
"(",
"duplex",
"=",
"False",
")",
"# spawn process which runs a server",
"self",
".",
"_process",
"=",
"Process",
"(",
"target",
"=",
"type",
"(",
"self",
")",
".",
"_run_server",
",",
"args",
"=",
"(",
"self",
".",
"_registry",
",",
"self",
".",
"_address",
",",
"bytes",
"(",
"self",
".",
"_authkey",
")",
",",
"self",
".",
"_serializer",
",",
"writer",
",",
"initializer",
",",
"initargs",
")",
",",
")",
"ident",
"=",
"':'",
".",
"join",
"(",
"str",
"(",
"i",
")",
"for",
"i",
"in",
"self",
".",
"_process",
".",
"_identity",
")",
"self",
".",
"_process",
".",
"name",
"=",
"type",
"(",
"self",
")",
".",
"__name__",
"+",
"'-'",
"+",
"ident",
"self",
".",
"_process",
".",
"start",
"(",
")",
"# get address of server",
"writer",
".",
"close",
"(",
")",
"self",
".",
"_address",
"=",
"reader",
".",
"recv",
"(",
")",
"reader",
".",
"close",
"(",
")",
"# register a finalizer",
"self",
".",
"_state",
".",
"value",
"=",
"State",
".",
"STARTED",
"self",
".",
"shutdown",
"=",
"mp",
".",
"util",
".",
"Finalize",
"(",
"self",
",",
"type",
"(",
"self",
")",
".",
"_finalize_manager",
",",
"args",
"=",
"(",
"self",
".",
"_process",
",",
"self",
".",
"_address",
",",
"self",
".",
"_authkey",
",",
"self",
".",
"_state",
",",
"self",
".",
"_Client",
")",
",",
"exitpriority",
"=",
"0",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
DupFd
|
Return a wrapper for an fd.
|
loky/backend/_posix_reduction.py
|
def DupFd(fd):
'''Return a wrapper for an fd.'''
popen_obj = get_spawning_popen()
if popen_obj is not None:
return popen_obj.DupFd(popen_obj.duplicate_for_child(fd))
elif HAVE_SEND_HANDLE and sys.version_info[:2] > (3, 3):
from multiprocessing import resource_sharer
return resource_sharer.DupFd(fd)
else:
raise TypeError(
'Cannot pickle connection object. This object can only be '
'passed when spawning a new process'
)
|
def DupFd(fd):
'''Return a wrapper for an fd.'''
popen_obj = get_spawning_popen()
if popen_obj is not None:
return popen_obj.DupFd(popen_obj.duplicate_for_child(fd))
elif HAVE_SEND_HANDLE and sys.version_info[:2] > (3, 3):
from multiprocessing import resource_sharer
return resource_sharer.DupFd(fd)
else:
raise TypeError(
'Cannot pickle connection object. This object can only be '
'passed when spawning a new process'
)
|
[
"Return",
"a",
"wrapper",
"for",
"an",
"fd",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/_posix_reduction.py#L34-L46
|
[
"def",
"DupFd",
"(",
"fd",
")",
":",
"popen_obj",
"=",
"get_spawning_popen",
"(",
")",
"if",
"popen_obj",
"is",
"not",
"None",
":",
"return",
"popen_obj",
".",
"DupFd",
"(",
"popen_obj",
".",
"duplicate_for_child",
"(",
"fd",
")",
")",
"elif",
"HAVE_SEND_HANDLE",
"and",
"sys",
".",
"version_info",
"[",
":",
"2",
"]",
">",
"(",
"3",
",",
"3",
")",
":",
"from",
"multiprocessing",
"import",
"resource_sharer",
"return",
"resource_sharer",
".",
"DupFd",
"(",
"fd",
")",
"else",
":",
"raise",
"TypeError",
"(",
"'Cannot pickle connection object. This object can only be '",
"'passed when spawning a new process'",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
get_reusable_executor
|
Return the current ReusableExectutor instance.
Start a new instance if it has not been started already or if the previous
instance was left in a broken state.
If the previous instance does not have the requested number of workers, the
executor is dynamically resized to adjust the number of workers prior to
returning.
Reusing a singleton instance spares the overhead of starting new worker
processes and importing common python packages each time.
``max_workers`` controls the maximum number of tasks that can be running in
parallel in worker processes. By default this is set to the number of
CPUs on the host.
Setting ``timeout`` (in seconds) makes idle workers automatically shutdown
so as to release system resources. New workers are respawn upon submission
of new tasks so that ``max_workers`` are available to accept the newly
submitted tasks. Setting ``timeout`` to around 100 times the time required
to spawn new processes and import packages in them (on the order of 100ms)
ensures that the overhead of spawning workers is negligible.
Setting ``kill_workers=True`` makes it possible to forcibly interrupt
previously spawned jobs to get a new instance of the reusable executor
with new constructor argument values.
The ``job_reducers`` and ``result_reducers`` are used to customize the
pickling of tasks and results send to the executor.
When provided, the ``initializer`` is run first in newly spawned
processes with argument ``initargs``.
|
loky/reusable_executor.py
|
def get_reusable_executor(max_workers=None, context=None, timeout=10,
kill_workers=False, reuse="auto",
job_reducers=None, result_reducers=None,
initializer=None, initargs=()):
"""Return the current ReusableExectutor instance.
Start a new instance if it has not been started already or if the previous
instance was left in a broken state.
If the previous instance does not have the requested number of workers, the
executor is dynamically resized to adjust the number of workers prior to
returning.
Reusing a singleton instance spares the overhead of starting new worker
processes and importing common python packages each time.
``max_workers`` controls the maximum number of tasks that can be running in
parallel in worker processes. By default this is set to the number of
CPUs on the host.
Setting ``timeout`` (in seconds) makes idle workers automatically shutdown
so as to release system resources. New workers are respawn upon submission
of new tasks so that ``max_workers`` are available to accept the newly
submitted tasks. Setting ``timeout`` to around 100 times the time required
to spawn new processes and import packages in them (on the order of 100ms)
ensures that the overhead of spawning workers is negligible.
Setting ``kill_workers=True`` makes it possible to forcibly interrupt
previously spawned jobs to get a new instance of the reusable executor
with new constructor argument values.
The ``job_reducers`` and ``result_reducers`` are used to customize the
pickling of tasks and results send to the executor.
When provided, the ``initializer`` is run first in newly spawned
processes with argument ``initargs``.
"""
with _executor_lock:
global _executor, _executor_kwargs
executor = _executor
if max_workers is None:
if reuse is True and executor is not None:
max_workers = executor._max_workers
else:
max_workers = cpu_count()
elif max_workers <= 0:
raise ValueError(
"max_workers must be greater than 0, got {}."
.format(max_workers))
if isinstance(context, STRING_TYPE):
context = get_context(context)
if context is not None and context.get_start_method() == "fork":
raise ValueError("Cannot use reusable executor with the 'fork' "
"context")
kwargs = dict(context=context, timeout=timeout,
job_reducers=job_reducers,
result_reducers=result_reducers,
initializer=initializer, initargs=initargs)
if executor is None:
mp.util.debug("Create a executor with max_workers={}."
.format(max_workers))
executor_id = _get_next_executor_id()
_executor_kwargs = kwargs
_executor = executor = _ReusablePoolExecutor(
_executor_lock, max_workers=max_workers,
executor_id=executor_id, **kwargs)
else:
if reuse == 'auto':
reuse = kwargs == _executor_kwargs
if (executor._flags.broken or executor._flags.shutdown
or not reuse):
if executor._flags.broken:
reason = "broken"
elif executor._flags.shutdown:
reason = "shutdown"
else:
reason = "arguments have changed"
mp.util.debug(
"Creating a new executor with max_workers={} as the "
"previous instance cannot be reused ({})."
.format(max_workers, reason))
executor.shutdown(wait=True, kill_workers=kill_workers)
_executor = executor = _executor_kwargs = None
# Recursive call to build a new instance
return get_reusable_executor(max_workers=max_workers,
**kwargs)
else:
mp.util.debug("Reusing existing executor with max_workers={}."
.format(executor._max_workers))
executor._resize(max_workers)
return executor
|
def get_reusable_executor(max_workers=None, context=None, timeout=10,
kill_workers=False, reuse="auto",
job_reducers=None, result_reducers=None,
initializer=None, initargs=()):
"""Return the current ReusableExectutor instance.
Start a new instance if it has not been started already or if the previous
instance was left in a broken state.
If the previous instance does not have the requested number of workers, the
executor is dynamically resized to adjust the number of workers prior to
returning.
Reusing a singleton instance spares the overhead of starting new worker
processes and importing common python packages each time.
``max_workers`` controls the maximum number of tasks that can be running in
parallel in worker processes. By default this is set to the number of
CPUs on the host.
Setting ``timeout`` (in seconds) makes idle workers automatically shutdown
so as to release system resources. New workers are respawn upon submission
of new tasks so that ``max_workers`` are available to accept the newly
submitted tasks. Setting ``timeout`` to around 100 times the time required
to spawn new processes and import packages in them (on the order of 100ms)
ensures that the overhead of spawning workers is negligible.
Setting ``kill_workers=True`` makes it possible to forcibly interrupt
previously spawned jobs to get a new instance of the reusable executor
with new constructor argument values.
The ``job_reducers`` and ``result_reducers`` are used to customize the
pickling of tasks and results send to the executor.
When provided, the ``initializer`` is run first in newly spawned
processes with argument ``initargs``.
"""
with _executor_lock:
global _executor, _executor_kwargs
executor = _executor
if max_workers is None:
if reuse is True and executor is not None:
max_workers = executor._max_workers
else:
max_workers = cpu_count()
elif max_workers <= 0:
raise ValueError(
"max_workers must be greater than 0, got {}."
.format(max_workers))
if isinstance(context, STRING_TYPE):
context = get_context(context)
if context is not None and context.get_start_method() == "fork":
raise ValueError("Cannot use reusable executor with the 'fork' "
"context")
kwargs = dict(context=context, timeout=timeout,
job_reducers=job_reducers,
result_reducers=result_reducers,
initializer=initializer, initargs=initargs)
if executor is None:
mp.util.debug("Create a executor with max_workers={}."
.format(max_workers))
executor_id = _get_next_executor_id()
_executor_kwargs = kwargs
_executor = executor = _ReusablePoolExecutor(
_executor_lock, max_workers=max_workers,
executor_id=executor_id, **kwargs)
else:
if reuse == 'auto':
reuse = kwargs == _executor_kwargs
if (executor._flags.broken or executor._flags.shutdown
or not reuse):
if executor._flags.broken:
reason = "broken"
elif executor._flags.shutdown:
reason = "shutdown"
else:
reason = "arguments have changed"
mp.util.debug(
"Creating a new executor with max_workers={} as the "
"previous instance cannot be reused ({})."
.format(max_workers, reason))
executor.shutdown(wait=True, kill_workers=kill_workers)
_executor = executor = _executor_kwargs = None
# Recursive call to build a new instance
return get_reusable_executor(max_workers=max_workers,
**kwargs)
else:
mp.util.debug("Reusing existing executor with max_workers={}."
.format(executor._max_workers))
executor._resize(max_workers)
return executor
|
[
"Return",
"the",
"current",
"ReusableExectutor",
"instance",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/reusable_executor.py#L40-L134
|
[
"def",
"get_reusable_executor",
"(",
"max_workers",
"=",
"None",
",",
"context",
"=",
"None",
",",
"timeout",
"=",
"10",
",",
"kill_workers",
"=",
"False",
",",
"reuse",
"=",
"\"auto\"",
",",
"job_reducers",
"=",
"None",
",",
"result_reducers",
"=",
"None",
",",
"initializer",
"=",
"None",
",",
"initargs",
"=",
"(",
")",
")",
":",
"with",
"_executor_lock",
":",
"global",
"_executor",
",",
"_executor_kwargs",
"executor",
"=",
"_executor",
"if",
"max_workers",
"is",
"None",
":",
"if",
"reuse",
"is",
"True",
"and",
"executor",
"is",
"not",
"None",
":",
"max_workers",
"=",
"executor",
".",
"_max_workers",
"else",
":",
"max_workers",
"=",
"cpu_count",
"(",
")",
"elif",
"max_workers",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"\"max_workers must be greater than 0, got {}.\"",
".",
"format",
"(",
"max_workers",
")",
")",
"if",
"isinstance",
"(",
"context",
",",
"STRING_TYPE",
")",
":",
"context",
"=",
"get_context",
"(",
"context",
")",
"if",
"context",
"is",
"not",
"None",
"and",
"context",
".",
"get_start_method",
"(",
")",
"==",
"\"fork\"",
":",
"raise",
"ValueError",
"(",
"\"Cannot use reusable executor with the 'fork' \"",
"\"context\"",
")",
"kwargs",
"=",
"dict",
"(",
"context",
"=",
"context",
",",
"timeout",
"=",
"timeout",
",",
"job_reducers",
"=",
"job_reducers",
",",
"result_reducers",
"=",
"result_reducers",
",",
"initializer",
"=",
"initializer",
",",
"initargs",
"=",
"initargs",
")",
"if",
"executor",
"is",
"None",
":",
"mp",
".",
"util",
".",
"debug",
"(",
"\"Create a executor with max_workers={}.\"",
".",
"format",
"(",
"max_workers",
")",
")",
"executor_id",
"=",
"_get_next_executor_id",
"(",
")",
"_executor_kwargs",
"=",
"kwargs",
"_executor",
"=",
"executor",
"=",
"_ReusablePoolExecutor",
"(",
"_executor_lock",
",",
"max_workers",
"=",
"max_workers",
",",
"executor_id",
"=",
"executor_id",
",",
"*",
"*",
"kwargs",
")",
"else",
":",
"if",
"reuse",
"==",
"'auto'",
":",
"reuse",
"=",
"kwargs",
"==",
"_executor_kwargs",
"if",
"(",
"executor",
".",
"_flags",
".",
"broken",
"or",
"executor",
".",
"_flags",
".",
"shutdown",
"or",
"not",
"reuse",
")",
":",
"if",
"executor",
".",
"_flags",
".",
"broken",
":",
"reason",
"=",
"\"broken\"",
"elif",
"executor",
".",
"_flags",
".",
"shutdown",
":",
"reason",
"=",
"\"shutdown\"",
"else",
":",
"reason",
"=",
"\"arguments have changed\"",
"mp",
".",
"util",
".",
"debug",
"(",
"\"Creating a new executor with max_workers={} as the \"",
"\"previous instance cannot be reused ({}).\"",
".",
"format",
"(",
"max_workers",
",",
"reason",
")",
")",
"executor",
".",
"shutdown",
"(",
"wait",
"=",
"True",
",",
"kill_workers",
"=",
"kill_workers",
")",
"_executor",
"=",
"executor",
"=",
"_executor_kwargs",
"=",
"None",
"# Recursive call to build a new instance",
"return",
"get_reusable_executor",
"(",
"max_workers",
"=",
"max_workers",
",",
"*",
"*",
"kwargs",
")",
"else",
":",
"mp",
".",
"util",
".",
"debug",
"(",
"\"Reusing existing executor with max_workers={}.\"",
".",
"format",
"(",
"executor",
".",
"_max_workers",
")",
")",
"executor",
".",
"_resize",
"(",
"max_workers",
")",
"return",
"executor"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
_ReusablePoolExecutor._wait_job_completion
|
Wait for the cache to be empty before resizing the pool.
|
loky/reusable_executor.py
|
def _wait_job_completion(self):
"""Wait for the cache to be empty before resizing the pool."""
# Issue a warning to the user about the bad effect of this usage.
if len(self._pending_work_items) > 0:
warnings.warn("Trying to resize an executor with running jobs: "
"waiting for jobs completion before resizing.",
UserWarning)
mp.util.debug("Executor {} waiting for jobs completion before"
" resizing".format(self.executor_id))
# Wait for the completion of the jobs
while len(self._pending_work_items) > 0:
time.sleep(1e-3)
|
def _wait_job_completion(self):
"""Wait for the cache to be empty before resizing the pool."""
# Issue a warning to the user about the bad effect of this usage.
if len(self._pending_work_items) > 0:
warnings.warn("Trying to resize an executor with running jobs: "
"waiting for jobs completion before resizing.",
UserWarning)
mp.util.debug("Executor {} waiting for jobs completion before"
" resizing".format(self.executor_id))
# Wait for the completion of the jobs
while len(self._pending_work_items) > 0:
time.sleep(1e-3)
|
[
"Wait",
"for",
"the",
"cache",
"to",
"be",
"empty",
"before",
"resizing",
"the",
"pool",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/reusable_executor.py#L187-L198
|
[
"def",
"_wait_job_completion",
"(",
"self",
")",
":",
"# Issue a warning to the user about the bad effect of this usage.",
"if",
"len",
"(",
"self",
".",
"_pending_work_items",
")",
">",
"0",
":",
"warnings",
".",
"warn",
"(",
"\"Trying to resize an executor with running jobs: \"",
"\"waiting for jobs completion before resizing.\"",
",",
"UserWarning",
")",
"mp",
".",
"util",
".",
"debug",
"(",
"\"Executor {} waiting for jobs completion before\"",
"\" resizing\"",
".",
"format",
"(",
"self",
".",
"executor_id",
")",
")",
"# Wait for the completion of the jobs",
"while",
"len",
"(",
"self",
".",
"_pending_work_items",
")",
">",
"0",
":",
"time",
".",
"sleep",
"(",
"1e-3",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
get_preparation_data
|
Return info about parent needed by child to unpickle process object
|
loky/backend/spawn.py
|
def get_preparation_data(name, init_main_module=True):
'''
Return info about parent needed by child to unpickle process object
'''
_check_not_importing_main()
d = dict(
log_to_stderr=util._log_to_stderr,
authkey=bytes(process.current_process().authkey),
)
if util._logger is not None:
d['log_level'] = util._logger.getEffectiveLevel()
if len(util._logger.handlers) > 0:
h = util._logger.handlers[0]
d['log_fmt'] = h.formatter._fmt
sys_path = [p for p in sys.path]
try:
i = sys_path.index('')
except ValueError:
pass
else:
sys_path[i] = process.ORIGINAL_DIR
d.update(
name=name,
sys_path=sys_path,
sys_argv=sys.argv,
orig_dir=process.ORIGINAL_DIR,
dir=os.getcwd()
)
if sys.platform != "win32":
# Pass the semaphore_tracker pid to avoid re-spawning it in every child
from . import semaphore_tracker
semaphore_tracker.ensure_running()
d['tracker_pid'] = semaphore_tracker._semaphore_tracker._pid
# Figure out whether to initialise main in the subprocess as a module
# or through direct execution (or to leave it alone entirely)
if init_main_module:
main_module = sys.modules['__main__']
try:
main_mod_name = getattr(main_module.__spec__, "name", None)
except BaseException:
main_mod_name = None
if main_mod_name is not None:
d['init_main_from_name'] = main_mod_name
elif sys.platform != 'win32' or (not WINEXE and not WINSERVICE):
main_path = getattr(main_module, '__file__', None)
if main_path is not None:
if (not os.path.isabs(main_path) and
process.ORIGINAL_DIR is not None):
main_path = os.path.join(process.ORIGINAL_DIR, main_path)
d['init_main_from_path'] = os.path.normpath(main_path)
# Compat for python2.7
d['main_path'] = d['init_main_from_path']
return d
|
def get_preparation_data(name, init_main_module=True):
'''
Return info about parent needed by child to unpickle process object
'''
_check_not_importing_main()
d = dict(
log_to_stderr=util._log_to_stderr,
authkey=bytes(process.current_process().authkey),
)
if util._logger is not None:
d['log_level'] = util._logger.getEffectiveLevel()
if len(util._logger.handlers) > 0:
h = util._logger.handlers[0]
d['log_fmt'] = h.formatter._fmt
sys_path = [p for p in sys.path]
try:
i = sys_path.index('')
except ValueError:
pass
else:
sys_path[i] = process.ORIGINAL_DIR
d.update(
name=name,
sys_path=sys_path,
sys_argv=sys.argv,
orig_dir=process.ORIGINAL_DIR,
dir=os.getcwd()
)
if sys.platform != "win32":
# Pass the semaphore_tracker pid to avoid re-spawning it in every child
from . import semaphore_tracker
semaphore_tracker.ensure_running()
d['tracker_pid'] = semaphore_tracker._semaphore_tracker._pid
# Figure out whether to initialise main in the subprocess as a module
# or through direct execution (or to leave it alone entirely)
if init_main_module:
main_module = sys.modules['__main__']
try:
main_mod_name = getattr(main_module.__spec__, "name", None)
except BaseException:
main_mod_name = None
if main_mod_name is not None:
d['init_main_from_name'] = main_mod_name
elif sys.platform != 'win32' or (not WINEXE and not WINSERVICE):
main_path = getattr(main_module, '__file__', None)
if main_path is not None:
if (not os.path.isabs(main_path) and
process.ORIGINAL_DIR is not None):
main_path = os.path.join(process.ORIGINAL_DIR, main_path)
d['init_main_from_path'] = os.path.normpath(main_path)
# Compat for python2.7
d['main_path'] = d['init_main_from_path']
return d
|
[
"Return",
"info",
"about",
"parent",
"needed",
"by",
"child",
"to",
"unpickle",
"process",
"object"
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/spawn.py#L53-L111
|
[
"def",
"get_preparation_data",
"(",
"name",
",",
"init_main_module",
"=",
"True",
")",
":",
"_check_not_importing_main",
"(",
")",
"d",
"=",
"dict",
"(",
"log_to_stderr",
"=",
"util",
".",
"_log_to_stderr",
",",
"authkey",
"=",
"bytes",
"(",
"process",
".",
"current_process",
"(",
")",
".",
"authkey",
")",
",",
")",
"if",
"util",
".",
"_logger",
"is",
"not",
"None",
":",
"d",
"[",
"'log_level'",
"]",
"=",
"util",
".",
"_logger",
".",
"getEffectiveLevel",
"(",
")",
"if",
"len",
"(",
"util",
".",
"_logger",
".",
"handlers",
")",
">",
"0",
":",
"h",
"=",
"util",
".",
"_logger",
".",
"handlers",
"[",
"0",
"]",
"d",
"[",
"'log_fmt'",
"]",
"=",
"h",
".",
"formatter",
".",
"_fmt",
"sys_path",
"=",
"[",
"p",
"for",
"p",
"in",
"sys",
".",
"path",
"]",
"try",
":",
"i",
"=",
"sys_path",
".",
"index",
"(",
"''",
")",
"except",
"ValueError",
":",
"pass",
"else",
":",
"sys_path",
"[",
"i",
"]",
"=",
"process",
".",
"ORIGINAL_DIR",
"d",
".",
"update",
"(",
"name",
"=",
"name",
",",
"sys_path",
"=",
"sys_path",
",",
"sys_argv",
"=",
"sys",
".",
"argv",
",",
"orig_dir",
"=",
"process",
".",
"ORIGINAL_DIR",
",",
"dir",
"=",
"os",
".",
"getcwd",
"(",
")",
")",
"if",
"sys",
".",
"platform",
"!=",
"\"win32\"",
":",
"# Pass the semaphore_tracker pid to avoid re-spawning it in every child",
"from",
".",
"import",
"semaphore_tracker",
"semaphore_tracker",
".",
"ensure_running",
"(",
")",
"d",
"[",
"'tracker_pid'",
"]",
"=",
"semaphore_tracker",
".",
"_semaphore_tracker",
".",
"_pid",
"# Figure out whether to initialise main in the subprocess as a module",
"# or through direct execution (or to leave it alone entirely)",
"if",
"init_main_module",
":",
"main_module",
"=",
"sys",
".",
"modules",
"[",
"'__main__'",
"]",
"try",
":",
"main_mod_name",
"=",
"getattr",
"(",
"main_module",
".",
"__spec__",
",",
"\"name\"",
",",
"None",
")",
"except",
"BaseException",
":",
"main_mod_name",
"=",
"None",
"if",
"main_mod_name",
"is",
"not",
"None",
":",
"d",
"[",
"'init_main_from_name'",
"]",
"=",
"main_mod_name",
"elif",
"sys",
".",
"platform",
"!=",
"'win32'",
"or",
"(",
"not",
"WINEXE",
"and",
"not",
"WINSERVICE",
")",
":",
"main_path",
"=",
"getattr",
"(",
"main_module",
",",
"'__file__'",
",",
"None",
")",
"if",
"main_path",
"is",
"not",
"None",
":",
"if",
"(",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"main_path",
")",
"and",
"process",
".",
"ORIGINAL_DIR",
"is",
"not",
"None",
")",
":",
"main_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"process",
".",
"ORIGINAL_DIR",
",",
"main_path",
")",
"d",
"[",
"'init_main_from_path'",
"]",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"main_path",
")",
"# Compat for python2.7",
"d",
"[",
"'main_path'",
"]",
"=",
"d",
"[",
"'init_main_from_path'",
"]",
"return",
"d"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
prepare
|
Try to get current process ready to unpickle process object
|
loky/backend/spawn.py
|
def prepare(data):
'''
Try to get current process ready to unpickle process object
'''
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process().authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'log_fmt' in data:
import logging
util.get_logger().handlers[0].setFormatter(
logging.Formatter(data['log_fmt'])
)
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if 'tracker_pid' in data:
from . import semaphore_tracker
semaphore_tracker._semaphore_tracker._pid = data["tracker_pid"]
if 'init_main_from_name' in data:
_fixup_main_from_name(data['init_main_from_name'])
elif 'init_main_from_path' in data:
_fixup_main_from_path(data['init_main_from_path'])
|
def prepare(data):
'''
Try to get current process ready to unpickle process object
'''
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process().authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'log_fmt' in data:
import logging
util.get_logger().handlers[0].setFormatter(
logging.Formatter(data['log_fmt'])
)
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if 'tracker_pid' in data:
from . import semaphore_tracker
semaphore_tracker._semaphore_tracker._pid = data["tracker_pid"]
if 'init_main_from_name' in data:
_fixup_main_from_name(data['init_main_from_name'])
elif 'init_main_from_path' in data:
_fixup_main_from_path(data['init_main_from_path'])
|
[
"Try",
"to",
"get",
"current",
"process",
"ready",
"to",
"unpickle",
"process",
"object"
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/spawn.py#L120-L161
|
[
"def",
"prepare",
"(",
"data",
")",
":",
"if",
"'name'",
"in",
"data",
":",
"process",
".",
"current_process",
"(",
")",
".",
"name",
"=",
"data",
"[",
"'name'",
"]",
"if",
"'authkey'",
"in",
"data",
":",
"process",
".",
"current_process",
"(",
")",
".",
"authkey",
"=",
"data",
"[",
"'authkey'",
"]",
"if",
"'log_to_stderr'",
"in",
"data",
"and",
"data",
"[",
"'log_to_stderr'",
"]",
":",
"util",
".",
"log_to_stderr",
"(",
")",
"if",
"'log_level'",
"in",
"data",
":",
"util",
".",
"get_logger",
"(",
")",
".",
"setLevel",
"(",
"data",
"[",
"'log_level'",
"]",
")",
"if",
"'log_fmt'",
"in",
"data",
":",
"import",
"logging",
"util",
".",
"get_logger",
"(",
")",
".",
"handlers",
"[",
"0",
"]",
".",
"setFormatter",
"(",
"logging",
".",
"Formatter",
"(",
"data",
"[",
"'log_fmt'",
"]",
")",
")",
"if",
"'sys_path'",
"in",
"data",
":",
"sys",
".",
"path",
"=",
"data",
"[",
"'sys_path'",
"]",
"if",
"'sys_argv'",
"in",
"data",
":",
"sys",
".",
"argv",
"=",
"data",
"[",
"'sys_argv'",
"]",
"if",
"'dir'",
"in",
"data",
":",
"os",
".",
"chdir",
"(",
"data",
"[",
"'dir'",
"]",
")",
"if",
"'orig_dir'",
"in",
"data",
":",
"process",
".",
"ORIGINAL_DIR",
"=",
"data",
"[",
"'orig_dir'",
"]",
"if",
"'tracker_pid'",
"in",
"data",
":",
"from",
".",
"import",
"semaphore_tracker",
"semaphore_tracker",
".",
"_semaphore_tracker",
".",
"_pid",
"=",
"data",
"[",
"\"tracker_pid\"",
"]",
"if",
"'init_main_from_name'",
"in",
"data",
":",
"_fixup_main_from_name",
"(",
"data",
"[",
"'init_main_from_name'",
"]",
")",
"elif",
"'init_main_from_path'",
"in",
"data",
":",
"_fixup_main_from_path",
"(",
"data",
"[",
"'init_main_from_path'",
"]",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
wait
|
Wait till an object in object_list is ready/readable.
Returns list of those objects which are ready/readable.
|
loky/backend/_posix_wait.py
|
def wait(object_list, timeout=None):
'''
Wait till an object in object_list is ready/readable.
Returns list of those objects which are ready/readable.
'''
if timeout is not None:
if timeout <= 0:
return _poll(object_list, 0)
else:
deadline = monotonic() + timeout
while True:
try:
return _poll(object_list, timeout)
except (OSError, IOError, socket.error) as e: # pragma: no cover
if e.errno != errno.EINTR:
raise
if timeout is not None:
timeout = deadline - monotonic()
|
def wait(object_list, timeout=None):
'''
Wait till an object in object_list is ready/readable.
Returns list of those objects which are ready/readable.
'''
if timeout is not None:
if timeout <= 0:
return _poll(object_list, 0)
else:
deadline = monotonic() + timeout
while True:
try:
return _poll(object_list, timeout)
except (OSError, IOError, socket.error) as e: # pragma: no cover
if e.errno != errno.EINTR:
raise
if timeout is not None:
timeout = deadline - monotonic()
|
[
"Wait",
"till",
"an",
"object",
"in",
"object_list",
"is",
"ready",
"/",
"readable",
".",
"Returns",
"list",
"of",
"those",
"objects",
"which",
"are",
"ready",
"/",
"readable",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/_posix_wait.py#L88-L105
|
[
"def",
"wait",
"(",
"object_list",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"not",
"None",
":",
"if",
"timeout",
"<=",
"0",
":",
"return",
"_poll",
"(",
"object_list",
",",
"0",
")",
"else",
":",
"deadline",
"=",
"monotonic",
"(",
")",
"+",
"timeout",
"while",
"True",
":",
"try",
":",
"return",
"_poll",
"(",
"object_list",
",",
"timeout",
")",
"except",
"(",
"OSError",
",",
"IOError",
",",
"socket",
".",
"error",
")",
"as",
"e",
":",
"# pragma: no cover",
"if",
"e",
".",
"errno",
"!=",
"errno",
".",
"EINTR",
":",
"raise",
"if",
"timeout",
"is",
"not",
"None",
":",
"timeout",
"=",
"deadline",
"-",
"monotonic",
"(",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
close_fds
|
Close all the file descriptors except those in keep_fds.
|
loky/backend/fork_exec.py
|
def close_fds(keep_fds): # pragma: no cover
"""Close all the file descriptors except those in keep_fds."""
# Make sure to keep stdout and stderr open for logging purpose
keep_fds = set(keep_fds).union([1, 2])
# We try to retrieve all the open fds
try:
open_fds = set(int(fd) for fd in os.listdir('/proc/self/fd'))
except FileNotFoundError:
import resource
max_nfds = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
open_fds = set(fd for fd in range(3, max_nfds))
open_fds.add(0)
for i in open_fds - keep_fds:
try:
os.close(i)
except OSError:
pass
|
def close_fds(keep_fds): # pragma: no cover
"""Close all the file descriptors except those in keep_fds."""
# Make sure to keep stdout and stderr open for logging purpose
keep_fds = set(keep_fds).union([1, 2])
# We try to retrieve all the open fds
try:
open_fds = set(int(fd) for fd in os.listdir('/proc/self/fd'))
except FileNotFoundError:
import resource
max_nfds = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
open_fds = set(fd for fd in range(3, max_nfds))
open_fds.add(0)
for i in open_fds - keep_fds:
try:
os.close(i)
except OSError:
pass
|
[
"Close",
"all",
"the",
"file",
"descriptors",
"except",
"those",
"in",
"keep_fds",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/fork_exec.py#L14-L33
|
[
"def",
"close_fds",
"(",
"keep_fds",
")",
":",
"# pragma: no cover",
"# Make sure to keep stdout and stderr open for logging purpose",
"keep_fds",
"=",
"set",
"(",
"keep_fds",
")",
".",
"union",
"(",
"[",
"1",
",",
"2",
"]",
")",
"# We try to retrieve all the open fds",
"try",
":",
"open_fds",
"=",
"set",
"(",
"int",
"(",
"fd",
")",
"for",
"fd",
"in",
"os",
".",
"listdir",
"(",
"'/proc/self/fd'",
")",
")",
"except",
"FileNotFoundError",
":",
"import",
"resource",
"max_nfds",
"=",
"resource",
".",
"getrlimit",
"(",
"resource",
".",
"RLIMIT_NOFILE",
")",
"[",
"0",
"]",
"open_fds",
"=",
"set",
"(",
"fd",
"for",
"fd",
"in",
"range",
"(",
"3",
",",
"max_nfds",
")",
")",
"open_fds",
".",
"add",
"(",
"0",
")",
"for",
"i",
"in",
"open_fds",
"-",
"keep_fds",
":",
"try",
":",
"os",
".",
"close",
"(",
"i",
")",
"except",
"OSError",
":",
"pass"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
_recursive_terminate_without_psutil
|
Terminate a process and its descendants.
|
loky/backend/utils.py
|
def _recursive_terminate_without_psutil(process):
"""Terminate a process and its descendants.
"""
try:
_recursive_terminate(process.pid)
except OSError as e:
warnings.warn("Failed to kill subprocesses on this platform. Please"
"install psutil: https://github.com/giampaolo/psutil")
# In case we cannot introspect the children, we fall back to the
# classic Process.terminate.
process.terminate()
process.join()
|
def _recursive_terminate_without_psutil(process):
"""Terminate a process and its descendants.
"""
try:
_recursive_terminate(process.pid)
except OSError as e:
warnings.warn("Failed to kill subprocesses on this platform. Please"
"install psutil: https://github.com/giampaolo/psutil")
# In case we cannot introspect the children, we fall back to the
# classic Process.terminate.
process.terminate()
process.join()
|
[
"Terminate",
"a",
"process",
"and",
"its",
"descendants",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/utils.py#L49-L60
|
[
"def",
"_recursive_terminate_without_psutil",
"(",
"process",
")",
":",
"try",
":",
"_recursive_terminate",
"(",
"process",
".",
"pid",
")",
"except",
"OSError",
"as",
"e",
":",
"warnings",
".",
"warn",
"(",
"\"Failed to kill subprocesses on this platform. Please\"",
"\"install psutil: https://github.com/giampaolo/psutil\"",
")",
"# In case we cannot introspect the children, we fall back to the",
"# classic Process.terminate.",
"process",
".",
"terminate",
"(",
")",
"process",
".",
"join",
"(",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
_recursive_terminate
|
Recursively kill the descendants of a process before killing it.
|
loky/backend/utils.py
|
def _recursive_terminate(pid):
"""Recursively kill the descendants of a process before killing it.
"""
if sys.platform == "win32":
# On windows, the taskkill function with option `/T` terminate a given
# process pid and its children.
try:
subprocess.check_output(
["taskkill", "/F", "/T", "/PID", str(pid)],
stderr=None)
except subprocess.CalledProcessError as e:
# In windows, taskkill return 1 for permission denied and 128, 255
# for no process found.
if e.returncode not in [1, 128, 255]:
raise
elif e.returncode == 1:
# Try to kill the process without its descendants if taskkill
# was denied permission. If this fails too, with an error
# different from process not found, let the top level function
# raise a warning and retry to kill the process.
try:
os.kill(pid, signal.SIGTERM)
except OSError as e:
if e.errno != errno.ESRCH:
raise
else:
try:
children_pids = subprocess.check_output(
["pgrep", "-P", str(pid)],
stderr=None
)
except subprocess.CalledProcessError as e:
# `ps` returns 1 when no child process has been found
if e.returncode == 1:
children_pids = b''
else:
raise
# Decode the result, split the cpid and remove the trailing line
children_pids = children_pids.decode().split('\n')[:-1]
for cpid in children_pids:
cpid = int(cpid)
_recursive_terminate(cpid)
try:
os.kill(pid, signal.SIGTERM)
except OSError as e:
# if OSError is raised with [Errno 3] no such process, the process
# is already terminated, else, raise the error and let the top
# level function raise a warning and retry to kill the process.
if e.errno != errno.ESRCH:
raise
|
def _recursive_terminate(pid):
"""Recursively kill the descendants of a process before killing it.
"""
if sys.platform == "win32":
# On windows, the taskkill function with option `/T` terminate a given
# process pid and its children.
try:
subprocess.check_output(
["taskkill", "/F", "/T", "/PID", str(pid)],
stderr=None)
except subprocess.CalledProcessError as e:
# In windows, taskkill return 1 for permission denied and 128, 255
# for no process found.
if e.returncode not in [1, 128, 255]:
raise
elif e.returncode == 1:
# Try to kill the process without its descendants if taskkill
# was denied permission. If this fails too, with an error
# different from process not found, let the top level function
# raise a warning and retry to kill the process.
try:
os.kill(pid, signal.SIGTERM)
except OSError as e:
if e.errno != errno.ESRCH:
raise
else:
try:
children_pids = subprocess.check_output(
["pgrep", "-P", str(pid)],
stderr=None
)
except subprocess.CalledProcessError as e:
# `ps` returns 1 when no child process has been found
if e.returncode == 1:
children_pids = b''
else:
raise
# Decode the result, split the cpid and remove the trailing line
children_pids = children_pids.decode().split('\n')[:-1]
for cpid in children_pids:
cpid = int(cpid)
_recursive_terminate(cpid)
try:
os.kill(pid, signal.SIGTERM)
except OSError as e:
# if OSError is raised with [Errno 3] no such process, the process
# is already terminated, else, raise the error and let the top
# level function raise a warning and retry to kill the process.
if e.errno != errno.ESRCH:
raise
|
[
"Recursively",
"kill",
"the",
"descendants",
"of",
"a",
"process",
"before",
"killing",
"it",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/utils.py#L63-L116
|
[
"def",
"_recursive_terminate",
"(",
"pid",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"\"win32\"",
":",
"# On windows, the taskkill function with option `/T` terminate a given",
"# process pid and its children.",
"try",
":",
"subprocess",
".",
"check_output",
"(",
"[",
"\"taskkill\"",
",",
"\"/F\"",
",",
"\"/T\"",
",",
"\"/PID\"",
",",
"str",
"(",
"pid",
")",
"]",
",",
"stderr",
"=",
"None",
")",
"except",
"subprocess",
".",
"CalledProcessError",
"as",
"e",
":",
"# In windows, taskkill return 1 for permission denied and 128, 255",
"# for no process found.",
"if",
"e",
".",
"returncode",
"not",
"in",
"[",
"1",
",",
"128",
",",
"255",
"]",
":",
"raise",
"elif",
"e",
".",
"returncode",
"==",
"1",
":",
"# Try to kill the process without its descendants if taskkill",
"# was denied permission. If this fails too, with an error",
"# different from process not found, let the top level function",
"# raise a warning and retry to kill the process.",
"try",
":",
"os",
".",
"kill",
"(",
"pid",
",",
"signal",
".",
"SIGTERM",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"!=",
"errno",
".",
"ESRCH",
":",
"raise",
"else",
":",
"try",
":",
"children_pids",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"\"pgrep\"",
",",
"\"-P\"",
",",
"str",
"(",
"pid",
")",
"]",
",",
"stderr",
"=",
"None",
")",
"except",
"subprocess",
".",
"CalledProcessError",
"as",
"e",
":",
"# `ps` returns 1 when no child process has been found",
"if",
"e",
".",
"returncode",
"==",
"1",
":",
"children_pids",
"=",
"b''",
"else",
":",
"raise",
"# Decode the result, split the cpid and remove the trailing line",
"children_pids",
"=",
"children_pids",
".",
"decode",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
"[",
":",
"-",
"1",
"]",
"for",
"cpid",
"in",
"children_pids",
":",
"cpid",
"=",
"int",
"(",
"cpid",
")",
"_recursive_terminate",
"(",
"cpid",
")",
"try",
":",
"os",
".",
"kill",
"(",
"pid",
",",
"signal",
".",
"SIGTERM",
")",
"except",
"OSError",
"as",
"e",
":",
"# if OSError is raised with [Errno 3] no such process, the process",
"# is already terminated, else, raise the error and let the top",
"# level function raise a warning and retry to kill the process.",
"if",
"e",
".",
"errno",
"!=",
"errno",
".",
"ESRCH",
":",
"raise"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
get_exitcodes_terminated_worker
|
Return a formated string with the exitcodes of terminated workers.
If necessary, wait (up to .25s) for the system to correctly set the
exitcode of one terminated worker.
|
loky/backend/utils.py
|
def get_exitcodes_terminated_worker(processes):
"""Return a formated string with the exitcodes of terminated workers.
If necessary, wait (up to .25s) for the system to correctly set the
exitcode of one terminated worker.
"""
patience = 5
# Catch the exitcode of the terminated workers. There should at least be
# one. If not, wait a bit for the system to correctly set the exitcode of
# the terminated worker.
exitcodes = [p.exitcode for p in list(processes.values())
if p.exitcode is not None]
while len(exitcodes) == 0 and patience > 0:
patience -= 1
exitcodes = [p.exitcode for p in list(processes.values())
if p.exitcode is not None]
time.sleep(.05)
return _format_exitcodes(exitcodes)
|
def get_exitcodes_terminated_worker(processes):
"""Return a formated string with the exitcodes of terminated workers.
If necessary, wait (up to .25s) for the system to correctly set the
exitcode of one terminated worker.
"""
patience = 5
# Catch the exitcode of the terminated workers. There should at least be
# one. If not, wait a bit for the system to correctly set the exitcode of
# the terminated worker.
exitcodes = [p.exitcode for p in list(processes.values())
if p.exitcode is not None]
while len(exitcodes) == 0 and patience > 0:
patience -= 1
exitcodes = [p.exitcode for p in list(processes.values())
if p.exitcode is not None]
time.sleep(.05)
return _format_exitcodes(exitcodes)
|
[
"Return",
"a",
"formated",
"string",
"with",
"the",
"exitcodes",
"of",
"terminated",
"workers",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/utils.py#L119-L138
|
[
"def",
"get_exitcodes_terminated_worker",
"(",
"processes",
")",
":",
"patience",
"=",
"5",
"# Catch the exitcode of the terminated workers. There should at least be",
"# one. If not, wait a bit for the system to correctly set the exitcode of",
"# the terminated worker.",
"exitcodes",
"=",
"[",
"p",
".",
"exitcode",
"for",
"p",
"in",
"list",
"(",
"processes",
".",
"values",
"(",
")",
")",
"if",
"p",
".",
"exitcode",
"is",
"not",
"None",
"]",
"while",
"len",
"(",
"exitcodes",
")",
"==",
"0",
"and",
"patience",
">",
"0",
":",
"patience",
"-=",
"1",
"exitcodes",
"=",
"[",
"p",
".",
"exitcode",
"for",
"p",
"in",
"list",
"(",
"processes",
".",
"values",
"(",
")",
")",
"if",
"p",
".",
"exitcode",
"is",
"not",
"None",
"]",
"time",
".",
"sleep",
"(",
".05",
")",
"return",
"_format_exitcodes",
"(",
"exitcodes",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
_format_exitcodes
|
Format a list of exit code with names of the signals if possible
|
loky/backend/utils.py
|
def _format_exitcodes(exitcodes):
"""Format a list of exit code with names of the signals if possible"""
str_exitcodes = ["{}({})".format(_get_exitcode_name(e), e)
for e in exitcodes if e is not None]
return "{" + ", ".join(str_exitcodes) + "}"
|
def _format_exitcodes(exitcodes):
"""Format a list of exit code with names of the signals if possible"""
str_exitcodes = ["{}({})".format(_get_exitcode_name(e), e)
for e in exitcodes if e is not None]
return "{" + ", ".join(str_exitcodes) + "}"
|
[
"Format",
"a",
"list",
"of",
"exit",
"code",
"with",
"names",
"of",
"the",
"signals",
"if",
"possible"
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/utils.py#L141-L145
|
[
"def",
"_format_exitcodes",
"(",
"exitcodes",
")",
":",
"str_exitcodes",
"=",
"[",
"\"{}({})\"",
".",
"format",
"(",
"_get_exitcode_name",
"(",
"e",
")",
",",
"e",
")",
"for",
"e",
"in",
"exitcodes",
"if",
"e",
"is",
"not",
"None",
"]",
"return",
"\"{\"",
"+",
"\", \"",
".",
"join",
"(",
"str_exitcodes",
")",
"+",
"\"}\""
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
main
|
Run semaphore tracker.
|
loky/backend/semaphore_tracker.py
|
def main(fd, verbose=0):
'''Run semaphore tracker.'''
# protect the process from ^C and "killall python" etc
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS)
for f in (sys.stdin, sys.stdout):
try:
f.close()
except Exception:
pass
if verbose: # pragma: no cover
sys.stderr.write("Main semaphore tracker is running\n")
sys.stderr.flush()
cache = set()
try:
# keep track of registered/unregistered semaphores
with os.fdopen(fd, 'rb') as f:
for line in f:
try:
cmd, name = line.strip().split(b':')
if cmd == b'REGISTER':
name = name.decode('ascii')
cache.add(name)
if verbose: # pragma: no cover
sys.stderr.write("[SemaphoreTracker] register {}\n"
.format(name))
sys.stderr.flush()
elif cmd == b'UNREGISTER':
name = name.decode('ascii')
cache.remove(name)
if verbose: # pragma: no cover
sys.stderr.write("[SemaphoreTracker] unregister {}"
": cache({})\n"
.format(name, len(cache)))
sys.stderr.flush()
elif cmd == b'PROBE':
pass
else:
raise RuntimeError('unrecognized command %r' % cmd)
except BaseException:
try:
sys.excepthook(*sys.exc_info())
except BaseException:
pass
finally:
# all processes have terminated; cleanup any remaining semaphores
if cache:
try:
warnings.warn('semaphore_tracker: There appear to be %d '
'leaked semaphores to clean up at shutdown' %
len(cache))
except Exception:
pass
for name in cache:
# For some reason the process which created and registered this
# semaphore has failed to unregister it. Presumably it has died.
# We therefore unlink it.
try:
try:
sem_unlink(name)
if verbose: # pragma: no cover
sys.stderr.write("[SemaphoreTracker] unlink {}\n"
.format(name))
sys.stderr.flush()
except Exception as e:
warnings.warn('semaphore_tracker: %s: %r' % (name, e))
finally:
pass
if verbose: # pragma: no cover
sys.stderr.write("semaphore tracker shut down\n")
sys.stderr.flush()
|
def main(fd, verbose=0):
'''Run semaphore tracker.'''
# protect the process from ^C and "killall python" etc
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS)
for f in (sys.stdin, sys.stdout):
try:
f.close()
except Exception:
pass
if verbose: # pragma: no cover
sys.stderr.write("Main semaphore tracker is running\n")
sys.stderr.flush()
cache = set()
try:
# keep track of registered/unregistered semaphores
with os.fdopen(fd, 'rb') as f:
for line in f:
try:
cmd, name = line.strip().split(b':')
if cmd == b'REGISTER':
name = name.decode('ascii')
cache.add(name)
if verbose: # pragma: no cover
sys.stderr.write("[SemaphoreTracker] register {}\n"
.format(name))
sys.stderr.flush()
elif cmd == b'UNREGISTER':
name = name.decode('ascii')
cache.remove(name)
if verbose: # pragma: no cover
sys.stderr.write("[SemaphoreTracker] unregister {}"
": cache({})\n"
.format(name, len(cache)))
sys.stderr.flush()
elif cmd == b'PROBE':
pass
else:
raise RuntimeError('unrecognized command %r' % cmd)
except BaseException:
try:
sys.excepthook(*sys.exc_info())
except BaseException:
pass
finally:
# all processes have terminated; cleanup any remaining semaphores
if cache:
try:
warnings.warn('semaphore_tracker: There appear to be %d '
'leaked semaphores to clean up at shutdown' %
len(cache))
except Exception:
pass
for name in cache:
# For some reason the process which created and registered this
# semaphore has failed to unregister it. Presumably it has died.
# We therefore unlink it.
try:
try:
sem_unlink(name)
if verbose: # pragma: no cover
sys.stderr.write("[SemaphoreTracker] unlink {}\n"
.format(name))
sys.stderr.flush()
except Exception as e:
warnings.warn('semaphore_tracker: %s: %r' % (name, e))
finally:
pass
if verbose: # pragma: no cover
sys.stderr.write("semaphore tracker shut down\n")
sys.stderr.flush()
|
[
"Run",
"semaphore",
"tracker",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/semaphore_tracker.py#L170-L247
|
[
"def",
"main",
"(",
"fd",
",",
"verbose",
"=",
"0",
")",
":",
"# protect the process from ^C and \"killall python\" etc",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGINT",
",",
"signal",
".",
"SIG_IGN",
")",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGTERM",
",",
"signal",
".",
"SIG_IGN",
")",
"if",
"_HAVE_SIGMASK",
":",
"signal",
".",
"pthread_sigmask",
"(",
"signal",
".",
"SIG_UNBLOCK",
",",
"_IGNORED_SIGNALS",
")",
"for",
"f",
"in",
"(",
"sys",
".",
"stdin",
",",
"sys",
".",
"stdout",
")",
":",
"try",
":",
"f",
".",
"close",
"(",
")",
"except",
"Exception",
":",
"pass",
"if",
"verbose",
":",
"# pragma: no cover",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"Main semaphore tracker is running\\n\"",
")",
"sys",
".",
"stderr",
".",
"flush",
"(",
")",
"cache",
"=",
"set",
"(",
")",
"try",
":",
"# keep track of registered/unregistered semaphores",
"with",
"os",
".",
"fdopen",
"(",
"fd",
",",
"'rb'",
")",
"as",
"f",
":",
"for",
"line",
"in",
"f",
":",
"try",
":",
"cmd",
",",
"name",
"=",
"line",
".",
"strip",
"(",
")",
".",
"split",
"(",
"b':'",
")",
"if",
"cmd",
"==",
"b'REGISTER'",
":",
"name",
"=",
"name",
".",
"decode",
"(",
"'ascii'",
")",
"cache",
".",
"add",
"(",
"name",
")",
"if",
"verbose",
":",
"# pragma: no cover",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"[SemaphoreTracker] register {}\\n\"",
".",
"format",
"(",
"name",
")",
")",
"sys",
".",
"stderr",
".",
"flush",
"(",
")",
"elif",
"cmd",
"==",
"b'UNREGISTER'",
":",
"name",
"=",
"name",
".",
"decode",
"(",
"'ascii'",
")",
"cache",
".",
"remove",
"(",
"name",
")",
"if",
"verbose",
":",
"# pragma: no cover",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"[SemaphoreTracker] unregister {}\"",
"\": cache({})\\n\"",
".",
"format",
"(",
"name",
",",
"len",
"(",
"cache",
")",
")",
")",
"sys",
".",
"stderr",
".",
"flush",
"(",
")",
"elif",
"cmd",
"==",
"b'PROBE'",
":",
"pass",
"else",
":",
"raise",
"RuntimeError",
"(",
"'unrecognized command %r'",
"%",
"cmd",
")",
"except",
"BaseException",
":",
"try",
":",
"sys",
".",
"excepthook",
"(",
"*",
"sys",
".",
"exc_info",
"(",
")",
")",
"except",
"BaseException",
":",
"pass",
"finally",
":",
"# all processes have terminated; cleanup any remaining semaphores",
"if",
"cache",
":",
"try",
":",
"warnings",
".",
"warn",
"(",
"'semaphore_tracker: There appear to be %d '",
"'leaked semaphores to clean up at shutdown'",
"%",
"len",
"(",
"cache",
")",
")",
"except",
"Exception",
":",
"pass",
"for",
"name",
"in",
"cache",
":",
"# For some reason the process which created and registered this",
"# semaphore has failed to unregister it. Presumably it has died.",
"# We therefore unlink it.",
"try",
":",
"try",
":",
"sem_unlink",
"(",
"name",
")",
"if",
"verbose",
":",
"# pragma: no cover",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"[SemaphoreTracker] unlink {}\\n\"",
".",
"format",
"(",
"name",
")",
")",
"sys",
".",
"stderr",
".",
"flush",
"(",
")",
"except",
"Exception",
"as",
"e",
":",
"warnings",
".",
"warn",
"(",
"'semaphore_tracker: %s: %r'",
"%",
"(",
"name",
",",
"e",
")",
")",
"finally",
":",
"pass",
"if",
"verbose",
":",
"# pragma: no cover",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"semaphore tracker shut down\\n\"",
")",
"sys",
".",
"stderr",
".",
"flush",
"(",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
SemaphoreTracker.ensure_running
|
Make sure that semaphore tracker process is running.
This can be run from any process. Usually a child process will use
the semaphore created by its parent.
|
loky/backend/semaphore_tracker.py
|
def ensure_running(self):
'''Make sure that semaphore tracker process is running.
This can be run from any process. Usually a child process will use
the semaphore created by its parent.'''
with self._lock:
if self._fd is not None:
# semaphore tracker was launched before, is it still running?
if self._check_alive():
# => still alive
return
# => dead, launch it again
os.close(self._fd)
try:
# Clean-up to avoid dangling processes.
os.waitpid(self._pid, 0)
except OSError:
# The process was terminated or is a child from an ancestor
# of the current process.
pass
self._fd = None
self._pid = None
warnings.warn('semaphore_tracker: process died unexpectedly, '
'relaunching. Some semaphores might leak.')
fds_to_pass = []
try:
fds_to_pass.append(sys.stderr.fileno())
except Exception:
pass
r, w = os.pipe()
cmd = 'from {} import main; main({}, {})'.format(
main.__module__, r, VERBOSE)
try:
fds_to_pass.append(r)
# process will out live us, so no need to wait on pid
exe = spawn.get_executable()
args = [exe] + util._args_from_interpreter_flags()
# In python 3.3, there is a bug which put `-RRRRR..` instead of
# `-R` in args. Replace it to get the correct flags.
# See https://github.com/python/cpython/blob/3.3/Lib/subprocess.py#L488
if sys.version_info[:2] <= (3, 3):
import re
for i in range(1, len(args)):
args[i] = re.sub("-R+", "-R", args[i])
args += ['-c', cmd]
util.debug("launching Semaphore tracker: {}".format(args))
# bpo-33613: Register a signal mask that will block the
# signals. This signal mask will be inherited by the child
# that is going to be spawned and will protect the child from a
# race condition that can make the child die before it
# registers signal handlers for SIGINT and SIGTERM. The mask is
# unregistered after spawning the child.
try:
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_BLOCK,
_IGNORED_SIGNALS)
pid = spawnv_passfds(exe, args, fds_to_pass)
finally:
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_UNBLOCK,
_IGNORED_SIGNALS)
except BaseException:
os.close(w)
raise
else:
self._fd = w
self._pid = pid
finally:
os.close(r)
|
def ensure_running(self):
'''Make sure that semaphore tracker process is running.
This can be run from any process. Usually a child process will use
the semaphore created by its parent.'''
with self._lock:
if self._fd is not None:
# semaphore tracker was launched before, is it still running?
if self._check_alive():
# => still alive
return
# => dead, launch it again
os.close(self._fd)
try:
# Clean-up to avoid dangling processes.
os.waitpid(self._pid, 0)
except OSError:
# The process was terminated or is a child from an ancestor
# of the current process.
pass
self._fd = None
self._pid = None
warnings.warn('semaphore_tracker: process died unexpectedly, '
'relaunching. Some semaphores might leak.')
fds_to_pass = []
try:
fds_to_pass.append(sys.stderr.fileno())
except Exception:
pass
r, w = os.pipe()
cmd = 'from {} import main; main({}, {})'.format(
main.__module__, r, VERBOSE)
try:
fds_to_pass.append(r)
# process will out live us, so no need to wait on pid
exe = spawn.get_executable()
args = [exe] + util._args_from_interpreter_flags()
# In python 3.3, there is a bug which put `-RRRRR..` instead of
# `-R` in args. Replace it to get the correct flags.
# See https://github.com/python/cpython/blob/3.3/Lib/subprocess.py#L488
if sys.version_info[:2] <= (3, 3):
import re
for i in range(1, len(args)):
args[i] = re.sub("-R+", "-R", args[i])
args += ['-c', cmd]
util.debug("launching Semaphore tracker: {}".format(args))
# bpo-33613: Register a signal mask that will block the
# signals. This signal mask will be inherited by the child
# that is going to be spawned and will protect the child from a
# race condition that can make the child die before it
# registers signal handlers for SIGINT and SIGTERM. The mask is
# unregistered after spawning the child.
try:
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_BLOCK,
_IGNORED_SIGNALS)
pid = spawnv_passfds(exe, args, fds_to_pass)
finally:
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_UNBLOCK,
_IGNORED_SIGNALS)
except BaseException:
os.close(w)
raise
else:
self._fd = w
self._pid = pid
finally:
os.close(r)
|
[
"Make",
"sure",
"that",
"semaphore",
"tracker",
"process",
"is",
"running",
"."
] |
tomMoral/loky
|
python
|
https://github.com/tomMoral/loky/blob/dc2d941d8285a96f3a5b666a4bd04875b0b25984/loky/backend/semaphore_tracker.py#L61-L132
|
[
"def",
"ensure_running",
"(",
"self",
")",
":",
"with",
"self",
".",
"_lock",
":",
"if",
"self",
".",
"_fd",
"is",
"not",
"None",
":",
"# semaphore tracker was launched before, is it still running?",
"if",
"self",
".",
"_check_alive",
"(",
")",
":",
"# => still alive",
"return",
"# => dead, launch it again",
"os",
".",
"close",
"(",
"self",
".",
"_fd",
")",
"try",
":",
"# Clean-up to avoid dangling processes.",
"os",
".",
"waitpid",
"(",
"self",
".",
"_pid",
",",
"0",
")",
"except",
"OSError",
":",
"# The process was terminated or is a child from an ancestor",
"# of the current process.",
"pass",
"self",
".",
"_fd",
"=",
"None",
"self",
".",
"_pid",
"=",
"None",
"warnings",
".",
"warn",
"(",
"'semaphore_tracker: process died unexpectedly, '",
"'relaunching. Some semaphores might leak.'",
")",
"fds_to_pass",
"=",
"[",
"]",
"try",
":",
"fds_to_pass",
".",
"append",
"(",
"sys",
".",
"stderr",
".",
"fileno",
"(",
")",
")",
"except",
"Exception",
":",
"pass",
"r",
",",
"w",
"=",
"os",
".",
"pipe",
"(",
")",
"cmd",
"=",
"'from {} import main; main({}, {})'",
".",
"format",
"(",
"main",
".",
"__module__",
",",
"r",
",",
"VERBOSE",
")",
"try",
":",
"fds_to_pass",
".",
"append",
"(",
"r",
")",
"# process will out live us, so no need to wait on pid",
"exe",
"=",
"spawn",
".",
"get_executable",
"(",
")",
"args",
"=",
"[",
"exe",
"]",
"+",
"util",
".",
"_args_from_interpreter_flags",
"(",
")",
"# In python 3.3, there is a bug which put `-RRRRR..` instead of",
"# `-R` in args. Replace it to get the correct flags.",
"# See https://github.com/python/cpython/blob/3.3/Lib/subprocess.py#L488",
"if",
"sys",
".",
"version_info",
"[",
":",
"2",
"]",
"<=",
"(",
"3",
",",
"3",
")",
":",
"import",
"re",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"args",
")",
")",
":",
"args",
"[",
"i",
"]",
"=",
"re",
".",
"sub",
"(",
"\"-R+\"",
",",
"\"-R\"",
",",
"args",
"[",
"i",
"]",
")",
"args",
"+=",
"[",
"'-c'",
",",
"cmd",
"]",
"util",
".",
"debug",
"(",
"\"launching Semaphore tracker: {}\"",
".",
"format",
"(",
"args",
")",
")",
"# bpo-33613: Register a signal mask that will block the",
"# signals. This signal mask will be inherited by the child",
"# that is going to be spawned and will protect the child from a",
"# race condition that can make the child die before it",
"# registers signal handlers for SIGINT and SIGTERM. The mask is",
"# unregistered after spawning the child.",
"try",
":",
"if",
"_HAVE_SIGMASK",
":",
"signal",
".",
"pthread_sigmask",
"(",
"signal",
".",
"SIG_BLOCK",
",",
"_IGNORED_SIGNALS",
")",
"pid",
"=",
"spawnv_passfds",
"(",
"exe",
",",
"args",
",",
"fds_to_pass",
")",
"finally",
":",
"if",
"_HAVE_SIGMASK",
":",
"signal",
".",
"pthread_sigmask",
"(",
"signal",
".",
"SIG_UNBLOCK",
",",
"_IGNORED_SIGNALS",
")",
"except",
"BaseException",
":",
"os",
".",
"close",
"(",
"w",
")",
"raise",
"else",
":",
"self",
".",
"_fd",
"=",
"w",
"self",
".",
"_pid",
"=",
"pid",
"finally",
":",
"os",
".",
"close",
"(",
"r",
")"
] |
dc2d941d8285a96f3a5b666a4bd04875b0b25984
|
test
|
PrintProcessor.event_processor
|
A simple event processor that prints out events.
|
trepan/processor/trace.py
|
def event_processor(self, frame, event, arg):
'A simple event processor that prints out events.'
out = self.debugger.intf[-1].output
lineno = frame.f_lineno
filename = self.core.canonic_filename(frame)
filename = self.core.filename(filename)
if not out:
print("%s - %s:%d" % (event, filename, lineno))
else:
out.write("%s - %s:%d" % (event, filename, lineno))
if arg is not None:
out.writeline(', %s ' % repr(arg))
else:
out.writeline('')
pass
pass
return self.event_processor
|
def event_processor(self, frame, event, arg):
'A simple event processor that prints out events.'
out = self.debugger.intf[-1].output
lineno = frame.f_lineno
filename = self.core.canonic_filename(frame)
filename = self.core.filename(filename)
if not out:
print("%s - %s:%d" % (event, filename, lineno))
else:
out.write("%s - %s:%d" % (event, filename, lineno))
if arg is not None:
out.writeline(', %s ' % repr(arg))
else:
out.writeline('')
pass
pass
return self.event_processor
|
[
"A",
"simple",
"event",
"processor",
"that",
"prints",
"out",
"events",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/trace.py#L36-L52
|
[
"def",
"event_processor",
"(",
"self",
",",
"frame",
",",
"event",
",",
"arg",
")",
":",
"out",
"=",
"self",
".",
"debugger",
".",
"intf",
"[",
"-",
"1",
"]",
".",
"output",
"lineno",
"=",
"frame",
".",
"f_lineno",
"filename",
"=",
"self",
".",
"core",
".",
"canonic_filename",
"(",
"frame",
")",
"filename",
"=",
"self",
".",
"core",
".",
"filename",
"(",
"filename",
")",
"if",
"not",
"out",
":",
"print",
"(",
"\"%s - %s:%d\"",
"%",
"(",
"event",
",",
"filename",
",",
"lineno",
")",
")",
"else",
":",
"out",
".",
"write",
"(",
"\"%s - %s:%d\"",
"%",
"(",
"event",
",",
"filename",
",",
"lineno",
")",
")",
"if",
"arg",
"is",
"not",
"None",
":",
"out",
".",
"writeline",
"(",
"', %s '",
"%",
"repr",
"(",
"arg",
")",
")",
"else",
":",
"out",
".",
"writeline",
"(",
"''",
")",
"pass",
"pass",
"return",
"self",
".",
"event_processor"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
InfoPC.run
|
Program counter.
|
trepan/processor/command/info_subcmd/pc.py
|
def run(self, args):
"""Program counter."""
mainfile = self.core.filename(None)
if self.core.is_running():
curframe = self.proc.curframe
if curframe:
line_no = inspect.getlineno(curframe)
offset = curframe.f_lasti
self.msg("PC offset is %d." % offset)
offset = max(offset, 0)
code = curframe.f_code
co_code = code.co_code
disassemble_bytes(self.msg, self.msg_nocr,
co_code, offset, line_no, line_no-1, line_no+1,
constants=code.co_consts, cells=code.co_cellvars,
varnames=code.co_varnames, freevars=code.co_freevars,
linestarts=dict(findlinestarts(code)),
end_offset=offset+10)
pass
pass
else:
if mainfile:
part1 = "Python program '%s'" % mainfile
msg = "is not currently running. "
self.msg(Mmisc.wrapped_lines(part1, msg,
self.settings['width']))
else:
self.msg('No Python program is currently running.')
pass
self.msg(self.core.execution_status)
pass
return False
|
def run(self, args):
"""Program counter."""
mainfile = self.core.filename(None)
if self.core.is_running():
curframe = self.proc.curframe
if curframe:
line_no = inspect.getlineno(curframe)
offset = curframe.f_lasti
self.msg("PC offset is %d." % offset)
offset = max(offset, 0)
code = curframe.f_code
co_code = code.co_code
disassemble_bytes(self.msg, self.msg_nocr,
co_code, offset, line_no, line_no-1, line_no+1,
constants=code.co_consts, cells=code.co_cellvars,
varnames=code.co_varnames, freevars=code.co_freevars,
linestarts=dict(findlinestarts(code)),
end_offset=offset+10)
pass
pass
else:
if mainfile:
part1 = "Python program '%s'" % mainfile
msg = "is not currently running. "
self.msg(Mmisc.wrapped_lines(part1, msg,
self.settings['width']))
else:
self.msg('No Python program is currently running.')
pass
self.msg(self.core.execution_status)
pass
return False
|
[
"Program",
"counter",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/command/info_subcmd/pc.py#L42-L73
|
[
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"mainfile",
"=",
"self",
".",
"core",
".",
"filename",
"(",
"None",
")",
"if",
"self",
".",
"core",
".",
"is_running",
"(",
")",
":",
"curframe",
"=",
"self",
".",
"proc",
".",
"curframe",
"if",
"curframe",
":",
"line_no",
"=",
"inspect",
".",
"getlineno",
"(",
"curframe",
")",
"offset",
"=",
"curframe",
".",
"f_lasti",
"self",
".",
"msg",
"(",
"\"PC offset is %d.\"",
"%",
"offset",
")",
"offset",
"=",
"max",
"(",
"offset",
",",
"0",
")",
"code",
"=",
"curframe",
".",
"f_code",
"co_code",
"=",
"code",
".",
"co_code",
"disassemble_bytes",
"(",
"self",
".",
"msg",
",",
"self",
".",
"msg_nocr",
",",
"co_code",
",",
"offset",
",",
"line_no",
",",
"line_no",
"-",
"1",
",",
"line_no",
"+",
"1",
",",
"constants",
"=",
"code",
".",
"co_consts",
",",
"cells",
"=",
"code",
".",
"co_cellvars",
",",
"varnames",
"=",
"code",
".",
"co_varnames",
",",
"freevars",
"=",
"code",
".",
"co_freevars",
",",
"linestarts",
"=",
"dict",
"(",
"findlinestarts",
"(",
"code",
")",
")",
",",
"end_offset",
"=",
"offset",
"+",
"10",
")",
"pass",
"pass",
"else",
":",
"if",
"mainfile",
":",
"part1",
"=",
"\"Python program '%s'\"",
"%",
"mainfile",
"msg",
"=",
"\"is not currently running. \"",
"self",
".",
"msg",
"(",
"Mmisc",
".",
"wrapped_lines",
"(",
"part1",
",",
"msg",
",",
"self",
".",
"settings",
"[",
"'width'",
"]",
")",
")",
"else",
":",
"self",
".",
"msg",
"(",
"'No Python program is currently running.'",
")",
"pass",
"self",
".",
"msg",
"(",
"self",
".",
"core",
".",
"execution_status",
")",
"pass",
"return",
"False"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
interact
|
Almost a copy of code.interact
Closely emulate the interactive Python interpreter.
This is a backwards compatible interface to the InteractiveConsole
class. When readfunc is not specified, it attempts to import the
readline module to enable GNU readline if it is available.
Arguments (all optional, all default to None):
banner -- passed to InteractiveConsole.interact()
readfunc -- if not None, replaces InteractiveConsole.raw_input()
local -- passed to InteractiveInterpreter.__init__()
|
trepan/processor/command/ipython.py
|
def interact(banner=None, readfunc=None, my_locals=None, my_globals=None):
"""Almost a copy of code.interact
Closely emulate the interactive Python interpreter.
This is a backwards compatible interface to the InteractiveConsole
class. When readfunc is not specified, it attempts to import the
readline module to enable GNU readline if it is available.
Arguments (all optional, all default to None):
banner -- passed to InteractiveConsole.interact()
readfunc -- if not None, replaces InteractiveConsole.raw_input()
local -- passed to InteractiveInterpreter.__init__()
"""
console = code.InteractiveConsole(my_locals, filename='<trepan>')
console.runcode = lambda code_obj: runcode(console, code_obj)
setattr(console, 'globals', my_globals)
if readfunc is not None:
console.raw_input = readfunc
else:
try:
import readline
except ImportError:
pass
console.interact(banner)
pass
|
def interact(banner=None, readfunc=None, my_locals=None, my_globals=None):
"""Almost a copy of code.interact
Closely emulate the interactive Python interpreter.
This is a backwards compatible interface to the InteractiveConsole
class. When readfunc is not specified, it attempts to import the
readline module to enable GNU readline if it is available.
Arguments (all optional, all default to None):
banner -- passed to InteractiveConsole.interact()
readfunc -- if not None, replaces InteractiveConsole.raw_input()
local -- passed to InteractiveInterpreter.__init__()
"""
console = code.InteractiveConsole(my_locals, filename='<trepan>')
console.runcode = lambda code_obj: runcode(console, code_obj)
setattr(console, 'globals', my_globals)
if readfunc is not None:
console.raw_input = readfunc
else:
try:
import readline
except ImportError:
pass
console.interact(banner)
pass
|
[
"Almost",
"a",
"copy",
"of",
"code",
".",
"interact",
"Closely",
"emulate",
"the",
"interactive",
"Python",
"interpreter",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/command/ipython.py#L137-L163
|
[
"def",
"interact",
"(",
"banner",
"=",
"None",
",",
"readfunc",
"=",
"None",
",",
"my_locals",
"=",
"None",
",",
"my_globals",
"=",
"None",
")",
":",
"console",
"=",
"code",
".",
"InteractiveConsole",
"(",
"my_locals",
",",
"filename",
"=",
"'<trepan>'",
")",
"console",
".",
"runcode",
"=",
"lambda",
"code_obj",
":",
"runcode",
"(",
"console",
",",
"code_obj",
")",
"setattr",
"(",
"console",
",",
"'globals'",
",",
"my_globals",
")",
"if",
"readfunc",
"is",
"not",
"None",
":",
"console",
".",
"raw_input",
"=",
"readfunc",
"else",
":",
"try",
":",
"import",
"readline",
"except",
"ImportError",
":",
"pass",
"console",
".",
"interact",
"(",
"banner",
")",
"pass"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
runcode
|
Execute a code object.
When an exception occurs, self.showtraceback() is called to
display a traceback. All exceptions are caught except
SystemExit, which is reraised.
A note about KeyboardInterrupt: this exception may occur
elsewhere in this code, and may not always be caught. The
caller should be prepared to deal with it.
|
trepan/processor/command/ipython.py
|
def runcode(obj, code_obj):
"""Execute a code object.
When an exception occurs, self.showtraceback() is called to
display a traceback. All exceptions are caught except
SystemExit, which is reraised.
A note about KeyboardInterrupt: this exception may occur
elsewhere in this code, and may not always be caught. The
caller should be prepared to deal with it.
"""
try:
exec(code_obj, obj.locals, obj.globals)
except SystemExit:
raise
except:
obj.showtraceback()
else:
if code.softspace(sys.stdout, 0):
print()
pass
pass
return
|
def runcode(obj, code_obj):
"""Execute a code object.
When an exception occurs, self.showtraceback() is called to
display a traceback. All exceptions are caught except
SystemExit, which is reraised.
A note about KeyboardInterrupt: this exception may occur
elsewhere in this code, and may not always be caught. The
caller should be prepared to deal with it.
"""
try:
exec(code_obj, obj.locals, obj.globals)
except SystemExit:
raise
except:
obj.showtraceback()
else:
if code.softspace(sys.stdout, 0):
print()
pass
pass
return
|
[
"Execute",
"a",
"code",
"object",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/command/ipython.py#L167-L190
|
[
"def",
"runcode",
"(",
"obj",
",",
"code_obj",
")",
":",
"try",
":",
"exec",
"(",
"code_obj",
",",
"obj",
".",
"locals",
",",
"obj",
".",
"globals",
")",
"except",
"SystemExit",
":",
"raise",
"except",
":",
"obj",
".",
"showtraceback",
"(",
")",
"else",
":",
"if",
"code",
".",
"softspace",
"(",
"sys",
".",
"stdout",
",",
"0",
")",
":",
"print",
"(",
")",
"pass",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
adjust_frame
|
Adjust stack frame by pos positions. If absolute_pos then
pos is an absolute number. Otherwise it is a relative number.
A negative number indexes from the other end.
|
trepan/processor/frame.py
|
def adjust_frame(proc_obj, name, pos, absolute_pos):
"""Adjust stack frame by pos positions. If absolute_pos then
pos is an absolute number. Otherwise it is a relative number.
A negative number indexes from the other end."""
if not proc_obj.curframe:
proc_obj.errmsg("No stack.")
return
# Below we remove any negativity. At the end, pos will be
# the new value of proc_obj.curindex.
if absolute_pos:
if pos >= 0:
pos = frame_num(proc_obj, pos)
else:
pos = -pos - 1
pass
else:
pos += proc_obj.curindex
pass
if pos < 0:
proc_obj.errmsg("Adjusting would put us beyond the oldest frame.")
return
elif pos >= len(proc_obj.stack):
proc_obj.errmsg("Adjusting would put us beyond the newest frame.")
return
proc_obj.curindex = pos
proc_obj.curframe = proc_obj.stack[proc_obj.curindex][0]
proc_obj.location()
proc_obj.list_lineno = None
proc_obj.list_offset = proc_obj.curframe.f_lasti
proc_obj.list_object = proc_obj.curframe
proc_obj.list_filename = proc_obj.curframe.f_code.co_filename
return
|
def adjust_frame(proc_obj, name, pos, absolute_pos):
"""Adjust stack frame by pos positions. If absolute_pos then
pos is an absolute number. Otherwise it is a relative number.
A negative number indexes from the other end."""
if not proc_obj.curframe:
proc_obj.errmsg("No stack.")
return
# Below we remove any negativity. At the end, pos will be
# the new value of proc_obj.curindex.
if absolute_pos:
if pos >= 0:
pos = frame_num(proc_obj, pos)
else:
pos = -pos - 1
pass
else:
pos += proc_obj.curindex
pass
if pos < 0:
proc_obj.errmsg("Adjusting would put us beyond the oldest frame.")
return
elif pos >= len(proc_obj.stack):
proc_obj.errmsg("Adjusting would put us beyond the newest frame.")
return
proc_obj.curindex = pos
proc_obj.curframe = proc_obj.stack[proc_obj.curindex][0]
proc_obj.location()
proc_obj.list_lineno = None
proc_obj.list_offset = proc_obj.curframe.f_lasti
proc_obj.list_object = proc_obj.curframe
proc_obj.list_filename = proc_obj.curframe.f_code.co_filename
return
|
[
"Adjust",
"stack",
"frame",
"by",
"pos",
"positions",
".",
"If",
"absolute_pos",
"then",
"pos",
"is",
"an",
"absolute",
"number",
".",
"Otherwise",
"it",
"is",
"a",
"relative",
"number",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/frame.py#L45-L81
|
[
"def",
"adjust_frame",
"(",
"proc_obj",
",",
"name",
",",
"pos",
",",
"absolute_pos",
")",
":",
"if",
"not",
"proc_obj",
".",
"curframe",
":",
"proc_obj",
".",
"errmsg",
"(",
"\"No stack.\"",
")",
"return",
"# Below we remove any negativity. At the end, pos will be",
"# the new value of proc_obj.curindex.",
"if",
"absolute_pos",
":",
"if",
"pos",
">=",
"0",
":",
"pos",
"=",
"frame_num",
"(",
"proc_obj",
",",
"pos",
")",
"else",
":",
"pos",
"=",
"-",
"pos",
"-",
"1",
"pass",
"else",
":",
"pos",
"+=",
"proc_obj",
".",
"curindex",
"pass",
"if",
"pos",
"<",
"0",
":",
"proc_obj",
".",
"errmsg",
"(",
"\"Adjusting would put us beyond the oldest frame.\"",
")",
"return",
"elif",
"pos",
">=",
"len",
"(",
"proc_obj",
".",
"stack",
")",
":",
"proc_obj",
".",
"errmsg",
"(",
"\"Adjusting would put us beyond the newest frame.\"",
")",
"return",
"proc_obj",
".",
"curindex",
"=",
"pos",
"proc_obj",
".",
"curframe",
"=",
"proc_obj",
".",
"stack",
"[",
"proc_obj",
".",
"curindex",
"]",
"[",
"0",
"]",
"proc_obj",
".",
"location",
"(",
")",
"proc_obj",
".",
"list_lineno",
"=",
"None",
"proc_obj",
".",
"list_offset",
"=",
"proc_obj",
".",
"curframe",
".",
"f_lasti",
"proc_obj",
".",
"list_object",
"=",
"proc_obj",
".",
"curframe",
"proc_obj",
".",
"list_filename",
"=",
"proc_obj",
".",
"curframe",
".",
"f_code",
".",
"co_filename",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
parse_list_cmd
|
Parses arguments for the "list" command and returns the tuple:
(filename, first line number, last line number)
or sets these to None if there was some problem.
|
trepan/processor/cmdlist.py
|
def parse_list_cmd(proc, args, listsize=10):
"""Parses arguments for the "list" command and returns the tuple:
(filename, first line number, last line number)
or sets these to None if there was some problem."""
text = proc.current_command[len(args[0])+1:].strip()
if text in frozenset(('', '.', '+', '-')):
if text == '.':
location = resolve_location(proc, '.')
return location.path, location.line_number, listsize
else:
if proc.list_lineno is None:
proc.errmsg("Don't have previous list location")
return INVALID_PARSE_LIST
filename = proc.list_filename
if text == '+':
first = max(1, proc.list_lineno + listsize)
elif text == '-':
if proc.list_lineno == 1 + listsize:
proc.errmsg("Already at start of %s." % proc.list_filename)
return INVALID_PARSE_LIST
first = max(1, proc.list_lineno - (2*listsize) - 1)
elif text == '':
# Continue from where we last left off
first = proc.list_lineno + 1
last = first + listsize - 1
return filename, first, last
else:
try:
list_range = build_range(text)
except LocationError as e:
proc.errmsg("Error in parsing list range at or around:")
proc.errmsg(e.text)
proc.errmsg(e.text_cursor)
return INVALID_PARSE_LIST
except ScannerError as e:
proc.errmsg("Lexical error in parsing list range at or around:")
proc.errmsg(e.text)
proc.errmsg(e.text_cursor)
return INVALID_PARSE_LIST
if list_range.first is None:
# Last must have been given
assert isinstance(list_range.last, Location)
location = resolve_location(proc, list_range.last)
if not location:
return INVALID_PARSE_LIST
last = location.line_number
first = max(1, last - listsize)
return location.path, first, last
elif isinstance(list_range.first, int):
first = list_range.first
location = resolve_location(proc, list_range.last)
if not location:
return INVALID_PARSE_LIST
filename = location.path
last = location.line_number
if last < first:
# Treat as a count rather than an absolute location
last = first + last
return location.path, first, last
else:
# First is location. Last may be empty or a number
assert isinstance(list_range.first, Location)
location = resolve_location(proc, list_range.first)
if not location:
return INVALID_PARSE_LIST
first = location.line_number
last = list_range.last
if location.method:
first -= listsize // 2
if isinstance(last, str):
# Is an offset +number
assert last[0] == '+'
last = first + int(last[1:])
elif not last:
last = first + listsize
elif last < first:
# Treat as a count rather than an absolute location
last = first + last
return location.path, first, last
pass
return
|
def parse_list_cmd(proc, args, listsize=10):
"""Parses arguments for the "list" command and returns the tuple:
(filename, first line number, last line number)
or sets these to None if there was some problem."""
text = proc.current_command[len(args[0])+1:].strip()
if text in frozenset(('', '.', '+', '-')):
if text == '.':
location = resolve_location(proc, '.')
return location.path, location.line_number, listsize
else:
if proc.list_lineno is None:
proc.errmsg("Don't have previous list location")
return INVALID_PARSE_LIST
filename = proc.list_filename
if text == '+':
first = max(1, proc.list_lineno + listsize)
elif text == '-':
if proc.list_lineno == 1 + listsize:
proc.errmsg("Already at start of %s." % proc.list_filename)
return INVALID_PARSE_LIST
first = max(1, proc.list_lineno - (2*listsize) - 1)
elif text == '':
# Continue from where we last left off
first = proc.list_lineno + 1
last = first + listsize - 1
return filename, first, last
else:
try:
list_range = build_range(text)
except LocationError as e:
proc.errmsg("Error in parsing list range at or around:")
proc.errmsg(e.text)
proc.errmsg(e.text_cursor)
return INVALID_PARSE_LIST
except ScannerError as e:
proc.errmsg("Lexical error in parsing list range at or around:")
proc.errmsg(e.text)
proc.errmsg(e.text_cursor)
return INVALID_PARSE_LIST
if list_range.first is None:
# Last must have been given
assert isinstance(list_range.last, Location)
location = resolve_location(proc, list_range.last)
if not location:
return INVALID_PARSE_LIST
last = location.line_number
first = max(1, last - listsize)
return location.path, first, last
elif isinstance(list_range.first, int):
first = list_range.first
location = resolve_location(proc, list_range.last)
if not location:
return INVALID_PARSE_LIST
filename = location.path
last = location.line_number
if last < first:
# Treat as a count rather than an absolute location
last = first + last
return location.path, first, last
else:
# First is location. Last may be empty or a number
assert isinstance(list_range.first, Location)
location = resolve_location(proc, list_range.first)
if not location:
return INVALID_PARSE_LIST
first = location.line_number
last = list_range.last
if location.method:
first -= listsize // 2
if isinstance(last, str):
# Is an offset +number
assert last[0] == '+'
last = first + int(last[1:])
elif not last:
last = first + listsize
elif last < first:
# Treat as a count rather than an absolute location
last = first + last
return location.path, first, last
pass
return
|
[
"Parses",
"arguments",
"for",
"the",
"list",
"command",
"and",
"returns",
"the",
"tuple",
":",
"(",
"filename",
"first",
"line",
"number",
"last",
"line",
"number",
")",
"or",
"sets",
"these",
"to",
"None",
"if",
"there",
"was",
"some",
"problem",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdlist.py#L23-L107
|
[
"def",
"parse_list_cmd",
"(",
"proc",
",",
"args",
",",
"listsize",
"=",
"10",
")",
":",
"text",
"=",
"proc",
".",
"current_command",
"[",
"len",
"(",
"args",
"[",
"0",
"]",
")",
"+",
"1",
":",
"]",
".",
"strip",
"(",
")",
"if",
"text",
"in",
"frozenset",
"(",
"(",
"''",
",",
"'.'",
",",
"'+'",
",",
"'-'",
")",
")",
":",
"if",
"text",
"==",
"'.'",
":",
"location",
"=",
"resolve_location",
"(",
"proc",
",",
"'.'",
")",
"return",
"location",
".",
"path",
",",
"location",
".",
"line_number",
",",
"listsize",
"else",
":",
"if",
"proc",
".",
"list_lineno",
"is",
"None",
":",
"proc",
".",
"errmsg",
"(",
"\"Don't have previous list location\"",
")",
"return",
"INVALID_PARSE_LIST",
"filename",
"=",
"proc",
".",
"list_filename",
"if",
"text",
"==",
"'+'",
":",
"first",
"=",
"max",
"(",
"1",
",",
"proc",
".",
"list_lineno",
"+",
"listsize",
")",
"elif",
"text",
"==",
"'-'",
":",
"if",
"proc",
".",
"list_lineno",
"==",
"1",
"+",
"listsize",
":",
"proc",
".",
"errmsg",
"(",
"\"Already at start of %s.\"",
"%",
"proc",
".",
"list_filename",
")",
"return",
"INVALID_PARSE_LIST",
"first",
"=",
"max",
"(",
"1",
",",
"proc",
".",
"list_lineno",
"-",
"(",
"2",
"*",
"listsize",
")",
"-",
"1",
")",
"elif",
"text",
"==",
"''",
":",
"# Continue from where we last left off",
"first",
"=",
"proc",
".",
"list_lineno",
"+",
"1",
"last",
"=",
"first",
"+",
"listsize",
"-",
"1",
"return",
"filename",
",",
"first",
",",
"last",
"else",
":",
"try",
":",
"list_range",
"=",
"build_range",
"(",
"text",
")",
"except",
"LocationError",
"as",
"e",
":",
"proc",
".",
"errmsg",
"(",
"\"Error in parsing list range at or around:\"",
")",
"proc",
".",
"errmsg",
"(",
"e",
".",
"text",
")",
"proc",
".",
"errmsg",
"(",
"e",
".",
"text_cursor",
")",
"return",
"INVALID_PARSE_LIST",
"except",
"ScannerError",
"as",
"e",
":",
"proc",
".",
"errmsg",
"(",
"\"Lexical error in parsing list range at or around:\"",
")",
"proc",
".",
"errmsg",
"(",
"e",
".",
"text",
")",
"proc",
".",
"errmsg",
"(",
"e",
".",
"text_cursor",
")",
"return",
"INVALID_PARSE_LIST",
"if",
"list_range",
".",
"first",
"is",
"None",
":",
"# Last must have been given",
"assert",
"isinstance",
"(",
"list_range",
".",
"last",
",",
"Location",
")",
"location",
"=",
"resolve_location",
"(",
"proc",
",",
"list_range",
".",
"last",
")",
"if",
"not",
"location",
":",
"return",
"INVALID_PARSE_LIST",
"last",
"=",
"location",
".",
"line_number",
"first",
"=",
"max",
"(",
"1",
",",
"last",
"-",
"listsize",
")",
"return",
"location",
".",
"path",
",",
"first",
",",
"last",
"elif",
"isinstance",
"(",
"list_range",
".",
"first",
",",
"int",
")",
":",
"first",
"=",
"list_range",
".",
"first",
"location",
"=",
"resolve_location",
"(",
"proc",
",",
"list_range",
".",
"last",
")",
"if",
"not",
"location",
":",
"return",
"INVALID_PARSE_LIST",
"filename",
"=",
"location",
".",
"path",
"last",
"=",
"location",
".",
"line_number",
"if",
"last",
"<",
"first",
":",
"# Treat as a count rather than an absolute location",
"last",
"=",
"first",
"+",
"last",
"return",
"location",
".",
"path",
",",
"first",
",",
"last",
"else",
":",
"# First is location. Last may be empty or a number",
"assert",
"isinstance",
"(",
"list_range",
".",
"first",
",",
"Location",
")",
"location",
"=",
"resolve_location",
"(",
"proc",
",",
"list_range",
".",
"first",
")",
"if",
"not",
"location",
":",
"return",
"INVALID_PARSE_LIST",
"first",
"=",
"location",
".",
"line_number",
"last",
"=",
"list_range",
".",
"last",
"if",
"location",
".",
"method",
":",
"first",
"-=",
"listsize",
"//",
"2",
"if",
"isinstance",
"(",
"last",
",",
"str",
")",
":",
"# Is an offset +number",
"assert",
"last",
"[",
"0",
"]",
"==",
"'+'",
"last",
"=",
"first",
"+",
"int",
"(",
"last",
"[",
"1",
":",
"]",
")",
"elif",
"not",
"last",
":",
"last",
"=",
"first",
"+",
"listsize",
"elif",
"last",
"<",
"first",
":",
"# Treat as a count rather than an absolute location",
"last",
"=",
"first",
"+",
"last",
"return",
"location",
".",
"path",
",",
"first",
",",
"last",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
DebuggerUserInput.open
|
Use this to set where to read from.
Set opts['try_lineedit'] if you want this input to interact
with GNU-like readline library. By default, we will assume to
try importing and using readline. If readline is not
importable, line editing is not available whether or not
opts['try_readline'] is set.
Set opts['use_raw'] if input should use Python's use_raw(). If
however 'inp' is a string and opts['use_raw'] is not set, we
will assume no raw output. Note that an individual readline
may override the setting.
|
trepan/inout/input.py
|
def open(self, inp, opts={}):
"""Use this to set where to read from.
Set opts['try_lineedit'] if you want this input to interact
with GNU-like readline library. By default, we will assume to
try importing and using readline. If readline is not
importable, line editing is not available whether or not
opts['try_readline'] is set.
Set opts['use_raw'] if input should use Python's use_raw(). If
however 'inp' is a string and opts['use_raw'] is not set, we
will assume no raw output. Note that an individual readline
may override the setting.
"""
get_option = lambda key: Mmisc.option_set(opts, key,
self.DEFAULT_OPEN_READ_OPTS)
if (isinstance(inp, io.TextIOWrapper) or
isinstance(inp, io.StringIO) or
hasattr(inp, 'isatty') and inp.isatty()):
self.use_raw = get_option('use_raw')
elif isinstance(inp, 'string'.__class__): # FIXME
if opts is None:
self.use_raw = False
else:
self.use_raw = get_option('use_raw')
pass
inp = open(inp, 'r')
else:
raise IOError("Invalid input type (%s) for %s" % (type(inp),
inp))
self.input = inp
self.line_edit = get_option('try_readline') and readline_importable()
self.closed = False
return
|
def open(self, inp, opts={}):
"""Use this to set where to read from.
Set opts['try_lineedit'] if you want this input to interact
with GNU-like readline library. By default, we will assume to
try importing and using readline. If readline is not
importable, line editing is not available whether or not
opts['try_readline'] is set.
Set opts['use_raw'] if input should use Python's use_raw(). If
however 'inp' is a string and opts['use_raw'] is not set, we
will assume no raw output. Note that an individual readline
may override the setting.
"""
get_option = lambda key: Mmisc.option_set(opts, key,
self.DEFAULT_OPEN_READ_OPTS)
if (isinstance(inp, io.TextIOWrapper) or
isinstance(inp, io.StringIO) or
hasattr(inp, 'isatty') and inp.isatty()):
self.use_raw = get_option('use_raw')
elif isinstance(inp, 'string'.__class__): # FIXME
if opts is None:
self.use_raw = False
else:
self.use_raw = get_option('use_raw')
pass
inp = open(inp, 'r')
else:
raise IOError("Invalid input type (%s) for %s" % (type(inp),
inp))
self.input = inp
self.line_edit = get_option('try_readline') and readline_importable()
self.closed = False
return
|
[
"Use",
"this",
"to",
"set",
"where",
"to",
"read",
"from",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/input.py#L57-L90
|
[
"def",
"open",
"(",
"self",
",",
"inp",
",",
"opts",
"=",
"{",
"}",
")",
":",
"get_option",
"=",
"lambda",
"key",
":",
"Mmisc",
".",
"option_set",
"(",
"opts",
",",
"key",
",",
"self",
".",
"DEFAULT_OPEN_READ_OPTS",
")",
"if",
"(",
"isinstance",
"(",
"inp",
",",
"io",
".",
"TextIOWrapper",
")",
"or",
"isinstance",
"(",
"inp",
",",
"io",
".",
"StringIO",
")",
"or",
"hasattr",
"(",
"inp",
",",
"'isatty'",
")",
"and",
"inp",
".",
"isatty",
"(",
")",
")",
":",
"self",
".",
"use_raw",
"=",
"get_option",
"(",
"'use_raw'",
")",
"elif",
"isinstance",
"(",
"inp",
",",
"'string'",
".",
"__class__",
")",
":",
"# FIXME",
"if",
"opts",
"is",
"None",
":",
"self",
".",
"use_raw",
"=",
"False",
"else",
":",
"self",
".",
"use_raw",
"=",
"get_option",
"(",
"'use_raw'",
")",
"pass",
"inp",
"=",
"open",
"(",
"inp",
",",
"'r'",
")",
"else",
":",
"raise",
"IOError",
"(",
"\"Invalid input type (%s) for %s\"",
"%",
"(",
"type",
"(",
"inp",
")",
",",
"inp",
")",
")",
"self",
".",
"input",
"=",
"inp",
"self",
".",
"line_edit",
"=",
"get_option",
"(",
"'try_readline'",
")",
"and",
"readline_importable",
"(",
")",
"self",
".",
"closed",
"=",
"False",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
DebuggerUserInput.readline
|
Read a line of input. EOFError will be raised on EOF.
Note: some user interfaces may decide to arrange to call
DebuggerOutput.write() first with the prompt rather than pass
it here.. If `use_raw' is set raw_input() will be used in that
is supported by the specific input input. If this option is
left None as is normally expected the value from the class
initialization is used.
|
trepan/inout/input.py
|
def readline(self, use_raw=None, prompt=''):
"""Read a line of input. EOFError will be raised on EOF.
Note: some user interfaces may decide to arrange to call
DebuggerOutput.write() first with the prompt rather than pass
it here.. If `use_raw' is set raw_input() will be used in that
is supported by the specific input input. If this option is
left None as is normally expected the value from the class
initialization is used.
"""
# FIXME we don't do command completion.
if use_raw is None:
use_raw = self.use_raw
pass
if use_raw:
try:
inp = input(prompt)
# import pdb; pdb.set_trace()
return inp
except ValueError:
raise EOFError
pass
else:
line = self.input.readline()
if not line: raise EOFError
return line.rstrip("\n")
pass
|
def readline(self, use_raw=None, prompt=''):
"""Read a line of input. EOFError will be raised on EOF.
Note: some user interfaces may decide to arrange to call
DebuggerOutput.write() first with the prompt rather than pass
it here.. If `use_raw' is set raw_input() will be used in that
is supported by the specific input input. If this option is
left None as is normally expected the value from the class
initialization is used.
"""
# FIXME we don't do command completion.
if use_raw is None:
use_raw = self.use_raw
pass
if use_raw:
try:
inp = input(prompt)
# import pdb; pdb.set_trace()
return inp
except ValueError:
raise EOFError
pass
else:
line = self.input.readline()
if not line: raise EOFError
return line.rstrip("\n")
pass
|
[
"Read",
"a",
"line",
"of",
"input",
".",
"EOFError",
"will",
"be",
"raised",
"on",
"EOF",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/input.py#L92-L119
|
[
"def",
"readline",
"(",
"self",
",",
"use_raw",
"=",
"None",
",",
"prompt",
"=",
"''",
")",
":",
"# FIXME we don't do command completion.",
"if",
"use_raw",
"is",
"None",
":",
"use_raw",
"=",
"self",
".",
"use_raw",
"pass",
"if",
"use_raw",
":",
"try",
":",
"inp",
"=",
"input",
"(",
"prompt",
")",
"# import pdb; pdb.set_trace()",
"return",
"inp",
"except",
"ValueError",
":",
"raise",
"EOFError",
"pass",
"else",
":",
"line",
"=",
"self",
".",
"input",
".",
"readline",
"(",
")",
"if",
"not",
"line",
":",
"raise",
"EOFError",
"return",
"line",
".",
"rstrip",
"(",
"\"\\n\"",
")",
"pass"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Trepan.run
|
Run debugger on string `cmd' using builtin function eval
and if that builtin exec. Arguments `globals_' and `locals_'
are the dictionaries to use for local and global variables. By
default, the value of globals is globals(), the current global
variables. If `locals_' is not given, it becomes a copy of
`globals_'.
Debugger.core.start settings are passed via optional
dictionary `start_opts'. Overall debugger settings are in
Debugger.settings which changed after an instance is created
. Also see `run_eval' if what you want to run is an
run_eval'able expression have that result returned and
`run_call' if you want to debug function run_call.
|
trepan/debugger.py
|
def run(self, cmd, start_opts=None, globals_=None, locals_=None):
""" Run debugger on string `cmd' using builtin function eval
and if that builtin exec. Arguments `globals_' and `locals_'
are the dictionaries to use for local and global variables. By
default, the value of globals is globals(), the current global
variables. If `locals_' is not given, it becomes a copy of
`globals_'.
Debugger.core.start settings are passed via optional
dictionary `start_opts'. Overall debugger settings are in
Debugger.settings which changed after an instance is created
. Also see `run_eval' if what you want to run is an
run_eval'able expression have that result returned and
`run_call' if you want to debug function run_call.
"""
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
if not isinstance(cmd, types.CodeType):
self.eval_string = cmd
cmd = cmd+'\n'
pass
retval = None
self.core.start(start_opts)
try:
retval = eval(cmd, globals_, locals_)
except SyntaxError:
try:
exec(cmd, globals_, locals_)
except DebuggerQuit:
pass
except DebuggerQuit:
pass
pass
except DebuggerQuit:
pass
finally:
self.core.stop()
return retval
|
def run(self, cmd, start_opts=None, globals_=None, locals_=None):
""" Run debugger on string `cmd' using builtin function eval
and if that builtin exec. Arguments `globals_' and `locals_'
are the dictionaries to use for local and global variables. By
default, the value of globals is globals(), the current global
variables. If `locals_' is not given, it becomes a copy of
`globals_'.
Debugger.core.start settings are passed via optional
dictionary `start_opts'. Overall debugger settings are in
Debugger.settings which changed after an instance is created
. Also see `run_eval' if what you want to run is an
run_eval'able expression have that result returned and
`run_call' if you want to debug function run_call.
"""
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
if not isinstance(cmd, types.CodeType):
self.eval_string = cmd
cmd = cmd+'\n'
pass
retval = None
self.core.start(start_opts)
try:
retval = eval(cmd, globals_, locals_)
except SyntaxError:
try:
exec(cmd, globals_, locals_)
except DebuggerQuit:
pass
except DebuggerQuit:
pass
pass
except DebuggerQuit:
pass
finally:
self.core.stop()
return retval
|
[
"Run",
"debugger",
"on",
"string",
"cmd",
"using",
"builtin",
"function",
"eval",
"and",
"if",
"that",
"builtin",
"exec",
".",
"Arguments",
"globals_",
"and",
"locals_",
"are",
"the",
"dictionaries",
"to",
"use",
"for",
"local",
"and",
"global",
"variables",
".",
"By",
"default",
"the",
"value",
"of",
"globals",
"is",
"globals",
"()",
"the",
"current",
"global",
"variables",
".",
"If",
"locals_",
"is",
"not",
"given",
"it",
"becomes",
"a",
"copy",
"of",
"globals_",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/debugger.py#L62-L101
|
[
"def",
"run",
"(",
"self",
",",
"cmd",
",",
"start_opts",
"=",
"None",
",",
"globals_",
"=",
"None",
",",
"locals_",
"=",
"None",
")",
":",
"if",
"globals_",
"is",
"None",
":",
"globals_",
"=",
"globals",
"(",
")",
"if",
"locals_",
"is",
"None",
":",
"locals_",
"=",
"globals_",
"if",
"not",
"isinstance",
"(",
"cmd",
",",
"types",
".",
"CodeType",
")",
":",
"self",
".",
"eval_string",
"=",
"cmd",
"cmd",
"=",
"cmd",
"+",
"'\\n'",
"pass",
"retval",
"=",
"None",
"self",
".",
"core",
".",
"start",
"(",
"start_opts",
")",
"try",
":",
"retval",
"=",
"eval",
"(",
"cmd",
",",
"globals_",
",",
"locals_",
")",
"except",
"SyntaxError",
":",
"try",
":",
"exec",
"(",
"cmd",
",",
"globals_",
",",
"locals_",
")",
"except",
"DebuggerQuit",
":",
"pass",
"except",
"DebuggerQuit",
":",
"pass",
"pass",
"except",
"DebuggerQuit",
":",
"pass",
"finally",
":",
"self",
".",
"core",
".",
"stop",
"(",
")",
"return",
"retval"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Trepan.run_exec
|
Run debugger on string `cmd' which will executed via the
builtin function exec. Arguments `globals_' and `locals_' are
the dictionaries to use for local and global variables. By
default, the value of globals is globals(), the current global
variables. If `locals_' is not given, it becomes a copy of
`globals_'.
Debugger.core.start settings are passed via optional
dictionary `start_opts'. Overall debugger settings are in
Debugger.settings which changed after an instance is created
. Also see `run_eval' if what you want to run is an
run_eval'able expression have that result returned and
`run_call' if you want to debug function run_call.
|
trepan/debugger.py
|
def run_exec(self, cmd, start_opts=None, globals_=None, locals_=None):
""" Run debugger on string `cmd' which will executed via the
builtin function exec. Arguments `globals_' and `locals_' are
the dictionaries to use for local and global variables. By
default, the value of globals is globals(), the current global
variables. If `locals_' is not given, it becomes a copy of
`globals_'.
Debugger.core.start settings are passed via optional
dictionary `start_opts'. Overall debugger settings are in
Debugger.settings which changed after an instance is created
. Also see `run_eval' if what you want to run is an
run_eval'able expression have that result returned and
`run_call' if you want to debug function run_call.
"""
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
if not isinstance(cmd, types.CodeType):
cmd = cmd+'\n'
pass
self.core.start(start_opts)
try:
exec(cmd, globals_, locals_)
except DebuggerQuit:
pass
finally:
self.core.stop()
return
|
def run_exec(self, cmd, start_opts=None, globals_=None, locals_=None):
""" Run debugger on string `cmd' which will executed via the
builtin function exec. Arguments `globals_' and `locals_' are
the dictionaries to use for local and global variables. By
default, the value of globals is globals(), the current global
variables. If `locals_' is not given, it becomes a copy of
`globals_'.
Debugger.core.start settings are passed via optional
dictionary `start_opts'. Overall debugger settings are in
Debugger.settings which changed after an instance is created
. Also see `run_eval' if what you want to run is an
run_eval'able expression have that result returned and
`run_call' if you want to debug function run_call.
"""
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
if not isinstance(cmd, types.CodeType):
cmd = cmd+'\n'
pass
self.core.start(start_opts)
try:
exec(cmd, globals_, locals_)
except DebuggerQuit:
pass
finally:
self.core.stop()
return
|
[
"Run",
"debugger",
"on",
"string",
"cmd",
"which",
"will",
"executed",
"via",
"the",
"builtin",
"function",
"exec",
".",
"Arguments",
"globals_",
"and",
"locals_",
"are",
"the",
"dictionaries",
"to",
"use",
"for",
"local",
"and",
"global",
"variables",
".",
"By",
"default",
"the",
"value",
"of",
"globals",
"is",
"globals",
"()",
"the",
"current",
"global",
"variables",
".",
"If",
"locals_",
"is",
"not",
"given",
"it",
"becomes",
"a",
"copy",
"of",
"globals_",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/debugger.py#L103-L132
|
[
"def",
"run_exec",
"(",
"self",
",",
"cmd",
",",
"start_opts",
"=",
"None",
",",
"globals_",
"=",
"None",
",",
"locals_",
"=",
"None",
")",
":",
"if",
"globals_",
"is",
"None",
":",
"globals_",
"=",
"globals",
"(",
")",
"if",
"locals_",
"is",
"None",
":",
"locals_",
"=",
"globals_",
"if",
"not",
"isinstance",
"(",
"cmd",
",",
"types",
".",
"CodeType",
")",
":",
"cmd",
"=",
"cmd",
"+",
"'\\n'",
"pass",
"self",
".",
"core",
".",
"start",
"(",
"start_opts",
")",
"try",
":",
"exec",
"(",
"cmd",
",",
"globals_",
",",
"locals_",
")",
"except",
"DebuggerQuit",
":",
"pass",
"finally",
":",
"self",
".",
"core",
".",
"stop",
"(",
")",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Trepan.run_call
|
Run debugger on function call: `func(*args, **kwds)'
See also `run_eval' if what you want to run is an eval'able
expression have that result returned and `run' if you want to
debug a statment via exec.
|
trepan/debugger.py
|
def run_call(self, func, start_opts=None, *args, **kwds):
""" Run debugger on function call: `func(*args, **kwds)'
See also `run_eval' if what you want to run is an eval'able
expression have that result returned and `run' if you want to
debug a statment via exec.
"""
res = None
self.core.start(opts=start_opts)
try:
res = func(*args, **kwds)
except DebuggerQuit:
pass
finally:
self.core.stop()
return res
|
def run_call(self, func, start_opts=None, *args, **kwds):
""" Run debugger on function call: `func(*args, **kwds)'
See also `run_eval' if what you want to run is an eval'able
expression have that result returned and `run' if you want to
debug a statment via exec.
"""
res = None
self.core.start(opts=start_opts)
try:
res = func(*args, **kwds)
except DebuggerQuit:
pass
finally:
self.core.stop()
return res
|
[
"Run",
"debugger",
"on",
"function",
"call",
":",
"func",
"(",
"*",
"args",
"**",
"kwds",
")"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/debugger.py#L134-L149
|
[
"def",
"run_call",
"(",
"self",
",",
"func",
",",
"start_opts",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"res",
"=",
"None",
"self",
".",
"core",
".",
"start",
"(",
"opts",
"=",
"start_opts",
")",
"try",
":",
"res",
"=",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
"except",
"DebuggerQuit",
":",
"pass",
"finally",
":",
"self",
".",
"core",
".",
"stop",
"(",
")",
"return",
"res"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Trepan.run_eval
|
Run debugger on string `expr' which will executed via the
built-in Python function: eval; `globals_' and `locals_' are
the dictionaries to use for local and global variables. If
`globals' is not given, __main__.__dict__ (the current global
variables) is used. If `locals_' is not given, it becomes a
copy of `globals_'.
See also `run_call' if what you to debug a function call and
`run' if you want to debug general Python statements.
|
trepan/debugger.py
|
def run_eval(self, expr, start_opts=None, globals_=None, locals_=None):
""" Run debugger on string `expr' which will executed via the
built-in Python function: eval; `globals_' and `locals_' are
the dictionaries to use for local and global variables. If
`globals' is not given, __main__.__dict__ (the current global
variables) is used. If `locals_' is not given, it becomes a
copy of `globals_'.
See also `run_call' if what you to debug a function call and
`run' if you want to debug general Python statements.
"""
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
if not isinstance(expr, types.CodeType):
self.eval_string = expr
expr = expr+'\n'
pass
retval = None
self.core.start(start_opts)
try:
retval = eval(expr, globals_, locals_)
except DebuggerQuit:
pass
finally:
pyficache.remove_remap_file('<string>')
self.core.stop()
return retval
|
def run_eval(self, expr, start_opts=None, globals_=None, locals_=None):
""" Run debugger on string `expr' which will executed via the
built-in Python function: eval; `globals_' and `locals_' are
the dictionaries to use for local and global variables. If
`globals' is not given, __main__.__dict__ (the current global
variables) is used. If `locals_' is not given, it becomes a
copy of `globals_'.
See also `run_call' if what you to debug a function call and
`run' if you want to debug general Python statements.
"""
if globals_ is None:
globals_ = globals()
if locals_ is None:
locals_ = globals_
if not isinstance(expr, types.CodeType):
self.eval_string = expr
expr = expr+'\n'
pass
retval = None
self.core.start(start_opts)
try:
retval = eval(expr, globals_, locals_)
except DebuggerQuit:
pass
finally:
pyficache.remove_remap_file('<string>')
self.core.stop()
return retval
|
[
"Run",
"debugger",
"on",
"string",
"expr",
"which",
"will",
"executed",
"via",
"the",
"built",
"-",
"in",
"Python",
"function",
":",
"eval",
";",
"globals_",
"and",
"locals_",
"are",
"the",
"dictionaries",
"to",
"use",
"for",
"local",
"and",
"global",
"variables",
".",
"If",
"globals",
"is",
"not",
"given",
"__main__",
".",
"__dict__",
"(",
"the",
"current",
"global",
"variables",
")",
"is",
"used",
".",
"If",
"locals_",
"is",
"not",
"given",
"it",
"becomes",
"a",
"copy",
"of",
"globals_",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/debugger.py#L151-L179
|
[
"def",
"run_eval",
"(",
"self",
",",
"expr",
",",
"start_opts",
"=",
"None",
",",
"globals_",
"=",
"None",
",",
"locals_",
"=",
"None",
")",
":",
"if",
"globals_",
"is",
"None",
":",
"globals_",
"=",
"globals",
"(",
")",
"if",
"locals_",
"is",
"None",
":",
"locals_",
"=",
"globals_",
"if",
"not",
"isinstance",
"(",
"expr",
",",
"types",
".",
"CodeType",
")",
":",
"self",
".",
"eval_string",
"=",
"expr",
"expr",
"=",
"expr",
"+",
"'\\n'",
"pass",
"retval",
"=",
"None",
"self",
".",
"core",
".",
"start",
"(",
"start_opts",
")",
"try",
":",
"retval",
"=",
"eval",
"(",
"expr",
",",
"globals_",
",",
"locals_",
")",
"except",
"DebuggerQuit",
":",
"pass",
"finally",
":",
"pyficache",
".",
"remove_remap_file",
"(",
"'<string>'",
")",
"self",
".",
"core",
".",
"stop",
"(",
")",
"return",
"retval"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Trepan.run_script
|
Run debugger on Python script `filename'. The script may
inspect sys.argv for command arguments. `globals_' and
`locals_' are the dictionaries to use for local and global
variables. If `globals' is not given, globals() (the current
global variables) is used. If `locals_' is not given, it
becomes a copy of `globals_'.
True is returned if the program terminated normally and False
if the debugger initiated a quit or the program did not normally
terminate.
See also `run_call' if what you to debug a function call,
`run_eval' if you want to debug an expression, and `run' if you
want to debug general Python statements not inside a file.
|
trepan/debugger.py
|
def run_script(self, filename, start_opts=None, globals_=None,
locals_=None):
""" Run debugger on Python script `filename'. The script may
inspect sys.argv for command arguments. `globals_' and
`locals_' are the dictionaries to use for local and global
variables. If `globals' is not given, globals() (the current
global variables) is used. If `locals_' is not given, it
becomes a copy of `globals_'.
True is returned if the program terminated normally and False
if the debugger initiated a quit or the program did not normally
terminate.
See also `run_call' if what you to debug a function call,
`run_eval' if you want to debug an expression, and `run' if you
want to debug general Python statements not inside a file.
"""
self.mainpyfile = self.core.canonic(filename)
# Start with fresh empty copy of globals and locals and tell the script
# that it's being run as __main__ to avoid scripts being able to access
# the debugger namespace.
if globals_ is None:
import __main__ # NOQA
globals_ = {"__name__" : "__main__",
"__file__" : self.mainpyfile,
"__builtins__" : __builtins__
} # NOQA
if locals_ is None:
locals_ = globals_
retval = False
self.core.execution_status = 'Running'
try:
compiled = compile(open(self.mainpyfile).read(),
self.mainpyfile, 'exec')
self.core.start(start_opts)
exec(compiled, globals_, locals_)
retval = True
except SyntaxError:
print(sys.exc_info()[1])
retval = False
pass
except IOError:
print(sys.exc_info()[1])
except DebuggerQuit:
retval = False
pass
except DebuggerRestart:
self.core.execution_status = 'Restart requested'
raise DebuggerRestart
finally:
self.core.stop(options={'remove': True})
return retval
|
def run_script(self, filename, start_opts=None, globals_=None,
locals_=None):
""" Run debugger on Python script `filename'. The script may
inspect sys.argv for command arguments. `globals_' and
`locals_' are the dictionaries to use for local and global
variables. If `globals' is not given, globals() (the current
global variables) is used. If `locals_' is not given, it
becomes a copy of `globals_'.
True is returned if the program terminated normally and False
if the debugger initiated a quit or the program did not normally
terminate.
See also `run_call' if what you to debug a function call,
`run_eval' if you want to debug an expression, and `run' if you
want to debug general Python statements not inside a file.
"""
self.mainpyfile = self.core.canonic(filename)
# Start with fresh empty copy of globals and locals and tell the script
# that it's being run as __main__ to avoid scripts being able to access
# the debugger namespace.
if globals_ is None:
import __main__ # NOQA
globals_ = {"__name__" : "__main__",
"__file__" : self.mainpyfile,
"__builtins__" : __builtins__
} # NOQA
if locals_ is None:
locals_ = globals_
retval = False
self.core.execution_status = 'Running'
try:
compiled = compile(open(self.mainpyfile).read(),
self.mainpyfile, 'exec')
self.core.start(start_opts)
exec(compiled, globals_, locals_)
retval = True
except SyntaxError:
print(sys.exc_info()[1])
retval = False
pass
except IOError:
print(sys.exc_info()[1])
except DebuggerQuit:
retval = False
pass
except DebuggerRestart:
self.core.execution_status = 'Restart requested'
raise DebuggerRestart
finally:
self.core.stop(options={'remove': True})
return retval
|
[
"Run",
"debugger",
"on",
"Python",
"script",
"filename",
".",
"The",
"script",
"may",
"inspect",
"sys",
".",
"argv",
"for",
"command",
"arguments",
".",
"globals_",
"and",
"locals_",
"are",
"the",
"dictionaries",
"to",
"use",
"for",
"local",
"and",
"global",
"variables",
".",
"If",
"globals",
"is",
"not",
"given",
"globals",
"()",
"(",
"the",
"current",
"global",
"variables",
")",
"is",
"used",
".",
"If",
"locals_",
"is",
"not",
"given",
"it",
"becomes",
"a",
"copy",
"of",
"globals_",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/debugger.py#L181-L233
|
[
"def",
"run_script",
"(",
"self",
",",
"filename",
",",
"start_opts",
"=",
"None",
",",
"globals_",
"=",
"None",
",",
"locals_",
"=",
"None",
")",
":",
"self",
".",
"mainpyfile",
"=",
"self",
".",
"core",
".",
"canonic",
"(",
"filename",
")",
"# Start with fresh empty copy of globals and locals and tell the script",
"# that it's being run as __main__ to avoid scripts being able to access",
"# the debugger namespace.",
"if",
"globals_",
"is",
"None",
":",
"import",
"__main__",
"# NOQA",
"globals_",
"=",
"{",
"\"__name__\"",
":",
"\"__main__\"",
",",
"\"__file__\"",
":",
"self",
".",
"mainpyfile",
",",
"\"__builtins__\"",
":",
"__builtins__",
"}",
"# NOQA",
"if",
"locals_",
"is",
"None",
":",
"locals_",
"=",
"globals_",
"retval",
"=",
"False",
"self",
".",
"core",
".",
"execution_status",
"=",
"'Running'",
"try",
":",
"compiled",
"=",
"compile",
"(",
"open",
"(",
"self",
".",
"mainpyfile",
")",
".",
"read",
"(",
")",
",",
"self",
".",
"mainpyfile",
",",
"'exec'",
")",
"self",
".",
"core",
".",
"start",
"(",
"start_opts",
")",
"exec",
"(",
"compiled",
",",
"globals_",
",",
"locals_",
")",
"retval",
"=",
"True",
"except",
"SyntaxError",
":",
"print",
"(",
"sys",
".",
"exc_info",
"(",
")",
"[",
"1",
"]",
")",
"retval",
"=",
"False",
"pass",
"except",
"IOError",
":",
"print",
"(",
"sys",
".",
"exc_info",
"(",
")",
"[",
"1",
"]",
")",
"except",
"DebuggerQuit",
":",
"retval",
"=",
"False",
"pass",
"except",
"DebuggerRestart",
":",
"self",
".",
"core",
".",
"execution_status",
"=",
"'Restart requested'",
"raise",
"DebuggerRestart",
"finally",
":",
"self",
".",
"core",
".",
"stop",
"(",
"options",
"=",
"{",
"'remove'",
":",
"True",
"}",
")",
"return",
"retval"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
arg_split
|
Split a command line's arguments in a shell-like manner returned
as a list of lists. Use ';;' with white space to indicate separate
commands.
This is a modified version of the standard library's shlex.split()
function, but with a default of posix=False for splitting, so that quotes
in inputs are respected.
|
trepan/processor/cmdproc.py
|
def arg_split(s, posix=False):
"""Split a command line's arguments in a shell-like manner returned
as a list of lists. Use ';;' with white space to indicate separate
commands.
This is a modified version of the standard library's shlex.split()
function, but with a default of posix=False for splitting, so that quotes
in inputs are respected.
"""
args_list = [[]]
if isinstance(s, bytes):
s = s.decode("utf-8")
lex = shlex.shlex(s, posix=posix)
lex.whitespace_split = True
args = list(lex)
for arg in args:
if ';;' == arg:
args_list.append([])
else:
args_list[-1].append(arg)
pass
pass
return args_list
|
def arg_split(s, posix=False):
"""Split a command line's arguments in a shell-like manner returned
as a list of lists. Use ';;' with white space to indicate separate
commands.
This is a modified version of the standard library's shlex.split()
function, but with a default of posix=False for splitting, so that quotes
in inputs are respected.
"""
args_list = [[]]
if isinstance(s, bytes):
s = s.decode("utf-8")
lex = shlex.shlex(s, posix=posix)
lex.whitespace_split = True
args = list(lex)
for arg in args:
if ';;' == arg:
args_list.append([])
else:
args_list[-1].append(arg)
pass
pass
return args_list
|
[
"Split",
"a",
"command",
"line",
"s",
"arguments",
"in",
"a",
"shell",
"-",
"like",
"manner",
"returned",
"as",
"a",
"list",
"of",
"lists",
".",
"Use",
";;",
"with",
"white",
"space",
"to",
"indicate",
"separate",
"commands",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L49-L73
|
[
"def",
"arg_split",
"(",
"s",
",",
"posix",
"=",
"False",
")",
":",
"args_list",
"=",
"[",
"[",
"]",
"]",
"if",
"isinstance",
"(",
"s",
",",
"bytes",
")",
":",
"s",
"=",
"s",
".",
"decode",
"(",
"\"utf-8\"",
")",
"lex",
"=",
"shlex",
".",
"shlex",
"(",
"s",
",",
"posix",
"=",
"posix",
")",
"lex",
".",
"whitespace_split",
"=",
"True",
"args",
"=",
"list",
"(",
"lex",
")",
"for",
"arg",
"in",
"args",
":",
"if",
"';;'",
"==",
"arg",
":",
"args_list",
".",
"append",
"(",
"[",
"]",
")",
"else",
":",
"args_list",
"[",
"-",
"1",
"]",
".",
"append",
"(",
"arg",
")",
"pass",
"pass",
"return",
"args_list"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
get_stack
|
Return a stack of frames which the debugger will use for in
showing backtraces and in frame switching. As such various frame
that are really around may be excluded unless we are debugging the
sebugger. Also we will add traceback frame on top if that
exists.
|
trepan/processor/cmdproc.py
|
def get_stack(f, t, botframe, proc_obj=None):
"""Return a stack of frames which the debugger will use for in
showing backtraces and in frame switching. As such various frame
that are really around may be excluded unless we are debugging the
sebugger. Also we will add traceback frame on top if that
exists."""
exclude_frame = lambda f: False
if proc_obj:
settings = proc_obj.debugger.settings
if not settings['dbg_trepan']:
exclude_frame = lambda f: \
proc_obj.core.ignore_filter.is_included(f)
pass
pass
stack = []
if t and t.tb_frame is f:
t = t.tb_next
while f is not None:
if exclude_frame(f): break # See commented alternative below
stack.append((f, f.f_lineno))
# bdb has:
# if f is botframe: break
f = f.f_back
pass
stack.reverse()
i = max(0, len(stack) - 1)
while t is not None:
stack.append((t.tb_frame, t.tb_lineno))
t = t.tb_next
pass
return stack, i
|
def get_stack(f, t, botframe, proc_obj=None):
"""Return a stack of frames which the debugger will use for in
showing backtraces and in frame switching. As such various frame
that are really around may be excluded unless we are debugging the
sebugger. Also we will add traceback frame on top if that
exists."""
exclude_frame = lambda f: False
if proc_obj:
settings = proc_obj.debugger.settings
if not settings['dbg_trepan']:
exclude_frame = lambda f: \
proc_obj.core.ignore_filter.is_included(f)
pass
pass
stack = []
if t and t.tb_frame is f:
t = t.tb_next
while f is not None:
if exclude_frame(f): break # See commented alternative below
stack.append((f, f.f_lineno))
# bdb has:
# if f is botframe: break
f = f.f_back
pass
stack.reverse()
i = max(0, len(stack) - 1)
while t is not None:
stack.append((t.tb_frame, t.tb_lineno))
t = t.tb_next
pass
return stack, i
|
[
"Return",
"a",
"stack",
"of",
"frames",
"which",
"the",
"debugger",
"will",
"use",
"for",
"in",
"showing",
"backtraces",
"and",
"in",
"frame",
"switching",
".",
"As",
"such",
"various",
"frame",
"that",
"are",
"really",
"around",
"may",
"be",
"excluded",
"unless",
"we",
"are",
"debugging",
"the",
"sebugger",
".",
"Also",
"we",
"will",
"add",
"traceback",
"frame",
"on",
"top",
"if",
"that",
"exists",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L75-L105
|
[
"def",
"get_stack",
"(",
"f",
",",
"t",
",",
"botframe",
",",
"proc_obj",
"=",
"None",
")",
":",
"exclude_frame",
"=",
"lambda",
"f",
":",
"False",
"if",
"proc_obj",
":",
"settings",
"=",
"proc_obj",
".",
"debugger",
".",
"settings",
"if",
"not",
"settings",
"[",
"'dbg_trepan'",
"]",
":",
"exclude_frame",
"=",
"lambda",
"f",
":",
"proc_obj",
".",
"core",
".",
"ignore_filter",
".",
"is_included",
"(",
"f",
")",
"pass",
"pass",
"stack",
"=",
"[",
"]",
"if",
"t",
"and",
"t",
".",
"tb_frame",
"is",
"f",
":",
"t",
"=",
"t",
".",
"tb_next",
"while",
"f",
"is",
"not",
"None",
":",
"if",
"exclude_frame",
"(",
"f",
")",
":",
"break",
"# See commented alternative below",
"stack",
".",
"append",
"(",
"(",
"f",
",",
"f",
".",
"f_lineno",
")",
")",
"# bdb has:",
"# if f is botframe: break",
"f",
"=",
"f",
".",
"f_back",
"pass",
"stack",
".",
"reverse",
"(",
")",
"i",
"=",
"max",
"(",
"0",
",",
"len",
"(",
"stack",
")",
"-",
"1",
")",
"while",
"t",
"is",
"not",
"None",
":",
"stack",
".",
"append",
"(",
"(",
"t",
".",
"tb_frame",
",",
"t",
".",
"tb_lineno",
")",
")",
"t",
"=",
"t",
".",
"tb_next",
"pass",
"return",
"stack",
",",
"i"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_hooks
|
Run each function in `hooks' with args
|
trepan/processor/cmdproc.py
|
def run_hooks(obj, hooks, *args):
"""Run each function in `hooks' with args"""
for hook in hooks:
if hook(obj, *args): return True
pass
return False
|
def run_hooks(obj, hooks, *args):
"""Run each function in `hooks' with args"""
for hook in hooks:
if hook(obj, *args): return True
pass
return False
|
[
"Run",
"each",
"function",
"in",
"hooks",
"with",
"args"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L107-L112
|
[
"def",
"run_hooks",
"(",
"obj",
",",
"hooks",
",",
"*",
"args",
")",
":",
"for",
"hook",
"in",
"hooks",
":",
"if",
"hook",
"(",
"obj",
",",
"*",
"args",
")",
":",
"return",
"True",
"pass",
"return",
"False"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
print_source_location_info
|
Print out a source location , e.g. the first line in
line in:
(/tmp.py:2 @21): <module>
L -- 2 import sys,os
(trepan3k)
|
trepan/processor/cmdproc.py
|
def print_source_location_info(print_fn, filename, lineno, fn_name=None,
f_lasti=None, remapped_file=None):
"""Print out a source location , e.g. the first line in
line in:
(/tmp.py:2 @21): <module>
L -- 2 import sys,os
(trepan3k)
"""
if remapped_file:
mess = '(%s:%s remapped %s' % (remapped_file, lineno, filename)
else:
mess = '(%s:%s' % (filename, lineno)
if f_lasti and f_lasti != -1:
mess += ' @%d' % f_lasti
pass
mess += '):'
if fn_name and fn_name != '?':
mess += " %s" % fn_name
pass
print_fn(mess)
return
|
def print_source_location_info(print_fn, filename, lineno, fn_name=None,
f_lasti=None, remapped_file=None):
"""Print out a source location , e.g. the first line in
line in:
(/tmp.py:2 @21): <module>
L -- 2 import sys,os
(trepan3k)
"""
if remapped_file:
mess = '(%s:%s remapped %s' % (remapped_file, lineno, filename)
else:
mess = '(%s:%s' % (filename, lineno)
if f_lasti and f_lasti != -1:
mess += ' @%d' % f_lasti
pass
mess += '):'
if fn_name and fn_name != '?':
mess += " %s" % fn_name
pass
print_fn(mess)
return
|
[
"Print",
"out",
"a",
"source",
"location",
"e",
".",
"g",
".",
"the",
"first",
"line",
"in",
"line",
"in",
":",
"(",
"/",
"tmp",
".",
"py",
":",
"2"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L143-L163
|
[
"def",
"print_source_location_info",
"(",
"print_fn",
",",
"filename",
",",
"lineno",
",",
"fn_name",
"=",
"None",
",",
"f_lasti",
"=",
"None",
",",
"remapped_file",
"=",
"None",
")",
":",
"if",
"remapped_file",
":",
"mess",
"=",
"'(%s:%s remapped %s'",
"%",
"(",
"remapped_file",
",",
"lineno",
",",
"filename",
")",
"else",
":",
"mess",
"=",
"'(%s:%s'",
"%",
"(",
"filename",
",",
"lineno",
")",
"if",
"f_lasti",
"and",
"f_lasti",
"!=",
"-",
"1",
":",
"mess",
"+=",
"' @%d'",
"%",
"f_lasti",
"pass",
"mess",
"+=",
"'):'",
"if",
"fn_name",
"and",
"fn_name",
"!=",
"'?'",
":",
"mess",
"+=",
"\" %s\"",
"%",
"fn_name",
"pass",
"print_fn",
"(",
"mess",
")",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
print_location
|
Show where we are. GUI's and front-end interfaces often
use this to update displays. So it is helpful to make sure
we give at least some place that's located in a file.
|
trepan/processor/cmdproc.py
|
def print_location(proc_obj):
"""Show where we are. GUI's and front-end interfaces often
use this to update displays. So it is helpful to make sure
we give at least some place that's located in a file.
"""
i_stack = proc_obj.curindex
if i_stack is None or proc_obj.stack is None:
return False
core_obj = proc_obj.core
dbgr_obj = proc_obj.debugger
intf_obj = dbgr_obj.intf[-1]
# Evaluation routines like "exec" don't show useful location
# info. In these cases, we will use the position before that in
# the stack. Hence the looping below which in practices loops
# once and sometimes twice.
remapped_file = None
source_text = None
while i_stack >= 0:
frame_lineno = proc_obj.stack[i_stack]
i_stack -= 1
frame, lineno = frame_lineno
# # Next check to see that local variable breadcrumb exists and
# # has the magic dynamic value.
# # If so, it's us and we don't normally show this.a
# if 'breadcrumb' in frame.f_locals:
# if self.run == frame.f_locals['breadcrumb']:
# break
filename = Mstack.frame2file(core_obj, frame, canonic=False)
if '<string>' == filename and dbgr_obj.eval_string:
remapped_file = filename
filename = pyficache.unmap_file(filename)
if '<string>' == filename:
remapped = cmdfns.source_tempfile_remap('eval_string',
dbgr_obj.eval_string)
pyficache.remap_file(filename, remapped)
filename = remapped
lineno = pyficache.unmap_file_line(filename, lineno)
pass
pass
elif '<string>' == filename:
source_text = deparse_fn(frame.f_code)
filename = "<string: '%s'>" % source_text
pass
else:
m = re.search('^<frozen (.*)>', filename)
if m and m.group(1) in pyficache.file2file_remap:
remapped_file = pyficache.file2file_remap[m.group(1)]
pass
elif filename in pyficache.file2file_remap:
remapped_file = pyficache.unmap_file(filename)
# FIXME: a remapped_file shouldn't be the same as its unmapped version
if remapped_file == filename:
remapped_file = None
pass
pass
elif m and m.group(1) in sys.modules:
remapped_file = m.group(1)
pyficache.remap_file(filename, remapped_file)
pass
opts = {
'reload_on_change' : proc_obj.settings('reload'),
'output' : proc_obj.settings('highlight')
}
if 'style' in proc_obj.debugger.settings:
opts['style'] = proc_obj.settings('style')
pyficache.update_cache(filename)
line = pyficache.getline(filename, lineno, opts)
if not line:
if (not source_text and
filename.startswith("<string: ") and proc_obj.curframe.f_code):
# Deparse the code object into a temp file and remap the line from code
# into the corresponding line of the tempfile
co = proc_obj.curframe.f_code
temp_filename, name_for_code = deparse_and_cache(co, proc_obj.errmsg)
lineno = 1
# _, lineno = pyficache.unmap_file_line(temp_filename, lineno, True)
if temp_filename:
filename = temp_filename
pass
else:
# FIXME:
if source_text:
lines = source_text.split("\n")
temp_name='string-'
else:
# try with good ol linecache and consider fixing pyficache
lines = linecache.getlines(filename)
temp_name = filename
if lines:
# FIXME: DRY code with version in cmdproc.py print_location
prefix = os.path.basename(temp_name).split('.')[0]
fd = tempfile.NamedTemporaryFile(suffix='.py',
prefix=prefix,
delete=False)
with fd:
fd.write(''.join(lines))
remapped_file = fd.name
pyficache.remap_file(remapped_file, filename)
fd.close()
pass
line = linecache.getline(filename, lineno,
proc_obj.curframe.f_globals)
if not line:
m = re.search('^<frozen (.*)>', filename)
if m and m.group(1):
remapped_file = m.group(1)
try_module = sys.modules.get(remapped_file)
if (try_module and inspect.ismodule(try_module) and
hasattr(try_module, '__file__')):
remapped_file = sys.modules[remapped_file].__file__
pyficache.remap_file(filename, remapped_file)
line = linecache.getline(remapped_file, lineno,
proc_obj.curframe.f_globals)
else:
remapped_file = m.group(1)
code = proc_obj.curframe.f_code
filename, line = cmdfns.deparse_getline(code, remapped_file,
lineno, opts)
pass
pass
try:
match, reason = Mstack.check_path_with_frame(frame, filename)
if not match:
if filename not in warned_file_mismatches:
proc_obj.errmsg(reason)
warned_file_mismatches.add(filename)
except:
pass
fn_name = frame.f_code.co_name
last_i = frame.f_lasti
print_source_location_info(intf_obj.msg, filename, lineno, fn_name,
remapped_file = remapped_file,
f_lasti = last_i)
if line and len(line.strip()) != 0:
if proc_obj.event:
print_source_line(intf_obj.msg, lineno, line,
proc_obj.event2short[proc_obj.event])
pass
if '<string>' != filename: break
pass
if proc_obj.event in ['return', 'exception']:
val = proc_obj.event_arg
intf_obj.msg('R=> %s' % proc_obj._saferepr(val))
pass
return True
|
def print_location(proc_obj):
"""Show where we are. GUI's and front-end interfaces often
use this to update displays. So it is helpful to make sure
we give at least some place that's located in a file.
"""
i_stack = proc_obj.curindex
if i_stack is None or proc_obj.stack is None:
return False
core_obj = proc_obj.core
dbgr_obj = proc_obj.debugger
intf_obj = dbgr_obj.intf[-1]
# Evaluation routines like "exec" don't show useful location
# info. In these cases, we will use the position before that in
# the stack. Hence the looping below which in practices loops
# once and sometimes twice.
remapped_file = None
source_text = None
while i_stack >= 0:
frame_lineno = proc_obj.stack[i_stack]
i_stack -= 1
frame, lineno = frame_lineno
# # Next check to see that local variable breadcrumb exists and
# # has the magic dynamic value.
# # If so, it's us and we don't normally show this.a
# if 'breadcrumb' in frame.f_locals:
# if self.run == frame.f_locals['breadcrumb']:
# break
filename = Mstack.frame2file(core_obj, frame, canonic=False)
if '<string>' == filename and dbgr_obj.eval_string:
remapped_file = filename
filename = pyficache.unmap_file(filename)
if '<string>' == filename:
remapped = cmdfns.source_tempfile_remap('eval_string',
dbgr_obj.eval_string)
pyficache.remap_file(filename, remapped)
filename = remapped
lineno = pyficache.unmap_file_line(filename, lineno)
pass
pass
elif '<string>' == filename:
source_text = deparse_fn(frame.f_code)
filename = "<string: '%s'>" % source_text
pass
else:
m = re.search('^<frozen (.*)>', filename)
if m and m.group(1) in pyficache.file2file_remap:
remapped_file = pyficache.file2file_remap[m.group(1)]
pass
elif filename in pyficache.file2file_remap:
remapped_file = pyficache.unmap_file(filename)
# FIXME: a remapped_file shouldn't be the same as its unmapped version
if remapped_file == filename:
remapped_file = None
pass
pass
elif m and m.group(1) in sys.modules:
remapped_file = m.group(1)
pyficache.remap_file(filename, remapped_file)
pass
opts = {
'reload_on_change' : proc_obj.settings('reload'),
'output' : proc_obj.settings('highlight')
}
if 'style' in proc_obj.debugger.settings:
opts['style'] = proc_obj.settings('style')
pyficache.update_cache(filename)
line = pyficache.getline(filename, lineno, opts)
if not line:
if (not source_text and
filename.startswith("<string: ") and proc_obj.curframe.f_code):
# Deparse the code object into a temp file and remap the line from code
# into the corresponding line of the tempfile
co = proc_obj.curframe.f_code
temp_filename, name_for_code = deparse_and_cache(co, proc_obj.errmsg)
lineno = 1
# _, lineno = pyficache.unmap_file_line(temp_filename, lineno, True)
if temp_filename:
filename = temp_filename
pass
else:
# FIXME:
if source_text:
lines = source_text.split("\n")
temp_name='string-'
else:
# try with good ol linecache and consider fixing pyficache
lines = linecache.getlines(filename)
temp_name = filename
if lines:
# FIXME: DRY code with version in cmdproc.py print_location
prefix = os.path.basename(temp_name).split('.')[0]
fd = tempfile.NamedTemporaryFile(suffix='.py',
prefix=prefix,
delete=False)
with fd:
fd.write(''.join(lines))
remapped_file = fd.name
pyficache.remap_file(remapped_file, filename)
fd.close()
pass
line = linecache.getline(filename, lineno,
proc_obj.curframe.f_globals)
if not line:
m = re.search('^<frozen (.*)>', filename)
if m and m.group(1):
remapped_file = m.group(1)
try_module = sys.modules.get(remapped_file)
if (try_module and inspect.ismodule(try_module) and
hasattr(try_module, '__file__')):
remapped_file = sys.modules[remapped_file].__file__
pyficache.remap_file(filename, remapped_file)
line = linecache.getline(remapped_file, lineno,
proc_obj.curframe.f_globals)
else:
remapped_file = m.group(1)
code = proc_obj.curframe.f_code
filename, line = cmdfns.deparse_getline(code, remapped_file,
lineno, opts)
pass
pass
try:
match, reason = Mstack.check_path_with_frame(frame, filename)
if not match:
if filename not in warned_file_mismatches:
proc_obj.errmsg(reason)
warned_file_mismatches.add(filename)
except:
pass
fn_name = frame.f_code.co_name
last_i = frame.f_lasti
print_source_location_info(intf_obj.msg, filename, lineno, fn_name,
remapped_file = remapped_file,
f_lasti = last_i)
if line and len(line.strip()) != 0:
if proc_obj.event:
print_source_line(intf_obj.msg, lineno, line,
proc_obj.event2short[proc_obj.event])
pass
if '<string>' != filename: break
pass
if proc_obj.event in ['return', 'exception']:
val = proc_obj.event_arg
intf_obj.msg('R=> %s' % proc_obj._saferepr(val))
pass
return True
|
[
"Show",
"where",
"we",
"are",
".",
"GUI",
"s",
"and",
"front",
"-",
"end",
"interfaces",
"often",
"use",
"this",
"to",
"update",
"displays",
".",
"So",
"it",
"is",
"helpful",
"to",
"make",
"sure",
"we",
"give",
"at",
"least",
"some",
"place",
"that",
"s",
"located",
"in",
"a",
"file",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L165-L319
|
[
"def",
"print_location",
"(",
"proc_obj",
")",
":",
"i_stack",
"=",
"proc_obj",
".",
"curindex",
"if",
"i_stack",
"is",
"None",
"or",
"proc_obj",
".",
"stack",
"is",
"None",
":",
"return",
"False",
"core_obj",
"=",
"proc_obj",
".",
"core",
"dbgr_obj",
"=",
"proc_obj",
".",
"debugger",
"intf_obj",
"=",
"dbgr_obj",
".",
"intf",
"[",
"-",
"1",
"]",
"# Evaluation routines like \"exec\" don't show useful location",
"# info. In these cases, we will use the position before that in",
"# the stack. Hence the looping below which in practices loops",
"# once and sometimes twice.",
"remapped_file",
"=",
"None",
"source_text",
"=",
"None",
"while",
"i_stack",
">=",
"0",
":",
"frame_lineno",
"=",
"proc_obj",
".",
"stack",
"[",
"i_stack",
"]",
"i_stack",
"-=",
"1",
"frame",
",",
"lineno",
"=",
"frame_lineno",
"# # Next check to see that local variable breadcrumb exists and",
"# # has the magic dynamic value.",
"# # If so, it's us and we don't normally show this.a",
"# if 'breadcrumb' in frame.f_locals:",
"# if self.run == frame.f_locals['breadcrumb']:",
"# break",
"filename",
"=",
"Mstack",
".",
"frame2file",
"(",
"core_obj",
",",
"frame",
",",
"canonic",
"=",
"False",
")",
"if",
"'<string>'",
"==",
"filename",
"and",
"dbgr_obj",
".",
"eval_string",
":",
"remapped_file",
"=",
"filename",
"filename",
"=",
"pyficache",
".",
"unmap_file",
"(",
"filename",
")",
"if",
"'<string>'",
"==",
"filename",
":",
"remapped",
"=",
"cmdfns",
".",
"source_tempfile_remap",
"(",
"'eval_string'",
",",
"dbgr_obj",
".",
"eval_string",
")",
"pyficache",
".",
"remap_file",
"(",
"filename",
",",
"remapped",
")",
"filename",
"=",
"remapped",
"lineno",
"=",
"pyficache",
".",
"unmap_file_line",
"(",
"filename",
",",
"lineno",
")",
"pass",
"pass",
"elif",
"'<string>'",
"==",
"filename",
":",
"source_text",
"=",
"deparse_fn",
"(",
"frame",
".",
"f_code",
")",
"filename",
"=",
"\"<string: '%s'>\"",
"%",
"source_text",
"pass",
"else",
":",
"m",
"=",
"re",
".",
"search",
"(",
"'^<frozen (.*)>'",
",",
"filename",
")",
"if",
"m",
"and",
"m",
".",
"group",
"(",
"1",
")",
"in",
"pyficache",
".",
"file2file_remap",
":",
"remapped_file",
"=",
"pyficache",
".",
"file2file_remap",
"[",
"m",
".",
"group",
"(",
"1",
")",
"]",
"pass",
"elif",
"filename",
"in",
"pyficache",
".",
"file2file_remap",
":",
"remapped_file",
"=",
"pyficache",
".",
"unmap_file",
"(",
"filename",
")",
"# FIXME: a remapped_file shouldn't be the same as its unmapped version",
"if",
"remapped_file",
"==",
"filename",
":",
"remapped_file",
"=",
"None",
"pass",
"pass",
"elif",
"m",
"and",
"m",
".",
"group",
"(",
"1",
")",
"in",
"sys",
".",
"modules",
":",
"remapped_file",
"=",
"m",
".",
"group",
"(",
"1",
")",
"pyficache",
".",
"remap_file",
"(",
"filename",
",",
"remapped_file",
")",
"pass",
"opts",
"=",
"{",
"'reload_on_change'",
":",
"proc_obj",
".",
"settings",
"(",
"'reload'",
")",
",",
"'output'",
":",
"proc_obj",
".",
"settings",
"(",
"'highlight'",
")",
"}",
"if",
"'style'",
"in",
"proc_obj",
".",
"debugger",
".",
"settings",
":",
"opts",
"[",
"'style'",
"]",
"=",
"proc_obj",
".",
"settings",
"(",
"'style'",
")",
"pyficache",
".",
"update_cache",
"(",
"filename",
")",
"line",
"=",
"pyficache",
".",
"getline",
"(",
"filename",
",",
"lineno",
",",
"opts",
")",
"if",
"not",
"line",
":",
"if",
"(",
"not",
"source_text",
"and",
"filename",
".",
"startswith",
"(",
"\"<string: \"",
")",
"and",
"proc_obj",
".",
"curframe",
".",
"f_code",
")",
":",
"# Deparse the code object into a temp file and remap the line from code",
"# into the corresponding line of the tempfile",
"co",
"=",
"proc_obj",
".",
"curframe",
".",
"f_code",
"temp_filename",
",",
"name_for_code",
"=",
"deparse_and_cache",
"(",
"co",
",",
"proc_obj",
".",
"errmsg",
")",
"lineno",
"=",
"1",
"# _, lineno = pyficache.unmap_file_line(temp_filename, lineno, True)",
"if",
"temp_filename",
":",
"filename",
"=",
"temp_filename",
"pass",
"else",
":",
"# FIXME:",
"if",
"source_text",
":",
"lines",
"=",
"source_text",
".",
"split",
"(",
"\"\\n\"",
")",
"temp_name",
"=",
"'string-'",
"else",
":",
"# try with good ol linecache and consider fixing pyficache",
"lines",
"=",
"linecache",
".",
"getlines",
"(",
"filename",
")",
"temp_name",
"=",
"filename",
"if",
"lines",
":",
"# FIXME: DRY code with version in cmdproc.py print_location",
"prefix",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"temp_name",
")",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"fd",
"=",
"tempfile",
".",
"NamedTemporaryFile",
"(",
"suffix",
"=",
"'.py'",
",",
"prefix",
"=",
"prefix",
",",
"delete",
"=",
"False",
")",
"with",
"fd",
":",
"fd",
".",
"write",
"(",
"''",
".",
"join",
"(",
"lines",
")",
")",
"remapped_file",
"=",
"fd",
".",
"name",
"pyficache",
".",
"remap_file",
"(",
"remapped_file",
",",
"filename",
")",
"fd",
".",
"close",
"(",
")",
"pass",
"line",
"=",
"linecache",
".",
"getline",
"(",
"filename",
",",
"lineno",
",",
"proc_obj",
".",
"curframe",
".",
"f_globals",
")",
"if",
"not",
"line",
":",
"m",
"=",
"re",
".",
"search",
"(",
"'^<frozen (.*)>'",
",",
"filename",
")",
"if",
"m",
"and",
"m",
".",
"group",
"(",
"1",
")",
":",
"remapped_file",
"=",
"m",
".",
"group",
"(",
"1",
")",
"try_module",
"=",
"sys",
".",
"modules",
".",
"get",
"(",
"remapped_file",
")",
"if",
"(",
"try_module",
"and",
"inspect",
".",
"ismodule",
"(",
"try_module",
")",
"and",
"hasattr",
"(",
"try_module",
",",
"'__file__'",
")",
")",
":",
"remapped_file",
"=",
"sys",
".",
"modules",
"[",
"remapped_file",
"]",
".",
"__file__",
"pyficache",
".",
"remap_file",
"(",
"filename",
",",
"remapped_file",
")",
"line",
"=",
"linecache",
".",
"getline",
"(",
"remapped_file",
",",
"lineno",
",",
"proc_obj",
".",
"curframe",
".",
"f_globals",
")",
"else",
":",
"remapped_file",
"=",
"m",
".",
"group",
"(",
"1",
")",
"code",
"=",
"proc_obj",
".",
"curframe",
".",
"f_code",
"filename",
",",
"line",
"=",
"cmdfns",
".",
"deparse_getline",
"(",
"code",
",",
"remapped_file",
",",
"lineno",
",",
"opts",
")",
"pass",
"pass",
"try",
":",
"match",
",",
"reason",
"=",
"Mstack",
".",
"check_path_with_frame",
"(",
"frame",
",",
"filename",
")",
"if",
"not",
"match",
":",
"if",
"filename",
"not",
"in",
"warned_file_mismatches",
":",
"proc_obj",
".",
"errmsg",
"(",
"reason",
")",
"warned_file_mismatches",
".",
"add",
"(",
"filename",
")",
"except",
":",
"pass",
"fn_name",
"=",
"frame",
".",
"f_code",
".",
"co_name",
"last_i",
"=",
"frame",
".",
"f_lasti",
"print_source_location_info",
"(",
"intf_obj",
".",
"msg",
",",
"filename",
",",
"lineno",
",",
"fn_name",
",",
"remapped_file",
"=",
"remapped_file",
",",
"f_lasti",
"=",
"last_i",
")",
"if",
"line",
"and",
"len",
"(",
"line",
".",
"strip",
"(",
")",
")",
"!=",
"0",
":",
"if",
"proc_obj",
".",
"event",
":",
"print_source_line",
"(",
"intf_obj",
".",
"msg",
",",
"lineno",
",",
"line",
",",
"proc_obj",
".",
"event2short",
"[",
"proc_obj",
".",
"event",
"]",
")",
"pass",
"if",
"'<string>'",
"!=",
"filename",
":",
"break",
"pass",
"if",
"proc_obj",
".",
"event",
"in",
"[",
"'return'",
",",
"'exception'",
"]",
":",
"val",
"=",
"proc_obj",
".",
"event_arg",
"intf_obj",
".",
"msg",
"(",
"'R=> %s'",
"%",
"proc_obj",
".",
"_saferepr",
"(",
"val",
")",
")",
"pass",
"return",
"True"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.event_processor
|
command event processor: reading a commands do something with them.
|
trepan/processor/cmdproc.py
|
def event_processor(self, frame, event, event_arg, prompt='trepan3k'):
'command event processor: reading a commands do something with them.'
self.frame = frame
self.event = event
self.event_arg = event_arg
filename = frame.f_code.co_filename
lineno = frame.f_lineno
line = linecache.getline(filename, lineno, frame.f_globals)
if not line:
opts = {'output': 'plain',
'reload_on_change': self.settings('reload'),
'strip_nl': False}
m = re.search('^<frozen (.*)>', filename)
if m and m.group(1):
filename = pyficache.unmap_file(m.group(1))
line = pyficache.getline(filename, lineno, opts)
self.current_source_text = line
if self.settings('skip') is not None:
if Mbytecode.is_def_stmt(line, frame):
return True
if Mbytecode.is_class_def(line, frame):
return True
pass
self.thread_name = Mthread.current_thread_name()
self.frame_thread_name = self.thread_name
self.set_prompt(prompt)
self.process_commands()
if filename == '<string>': pyficache.remove_remap_file('<string>')
return True
|
def event_processor(self, frame, event, event_arg, prompt='trepan3k'):
'command event processor: reading a commands do something with them.'
self.frame = frame
self.event = event
self.event_arg = event_arg
filename = frame.f_code.co_filename
lineno = frame.f_lineno
line = linecache.getline(filename, lineno, frame.f_globals)
if not line:
opts = {'output': 'plain',
'reload_on_change': self.settings('reload'),
'strip_nl': False}
m = re.search('^<frozen (.*)>', filename)
if m and m.group(1):
filename = pyficache.unmap_file(m.group(1))
line = pyficache.getline(filename, lineno, opts)
self.current_source_text = line
if self.settings('skip') is not None:
if Mbytecode.is_def_stmt(line, frame):
return True
if Mbytecode.is_class_def(line, frame):
return True
pass
self.thread_name = Mthread.current_thread_name()
self.frame_thread_name = self.thread_name
self.set_prompt(prompt)
self.process_commands()
if filename == '<string>': pyficache.remove_remap_file('<string>')
return True
|
[
"command",
"event",
"processor",
":",
"reading",
"a",
"commands",
"do",
"something",
"with",
"them",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L438-L467
|
[
"def",
"event_processor",
"(",
"self",
",",
"frame",
",",
"event",
",",
"event_arg",
",",
"prompt",
"=",
"'trepan3k'",
")",
":",
"self",
".",
"frame",
"=",
"frame",
"self",
".",
"event",
"=",
"event",
"self",
".",
"event_arg",
"=",
"event_arg",
"filename",
"=",
"frame",
".",
"f_code",
".",
"co_filename",
"lineno",
"=",
"frame",
".",
"f_lineno",
"line",
"=",
"linecache",
".",
"getline",
"(",
"filename",
",",
"lineno",
",",
"frame",
".",
"f_globals",
")",
"if",
"not",
"line",
":",
"opts",
"=",
"{",
"'output'",
":",
"'plain'",
",",
"'reload_on_change'",
":",
"self",
".",
"settings",
"(",
"'reload'",
")",
",",
"'strip_nl'",
":",
"False",
"}",
"m",
"=",
"re",
".",
"search",
"(",
"'^<frozen (.*)>'",
",",
"filename",
")",
"if",
"m",
"and",
"m",
".",
"group",
"(",
"1",
")",
":",
"filename",
"=",
"pyficache",
".",
"unmap_file",
"(",
"m",
".",
"group",
"(",
"1",
")",
")",
"line",
"=",
"pyficache",
".",
"getline",
"(",
"filename",
",",
"lineno",
",",
"opts",
")",
"self",
".",
"current_source_text",
"=",
"line",
"if",
"self",
".",
"settings",
"(",
"'skip'",
")",
"is",
"not",
"None",
":",
"if",
"Mbytecode",
".",
"is_def_stmt",
"(",
"line",
",",
"frame",
")",
":",
"return",
"True",
"if",
"Mbytecode",
".",
"is_class_def",
"(",
"line",
",",
"frame",
")",
":",
"return",
"True",
"pass",
"self",
".",
"thread_name",
"=",
"Mthread",
".",
"current_thread_name",
"(",
")",
"self",
".",
"frame_thread_name",
"=",
"self",
".",
"thread_name",
"self",
".",
"set_prompt",
"(",
"prompt",
")",
"self",
".",
"process_commands",
"(",
")",
"if",
"filename",
"==",
"'<string>'",
":",
"pyficache",
".",
"remove_remap_file",
"(",
"'<string>'",
")",
"return",
"True"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.forget
|
Remove memory of state variables set in the command processor
|
trepan/processor/cmdproc.py
|
def forget(self):
""" Remove memory of state variables set in the command processor """
self.stack = []
self.curindex = 0
self.curframe = None
self.thread_name = None
self.frame_thread_name = None
return
|
def forget(self):
""" Remove memory of state variables set in the command processor """
self.stack = []
self.curindex = 0
self.curframe = None
self.thread_name = None
self.frame_thread_name = None
return
|
[
"Remove",
"memory",
"of",
"state",
"variables",
"set",
"in",
"the",
"command",
"processor"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L469-L476
|
[
"def",
"forget",
"(",
"self",
")",
":",
"self",
".",
"stack",
"=",
"[",
"]",
"self",
".",
"curindex",
"=",
"0",
"self",
".",
"curframe",
"=",
"None",
"self",
".",
"thread_name",
"=",
"None",
"self",
".",
"frame_thread_name",
"=",
"None",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.get_an_int
|
Like cmdfns.get_an_int(), but if there's a stack frame use that
in evaluation.
|
trepan/processor/cmdproc.py
|
def get_an_int(self, arg, msg_on_error, min_value=None, max_value=None):
"""Like cmdfns.get_an_int(), but if there's a stack frame use that
in evaluation."""
ret_value = self.get_int_noerr(arg)
if ret_value is None:
if msg_on_error:
self.errmsg(msg_on_error)
else:
self.errmsg('Expecting an integer, got: %s.' % str(arg))
pass
return None
if min_value and ret_value < min_value:
self.errmsg('Expecting integer value to be at least %d, got: %d.' %
(min_value, ret_value))
return None
elif max_value and ret_value > max_value:
self.errmsg('Expecting integer value to be at most %d, got: %d.' %
(max_value, ret_value))
return None
return ret_value
|
def get_an_int(self, arg, msg_on_error, min_value=None, max_value=None):
"""Like cmdfns.get_an_int(), but if there's a stack frame use that
in evaluation."""
ret_value = self.get_int_noerr(arg)
if ret_value is None:
if msg_on_error:
self.errmsg(msg_on_error)
else:
self.errmsg('Expecting an integer, got: %s.' % str(arg))
pass
return None
if min_value and ret_value < min_value:
self.errmsg('Expecting integer value to be at least %d, got: %d.' %
(min_value, ret_value))
return None
elif max_value and ret_value > max_value:
self.errmsg('Expecting integer value to be at most %d, got: %d.' %
(max_value, ret_value))
return None
return ret_value
|
[
"Like",
"cmdfns",
".",
"get_an_int",
"()",
"but",
"if",
"there",
"s",
"a",
"stack",
"frame",
"use",
"that",
"in",
"evaluation",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L516-L535
|
[
"def",
"get_an_int",
"(",
"self",
",",
"arg",
",",
"msg_on_error",
",",
"min_value",
"=",
"None",
",",
"max_value",
"=",
"None",
")",
":",
"ret_value",
"=",
"self",
".",
"get_int_noerr",
"(",
"arg",
")",
"if",
"ret_value",
"is",
"None",
":",
"if",
"msg_on_error",
":",
"self",
".",
"errmsg",
"(",
"msg_on_error",
")",
"else",
":",
"self",
".",
"errmsg",
"(",
"'Expecting an integer, got: %s.'",
"%",
"str",
"(",
"arg",
")",
")",
"pass",
"return",
"None",
"if",
"min_value",
"and",
"ret_value",
"<",
"min_value",
":",
"self",
".",
"errmsg",
"(",
"'Expecting integer value to be at least %d, got: %d.'",
"%",
"(",
"min_value",
",",
"ret_value",
")",
")",
"return",
"None",
"elif",
"max_value",
"and",
"ret_value",
">",
"max_value",
":",
"self",
".",
"errmsg",
"(",
"'Expecting integer value to be at most %d, got: %d.'",
"%",
"(",
"max_value",
",",
"ret_value",
")",
")",
"return",
"None",
"return",
"ret_value"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.get_int_noerr
|
Eval arg and it is an integer return the value. Otherwise
return None
|
trepan/processor/cmdproc.py
|
def get_int_noerr(self, arg):
"""Eval arg and it is an integer return the value. Otherwise
return None"""
if self.curframe:
g = self.curframe.f_globals
l = self.curframe.f_locals
else:
g = globals()
l = locals()
pass
try:
val = int(eval(arg, g, l))
except (SyntaxError, NameError, ValueError, TypeError):
return None
return val
|
def get_int_noerr(self, arg):
"""Eval arg and it is an integer return the value. Otherwise
return None"""
if self.curframe:
g = self.curframe.f_globals
l = self.curframe.f_locals
else:
g = globals()
l = locals()
pass
try:
val = int(eval(arg, g, l))
except (SyntaxError, NameError, ValueError, TypeError):
return None
return val
|
[
"Eval",
"arg",
"and",
"it",
"is",
"an",
"integer",
"return",
"the",
"value",
".",
"Otherwise",
"return",
"None"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L537-L551
|
[
"def",
"get_int_noerr",
"(",
"self",
",",
"arg",
")",
":",
"if",
"self",
".",
"curframe",
":",
"g",
"=",
"self",
".",
"curframe",
".",
"f_globals",
"l",
"=",
"self",
".",
"curframe",
".",
"f_locals",
"else",
":",
"g",
"=",
"globals",
"(",
")",
"l",
"=",
"locals",
"(",
")",
"pass",
"try",
":",
"val",
"=",
"int",
"(",
"eval",
"(",
"arg",
",",
"g",
",",
"l",
")",
")",
"except",
"(",
"SyntaxError",
",",
"NameError",
",",
"ValueError",
",",
"TypeError",
")",
":",
"return",
"None",
"return",
"val"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.get_int
|
If no argument use the default. If arg is a an integer between
least min_value and at_most, use that. Otherwise report an error.
If there's a stack frame use that in evaluation.
|
trepan/processor/cmdproc.py
|
def get_int(self, arg, min_value=0, default=1, cmdname=None,
at_most=None):
"""If no argument use the default. If arg is a an integer between
least min_value and at_most, use that. Otherwise report an error.
If there's a stack frame use that in evaluation."""
if arg is None: return default
default = self.get_int_noerr(arg)
if default is None:
if cmdname:
self.errmsg(("Command '%s' expects an integer; "
+ "got: %s.") % (cmdname, str(arg)))
else:
self.errmsg('Expecting a positive integer, got: %s'
% str(arg))
pass
return None
pass
if default < min_value:
if cmdname:
self.errmsg(("Command '%s' expects an integer at least" +
' %d; got: %d.')
% (cmdname, min_value, default))
else:
self.errmsg(("Expecting a positive integer at least" +
' %d; got: %d')
% (min_value, default))
pass
return None
elif at_most and default > at_most:
if cmdname:
self.errmsg(("Command '%s' expects an integer at most" +
' %d; got: %d.')
% (cmdname, at_most, default))
else:
self.errmsg(("Expecting an integer at most %d; got: %d")
% (at_most, default))
pass
pass
return default
|
def get_int(self, arg, min_value=0, default=1, cmdname=None,
at_most=None):
"""If no argument use the default. If arg is a an integer between
least min_value and at_most, use that. Otherwise report an error.
If there's a stack frame use that in evaluation."""
if arg is None: return default
default = self.get_int_noerr(arg)
if default is None:
if cmdname:
self.errmsg(("Command '%s' expects an integer; "
+ "got: %s.") % (cmdname, str(arg)))
else:
self.errmsg('Expecting a positive integer, got: %s'
% str(arg))
pass
return None
pass
if default < min_value:
if cmdname:
self.errmsg(("Command '%s' expects an integer at least" +
' %d; got: %d.')
% (cmdname, min_value, default))
else:
self.errmsg(("Expecting a positive integer at least" +
' %d; got: %d')
% (min_value, default))
pass
return None
elif at_most and default > at_most:
if cmdname:
self.errmsg(("Command '%s' expects an integer at most" +
' %d; got: %d.')
% (cmdname, at_most, default))
else:
self.errmsg(("Expecting an integer at most %d; got: %d")
% (at_most, default))
pass
pass
return default
|
[
"If",
"no",
"argument",
"use",
"the",
"default",
".",
"If",
"arg",
"is",
"a",
"an",
"integer",
"between",
"least",
"min_value",
"and",
"at_most",
"use",
"that",
".",
"Otherwise",
"report",
"an",
"error",
".",
"If",
"there",
"s",
"a",
"stack",
"frame",
"use",
"that",
"in",
"evaluation",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L553-L592
|
[
"def",
"get_int",
"(",
"self",
",",
"arg",
",",
"min_value",
"=",
"0",
",",
"default",
"=",
"1",
",",
"cmdname",
"=",
"None",
",",
"at_most",
"=",
"None",
")",
":",
"if",
"arg",
"is",
"None",
":",
"return",
"default",
"default",
"=",
"self",
".",
"get_int_noerr",
"(",
"arg",
")",
"if",
"default",
"is",
"None",
":",
"if",
"cmdname",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Command '%s' expects an integer; \"",
"+",
"\"got: %s.\"",
")",
"%",
"(",
"cmdname",
",",
"str",
"(",
"arg",
")",
")",
")",
"else",
":",
"self",
".",
"errmsg",
"(",
"'Expecting a positive integer, got: %s'",
"%",
"str",
"(",
"arg",
")",
")",
"pass",
"return",
"None",
"pass",
"if",
"default",
"<",
"min_value",
":",
"if",
"cmdname",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Command '%s' expects an integer at least\"",
"+",
"' %d; got: %d.'",
")",
"%",
"(",
"cmdname",
",",
"min_value",
",",
"default",
")",
")",
"else",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Expecting a positive integer at least\"",
"+",
"' %d; got: %d'",
")",
"%",
"(",
"min_value",
",",
"default",
")",
")",
"pass",
"return",
"None",
"elif",
"at_most",
"and",
"default",
">",
"at_most",
":",
"if",
"cmdname",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Command '%s' expects an integer at most\"",
"+",
"' %d; got: %d.'",
")",
"%",
"(",
"cmdname",
",",
"at_most",
",",
"default",
")",
")",
"else",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Expecting an integer at most %d; got: %d\"",
")",
"%",
"(",
"at_most",
",",
"default",
")",
")",
"pass",
"pass",
"return",
"default"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.ok_for_running
|
We separate some of the common debugger command checks here:
whether it makes sense to run the command in this execution state,
if the command has the right number of arguments and so on.
|
trepan/processor/cmdproc.py
|
def ok_for_running(self, cmd_obj, name, nargs):
"""We separate some of the common debugger command checks here:
whether it makes sense to run the command in this execution state,
if the command has the right number of arguments and so on.
"""
if hasattr(cmd_obj, 'execution_set'):
if not (self.core.execution_status in cmd_obj.execution_set):
part1 = ("Command '%s' is not available for execution status:"
% name)
mess = Mmisc.wrapped_lines(part1,
self.core.execution_status,
self.debugger.settings['width'])
self.errmsg(mess)
return False
pass
if self.frame is None and cmd_obj.need_stack:
self.intf[-1].errmsg("Command '%s' needs an execution stack."
% name)
return False
if nargs < cmd_obj.min_args:
self.errmsg(("Command '%s' needs at least %d argument(s); " +
"got %d.") %
(name, cmd_obj.min_args, nargs))
return False
elif cmd_obj.max_args is not None and nargs > cmd_obj.max_args:
self.errmsg(("Command '%s' can take at most %d argument(s);" +
" got %d.") %
(name, cmd_obj.max_args, nargs))
return False
return True
|
def ok_for_running(self, cmd_obj, name, nargs):
"""We separate some of the common debugger command checks here:
whether it makes sense to run the command in this execution state,
if the command has the right number of arguments and so on.
"""
if hasattr(cmd_obj, 'execution_set'):
if not (self.core.execution_status in cmd_obj.execution_set):
part1 = ("Command '%s' is not available for execution status:"
% name)
mess = Mmisc.wrapped_lines(part1,
self.core.execution_status,
self.debugger.settings['width'])
self.errmsg(mess)
return False
pass
if self.frame is None and cmd_obj.need_stack:
self.intf[-1].errmsg("Command '%s' needs an execution stack."
% name)
return False
if nargs < cmd_obj.min_args:
self.errmsg(("Command '%s' needs at least %d argument(s); " +
"got %d.") %
(name, cmd_obj.min_args, nargs))
return False
elif cmd_obj.max_args is not None and nargs > cmd_obj.max_args:
self.errmsg(("Command '%s' can take at most %d argument(s);" +
" got %d.") %
(name, cmd_obj.max_args, nargs))
return False
return True
|
[
"We",
"separate",
"some",
"of",
"the",
"common",
"debugger",
"command",
"checks",
"here",
":",
"whether",
"it",
"makes",
"sense",
"to",
"run",
"the",
"command",
"in",
"this",
"execution",
"state",
"if",
"the",
"command",
"has",
"the",
"right",
"number",
"of",
"arguments",
"and",
"so",
"on",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L608-L637
|
[
"def",
"ok_for_running",
"(",
"self",
",",
"cmd_obj",
",",
"name",
",",
"nargs",
")",
":",
"if",
"hasattr",
"(",
"cmd_obj",
",",
"'execution_set'",
")",
":",
"if",
"not",
"(",
"self",
".",
"core",
".",
"execution_status",
"in",
"cmd_obj",
".",
"execution_set",
")",
":",
"part1",
"=",
"(",
"\"Command '%s' is not available for execution status:\"",
"%",
"name",
")",
"mess",
"=",
"Mmisc",
".",
"wrapped_lines",
"(",
"part1",
",",
"self",
".",
"core",
".",
"execution_status",
",",
"self",
".",
"debugger",
".",
"settings",
"[",
"'width'",
"]",
")",
"self",
".",
"errmsg",
"(",
"mess",
")",
"return",
"False",
"pass",
"if",
"self",
".",
"frame",
"is",
"None",
"and",
"cmd_obj",
".",
"need_stack",
":",
"self",
".",
"intf",
"[",
"-",
"1",
"]",
".",
"errmsg",
"(",
"\"Command '%s' needs an execution stack.\"",
"%",
"name",
")",
"return",
"False",
"if",
"nargs",
"<",
"cmd_obj",
".",
"min_args",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Command '%s' needs at least %d argument(s); \"",
"+",
"\"got %d.\"",
")",
"%",
"(",
"name",
",",
"cmd_obj",
".",
"min_args",
",",
"nargs",
")",
")",
"return",
"False",
"elif",
"cmd_obj",
".",
"max_args",
"is",
"not",
"None",
"and",
"nargs",
">",
"cmd_obj",
".",
"max_args",
":",
"self",
".",
"errmsg",
"(",
"(",
"\"Command '%s' can take at most %d argument(s);\"",
"+",
"\" got %d.\"",
")",
"%",
"(",
"name",
",",
"cmd_obj",
".",
"max_args",
",",
"nargs",
")",
")",
"return",
"False",
"return",
"True"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.process_commands
|
Handle debugger commands.
|
trepan/processor/cmdproc.py
|
def process_commands(self):
"""Handle debugger commands."""
if self.core.execution_status != 'No program':
self.setup()
self.location()
pass
leave_loop = run_hooks(self, self.preloop_hooks)
self.continue_running = False
while not leave_loop:
try:
run_hooks(self, self.precmd_hooks)
# bdb had a True return to leave loop.
# A more straight-forward way is to set
# instance variable self.continue_running.
leave_loop = self.process_command()
if leave_loop or self.continue_running: break
except EOFError:
# If we have stacked interfaces, pop to the next
# one. If this is the last one however, we'll
# just stick with that. FIXME: Possibly we should
# check to see if we are interactive. and not
# leave if that's the case. Is this the right
# thing? investigate and fix.
if len(self.debugger.intf) > 1:
del self.debugger.intf[-1]
self.last_command = ''
else:
if self.debugger.intf[-1].output:
self.debugger.intf[-1].output.writeline('Leaving')
raise Mexcept.DebuggerQuit
pass
break
pass
pass
return run_hooks(self, self.postcmd_hooks)
|
def process_commands(self):
"""Handle debugger commands."""
if self.core.execution_status != 'No program':
self.setup()
self.location()
pass
leave_loop = run_hooks(self, self.preloop_hooks)
self.continue_running = False
while not leave_loop:
try:
run_hooks(self, self.precmd_hooks)
# bdb had a True return to leave loop.
# A more straight-forward way is to set
# instance variable self.continue_running.
leave_loop = self.process_command()
if leave_loop or self.continue_running: break
except EOFError:
# If we have stacked interfaces, pop to the next
# one. If this is the last one however, we'll
# just stick with that. FIXME: Possibly we should
# check to see if we are interactive. and not
# leave if that's the case. Is this the right
# thing? investigate and fix.
if len(self.debugger.intf) > 1:
del self.debugger.intf[-1]
self.last_command = ''
else:
if self.debugger.intf[-1].output:
self.debugger.intf[-1].output.writeline('Leaving')
raise Mexcept.DebuggerQuit
pass
break
pass
pass
return run_hooks(self, self.postcmd_hooks)
|
[
"Handle",
"debugger",
"commands",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L639-L674
|
[
"def",
"process_commands",
"(",
"self",
")",
":",
"if",
"self",
".",
"core",
".",
"execution_status",
"!=",
"'No program'",
":",
"self",
".",
"setup",
"(",
")",
"self",
".",
"location",
"(",
")",
"pass",
"leave_loop",
"=",
"run_hooks",
"(",
"self",
",",
"self",
".",
"preloop_hooks",
")",
"self",
".",
"continue_running",
"=",
"False",
"while",
"not",
"leave_loop",
":",
"try",
":",
"run_hooks",
"(",
"self",
",",
"self",
".",
"precmd_hooks",
")",
"# bdb had a True return to leave loop.",
"# A more straight-forward way is to set",
"# instance variable self.continue_running.",
"leave_loop",
"=",
"self",
".",
"process_command",
"(",
")",
"if",
"leave_loop",
"or",
"self",
".",
"continue_running",
":",
"break",
"except",
"EOFError",
":",
"# If we have stacked interfaces, pop to the next",
"# one. If this is the last one however, we'll",
"# just stick with that. FIXME: Possibly we should",
"# check to see if we are interactive. and not",
"# leave if that's the case. Is this the right",
"# thing? investigate and fix.",
"if",
"len",
"(",
"self",
".",
"debugger",
".",
"intf",
")",
">",
"1",
":",
"del",
"self",
".",
"debugger",
".",
"intf",
"[",
"-",
"1",
"]",
"self",
".",
"last_command",
"=",
"''",
"else",
":",
"if",
"self",
".",
"debugger",
".",
"intf",
"[",
"-",
"1",
"]",
".",
"output",
":",
"self",
".",
"debugger",
".",
"intf",
"[",
"-",
"1",
"]",
".",
"output",
".",
"writeline",
"(",
"'Leaving'",
")",
"raise",
"Mexcept",
".",
"DebuggerQuit",
"pass",
"break",
"pass",
"pass",
"return",
"run_hooks",
"(",
"self",
",",
"self",
".",
"postcmd_hooks",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.setup
|
Initialization done before entering the debugger-command
loop. In particular we set up the call stack used for local
variable lookup and frame/up/down commands.
We return True if we should NOT enter the debugger-command
loop.
|
trepan/processor/cmdproc.py
|
def setup(self):
"""Initialization done before entering the debugger-command
loop. In particular we set up the call stack used for local
variable lookup and frame/up/down commands.
We return True if we should NOT enter the debugger-command
loop."""
self.forget()
if self.settings('dbg_trepan'):
self.frame = inspect.currentframe()
pass
if self.event in ['exception', 'c_exception']:
exc_type, exc_value, exc_traceback = self.event_arg
else:
_, _, exc_traceback = (None, None, None,) # NOQA
pass
if self.frame or exc_traceback:
self.stack, self.curindex = \
get_stack(self.frame, exc_traceback, None, self)
self.curframe = self.stack[self.curindex][0]
self.thread_name = Mthread.current_thread_name()
if exc_traceback:
self.list_lineno = traceback.extract_tb(exc_traceback, 1)[0][1]
self.list_offset = self.curframe.f_lasti
self.list_object = self.curframe
else:
self.stack = self.curframe = \
self.botframe = None
pass
if self.curframe:
self.list_lineno = \
max(1, inspect.getlineno(self.curframe)
- int(self.settings('listsize') / 2)) - 1
self.list_offset = self.curframe.f_lasti
self.list_filename = self.curframe.f_code.co_filename
self.list_object = self.curframe
else:
if not exc_traceback: self.list_lineno = None
pass
# if self.execRcLines()==1: return True
# FIXME: do we want to save self.list_lineno a second place
# so that we can do 'list .' and go back to the first place we listed?
return False
|
def setup(self):
"""Initialization done before entering the debugger-command
loop. In particular we set up the call stack used for local
variable lookup and frame/up/down commands.
We return True if we should NOT enter the debugger-command
loop."""
self.forget()
if self.settings('dbg_trepan'):
self.frame = inspect.currentframe()
pass
if self.event in ['exception', 'c_exception']:
exc_type, exc_value, exc_traceback = self.event_arg
else:
_, _, exc_traceback = (None, None, None,) # NOQA
pass
if self.frame or exc_traceback:
self.stack, self.curindex = \
get_stack(self.frame, exc_traceback, None, self)
self.curframe = self.stack[self.curindex][0]
self.thread_name = Mthread.current_thread_name()
if exc_traceback:
self.list_lineno = traceback.extract_tb(exc_traceback, 1)[0][1]
self.list_offset = self.curframe.f_lasti
self.list_object = self.curframe
else:
self.stack = self.curframe = \
self.botframe = None
pass
if self.curframe:
self.list_lineno = \
max(1, inspect.getlineno(self.curframe)
- int(self.settings('listsize') / 2)) - 1
self.list_offset = self.curframe.f_lasti
self.list_filename = self.curframe.f_code.co_filename
self.list_object = self.curframe
else:
if not exc_traceback: self.list_lineno = None
pass
# if self.execRcLines()==1: return True
# FIXME: do we want to save self.list_lineno a second place
# so that we can do 'list .' and go back to the first place we listed?
return False
|
[
"Initialization",
"done",
"before",
"entering",
"the",
"debugger",
"-",
"command",
"loop",
".",
"In",
"particular",
"we",
"set",
"up",
"the",
"call",
"stack",
"used",
"for",
"local",
"variable",
"lookup",
"and",
"frame",
"/",
"up",
"/",
"down",
"commands",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L782-L825
|
[
"def",
"setup",
"(",
"self",
")",
":",
"self",
".",
"forget",
"(",
")",
"if",
"self",
".",
"settings",
"(",
"'dbg_trepan'",
")",
":",
"self",
".",
"frame",
"=",
"inspect",
".",
"currentframe",
"(",
")",
"pass",
"if",
"self",
".",
"event",
"in",
"[",
"'exception'",
",",
"'c_exception'",
"]",
":",
"exc_type",
",",
"exc_value",
",",
"exc_traceback",
"=",
"self",
".",
"event_arg",
"else",
":",
"_",
",",
"_",
",",
"exc_traceback",
"=",
"(",
"None",
",",
"None",
",",
"None",
",",
")",
"# NOQA",
"pass",
"if",
"self",
".",
"frame",
"or",
"exc_traceback",
":",
"self",
".",
"stack",
",",
"self",
".",
"curindex",
"=",
"get_stack",
"(",
"self",
".",
"frame",
",",
"exc_traceback",
",",
"None",
",",
"self",
")",
"self",
".",
"curframe",
"=",
"self",
".",
"stack",
"[",
"self",
".",
"curindex",
"]",
"[",
"0",
"]",
"self",
".",
"thread_name",
"=",
"Mthread",
".",
"current_thread_name",
"(",
")",
"if",
"exc_traceback",
":",
"self",
".",
"list_lineno",
"=",
"traceback",
".",
"extract_tb",
"(",
"exc_traceback",
",",
"1",
")",
"[",
"0",
"]",
"[",
"1",
"]",
"self",
".",
"list_offset",
"=",
"self",
".",
"curframe",
".",
"f_lasti",
"self",
".",
"list_object",
"=",
"self",
".",
"curframe",
"else",
":",
"self",
".",
"stack",
"=",
"self",
".",
"curframe",
"=",
"self",
".",
"botframe",
"=",
"None",
"pass",
"if",
"self",
".",
"curframe",
":",
"self",
".",
"list_lineno",
"=",
"max",
"(",
"1",
",",
"inspect",
".",
"getlineno",
"(",
"self",
".",
"curframe",
")",
"-",
"int",
"(",
"self",
".",
"settings",
"(",
"'listsize'",
")",
"/",
"2",
")",
")",
"-",
"1",
"self",
".",
"list_offset",
"=",
"self",
".",
"curframe",
".",
"f_lasti",
"self",
".",
"list_filename",
"=",
"self",
".",
"curframe",
".",
"f_code",
".",
"co_filename",
"self",
".",
"list_object",
"=",
"self",
".",
"curframe",
"else",
":",
"if",
"not",
"exc_traceback",
":",
"self",
".",
"list_lineno",
"=",
"None",
"pass",
"# if self.execRcLines()==1: return True",
"# FIXME: do we want to save self.list_lineno a second place",
"# so that we can do 'list .' and go back to the first place we listed?",
"return",
"False"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.queue_startfile
|
Arrange for file of debugger commands to get read in the
process-command loop.
|
trepan/processor/cmdproc.py
|
def queue_startfile(self, cmdfile):
"""Arrange for file of debugger commands to get read in the
process-command loop."""
expanded_cmdfile = os.path.expanduser(cmdfile)
is_readable = Mfile.readable(expanded_cmdfile)
if is_readable:
self.cmd_queue.append('source ' + expanded_cmdfile)
elif is_readable is None:
self.errmsg("source file '%s' doesn't exist" % expanded_cmdfile)
else:
self.errmsg("source file '%s' is not readable" %
expanded_cmdfile)
pass
return
|
def queue_startfile(self, cmdfile):
"""Arrange for file of debugger commands to get read in the
process-command loop."""
expanded_cmdfile = os.path.expanduser(cmdfile)
is_readable = Mfile.readable(expanded_cmdfile)
if is_readable:
self.cmd_queue.append('source ' + expanded_cmdfile)
elif is_readable is None:
self.errmsg("source file '%s' doesn't exist" % expanded_cmdfile)
else:
self.errmsg("source file '%s' is not readable" %
expanded_cmdfile)
pass
return
|
[
"Arrange",
"for",
"file",
"of",
"debugger",
"commands",
"to",
"get",
"read",
"in",
"the",
"process",
"-",
"command",
"loop",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L827-L840
|
[
"def",
"queue_startfile",
"(",
"self",
",",
"cmdfile",
")",
":",
"expanded_cmdfile",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"cmdfile",
")",
"is_readable",
"=",
"Mfile",
".",
"readable",
"(",
"expanded_cmdfile",
")",
"if",
"is_readable",
":",
"self",
".",
"cmd_queue",
".",
"append",
"(",
"'source '",
"+",
"expanded_cmdfile",
")",
"elif",
"is_readable",
"is",
"None",
":",
"self",
".",
"errmsg",
"(",
"\"source file '%s' doesn't exist\"",
"%",
"expanded_cmdfile",
")",
"else",
":",
"self",
".",
"errmsg",
"(",
"\"source file '%s' is not readable\"",
"%",
"expanded_cmdfile",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.read_history_file
|
Read the command history file -- possibly.
|
trepan/processor/cmdproc.py
|
def read_history_file(self):
"""Read the command history file -- possibly."""
histfile = self.debugger.intf[-1].histfile
try:
import readline
readline.read_history_file(histfile)
except IOError:
pass
except ImportError:
pass
return
|
def read_history_file(self):
"""Read the command history file -- possibly."""
histfile = self.debugger.intf[-1].histfile
try:
import readline
readline.read_history_file(histfile)
except IOError:
pass
except ImportError:
pass
return
|
[
"Read",
"the",
"command",
"history",
"file",
"--",
"possibly",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L847-L857
|
[
"def",
"read_history_file",
"(",
"self",
")",
":",
"histfile",
"=",
"self",
".",
"debugger",
".",
"intf",
"[",
"-",
"1",
"]",
".",
"histfile",
"try",
":",
"import",
"readline",
"readline",
".",
"read_history_file",
"(",
"histfile",
")",
"except",
"IOError",
":",
"pass",
"except",
"ImportError",
":",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor.write_history_file
|
Write the command history file -- possibly.
|
trepan/processor/cmdproc.py
|
def write_history_file(self):
"""Write the command history file -- possibly."""
settings = self.debugger.settings
histfile = self.debugger.intf[-1].histfile
if settings['hist_save']:
try:
import readline
try:
readline.write_history_file(histfile)
except IOError:
pass
except ImportError:
pass
pass
return
|
def write_history_file(self):
"""Write the command history file -- possibly."""
settings = self.debugger.settings
histfile = self.debugger.intf[-1].histfile
if settings['hist_save']:
try:
import readline
try:
readline.write_history_file(histfile)
except IOError:
pass
except ImportError:
pass
pass
return
|
[
"Write",
"the",
"command",
"history",
"file",
"--",
"possibly",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L859-L873
|
[
"def",
"write_history_file",
"(",
"self",
")",
":",
"settings",
"=",
"self",
".",
"debugger",
".",
"settings",
"histfile",
"=",
"self",
".",
"debugger",
".",
"intf",
"[",
"-",
"1",
"]",
".",
"histfile",
"if",
"settings",
"[",
"'hist_save'",
"]",
":",
"try",
":",
"import",
"readline",
"try",
":",
"readline",
".",
"write_history_file",
"(",
"histfile",
")",
"except",
"IOError",
":",
"pass",
"except",
"ImportError",
":",
"pass",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor._populate_commands
|
Create an instance of each of the debugger
commands. Commands are found by importing files in the
directory 'command'. Some files are excluded via an array set
in __init__. For each of the remaining files, we import them
and scan for class names inside those files and for each class
name, we will create an instance of that class. The set of
DebuggerCommand class instances form set of possible debugger
commands.
|
trepan/processor/cmdproc.py
|
def _populate_commands(self):
""" Create an instance of each of the debugger
commands. Commands are found by importing files in the
directory 'command'. Some files are excluded via an array set
in __init__. For each of the remaining files, we import them
and scan for class names inside those files and for each class
name, we will create an instance of that class. The set of
DebuggerCommand class instances form set of possible debugger
commands."""
from trepan.processor import command as Mcommand
if hasattr(Mcommand, '__modules__'):
return self.populate_commands_easy_install(Mcommand)
else:
return self.populate_commands_pip(Mcommand)
|
def _populate_commands(self):
""" Create an instance of each of the debugger
commands. Commands are found by importing files in the
directory 'command'. Some files are excluded via an array set
in __init__. For each of the remaining files, we import them
and scan for class names inside those files and for each class
name, we will create an instance of that class. The set of
DebuggerCommand class instances form set of possible debugger
commands."""
from trepan.processor import command as Mcommand
if hasattr(Mcommand, '__modules__'):
return self.populate_commands_easy_install(Mcommand)
else:
return self.populate_commands_pip(Mcommand)
|
[
"Create",
"an",
"instance",
"of",
"each",
"of",
"the",
"debugger",
"commands",
".",
"Commands",
"are",
"found",
"by",
"importing",
"files",
"in",
"the",
"directory",
"command",
".",
"Some",
"files",
"are",
"excluded",
"via",
"an",
"array",
"set",
"in",
"__init__",
".",
"For",
"each",
"of",
"the",
"remaining",
"files",
"we",
"import",
"them",
"and",
"scan",
"for",
"class",
"names",
"inside",
"those",
"files",
"and",
"for",
"each",
"class",
"name",
"we",
"will",
"create",
"an",
"instance",
"of",
"that",
"class",
".",
"The",
"set",
"of",
"DebuggerCommand",
"class",
"instances",
"form",
"set",
"of",
"possible",
"debugger",
"commands",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L875-L888
|
[
"def",
"_populate_commands",
"(",
"self",
")",
":",
"from",
"trepan",
".",
"processor",
"import",
"command",
"as",
"Mcommand",
"if",
"hasattr",
"(",
"Mcommand",
",",
"'__modules__'",
")",
":",
"return",
"self",
".",
"populate_commands_easy_install",
"(",
"Mcommand",
")",
"else",
":",
"return",
"self",
".",
"populate_commands_pip",
"(",
"Mcommand",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
CommandProcessor._populate_cmd_lists
|
Populate self.lists and hashes:
self.commands, and self.aliases, self.category
|
trepan/processor/cmdproc.py
|
def _populate_cmd_lists(self):
""" Populate self.lists and hashes:
self.commands, and self.aliases, self.category """
self.commands = {}
self.aliases = {}
self.category = {}
# self.short_help = {}
for cmd_instance in self.cmd_instances:
if not hasattr(cmd_instance, 'aliases'): continue
alias_names = cmd_instance.aliases
cmd_name = cmd_instance.name
self.commands[cmd_name] = cmd_instance
for alias_name in alias_names:
self.aliases[alias_name] = cmd_name
pass
cat = getattr(cmd_instance, 'category')
if cat and self.category.get(cat):
self.category[cat].append(cmd_name)
else:
self.category[cat] = [cmd_name]
pass
# sh = getattr(cmd_instance, 'short_help')
# if sh:
# self.short_help[cmd_name] = getattr(c, 'short_help')
# pass
pass
for k in list(self.category.keys()):
self.category[k].sort()
pass
return
|
def _populate_cmd_lists(self):
""" Populate self.lists and hashes:
self.commands, and self.aliases, self.category """
self.commands = {}
self.aliases = {}
self.category = {}
# self.short_help = {}
for cmd_instance in self.cmd_instances:
if not hasattr(cmd_instance, 'aliases'): continue
alias_names = cmd_instance.aliases
cmd_name = cmd_instance.name
self.commands[cmd_name] = cmd_instance
for alias_name in alias_names:
self.aliases[alias_name] = cmd_name
pass
cat = getattr(cmd_instance, 'category')
if cat and self.category.get(cat):
self.category[cat].append(cmd_name)
else:
self.category[cat] = [cmd_name]
pass
# sh = getattr(cmd_instance, 'short_help')
# if sh:
# self.short_help[cmd_name] = getattr(c, 'short_help')
# pass
pass
for k in list(self.category.keys()):
self.category[k].sort()
pass
return
|
[
"Populate",
"self",
".",
"lists",
"and",
"hashes",
":",
"self",
".",
"commands",
"and",
"self",
".",
"aliases",
"self",
".",
"category"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdproc.py#L974-L1004
|
[
"def",
"_populate_cmd_lists",
"(",
"self",
")",
":",
"self",
".",
"commands",
"=",
"{",
"}",
"self",
".",
"aliases",
"=",
"{",
"}",
"self",
".",
"category",
"=",
"{",
"}",
"# self.short_help = {}",
"for",
"cmd_instance",
"in",
"self",
".",
"cmd_instances",
":",
"if",
"not",
"hasattr",
"(",
"cmd_instance",
",",
"'aliases'",
")",
":",
"continue",
"alias_names",
"=",
"cmd_instance",
".",
"aliases",
"cmd_name",
"=",
"cmd_instance",
".",
"name",
"self",
".",
"commands",
"[",
"cmd_name",
"]",
"=",
"cmd_instance",
"for",
"alias_name",
"in",
"alias_names",
":",
"self",
".",
"aliases",
"[",
"alias_name",
"]",
"=",
"cmd_name",
"pass",
"cat",
"=",
"getattr",
"(",
"cmd_instance",
",",
"'category'",
")",
"if",
"cat",
"and",
"self",
".",
"category",
".",
"get",
"(",
"cat",
")",
":",
"self",
".",
"category",
"[",
"cat",
"]",
".",
"append",
"(",
"cmd_name",
")",
"else",
":",
"self",
".",
"category",
"[",
"cat",
"]",
"=",
"[",
"cmd_name",
"]",
"pass",
"# sh = getattr(cmd_instance, 'short_help')",
"# if sh:",
"# self.short_help[cmd_name] = getattr(c, 'short_help')",
"# pass",
"pass",
"for",
"k",
"in",
"list",
"(",
"self",
".",
"category",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"category",
"[",
"k",
"]",
".",
"sort",
"(",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
complete_token_filtered_with_next
|
Find all starting matches in dictionary *aliases* that start
with *prefix*, but filter out any matches already in
*expanded*.
|
trepan/lib/complete.py
|
def complete_token_filtered_with_next(aliases, prefix, expanded, commands):
"""Find all starting matches in dictionary *aliases* that start
with *prefix*, but filter out any matches already in
*expanded*."""
complete_ary = list(aliases.keys())
expanded_ary = list(expanded.keys())
# result = [cmd for cmd in
# complete_ary if cmd.startswith(prefix) and not (
# cmd in aliases and
# 0 == len(set(expanded_ary) - set([aliases[cmd]])))]
result = []
for cmd in complete_ary:
if cmd.startswith(prefix):
if cmd in aliases and (
0 == len(set(expanded_ary) - set([aliases[cmd]]))):
result.append([cmd, aliases[cmd]])
pass
pass
pass
return sorted(result, key=lambda pair: pair[0])
|
def complete_token_filtered_with_next(aliases, prefix, expanded, commands):
"""Find all starting matches in dictionary *aliases* that start
with *prefix*, but filter out any matches already in
*expanded*."""
complete_ary = list(aliases.keys())
expanded_ary = list(expanded.keys())
# result = [cmd for cmd in
# complete_ary if cmd.startswith(prefix) and not (
# cmd in aliases and
# 0 == len(set(expanded_ary) - set([aliases[cmd]])))]
result = []
for cmd in complete_ary:
if cmd.startswith(prefix):
if cmd in aliases and (
0 == len(set(expanded_ary) - set([aliases[cmd]]))):
result.append([cmd, aliases[cmd]])
pass
pass
pass
return sorted(result, key=lambda pair: pair[0])
|
[
"Find",
"all",
"starting",
"matches",
"in",
"dictionary",
"*",
"aliases",
"*",
"that",
"start",
"with",
"*",
"prefix",
"*",
"but",
"filter",
"out",
"any",
"matches",
"already",
"in",
"*",
"expanded",
"*",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/complete.py#L38-L58
|
[
"def",
"complete_token_filtered_with_next",
"(",
"aliases",
",",
"prefix",
",",
"expanded",
",",
"commands",
")",
":",
"complete_ary",
"=",
"list",
"(",
"aliases",
".",
"keys",
"(",
")",
")",
"expanded_ary",
"=",
"list",
"(",
"expanded",
".",
"keys",
"(",
")",
")",
"# result = [cmd for cmd in",
"# complete_ary if cmd.startswith(prefix) and not (",
"# cmd in aliases and",
"# 0 == len(set(expanded_ary) - set([aliases[cmd]])))]",
"result",
"=",
"[",
"]",
"for",
"cmd",
"in",
"complete_ary",
":",
"if",
"cmd",
".",
"startswith",
"(",
"prefix",
")",
":",
"if",
"cmd",
"in",
"aliases",
"and",
"(",
"0",
"==",
"len",
"(",
"set",
"(",
"expanded_ary",
")",
"-",
"set",
"(",
"[",
"aliases",
"[",
"cmd",
"]",
"]",
")",
")",
")",
":",
"result",
".",
"append",
"(",
"[",
"cmd",
",",
"aliases",
"[",
"cmd",
"]",
"]",
")",
"pass",
"pass",
"pass",
"return",
"sorted",
"(",
"result",
",",
"key",
"=",
"lambda",
"pair",
":",
"pair",
"[",
"0",
"]",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
complete_token_filtered
|
Find all starting matches in dictionary *aliases* that start
with *prefix*, but filter out any matches already in *expanded*
|
trepan/lib/complete.py
|
def complete_token_filtered(aliases, prefix, expanded):
"""Find all starting matches in dictionary *aliases* that start
with *prefix*, but filter out any matches already in *expanded*"""
complete_ary = aliases.keys()
return [cmd for cmd in complete_ary if cmd.startswith(prefix)]
|
def complete_token_filtered(aliases, prefix, expanded):
"""Find all starting matches in dictionary *aliases* that start
with *prefix*, but filter out any matches already in *expanded*"""
complete_ary = aliases.keys()
return [cmd for cmd in complete_ary if cmd.startswith(prefix)]
|
[
"Find",
"all",
"starting",
"matches",
"in",
"dictionary",
"*",
"aliases",
"*",
"that",
"start",
"with",
"*",
"prefix",
"*",
"but",
"filter",
"out",
"any",
"matches",
"already",
"in",
"*",
"expanded",
"*"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/complete.py#L61-L66
|
[
"def",
"complete_token_filtered",
"(",
"aliases",
",",
"prefix",
",",
"expanded",
")",
":",
"complete_ary",
"=",
"aliases",
".",
"keys",
"(",
")",
"return",
"[",
"cmd",
"for",
"cmd",
"in",
"complete_ary",
"if",
"cmd",
".",
"startswith",
"(",
"prefix",
")",
"]"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
next_token
|
Find the next token in str string from start_pos, we return
the token and the next blank position after the token or
str.size if this is the last token. Tokens are delimited by
white space.
|
trepan/lib/complete.py
|
def next_token(str, start_pos):
"""Find the next token in str string from start_pos, we return
the token and the next blank position after the token or
str.size if this is the last token. Tokens are delimited by
white space."""
look_at = str[start_pos:]
match = re.search('\S', look_at)
if match:
pos = match.start()
else:
pos = 0
pass
next_nonblank_pos = start_pos + pos
next_match = re.search('\s', str[next_nonblank_pos:])
if next_match:
next_blank_pos = next_nonblank_pos + next_match.start()
else:
next_blank_pos = len(str)
pass
return [next_blank_pos, str[next_nonblank_pos:next_blank_pos+1].rstrip()]
|
def next_token(str, start_pos):
"""Find the next token in str string from start_pos, we return
the token and the next blank position after the token or
str.size if this is the last token. Tokens are delimited by
white space."""
look_at = str[start_pos:]
match = re.search('\S', look_at)
if match:
pos = match.start()
else:
pos = 0
pass
next_nonblank_pos = start_pos + pos
next_match = re.search('\s', str[next_nonblank_pos:])
if next_match:
next_blank_pos = next_nonblank_pos + next_match.start()
else:
next_blank_pos = len(str)
pass
return [next_blank_pos, str[next_nonblank_pos:next_blank_pos+1].rstrip()]
|
[
"Find",
"the",
"next",
"token",
"in",
"str",
"string",
"from",
"start_pos",
"we",
"return",
"the",
"token",
"and",
"the",
"next",
"blank",
"position",
"after",
"the",
"token",
"or",
"str",
".",
"size",
"if",
"this",
"is",
"the",
"last",
"token",
".",
"Tokens",
"are",
"delimited",
"by",
"white",
"space",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/complete.py#L71-L90
|
[
"def",
"next_token",
"(",
"str",
",",
"start_pos",
")",
":",
"look_at",
"=",
"str",
"[",
"start_pos",
":",
"]",
"match",
"=",
"re",
".",
"search",
"(",
"'\\S'",
",",
"look_at",
")",
"if",
"match",
":",
"pos",
"=",
"match",
".",
"start",
"(",
")",
"else",
":",
"pos",
"=",
"0",
"pass",
"next_nonblank_pos",
"=",
"start_pos",
"+",
"pos",
"next_match",
"=",
"re",
".",
"search",
"(",
"'\\s'",
",",
"str",
"[",
"next_nonblank_pos",
":",
"]",
")",
"if",
"next_match",
":",
"next_blank_pos",
"=",
"next_nonblank_pos",
"+",
"next_match",
".",
"start",
"(",
")",
"else",
":",
"next_blank_pos",
"=",
"len",
"(",
"str",
")",
"pass",
"return",
"[",
"next_blank_pos",
",",
"str",
"[",
"next_nonblank_pos",
":",
"next_blank_pos",
"+",
"1",
"]",
".",
"rstrip",
"(",
")",
"]"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
ScriptInterface.errmsg
|
Common routine for reporting debugger error messages.
|
trepan/interfaces/script.py
|
def errmsg(self, msg, prefix="** "):
"""Common routine for reporting debugger error messages.
"""
# self.verbose shows lines so we don't have to duplicate info
# here. Perhaps there should be a 'terse' mode to never show
# position info.
if not self.verbose:
location = ("%s:%s: Error in source command file"
% (self.script_name, self.input_lineno))
msg = "%s%s:\n%s%s" %(prefix, location, prefix, msg)
else:
msg = "%s%s" %(prefix, msg)
pass
self.msg(msg)
if self.abort_on_error:
raise EOFError
return
|
def errmsg(self, msg, prefix="** "):
"""Common routine for reporting debugger error messages.
"""
# self.verbose shows lines so we don't have to duplicate info
# here. Perhaps there should be a 'terse' mode to never show
# position info.
if not self.verbose:
location = ("%s:%s: Error in source command file"
% (self.script_name, self.input_lineno))
msg = "%s%s:\n%s%s" %(prefix, location, prefix, msg)
else:
msg = "%s%s" %(prefix, msg)
pass
self.msg(msg)
if self.abort_on_error:
raise EOFError
return
|
[
"Common",
"routine",
"for",
"reporting",
"debugger",
"error",
"messages",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/interfaces/script.py#L62-L78
|
[
"def",
"errmsg",
"(",
"self",
",",
"msg",
",",
"prefix",
"=",
"\"** \"",
")",
":",
"# self.verbose shows lines so we don't have to duplicate info",
"# here. Perhaps there should be a 'terse' mode to never show",
"# position info.",
"if",
"not",
"self",
".",
"verbose",
":",
"location",
"=",
"(",
"\"%s:%s: Error in source command file\"",
"%",
"(",
"self",
".",
"script_name",
",",
"self",
".",
"input_lineno",
")",
")",
"msg",
"=",
"\"%s%s:\\n%s%s\"",
"%",
"(",
"prefix",
",",
"location",
",",
"prefix",
",",
"msg",
")",
"else",
":",
"msg",
"=",
"\"%s%s\"",
"%",
"(",
"prefix",
",",
"msg",
")",
"pass",
"self",
".",
"msg",
"(",
"msg",
")",
"if",
"self",
".",
"abort_on_error",
":",
"raise",
"EOFError",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
ScriptInterface.read_command
|
Script interface to read a command. `prompt' is a parameter for
compatibilty and is ignored.
|
trepan/interfaces/script.py
|
def read_command(self, prompt=''):
'''Script interface to read a command. `prompt' is a parameter for
compatibilty and is ignored.'''
self.input_lineno += 1
line = self.readline()
if self.verbose:
location = "%s line %s" % (self.script_name, self.input_lineno)
self.msg('+ %s: %s' % (location, line))
pass
# Do something with history?
return line
|
def read_command(self, prompt=''):
'''Script interface to read a command. `prompt' is a parameter for
compatibilty and is ignored.'''
self.input_lineno += 1
line = self.readline()
if self.verbose:
location = "%s line %s" % (self.script_name, self.input_lineno)
self.msg('+ %s: %s' % (location, line))
pass
# Do something with history?
return line
|
[
"Script",
"interface",
"to",
"read",
"a",
"command",
".",
"prompt",
"is",
"a",
"parameter",
"for",
"compatibilty",
"and",
"is",
"ignored",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/interfaces/script.py#L86-L96
|
[
"def",
"read_command",
"(",
"self",
",",
"prompt",
"=",
"''",
")",
":",
"self",
".",
"input_lineno",
"+=",
"1",
"line",
"=",
"self",
".",
"readline",
"(",
")",
"if",
"self",
".",
"verbose",
":",
"location",
"=",
"\"%s line %s\"",
"%",
"(",
"self",
".",
"script_name",
",",
"self",
".",
"input_lineno",
")",
"self",
".",
"msg",
"(",
"'+ %s: %s'",
"%",
"(",
"location",
",",
"line",
")",
")",
"pass",
"# Do something with history?",
"return",
"line"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
FIFOClient.close
|
Closes both input and output
|
trepan/inout/fifoclient.py
|
def close(self):
""" Closes both input and output """
self.state = 'closing'
if self.input:
self.input.close()
pass
if self.output:
self.output.close()
pass
self.state = 'disconnnected'
return
|
def close(self):
""" Closes both input and output """
self.state = 'closing'
if self.input:
self.input.close()
pass
if self.output:
self.output.close()
pass
self.state = 'disconnnected'
return
|
[
"Closes",
"both",
"input",
"and",
"output"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/fifoclient.py#L45-L55
|
[
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"state",
"=",
"'closing'",
"if",
"self",
".",
"input",
":",
"self",
".",
"input",
".",
"close",
"(",
")",
"pass",
"if",
"self",
".",
"output",
":",
"self",
".",
"output",
".",
"close",
"(",
")",
"pass",
"self",
".",
"state",
"=",
"'disconnnected'",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
FIFOClient.read_msg
|
Read a line of input. EOFError will be raised on EOF.
Note that we don't support prompting
|
trepan/inout/fifoclient.py
|
def read_msg(self):
"""Read a line of input. EOFError will be raised on EOF.
Note that we don't support prompting"""
# FIXME: do we have to create and check a buffer for
# lines?
if self.state == 'active':
if not self.input:
self.input = open(self.in_name, 'r')
pass
line = self.input.readline()
if not line:
self.state = 'disconnected'
raise EOFError
return line.encode("utf-8")
else:
raise IOError("readline called in state: %s." % self.state)
return
|
def read_msg(self):
"""Read a line of input. EOFError will be raised on EOF.
Note that we don't support prompting"""
# FIXME: do we have to create and check a buffer for
# lines?
if self.state == 'active':
if not self.input:
self.input = open(self.in_name, 'r')
pass
line = self.input.readline()
if not line:
self.state = 'disconnected'
raise EOFError
return line.encode("utf-8")
else:
raise IOError("readline called in state: %s." % self.state)
return
|
[
"Read",
"a",
"line",
"of",
"input",
".",
"EOFError",
"will",
"be",
"raised",
"on",
"EOF",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/fifoclient.py#L87-L104
|
[
"def",
"read_msg",
"(",
"self",
")",
":",
"# FIXME: do we have to create and check a buffer for",
"# lines?",
"if",
"self",
".",
"state",
"==",
"'active'",
":",
"if",
"not",
"self",
".",
"input",
":",
"self",
".",
"input",
"=",
"open",
"(",
"self",
".",
"in_name",
",",
"'r'",
")",
"pass",
"line",
"=",
"self",
".",
"input",
".",
"readline",
"(",
")",
"if",
"not",
"line",
":",
"self",
".",
"state",
"=",
"'disconnected'",
"raise",
"EOFError",
"return",
"line",
".",
"encode",
"(",
"\"utf-8\"",
")",
"else",
":",
"raise",
"IOError",
"(",
"\"readline called in state: %s.\"",
"%",
"self",
".",
"state",
")",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
FIFOClient.write
|
This method the debugger uses to write. In contrast to
writeline, no newline is added to the end to `str'.
|
trepan/inout/fifoclient.py
|
def write(self, msg):
""" This method the debugger uses to write. In contrast to
writeline, no newline is added to the end to `str'.
"""
if self.state == 'active':
if not self.output:
self.output = open(self.out_name, 'w')
pass
pass
else:
raise EOFError
self.output.write(msg)
if self.flush_after_write: self.flush()
return
|
def write(self, msg):
""" This method the debugger uses to write. In contrast to
writeline, no newline is added to the end to `str'.
"""
if self.state == 'active':
if not self.output:
self.output = open(self.out_name, 'w')
pass
pass
else:
raise EOFError
self.output.write(msg)
if self.flush_after_write: self.flush()
return
|
[
"This",
"method",
"the",
"debugger",
"uses",
"to",
"write",
".",
"In",
"contrast",
"to",
"writeline",
"no",
"newline",
"is",
"added",
"to",
"the",
"end",
"to",
"str",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/fifoclient.py#L106-L119
|
[
"def",
"write",
"(",
"self",
",",
"msg",
")",
":",
"if",
"self",
".",
"state",
"==",
"'active'",
":",
"if",
"not",
"self",
".",
"output",
":",
"self",
".",
"output",
"=",
"open",
"(",
"self",
".",
"out_name",
",",
"'w'",
")",
"pass",
"pass",
"else",
":",
"raise",
"EOFError",
"self",
".",
"output",
".",
"write",
"(",
"msg",
")",
"if",
"self",
".",
"flush_after_write",
":",
"self",
".",
"flush",
"(",
")",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
process_options
|
Handle debugger options. Set `option_list' if you are writing
another main program and want to extend the existing set of debugger
options.
The options dicionary from opt_parser is return. sys_argv is
also updated.
|
trepan/client.py
|
def process_options(pkg_version, sys_argv, option_list=None):
"""Handle debugger options. Set `option_list' if you are writing
another main program and want to extend the existing set of debugger
options.
The options dicionary from opt_parser is return. sys_argv is
also updated."""
usage_str="""%prog [debugger-options]]
Client connection to an out-of-process trepan3k debugger session"""
# serverChoices = ('TCP','FIFO', None) # we use PID for now.
optparser = OptionParser(usage=usage_str, option_list=option_list,
version="%%prog version %s" % pkg_version)
optparser.add_option("-H", "--host", dest="host", default='127.0.0.1',
action="store", type='string', metavar='IP-OR-HOST',
help="connect IP or host name.")
optparser.add_option("-P", "--port", dest="port", default=1027,
action="store", type='int', metavar='NUMBER',
help="Use TCP port number NUMBER for "
"out-of-process connections.")
optparser.add_option("--pid", dest="pid", default=0,
action="store", type='int', metavar='NUMBER',
help="Use PID to get FIFO names for "
"out-of-process connections.")
optparser.disable_interspersed_args()
sys.argv = list(sys_argv)
(opts, sys.argv) = optparser.parse_args()
return opts, sys.argv
|
def process_options(pkg_version, sys_argv, option_list=None):
"""Handle debugger options. Set `option_list' if you are writing
another main program and want to extend the existing set of debugger
options.
The options dicionary from opt_parser is return. sys_argv is
also updated."""
usage_str="""%prog [debugger-options]]
Client connection to an out-of-process trepan3k debugger session"""
# serverChoices = ('TCP','FIFO', None) # we use PID for now.
optparser = OptionParser(usage=usage_str, option_list=option_list,
version="%%prog version %s" % pkg_version)
optparser.add_option("-H", "--host", dest="host", default='127.0.0.1',
action="store", type='string', metavar='IP-OR-HOST',
help="connect IP or host name.")
optparser.add_option("-P", "--port", dest="port", default=1027,
action="store", type='int', metavar='NUMBER',
help="Use TCP port number NUMBER for "
"out-of-process connections.")
optparser.add_option("--pid", dest="pid", default=0,
action="store", type='int', metavar='NUMBER',
help="Use PID to get FIFO names for "
"out-of-process connections.")
optparser.disable_interspersed_args()
sys.argv = list(sys_argv)
(opts, sys.argv) = optparser.parse_args()
return opts, sys.argv
|
[
"Handle",
"debugger",
"options",
".",
"Set",
"option_list",
"if",
"you",
"are",
"writing",
"another",
"main",
"program",
"and",
"want",
"to",
"extend",
"the",
"existing",
"set",
"of",
"debugger",
"options",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/client.py#L30-L62
|
[
"def",
"process_options",
"(",
"pkg_version",
",",
"sys_argv",
",",
"option_list",
"=",
"None",
")",
":",
"usage_str",
"=",
"\"\"\"%prog [debugger-options]]\n\n Client connection to an out-of-process trepan3k debugger session\"\"\"",
"# serverChoices = ('TCP','FIFO', None) # we use PID for now.",
"optparser",
"=",
"OptionParser",
"(",
"usage",
"=",
"usage_str",
",",
"option_list",
"=",
"option_list",
",",
"version",
"=",
"\"%%prog version %s\"",
"%",
"pkg_version",
")",
"optparser",
".",
"add_option",
"(",
"\"-H\"",
",",
"\"--host\"",
",",
"dest",
"=",
"\"host\"",
",",
"default",
"=",
"'127.0.0.1'",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'string'",
",",
"metavar",
"=",
"'IP-OR-HOST'",
",",
"help",
"=",
"\"connect IP or host name.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"-P\"",
",",
"\"--port\"",
",",
"dest",
"=",
"\"port\"",
",",
"default",
"=",
"1027",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'int'",
",",
"metavar",
"=",
"'NUMBER'",
",",
"help",
"=",
"\"Use TCP port number NUMBER for \"",
"\"out-of-process connections.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--pid\"",
",",
"dest",
"=",
"\"pid\"",
",",
"default",
"=",
"0",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'int'",
",",
"metavar",
"=",
"'NUMBER'",
",",
"help",
"=",
"\"Use PID to get FIFO names for \"",
"\"out-of-process connections.\"",
")",
"optparser",
".",
"disable_interspersed_args",
"(",
")",
"sys",
".",
"argv",
"=",
"list",
"(",
"sys_argv",
")",
"(",
"opts",
",",
"sys",
".",
"argv",
")",
"=",
"optparser",
".",
"parse_args",
"(",
")",
"return",
"opts",
",",
"sys",
".",
"argv"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
dis
|
Disassemble classes, methods, functions, or code.
With no argument, disassemble the last traceback.
|
trepan/lib/disassemble.py
|
def dis(msg, msg_nocr, section, errmsg, x=None, start_line=-1, end_line=None,
relative_pos = False, highlight='light', start_offset=0, end_offset=None,
include_header=False):
"""Disassemble classes, methods, functions, or code.
With no argument, disassemble the last traceback.
"""
lasti = -1
if x is None:
distb()
return None, None
if start_offset is None:
start_offset = 0
mess = ''
if start_line > 1:
mess += "from line %d " % start_line
elif start_offset > 1:
mess = "from offset %d " % start_offset
if end_line:
mess += "to line %d" % end_line
elif end_offset:
mess += "to offset %d" % end_offset
sectioned = False
# Try to dogpaddle to the code object for the type setting x
if hasattr(types, 'InstanceType') and isinstance(x, types.InstanceType):
x = x.__class__
if inspect.ismethod(x):
section("Disassembly of %s: %s" % (x, mess))
sectioned = True
x = x.im_func
elif inspect.isfunction(x) or inspect.isgeneratorfunction(x):
section("Disassembly of %s: %s" % (x, mess))
x = x.func_code
sectioned = True
elif inspect.isgenerator(x):
section("Disassembly of %s: %s" % (x, mess))
frame = x.gi_frame
lasti = frame.f_last_i
x = x.gi_code
sectioned = True
elif inspect.isframe(x):
section("Disassembly of %s: %s" % (x, mess))
sectioned = True
if hasattr(x, 'f_lasti'):
lasti = x.f_lasti
if lasti == -1: lasti = 0
pass
opc = get_opcode(PYTHON_VERSION, IS_PYPY)
x = x.f_code
if include_header:
header_lines = Bytecode(x, opc).info().split("\n")
header = '\n'.join([format_token(Mformat.Comment, h) for h in header_lines])
msg(header)
pass
elif inspect.iscode(x):
pass
if hasattr(x, '__dict__'): # Class or module
items = sorted(x.__dict__.items())
for name, x1 in items:
if isinstance(x1, _have_code):
if not sectioned:
section("Disassembly of %s: " % x)
try:
dis(msg, msg_nocr, section, errmsg, x1,
start_line=start_line, end_line=end_line,
relative_pos = relative_pos)
msg("")
except TypeError:
_, msg, _ = sys.exc_info()
errmsg("Sorry:", msg)
pass
pass
pass
pass
elif hasattr(x, 'co_code'): # Code object
if not sectioned:
section("Disassembly of %s: " % x)
return disassemble(msg, msg_nocr, section, x, lasti=lasti,
start_line=start_line, end_line=end_line,
relative_pos = relative_pos,
highlight = highlight,
start_offset = start_offset,
end_offset = end_offset)
elif isinstance(x, str): # Source code
return disassemble_string(msg, msg_nocr, x,)
else:
errmsg("Don't know how to disassemble %s objects." %
type(x).__name__)
return None, None
|
def dis(msg, msg_nocr, section, errmsg, x=None, start_line=-1, end_line=None,
relative_pos = False, highlight='light', start_offset=0, end_offset=None,
include_header=False):
"""Disassemble classes, methods, functions, or code.
With no argument, disassemble the last traceback.
"""
lasti = -1
if x is None:
distb()
return None, None
if start_offset is None:
start_offset = 0
mess = ''
if start_line > 1:
mess += "from line %d " % start_line
elif start_offset > 1:
mess = "from offset %d " % start_offset
if end_line:
mess += "to line %d" % end_line
elif end_offset:
mess += "to offset %d" % end_offset
sectioned = False
# Try to dogpaddle to the code object for the type setting x
if hasattr(types, 'InstanceType') and isinstance(x, types.InstanceType):
x = x.__class__
if inspect.ismethod(x):
section("Disassembly of %s: %s" % (x, mess))
sectioned = True
x = x.im_func
elif inspect.isfunction(x) or inspect.isgeneratorfunction(x):
section("Disassembly of %s: %s" % (x, mess))
x = x.func_code
sectioned = True
elif inspect.isgenerator(x):
section("Disassembly of %s: %s" % (x, mess))
frame = x.gi_frame
lasti = frame.f_last_i
x = x.gi_code
sectioned = True
elif inspect.isframe(x):
section("Disassembly of %s: %s" % (x, mess))
sectioned = True
if hasattr(x, 'f_lasti'):
lasti = x.f_lasti
if lasti == -1: lasti = 0
pass
opc = get_opcode(PYTHON_VERSION, IS_PYPY)
x = x.f_code
if include_header:
header_lines = Bytecode(x, opc).info().split("\n")
header = '\n'.join([format_token(Mformat.Comment, h) for h in header_lines])
msg(header)
pass
elif inspect.iscode(x):
pass
if hasattr(x, '__dict__'): # Class or module
items = sorted(x.__dict__.items())
for name, x1 in items:
if isinstance(x1, _have_code):
if not sectioned:
section("Disassembly of %s: " % x)
try:
dis(msg, msg_nocr, section, errmsg, x1,
start_line=start_line, end_line=end_line,
relative_pos = relative_pos)
msg("")
except TypeError:
_, msg, _ = sys.exc_info()
errmsg("Sorry:", msg)
pass
pass
pass
pass
elif hasattr(x, 'co_code'): # Code object
if not sectioned:
section("Disassembly of %s: " % x)
return disassemble(msg, msg_nocr, section, x, lasti=lasti,
start_line=start_line, end_line=end_line,
relative_pos = relative_pos,
highlight = highlight,
start_offset = start_offset,
end_offset = end_offset)
elif isinstance(x, str): # Source code
return disassemble_string(msg, msg_nocr, x,)
else:
errmsg("Don't know how to disassemble %s objects." %
type(x).__name__)
return None, None
|
[
"Disassemble",
"classes",
"methods",
"functions",
"or",
"code",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/disassemble.py#L35-L128
|
[
"def",
"dis",
"(",
"msg",
",",
"msg_nocr",
",",
"section",
",",
"errmsg",
",",
"x",
"=",
"None",
",",
"start_line",
"=",
"-",
"1",
",",
"end_line",
"=",
"None",
",",
"relative_pos",
"=",
"False",
",",
"highlight",
"=",
"'light'",
",",
"start_offset",
"=",
"0",
",",
"end_offset",
"=",
"None",
",",
"include_header",
"=",
"False",
")",
":",
"lasti",
"=",
"-",
"1",
"if",
"x",
"is",
"None",
":",
"distb",
"(",
")",
"return",
"None",
",",
"None",
"if",
"start_offset",
"is",
"None",
":",
"start_offset",
"=",
"0",
"mess",
"=",
"''",
"if",
"start_line",
">",
"1",
":",
"mess",
"+=",
"\"from line %d \"",
"%",
"start_line",
"elif",
"start_offset",
">",
"1",
":",
"mess",
"=",
"\"from offset %d \"",
"%",
"start_offset",
"if",
"end_line",
":",
"mess",
"+=",
"\"to line %d\"",
"%",
"end_line",
"elif",
"end_offset",
":",
"mess",
"+=",
"\"to offset %d\"",
"%",
"end_offset",
"sectioned",
"=",
"False",
"# Try to dogpaddle to the code object for the type setting x",
"if",
"hasattr",
"(",
"types",
",",
"'InstanceType'",
")",
"and",
"isinstance",
"(",
"x",
",",
"types",
".",
"InstanceType",
")",
":",
"x",
"=",
"x",
".",
"__class__",
"if",
"inspect",
".",
"ismethod",
"(",
"x",
")",
":",
"section",
"(",
"\"Disassembly of %s: %s\"",
"%",
"(",
"x",
",",
"mess",
")",
")",
"sectioned",
"=",
"True",
"x",
"=",
"x",
".",
"im_func",
"elif",
"inspect",
".",
"isfunction",
"(",
"x",
")",
"or",
"inspect",
".",
"isgeneratorfunction",
"(",
"x",
")",
":",
"section",
"(",
"\"Disassembly of %s: %s\"",
"%",
"(",
"x",
",",
"mess",
")",
")",
"x",
"=",
"x",
".",
"func_code",
"sectioned",
"=",
"True",
"elif",
"inspect",
".",
"isgenerator",
"(",
"x",
")",
":",
"section",
"(",
"\"Disassembly of %s: %s\"",
"%",
"(",
"x",
",",
"mess",
")",
")",
"frame",
"=",
"x",
".",
"gi_frame",
"lasti",
"=",
"frame",
".",
"f_last_i",
"x",
"=",
"x",
".",
"gi_code",
"sectioned",
"=",
"True",
"elif",
"inspect",
".",
"isframe",
"(",
"x",
")",
":",
"section",
"(",
"\"Disassembly of %s: %s\"",
"%",
"(",
"x",
",",
"mess",
")",
")",
"sectioned",
"=",
"True",
"if",
"hasattr",
"(",
"x",
",",
"'f_lasti'",
")",
":",
"lasti",
"=",
"x",
".",
"f_lasti",
"if",
"lasti",
"==",
"-",
"1",
":",
"lasti",
"=",
"0",
"pass",
"opc",
"=",
"get_opcode",
"(",
"PYTHON_VERSION",
",",
"IS_PYPY",
")",
"x",
"=",
"x",
".",
"f_code",
"if",
"include_header",
":",
"header_lines",
"=",
"Bytecode",
"(",
"x",
",",
"opc",
")",
".",
"info",
"(",
")",
".",
"split",
"(",
"\"\\n\"",
")",
"header",
"=",
"'\\n'",
".",
"join",
"(",
"[",
"format_token",
"(",
"Mformat",
".",
"Comment",
",",
"h",
")",
"for",
"h",
"in",
"header_lines",
"]",
")",
"msg",
"(",
"header",
")",
"pass",
"elif",
"inspect",
".",
"iscode",
"(",
"x",
")",
":",
"pass",
"if",
"hasattr",
"(",
"x",
",",
"'__dict__'",
")",
":",
"# Class or module",
"items",
"=",
"sorted",
"(",
"x",
".",
"__dict__",
".",
"items",
"(",
")",
")",
"for",
"name",
",",
"x1",
"in",
"items",
":",
"if",
"isinstance",
"(",
"x1",
",",
"_have_code",
")",
":",
"if",
"not",
"sectioned",
":",
"section",
"(",
"\"Disassembly of %s: \"",
"%",
"x",
")",
"try",
":",
"dis",
"(",
"msg",
",",
"msg_nocr",
",",
"section",
",",
"errmsg",
",",
"x1",
",",
"start_line",
"=",
"start_line",
",",
"end_line",
"=",
"end_line",
",",
"relative_pos",
"=",
"relative_pos",
")",
"msg",
"(",
"\"\"",
")",
"except",
"TypeError",
":",
"_",
",",
"msg",
",",
"_",
"=",
"sys",
".",
"exc_info",
"(",
")",
"errmsg",
"(",
"\"Sorry:\"",
",",
"msg",
")",
"pass",
"pass",
"pass",
"pass",
"elif",
"hasattr",
"(",
"x",
",",
"'co_code'",
")",
":",
"# Code object",
"if",
"not",
"sectioned",
":",
"section",
"(",
"\"Disassembly of %s: \"",
"%",
"x",
")",
"return",
"disassemble",
"(",
"msg",
",",
"msg_nocr",
",",
"section",
",",
"x",
",",
"lasti",
"=",
"lasti",
",",
"start_line",
"=",
"start_line",
",",
"end_line",
"=",
"end_line",
",",
"relative_pos",
"=",
"relative_pos",
",",
"highlight",
"=",
"highlight",
",",
"start_offset",
"=",
"start_offset",
",",
"end_offset",
"=",
"end_offset",
")",
"elif",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"# Source code",
"return",
"disassemble_string",
"(",
"msg",
",",
"msg_nocr",
",",
"x",
",",
")",
"else",
":",
"errmsg",
"(",
"\"Don't know how to disassemble %s objects.\"",
"%",
"type",
"(",
"x",
")",
".",
"__name__",
")",
"return",
"None",
",",
"None"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
disassemble
|
Disassemble a code object.
|
trepan/lib/disassemble.py
|
def disassemble(msg, msg_nocr, section, co, lasti=-1, start_line=-1,
end_line=None, relative_pos=False, highlight='light',
start_offset=0, end_offset=None):
"""Disassemble a code object."""
return disassemble_bytes(msg, msg_nocr, co.co_code, lasti, co.co_firstlineno,
start_line, end_line, relative_pos,
co.co_varnames, co.co_names, co.co_consts,
co.co_cellvars, co.co_freevars,
dict(findlinestarts(co)), highlight,
start_offset=start_offset, end_offset=end_offset)
|
def disassemble(msg, msg_nocr, section, co, lasti=-1, start_line=-1,
end_line=None, relative_pos=False, highlight='light',
start_offset=0, end_offset=None):
"""Disassemble a code object."""
return disassemble_bytes(msg, msg_nocr, co.co_code, lasti, co.co_firstlineno,
start_line, end_line, relative_pos,
co.co_varnames, co.co_names, co.co_consts,
co.co_cellvars, co.co_freevars,
dict(findlinestarts(co)), highlight,
start_offset=start_offset, end_offset=end_offset)
|
[
"Disassemble",
"a",
"code",
"object",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/disassemble.py#L131-L140
|
[
"def",
"disassemble",
"(",
"msg",
",",
"msg_nocr",
",",
"section",
",",
"co",
",",
"lasti",
"=",
"-",
"1",
",",
"start_line",
"=",
"-",
"1",
",",
"end_line",
"=",
"None",
",",
"relative_pos",
"=",
"False",
",",
"highlight",
"=",
"'light'",
",",
"start_offset",
"=",
"0",
",",
"end_offset",
"=",
"None",
")",
":",
"return",
"disassemble_bytes",
"(",
"msg",
",",
"msg_nocr",
",",
"co",
".",
"co_code",
",",
"lasti",
",",
"co",
".",
"co_firstlineno",
",",
"start_line",
",",
"end_line",
",",
"relative_pos",
",",
"co",
".",
"co_varnames",
",",
"co",
".",
"co_names",
",",
"co",
".",
"co_consts",
",",
"co",
".",
"co_cellvars",
",",
"co",
".",
"co_freevars",
",",
"dict",
"(",
"findlinestarts",
"(",
"co",
")",
")",
",",
"highlight",
",",
"start_offset",
"=",
"start_offset",
",",
"end_offset",
"=",
"end_offset",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
disassemble_bytes
|
Disassemble byte string of code. If end_line is negative
it counts the number of statement linestarts to use.
|
trepan/lib/disassemble.py
|
def disassemble_bytes(orig_msg, orig_msg_nocr, code, lasti=-1, cur_line=0,
start_line=-1, end_line=None, relative_pos=False,
varnames=(), names=(), constants=(), cells=(),
freevars=(), linestarts={}, highlight='light',
start_offset=0, end_offset=None):
"""Disassemble byte string of code. If end_line is negative
it counts the number of statement linestarts to use."""
statement_count = 10000
if end_line is None:
end_line = 10000
elif relative_pos:
end_line += start_line -1
pass
labels = findlabels(code)
null_print = lambda x: None
if start_line > cur_line:
msg_nocr = null_print
msg = null_print
else:
msg_nocr = orig_msg_nocr
msg = orig_msg
for instr in get_instructions_bytes(code, opc, varnames, names,
constants, cells, linestarts):
offset = instr.offset
if end_offset and offset > end_offset:
break
if instr.starts_line:
if offset:
msg("")
cur_line = instr.starts_line
if (start_line and ((start_line > cur_line) or
start_offset and start_offset > offset)) :
msg_nocr = null_print
msg = null_print
else:
statement_count -= 1
msg_nocr = orig_msg_nocr
msg = orig_msg
pass
if ((cur_line > end_line) or
(end_offset and offset > end_offset)):
break
msg_nocr(format_token(Mformat.LineNumber,
"%4d" % cur_line,
highlight=highlight))
else:
if start_offset and offset and start_offset <= offset:
msg_nocr = orig_msg_nocr
msg = orig_msg
pass
msg_nocr(' ')
if offset == lasti: msg_nocr(format_token(Mformat.Arrow, '-->',
highlight=highlight))
else: msg_nocr(' ')
if offset in labels: msg_nocr(format_token(Mformat.Arrow, '>>',
highlight=highlight))
else: msg_nocr(' ')
msg_nocr(repr(offset).rjust(4))
msg_nocr(' ')
msg_nocr(format_token(Mformat.Opcode,
instr.opname.ljust(20),
highlight=highlight))
msg_nocr(repr(instr.arg).ljust(10))
msg_nocr(' ')
# Show argval?
msg(format_token(Mformat.Name,
instr.argrepr.ljust(20),
highlight=highlight))
pass
return code, offset
|
def disassemble_bytes(orig_msg, orig_msg_nocr, code, lasti=-1, cur_line=0,
start_line=-1, end_line=None, relative_pos=False,
varnames=(), names=(), constants=(), cells=(),
freevars=(), linestarts={}, highlight='light',
start_offset=0, end_offset=None):
"""Disassemble byte string of code. If end_line is negative
it counts the number of statement linestarts to use."""
statement_count = 10000
if end_line is None:
end_line = 10000
elif relative_pos:
end_line += start_line -1
pass
labels = findlabels(code)
null_print = lambda x: None
if start_line > cur_line:
msg_nocr = null_print
msg = null_print
else:
msg_nocr = orig_msg_nocr
msg = orig_msg
for instr in get_instructions_bytes(code, opc, varnames, names,
constants, cells, linestarts):
offset = instr.offset
if end_offset and offset > end_offset:
break
if instr.starts_line:
if offset:
msg("")
cur_line = instr.starts_line
if (start_line and ((start_line > cur_line) or
start_offset and start_offset > offset)) :
msg_nocr = null_print
msg = null_print
else:
statement_count -= 1
msg_nocr = orig_msg_nocr
msg = orig_msg
pass
if ((cur_line > end_line) or
(end_offset and offset > end_offset)):
break
msg_nocr(format_token(Mformat.LineNumber,
"%4d" % cur_line,
highlight=highlight))
else:
if start_offset and offset and start_offset <= offset:
msg_nocr = orig_msg_nocr
msg = orig_msg
pass
msg_nocr(' ')
if offset == lasti: msg_nocr(format_token(Mformat.Arrow, '-->',
highlight=highlight))
else: msg_nocr(' ')
if offset in labels: msg_nocr(format_token(Mformat.Arrow, '>>',
highlight=highlight))
else: msg_nocr(' ')
msg_nocr(repr(offset).rjust(4))
msg_nocr(' ')
msg_nocr(format_token(Mformat.Opcode,
instr.opname.ljust(20),
highlight=highlight))
msg_nocr(repr(instr.arg).ljust(10))
msg_nocr(' ')
# Show argval?
msg(format_token(Mformat.Name,
instr.argrepr.ljust(20),
highlight=highlight))
pass
return code, offset
|
[
"Disassemble",
"byte",
"string",
"of",
"code",
".",
"If",
"end_line",
"is",
"negative",
"it",
"counts",
"the",
"number",
"of",
"statement",
"linestarts",
"to",
"use",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/disassemble.py#L150-L226
|
[
"def",
"disassemble_bytes",
"(",
"orig_msg",
",",
"orig_msg_nocr",
",",
"code",
",",
"lasti",
"=",
"-",
"1",
",",
"cur_line",
"=",
"0",
",",
"start_line",
"=",
"-",
"1",
",",
"end_line",
"=",
"None",
",",
"relative_pos",
"=",
"False",
",",
"varnames",
"=",
"(",
")",
",",
"names",
"=",
"(",
")",
",",
"constants",
"=",
"(",
")",
",",
"cells",
"=",
"(",
")",
",",
"freevars",
"=",
"(",
")",
",",
"linestarts",
"=",
"{",
"}",
",",
"highlight",
"=",
"'light'",
",",
"start_offset",
"=",
"0",
",",
"end_offset",
"=",
"None",
")",
":",
"statement_count",
"=",
"10000",
"if",
"end_line",
"is",
"None",
":",
"end_line",
"=",
"10000",
"elif",
"relative_pos",
":",
"end_line",
"+=",
"start_line",
"-",
"1",
"pass",
"labels",
"=",
"findlabels",
"(",
"code",
")",
"null_print",
"=",
"lambda",
"x",
":",
"None",
"if",
"start_line",
">",
"cur_line",
":",
"msg_nocr",
"=",
"null_print",
"msg",
"=",
"null_print",
"else",
":",
"msg_nocr",
"=",
"orig_msg_nocr",
"msg",
"=",
"orig_msg",
"for",
"instr",
"in",
"get_instructions_bytes",
"(",
"code",
",",
"opc",
",",
"varnames",
",",
"names",
",",
"constants",
",",
"cells",
",",
"linestarts",
")",
":",
"offset",
"=",
"instr",
".",
"offset",
"if",
"end_offset",
"and",
"offset",
">",
"end_offset",
":",
"break",
"if",
"instr",
".",
"starts_line",
":",
"if",
"offset",
":",
"msg",
"(",
"\"\"",
")",
"cur_line",
"=",
"instr",
".",
"starts_line",
"if",
"(",
"start_line",
"and",
"(",
"(",
"start_line",
">",
"cur_line",
")",
"or",
"start_offset",
"and",
"start_offset",
">",
"offset",
")",
")",
":",
"msg_nocr",
"=",
"null_print",
"msg",
"=",
"null_print",
"else",
":",
"statement_count",
"-=",
"1",
"msg_nocr",
"=",
"orig_msg_nocr",
"msg",
"=",
"orig_msg",
"pass",
"if",
"(",
"(",
"cur_line",
">",
"end_line",
")",
"or",
"(",
"end_offset",
"and",
"offset",
">",
"end_offset",
")",
")",
":",
"break",
"msg_nocr",
"(",
"format_token",
"(",
"Mformat",
".",
"LineNumber",
",",
"\"%4d\"",
"%",
"cur_line",
",",
"highlight",
"=",
"highlight",
")",
")",
"else",
":",
"if",
"start_offset",
"and",
"offset",
"and",
"start_offset",
"<=",
"offset",
":",
"msg_nocr",
"=",
"orig_msg_nocr",
"msg",
"=",
"orig_msg",
"pass",
"msg_nocr",
"(",
"' '",
")",
"if",
"offset",
"==",
"lasti",
":",
"msg_nocr",
"(",
"format_token",
"(",
"Mformat",
".",
"Arrow",
",",
"'-->'",
",",
"highlight",
"=",
"highlight",
")",
")",
"else",
":",
"msg_nocr",
"(",
"' '",
")",
"if",
"offset",
"in",
"labels",
":",
"msg_nocr",
"(",
"format_token",
"(",
"Mformat",
".",
"Arrow",
",",
"'>>'",
",",
"highlight",
"=",
"highlight",
")",
")",
"else",
":",
"msg_nocr",
"(",
"' '",
")",
"msg_nocr",
"(",
"repr",
"(",
"offset",
")",
".",
"rjust",
"(",
"4",
")",
")",
"msg_nocr",
"(",
"' '",
")",
"msg_nocr",
"(",
"format_token",
"(",
"Mformat",
".",
"Opcode",
",",
"instr",
".",
"opname",
".",
"ljust",
"(",
"20",
")",
",",
"highlight",
"=",
"highlight",
")",
")",
"msg_nocr",
"(",
"repr",
"(",
"instr",
".",
"arg",
")",
".",
"ljust",
"(",
"10",
")",
")",
"msg_nocr",
"(",
"' '",
")",
"# Show argval?",
"msg",
"(",
"format_token",
"(",
"Mformat",
".",
"Name",
",",
"instr",
".",
"argrepr",
".",
"ljust",
"(",
"20",
")",
",",
"highlight",
"=",
"highlight",
")",
")",
"pass",
"return",
"code",
",",
"offset"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
count_frames
|
Return a count of the number of frames
|
trepan/lib/stack.py
|
def count_frames(frame, count_start=0):
"Return a count of the number of frames"
count = -count_start
while frame:
count += 1
frame = frame.f_back
return count
|
def count_frames(frame, count_start=0):
"Return a count of the number of frames"
count = -count_start
while frame:
count += 1
frame = frame.f_back
return count
|
[
"Return",
"a",
"count",
"of",
"the",
"number",
"of",
"frames"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/stack.py#L31-L37
|
[
"def",
"count_frames",
"(",
"frame",
",",
"count_start",
"=",
"0",
")",
":",
"count",
"=",
"-",
"count_start",
"while",
"frame",
":",
"count",
"+=",
"1",
"frame",
"=",
"frame",
".",
"f_back",
"return",
"count"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
format_stack_entry
|
Format and return a stack entry gdb-style.
Note: lprefix is not used. It is kept for compatibility.
|
trepan/lib/stack.py
|
def format_stack_entry(dbg_obj, frame_lineno, lprefix=': ',
include_location=True, color='plain'):
"""Format and return a stack entry gdb-style.
Note: lprefix is not used. It is kept for compatibility.
"""
frame, lineno = frame_lineno
filename = frame2file(dbg_obj.core, frame)
s = ''
if frame.f_code.co_name:
funcname = frame.f_code.co_name
else:
funcname = "<lambda>"
pass
s = format_token(Mformat.Function, funcname, highlight=color)
args, varargs, varkw, local_vars = inspect.getargvalues(frame)
if '<module>' == funcname and ([], None, None,) == (args, varargs, varkw,):
is_module = True
if is_exec_stmt(frame):
fn_name = format_token(Mformat.Function, 'exec', highlight=color)
source_text = deparse_source_from_code(frame.f_code)
s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
highlight=color), source_text)
else:
fn_name = get_call_function_name(frame)
if fn_name:
source_text = deparse_source_from_code(frame.f_code)
if fn_name: s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
highlight=color), source_text)
pass
else:
is_module = False
parms=inspect.formatargvalues(args, varargs, varkw, local_vars)
maxargstrsize = dbg_obj.settings['maxargstrsize']
if len(parms) >= maxargstrsize:
parms = "%s...)" % parms[0:maxargstrsize]
pass
s += parms
pass
# Note: ddd can't handle wrapped stack entries (yet).
# The 35 is hoaky though. FIXME.
if len(s) >= 35: s += "\n "
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
s += '->'
s += format_token(Mformat.Return, Mrepr.repr(rv),
highlight=color)
pass
if include_location:
is_pseudo_file = _re_pseudo_file.match(filename)
add_quotes_around_file = not is_pseudo_file
if is_module:
if filename == '<string>':
s += ' in exec'
elif not is_exec_stmt(frame) and not is_pseudo_file:
s += ' file'
elif s == '?()':
if is_exec_stmt(frame):
s = 'in exec'
# exec_str = get_exec_string(frame.f_back)
# if exec_str != None:
# filename = exec_str
# add_quotes_around_file = False
# pass
# pass
elif not is_pseudo_file:
s = 'in file'
pass
pass
elif not is_pseudo_file:
s += ' called from file'
pass
if add_quotes_around_file: filename = "'%s'" % filename
s += " %s at line %s" % (
format_token(Mformat.Filename, filename,
highlight=color),
format_token(Mformat.LineNumber, "%r" % lineno,
highlight=color)
)
return s
|
def format_stack_entry(dbg_obj, frame_lineno, lprefix=': ',
include_location=True, color='plain'):
"""Format and return a stack entry gdb-style.
Note: lprefix is not used. It is kept for compatibility.
"""
frame, lineno = frame_lineno
filename = frame2file(dbg_obj.core, frame)
s = ''
if frame.f_code.co_name:
funcname = frame.f_code.co_name
else:
funcname = "<lambda>"
pass
s = format_token(Mformat.Function, funcname, highlight=color)
args, varargs, varkw, local_vars = inspect.getargvalues(frame)
if '<module>' == funcname and ([], None, None,) == (args, varargs, varkw,):
is_module = True
if is_exec_stmt(frame):
fn_name = format_token(Mformat.Function, 'exec', highlight=color)
source_text = deparse_source_from_code(frame.f_code)
s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
highlight=color), source_text)
else:
fn_name = get_call_function_name(frame)
if fn_name:
source_text = deparse_source_from_code(frame.f_code)
if fn_name: s += ' %s(%s)' % (format_token(Mformat.Function, fn_name,
highlight=color), source_text)
pass
else:
is_module = False
parms=inspect.formatargvalues(args, varargs, varkw, local_vars)
maxargstrsize = dbg_obj.settings['maxargstrsize']
if len(parms) >= maxargstrsize:
parms = "%s...)" % parms[0:maxargstrsize]
pass
s += parms
pass
# Note: ddd can't handle wrapped stack entries (yet).
# The 35 is hoaky though. FIXME.
if len(s) >= 35: s += "\n "
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
s += '->'
s += format_token(Mformat.Return, Mrepr.repr(rv),
highlight=color)
pass
if include_location:
is_pseudo_file = _re_pseudo_file.match(filename)
add_quotes_around_file = not is_pseudo_file
if is_module:
if filename == '<string>':
s += ' in exec'
elif not is_exec_stmt(frame) and not is_pseudo_file:
s += ' file'
elif s == '?()':
if is_exec_stmt(frame):
s = 'in exec'
# exec_str = get_exec_string(frame.f_back)
# if exec_str != None:
# filename = exec_str
# add_quotes_around_file = False
# pass
# pass
elif not is_pseudo_file:
s = 'in file'
pass
pass
elif not is_pseudo_file:
s += ' called from file'
pass
if add_quotes_around_file: filename = "'%s'" % filename
s += " %s at line %s" % (
format_token(Mformat.Filename, filename,
highlight=color),
format_token(Mformat.LineNumber, "%r" % lineno,
highlight=color)
)
return s
|
[
"Format",
"and",
"return",
"a",
"stack",
"entry",
"gdb",
"-",
"style",
".",
"Note",
":",
"lprefix",
"is",
"not",
"used",
".",
"It",
"is",
"kept",
"for",
"compatibility",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/stack.py#L60-L144
|
[
"def",
"format_stack_entry",
"(",
"dbg_obj",
",",
"frame_lineno",
",",
"lprefix",
"=",
"': '",
",",
"include_location",
"=",
"True",
",",
"color",
"=",
"'plain'",
")",
":",
"frame",
",",
"lineno",
"=",
"frame_lineno",
"filename",
"=",
"frame2file",
"(",
"dbg_obj",
".",
"core",
",",
"frame",
")",
"s",
"=",
"''",
"if",
"frame",
".",
"f_code",
".",
"co_name",
":",
"funcname",
"=",
"frame",
".",
"f_code",
".",
"co_name",
"else",
":",
"funcname",
"=",
"\"<lambda>\"",
"pass",
"s",
"=",
"format_token",
"(",
"Mformat",
".",
"Function",
",",
"funcname",
",",
"highlight",
"=",
"color",
")",
"args",
",",
"varargs",
",",
"varkw",
",",
"local_vars",
"=",
"inspect",
".",
"getargvalues",
"(",
"frame",
")",
"if",
"'<module>'",
"==",
"funcname",
"and",
"(",
"[",
"]",
",",
"None",
",",
"None",
",",
")",
"==",
"(",
"args",
",",
"varargs",
",",
"varkw",
",",
")",
":",
"is_module",
"=",
"True",
"if",
"is_exec_stmt",
"(",
"frame",
")",
":",
"fn_name",
"=",
"format_token",
"(",
"Mformat",
".",
"Function",
",",
"'exec'",
",",
"highlight",
"=",
"color",
")",
"source_text",
"=",
"deparse_source_from_code",
"(",
"frame",
".",
"f_code",
")",
"s",
"+=",
"' %s(%s)'",
"%",
"(",
"format_token",
"(",
"Mformat",
".",
"Function",
",",
"fn_name",
",",
"highlight",
"=",
"color",
")",
",",
"source_text",
")",
"else",
":",
"fn_name",
"=",
"get_call_function_name",
"(",
"frame",
")",
"if",
"fn_name",
":",
"source_text",
"=",
"deparse_source_from_code",
"(",
"frame",
".",
"f_code",
")",
"if",
"fn_name",
":",
"s",
"+=",
"' %s(%s)'",
"%",
"(",
"format_token",
"(",
"Mformat",
".",
"Function",
",",
"fn_name",
",",
"highlight",
"=",
"color",
")",
",",
"source_text",
")",
"pass",
"else",
":",
"is_module",
"=",
"False",
"parms",
"=",
"inspect",
".",
"formatargvalues",
"(",
"args",
",",
"varargs",
",",
"varkw",
",",
"local_vars",
")",
"maxargstrsize",
"=",
"dbg_obj",
".",
"settings",
"[",
"'maxargstrsize'",
"]",
"if",
"len",
"(",
"parms",
")",
">=",
"maxargstrsize",
":",
"parms",
"=",
"\"%s...)\"",
"%",
"parms",
"[",
"0",
":",
"maxargstrsize",
"]",
"pass",
"s",
"+=",
"parms",
"pass",
"# Note: ddd can't handle wrapped stack entries (yet).",
"# The 35 is hoaky though. FIXME.",
"if",
"len",
"(",
"s",
")",
">=",
"35",
":",
"s",
"+=",
"\"\\n \"",
"if",
"'__return__'",
"in",
"frame",
".",
"f_locals",
":",
"rv",
"=",
"frame",
".",
"f_locals",
"[",
"'__return__'",
"]",
"s",
"+=",
"'->'",
"s",
"+=",
"format_token",
"(",
"Mformat",
".",
"Return",
",",
"Mrepr",
".",
"repr",
"(",
"rv",
")",
",",
"highlight",
"=",
"color",
")",
"pass",
"if",
"include_location",
":",
"is_pseudo_file",
"=",
"_re_pseudo_file",
".",
"match",
"(",
"filename",
")",
"add_quotes_around_file",
"=",
"not",
"is_pseudo_file",
"if",
"is_module",
":",
"if",
"filename",
"==",
"'<string>'",
":",
"s",
"+=",
"' in exec'",
"elif",
"not",
"is_exec_stmt",
"(",
"frame",
")",
"and",
"not",
"is_pseudo_file",
":",
"s",
"+=",
"' file'",
"elif",
"s",
"==",
"'?()'",
":",
"if",
"is_exec_stmt",
"(",
"frame",
")",
":",
"s",
"=",
"'in exec'",
"# exec_str = get_exec_string(frame.f_back)",
"# if exec_str != None:",
"# filename = exec_str",
"# add_quotes_around_file = False",
"# pass",
"# pass",
"elif",
"not",
"is_pseudo_file",
":",
"s",
"=",
"'in file'",
"pass",
"pass",
"elif",
"not",
"is_pseudo_file",
":",
"s",
"+=",
"' called from file'",
"pass",
"if",
"add_quotes_around_file",
":",
"filename",
"=",
"\"'%s'\"",
"%",
"filename",
"s",
"+=",
"\" %s at line %s\"",
"%",
"(",
"format_token",
"(",
"Mformat",
".",
"Filename",
",",
"filename",
",",
"highlight",
"=",
"color",
")",
",",
"format_token",
"(",
"Mformat",
".",
"LineNumber",
",",
"\"%r\"",
"%",
"lineno",
",",
"highlight",
"=",
"color",
")",
")",
"return",
"s"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
get_call_function_name
|
If f_back is looking at a call function, return
the name for it. Otherwise return None
|
trepan/lib/stack.py
|
def get_call_function_name(frame):
"""If f_back is looking at a call function, return
the name for it. Otherwise return None"""
f_back = frame.f_back
if not f_back: return None
if 'CALL_FUNCTION' != Mbytecode.op_at_frame(f_back): return None
co = f_back.f_code
code = co.co_code
# labels = dis.findlabels(code)
linestarts = dict(dis.findlinestarts(co))
offset = f_back.f_lasti
while offset >= 0:
if offset in linestarts:
op = code[offset]
offset += 1
arg = code[offset]
# FIXME: put this code in xdis
extended_arg = 0
while True:
if PYTHON_VERSION >= 3.6:
if op == opc.EXTENDED_ARG:
extended_arg += (arg << 8)
continue
arg = code[offset] + extended_arg
# FIXME: Python 3.6.0a1 is 2, for 3.6.a3 we have 1
else:
if op == opc.EXTENDED_ARG:
extended_arg += (arg << 256)
continue
arg = code[offset] + code[offset+1]*256 + extended_arg
break
return co.co_names[arg]
offset -= 1
pass
return None
|
def get_call_function_name(frame):
"""If f_back is looking at a call function, return
the name for it. Otherwise return None"""
f_back = frame.f_back
if not f_back: return None
if 'CALL_FUNCTION' != Mbytecode.op_at_frame(f_back): return None
co = f_back.f_code
code = co.co_code
# labels = dis.findlabels(code)
linestarts = dict(dis.findlinestarts(co))
offset = f_back.f_lasti
while offset >= 0:
if offset in linestarts:
op = code[offset]
offset += 1
arg = code[offset]
# FIXME: put this code in xdis
extended_arg = 0
while True:
if PYTHON_VERSION >= 3.6:
if op == opc.EXTENDED_ARG:
extended_arg += (arg << 8)
continue
arg = code[offset] + extended_arg
# FIXME: Python 3.6.0a1 is 2, for 3.6.a3 we have 1
else:
if op == opc.EXTENDED_ARG:
extended_arg += (arg << 256)
continue
arg = code[offset] + code[offset+1]*256 + extended_arg
break
return co.co_names[arg]
offset -= 1
pass
return None
|
[
"If",
"f_back",
"is",
"looking",
"at",
"a",
"call",
"function",
"return",
"the",
"name",
"for",
"it",
".",
"Otherwise",
"return",
"None"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/stack.py#L188-L224
|
[
"def",
"get_call_function_name",
"(",
"frame",
")",
":",
"f_back",
"=",
"frame",
".",
"f_back",
"if",
"not",
"f_back",
":",
"return",
"None",
"if",
"'CALL_FUNCTION'",
"!=",
"Mbytecode",
".",
"op_at_frame",
"(",
"f_back",
")",
":",
"return",
"None",
"co",
"=",
"f_back",
".",
"f_code",
"code",
"=",
"co",
".",
"co_code",
"# labels = dis.findlabels(code)",
"linestarts",
"=",
"dict",
"(",
"dis",
".",
"findlinestarts",
"(",
"co",
")",
")",
"offset",
"=",
"f_back",
".",
"f_lasti",
"while",
"offset",
">=",
"0",
":",
"if",
"offset",
"in",
"linestarts",
":",
"op",
"=",
"code",
"[",
"offset",
"]",
"offset",
"+=",
"1",
"arg",
"=",
"code",
"[",
"offset",
"]",
"# FIXME: put this code in xdis",
"extended_arg",
"=",
"0",
"while",
"True",
":",
"if",
"PYTHON_VERSION",
">=",
"3.6",
":",
"if",
"op",
"==",
"opc",
".",
"EXTENDED_ARG",
":",
"extended_arg",
"+=",
"(",
"arg",
"<<",
"8",
")",
"continue",
"arg",
"=",
"code",
"[",
"offset",
"]",
"+",
"extended_arg",
"# FIXME: Python 3.6.0a1 is 2, for 3.6.a3 we have 1",
"else",
":",
"if",
"op",
"==",
"opc",
".",
"EXTENDED_ARG",
":",
"extended_arg",
"+=",
"(",
"arg",
"<<",
"256",
")",
"continue",
"arg",
"=",
"code",
"[",
"offset",
"]",
"+",
"code",
"[",
"offset",
"+",
"1",
"]",
"*",
"256",
"+",
"extended_arg",
"break",
"return",
"co",
".",
"co_names",
"[",
"arg",
"]",
"offset",
"-=",
"1",
"pass",
"return",
"None"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
print_stack_trace
|
Print count entries of the stack trace
|
trepan/lib/stack.py
|
def print_stack_trace(proc_obj, count=None, color='plain', opts={}):
"Print count entries of the stack trace"
if count is None:
n=len(proc_obj.stack)
else:
n=min(len(proc_obj.stack), count)
try:
for i in range(n):
print_stack_entry(proc_obj, i, color=color, opts=opts)
except KeyboardInterrupt:
pass
return
|
def print_stack_trace(proc_obj, count=None, color='plain', opts={}):
"Print count entries of the stack trace"
if count is None:
n=len(proc_obj.stack)
else:
n=min(len(proc_obj.stack), count)
try:
for i in range(n):
print_stack_entry(proc_obj, i, color=color, opts=opts)
except KeyboardInterrupt:
pass
return
|
[
"Print",
"count",
"entries",
"of",
"the",
"stack",
"trace"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/stack.py#L282-L293
|
[
"def",
"print_stack_trace",
"(",
"proc_obj",
",",
"count",
"=",
"None",
",",
"color",
"=",
"'plain'",
",",
"opts",
"=",
"{",
"}",
")",
":",
"if",
"count",
"is",
"None",
":",
"n",
"=",
"len",
"(",
"proc_obj",
".",
"stack",
")",
"else",
":",
"n",
"=",
"min",
"(",
"len",
"(",
"proc_obj",
".",
"stack",
")",
",",
"count",
")",
"try",
":",
"for",
"i",
"in",
"range",
"(",
"n",
")",
":",
"print_stack_entry",
"(",
"proc_obj",
",",
"i",
",",
"color",
"=",
"color",
",",
"opts",
"=",
"opts",
")",
"except",
"KeyboardInterrupt",
":",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
eval_print_obj
|
Return a string representation of an object
|
trepan/lib/stack.py
|
def eval_print_obj(arg, frame, format=None, short=False):
"""Return a string representation of an object """
try:
if not frame:
# ?? Should we have set up a dummy globals
# to have persistence?
val = eval(arg, None, None)
else:
val = eval(arg, frame.f_globals, frame.f_locals)
pass
except:
return 'No symbol "' + arg + '" in current context.'
return print_obj(arg, val, format, short)
|
def eval_print_obj(arg, frame, format=None, short=False):
"""Return a string representation of an object """
try:
if not frame:
# ?? Should we have set up a dummy globals
# to have persistence?
val = eval(arg, None, None)
else:
val = eval(arg, frame.f_globals, frame.f_locals)
pass
except:
return 'No symbol "' + arg + '" in current context.'
return print_obj(arg, val, format, short)
|
[
"Return",
"a",
"string",
"representation",
"of",
"an",
"object"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/stack.py#L314-L327
|
[
"def",
"eval_print_obj",
"(",
"arg",
",",
"frame",
",",
"format",
"=",
"None",
",",
"short",
"=",
"False",
")",
":",
"try",
":",
"if",
"not",
"frame",
":",
"# ?? Should we have set up a dummy globals",
"# to have persistence?",
"val",
"=",
"eval",
"(",
"arg",
",",
"None",
",",
"None",
")",
"else",
":",
"val",
"=",
"eval",
"(",
"arg",
",",
"frame",
".",
"f_globals",
",",
"frame",
".",
"f_locals",
")",
"pass",
"except",
":",
"return",
"'No symbol \"'",
"+",
"arg",
"+",
"'\" in current context.'",
"return",
"print_obj",
"(",
"arg",
",",
"val",
",",
"format",
",",
"short",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
print_obj
|
Return a string representation of an object
|
trepan/lib/stack.py
|
def print_obj(arg, val, format=None, short=False):
"""Return a string representation of an object """
what = arg
if format:
what = format + ' ' + arg
val = Mprint.printf(val, format)
pass
s = '%s = %s' % (what, val)
if not short:
s += '\n type = %s' % type(val)
# Try to list the members of a class.
# Not sure if this is correct or the
# best way to do.
s = print_dict(s, val, "object variables")
if hasattr(val, "__class__"):
s = print_dict(s, val.__class__, "class variables")
pass
pass
return s
|
def print_obj(arg, val, format=None, short=False):
"""Return a string representation of an object """
what = arg
if format:
what = format + ' ' + arg
val = Mprint.printf(val, format)
pass
s = '%s = %s' % (what, val)
if not short:
s += '\n type = %s' % type(val)
# Try to list the members of a class.
# Not sure if this is correct or the
# best way to do.
s = print_dict(s, val, "object variables")
if hasattr(val, "__class__"):
s = print_dict(s, val.__class__, "class variables")
pass
pass
return s
|
[
"Return",
"a",
"string",
"representation",
"of",
"an",
"object"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/stack.py#L330-L348
|
[
"def",
"print_obj",
"(",
"arg",
",",
"val",
",",
"format",
"=",
"None",
",",
"short",
"=",
"False",
")",
":",
"what",
"=",
"arg",
"if",
"format",
":",
"what",
"=",
"format",
"+",
"' '",
"+",
"arg",
"val",
"=",
"Mprint",
".",
"printf",
"(",
"val",
",",
"format",
")",
"pass",
"s",
"=",
"'%s = %s'",
"%",
"(",
"what",
",",
"val",
")",
"if",
"not",
"short",
":",
"s",
"+=",
"'\\n type = %s'",
"%",
"type",
"(",
"val",
")",
"# Try to list the members of a class.",
"# Not sure if this is correct or the",
"# best way to do.",
"s",
"=",
"print_dict",
"(",
"s",
",",
"val",
",",
"\"object variables\"",
")",
"if",
"hasattr",
"(",
"val",
",",
"\"__class__\"",
")",
":",
"s",
"=",
"print_dict",
"(",
"s",
",",
"val",
".",
"__class__",
",",
"\"class variables\"",
")",
"pass",
"pass",
"return",
"s"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Subcmd.lookup
|
Find subcmd in self.subcmds
|
trepan/processor/subcmd.py
|
def lookup(self, subcmd_prefix):
"""Find subcmd in self.subcmds"""
for subcmd_name in list(self.subcmds.keys()):
if subcmd_name.startswith(subcmd_prefix) \
and len(subcmd_prefix) >= \
self.subcmds[subcmd_name].__class__.min_abbrev:
return self.subcmds[subcmd_name]
pass
return None
|
def lookup(self, subcmd_prefix):
"""Find subcmd in self.subcmds"""
for subcmd_name in list(self.subcmds.keys()):
if subcmd_name.startswith(subcmd_prefix) \
and len(subcmd_prefix) >= \
self.subcmds[subcmd_name].__class__.min_abbrev:
return self.subcmds[subcmd_name]
pass
return None
|
[
"Find",
"subcmd",
"in",
"self",
".",
"subcmds"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/subcmd.py#L28-L36
|
[
"def",
"lookup",
"(",
"self",
",",
"subcmd_prefix",
")",
":",
"for",
"subcmd_name",
"in",
"list",
"(",
"self",
".",
"subcmds",
".",
"keys",
"(",
")",
")",
":",
"if",
"subcmd_name",
".",
"startswith",
"(",
"subcmd_prefix",
")",
"and",
"len",
"(",
"subcmd_prefix",
")",
">=",
"self",
".",
"subcmds",
"[",
"subcmd_name",
"]",
".",
"__class__",
".",
"min_abbrev",
":",
"return",
"self",
".",
"subcmds",
"[",
"subcmd_name",
"]",
"pass",
"return",
"None"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Subcmd.short_help
|
Show short help for a subcommand.
|
trepan/processor/subcmd.py
|
def short_help(self, subcmd_cb, subcmd_name, label=False):
"""Show short help for a subcommand."""
entry = self.lookup(subcmd_name)
if entry:
if label:
prefix = entry.name
else:
prefix = ''
pass
if hasattr(entry, 'short_help'):
if prefix: prefix += ' -- '
self.cmd_obj.msg(prefix + entry.short_help)
pass
pass
else:
self.undefined_subcmd("help", subcmd_name)
pass
return
|
def short_help(self, subcmd_cb, subcmd_name, label=False):
"""Show short help for a subcommand."""
entry = self.lookup(subcmd_name)
if entry:
if label:
prefix = entry.name
else:
prefix = ''
pass
if hasattr(entry, 'short_help'):
if prefix: prefix += ' -- '
self.cmd_obj.msg(prefix + entry.short_help)
pass
pass
else:
self.undefined_subcmd("help", subcmd_name)
pass
return
|
[
"Show",
"short",
"help",
"for",
"a",
"subcommand",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/subcmd.py#L38-L55
|
[
"def",
"short_help",
"(",
"self",
",",
"subcmd_cb",
",",
"subcmd_name",
",",
"label",
"=",
"False",
")",
":",
"entry",
"=",
"self",
".",
"lookup",
"(",
"subcmd_name",
")",
"if",
"entry",
":",
"if",
"label",
":",
"prefix",
"=",
"entry",
".",
"name",
"else",
":",
"prefix",
"=",
"''",
"pass",
"if",
"hasattr",
"(",
"entry",
",",
"'short_help'",
")",
":",
"if",
"prefix",
":",
"prefix",
"+=",
"' -- '",
"self",
".",
"cmd_obj",
".",
"msg",
"(",
"prefix",
"+",
"entry",
".",
"short_help",
")",
"pass",
"pass",
"else",
":",
"self",
".",
"undefined_subcmd",
"(",
"\"help\"",
",",
"subcmd_name",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Subcmd.add
|
Add subcmd to the available subcommands for this object.
It will have the supplied docstring, and subcmd_cb will be called
when we want to run the command. min_len is the minimum length
allowed to abbreviate the command. in_list indicates with the
show command will be run when giving a list of all sub commands
of this object. Some commands have long output like "show commands"
so we might not want to show that.
|
trepan/processor/subcmd.py
|
def add(self, subcmd_cb):
"""Add subcmd to the available subcommands for this object.
It will have the supplied docstring, and subcmd_cb will be called
when we want to run the command. min_len is the minimum length
allowed to abbreviate the command. in_list indicates with the
show command will be run when giving a list of all sub commands
of this object. Some commands have long output like "show commands"
so we might not want to show that.
"""
subcmd_name = subcmd_cb.name
self.subcmds[subcmd_name] = subcmd_cb
# We keep a list of subcommands to assist command completion
self.cmdlist.append(subcmd_name)
|
def add(self, subcmd_cb):
"""Add subcmd to the available subcommands for this object.
It will have the supplied docstring, and subcmd_cb will be called
when we want to run the command. min_len is the minimum length
allowed to abbreviate the command. in_list indicates with the
show command will be run when giving a list of all sub commands
of this object. Some commands have long output like "show commands"
so we might not want to show that.
"""
subcmd_name = subcmd_cb.name
self.subcmds[subcmd_name] = subcmd_cb
# We keep a list of subcommands to assist command completion
self.cmdlist.append(subcmd_name)
|
[
"Add",
"subcmd",
"to",
"the",
"available",
"subcommands",
"for",
"this",
"object",
".",
"It",
"will",
"have",
"the",
"supplied",
"docstring",
"and",
"subcmd_cb",
"will",
"be",
"called",
"when",
"we",
"want",
"to",
"run",
"the",
"command",
".",
"min_len",
"is",
"the",
"minimum",
"length",
"allowed",
"to",
"abbreviate",
"the",
"command",
".",
"in_list",
"indicates",
"with",
"the",
"show",
"command",
"will",
"be",
"run",
"when",
"giving",
"a",
"list",
"of",
"all",
"sub",
"commands",
"of",
"this",
"object",
".",
"Some",
"commands",
"have",
"long",
"output",
"like",
"show",
"commands",
"so",
"we",
"might",
"not",
"want",
"to",
"show",
"that",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/subcmd.py#L57-L70
|
[
"def",
"add",
"(",
"self",
",",
"subcmd_cb",
")",
":",
"subcmd_name",
"=",
"subcmd_cb",
".",
"name",
"self",
".",
"subcmds",
"[",
"subcmd_name",
"]",
"=",
"subcmd_cb",
"# We keep a list of subcommands to assist command completion",
"self",
".",
"cmdlist",
".",
"append",
"(",
"subcmd_name",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Subcmd.run
|
Run subcmd_name with args using obj for the environent
|
trepan/processor/subcmd.py
|
def run(self, subcmd_name, arg):
"""Run subcmd_name with args using obj for the environent"""
entry=self.lookup(subcmd_name)
if entry:
entry['callback'](arg)
else:
self.cmdproc.undefined_cmd(entry.__class__.name, subcmd_name)
pass
return
|
def run(self, subcmd_name, arg):
"""Run subcmd_name with args using obj for the environent"""
entry=self.lookup(subcmd_name)
if entry:
entry['callback'](arg)
else:
self.cmdproc.undefined_cmd(entry.__class__.name, subcmd_name)
pass
return
|
[
"Run",
"subcmd_name",
"with",
"args",
"using",
"obj",
"for",
"the",
"environent"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/subcmd.py#L72-L80
|
[
"def",
"run",
"(",
"self",
",",
"subcmd_name",
",",
"arg",
")",
":",
"entry",
"=",
"self",
".",
"lookup",
"(",
"subcmd_name",
")",
"if",
"entry",
":",
"entry",
"[",
"'callback'",
"]",
"(",
"arg",
")",
"else",
":",
"self",
".",
"cmdproc",
".",
"undefined_cmd",
"(",
"entry",
".",
"__class__",
".",
"name",
",",
"subcmd_name",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
Subcmd.help
|
help for subcommands.
|
trepan/processor/subcmd.py
|
def help(self, *args):
"""help for subcommands."""
print(args)
subcmd_prefix = args[0]
if not subcmd_prefix or len(subcmd_prefix) == 0:
self.msg(self.doc)
self.msg("""
List of %s subcommands:
""" % (self.name))
for subcmd_name in self.list():
self._subcmd_helper(subcmd_name, self, True, True)
return
entry = self.lookup(subcmd_prefix)
if entry and hasattr(entry, 'help'):
entry.help(args)
else:
self.cmd_obj.errmsg("Unknown 'help %s' subcommand %s"
% (self.name, subcmd_prefix))
|
def help(self, *args):
"""help for subcommands."""
print(args)
subcmd_prefix = args[0]
if not subcmd_prefix or len(subcmd_prefix) == 0:
self.msg(self.doc)
self.msg("""
List of %s subcommands:
""" % (self.name))
for subcmd_name in self.list():
self._subcmd_helper(subcmd_name, self, True, True)
return
entry = self.lookup(subcmd_prefix)
if entry and hasattr(entry, 'help'):
entry.help(args)
else:
self.cmd_obj.errmsg("Unknown 'help %s' subcommand %s"
% (self.name, subcmd_prefix))
|
[
"help",
"for",
"subcommands",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/subcmd.py#L83-L102
|
[
"def",
"help",
"(",
"self",
",",
"*",
"args",
")",
":",
"print",
"(",
"args",
")",
"subcmd_prefix",
"=",
"args",
"[",
"0",
"]",
"if",
"not",
"subcmd_prefix",
"or",
"len",
"(",
"subcmd_prefix",
")",
"==",
"0",
":",
"self",
".",
"msg",
"(",
"self",
".",
"doc",
")",
"self",
".",
"msg",
"(",
"\"\"\"\nList of %s subcommands:\n\"\"\"",
"%",
"(",
"self",
".",
"name",
")",
")",
"for",
"subcmd_name",
"in",
"self",
".",
"list",
"(",
")",
":",
"self",
".",
"_subcmd_helper",
"(",
"subcmd_name",
",",
"self",
",",
"True",
",",
"True",
")",
"return",
"entry",
"=",
"self",
".",
"lookup",
"(",
"subcmd_prefix",
")",
"if",
"entry",
"and",
"hasattr",
"(",
"entry",
",",
"'help'",
")",
":",
"entry",
".",
"help",
"(",
"args",
")",
"else",
":",
"self",
".",
"cmd_obj",
".",
"errmsg",
"(",
"\"Unknown 'help %s' subcommand %s\"",
"%",
"(",
"self",
".",
"name",
",",
"subcmd_prefix",
")",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
yield_sphinx_only_markup
|
:param file_inp: a `filename` or ``sys.stdin``?
:param file_out: a `filename` or ``sys.stdout`?`
|
rst2html.py
|
def yield_sphinx_only_markup(lines):
"""
:param file_inp: a `filename` or ``sys.stdin``?
:param file_out: a `filename` or ``sys.stdout`?`
"""
substs = [
## Selected Sphinx-only Roles.
#
(r':abbr:`([^`]+)`', r'\1'),
(r':ref:`([^`]+)`', r'`\1`_'),
(r':term:`([^`]+)`', r'**\1**'),
(r':dfn:`([^`]+)`', r'**\1**'),
(r':(samp|guilabel|menuselection):`([^`]+)`', r'``\2``'),
## Sphinx-only roles:
# :foo:`bar` --> foo(``bar``)
# :a:foo:`bar` XXX afoo(``bar``)
#
#(r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'),
(r':(\w+):`([^`]*)`', r'\1(``\2``)'),
## Sphinx-only Directives.
#
(r'\.\. doctest', r'code-block'),
(r'\.\. plot::', r'.. '),
(r'\.\. seealso', r'info'),
(r'\.\. glossary', r'rubric'),
(r'\.\. figure::', r'.. '),
## Other
#
(r'\|version\|', r'x.x.x'),
]
regex_subs = [ (re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs ]
def clean_line(line):
try:
for (regex, sub) in regex_subs:
line = regex.sub(sub, line)
except Exception as ex:
print("ERROR: %s, (line(%s)"%(regex, sub))
raise ex
return line
for line in lines:
yield clean_line(line)
|
def yield_sphinx_only_markup(lines):
"""
:param file_inp: a `filename` or ``sys.stdin``?
:param file_out: a `filename` or ``sys.stdout`?`
"""
substs = [
## Selected Sphinx-only Roles.
#
(r':abbr:`([^`]+)`', r'\1'),
(r':ref:`([^`]+)`', r'`\1`_'),
(r':term:`([^`]+)`', r'**\1**'),
(r':dfn:`([^`]+)`', r'**\1**'),
(r':(samp|guilabel|menuselection):`([^`]+)`', r'``\2``'),
## Sphinx-only roles:
# :foo:`bar` --> foo(``bar``)
# :a:foo:`bar` XXX afoo(``bar``)
#
#(r'(:(\w+))?:(\w+):`([^`]*)`', r'\2\3(``\4``)'),
(r':(\w+):`([^`]*)`', r'\1(``\2``)'),
## Sphinx-only Directives.
#
(r'\.\. doctest', r'code-block'),
(r'\.\. plot::', r'.. '),
(r'\.\. seealso', r'info'),
(r'\.\. glossary', r'rubric'),
(r'\.\. figure::', r'.. '),
## Other
#
(r'\|version\|', r'x.x.x'),
]
regex_subs = [ (re.compile(regex, re.IGNORECASE), sub) for (regex, sub) in substs ]
def clean_line(line):
try:
for (regex, sub) in regex_subs:
line = regex.sub(sub, line)
except Exception as ex:
print("ERROR: %s, (line(%s)"%(regex, sub))
raise ex
return line
for line in lines:
yield clean_line(line)
|
[
":",
"param",
"file_inp",
":",
"a",
"filename",
"or",
"sys",
".",
"stdin",
"?",
":",
"param",
"file_out",
":",
"a",
"filename",
"or",
"sys",
".",
"stdout",
"?"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/rst2html.py#L14-L65
|
[
"def",
"yield_sphinx_only_markup",
"(",
"lines",
")",
":",
"substs",
"=",
"[",
"## Selected Sphinx-only Roles.",
"#",
"(",
"r':abbr:`([^`]+)`'",
",",
"r'\\1'",
")",
",",
"(",
"r':ref:`([^`]+)`'",
",",
"r'`\\1`_'",
")",
",",
"(",
"r':term:`([^`]+)`'",
",",
"r'**\\1**'",
")",
",",
"(",
"r':dfn:`([^`]+)`'",
",",
"r'**\\1**'",
")",
",",
"(",
"r':(samp|guilabel|menuselection):`([^`]+)`'",
",",
"r'``\\2``'",
")",
",",
"## Sphinx-only roles:",
"# :foo:`bar` --> foo(``bar``)",
"# :a:foo:`bar` XXX afoo(``bar``)",
"#",
"#(r'(:(\\w+))?:(\\w+):`([^`]*)`', r'\\2\\3(``\\4``)'),",
"(",
"r':(\\w+):`([^`]*)`'",
",",
"r'\\1(``\\2``)'",
")",
",",
"## Sphinx-only Directives.",
"#",
"(",
"r'\\.\\. doctest'",
",",
"r'code-block'",
")",
",",
"(",
"r'\\.\\. plot::'",
",",
"r'.. '",
")",
",",
"(",
"r'\\.\\. seealso'",
",",
"r'info'",
")",
",",
"(",
"r'\\.\\. glossary'",
",",
"r'rubric'",
")",
",",
"(",
"r'\\.\\. figure::'",
",",
"r'.. '",
")",
",",
"## Other",
"#",
"(",
"r'\\|version\\|'",
",",
"r'x.x.x'",
")",
",",
"]",
"regex_subs",
"=",
"[",
"(",
"re",
".",
"compile",
"(",
"regex",
",",
"re",
".",
"IGNORECASE",
")",
",",
"sub",
")",
"for",
"(",
"regex",
",",
"sub",
")",
"in",
"substs",
"]",
"def",
"clean_line",
"(",
"line",
")",
":",
"try",
":",
"for",
"(",
"regex",
",",
"sub",
")",
"in",
"regex_subs",
":",
"line",
"=",
"regex",
".",
"sub",
"(",
"sub",
",",
"line",
")",
"except",
"Exception",
"as",
"ex",
":",
"print",
"(",
"\"ERROR: %s, (line(%s)\"",
"%",
"(",
"regex",
",",
"sub",
")",
")",
"raise",
"ex",
"return",
"line",
"for",
"line",
"in",
"lines",
":",
"yield",
"clean_line",
"(",
"line",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_eval
|
Evaluate the expression (given as a string) under debugger
control starting with the statement subsequent to the place that
this appears in your program.
This is a wrapper to Debugger.run_eval(), so see that.
When run_eval() returns, it returns the value of the expression.
Otherwise this function is similar to run().
|
trepan/api.py
|
def run_eval(expression, debug_opts=None, start_opts=None, globals_=None,
locals_=None, tb_fn = None):
"""Evaluate the expression (given as a string) under debugger
control starting with the statement subsequent to the place that
this appears in your program.
This is a wrapper to Debugger.run_eval(), so see that.
When run_eval() returns, it returns the value of the expression.
Otherwise this function is similar to run().
"""
dbg = Mdebugger.Trepan(opts=debug_opts)
try:
return dbg.run_eval(expression, start_opts=start_opts,
globals_=globals_, locals_=locals_)
except:
dbg.core.trace_hook_suspend = True
if start_opts and 'tb_fn' in start_opts: tb_fn = start_opts['tb_fn']
Mpost_mortem.uncaught_exception(dbg, tb_fn)
finally:
dbg.core.trace_hook_suspend = False
return
|
def run_eval(expression, debug_opts=None, start_opts=None, globals_=None,
locals_=None, tb_fn = None):
"""Evaluate the expression (given as a string) under debugger
control starting with the statement subsequent to the place that
this appears in your program.
This is a wrapper to Debugger.run_eval(), so see that.
When run_eval() returns, it returns the value of the expression.
Otherwise this function is similar to run().
"""
dbg = Mdebugger.Trepan(opts=debug_opts)
try:
return dbg.run_eval(expression, start_opts=start_opts,
globals_=globals_, locals_=locals_)
except:
dbg.core.trace_hook_suspend = True
if start_opts and 'tb_fn' in start_opts: tb_fn = start_opts['tb_fn']
Mpost_mortem.uncaught_exception(dbg, tb_fn)
finally:
dbg.core.trace_hook_suspend = False
return
|
[
"Evaluate",
"the",
"expression",
"(",
"given",
"as",
"a",
"string",
")",
"under",
"debugger",
"control",
"starting",
"with",
"the",
"statement",
"subsequent",
"to",
"the",
"place",
"that",
"this",
"appears",
"in",
"your",
"program",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/api.py#L45-L68
|
[
"def",
"run_eval",
"(",
"expression",
",",
"debug_opts",
"=",
"None",
",",
"start_opts",
"=",
"None",
",",
"globals_",
"=",
"None",
",",
"locals_",
"=",
"None",
",",
"tb_fn",
"=",
"None",
")",
":",
"dbg",
"=",
"Mdebugger",
".",
"Trepan",
"(",
"opts",
"=",
"debug_opts",
")",
"try",
":",
"return",
"dbg",
".",
"run_eval",
"(",
"expression",
",",
"start_opts",
"=",
"start_opts",
",",
"globals_",
"=",
"globals_",
",",
"locals_",
"=",
"locals_",
")",
"except",
":",
"dbg",
".",
"core",
".",
"trace_hook_suspend",
"=",
"True",
"if",
"start_opts",
"and",
"'tb_fn'",
"in",
"start_opts",
":",
"tb_fn",
"=",
"start_opts",
"[",
"'tb_fn'",
"]",
"Mpost_mortem",
".",
"uncaught_exception",
"(",
"dbg",
",",
"tb_fn",
")",
"finally",
":",
"dbg",
".",
"core",
".",
"trace_hook_suspend",
"=",
"False",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_call
|
Call the function (a function or method object, not a string)
with the given arguments starting with the statement subsequent to
the place that this appears in your program.
When run_call() returns, it returns whatever the function call
returned. The debugger prompt appears as soon as the function is
entered.
|
trepan/api.py
|
def run_call(func, debug_opts=None, start_opts=None, *args, **kwds):
"""Call the function (a function or method object, not a string)
with the given arguments starting with the statement subsequent to
the place that this appears in your program.
When run_call() returns, it returns whatever the function call
returned. The debugger prompt appears as soon as the function is
entered."""
dbg = Mdebugger.Trepan(opts=debug_opts)
try:
return dbg.run_call(func, start_opts, *args, **kwds)
except:
Mpost_mortem.uncaught_exception(dbg)
pass
return
|
def run_call(func, debug_opts=None, start_opts=None, *args, **kwds):
"""Call the function (a function or method object, not a string)
with the given arguments starting with the statement subsequent to
the place that this appears in your program.
When run_call() returns, it returns whatever the function call
returned. The debugger prompt appears as soon as the function is
entered."""
dbg = Mdebugger.Trepan(opts=debug_opts)
try:
return dbg.run_call(func, start_opts, *args, **kwds)
except:
Mpost_mortem.uncaught_exception(dbg)
pass
return
|
[
"Call",
"the",
"function",
"(",
"a",
"function",
"or",
"method",
"object",
"not",
"a",
"string",
")",
"with",
"the",
"given",
"arguments",
"starting",
"with",
"the",
"statement",
"subsequent",
"to",
"the",
"place",
"that",
"this",
"appears",
"in",
"your",
"program",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/api.py#L71-L87
|
[
"def",
"run_call",
"(",
"func",
",",
"debug_opts",
"=",
"None",
",",
"start_opts",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"dbg",
"=",
"Mdebugger",
".",
"Trepan",
"(",
"opts",
"=",
"debug_opts",
")",
"try",
":",
"return",
"dbg",
".",
"run_call",
"(",
"func",
",",
"start_opts",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
"except",
":",
"Mpost_mortem",
".",
"uncaught_exception",
"(",
"dbg",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_exec
|
Execute the statement (given as a string) under debugger
control starting with the statement subsequent to the place that
this run_call appears in your program.
This is a wrapper to Debugger.run_exec(), so see that.
The debugger prompt appears before any code is executed;
you can set breakpoints and type 'continue', or you can step
through the statement using 'step' or 'next'
The optional globals_ and locals_ arguments specify the environment
in which the code is executed; by default the dictionary of the
module __main__ is used.
|
trepan/api.py
|
def run_exec(statement, debug_opts=None, start_opts=None, globals_=None,
locals_=None):
"""Execute the statement (given as a string) under debugger
control starting with the statement subsequent to the place that
this run_call appears in your program.
This is a wrapper to Debugger.run_exec(), so see that.
The debugger prompt appears before any code is executed;
you can set breakpoints and type 'continue', or you can step
through the statement using 'step' or 'next'
The optional globals_ and locals_ arguments specify the environment
in which the code is executed; by default the dictionary of the
module __main__ is used."""
dbg = Mdebugger.Trepan(opts=debug_opts)
try:
return dbg.run_exec(statement, start_opts=start_opts,
globals_=globals_, locals_=locals_)
except:
Mpost_mortem.uncaught_exception(dbg)
pass
return
|
def run_exec(statement, debug_opts=None, start_opts=None, globals_=None,
locals_=None):
"""Execute the statement (given as a string) under debugger
control starting with the statement subsequent to the place that
this run_call appears in your program.
This is a wrapper to Debugger.run_exec(), so see that.
The debugger prompt appears before any code is executed;
you can set breakpoints and type 'continue', or you can step
through the statement using 'step' or 'next'
The optional globals_ and locals_ arguments specify the environment
in which the code is executed; by default the dictionary of the
module __main__ is used."""
dbg = Mdebugger.Trepan(opts=debug_opts)
try:
return dbg.run_exec(statement, start_opts=start_opts,
globals_=globals_, locals_=locals_)
except:
Mpost_mortem.uncaught_exception(dbg)
pass
return
|
[
"Execute",
"the",
"statement",
"(",
"given",
"as",
"a",
"string",
")",
"under",
"debugger",
"control",
"starting",
"with",
"the",
"statement",
"subsequent",
"to",
"the",
"place",
"that",
"this",
"run_call",
"appears",
"in",
"your",
"program",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/api.py#L90-L114
|
[
"def",
"run_exec",
"(",
"statement",
",",
"debug_opts",
"=",
"None",
",",
"start_opts",
"=",
"None",
",",
"globals_",
"=",
"None",
",",
"locals_",
"=",
"None",
")",
":",
"dbg",
"=",
"Mdebugger",
".",
"Trepan",
"(",
"opts",
"=",
"debug_opts",
")",
"try",
":",
"return",
"dbg",
".",
"run_exec",
"(",
"statement",
",",
"start_opts",
"=",
"start_opts",
",",
"globals_",
"=",
"globals_",
",",
"locals_",
"=",
"locals_",
")",
"except",
":",
"Mpost_mortem",
".",
"uncaught_exception",
"(",
"dbg",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
debug
|
Enter the debugger.
Parameters
----------
level : how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.
step_ignore : how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.
param dbg_opts : is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().
Use like this:
.. code-block:: python
... # Possibly some Python code
import trepan.api # Needed only once
... # Possibly some more Python code
trepan.api.debug() # You can wrap inside conditional logic too
pass # Stop will be here.
# Below is code you want to use the debugger to do things.
.... # more Python code
# If you get to a place in the program where you aren't going
# want to debug any more, but want to remove debugger trace overhead:
trepan.api.stop()
Parameter "level" specifies how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.
Parameter "step_ignore" specifies how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.
In situations where you want an immediate stop in the "debug" call
rather than the statement following it ("pass" above), add parameter
step_ignore=0 to debug() like this::
import trepan.api # Needed only once
# ... as before
trepan.api.debug(step_ignore=0)
# ... as before
Module variable _debugger_obj_ from module trepan.debugger is used as
the debugger instance variable; it can be subsequently used to change
settings or alter behavior. It should be of type Debugger (found in
module trepan). If not, it will get changed to that type::
$ python
>>> from trepan.debugger import debugger_obj
>>> type(debugger_obj)
<type 'NoneType'>
>>> import trepan.api
>>> trepan.api.debug()
...
(Trepan) c
>>> from trepan.debugger import debugger_obj
>>> debugger_obj
<trepan.debugger.Debugger instance at 0x7fbcacd514d0>
>>>
If however you want your own separate debugger instance, you can
create it from the debugger _class Debugger()_ from module
trepan.debugger::
$ python
>>> from trepan.debugger import Debugger
>>> dbgr = Debugger() # Add options as desired
>>> dbgr
<trepan.debugger.Debugger instance at 0x2e25320>
`dbg_opts' is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().
|
trepan/api.py
|
def debug(dbg_opts=None, start_opts=None, post_mortem=True,
step_ignore=1, level=0):
"""
Enter the debugger.
Parameters
----------
level : how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.
step_ignore : how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.
param dbg_opts : is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().
Use like this:
.. code-block:: python
... # Possibly some Python code
import trepan.api # Needed only once
... # Possibly some more Python code
trepan.api.debug() # You can wrap inside conditional logic too
pass # Stop will be here.
# Below is code you want to use the debugger to do things.
.... # more Python code
# If you get to a place in the program where you aren't going
# want to debug any more, but want to remove debugger trace overhead:
trepan.api.stop()
Parameter "level" specifies how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.
Parameter "step_ignore" specifies how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.
In situations where you want an immediate stop in the "debug" call
rather than the statement following it ("pass" above), add parameter
step_ignore=0 to debug() like this::
import trepan.api # Needed only once
# ... as before
trepan.api.debug(step_ignore=0)
# ... as before
Module variable _debugger_obj_ from module trepan.debugger is used as
the debugger instance variable; it can be subsequently used to change
settings or alter behavior. It should be of type Debugger (found in
module trepan). If not, it will get changed to that type::
$ python
>>> from trepan.debugger import debugger_obj
>>> type(debugger_obj)
<type 'NoneType'>
>>> import trepan.api
>>> trepan.api.debug()
...
(Trepan) c
>>> from trepan.debugger import debugger_obj
>>> debugger_obj
<trepan.debugger.Debugger instance at 0x7fbcacd514d0>
>>>
If however you want your own separate debugger instance, you can
create it from the debugger _class Debugger()_ from module
trepan.debugger::
$ python
>>> from trepan.debugger import Debugger
>>> dbgr = Debugger() # Add options as desired
>>> dbgr
<trepan.debugger.Debugger instance at 0x2e25320>
`dbg_opts' is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().
"""
if not isinstance(Mdebugger.debugger_obj, Mdebugger.Trepan):
Mdebugger.debugger_obj = Mdebugger.Trepan(dbg_opts)
Mdebugger.debugger_obj.core.add_ignore(debug, stop)
pass
core = Mdebugger.debugger_obj.core
frame = sys._getframe(0+level)
core.set_next(frame)
if start_opts and 'startup-profile' in start_opts and start_opts['startup-profile']:
dbg_initfiles = start_opts['startup-profile']
from trepan import options
options.add_startup_file(dbg_initfiles)
for init_cmdfile in dbg_initfiles:
core.processor.queue_startfile(init_cmdfile)
if not core.is_started():
core.start(start_opts)
pass
if post_mortem:
debugger_on_post_mortem()
pass
if 0 == step_ignore:
frame = sys._getframe(1+level)
core.stop_reason = 'at a debug() call'
old_trace_hook_suspend = core.trace_hook_suspend
core.trace_hook_suspend = True
core.processor.event_processor(frame, 'line', None)
core.trace_hook_suspend = old_trace_hook_suspend
else:
core.step_ignore = step_ignore-1
pass
return
|
def debug(dbg_opts=None, start_opts=None, post_mortem=True,
step_ignore=1, level=0):
"""
Enter the debugger.
Parameters
----------
level : how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.
step_ignore : how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.
param dbg_opts : is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().
Use like this:
.. code-block:: python
... # Possibly some Python code
import trepan.api # Needed only once
... # Possibly some more Python code
trepan.api.debug() # You can wrap inside conditional logic too
pass # Stop will be here.
# Below is code you want to use the debugger to do things.
.... # more Python code
# If you get to a place in the program where you aren't going
# want to debug any more, but want to remove debugger trace overhead:
trepan.api.stop()
Parameter "level" specifies how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.
Parameter "step_ignore" specifies how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.
In situations where you want an immediate stop in the "debug" call
rather than the statement following it ("pass" above), add parameter
step_ignore=0 to debug() like this::
import trepan.api # Needed only once
# ... as before
trepan.api.debug(step_ignore=0)
# ... as before
Module variable _debugger_obj_ from module trepan.debugger is used as
the debugger instance variable; it can be subsequently used to change
settings or alter behavior. It should be of type Debugger (found in
module trepan). If not, it will get changed to that type::
$ python
>>> from trepan.debugger import debugger_obj
>>> type(debugger_obj)
<type 'NoneType'>
>>> import trepan.api
>>> trepan.api.debug()
...
(Trepan) c
>>> from trepan.debugger import debugger_obj
>>> debugger_obj
<trepan.debugger.Debugger instance at 0x7fbcacd514d0>
>>>
If however you want your own separate debugger instance, you can
create it from the debugger _class Debugger()_ from module
trepan.debugger::
$ python
>>> from trepan.debugger import Debugger
>>> dbgr = Debugger() # Add options as desired
>>> dbgr
<trepan.debugger.Debugger instance at 0x2e25320>
`dbg_opts' is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().
"""
if not isinstance(Mdebugger.debugger_obj, Mdebugger.Trepan):
Mdebugger.debugger_obj = Mdebugger.Trepan(dbg_opts)
Mdebugger.debugger_obj.core.add_ignore(debug, stop)
pass
core = Mdebugger.debugger_obj.core
frame = sys._getframe(0+level)
core.set_next(frame)
if start_opts and 'startup-profile' in start_opts and start_opts['startup-profile']:
dbg_initfiles = start_opts['startup-profile']
from trepan import options
options.add_startup_file(dbg_initfiles)
for init_cmdfile in dbg_initfiles:
core.processor.queue_startfile(init_cmdfile)
if not core.is_started():
core.start(start_opts)
pass
if post_mortem:
debugger_on_post_mortem()
pass
if 0 == step_ignore:
frame = sys._getframe(1+level)
core.stop_reason = 'at a debug() call'
old_trace_hook_suspend = core.trace_hook_suspend
core.trace_hook_suspend = True
core.processor.event_processor(frame, 'line', None)
core.trace_hook_suspend = old_trace_hook_suspend
else:
core.step_ignore = step_ignore-1
pass
return
|
[
"Enter",
"the",
"debugger",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/api.py#L117-L229
|
[
"def",
"debug",
"(",
"dbg_opts",
"=",
"None",
",",
"start_opts",
"=",
"None",
",",
"post_mortem",
"=",
"True",
",",
"step_ignore",
"=",
"1",
",",
"level",
"=",
"0",
")",
":",
"if",
"not",
"isinstance",
"(",
"Mdebugger",
".",
"debugger_obj",
",",
"Mdebugger",
".",
"Trepan",
")",
":",
"Mdebugger",
".",
"debugger_obj",
"=",
"Mdebugger",
".",
"Trepan",
"(",
"dbg_opts",
")",
"Mdebugger",
".",
"debugger_obj",
".",
"core",
".",
"add_ignore",
"(",
"debug",
",",
"stop",
")",
"pass",
"core",
"=",
"Mdebugger",
".",
"debugger_obj",
".",
"core",
"frame",
"=",
"sys",
".",
"_getframe",
"(",
"0",
"+",
"level",
")",
"core",
".",
"set_next",
"(",
"frame",
")",
"if",
"start_opts",
"and",
"'startup-profile'",
"in",
"start_opts",
"and",
"start_opts",
"[",
"'startup-profile'",
"]",
":",
"dbg_initfiles",
"=",
"start_opts",
"[",
"'startup-profile'",
"]",
"from",
"trepan",
"import",
"options",
"options",
".",
"add_startup_file",
"(",
"dbg_initfiles",
")",
"for",
"init_cmdfile",
"in",
"dbg_initfiles",
":",
"core",
".",
"processor",
".",
"queue_startfile",
"(",
"init_cmdfile",
")",
"if",
"not",
"core",
".",
"is_started",
"(",
")",
":",
"core",
".",
"start",
"(",
"start_opts",
")",
"pass",
"if",
"post_mortem",
":",
"debugger_on_post_mortem",
"(",
")",
"pass",
"if",
"0",
"==",
"step_ignore",
":",
"frame",
"=",
"sys",
".",
"_getframe",
"(",
"1",
"+",
"level",
")",
"core",
".",
"stop_reason",
"=",
"'at a debug() call'",
"old_trace_hook_suspend",
"=",
"core",
".",
"trace_hook_suspend",
"core",
".",
"trace_hook_suspend",
"=",
"True",
"core",
".",
"processor",
".",
"event_processor",
"(",
"frame",
",",
"'line'",
",",
"None",
")",
"core",
".",
"trace_hook_suspend",
"=",
"old_trace_hook_suspend",
"else",
":",
"core",
".",
"step_ignore",
"=",
"step_ignore",
"-",
"1",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
HelpCommand.list_categories
|
List the command categories and a short description of each.
|
trepan/processor/command/help.py
|
def list_categories(self):
"""List the command categories and a short description of each."""
self.section("Classes of commands:")
cats = list(categories.keys())
cats.sort()
for cat in cats: # Foo! iteritems() doesn't do sorting
self.msg(" %-13s -- %s" % (cat, categories[cat]))
pass
final_msg = """
Type `help` followed by a class name for a list of commands in that class.
Type `help aliases` for a list of current aliases.
Type `help macros` for a list of current macros.
Type `help syntax *item*` for help on syntax *item*
Type `help *` for the list of all commands.
Type `help` *regexp* for the list of commands matching /^#{*regexp*}/
Type `help` followed by command name for full documentation.
"""
for line in re.compile('\n').split(final_msg.rstrip('\n')):
self.rst_msg(line)
pass
return
|
def list_categories(self):
"""List the command categories and a short description of each."""
self.section("Classes of commands:")
cats = list(categories.keys())
cats.sort()
for cat in cats: # Foo! iteritems() doesn't do sorting
self.msg(" %-13s -- %s" % (cat, categories[cat]))
pass
final_msg = """
Type `help` followed by a class name for a list of commands in that class.
Type `help aliases` for a list of current aliases.
Type `help macros` for a list of current macros.
Type `help syntax *item*` for help on syntax *item*
Type `help *` for the list of all commands.
Type `help` *regexp* for the list of commands matching /^#{*regexp*}/
Type `help` followed by command name for full documentation.
"""
for line in re.compile('\n').split(final_msg.rstrip('\n')):
self.rst_msg(line)
pass
return
|
[
"List",
"the",
"command",
"categories",
"and",
"a",
"short",
"description",
"of",
"each",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/command/help.py#L151-L171
|
[
"def",
"list_categories",
"(",
"self",
")",
":",
"self",
".",
"section",
"(",
"\"Classes of commands:\"",
")",
"cats",
"=",
"list",
"(",
"categories",
".",
"keys",
"(",
")",
")",
"cats",
".",
"sort",
"(",
")",
"for",
"cat",
"in",
"cats",
":",
"# Foo! iteritems() doesn't do sorting",
"self",
".",
"msg",
"(",
"\" %-13s -- %s\"",
"%",
"(",
"cat",
",",
"categories",
"[",
"cat",
"]",
")",
")",
"pass",
"final_msg",
"=",
"\"\"\"\nType `help` followed by a class name for a list of commands in that class.\nType `help aliases` for a list of current aliases.\nType `help macros` for a list of current macros.\nType `help syntax *item*` for help on syntax *item*\nType `help *` for the list of all commands.\nType `help` *regexp* for the list of commands matching /^#{*regexp*}/\nType `help` followed by command name for full documentation.\n\"\"\"",
"for",
"line",
"in",
"re",
".",
"compile",
"(",
"'\\n'",
")",
".",
"split",
"(",
"final_msg",
".",
"rstrip",
"(",
"'\\n'",
")",
")",
":",
"self",
".",
"rst_msg",
"(",
"line",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
HelpCommand.show_category
|
Show short help for all commands in `category'.
|
trepan/processor/command/help.py
|
def show_category(self, category, args):
"""Show short help for all commands in `category'."""
n2cmd = self.proc.commands
names = list(n2cmd.keys())
if len(args) == 1 and args[0] == '*':
self.section("Commands in class %s:" % category)
cmds = [cmd for cmd in names if category == n2cmd[cmd].category]
cmds.sort()
self.msg_nocr(self.columnize_commands(cmds))
return
self.msg("%s.\n" % categories[category])
self.section("List of commands:")
names.sort()
for name in names: # Foo! iteritems() doesn't do sorting
if category != n2cmd[name].category: continue
self.msg("%-13s -- %s" % (name, n2cmd[name].short_help,))
pass
return
|
def show_category(self, category, args):
"""Show short help for all commands in `category'."""
n2cmd = self.proc.commands
names = list(n2cmd.keys())
if len(args) == 1 and args[0] == '*':
self.section("Commands in class %s:" % category)
cmds = [cmd for cmd in names if category == n2cmd[cmd].category]
cmds.sort()
self.msg_nocr(self.columnize_commands(cmds))
return
self.msg("%s.\n" % categories[category])
self.section("List of commands:")
names.sort()
for name in names: # Foo! iteritems() doesn't do sorting
if category != n2cmd[name].category: continue
self.msg("%-13s -- %s" % (name, n2cmd[name].short_help,))
pass
return
|
[
"Show",
"short",
"help",
"for",
"all",
"commands",
"in",
"category",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/command/help.py#L173-L191
|
[
"def",
"show_category",
"(",
"self",
",",
"category",
",",
"args",
")",
":",
"n2cmd",
"=",
"self",
".",
"proc",
".",
"commands",
"names",
"=",
"list",
"(",
"n2cmd",
".",
"keys",
"(",
")",
")",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"args",
"[",
"0",
"]",
"==",
"'*'",
":",
"self",
".",
"section",
"(",
"\"Commands in class %s:\"",
"%",
"category",
")",
"cmds",
"=",
"[",
"cmd",
"for",
"cmd",
"in",
"names",
"if",
"category",
"==",
"n2cmd",
"[",
"cmd",
"]",
".",
"category",
"]",
"cmds",
".",
"sort",
"(",
")",
"self",
".",
"msg_nocr",
"(",
"self",
".",
"columnize_commands",
"(",
"cmds",
")",
")",
"return",
"self",
".",
"msg",
"(",
"\"%s.\\n\"",
"%",
"categories",
"[",
"category",
"]",
")",
"self",
".",
"section",
"(",
"\"List of commands:\"",
")",
"names",
".",
"sort",
"(",
")",
"for",
"name",
"in",
"names",
":",
"# Foo! iteritems() doesn't do sorting",
"if",
"category",
"!=",
"n2cmd",
"[",
"name",
"]",
".",
"category",
":",
"continue",
"self",
".",
"msg",
"(",
"\"%-13s -- %s\"",
"%",
"(",
"name",
",",
"n2cmd",
"[",
"name",
"]",
".",
"short_help",
",",
")",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
InfoLine.run
|
Current line number in source file
|
trepan/processor/command/info_subcmd/line.py
|
def run(self, args):
"""Current line number in source file"""
# info line identifier
if not self.proc.curframe:
self.errmsg("No line number information available.")
return
if len(args) == 3:
# lineinfo returns (item, file, lineno) or (None,)
answer = self.lineinfo(args[2])
if answer[0]:
item, filename, lineno = answer
if not os.path.isfile(filename):
filename = Mclifns.search_file(filename,
self.core.search_path,
self.main_dirname)
self.msg('Line %s of "%s" <%s>' %
(lineno, filename, item))
return
filename=self.core.canonic_filename(self.proc.curframe)
if not os.path.isfile(filename):
filename = Mclifns.search_file(filename, self.core.search_path,
self.main_dirname)
pass
filename = self.core.canonic_filename(self.proc.curframe)
msg1 = 'Line %d of \"%s\"' % (inspect.getlineno(self.proc.curframe),
self.core.filename(filename))
msg2 = ('at instruction %d' % self.proc.curframe.f_lasti)
if self.proc.event:
msg2 += ', %s event' % self.proc.event
pass
self.msg(Mmisc.wrapped_lines(msg1, msg2, self.settings['width']))
return False
|
def run(self, args):
"""Current line number in source file"""
# info line identifier
if not self.proc.curframe:
self.errmsg("No line number information available.")
return
if len(args) == 3:
# lineinfo returns (item, file, lineno) or (None,)
answer = self.lineinfo(args[2])
if answer[0]:
item, filename, lineno = answer
if not os.path.isfile(filename):
filename = Mclifns.search_file(filename,
self.core.search_path,
self.main_dirname)
self.msg('Line %s of "%s" <%s>' %
(lineno, filename, item))
return
filename=self.core.canonic_filename(self.proc.curframe)
if not os.path.isfile(filename):
filename = Mclifns.search_file(filename, self.core.search_path,
self.main_dirname)
pass
filename = self.core.canonic_filename(self.proc.curframe)
msg1 = 'Line %d of \"%s\"' % (inspect.getlineno(self.proc.curframe),
self.core.filename(filename))
msg2 = ('at instruction %d' % self.proc.curframe.f_lasti)
if self.proc.event:
msg2 += ', %s event' % self.proc.event
pass
self.msg(Mmisc.wrapped_lines(msg1, msg2, self.settings['width']))
return False
|
[
"Current",
"line",
"number",
"in",
"source",
"file"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/command/info_subcmd/line.py#L94-L126
|
[
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"# info line identifier",
"if",
"not",
"self",
".",
"proc",
".",
"curframe",
":",
"self",
".",
"errmsg",
"(",
"\"No line number information available.\"",
")",
"return",
"if",
"len",
"(",
"args",
")",
"==",
"3",
":",
"# lineinfo returns (item, file, lineno) or (None,)",
"answer",
"=",
"self",
".",
"lineinfo",
"(",
"args",
"[",
"2",
"]",
")",
"if",
"answer",
"[",
"0",
"]",
":",
"item",
",",
"filename",
",",
"lineno",
"=",
"answer",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"filename",
"=",
"Mclifns",
".",
"search_file",
"(",
"filename",
",",
"self",
".",
"core",
".",
"search_path",
",",
"self",
".",
"main_dirname",
")",
"self",
".",
"msg",
"(",
"'Line %s of \"%s\" <%s>'",
"%",
"(",
"lineno",
",",
"filename",
",",
"item",
")",
")",
"return",
"filename",
"=",
"self",
".",
"core",
".",
"canonic_filename",
"(",
"self",
".",
"proc",
".",
"curframe",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"filename",
"=",
"Mclifns",
".",
"search_file",
"(",
"filename",
",",
"self",
".",
"core",
".",
"search_path",
",",
"self",
".",
"main_dirname",
")",
"pass",
"filename",
"=",
"self",
".",
"core",
".",
"canonic_filename",
"(",
"self",
".",
"proc",
".",
"curframe",
")",
"msg1",
"=",
"'Line %d of \\\"%s\\\"'",
"%",
"(",
"inspect",
".",
"getlineno",
"(",
"self",
".",
"proc",
".",
"curframe",
")",
",",
"self",
".",
"core",
".",
"filename",
"(",
"filename",
")",
")",
"msg2",
"=",
"(",
"'at instruction %d'",
"%",
"self",
".",
"proc",
".",
"curframe",
".",
"f_lasti",
")",
"if",
"self",
".",
"proc",
".",
"event",
":",
"msg2",
"+=",
"', %s event'",
"%",
"self",
".",
"proc",
".",
"event",
"pass",
"self",
".",
"msg",
"(",
"Mmisc",
".",
"wrapped_lines",
"(",
"msg1",
",",
"msg2",
",",
"self",
".",
"settings",
"[",
"'width'",
"]",
")",
")",
"return",
"False"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
readable
|
Test whether a path exists and is readable. Returns None for
broken symbolic links or a failing stat() and False if
the file exists but does not have read permission. True is returned
if the file is readable.
|
trepan/lib/file.py
|
def readable(path):
"""Test whether a path exists and is readable. Returns None for
broken symbolic links or a failing stat() and False if
the file exists but does not have read permission. True is returned
if the file is readable."""
try:
st = os.stat(path)
return 0 != st.st_mode & READABLE_MASK
except os.error:
return None
return True
|
def readable(path):
"""Test whether a path exists and is readable. Returns None for
broken symbolic links or a failing stat() and False if
the file exists but does not have read permission. True is returned
if the file is readable."""
try:
st = os.stat(path)
return 0 != st.st_mode & READABLE_MASK
except os.error:
return None
return True
|
[
"Test",
"whether",
"a",
"path",
"exists",
"and",
"is",
"readable",
".",
"Returns",
"None",
"for",
"broken",
"symbolic",
"links",
"or",
"a",
"failing",
"stat",
"()",
"and",
"False",
"if",
"the",
"file",
"exists",
"but",
"does",
"not",
"have",
"read",
"permission",
".",
"True",
"is",
"returned",
"if",
"the",
"file",
"is",
"readable",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/file.py#L31-L41
|
[
"def",
"readable",
"(",
"path",
")",
":",
"try",
":",
"st",
"=",
"os",
".",
"stat",
"(",
"path",
")",
"return",
"0",
"!=",
"st",
".",
"st_mode",
"&",
"READABLE_MASK",
"except",
"os",
".",
"error",
":",
"return",
"None",
"return",
"True"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
lookupmodule
|
lookupmodule()->(module, file) translates a possibly incomplete
file or module name into an absolute file name. None can be
returned for either of the values positions of module or file when
no or module or file is found.
|
trepan/lib/file.py
|
def lookupmodule(name):
"""lookupmodule()->(module, file) translates a possibly incomplete
file or module name into an absolute file name. None can be
returned for either of the values positions of module or file when
no or module or file is found.
"""
if sys.modules.get(name):
return (sys.modules[name], sys.modules[name].__file__)
if os.path.isabs(name) and readable(name):
return (None, name)
f = os.path.join(sys.path[0], name)
if readable(f):
return (None, f)
root, ext = os.path.splitext(name)
if ext == '':
name = name + '.py'
pass
if os.path.isabs(name):
return (None, name)
for dirname in sys.path:
while os.path.islink(dirname):
dirname = os.readlink(dirname)
pass
fullname = os.path.join(dirname, name)
if readable(fullname):
return (None, fullname)
pass
return (None, None)
|
def lookupmodule(name):
"""lookupmodule()->(module, file) translates a possibly incomplete
file or module name into an absolute file name. None can be
returned for either of the values positions of module or file when
no or module or file is found.
"""
if sys.modules.get(name):
return (sys.modules[name], sys.modules[name].__file__)
if os.path.isabs(name) and readable(name):
return (None, name)
f = os.path.join(sys.path[0], name)
if readable(f):
return (None, f)
root, ext = os.path.splitext(name)
if ext == '':
name = name + '.py'
pass
if os.path.isabs(name):
return (None, name)
for dirname in sys.path:
while os.path.islink(dirname):
dirname = os.readlink(dirname)
pass
fullname = os.path.join(dirname, name)
if readable(fullname):
return (None, fullname)
pass
return (None, None)
|
[
"lookupmodule",
"()",
"-",
">",
"(",
"module",
"file",
")",
"translates",
"a",
"possibly",
"incomplete",
"file",
"or",
"module",
"name",
"into",
"an",
"absolute",
"file",
"name",
".",
"None",
"can",
"be",
"returned",
"for",
"either",
"of",
"the",
"values",
"positions",
"of",
"module",
"or",
"file",
"when",
"no",
"or",
"module",
"or",
"file",
"is",
"found",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/file.py#L44-L71
|
[
"def",
"lookupmodule",
"(",
"name",
")",
":",
"if",
"sys",
".",
"modules",
".",
"get",
"(",
"name",
")",
":",
"return",
"(",
"sys",
".",
"modules",
"[",
"name",
"]",
",",
"sys",
".",
"modules",
"[",
"name",
"]",
".",
"__file__",
")",
"if",
"os",
".",
"path",
".",
"isabs",
"(",
"name",
")",
"and",
"readable",
"(",
"name",
")",
":",
"return",
"(",
"None",
",",
"name",
")",
"f",
"=",
"os",
".",
"path",
".",
"join",
"(",
"sys",
".",
"path",
"[",
"0",
"]",
",",
"name",
")",
"if",
"readable",
"(",
"f",
")",
":",
"return",
"(",
"None",
",",
"f",
")",
"root",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"name",
")",
"if",
"ext",
"==",
"''",
":",
"name",
"=",
"name",
"+",
"'.py'",
"pass",
"if",
"os",
".",
"path",
".",
"isabs",
"(",
"name",
")",
":",
"return",
"(",
"None",
",",
"name",
")",
"for",
"dirname",
"in",
"sys",
".",
"path",
":",
"while",
"os",
".",
"path",
".",
"islink",
"(",
"dirname",
")",
":",
"dirname",
"=",
"os",
".",
"readlink",
"(",
"dirname",
")",
"pass",
"fullname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dirname",
",",
"name",
")",
"if",
"readable",
"(",
"fullname",
")",
":",
"return",
"(",
"None",
",",
"fullname",
")",
"pass",
"return",
"(",
"None",
",",
"None",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
parse_position
|
parse_position(errmsg, arg)->(fn, name, lineno)
Parse arg as [filename|module:]lineno
Make sure it works for C:\foo\bar.py:12
|
trepan/lib/file.py
|
def parse_position(errmsg, arg):
"""parse_position(errmsg, arg)->(fn, name, lineno)
Parse arg as [filename|module:]lineno
Make sure it works for C:\foo\bar.py:12
"""
colon = arg.rfind(':')
if colon >= 0:
filename = arg[:colon].rstrip()
m, f = lookupmodule(filename)
if not f:
errmsg("'%s' not found using sys.path" % filename)
return (None, None, None)
else:
filename = pyficache.pyc2py(f)
arg = arg[colon+1:].lstrip()
pass
try:
lineno = int(arg)
except TypeError:
errmsg("Bad line number: %s", str(arg))
return (None, filename, None)
return (None, filename, lineno)
return (None, None, None)
|
def parse_position(errmsg, arg):
"""parse_position(errmsg, arg)->(fn, name, lineno)
Parse arg as [filename|module:]lineno
Make sure it works for C:\foo\bar.py:12
"""
colon = arg.rfind(':')
if colon >= 0:
filename = arg[:colon].rstrip()
m, f = lookupmodule(filename)
if not f:
errmsg("'%s' not found using sys.path" % filename)
return (None, None, None)
else:
filename = pyficache.pyc2py(f)
arg = arg[colon+1:].lstrip()
pass
try:
lineno = int(arg)
except TypeError:
errmsg("Bad line number: %s", str(arg))
return (None, filename, None)
return (None, filename, lineno)
return (None, None, None)
|
[
"parse_position",
"(",
"errmsg",
"arg",
")",
"-",
">",
"(",
"fn",
"name",
"lineno",
")"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/file.py#L74-L97
|
[
"def",
"parse_position",
"(",
"errmsg",
",",
"arg",
")",
":",
"colon",
"=",
"arg",
".",
"rfind",
"(",
"':'",
")",
"if",
"colon",
">=",
"0",
":",
"filename",
"=",
"arg",
"[",
":",
"colon",
"]",
".",
"rstrip",
"(",
")",
"m",
",",
"f",
"=",
"lookupmodule",
"(",
"filename",
")",
"if",
"not",
"f",
":",
"errmsg",
"(",
"\"'%s' not found using sys.path\"",
"%",
"filename",
")",
"return",
"(",
"None",
",",
"None",
",",
"None",
")",
"else",
":",
"filename",
"=",
"pyficache",
".",
"pyc2py",
"(",
"f",
")",
"arg",
"=",
"arg",
"[",
"colon",
"+",
"1",
":",
"]",
".",
"lstrip",
"(",
")",
"pass",
"try",
":",
"lineno",
"=",
"int",
"(",
"arg",
")",
"except",
"TypeError",
":",
"errmsg",
"(",
"\"Bad line number: %s\"",
",",
"str",
"(",
"arg",
")",
")",
"return",
"(",
"None",
",",
"filename",
",",
"None",
")",
"return",
"(",
"None",
",",
"filename",
",",
"lineno",
")",
"return",
"(",
"None",
",",
"None",
",",
"None",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
find_debugged_frame
|
Find the first frame that is a debugged frame. We do this
Generally we want traceback information without polluting it with
debugger frames. We can tell these because those are frames on the
top which don't have f_trace set. So we'll look back from the top
to find the fist frame where f_trace is set.
|
trepan/lib/thred.py
|
def find_debugged_frame(frame):
"""Find the first frame that is a debugged frame. We do this
Generally we want traceback information without polluting it with
debugger frames. We can tell these because those are frames on the
top which don't have f_trace set. So we'll look back from the top
to find the fist frame where f_trace is set.
"""
f_prev = f = frame
while f is not None and f.f_trace is None:
f_prev = f
f = f.f_back
pass
if f_prev:
val = f_prev.f_locals.get('tracer_func_frame')
if val == f_prev:
if f_prev.f_back:
f_prev = f_prev.f_back
pass
pass
pass
else:
return frame
return f_prev
|
def find_debugged_frame(frame):
"""Find the first frame that is a debugged frame. We do this
Generally we want traceback information without polluting it with
debugger frames. We can tell these because those are frames on the
top which don't have f_trace set. So we'll look back from the top
to find the fist frame where f_trace is set.
"""
f_prev = f = frame
while f is not None and f.f_trace is None:
f_prev = f
f = f.f_back
pass
if f_prev:
val = f_prev.f_locals.get('tracer_func_frame')
if val == f_prev:
if f_prev.f_back:
f_prev = f_prev.f_back
pass
pass
pass
else:
return frame
return f_prev
|
[
"Find",
"the",
"first",
"frame",
"that",
"is",
"a",
"debugged",
"frame",
".",
"We",
"do",
"this",
"Generally",
"we",
"want",
"traceback",
"information",
"without",
"polluting",
"it",
"with",
"debugger",
"frames",
".",
"We",
"can",
"tell",
"these",
"because",
"those",
"are",
"frames",
"on",
"the",
"top",
"which",
"don",
"t",
"have",
"f_trace",
"set",
".",
"So",
"we",
"ll",
"look",
"back",
"from",
"the",
"top",
"to",
"find",
"the",
"fist",
"frame",
"where",
"f_trace",
"is",
"set",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/thred.py#L25-L47
|
[
"def",
"find_debugged_frame",
"(",
"frame",
")",
":",
"f_prev",
"=",
"f",
"=",
"frame",
"while",
"f",
"is",
"not",
"None",
"and",
"f",
".",
"f_trace",
"is",
"None",
":",
"f_prev",
"=",
"f",
"f",
"=",
"f",
".",
"f_back",
"pass",
"if",
"f_prev",
":",
"val",
"=",
"f_prev",
".",
"f_locals",
".",
"get",
"(",
"'tracer_func_frame'",
")",
"if",
"val",
"==",
"f_prev",
":",
"if",
"f_prev",
".",
"f_back",
":",
"f_prev",
"=",
"f_prev",
".",
"f_back",
"pass",
"pass",
"pass",
"else",
":",
"return",
"frame",
"return",
"f_prev"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
map_thread_names
|
Invert threading._active
|
trepan/lib/thred.py
|
def map_thread_names():
'''Invert threading._active'''
name2id = {}
for thread_id in list(threading._active.keys()):
thread = threading._active[thread_id]
name = thread.getName()
if name not in list(name2id.keys()):
name2id[name] = thread_id
pass
pass
return name2id
|
def map_thread_names():
'''Invert threading._active'''
name2id = {}
for thread_id in list(threading._active.keys()):
thread = threading._active[thread_id]
name = thread.getName()
if name not in list(name2id.keys()):
name2id[name] = thread_id
pass
pass
return name2id
|
[
"Invert",
"threading",
".",
"_active"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/thred.py#L54-L64
|
[
"def",
"map_thread_names",
"(",
")",
":",
"name2id",
"=",
"{",
"}",
"for",
"thread_id",
"in",
"list",
"(",
"threading",
".",
"_active",
".",
"keys",
"(",
")",
")",
":",
"thread",
"=",
"threading",
".",
"_active",
"[",
"thread_id",
"]",
"name",
"=",
"thread",
".",
"getName",
"(",
")",
"if",
"name",
"not",
"in",
"list",
"(",
"name2id",
".",
"keys",
"(",
")",
")",
":",
"name2id",
"[",
"name",
"]",
"=",
"thread_id",
"pass",
"pass",
"return",
"name2id"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
StringArrayInput.open
|
Use this to set where to read from.
|
trepan/inout/stringarray.py
|
def open(self, inp, opts=None):
"""Use this to set where to read from.
"""
if isinstance(inp, list):
self.input = inp
else:
raise IOError("Invalid input type (%s) for %s" % (type(inp), inp))
return
|
def open(self, inp, opts=None):
"""Use this to set where to read from.
"""
if isinstance(inp, list):
self.input = inp
else:
raise IOError("Invalid input type (%s) for %s" % (type(inp), inp))
return
|
[
"Use",
"this",
"to",
"set",
"where",
"to",
"read",
"from",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/stringarray.py#L37-L44
|
[
"def",
"open",
"(",
"self",
",",
"inp",
",",
"opts",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"inp",
",",
"list",
")",
":",
"self",
".",
"input",
"=",
"inp",
"else",
":",
"raise",
"IOError",
"(",
"\"Invalid input type (%s) for %s\"",
"%",
"(",
"type",
"(",
"inp",
")",
",",
"inp",
")",
")",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
StringArrayInput.readline
|
Read a line of input. EOFError will be raised on EOF.
Note that we don't support prompting
|
trepan/inout/stringarray.py
|
def readline(self, use_raw=None, prompt=''):
"""Read a line of input. EOFError will be raised on EOF.
Note that we don't support prompting"""
if self.closed: raise ValueError
if 0 == len(self.input):
self.closed = True
raise EOFError
line = self.input[0]
del self.input[0]
return line
|
def readline(self, use_raw=None, prompt=''):
"""Read a line of input. EOFError will be raised on EOF.
Note that we don't support prompting"""
if self.closed: raise ValueError
if 0 == len(self.input):
self.closed = True
raise EOFError
line = self.input[0]
del self.input[0]
return line
|
[
"Read",
"a",
"line",
"of",
"input",
".",
"EOFError",
"will",
"be",
"raised",
"on",
"EOF",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/stringarray.py#L46-L56
|
[
"def",
"readline",
"(",
"self",
",",
"use_raw",
"=",
"None",
",",
"prompt",
"=",
"''",
")",
":",
"if",
"self",
".",
"closed",
":",
"raise",
"ValueError",
"if",
"0",
"==",
"len",
"(",
"self",
".",
"input",
")",
":",
"self",
".",
"closed",
"=",
"True",
"raise",
"EOFError",
"line",
"=",
"self",
".",
"input",
"[",
"0",
"]",
"del",
"self",
".",
"input",
"[",
"0",
"]",
"return",
"line"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
StringArrayOutput.open
|
Use this to set where to write to. output can be a
file object or a string. This code raises IOError on error.
If another file was previously open upon calling this open,
that will be stacked and will come back into use after
a close_write().
|
trepan/inout/stringarray.py
|
def open(self, output):
"""Use this to set where to write to. output can be a
file object or a string. This code raises IOError on error.
If another file was previously open upon calling this open,
that will be stacked and will come back into use after
a close_write().
"""
if isinstance(output, types.Listype):
self.output = output
else:
raise IOError("Invalid output type (%s) for %s" % (type(output),
output))
return
|
def open(self, output):
"""Use this to set where to write to. output can be a
file object or a string. This code raises IOError on error.
If another file was previously open upon calling this open,
that will be stacked and will come back into use after
a close_write().
"""
if isinstance(output, types.Listype):
self.output = output
else:
raise IOError("Invalid output type (%s) for %s" % (type(output),
output))
return
|
[
"Use",
"this",
"to",
"set",
"where",
"to",
"write",
"to",
".",
"output",
"can",
"be",
"a",
"file",
"object",
"or",
"a",
"string",
".",
"This",
"code",
"raises",
"IOError",
"on",
"error",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/stringarray.py#L79-L92
|
[
"def",
"open",
"(",
"self",
",",
"output",
")",
":",
"if",
"isinstance",
"(",
"output",
",",
"types",
".",
"Listype",
")",
":",
"self",
".",
"output",
"=",
"output",
"else",
":",
"raise",
"IOError",
"(",
"\"Invalid output type (%s) for %s\"",
"%",
"(",
"type",
"(",
"output",
")",
",",
"output",
")",
")",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
StringArrayOutput.write
|
This method the debugger uses to write. In contrast to
writeline, no newline is added to the end to `str'.
|
trepan/inout/stringarray.py
|
def write(self, msg):
""" This method the debugger uses to write. In contrast to
writeline, no newline is added to the end to `str'.
"""
if self.closed: raise ValueError
if [] == self.output:
self.output = [msg]
else:
self.output[-1] += msg
pass
return
|
def write(self, msg):
""" This method the debugger uses to write. In contrast to
writeline, no newline is added to the end to `str'.
"""
if self.closed: raise ValueError
if [] == self.output:
self.output = [msg]
else:
self.output[-1] += msg
pass
return
|
[
"This",
"method",
"the",
"debugger",
"uses",
"to",
"write",
".",
"In",
"contrast",
"to",
"writeline",
"no",
"newline",
"is",
"added",
"to",
"the",
"end",
"to",
"str",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/inout/stringarray.py#L94-L104
|
[
"def",
"write",
"(",
"self",
",",
"msg",
")",
":",
"if",
"self",
".",
"closed",
":",
"raise",
"ValueError",
"if",
"[",
"]",
"==",
"self",
".",
"output",
":",
"self",
".",
"output",
"=",
"[",
"msg",
"]",
"else",
":",
"self",
".",
"output",
"[",
"-",
"1",
"]",
"+=",
"msg",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
default_configfile
|
Return fully expanded configuration filename location for
base_filename. python2 and python3 debuggers share the smae
directory: ~/.config/trepan.py
|
trepan/options.py
|
def default_configfile(base_filename):
'''Return fully expanded configuration filename location for
base_filename. python2 and python3 debuggers share the smae
directory: ~/.config/trepan.py
'''
file_dir = os.path.join(os.environ.get('HOME', '~'), '.config', 'trepanpy')
file_dir = Mclifns.path_expanduser_abs(file_dir)
if not os.path.isdir(file_dir):
os.makedirs(file_dir, mode=0o755)
return os.path.join(file_dir, base_filename)
|
def default_configfile(base_filename):
'''Return fully expanded configuration filename location for
base_filename. python2 and python3 debuggers share the smae
directory: ~/.config/trepan.py
'''
file_dir = os.path.join(os.environ.get('HOME', '~'), '.config', 'trepanpy')
file_dir = Mclifns.path_expanduser_abs(file_dir)
if not os.path.isdir(file_dir):
os.makedirs(file_dir, mode=0o755)
return os.path.join(file_dir, base_filename)
|
[
"Return",
"fully",
"expanded",
"configuration",
"filename",
"location",
"for",
"base_filename",
".",
"python2",
"and",
"python3",
"debuggers",
"share",
"the",
"smae",
"directory",
":",
"~",
"/",
".",
"config",
"/",
"trepan",
".",
"py"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/options.py#L25-L35
|
[
"def",
"default_configfile",
"(",
"base_filename",
")",
":",
"file_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'HOME'",
",",
"'~'",
")",
",",
"'.config'",
",",
"'trepanpy'",
")",
"file_dir",
"=",
"Mclifns",
".",
"path_expanduser_abs",
"(",
"file_dir",
")",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"file_dir",
")",
":",
"os",
".",
"makedirs",
"(",
"file_dir",
",",
"mode",
"=",
"0o755",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"file_dir",
",",
"base_filename",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
add_startup_file
|
Read debugger startup file(s): both python code and
debugger profile to dbg_initfiles.
|
trepan/options.py
|
def add_startup_file(dbg_initfiles):
""" Read debugger startup file(s): both python code and
debugger profile to dbg_initfiles."""
startup_python_file = default_configfile('profile.py')
if Mfile.readable(startup_python_file):
with codecs.open(startup_python_file, 'r', encoding='utf8') as fp:
exec(fp.read())
startup_trepan_file = default_configfile('profile')
if Mfile.readable(startup_trepan_file):
if startup_trepan_file not in dbg_initfiles:
dbg_initfiles.append(startup_trepan_file)
pass
return
|
def add_startup_file(dbg_initfiles):
""" Read debugger startup file(s): both python code and
debugger profile to dbg_initfiles."""
startup_python_file = default_configfile('profile.py')
if Mfile.readable(startup_python_file):
with codecs.open(startup_python_file, 'r', encoding='utf8') as fp:
exec(fp.read())
startup_trepan_file = default_configfile('profile')
if Mfile.readable(startup_trepan_file):
if startup_trepan_file not in dbg_initfiles:
dbg_initfiles.append(startup_trepan_file)
pass
return
|
[
"Read",
"debugger",
"startup",
"file",
"(",
"s",
")",
":",
"both",
"python",
"code",
"and",
"debugger",
"profile",
"to",
"dbg_initfiles",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/options.py#L37-L52
|
[
"def",
"add_startup_file",
"(",
"dbg_initfiles",
")",
":",
"startup_python_file",
"=",
"default_configfile",
"(",
"'profile.py'",
")",
"if",
"Mfile",
".",
"readable",
"(",
"startup_python_file",
")",
":",
"with",
"codecs",
".",
"open",
"(",
"startup_python_file",
",",
"'r'",
",",
"encoding",
"=",
"'utf8'",
")",
"as",
"fp",
":",
"exec",
"(",
"fp",
".",
"read",
"(",
")",
")",
"startup_trepan_file",
"=",
"default_configfile",
"(",
"'profile'",
")",
"if",
"Mfile",
".",
"readable",
"(",
"startup_trepan_file",
")",
":",
"if",
"startup_trepan_file",
"not",
"in",
"dbg_initfiles",
":",
"dbg_initfiles",
".",
"append",
"(",
"startup_trepan_file",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
process_options
|
Handle debugger options. Set `option_list' if you are writing
another main program and want to extend the existing set of debugger
options.
The options dicionary from optparser is returned. sys_argv is
also updated.
|
trepan/options.py
|
def process_options(debugger_name, pkg_version, sys_argv, option_list=None):
"""Handle debugger options. Set `option_list' if you are writing
another main program and want to extend the existing set of debugger
options.
The options dicionary from optparser is returned. sys_argv is
also updated."""
usage_str="""%prog [debugger-options] [python-script [script-options...]]
Runs the extended python debugger"""
# serverChoices = ('TCP','FIFO', None)
optparser = OptionParser(usage=usage_str, option_list=option_list,
version="%%prog version %s" % pkg_version)
optparser.add_option("-X", "--trace", dest="linetrace",
action="store_true", default=False,
help="Show lines before executing them. "
"This option also sets --batch")
optparser.add_option("-F", "--fntrace", dest="fntrace",
action="store_true", default=False,
help="Show functions before executing them. "
"This option also sets --batch")
optparser.add_option("--basename", dest="basename",
action="store_true", default=False,
help="Filenames strip off basename, "
"(e.g. for regression tests)"
)
# optparser.add_option("--batch", dest="noninteractive",
# action="store_true", default=False,
# help="Don't run interactive commands shell on "+
# "stops.")
optparser.add_option("--client", dest="client",
action='store_true',
help="Connect to an existing debugger process "
"started with the --server option. "
"See options for client.")
optparser.add_option("-x", "--command", dest="command",
action="store", type='string', metavar='FILE',
help="Execute commands from FILE.")
optparser.add_option("--cd", dest="cd",
action="store", type='string', metavar='DIR',
help="Change current directory to DIR.")
optparser.add_option("--confirm", dest="confirm",
action="store_true", default=True,
help="Confirm potentially dangerous operations")
optparser.add_option("--dbg_trepan", dest="dbg_trepan",
action="store_true", default=False,
help="Debug the debugger")
optparser.add_option("--different", dest="different",
action="store_true", default=True,
help="Consecutive stops should have "
"different positions")
# optparser.add_option("--error", dest="errors", metavar='FILE',
# action="store", type='string',
# help="Write debugger's error output "
# + "(stderr) to FILE")
optparser.add_option("-e", "--exec", dest="execute", type="string",
help="list of debugger commands to " +
"execute. Separate the commands with ;;")
optparser.add_option("-H", "--host", dest="host", default='127.0.0.1',
action="store", type='string', metavar='IP-OR-HOST',
help="connect IP or host name. "
"Only valid if --client option given.")
optparser.add_option("--highlight", dest="highlight",
action="store", type='string',
metavar='{light|dark|plain}',
default='light',
help="Use syntax and terminal highlight output. "
"'plain' is no highlight")
optparser.add_option("--private", dest="private",
action='store_true', default=False,
help="Don't register this as a global debugger")
optparser.add_option("--main", dest="main",
action="store_true", default=True,
help="First stop should be in __main__"
)
optparser.add_option("--no-main", dest="main",
action="store_false", default=True,
help="First stop should be in __main__"
)
optparser.add_option("--post-mortem", dest="post_mortem",
action='store_true', default=True,
help=("Enter debugger on an uncaught (fatal) "
"exception"))
optparser.add_option("--no-post-mortem", dest="post_mortem",
action='store_false', default=True,
help=("Don't enter debugger on an uncaught (fatal) "
"exception"))
optparser.add_option("-n", "--nx", dest="noexecute",
action="store_true", default=False,
help=("Don't execute commands found in any "
"initialization files"))
optparser.add_option("-o", "--output", dest="output", metavar='FILE',
action="store", type='string',
help=("Write debugger's output (stdout) "
"to FILE"))
optparser.add_option("-P", "--port", dest="port", default=1027,
action="store", type='int',
help="Use TCP port number NUMBER for "
"out-of-process connections.")
optparser.add_option("--server", dest="server",
action='store_true',
help="Out-of-process server connection mode")
# optparser.add_option("--style", dest="style",
# action="store", type='string',
# metavar='*pygments-style*',
# default=None,
# help=("Pygments style; 'none' "
# "uses 8-color rather than 256-color terminal"))
optparser.add_option("--sigcheck", dest="sigcheck",
action="store_true", default=False,
help="Set to watch for signal handler changes")
optparser.add_option("-t", "--target", dest="target",
help=("Specify a target to connect to. Arguments"
" should be of form, 'protocol address'.")),
optparser.add_option("--from_ipython", dest='from_ipython', action='store_true',
default=False, help="Called from inside ipython")
# annotate option produces annotations, used in trepan.el for a
# better emacs integration. Annotations are similar in purpose to
# those of GDB (see that manual for a description), although the
# syntax is different. they have the following format:
#
# ^Z^Zannotation-name
# <arbitrary text>
# ^Z^Z
#
# where ^Z is the ctrl-Z character, and "annotname" is the name of the
# annotation. A line with only two ^Z ends the annotation (no nesting
# allowed). See trepan.el for the usage
optparser.add_option("--annotate", default=0, type="int",
help="Use annotations to work inside emacs")
# Set up to stop on the first non-option because that's the name
# of the script to be debugged on arguments following that are
# that scripts options that should be left untouched. We would
# not want to interpret and option for the script, e.g. --help, as
# one one of our own, e.g. --help.
optparser.disable_interspersed_args()
sys.argv = list(sys_argv)
# FIXME: why does this mess up integration tests?
# (opts, sys.argv) = optparser.parse_args(sys_argv)
(opts, sys.argv) = optparser.parse_args()
dbg_opts = {'from_ipython': opts.from_ipython}
# Handle debugger startup command files: --nx (-n) and --command.
dbg_initfiles = []
if not opts.noexecute:
add_startup_file(dbg_initfiles)
# As per gdb, first we execute user initialization files and then
# we execute any file specified via --command.
if opts.command:
dbg_initfiles.append(opts.command)
pass
dbg_opts['proc_opts'] = {'initfile_list': dbg_initfiles}
if opts.cd:
os.chdir(opts.cd)
pass
if opts.output:
try:
dbg_opts['output'] = Moutput.DebuggerUserOutput(opts.output)
except IOError:
_, xxx_todo_changeme, _ = sys.exc_info()
(errno, strerror) = xxx_todo_changeme.args
print("I/O in opening debugger output file %s" % opts.output)
print("error(%s): %s" % (errno, strerror))
except:
print("Unexpected error in opening debugger output file %s" %
opts.output)
print(sys.exc_info()[0])
sys.exit(2)
pass
pass
return opts, dbg_opts, sys.argv
|
def process_options(debugger_name, pkg_version, sys_argv, option_list=None):
"""Handle debugger options. Set `option_list' if you are writing
another main program and want to extend the existing set of debugger
options.
The options dicionary from optparser is returned. sys_argv is
also updated."""
usage_str="""%prog [debugger-options] [python-script [script-options...]]
Runs the extended python debugger"""
# serverChoices = ('TCP','FIFO', None)
optparser = OptionParser(usage=usage_str, option_list=option_list,
version="%%prog version %s" % pkg_version)
optparser.add_option("-X", "--trace", dest="linetrace",
action="store_true", default=False,
help="Show lines before executing them. "
"This option also sets --batch")
optparser.add_option("-F", "--fntrace", dest="fntrace",
action="store_true", default=False,
help="Show functions before executing them. "
"This option also sets --batch")
optparser.add_option("--basename", dest="basename",
action="store_true", default=False,
help="Filenames strip off basename, "
"(e.g. for regression tests)"
)
# optparser.add_option("--batch", dest="noninteractive",
# action="store_true", default=False,
# help="Don't run interactive commands shell on "+
# "stops.")
optparser.add_option("--client", dest="client",
action='store_true',
help="Connect to an existing debugger process "
"started with the --server option. "
"See options for client.")
optparser.add_option("-x", "--command", dest="command",
action="store", type='string', metavar='FILE',
help="Execute commands from FILE.")
optparser.add_option("--cd", dest="cd",
action="store", type='string', metavar='DIR',
help="Change current directory to DIR.")
optparser.add_option("--confirm", dest="confirm",
action="store_true", default=True,
help="Confirm potentially dangerous operations")
optparser.add_option("--dbg_trepan", dest="dbg_trepan",
action="store_true", default=False,
help="Debug the debugger")
optparser.add_option("--different", dest="different",
action="store_true", default=True,
help="Consecutive stops should have "
"different positions")
# optparser.add_option("--error", dest="errors", metavar='FILE',
# action="store", type='string',
# help="Write debugger's error output "
# + "(stderr) to FILE")
optparser.add_option("-e", "--exec", dest="execute", type="string",
help="list of debugger commands to " +
"execute. Separate the commands with ;;")
optparser.add_option("-H", "--host", dest="host", default='127.0.0.1',
action="store", type='string', metavar='IP-OR-HOST',
help="connect IP or host name. "
"Only valid if --client option given.")
optparser.add_option("--highlight", dest="highlight",
action="store", type='string',
metavar='{light|dark|plain}',
default='light',
help="Use syntax and terminal highlight output. "
"'plain' is no highlight")
optparser.add_option("--private", dest="private",
action='store_true', default=False,
help="Don't register this as a global debugger")
optparser.add_option("--main", dest="main",
action="store_true", default=True,
help="First stop should be in __main__"
)
optparser.add_option("--no-main", dest="main",
action="store_false", default=True,
help="First stop should be in __main__"
)
optparser.add_option("--post-mortem", dest="post_mortem",
action='store_true', default=True,
help=("Enter debugger on an uncaught (fatal) "
"exception"))
optparser.add_option("--no-post-mortem", dest="post_mortem",
action='store_false', default=True,
help=("Don't enter debugger on an uncaught (fatal) "
"exception"))
optparser.add_option("-n", "--nx", dest="noexecute",
action="store_true", default=False,
help=("Don't execute commands found in any "
"initialization files"))
optparser.add_option("-o", "--output", dest="output", metavar='FILE',
action="store", type='string',
help=("Write debugger's output (stdout) "
"to FILE"))
optparser.add_option("-P", "--port", dest="port", default=1027,
action="store", type='int',
help="Use TCP port number NUMBER for "
"out-of-process connections.")
optparser.add_option("--server", dest="server",
action='store_true',
help="Out-of-process server connection mode")
# optparser.add_option("--style", dest="style",
# action="store", type='string',
# metavar='*pygments-style*',
# default=None,
# help=("Pygments style; 'none' "
# "uses 8-color rather than 256-color terminal"))
optparser.add_option("--sigcheck", dest="sigcheck",
action="store_true", default=False,
help="Set to watch for signal handler changes")
optparser.add_option("-t", "--target", dest="target",
help=("Specify a target to connect to. Arguments"
" should be of form, 'protocol address'.")),
optparser.add_option("--from_ipython", dest='from_ipython', action='store_true',
default=False, help="Called from inside ipython")
# annotate option produces annotations, used in trepan.el for a
# better emacs integration. Annotations are similar in purpose to
# those of GDB (see that manual for a description), although the
# syntax is different. they have the following format:
#
# ^Z^Zannotation-name
# <arbitrary text>
# ^Z^Z
#
# where ^Z is the ctrl-Z character, and "annotname" is the name of the
# annotation. A line with only two ^Z ends the annotation (no nesting
# allowed). See trepan.el for the usage
optparser.add_option("--annotate", default=0, type="int",
help="Use annotations to work inside emacs")
# Set up to stop on the first non-option because that's the name
# of the script to be debugged on arguments following that are
# that scripts options that should be left untouched. We would
# not want to interpret and option for the script, e.g. --help, as
# one one of our own, e.g. --help.
optparser.disable_interspersed_args()
sys.argv = list(sys_argv)
# FIXME: why does this mess up integration tests?
# (opts, sys.argv) = optparser.parse_args(sys_argv)
(opts, sys.argv) = optparser.parse_args()
dbg_opts = {'from_ipython': opts.from_ipython}
# Handle debugger startup command files: --nx (-n) and --command.
dbg_initfiles = []
if not opts.noexecute:
add_startup_file(dbg_initfiles)
# As per gdb, first we execute user initialization files and then
# we execute any file specified via --command.
if opts.command:
dbg_initfiles.append(opts.command)
pass
dbg_opts['proc_opts'] = {'initfile_list': dbg_initfiles}
if opts.cd:
os.chdir(opts.cd)
pass
if opts.output:
try:
dbg_opts['output'] = Moutput.DebuggerUserOutput(opts.output)
except IOError:
_, xxx_todo_changeme, _ = sys.exc_info()
(errno, strerror) = xxx_todo_changeme.args
print("I/O in opening debugger output file %s" % opts.output)
print("error(%s): %s" % (errno, strerror))
except:
print("Unexpected error in opening debugger output file %s" %
opts.output)
print(sys.exc_info()[0])
sys.exit(2)
pass
pass
return opts, dbg_opts, sys.argv
|
[
"Handle",
"debugger",
"options",
".",
"Set",
"option_list",
"if",
"you",
"are",
"writing",
"another",
"main",
"program",
"and",
"want",
"to",
"extend",
"the",
"existing",
"set",
"of",
"debugger",
"options",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/options.py#L54-L246
|
[
"def",
"process_options",
"(",
"debugger_name",
",",
"pkg_version",
",",
"sys_argv",
",",
"option_list",
"=",
"None",
")",
":",
"usage_str",
"=",
"\"\"\"%prog [debugger-options] [python-script [script-options...]]\n\n Runs the extended python debugger\"\"\"",
"# serverChoices = ('TCP','FIFO', None)",
"optparser",
"=",
"OptionParser",
"(",
"usage",
"=",
"usage_str",
",",
"option_list",
"=",
"option_list",
",",
"version",
"=",
"\"%%prog version %s\"",
"%",
"pkg_version",
")",
"optparser",
".",
"add_option",
"(",
"\"-X\"",
",",
"\"--trace\"",
",",
"dest",
"=",
"\"linetrace\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Show lines before executing them. \"",
"\"This option also sets --batch\"",
")",
"optparser",
".",
"add_option",
"(",
"\"-F\"",
",",
"\"--fntrace\"",
",",
"dest",
"=",
"\"fntrace\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Show functions before executing them. \"",
"\"This option also sets --batch\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--basename\"",
",",
"dest",
"=",
"\"basename\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Filenames strip off basename, \"",
"\"(e.g. for regression tests)\"",
")",
"# optparser.add_option(\"--batch\", dest=\"noninteractive\",",
"# action=\"store_true\", default=False,",
"# help=\"Don't run interactive commands shell on \"+",
"# \"stops.\")",
"optparser",
".",
"add_option",
"(",
"\"--client\"",
",",
"dest",
"=",
"\"client\"",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"\"Connect to an existing debugger process \"",
"\"started with the --server option. \"",
"\"See options for client.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"-x\"",
",",
"\"--command\"",
",",
"dest",
"=",
"\"command\"",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'string'",
",",
"metavar",
"=",
"'FILE'",
",",
"help",
"=",
"\"Execute commands from FILE.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--cd\"",
",",
"dest",
"=",
"\"cd\"",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'string'",
",",
"metavar",
"=",
"'DIR'",
",",
"help",
"=",
"\"Change current directory to DIR.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--confirm\"",
",",
"dest",
"=",
"\"confirm\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"True",
",",
"help",
"=",
"\"Confirm potentially dangerous operations\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--dbg_trepan\"",
",",
"dest",
"=",
"\"dbg_trepan\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Debug the debugger\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--different\"",
",",
"dest",
"=",
"\"different\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"True",
",",
"help",
"=",
"\"Consecutive stops should have \"",
"\"different positions\"",
")",
"# optparser.add_option(\"--error\", dest=\"errors\", metavar='FILE',",
"# action=\"store\", type='string',",
"# help=\"Write debugger's error output \"",
"# + \"(stderr) to FILE\")",
"optparser",
".",
"add_option",
"(",
"\"-e\"",
",",
"\"--exec\"",
",",
"dest",
"=",
"\"execute\"",
",",
"type",
"=",
"\"string\"",
",",
"help",
"=",
"\"list of debugger commands to \"",
"+",
"\"execute. Separate the commands with ;;\"",
")",
"optparser",
".",
"add_option",
"(",
"\"-H\"",
",",
"\"--host\"",
",",
"dest",
"=",
"\"host\"",
",",
"default",
"=",
"'127.0.0.1'",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'string'",
",",
"metavar",
"=",
"'IP-OR-HOST'",
",",
"help",
"=",
"\"connect IP or host name. \"",
"\"Only valid if --client option given.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--highlight\"",
",",
"dest",
"=",
"\"highlight\"",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'string'",
",",
"metavar",
"=",
"'{light|dark|plain}'",
",",
"default",
"=",
"'light'",
",",
"help",
"=",
"\"Use syntax and terminal highlight output. \"",
"\"'plain' is no highlight\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--private\"",
",",
"dest",
"=",
"\"private\"",
",",
"action",
"=",
"'store_true'",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Don't register this as a global debugger\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--main\"",
",",
"dest",
"=",
"\"main\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"True",
",",
"help",
"=",
"\"First stop should be in __main__\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--no-main\"",
",",
"dest",
"=",
"\"main\"",
",",
"action",
"=",
"\"store_false\"",
",",
"default",
"=",
"True",
",",
"help",
"=",
"\"First stop should be in __main__\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--post-mortem\"",
",",
"dest",
"=",
"\"post_mortem\"",
",",
"action",
"=",
"'store_true'",
",",
"default",
"=",
"True",
",",
"help",
"=",
"(",
"\"Enter debugger on an uncaught (fatal) \"",
"\"exception\"",
")",
")",
"optparser",
".",
"add_option",
"(",
"\"--no-post-mortem\"",
",",
"dest",
"=",
"\"post_mortem\"",
",",
"action",
"=",
"'store_false'",
",",
"default",
"=",
"True",
",",
"help",
"=",
"(",
"\"Don't enter debugger on an uncaught (fatal) \"",
"\"exception\"",
")",
")",
"optparser",
".",
"add_option",
"(",
"\"-n\"",
",",
"\"--nx\"",
",",
"dest",
"=",
"\"noexecute\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"False",
",",
"help",
"=",
"(",
"\"Don't execute commands found in any \"",
"\"initialization files\"",
")",
")",
"optparser",
".",
"add_option",
"(",
"\"-o\"",
",",
"\"--output\"",
",",
"dest",
"=",
"\"output\"",
",",
"metavar",
"=",
"'FILE'",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'string'",
",",
"help",
"=",
"(",
"\"Write debugger's output (stdout) \"",
"\"to FILE\"",
")",
")",
"optparser",
".",
"add_option",
"(",
"\"-P\"",
",",
"\"--port\"",
",",
"dest",
"=",
"\"port\"",
",",
"default",
"=",
"1027",
",",
"action",
"=",
"\"store\"",
",",
"type",
"=",
"'int'",
",",
"help",
"=",
"\"Use TCP port number NUMBER for \"",
"\"out-of-process connections.\"",
")",
"optparser",
".",
"add_option",
"(",
"\"--server\"",
",",
"dest",
"=",
"\"server\"",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"\"Out-of-process server connection mode\"",
")",
"# optparser.add_option(\"--style\", dest=\"style\",",
"# action=\"store\", type='string',",
"# metavar='*pygments-style*',",
"# default=None,",
"# help=(\"Pygments style; 'none' \"",
"# \"uses 8-color rather than 256-color terminal\"))",
"optparser",
".",
"add_option",
"(",
"\"--sigcheck\"",
",",
"dest",
"=",
"\"sigcheck\"",
",",
"action",
"=",
"\"store_true\"",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Set to watch for signal handler changes\"",
")",
"optparser",
".",
"add_option",
"(",
"\"-t\"",
",",
"\"--target\"",
",",
"dest",
"=",
"\"target\"",
",",
"help",
"=",
"(",
"\"Specify a target to connect to. Arguments\"",
"\" should be of form, 'protocol address'.\"",
")",
")",
",",
"optparser",
".",
"add_option",
"(",
"\"--from_ipython\"",
",",
"dest",
"=",
"'from_ipython'",
",",
"action",
"=",
"'store_true'",
",",
"default",
"=",
"False",
",",
"help",
"=",
"\"Called from inside ipython\"",
")",
"# annotate option produces annotations, used in trepan.el for a",
"# better emacs integration. Annotations are similar in purpose to",
"# those of GDB (see that manual for a description), although the",
"# syntax is different. they have the following format:",
"#",
"# ^Z^Zannotation-name",
"# <arbitrary text>",
"# ^Z^Z",
"#",
"# where ^Z is the ctrl-Z character, and \"annotname\" is the name of the",
"# annotation. A line with only two ^Z ends the annotation (no nesting",
"# allowed). See trepan.el for the usage",
"optparser",
".",
"add_option",
"(",
"\"--annotate\"",
",",
"default",
"=",
"0",
",",
"type",
"=",
"\"int\"",
",",
"help",
"=",
"\"Use annotations to work inside emacs\"",
")",
"# Set up to stop on the first non-option because that's the name",
"# of the script to be debugged on arguments following that are",
"# that scripts options that should be left untouched. We would",
"# not want to interpret and option for the script, e.g. --help, as",
"# one one of our own, e.g. --help.",
"optparser",
".",
"disable_interspersed_args",
"(",
")",
"sys",
".",
"argv",
"=",
"list",
"(",
"sys_argv",
")",
"# FIXME: why does this mess up integration tests?",
"# (opts, sys.argv) = optparser.parse_args(sys_argv)",
"(",
"opts",
",",
"sys",
".",
"argv",
")",
"=",
"optparser",
".",
"parse_args",
"(",
")",
"dbg_opts",
"=",
"{",
"'from_ipython'",
":",
"opts",
".",
"from_ipython",
"}",
"# Handle debugger startup command files: --nx (-n) and --command.",
"dbg_initfiles",
"=",
"[",
"]",
"if",
"not",
"opts",
".",
"noexecute",
":",
"add_startup_file",
"(",
"dbg_initfiles",
")",
"# As per gdb, first we execute user initialization files and then",
"# we execute any file specified via --command.",
"if",
"opts",
".",
"command",
":",
"dbg_initfiles",
".",
"append",
"(",
"opts",
".",
"command",
")",
"pass",
"dbg_opts",
"[",
"'proc_opts'",
"]",
"=",
"{",
"'initfile_list'",
":",
"dbg_initfiles",
"}",
"if",
"opts",
".",
"cd",
":",
"os",
".",
"chdir",
"(",
"opts",
".",
"cd",
")",
"pass",
"if",
"opts",
".",
"output",
":",
"try",
":",
"dbg_opts",
"[",
"'output'",
"]",
"=",
"Moutput",
".",
"DebuggerUserOutput",
"(",
"opts",
".",
"output",
")",
"except",
"IOError",
":",
"_",
",",
"xxx_todo_changeme",
",",
"_",
"=",
"sys",
".",
"exc_info",
"(",
")",
"(",
"errno",
",",
"strerror",
")",
"=",
"xxx_todo_changeme",
".",
"args",
"print",
"(",
"\"I/O in opening debugger output file %s\"",
"%",
"opts",
".",
"output",
")",
"print",
"(",
"\"error(%s): %s\"",
"%",
"(",
"errno",
",",
"strerror",
")",
")",
"except",
":",
"print",
"(",
"\"Unexpected error in opening debugger output file %s\"",
"%",
"opts",
".",
"output",
")",
"print",
"(",
"sys",
".",
"exc_info",
"(",
")",
"[",
"0",
"]",
")",
"sys",
".",
"exit",
"(",
"2",
")",
"pass",
"pass",
"return",
"opts",
",",
"dbg_opts",
",",
"sys",
".",
"argv"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
_postprocess_options
|
Handle options (`opts') that feed into the debugger (`dbg')
|
trepan/options.py
|
def _postprocess_options(dbg, opts):
''' Handle options (`opts') that feed into the debugger (`dbg')'''
# Set dbg.settings['printset']
print_events = []
if opts.fntrace: print_events = ['c_call', 'c_return', 'call', 'return']
if opts.linetrace: print_events += ['line']
if len(print_events):
dbg.settings['printset'] = frozenset(print_events)
pass
for setting in ('annotate', 'basename', 'different'):
dbg.settings[setting] = getattr(opts, setting)
pass
if getattr(opts, 'highlight'):
dbg.settings['highlight'] = opts.highlight
else:
dbg.settings['highlight'] = 'plain'
# if getattr(opts, 'style') and opts.style != 'none':
# dbg.settings['style'] = opts.style
# else:
# dbg.settings['style'] = None
dbg.settings['style'] = None
# Normally we want to set Mdebugger.debugger_obj so that one can
# put trepan.debugger breakpoints in a program and not have more
# than one debugger running. More than one debugger may confuse
# users, e.g. set different might stop at the same line once for
# each debugger.
if not opts.private:
Mdebugger.debugger_obj = dbg
pass
# if opts.errors:
# try:
# dbg.stderr = open(opts.errors, 'w')
# except IOError, (errno, strerror):
# print "I/O in opening debugger output file %s" % opts.errors
# print "error(%s): %s" % (errno, strerror)
# except ValueError:
# print "Could not convert data to an integer."
# except:
# print "Unexpected error in opening debugger output "
# "file %s" % opts.errors
# print sys.exc_info()[0]
# sys.exit(2)
# if opts.execute:
# dbg.cmdqueue = list(opts.execute.split(';;'))
if opts.post_mortem:
Mapi.debugger_on_post_mortem()
pass
return
|
def _postprocess_options(dbg, opts):
''' Handle options (`opts') that feed into the debugger (`dbg')'''
# Set dbg.settings['printset']
print_events = []
if opts.fntrace: print_events = ['c_call', 'c_return', 'call', 'return']
if opts.linetrace: print_events += ['line']
if len(print_events):
dbg.settings['printset'] = frozenset(print_events)
pass
for setting in ('annotate', 'basename', 'different'):
dbg.settings[setting] = getattr(opts, setting)
pass
if getattr(opts, 'highlight'):
dbg.settings['highlight'] = opts.highlight
else:
dbg.settings['highlight'] = 'plain'
# if getattr(opts, 'style') and opts.style != 'none':
# dbg.settings['style'] = opts.style
# else:
# dbg.settings['style'] = None
dbg.settings['style'] = None
# Normally we want to set Mdebugger.debugger_obj so that one can
# put trepan.debugger breakpoints in a program and not have more
# than one debugger running. More than one debugger may confuse
# users, e.g. set different might stop at the same line once for
# each debugger.
if not opts.private:
Mdebugger.debugger_obj = dbg
pass
# if opts.errors:
# try:
# dbg.stderr = open(opts.errors, 'w')
# except IOError, (errno, strerror):
# print "I/O in opening debugger output file %s" % opts.errors
# print "error(%s): %s" % (errno, strerror)
# except ValueError:
# print "Could not convert data to an integer."
# except:
# print "Unexpected error in opening debugger output "
# "file %s" % opts.errors
# print sys.exc_info()[0]
# sys.exit(2)
# if opts.execute:
# dbg.cmdqueue = list(opts.execute.split(';;'))
if opts.post_mortem:
Mapi.debugger_on_post_mortem()
pass
return
|
[
"Handle",
"options",
"(",
"opts",
")",
"that",
"feed",
"into",
"the",
"debugger",
"(",
"dbg",
")"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/options.py#L248-L302
|
[
"def",
"_postprocess_options",
"(",
"dbg",
",",
"opts",
")",
":",
"# Set dbg.settings['printset']",
"print_events",
"=",
"[",
"]",
"if",
"opts",
".",
"fntrace",
":",
"print_events",
"=",
"[",
"'c_call'",
",",
"'c_return'",
",",
"'call'",
",",
"'return'",
"]",
"if",
"opts",
".",
"linetrace",
":",
"print_events",
"+=",
"[",
"'line'",
"]",
"if",
"len",
"(",
"print_events",
")",
":",
"dbg",
".",
"settings",
"[",
"'printset'",
"]",
"=",
"frozenset",
"(",
"print_events",
")",
"pass",
"for",
"setting",
"in",
"(",
"'annotate'",
",",
"'basename'",
",",
"'different'",
")",
":",
"dbg",
".",
"settings",
"[",
"setting",
"]",
"=",
"getattr",
"(",
"opts",
",",
"setting",
")",
"pass",
"if",
"getattr",
"(",
"opts",
",",
"'highlight'",
")",
":",
"dbg",
".",
"settings",
"[",
"'highlight'",
"]",
"=",
"opts",
".",
"highlight",
"else",
":",
"dbg",
".",
"settings",
"[",
"'highlight'",
"]",
"=",
"'plain'",
"# if getattr(opts, 'style') and opts.style != 'none':",
"# dbg.settings['style'] = opts.style",
"# else:",
"# dbg.settings['style'] = None",
"dbg",
".",
"settings",
"[",
"'style'",
"]",
"=",
"None",
"# Normally we want to set Mdebugger.debugger_obj so that one can",
"# put trepan.debugger breakpoints in a program and not have more",
"# than one debugger running. More than one debugger may confuse",
"# users, e.g. set different might stop at the same line once for",
"# each debugger.",
"if",
"not",
"opts",
".",
"private",
":",
"Mdebugger",
".",
"debugger_obj",
"=",
"dbg",
"pass",
"# if opts.errors:",
"# try:",
"# dbg.stderr = open(opts.errors, 'w')",
"# except IOError, (errno, strerror):",
"# print \"I/O in opening debugger output file %s\" % opts.errors",
"# print \"error(%s): %s\" % (errno, strerror)",
"# except ValueError:",
"# print \"Could not convert data to an integer.\"",
"# except:",
"# print \"Unexpected error in opening debugger output \"",
"# \"file %s\" % opts.errors",
"# print sys.exc_info()[0]",
"# sys.exit(2)",
"# if opts.execute:",
"# dbg.cmdqueue = list(opts.execute.split(';;'))",
"if",
"opts",
".",
"post_mortem",
":",
"Mapi",
".",
"debugger_on_post_mortem",
"(",
")",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
ClientInterface.read_remote
|
Send a message back to the server (in contrast to
the local user output channel).
|
trepan/interfaces/client.py
|
def read_remote(self):
'''Send a message back to the server (in contrast to
the local user output channel).'''
coded_line = self.inout.read_msg()
if isinstance(coded_line, bytes):
coded_line = coded_line.decode("utf-8")
control = coded_line[0]
remote_line = coded_line[1:]
return (control, remote_line)
|
def read_remote(self):
'''Send a message back to the server (in contrast to
the local user output channel).'''
coded_line = self.inout.read_msg()
if isinstance(coded_line, bytes):
coded_line = coded_line.decode("utf-8")
control = coded_line[0]
remote_line = coded_line[1:]
return (control, remote_line)
|
[
"Send",
"a",
"message",
"back",
"to",
"the",
"server",
"(",
"in",
"contrast",
"to",
"the",
"local",
"user",
"output",
"channel",
")",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/interfaces/client.py#L56-L64
|
[
"def",
"read_remote",
"(",
"self",
")",
":",
"coded_line",
"=",
"self",
".",
"inout",
".",
"read_msg",
"(",
")",
"if",
"isinstance",
"(",
"coded_line",
",",
"bytes",
")",
":",
"coded_line",
"=",
"coded_line",
".",
"decode",
"(",
"\"utf-8\"",
")",
"control",
"=",
"coded_line",
"[",
"0",
"]",
"remote_line",
"=",
"coded_line",
"[",
"1",
":",
"]",
"return",
"(",
"control",
",",
"remote_line",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
get_an_int
|
Another get_int() routine, this one simpler and less stylized
than get_int(). We eval arg return it as an integer value or
None if there was an error in parsing this.
|
trepan/processor/cmdfns.py
|
def get_an_int(errmsg, arg, msg_on_error, min_value=None, max_value=None):
"""Another get_int() routine, this one simpler and less stylized
than get_int(). We eval arg return it as an integer value or
None if there was an error in parsing this.
"""
ret_value = None
if arg:
try:
# eval() is used so we will allow arithmetic expressions,
# variables etc.
ret_value = int(eval(arg))
except (SyntaxError, NameError, ValueError):
if errmsg:
errmsg(msg_on_error)
else:
errmsg('Expecting an integer, got: %s.' % str(arg))
return None
if min_value and ret_value < min_value:
errmsg('Expecting integer value to be at least %d, got: %d.' %
(min_value, ret_value))
return None
elif max_value and ret_value > max_value:
errmsg('Expecting integer value to be at most %d, got: %d.' %
(max_value, ret_value))
return None
return ret_value
|
def get_an_int(errmsg, arg, msg_on_error, min_value=None, max_value=None):
"""Another get_int() routine, this one simpler and less stylized
than get_int(). We eval arg return it as an integer value or
None if there was an error in parsing this.
"""
ret_value = None
if arg:
try:
# eval() is used so we will allow arithmetic expressions,
# variables etc.
ret_value = int(eval(arg))
except (SyntaxError, NameError, ValueError):
if errmsg:
errmsg(msg_on_error)
else:
errmsg('Expecting an integer, got: %s.' % str(arg))
return None
if min_value and ret_value < min_value:
errmsg('Expecting integer value to be at least %d, got: %d.' %
(min_value, ret_value))
return None
elif max_value and ret_value > max_value:
errmsg('Expecting integer value to be at most %d, got: %d.' %
(max_value, ret_value))
return None
return ret_value
|
[
"Another",
"get_int",
"()",
"routine",
"this",
"one",
"simpler",
"and",
"less",
"stylized",
"than",
"get_int",
"()",
".",
"We",
"eval",
"arg",
"return",
"it",
"as",
"an",
"integer",
"value",
"or",
"None",
"if",
"there",
"was",
"an",
"error",
"in",
"parsing",
"this",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L74-L100
|
[
"def",
"get_an_int",
"(",
"errmsg",
",",
"arg",
",",
"msg_on_error",
",",
"min_value",
"=",
"None",
",",
"max_value",
"=",
"None",
")",
":",
"ret_value",
"=",
"None",
"if",
"arg",
":",
"try",
":",
"# eval() is used so we will allow arithmetic expressions,",
"# variables etc.",
"ret_value",
"=",
"int",
"(",
"eval",
"(",
"arg",
")",
")",
"except",
"(",
"SyntaxError",
",",
"NameError",
",",
"ValueError",
")",
":",
"if",
"errmsg",
":",
"errmsg",
"(",
"msg_on_error",
")",
"else",
":",
"errmsg",
"(",
"'Expecting an integer, got: %s.'",
"%",
"str",
"(",
"arg",
")",
")",
"return",
"None",
"if",
"min_value",
"and",
"ret_value",
"<",
"min_value",
":",
"errmsg",
"(",
"'Expecting integer value to be at least %d, got: %d.'",
"%",
"(",
"min_value",
",",
"ret_value",
")",
")",
"return",
"None",
"elif",
"max_value",
"and",
"ret_value",
">",
"max_value",
":",
"errmsg",
"(",
"'Expecting integer value to be at most %d, got: %d.'",
"%",
"(",
"max_value",
",",
"ret_value",
")",
")",
"return",
"None",
"return",
"ret_value"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
get_int
|
If arg is an int, use that otherwise take default.
|
trepan/processor/cmdfns.py
|
def get_int(errmsg, arg, default=1, cmdname=None):
"""If arg is an int, use that otherwise take default."""
if arg:
try:
# eval() is used so we will allow arithmetic expressions,
# variables etc.
default = int(eval(arg))
except (SyntaxError, NameError, ValueError):
if cmdname:
errmsg("Command '%s' expects an integer; got: %s." %
(cmdname, str(arg)))
else:
errmsg('Expecting an integer, got: %s.' % str(arg))
pass
raise ValueError
return default
|
def get_int(errmsg, arg, default=1, cmdname=None):
"""If arg is an int, use that otherwise take default."""
if arg:
try:
# eval() is used so we will allow arithmetic expressions,
# variables etc.
default = int(eval(arg))
except (SyntaxError, NameError, ValueError):
if cmdname:
errmsg("Command '%s' expects an integer; got: %s." %
(cmdname, str(arg)))
else:
errmsg('Expecting an integer, got: %s.' % str(arg))
pass
raise ValueError
return default
|
[
"If",
"arg",
"is",
"an",
"int",
"use",
"that",
"otherwise",
"take",
"default",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L103-L118
|
[
"def",
"get_int",
"(",
"errmsg",
",",
"arg",
",",
"default",
"=",
"1",
",",
"cmdname",
"=",
"None",
")",
":",
"if",
"arg",
":",
"try",
":",
"# eval() is used so we will allow arithmetic expressions,",
"# variables etc.",
"default",
"=",
"int",
"(",
"eval",
"(",
"arg",
")",
")",
"except",
"(",
"SyntaxError",
",",
"NameError",
",",
"ValueError",
")",
":",
"if",
"cmdname",
":",
"errmsg",
"(",
"\"Command '%s' expects an integer; got: %s.\"",
"%",
"(",
"cmdname",
",",
"str",
"(",
"arg",
")",
")",
")",
"else",
":",
"errmsg",
"(",
"'Expecting an integer, got: %s.'",
"%",
"str",
"(",
"arg",
")",
")",
"pass",
"raise",
"ValueError",
"return",
"default"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
get_onoff
|
Return True if arg is 'on' or 1 and False arg is 'off' or 0.
Any other value is raises ValueError.
|
trepan/processor/cmdfns.py
|
def get_onoff(errmsg, arg, default=None, print_error=True):
"""Return True if arg is 'on' or 1 and False arg is 'off' or 0.
Any other value is raises ValueError."""
if not arg:
if default is None:
if print_error:
errmsg("Expecting 'on', 1, 'off', or 0. Got nothing.")
pass
raise ValueError
return default
if arg == '1' or arg == 'on': return True
if arg == '0' or arg =='off': return False
if print_error:
errmsg("Expecting 'on', 1, 'off', or 0. Got: %s." % str(arg))
raise ValueError
|
def get_onoff(errmsg, arg, default=None, print_error=True):
"""Return True if arg is 'on' or 1 and False arg is 'off' or 0.
Any other value is raises ValueError."""
if not arg:
if default is None:
if print_error:
errmsg("Expecting 'on', 1, 'off', or 0. Got nothing.")
pass
raise ValueError
return default
if arg == '1' or arg == 'on': return True
if arg == '0' or arg =='off': return False
if print_error:
errmsg("Expecting 'on', 1, 'off', or 0. Got: %s." % str(arg))
raise ValueError
|
[
"Return",
"True",
"if",
"arg",
"is",
"on",
"or",
"1",
"and",
"False",
"arg",
"is",
"off",
"or",
"0",
".",
"Any",
"other",
"value",
"is",
"raises",
"ValueError",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L121-L136
|
[
"def",
"get_onoff",
"(",
"errmsg",
",",
"arg",
",",
"default",
"=",
"None",
",",
"print_error",
"=",
"True",
")",
":",
"if",
"not",
"arg",
":",
"if",
"default",
"is",
"None",
":",
"if",
"print_error",
":",
"errmsg",
"(",
"\"Expecting 'on', 1, 'off', or 0. Got nothing.\"",
")",
"pass",
"raise",
"ValueError",
"return",
"default",
"if",
"arg",
"==",
"'1'",
"or",
"arg",
"==",
"'on'",
":",
"return",
"True",
"if",
"arg",
"==",
"'0'",
"or",
"arg",
"==",
"'off'",
":",
"return",
"False",
"if",
"print_error",
":",
"errmsg",
"(",
"\"Expecting 'on', 1, 'off', or 0. Got: %s.\"",
"%",
"str",
"(",
"arg",
")",
")",
"raise",
"ValueError"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_set_bool
|
set a Boolean-valued debugger setting. 'obj' is a generally a
subcommand that has 'name' and 'debugger.settings' attributes
|
trepan/processor/cmdfns.py
|
def run_set_bool(obj, args):
"""set a Boolean-valued debugger setting. 'obj' is a generally a
subcommand that has 'name' and 'debugger.settings' attributes"""
try:
if 0 == len(args): args = ['on']
obj.debugger.settings[obj.name] = get_onoff(obj.errmsg, args[0])
except ValueError:
pass
return
|
def run_set_bool(obj, args):
"""set a Boolean-valued debugger setting. 'obj' is a generally a
subcommand that has 'name' and 'debugger.settings' attributes"""
try:
if 0 == len(args): args = ['on']
obj.debugger.settings[obj.name] = get_onoff(obj.errmsg, args[0])
except ValueError:
pass
return
|
[
"set",
"a",
"Boolean",
"-",
"valued",
"debugger",
"setting",
".",
"obj",
"is",
"a",
"generally",
"a",
"subcommand",
"that",
"has",
"name",
"and",
"debugger",
".",
"settings",
"attributes"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L153-L161
|
[
"def",
"run_set_bool",
"(",
"obj",
",",
"args",
")",
":",
"try",
":",
"if",
"0",
"==",
"len",
"(",
"args",
")",
":",
"args",
"=",
"[",
"'on'",
"]",
"obj",
".",
"debugger",
".",
"settings",
"[",
"obj",
".",
"name",
"]",
"=",
"get_onoff",
"(",
"obj",
".",
"errmsg",
",",
"args",
"[",
"0",
"]",
")",
"except",
"ValueError",
":",
"pass",
"return"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_set_int
|
set an Integer-valued debugger setting. 'obj' is a generally a
subcommand that has 'name' and 'debugger.settings' attributes
|
trepan/processor/cmdfns.py
|
def run_set_int(obj, arg, msg_on_error, min_value=None, max_value=None):
"""set an Integer-valued debugger setting. 'obj' is a generally a
subcommand that has 'name' and 'debugger.settings' attributes"""
if '' == arg.strip():
obj.errmsg("You need to supply a number.")
return
obj.debugger.settings[obj.name] = \
get_an_int(obj.errmsg, arg, msg_on_error, min_value, max_value)
return obj.debugger.settings[obj.name]
|
def run_set_int(obj, arg, msg_on_error, min_value=None, max_value=None):
"""set an Integer-valued debugger setting. 'obj' is a generally a
subcommand that has 'name' and 'debugger.settings' attributes"""
if '' == arg.strip():
obj.errmsg("You need to supply a number.")
return
obj.debugger.settings[obj.name] = \
get_an_int(obj.errmsg, arg, msg_on_error, min_value, max_value)
return obj.debugger.settings[obj.name]
|
[
"set",
"an",
"Integer",
"-",
"valued",
"debugger",
"setting",
".",
"obj",
"is",
"a",
"generally",
"a",
"subcommand",
"that",
"has",
"name",
"and",
"debugger",
".",
"settings",
"attributes"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L164-L172
|
[
"def",
"run_set_int",
"(",
"obj",
",",
"arg",
",",
"msg_on_error",
",",
"min_value",
"=",
"None",
",",
"max_value",
"=",
"None",
")",
":",
"if",
"''",
"==",
"arg",
".",
"strip",
"(",
")",
":",
"obj",
".",
"errmsg",
"(",
"\"You need to supply a number.\"",
")",
"return",
"obj",
".",
"debugger",
".",
"settings",
"[",
"obj",
".",
"name",
"]",
"=",
"get_an_int",
"(",
"obj",
".",
"errmsg",
",",
"arg",
",",
"msg_on_error",
",",
"min_value",
",",
"max_value",
")",
"return",
"obj",
".",
"debugger",
".",
"settings",
"[",
"obj",
".",
"name",
"]"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_show_bool
|
Generic subcommand showing a boolean-valued debugger setting.
'obj' is generally a subcommand that has 'name' and
'debugger.setting' attributes.
|
trepan/processor/cmdfns.py
|
def run_show_bool(obj, what=None):
"""Generic subcommand showing a boolean-valued debugger setting.
'obj' is generally a subcommand that has 'name' and
'debugger.setting' attributes."""
val = show_onoff(obj.debugger.settings[obj.name])
if not what: what = obj.name
return obj.msg("%s is %s." % (what, val))
|
def run_show_bool(obj, what=None):
"""Generic subcommand showing a boolean-valued debugger setting.
'obj' is generally a subcommand that has 'name' and
'debugger.setting' attributes."""
val = show_onoff(obj.debugger.settings[obj.name])
if not what: what = obj.name
return obj.msg("%s is %s." % (what, val))
|
[
"Generic",
"subcommand",
"showing",
"a",
"boolean",
"-",
"valued",
"debugger",
"setting",
".",
"obj",
"is",
"generally",
"a",
"subcommand",
"that",
"has",
"name",
"and",
"debugger",
".",
"setting",
"attributes",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L175-L181
|
[
"def",
"run_show_bool",
"(",
"obj",
",",
"what",
"=",
"None",
")",
":",
"val",
"=",
"show_onoff",
"(",
"obj",
".",
"debugger",
".",
"settings",
"[",
"obj",
".",
"name",
"]",
")",
"if",
"not",
"what",
":",
"what",
"=",
"obj",
".",
"name",
"return",
"obj",
".",
"msg",
"(",
"\"%s is %s.\"",
"%",
"(",
"what",
",",
"val",
")",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_show_int
|
Generic subcommand integer value display
|
trepan/processor/cmdfns.py
|
def run_show_int(obj, what=None):
"""Generic subcommand integer value display"""
val = obj.debugger.settings[obj.name]
if not what: what = obj.name
return obj.msg("%s is %d." % (what, val))
|
def run_show_int(obj, what=None):
"""Generic subcommand integer value display"""
val = obj.debugger.settings[obj.name]
if not what: what = obj.name
return obj.msg("%s is %d." % (what, val))
|
[
"Generic",
"subcommand",
"integer",
"value",
"display"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L184-L188
|
[
"def",
"run_show_int",
"(",
"obj",
",",
"what",
"=",
"None",
")",
":",
"val",
"=",
"obj",
".",
"debugger",
".",
"settings",
"[",
"obj",
".",
"name",
"]",
"if",
"not",
"what",
":",
"what",
"=",
"obj",
".",
"name",
"return",
"obj",
".",
"msg",
"(",
"\"%s is %d.\"",
"%",
"(",
"what",
",",
"val",
")",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
run_show_val
|
Generic subcommand value display
|
trepan/processor/cmdfns.py
|
def run_show_val(obj, name):
"""Generic subcommand value display"""
val = obj.debugger.settings[obj.name]
obj.msg("%s is %s." % (obj.name, obj.cmd.proc._saferepr(val),))
return False
|
def run_show_val(obj, name):
"""Generic subcommand value display"""
val = obj.debugger.settings[obj.name]
obj.msg("%s is %s." % (obj.name, obj.cmd.proc._saferepr(val),))
return False
|
[
"Generic",
"subcommand",
"value",
"display"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/processor/cmdfns.py#L201-L205
|
[
"def",
"run_show_val",
"(",
"obj",
",",
"name",
")",
":",
"val",
"=",
"obj",
".",
"debugger",
".",
"settings",
"[",
"obj",
".",
"name",
"]",
"obj",
".",
"msg",
"(",
"\"%s is %s.\"",
"%",
"(",
"obj",
".",
"name",
",",
"obj",
".",
"cmd",
".",
"proc",
".",
"_saferepr",
"(",
"val",
")",
",",
")",
")",
"return",
"False"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
next_opcode
|
Return the next opcode and offset as a tuple. Tuple (-100,
-1000) is returned when reaching the end.
|
trepan/lib/bytecode.py
|
def next_opcode(code, offset):
'''Return the next opcode and offset as a tuple. Tuple (-100,
-1000) is returned when reaching the end.'''
n = len(code)
while offset < n:
op = code[offset]
offset += 1
if op >= HAVE_ARGUMENT:
offset += 2
pass
yield op, offset
pass
yield -100, -1000
pass
|
def next_opcode(code, offset):
'''Return the next opcode and offset as a tuple. Tuple (-100,
-1000) is returned when reaching the end.'''
n = len(code)
while offset < n:
op = code[offset]
offset += 1
if op >= HAVE_ARGUMENT:
offset += 2
pass
yield op, offset
pass
yield -100, -1000
pass
|
[
"Return",
"the",
"next",
"opcode",
"and",
"offset",
"as",
"a",
"tuple",
".",
"Tuple",
"(",
"-",
"100",
"-",
"1000",
")",
"is",
"returned",
"when",
"reaching",
"the",
"end",
"."
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/bytecode.py#L36-L49
|
[
"def",
"next_opcode",
"(",
"code",
",",
"offset",
")",
":",
"n",
"=",
"len",
"(",
"code",
")",
"while",
"offset",
"<",
"n",
":",
"op",
"=",
"code",
"[",
"offset",
"]",
"offset",
"+=",
"1",
"if",
"op",
">=",
"HAVE_ARGUMENT",
":",
"offset",
"+=",
"2",
"pass",
"yield",
"op",
",",
"offset",
"pass",
"yield",
"-",
"100",
",",
"-",
"1000",
"pass"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
test
|
is_def_stmt
|
Return True if we are looking at a def statement
|
trepan/lib/bytecode.py
|
def is_def_stmt(line, frame):
"""Return True if we are looking at a def statement"""
# Should really also check that operand of 'LOAD_CONST' is a code object
return (line and _re_def.match(line) and op_at_frame(frame)=='LOAD_CONST'
and stmt_contains_opcode(frame.f_code, frame.f_lineno,
'MAKE_FUNCTION'))
|
def is_def_stmt(line, frame):
"""Return True if we are looking at a def statement"""
# Should really also check that operand of 'LOAD_CONST' is a code object
return (line and _re_def.match(line) and op_at_frame(frame)=='LOAD_CONST'
and stmt_contains_opcode(frame.f_code, frame.f_lineno,
'MAKE_FUNCTION'))
|
[
"Return",
"True",
"if",
"we",
"are",
"looking",
"at",
"a",
"def",
"statement"
] |
rocky/python3-trepan
|
python
|
https://github.com/rocky/python3-trepan/blob/14e91bc0acce090d67be145b1ac040cab92ac5f3/trepan/lib/bytecode.py#L90-L95
|
[
"def",
"is_def_stmt",
"(",
"line",
",",
"frame",
")",
":",
"# Should really also check that operand of 'LOAD_CONST' is a code object",
"return",
"(",
"line",
"and",
"_re_def",
".",
"match",
"(",
"line",
")",
"and",
"op_at_frame",
"(",
"frame",
")",
"==",
"'LOAD_CONST'",
"and",
"stmt_contains_opcode",
"(",
"frame",
".",
"f_code",
",",
"frame",
".",
"f_lineno",
",",
"'MAKE_FUNCTION'",
")",
")"
] |
14e91bc0acce090d67be145b1ac040cab92ac5f3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.