Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[script.module.web-pdb@matrix] 1.6.2 #2481

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions script.module.web-pdb/addon.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.web-pdb"
name="Web-PDB"
version="1.5.6+matrix.1"
version="1.6.2"
provider-name="Roman V.M.">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.bottle" version="0.12.0"/>
<import addon="script.module.bottle" />
</requires>
<extension point="xbmc.python.script" library="main.py">
<provides>executable</provides>
Expand All @@ -22,6 +22,7 @@
<icon>icon.png</icon>
<screenshot>resources/screenshot.jpg</screenshot>
</assets>
<news>- 1.5.6: Fixed not being able to assign a local variable via the debugger console.</news>
<news>- 1.6.2: Various internal changes.
- 1.6.0: Dropped Python 2 compatibility.</news>
</extension>
</addon>
48 changes: 16 additions & 32 deletions script.module.web-pdb/libs/web_pdb/__init__.py
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
#
Expand All @@ -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']
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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),
Expand All @@ -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):
Expand Down Expand Up @@ -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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@
Asynchronous WebSocket handler
"""

from __future__ import absolute_import
import sys
VER = sys.version_info[0]
if VER >= 3:
from http.server import BaseHTTPRequestHandler
from io import StringIO, BytesIO
else:
from BaseHTTPServer import BaseHTTPRequestHandler
from StringIO import StringIO

import asyncore
import hashlib
import base64
import codecs
import errno
import hashlib
import socket
import struct
import errno
import codecs
from collections import deque
from http.server import BaseHTTPRequestHandler
from io import BytesIO

from . import asyncore
from .. import logging

__all__ = ['WebSocket', 'AsyncWebSocketHandler']
Expand All @@ -36,22 +29,17 @@


def _check_unicode(val):
if VER >= 3:
return isinstance(val, str)
else:
return isinstance(val, unicode)
return isinstance(val, str)


class WebSocketError(Exception):
pass


class HTTPRequest(BaseHTTPRequestHandler):

def __init__(self, request_text):
if VER >= 3:
self.rfile = BytesIO(request_text)
else:
self.rfile = StringIO(request_text)
self.rfile = BytesIO(request_text)
self.raw_requestline = self.rfile.readline()
self.error_code = self.error_message = None
self.parse_request()
Expand Down Expand Up @@ -290,12 +278,8 @@ def _handleData(self):
if not data:
raise WebSocketError("remote socket closed")

if VER >= 3:
for d in data:
self._parseMessage(d)
else:
for d in data:
self._parseMessage(ord(d))
for d in data:
self._parseMessage(d)

def close(self, status=1000, reason=u''):
"""
Expand Down
4 changes: 2 additions & 2 deletions script.module.web-pdb/libs/web_pdb/asyncore_wsgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def handleClose(self):
the Standard Library and the echo WebSocket on ``'/ws'`` path.
"""

from __future__ import absolute_import
import asyncore
import select
import socket
from errno import EINTR
from io import BytesIO
from shutil import copyfileobj
from tempfile import TemporaryFile
from wsgiref.simple_server import WSGIServer, ServerHandler, WSGIRequestHandler

from . import asyncore
from .SimpleWebSocketServer import AsyncWebSocketHandler
from .. import logging

Expand Down
Loading