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

Updated syntax to work in python 3.11 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

/.idea
/__pycache__
8 changes: 4 additions & 4 deletions inputbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def ask(screen, question, default='', password=0):
"ask(screen, question) -> answer"
pygame.font.init()
current_string = list(default)
display_box(screen, question + ": " + string.join(current_string,""))
display_box(screen, question + ": " + "".join(current_string))
while 1:
inkey = get_key()
if inkey == K_BACKSPACE:
Expand All @@ -71,12 +71,12 @@ def ask(screen, question, default='', password=0):
if password:
display_box(screen, question + ": " + "*"*len(current_string))
else:
display_box(screen, question + ": " + string.join(current_string,""))
return string.join(current_string,"")
display_box(screen, question + ": " + "".join(current_string))
return "".join(current_string)

def main():
screen = pygame.display.set_mode((220,40))
screen.fill((0,100,255))
print ask(screen, "Name") + " was entered"
print(ask(screen, "Name") + " was entered")

if __name__ == '__main__': main()
86 changes: 43 additions & 43 deletions rfb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import pyDes
from twisted.python import usage, log
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import protocol
from twisted.application import internet, service
from twisted.internet import protocol
from twisted.application import internet, service

#~ from twisted.internet import reactor

Expand Down Expand Up @@ -399,9 +399,9 @@ def _handleDecodeHextileSubrectsColoured(self, block, bg, color, subrects, x, y,
color = block[pos:pos2]
xy = ord(block[pos2])
wh = ord(block[pos2+1])
sx = xy >> 4
sy = xy & 0xf
sw = (wh >> 4) + 1
sx = xy >> 4
sy = xy & 0xf
sw = (wh >> 4) + 1
sh = (wh & 0xf) + 1
self.fillRectangle(tx + sx, ty + sy, sw, sh, color)
pos += sz
Expand All @@ -414,9 +414,9 @@ def _handleDecodeHextileSubrectsFG(self, block, bg, color, subrects, x, y, width
while pos < end:
xy = ord(block[pos])
wh = ord(block[pos+1])
sx = xy >> 4
sy = xy & 0xf
sw = (wh >> 4) + 1
sx = xy >> 4
sy = xy & 0xf
sw = (wh >> 4) + 1
sh = (wh & 0xf) + 1
self.fillRectangle(tx + sx, ty + sy, sw, sh, color)
pos += 2
Expand Down Expand Up @@ -567,15 +567,15 @@ def copy_text(self, text):
"""The server has new ASCII text in its cut buffer.
(aka clipboard)"""

class RFBFactory(protocol.ClientFactory):
"""A factory for remote frame buffer connections."""

class RFBFactory(protocol.ClientFactory):
"""A factory for remote frame buffer connections."""
# the class of the protocol to build
# should be overriden by application to use a derrived class
# should be overriden by application to use a derrived class
protocol = RFBClient

def __init__(self, password = None, shared = 0):
self.password = password
self.password = password
self.shared = shared

class RFBDes(pyDes.des):
Expand All @@ -601,26 +601,26 @@ def setKey(self, key):
class RFBTest(RFBClient):
"""dummy client"""
def vncConnectionMade(self):
print "Screen format: depth=%d bytes_per_pixel=%r" % (self.depth, self.bpp)
print "Desktop name: %r" % self.name
print("Screen format: depth=%d bytes_per_pixel=%r" % (self.depth, self.bpp))
print("Desktop name: %r" % self.name)
self.SetEncodings([RAW_ENCODING])
self.FramebufferUpdateRequest()

def updateRectangle(self, x, y, width, height, data):
print "%s " * 5 % (x, y, width, height, repr(data[:20]))
print("%s " * 5 % (x, y, width, height, repr(data[:20])))

class RFBTestFactory(protocol.ClientFactory):
class RFBTestFactory(protocol.ClientFactory):
"""test factory"""
protocol = RFBTest
def clientConnectionLost(self, connector, reason):
print reason
from twisted.internet import reactor
reactor.stop()
#~ connector.connect()

def clientConnectionFailed(self, connector, reason):
print "connection failed:", reason
from twisted.internet import reactor
protocol = RFBTest
def clientConnectionLost(self, connector, reason):
print(reason)
from twisted.internet import reactor
reactor.stop()
#~ connector.connect()
def clientConnectionFailed(self, connector, reason):
print("connection failed:", reason)
from twisted.internet import reactor
reactor.stop()

class Options(usage.Options):
Expand All @@ -634,10 +634,10 @@ class Options(usage.Options):
o = Options()
try:
o.parseOptions()
except usage.UsageError, errortext:
print "%s: %s" % (sys.argv[0], errortext)
print "%s: Try --help for usage details." % (sys.argv[0])
raise SystemExit, 1
except usage.UsageError as errortext:
print("%s: %s" % (sys.argv[0], errortext))
print("%s: Try --help for usage details." % (sys.argv[0]))
raise SystemExit(1)

logFile = sys.stdout
if o.opts['outfile']:
Expand All @@ -647,15 +647,15 @@ class Options(usage.Options):
host = o.opts['host']
port = int(o.opts['display']) + 5900

application = service.Application("rfb test") # create Application

# connect to this host and port, and reconnect if we get disconnected
vncClient = internet.TCPClient(host, port, RFBFactory()) # create the service
vncClient.setServiceParent(application)

# this file should be run as 'twistd -y rfb.py' but it didn't work -
# could't import crippled_des.py, so using this hack.
# now with crippled_des.py replaced with pyDes this can be no more actual
from twisted.internet import reactor
vncClient.startService()
reactor.run()
application = service.Application("rfb test") # create Application
# connect to this host and port, and reconnect if we get disconnected
vncClient = internet.TCPClient(host, port, RFBFactory()) # create the service
vncClient.setServiceParent(application)
# this file should be run as 'twistd -y rfb.py' but it didn't work -
# could't import crippled_des.py, so using this hack.
# now with crippled_des.py replaced with pyDes this can be no more actual
from twisted.internet import reactor
vncClient.startService()
reactor.run()
42 changes: 21 additions & 21 deletions vncviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def setRFBSize(self, width, height, depth=32):
#then communicate that to the protocol...
else:
#~ self.screen = pygame.display.set_mode(self.area.size, winstyle, depth)
raise ValueError, "color depth not supported"
raise ValueError ("color depth not supported")
self.background = pygame.Surface((self.width, self.height), depth)
self.background.fill(0) #black

Expand Down Expand Up @@ -190,7 +190,7 @@ def checkEvents(self):
elif e.unicode:
self.protocol.keyEvent(ord(e.unicode))
else:
print "warning: unknown key %r" % (e)
print("warning: unknown key %r" % (e))
elif e.type == KEYUP:
if e.key in MODIFIERS:
self.protocol.keyEvent(MODIFIERS[e.key], down=0)
Expand Down Expand Up @@ -311,10 +311,10 @@ def fillRectangle(self, x, y, width, height, color):
self.screen.fill(struct.unpack("BBBB", color), (x, y, width, height))

def bell(self):
print "katsching"
print("katsching")

def copy_text(self, text):
print "Clipboard: %r" % text
print("Clipboard: %r" % text)

#use a derrived class for other depths. hopefully with better performance
#that a single class with complicated/dynamic color conversion.
Expand Down Expand Up @@ -345,7 +345,7 @@ def fillRectangle(self, x, y, width, height, color):
"""fill rectangle with one color"""
self.screen.fill(ord(color), (x, y, width, height))

class VNCFactory(rfb.RFBFactory):
class VNCFactory(rfb.RFBFactory):
"""A factory for remote frame buffer connections."""

def __init__(self, remoteframebuffer, depth, fast, *args, **kwargs):
Expand All @@ -356,7 +356,7 @@ def __init__(self, remoteframebuffer, depth, fast, *args, **kwargs):
elif depth == 8:
self.protocol = RFBToGUIeightbits
else:
raise ValueError, "color depth not supported"
raise ValueError("color depth not supported")

if fast:
self.encodings = [
Expand All @@ -377,14 +377,14 @@ def buildProtocol(self, addr):
display = addr.port - 5900
pygame.display.set_caption('Python VNC Viewer on %s:%s' % (addr.host, display))
return rfb.RFBFactory.buildProtocol(self, addr)

def clientConnectionLost(self, connector, reason):
log.msg("connection lost: %r" % reason.getErrorMessage())
reactor.stop()

def clientConnectionLost(self, connector, reason):
log.msg("connection lost: %r" % reason.getErrorMessage())
reactor.stop()
def clientConnectionFailed(self, connector, reason):
log.msg("cannot connect to server: %r\n" % reason.getErrorMessage())
reactor.stop()
log.msg("cannot connect to server: %r\n" % reason.getErrorMessage())
reactor.stop()

class Options(usage.Options):
optParameters = [
Expand Down Expand Up @@ -412,10 +412,10 @@ def main():
o = Options()
try:
o.parseOptions()
except usage.UsageError, errortext:
print "%s: %s" % (sys.argv[0], errortext)
print "%s: Try --help for usage details." % (sys.argv[0])
raise SystemExit, 1
except usage.UsageError as errortext:
print("%s: %s" % (sys.argv[0], errortext))
print("%s: Try --help for usage details." % (sys.argv[0]))
raise SystemExit(1)

depth = int(o.opts['depth'])

Expand Down Expand Up @@ -444,7 +444,7 @@ def main():
if host == '': host = 'localhost'
display = int(display)

# connect to this host and port, and reconnect if we get disconnected
# connect to this host and port, and reconnect if we get disconnected
reactor.connectTCP(
host, #remote hostname
display + 5900, #TCP port number
Expand All @@ -456,10 +456,10 @@ def main():
int(o.opts['shared']), #shared session flag
)
)

# run the application
# run the application
reactor.callLater(0.1, remoteframebuffer.mainloop)
reactor.run()
reactor.run()


if __name__ == '__main__':
Expand Down