[#3248|Console] Fix not accepting input under Python3

On Python 3 the chr function returns unicode so trying to decode will
result in an error. Applied a workaround to assign without decoding.
This commit is contained in:
Calum Lind 2019-05-08 20:25:49 +01:00
parent 7d67792493
commit 1a134cab1b
4 changed files with 9 additions and 4 deletions

View File

@ -16,6 +16,7 @@ class Parent(object):
def __init__(self):
self.border_off_x = 1
self.pane_width = 20
self.encoding = 'utf8'
class UICommonTestCase(unittest.TestCase):
@ -39,4 +40,5 @@ class UICommonTestCase(unittest.TestCase):
'/text/field/file/path',
complete=False,
)
self.assertTrue(t) # Shut flake8 up (unused variable)
self.assertTrue(t)
self.assertTrue(t.handle_read(33))

View File

@ -17,6 +17,7 @@ from io import open
import deluge.component as component
import deluge.configmanager
from deluge.common import PY2
from deluge.decorators import overrides
from deluge.ui.console.cmdline.command import Commander
from deluge.ui.console.modes.basemode import BaseMode, move_cursor
@ -334,7 +335,7 @@ class CmdLine(BaseMode, Commander):
if c > 31 and c < 256:
# Emulate getwch
stroke = chr(c)
uchar = ''
uchar = '' if PY2 else stroke
while not uchar:
try:
uchar = stroke.decode(self.encoding)

View File

@ -11,6 +11,7 @@ from __future__ import unicode_literals
import logging
from deluge.common import PY2
from deluge.decorators import overrides
from deluge.ui.console.modes.basemode import InputKeyHandler, move_cursor
from deluge.ui.console.modes.torrentlist.torrentactions import torrent_actions_popup
@ -175,7 +176,7 @@ class SearchMode(InputKeyHandler):
elif c > 31 and c < 256:
old_search_string = self.search_string
stroke = chr(c)
uchar = ''
uchar = '' if PY2 else stroke
while not uchar:
try:
uchar = stroke.decode(self.torrentlist.encoding)

View File

@ -14,6 +14,7 @@ from __future__ import unicode_literals
import logging
import os
from deluge.common import PY2
from deluge.decorators import overrides
from deluge.ui.console.modes.basemode import InputKeyHandler
from deluge.ui.console.utils import colors
@ -950,7 +951,7 @@ class TextInput(InputField):
elif c > 31 and c < 256:
# Emulate getwch
stroke = chr(c)
uchar = ''
uchar = '' if PY2 else stroke
while not uchar:
try:
uchar = stroke.decode(self.parent.encoding)