-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2481 from romanvm/script.module.web-pdb@matrix
[script.module.web-pdb@matrix] 1.6.2
- Loading branch information
Showing
10 changed files
with
699 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# coding: utf-8 | ||
# Author: Roman Miroshnychenko aka Roman V.M. | ||
# E-mail: [email protected] | ||
# E-mail: [email protected] | ||
# | ||
# Copyright (c) 2016 Roman Miroshnychenko | ||
# | ||
|
@@ -25,20 +24,18 @@ | |
A web-interface for Python's built-in PDB debugger | ||
""" | ||
|
||
from __future__ import absolute_import, unicode_literals | ||
import inspect | ||
import os | ||
import random | ||
import sys | ||
import traceback | ||
import random | ||
from contextlib import contextmanager | ||
from pdb import Pdb | ||
from pprint import pformat | ||
if sys.version_info[0] == 2: | ||
from .pdb_py2 import PdbPy2 as Pdb | ||
else: | ||
from pdb import Pdb | ||
|
||
import xbmc | ||
from xbmcgui import Dialog | ||
|
||
from .web_console import WebConsole | ||
|
||
__all__ = ['WebPdb', 'set_trace', 'post_mortem', 'catch_post_mortem'] | ||
|
@@ -68,7 +65,7 @@ def __init__(self, host='', port=5555): | |
random.seed() | ||
port = random.randint(32768, 65536) | ||
self.console = WebConsole(host, port, self) | ||
Pdb.__init__(self, stdin=self.console, stdout=self.console) | ||
super().__init__(stdin=self.console, stdout=self.console) | ||
WebPdb.active_instance = self | ||
|
||
def do_quit(self, arg): | ||
|
@@ -80,7 +77,7 @@ def do_quit(self, arg): | |
self.console.flush() | ||
self.console.close() | ||
WebPdb.active_instance = None | ||
return Pdb.do_quit(self, arg) | ||
return super().do_quit(arg) | ||
|
||
do_q = do_exit = do_quit | ||
|
||
|
@@ -96,18 +93,13 @@ def do_inspect(self, arg): | |
else: | ||
obj = WebPdb.null | ||
if obj is not WebPdb.null: | ||
self.console.writeline( | ||
'{0} = {1}:\n'.format(arg, type(obj)) | ||
) | ||
self.console.writeline(f'{arg} = {type(obj)}:\n') | ||
for name, value in inspect.getmembers(obj): | ||
if not (name.startswith('__') and (name.endswith('__'))): | ||
self.console.writeline(' {0}: {1}\n'.format( | ||
name, self._get_repr(value, pretty=True, indent=8) | ||
)) | ||
repr_value = self._get_repr(value, pretty=True, indent=8) | ||
self.console.writeline(f' {name}: {repr_value}\n') | ||
else: | ||
self.console.writeline( | ||
'NameError: name "{0}" is not defined\n'.format(arg) | ||
) | ||
self.console.writeline(f'NameError: name "{arg}" is not defined\n') | ||
self.console.flush() | ||
|
||
do_i = do_inspect | ||
|
@@ -130,12 +122,6 @@ def _get_repr(obj, pretty=False, indent=1): | |
repr_value = pformat(obj, indent) | ||
else: | ||
repr_value = repr(obj) | ||
if sys.version_info[0] == 2: | ||
# Try to convert Unicode string to human-readable form | ||
try: | ||
repr_value = repr_value.decode('raw_unicode_escape') | ||
except UnicodeError: | ||
repr_value = repr_value.decode('utf-8', 'replace') | ||
return repr_value | ||
|
||
def set_continue(self): | ||
|
@@ -144,7 +130,7 @@ def set_continue(self): | |
|
||
def dispatch_return(self, frame, arg): | ||
# The parent's method needs to be called first. | ||
ret = Pdb.dispatch_return(self, frame, arg) | ||
ret = super().dispatch_return(frame, arg) | ||
if frame.f_back is None: | ||
self.console.writeline('*** Thread finished ***\n') | ||
if not self.console.closed: | ||
|
@@ -164,8 +150,6 @@ def get_current_frame_data(self): | |
""" | ||
filename = self.curframe.f_code.co_filename | ||
lines, start_line = inspect.findsource(self.curframe) | ||
if sys.version_info[0] == 2: | ||
lines = [line.decode('utf-8') for line in lines] | ||
return { | ||
'dirname': os.path.dirname(os.path.abspath(filename)) + os.path.sep, | ||
'filename': os.path.basename(filename), | ||
|
@@ -187,7 +171,7 @@ def _format_variables(self, raw_vars): | |
for var, value in raw_vars.items(): | ||
if not (var.startswith('__') and var.endswith('__')): | ||
repr_value = self._get_repr(value) | ||
f_vars.append('{0} = {1}'.format(var, repr_value)) | ||
f_vars.append(f'{var} = {repr_value}') | ||
return '\n'.join(sorted(f_vars)) | ||
|
||
def get_globals(self): | ||
|
@@ -328,9 +312,9 @@ def catch_post_mortem(host='', port=5555): | |
try: | ||
yield | ||
except Exception: | ||
xbmc.log('Web-PDB: unhandled exception detected:\n{0}'.format( | ||
traceback.format_exc()), xbmc.LOGERROR | ||
) | ||
stack_trace = traceback.format_exc() | ||
xbmc.log(f'Web-PDB: unhandled exception detected:\n{stack_trace}', | ||
xbmc.LOGERROR) | ||
xbmc.log('Web-PDB: starting post-mortem debugging...', xbmc.LOGERROR) | ||
Dialog().notification('Web-PDB', | ||
'Addon error! Starting post-mortem debugging.', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.