Skip to content

Commit

Permalink
Switch to byte strings for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigc committed Dec 26, 2016
1 parent 98a3df2 commit 4622dc0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/conch/examples/demo_draw.tac
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Draw(insults.TerminalProtocol):
self.terminal.cursorBackward()

def makeService(args):
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username=b"password")

f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
Expand Down
2 changes: 1 addition & 1 deletion docs/conch/examples/demo_insults.tac
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class DemoProtocol(insults.TerminalProtocol):


def makeService(args):
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username=b"password")

f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
Expand Down
2 changes: 1 addition & 1 deletion docs/conch/examples/demo_manhole.tac
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ from twisted.application import internet, service
from twisted.cred import checkers, portal

def makeService(args):
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username=b"password")

f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
Expand Down
2 changes: 1 addition & 1 deletion docs/conch/examples/demo_recvline.tac
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DemoRecvLine(recvline.HistoricRecvLine):
self.terminal.write(self.ps[self.pn])

def makeService(args):
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username=b"password")

f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
Expand Down
2 changes: 1 addition & 1 deletion docs/conch/examples/demo_scroll.tac
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DemoProtocol(insults.TerminalProtocol):


def makeService(args):
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username=b"password")

f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
Expand Down
14 changes: 7 additions & 7 deletions docs/conch/examples/sshsimpleclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

# Replace this with your username.
# Default username and password will match the sshsimpleserver.py
USER = 'user'
USER = b'user'
HOST = 'localhost'
PORT = 5022
SERVER_FINGERPRINT = 'pu:t:se:rv:er:fi:ng:er:pr:in:t:he:re'
SERVER_FINGERPRINT = b'55:55:66:24:6b:03:0e:f1:ec:f8:66:c3:51:df:27:4b'

# Path to RSA SSH keys accepted by the server.
CLIENT_RSA_PUBLIC = 'ssh-keys/client_rsa.pub'
Expand Down Expand Up @@ -94,7 +94,7 @@ def serviceStarted(self):


class TrueChannel(channel.SSHChannel):
name = 'session' # needed for commands
name = b'session' # needed for commands

def openFailed(self, reason):
print('true failed', reason)
Expand All @@ -108,7 +108,7 @@ def request_exit_status(self, data):
self.loseConnection()

class FalseChannel(channel.SSHChannel):
name = 'session'
name = b'session'

def openFailed(self, reason):
print('false failed', reason)
Expand All @@ -122,18 +122,18 @@ def request_exit_status(self, data):
self.loseConnection()

class CatChannel(channel.SSHChannel):
name = 'session'
name = b'session'

def openFailed(self, reason):
print('echo failed', reason)

def channelOpen(self, ignoredData):
self.data = ''
self.data = b''
d = self.conn.sendRequest(self, 'exec', common.NS('cat'), wantReply = 1)
d.addCallback(self._cbRequest)

def _cbRequest(self, ignored):
self.write('hello conch\n')
self.write(b'hello conch\n')
self.conn.sendEOF(self)

def dataReceived(self, data):
Expand Down
20 changes: 10 additions & 10 deletions docs/conch/examples/sshsimpleserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ExampleAvatar(avatar.ConchUser):
def __init__(self, username):
avatar.ConchUser.__init__(self)
self.username = username
self.channelLookup.update({'session':session.SSHSession})
self.channelLookup.update({b'session':session.SSHSession})



Expand Down Expand Up @@ -130,9 +130,9 @@ def dataReceived(self, data):
Just echo the received data and and if Ctrl+C is received, close the
session.
"""
if data == '\r':
data = '\r\n'
elif data == '\x03': #^C
if data == b'\r':
data = b'\r\n'
elif data == b'\x03': #^C
self.transport.loseConnection()
return
self.transport.write(data)
Expand Down Expand Up @@ -206,15 +206,15 @@ class ExampleFactory(factory.SSHFactory):
# To simplify the example this server is defined only with a host key of
# type RSA.
publicKeys = {
'ssh-rsa': keys.Key.fromFile(SERVER_RSA_PUBLIC)
b'ssh-rsa': keys.Key.fromFile(SERVER_RSA_PUBLIC)
}
privateKeys = {
'ssh-rsa': keys.Key.fromFile(SERVER_RSA_PRIVATE)
b'ssh-rsa': keys.Key.fromFile(SERVER_RSA_PRIVATE)
}
# Service handlers.
services = {
'ssh-userauth': userauth.SSHUserAuthServer,
'ssh-connection': connection.SSHConnection
b'ssh-userauth': userauth.SSHUserAuthServer,
b'ssh-connection': connection.SSHConnection
}

def getPrimes(self):
Expand All @@ -226,9 +226,9 @@ def getPrimes(self):

portal = portal.Portal(ExampleRealm())
passwdDB = InMemoryUsernamePasswordDatabaseDontUse()
passwdDB.addUser('user', 'password')
passwdDB.addUser(b'user', b'password')
sshDB = SSHPublicKeyChecker(InMemorySSHKeyDB(
{'user': [keys.Key.fromFile(CLIENT_RSA_PUBLIC)]}))
{b'user': [keys.Key.fromFile(CLIENT_RSA_PUBLIC)]}))
portal.registerChecker(passwdDB)
portal.registerChecker(sshDB)
ExampleFactory.portal = portal
Expand Down
10 changes: 5 additions & 5 deletions docs/conch/examples/telnet_echo.tac
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ from twisted.application.service import Application

class TelnetEcho(TelnetProtocol):
def enableRemote(self, option):
self.transport.write("You tried to enable %r (I rejected it)\r\n" % (option,))
self.transport.write(b"You tried to enable " + option + b" (I rejected it)\r\n")
return False


def disableRemote(self, option):
self.transport.write("You disabled %r\r\n" % (option,))
self.transport.write(b"You disabled " + option + b"\r\n")


def enableLocal(self, option):
self.transport.write("You tried to make me enable %r (I rejected it)\r\n" % (option,))
self.transport.write(b"You tried to make me enable " + option + b" (I rejected it)\r\n" % (option,))
return False


def disableLocal(self, option):
self.transport.write("You asked me to disable %r\r\n" % (option,))
self.transport.write(b"You asked me to disable " + option + "\r\n")


def dataReceived(self, data):
self.transport.write("I received %r from you\r\n" % (data,))
self.transport.write(b"I received "+ data + b" from you\r\n")


factory = ServerFactory()
Expand Down
2 changes: 1 addition & 1 deletion docs/conch/examples/window.tac
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ButtonDemo(insults.TerminalProtocol):


def makeService(args):
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username=b"password")

f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
Expand Down

0 comments on commit 4622dc0

Please sign in to comment.