Skip to content

Commit

Permalink
Fixed twisted example: use implementer decorator instead of depreca…
Browse files Browse the repository at this point in the history
…ted `implements`.

Fix: PYI034
  • Loading branch information
Aleksei Stepanov committed Aug 15, 2023
1 parent 042db77 commit 19d8a47
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions examples/twisted_serve_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
)
from twisted.cred.portal import Portal
from twisted.python.components import Adapter, Componentized
from zope.interface import Attribute, Interface, implements
from zope.interface import Attribute, Interface, implementer

import urwid
from urwid.raw_display import Screen
Expand Down Expand Up @@ -84,8 +84,6 @@ def draw():
"""Refresh the UI"""




class UrwidUi:

def __init__(self, urwid_mind):
Expand All @@ -112,7 +110,6 @@ def create_urwid_mainloop(self):
return loop



class UnhandledKeyHandler:

def __init__(self, mind):
Expand All @@ -132,10 +129,9 @@ def key_ctrl_c(self, key):
self.mind.terminal.loseConnection()


@implementer(IUrwidMind)
class UrwidMind(Adapter):

implements(IUrwidMind)

cred_checkers = []
ui = None

Expand All @@ -160,9 +156,6 @@ def draw(self):
self.ui.loop.draw_screen()





class TwistedScreen(Screen):
"""A Urwid screen which knows about the Twisted terminal protocol that is
driving it.
Expand All @@ -189,8 +182,7 @@ def __init__(self, terminalProtocol):
self._pal_escape = {}
self.bright_is_bold = True
self.register_palette_entry(None, 'black', 'white')
urwid.signals.connect_signal(self, urwid.UPDATE_PALETTE_ENTRY,
self._on_update_palette_entry)
urwid.signals.connect_signal(self, urwid.UPDATE_PALETTE_ENTRY, self._on_update_palette_entry)
# Don't need to wait for anything to start
self._started = True

Expand Down Expand Up @@ -368,14 +360,14 @@ def dataReceived(self, data):
"""
self.urwid_mind.push(data)

def _unhandled_input(self, input):
def _unhandled_input(self, data):
# evil
proceed = True
if hasattr(self.urwid_toplevel, 'app'):
proceed = self.urwid_toplevel.app.unhandled_input(self, input)
proceed = self.urwid_toplevel.app.unhandled_input(self, data)
if not proceed:
return
if input == 'ctrl c':
if data == 'ctrl c':
self.terminal.loseConnection()


Expand All @@ -390,7 +382,7 @@ class UrwidUser(TerminalUser):
The default implementation doesn't
"""
def __init__(self, original, avatarId):
TerminalUser.__init__(self, original, avatarId)
super().__init__(original, avatarId)
self.avatarId = avatarId


Expand All @@ -406,8 +398,7 @@ class UrwidTerminalSession(TerminalSession):
def openShell(self, proto):
"""Open a shell.
"""
self.chained_protocol = UrwidServerProtocol(
UrwidTerminalProtocol, IUrwidMind(self.original))
self.chained_protocol = UrwidServerProtocol(UrwidTerminalProtocol, IUrwidMind(self.original))
TerminalSessionTransport(
proto, self.chained_protocol,
IConchUser(self.original),
Expand Down

0 comments on commit 19d8a47

Please sign in to comment.