mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3 compat for prpdb
Note this is not tested as I dont use it myself. Fixes #1903330 [TypeError when running calibre.rpdb cli](https://bugs.launchpad.net/calibre/+bug/1903330)
This commit is contained in:
parent
079a47cf81
commit
bdb403fc1c
@ -8,12 +8,11 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import pdb, socket, inspect, sys, select, os, atexit, time
|
import pdb, socket, inspect, sys, select, os, atexit, time
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
|
||||||
from calibre.constants import cache_dir
|
from calibre.constants import cache_dir
|
||||||
from polyglot.builtins import range, raw_input as rinput
|
from polyglot.builtins import range, raw_input as rinput
|
||||||
|
|
||||||
PROMPT = b'(debug) '
|
PROMPT = '(debug) '
|
||||||
QUESTION = b'\x00\x01\x02'
|
QUESTION = '\x00\x01\x02'
|
||||||
|
|
||||||
|
|
||||||
class RemotePdb(pdb.Pdb):
|
class RemotePdb(pdb.Pdb):
|
||||||
@ -59,7 +58,7 @@ class RemotePdb(pdb.Pdb):
|
|||||||
def do_clear(self, arg):
|
def do_clear(self, arg):
|
||||||
if not arg:
|
if not arg:
|
||||||
ans = self.ask_question("Clear all breaks? [y/n]: ")
|
ans = self.ask_question("Clear all breaks? [y/n]: ")
|
||||||
if ans.strip().lower() in {b'y', b'yes'}:
|
if ans.strip().lower() in {'y', 'yes'}:
|
||||||
self.clear_all_breaks()
|
self.clear_all_breaks()
|
||||||
self.prints('All breaks cleared')
|
self.prints('All breaks cleared')
|
||||||
return
|
return
|
||||||
@ -70,7 +69,7 @@ class RemotePdb(pdb.Pdb):
|
|||||||
if not self.breaks:
|
if not self.breaks:
|
||||||
ans = self.ask_question(
|
ans = self.ask_question(
|
||||||
'There are no breakpoints set. Continuing will terminate this debug session. Are you sure? [y/n]: ')
|
'There are no breakpoints set. Continuing will terminate this debug session. Are you sure? [y/n]: ')
|
||||||
if ans.strip().lower() in {b'y', b'yes'}:
|
if ans.strip().lower() in {'y', 'yes'}:
|
||||||
return self.end_session()
|
return self.end_session()
|
||||||
return
|
return
|
||||||
return pdb.Pdb.do_continue(self, arg)
|
return pdb.Pdb.do_continue(self, arg)
|
||||||
@ -120,36 +119,33 @@ def cli(port=4444):
|
|||||||
p = pdb.Pdb()
|
p = pdb.Pdb()
|
||||||
readline.set_completer(p.complete)
|
readline.set_completer(p.complete)
|
||||||
readline.parse_and_bind("tab: complete")
|
readline.parse_and_bind("tab: complete")
|
||||||
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
|
sockf = sock.makefile('rw')
|
||||||
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
recvd = b''
|
recvd = ''
|
||||||
while not recvd.endswith(PROMPT) or select.select([sock], [], [], 0) == ([sock], [], []):
|
while not recvd.endswith(PROMPT) or select.select([sock], [], [], 0) == ([sock], [], []):
|
||||||
buf = eintr_retry_call(sock.recv, 16 * 1024)
|
buf = sockf.read()
|
||||||
if not buf:
|
if not buf:
|
||||||
return
|
return
|
||||||
recvd += buf
|
recvd += buf
|
||||||
recvd = recvd[:-len(PROMPT)]
|
recvd = recvd[:-len(PROMPT)]
|
||||||
if recvd.startswith(QUESTION):
|
if recvd.startswith(QUESTION):
|
||||||
recvd = recvd[len(QUESTION):]
|
recvd = recvd[len(QUESTION):]
|
||||||
stdout.write(recvd)
|
sys.stdout.write(recvd)
|
||||||
raw = stdin.readline() or b'n'
|
raw = sys.stdin.readline() or 'n'
|
||||||
else:
|
else:
|
||||||
stdout.write(recvd)
|
sys.stdout.write(recvd)
|
||||||
raw = b''
|
raw = ''
|
||||||
try:
|
try:
|
||||||
raw = rinput(PROMPT.decode('utf-8'))
|
raw = rinput(PROMPT.decode('utf-8'))
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if not isinstance(raw, bytes):
|
raw += '\n'
|
||||||
raw = raw.encode('utf-8')
|
|
||||||
raw += b'\n'
|
|
||||||
if not raw:
|
if not raw:
|
||||||
raw = b'quit\n'
|
raw = 'quit\n'
|
||||||
eintr_retry_call(sock.send, raw)
|
sockf.write(raw)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user