diff options
author | Collin Winter <collinw@gmail.com> | 2007-07-17 20:59:35 (GMT) |
---|---|---|
committer | Collin Winter <collinw@gmail.com> | 2007-07-17 20:59:35 (GMT) |
commit | 6f2df4d5e193d54244b0c2de91ef0ab1604b9243 (patch) | |
tree | 5e172400da7561eb4bb8fafc62c8cab511d74dad /Demo/rpc | |
parent | a8c360ee76fb76902a2e2140fbb38d4b06b2d9fb (diff) | |
download | cpython-6f2df4d5e193d54244b0c2de91ef0ab1604b9243.zip cpython-6f2df4d5e193d54244b0c2de91ef0ab1604b9243.tar.gz cpython-6f2df4d5e193d54244b0c2de91ef0ab1604b9243.tar.bz2 |
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Diffstat (limited to 'Demo/rpc')
-rw-r--r-- | Demo/rpc/mountclient.py | 4 | ||||
-rw-r--r-- | Demo/rpc/nfsclient.py | 8 | ||||
-rw-r--r-- | Demo/rpc/rnusersclient.py | 10 | ||||
-rw-r--r-- | Demo/rpc/rpc.py | 92 | ||||
-rw-r--r-- | Demo/rpc/xdr.py | 26 |
5 files changed, 68 insertions, 72 deletions
diff --git a/Demo/rpc/mountclient.py b/Demo/rpc/mountclient.py index 318a9d9..3bb88b1 100644 --- a/Demo/rpc/mountclient.py +++ b/Demo/rpc/mountclient.py @@ -193,10 +193,10 @@ def test(): mcl = C(host) list = mcl.Export() for item in list: - print item + print(item) try: mcl.Mnt(item[0]) except: - print 'Sorry' + print('Sorry') continue mcl.Umnt(item[0]) diff --git a/Demo/rpc/nfsclient.py b/Demo/rpc/nfsclient.py index 3890aff..aad8cf3 100644 --- a/Demo/rpc/nfsclient.py +++ b/Demo/rpc/nfsclient.py @@ -187,14 +187,14 @@ def test(): if filesys == None: list = mcl.Export() for item in list: - print item + print(item) return sf = mcl.Mnt(filesys) - print sf + print(sf) fh = sf[1] if fh: ncl = NFSClient(host) - print ncl.Getattr(fh) + print(ncl.Getattr(fh)) list = ncl.Listdir(fh) - for item in list: print item + for item in list: print(item) mcl.Umnt(filesys) diff --git a/Demo/rpc/rnusersclient.py b/Demo/rpc/rnusersclient.py index 1f3a882..eaabefe 100644 --- a/Demo/rpc/rnusersclient.py +++ b/Demo/rpc/rnusersclient.py @@ -77,19 +77,19 @@ def test(): line = strip0(line) name = strip0(name) host = strip0(host) - print "%r %r %r %s %s" % (name, host, line, time, idle) + print("%r %r %r %s %s" % (name, host, line, time, idle)) def testbcast(): c = BroadcastRnusersClient('<broadcast>') def listit(list, fromaddr): host, port = fromaddr - print host + '\t:', + print(host + '\t:', end=' ') for (line, name, host, time), idle in list: - print strip0(name), - print + print(strip0(name), end=' ') + print() c.set_reply_handler(listit) all = c.Names() - print 'Total Count:', len(all) + print('Total Count:', len(all)) def strip0(s): while s and s[-1] == '\0': s = s[:-1] diff --git a/Demo/rpc/rpc.py b/Demo/rpc/rpc.py index f7231c1..99115d3 100644 --- a/Demo/rpc/rpc.py +++ b/Demo/rpc/rpc.py @@ -95,10 +95,10 @@ class Unpacker(xdr.Unpacker): xid = self.unpack_uint() temp = self.unpack_enum() if temp != CALL: - raise BadRPCFormat, 'no CALL but %r' % (temp,) + raise BadRPCFormat('no CALL but %r' % (temp,)) temp = self.unpack_uint() if temp != RPCVERSION: - raise BadRPCVersion, 'bad RPC version %r' % (temp,) + raise BadRPCVersion('bad RPC version %r' % (temp,)) prog = self.unpack_uint() vers = self.unpack_uint() proc = self.unpack_uint() @@ -111,38 +111,34 @@ class Unpacker(xdr.Unpacker): xid = self.unpack_uint() mtype = self.unpack_enum() if mtype != REPLY: - raise RuntimeError, 'no REPLY but %r' % (mtype,) + raise RuntimeError('no REPLY but %r' % (mtype,)) stat = self.unpack_enum() if stat == MSG_DENIED: stat = self.unpack_enum() if stat == RPC_MISMATCH: low = self.unpack_uint() high = self.unpack_uint() - raise RuntimeError, \ - 'MSG_DENIED: RPC_MISMATCH: %r' % ((low, high),) + raise RuntimeError('MSG_DENIED: RPC_MISMATCH: %r' % ((low, high),)) if stat == AUTH_ERROR: stat = self.unpack_uint() - raise RuntimeError, \ - 'MSG_DENIED: AUTH_ERROR: %r' % (stat,) - raise RuntimeError, 'MSG_DENIED: %r' % (stat,) + raise RuntimeError('MSG_DENIED: AUTH_ERROR: %r' % (stat,)) + raise RuntimeError('MSG_DENIED: %r' % (stat,)) if stat != MSG_ACCEPTED: - raise RuntimeError, \ - 'Neither MSG_DENIED nor MSG_ACCEPTED: %r' % (stat,) + raise RuntimeError('Neither MSG_DENIED nor MSG_ACCEPTED: %r' % (stat,)) verf = self.unpack_auth() stat = self.unpack_enum() if stat == PROG_UNAVAIL: - raise RuntimeError, 'call failed: PROG_UNAVAIL' + raise RuntimeError('call failed: PROG_UNAVAIL') if stat == PROG_MISMATCH: low = self.unpack_uint() high = self.unpack_uint() - raise RuntimeError, \ - 'call failed: PROG_MISMATCH: %r' % ((low, high),) + raise RuntimeError('call failed: PROG_MISMATCH: %r' % ((low, high),)) if stat == PROC_UNAVAIL: - raise RuntimeError, 'call failed: PROC_UNAVAIL' + raise RuntimeError('call failed: PROC_UNAVAIL') if stat == GARBAGE_ARGS: - raise RuntimeError, 'call failed: GARBAGE_ARGS' + raise RuntimeError('call failed: GARBAGE_ARGS') if stat != SUCCESS: - raise RuntimeError, 'call failed: %r' % (stat,) + raise RuntimeError('call failed: %r' % (stat,)) return xid, verf # Caller must get procedure-specific part of reply @@ -193,7 +189,7 @@ def unix_epoch(): offset, hh = divmod(hh + offset, 24) d = d + offset _unix_epoch = time.mktime((y, m, d, hh, mm, ss, 0, 0, 0)) - print "Unix epoch:", time.ctime(_unix_epoch) + print("Unix epoch:", time.ctime(_unix_epoch)) return _unix_epoch @@ -219,7 +215,7 @@ class Client: def makesocket(self): # This MUST be overridden - raise RuntimeError, 'makesocket not defined' + raise RuntimeError('makesocket not defined') def connsocket(self): # Override this if you don't want/need a connection @@ -237,7 +233,7 @@ class Client: def make_call(self, proc, args, pack_func, unpack_func): # Don't normally override this (but see Broadcast) if pack_func is None and args is not None: - raise TypeError, 'non-null args with null pack_func' + raise TypeError('non-null args with null pack_func') self.start_call(proc) if pack_func: pack_func(args) @@ -260,7 +256,7 @@ class Client: def do_call(self): # This MUST be overridden - raise RuntimeError, 'do_call not defined' + raise RuntimeError('do_call not defined') def mkcred(self): # Override this to use more powerful credentials @@ -282,7 +278,7 @@ class Client: def sendfrag(sock, last, frag): x = len(frag) - if last: x = x | 0x80000000L + if last: x = x | 0x80000000 header = (chr(int(x>>24 & 0xff)) + chr(int(x>>16 & 0xff)) + \ chr(int(x>>8 & 0xff)) + chr(int(x & 0xff))) sock.send(header + frag) @@ -294,7 +290,7 @@ def recvfrag(sock): header = sock.recv(4) if len(header) < 4: raise EOFError - x = long(ord(header[0]))<<24 | ord(header[1])<<16 | \ + x = int(ord(header[0]))<<24 | ord(header[1])<<16 | \ ord(header[2])<<8 | ord(header[3]) last = ((x & 0x80000000) != 0) n = int(x & 0x7fffffff) @@ -333,8 +329,8 @@ def bindresvport(sock, host): except socket.error as e: (errno, msg) = e if errno != 114: - raise socket.error, (errno, msg) - raise RuntimeError, 'can\'t assign reserved port' + raise socket.error(errno, msg) + raise RuntimeError('can\'t assign reserved port') # Client using TCP to a specific port @@ -353,8 +349,8 @@ class RawTCPClient(Client): xid, verf = u.unpack_replyheader() if xid != self.lastxid: # Can't really happen since this is TCP... - raise RuntimeError, 'wrong xid in reply %r instead of %r' % ( - xid, self.lastxid) + raise RuntimeError('wrong xid in reply %r instead of %r' % ( + xid, self.lastxid)) # Client using UDP to a specific port @@ -370,7 +366,7 @@ class RawUDPClient(Client): try: from select import select except ImportError: - print 'WARNING: select not found, RPC may hang' + print('WARNING: select not found, RPC may hang') select = None BUFSIZE = 8192 # Max UDP buffer size timeout = 1 @@ -381,7 +377,7 @@ class RawUDPClient(Client): r, w, x = select(r, w, x, timeout) if self.sock not in r: count = count - 1 - if count < 0: raise RuntimeError, 'timeout' + if count < 0: raise RuntimeError('timeout') if timeout < 25: timeout = timeout *2 ## print 'RESEND', timeout, count self.sock.send(call) @@ -417,7 +413,7 @@ class RawBroadcastUDPClient(RawUDPClient): def make_call(self, proc, args, pack_func, unpack_func): if pack_func is None and args is not None: - raise TypeError, 'non-null args with null pack_func' + raise TypeError('non-null args with null pack_func') self.start_call(proc) if pack_func: pack_func(args) @@ -426,7 +422,7 @@ class RawBroadcastUDPClient(RawUDPClient): try: from select import select except ImportError: - print 'WARNING: select not found, broadcast will hang' + print('WARNING: select not found, broadcast will hang') select = None BUFSIZE = 8192 # Max UDP buffer size (for reply) replies = [] @@ -585,7 +581,7 @@ class TCPClient(RawTCPClient): port = pmap.Getport((prog, vers, IPPROTO_TCP, 0)) pmap.close() if port == 0: - raise RuntimeError, 'program not registered' + raise RuntimeError('program not registered') RawTCPClient.__init__(self, host, prog, vers, port) @@ -596,7 +592,7 @@ class UDPClient(RawUDPClient): port = pmap.Getport((prog, vers, IPPROTO_UDP, 0)) pmap.close() if port == 0: - raise RuntimeError, 'program not registered' + raise RuntimeError('program not registered') RawUDPClient.__init__(self, host, prog, vers, port) @@ -665,13 +661,13 @@ class Server: mapping = self.prog, self.vers, self.prot, self.port p = TCPPortMapperClient(self.host) if not p.Set(mapping): - raise RuntimeError, 'register failed' + raise RuntimeError('register failed') def unregister(self): mapping = self.prog, self.vers, self.prot, self.port p = TCPPortMapperClient(self.host) if not p.Unset(mapping): - raise RuntimeError, 'unregister failed' + raise RuntimeError('unregister failed') def handle(self, call): # Don't use unpack_header but parse the header piecewise @@ -736,7 +732,7 @@ class Server: def makesocket(self): # This MUST be overridden - raise RuntimeError, 'makesocket not defined' + raise RuntimeError('makesocket not defined') def bindsocket(self): # Override this to bind to a different port (e.g. reserved) @@ -767,7 +763,7 @@ class TCPServer(Server): except EOFError: break except socket.error as msg: - print 'socket error:', msg + print('socket error:', msg) break reply = self.handle(call) if reply is not None: @@ -826,11 +822,11 @@ def test(): list = pmap.Dump() list.sort() for prog, vers, prot, port in list: - print prog, vers, - if prot == IPPROTO_TCP: print 'tcp', - elif prot == IPPROTO_UDP: print 'udp', - else: print prot, - print port + print(prog, vers, end=' ') + if prot == IPPROTO_TCP: print('tcp', end=' ') + elif prot == IPPROTO_UDP: print('udp', end=' ') + else: print(prot, end=' ') + print(port) # Test program for broadcast operation -- dump everybody's portmapper status @@ -843,7 +839,7 @@ def testbcast(): bcastaddr = '<broadcast>' def rh(reply, fromaddr): host, port = fromaddr - print host + '\t' + repr(reply) + print(host + '\t' + repr(reply)) pmap = BroadcastUDPPortMapperClient(bcastaddr) pmap.set_reply_handler(rh) pmap.set_timeout(5) @@ -861,21 +857,21 @@ def testsvr(): def handle_1(self): arg = self.unpacker.unpack_string() self.turn_around() - print 'RPC function 1 called, arg', repr(arg) + print('RPC function 1 called, arg', repr(arg)) self.packer.pack_string(arg + arg) # s = S('', 0x20000000, 1, 0) try: s.unregister() except RuntimeError as msg: - print 'RuntimeError:', msg, '(ignored)' + print('RuntimeError:', msg, '(ignored)') s.register() - print 'Service started...' + print('Service started...') try: s.loop() finally: s.unregister() - print 'Service interrupted.' + print('Service interrupted.') def testclt(): @@ -889,6 +885,6 @@ def testclt(): self.packer.pack_string, \ self.unpacker.unpack_string) c = C(host, 0x20000000, 1) - print 'making call...' + print('making call...') reply = c.call_1('hello, world, ') - print 'call returned', repr(reply) + print('call returned', repr(reply)) diff --git a/Demo/rpc/xdr.py b/Demo/rpc/xdr.py index e03b352..fd9efee 100644 --- a/Demo/rpc/xdr.py +++ b/Demo/rpc/xdr.py @@ -7,7 +7,7 @@ except ImportError: struct = None -Long = type(0L) +Long = type(0) class Packer: @@ -28,8 +28,8 @@ class Packer: if struct and struct.pack('l', 1) == '\0\0\0\1': def pack_uint(self, x): if type(x) == Long: - x = int((x + 0x80000000L) % 0x100000000L \ - - 0x80000000L) + x = int((x + 0x80000000) % 0x100000000 \ + - 0x80000000) self.buf = self.buf + struct.pack('l', x) pack_int = pack_uint @@ -56,7 +56,7 @@ class Packer: def pack_fstring(self, n, s): if n < 0: - raise ValueError, 'fstring size must be nonnegative' + raise ValueError('fstring size must be nonnegative') n = ((n+3)/4)*4 data = s[:n] data = data + (n - len(data)) * '\0' @@ -79,7 +79,7 @@ class Packer: def pack_farray(self, n, list, pack_item): if len(list) != n: - raise ValueError, 'wrong array size' + raise ValueError('wrong array size') for item in list: pack_item(item) @@ -100,7 +100,7 @@ class Unpacker: def done(self): if self.pos < len(self.buf): - raise RuntimeError, 'unextracted data remains' + raise RuntimeError('unextracted data remains') def unpack_uint(self): i = self.pos @@ -108,11 +108,11 @@ class Unpacker: data = self.buf[i:j] if len(data) < 4: raise EOFError - x = long(ord(data[0]))<<24 | ord(data[1])<<16 | \ + x = int(ord(data[0]))<<24 | ord(data[1])<<16 | \ ord(data[2])<<8 | ord(data[3]) # Return a Python long only if the value is not representable # as a nonnegative Python int - if x < 0x80000000L: x = int(x) + if x < 0x80000000: x = int(x) return x if struct and struct.unpack('l', '\0\0\0\1') == 1: def unpack_uint(self): @@ -125,7 +125,7 @@ class Unpacker: def unpack_int(self): x = self.unpack_uint() - if x >= 0x80000000L: x = x - 0x100000000L + if x >= 0x80000000: x = x - 0x100000000 return int(x) unpack_enum = unpack_int @@ -135,11 +135,11 @@ class Unpacker: def unpack_uhyper(self): hi = self.unpack_uint() lo = self.unpack_uint() - return long(hi)<<32 | lo + return int(hi)<<32 | lo def unpack_hyper(self): x = self.unpack_uhyper() - if x >= 0x8000000000000000L: x = x - 0x10000000000000000L + if x >= 0x8000000000000000: x = x - 0x10000000000000000 return x def unpack_float(self): @@ -162,7 +162,7 @@ class Unpacker: def unpack_fstring(self, n): if n < 0: - raise ValueError, 'fstring size must be nonnegative' + raise ValueError('fstring size must be nonnegative') i = self.pos j = i + (n+3)/4*4 if j > len(self.buf): @@ -184,7 +184,7 @@ class Unpacker: x = self.unpack_uint() if x == 0: break if x != 1: - raise RuntimeError, '0 or 1 expected, got %r' % (x, ) + raise RuntimeError('0 or 1 expected, got %r' % (x, )) item = unpack_item() list.append(item) return list |