diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73fb4fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +/.idea +/__pycache__ diff --git a/inputbox.py b/inputbox.py index 8c65115..7163b42 100644 --- a/inputbox.py +++ b/inputbox.py @@ -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: @@ -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() diff --git a/rfb.py b/rfb.py index b61997f..b58a3d9 100644 --- a/rfb.py +++ b/rfb.py @@ -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 @@ -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 @@ -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 @@ -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): @@ -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): @@ -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']: @@ -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() diff --git a/vncviewer.py b/vncviewer.py index 51f952b..eb970a9 100644 --- a/vncviewer.py +++ b/vncviewer.py @@ -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 @@ -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) @@ -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. @@ -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): @@ -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 = [ @@ -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 = [ @@ -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']) @@ -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 @@ -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__':