diff options
Diffstat (limited to 'Demo/pdist')
-rwxr-xr-x | Demo/pdist/FSProxy.py | 18 | ||||
-rwxr-xr-x | Demo/pdist/RCSProxy.py | 12 | ||||
-rwxr-xr-x | Demo/pdist/client.py | 26 | ||||
-rwxr-xr-x | Demo/pdist/cmdfw.py | 30 | ||||
-rwxr-xr-x | Demo/pdist/cmptree.py | 86 | ||||
-rwxr-xr-x | Demo/pdist/cvslib.py | 40 | ||||
-rwxr-xr-x | Demo/pdist/cvslock.py | 32 | ||||
-rwxr-xr-x | Demo/pdist/mac.py | 2 | ||||
-rwxr-xr-x | Demo/pdist/makechangelog.py | 16 | ||||
-rwxr-xr-x | Demo/pdist/rcslib.py | 18 | ||||
-rwxr-xr-x | Demo/pdist/rcvs.py | 70 | ||||
-rwxr-xr-x | Demo/pdist/rrcs.py | 58 | ||||
-rwxr-xr-x | Demo/pdist/security.py | 8 | ||||
-rwxr-xr-x | Demo/pdist/server.py | 30 | ||||
-rwxr-xr-x | Demo/pdist/sumtree.py | 4 |
15 files changed, 225 insertions, 225 deletions
diff --git a/Demo/pdist/FSProxy.py b/Demo/pdist/FSProxy.py index dad4015..510ac76 100755 --- a/Demo/pdist/FSProxy.py +++ b/Demo/pdist/FSProxy.py @@ -88,7 +88,7 @@ class FSProxyLocal: c, t = fs.GetCreatorType() if t != 'TEXT': return 0 except macfs.error as msg: - print "***", name, msg + print("***", name, msg) return 0 else: if os.path.islink(name): return 0 @@ -99,12 +99,12 @@ class FSProxyLocal: def check(self, name): if not self.visible(name): - raise os.error, "protected name %s" % repr(name) + raise os.error("protected name %s" % repr(name)) def checkfile(self, name): self.check(name) if not os.path.isfile(name): - raise os.error, "not a plain file %s" % repr(name) + raise os.error("not a plain file %s" % repr(name)) def pwd(self): return os.getcwd() @@ -118,7 +118,7 @@ class FSProxyLocal: def back(self): if not self._dirstack: - raise os.error, "empty directory stack" + raise os.error("empty directory stack") dir, ignore = self._dirstack[-1] os.chdir(dir) del self._dirstack[-1] @@ -128,8 +128,8 @@ class FSProxyLocal: if pat: def keep(name, pat = pat): return fnmatch.fnmatch(name, pat) - files = filter(keep, files) - files = filter(self.visible, files) + files = list(filter(keep, files)) + files = list(filter(self.visible, files)) files.sort() return files @@ -139,12 +139,12 @@ class FSProxyLocal: def listfiles(self, pat = None): files = os.listdir(os.curdir) - files = filter(os.path.isfile, files) + files = list(filter(os.path.isfile, files)) return self._filter(files, pat) def listsubdirs(self, pat = None): files = os.listdir(os.curdir) - files = filter(os.path.isdir, files) + files = list(filter(os.path.isdir, files)) return self._filter(files, pat) def exists(self, name): @@ -278,7 +278,7 @@ class FSProxyLocal: def mkdir(self, name): self.check(name) - os.mkdir(name, 0777) + os.mkdir(name, 0o777) def rmdir(self, name): self.check(name) diff --git a/Demo/pdist/RCSProxy.py b/Demo/pdist/RCSProxy.py index 6732308..7c3b24f 100755 --- a/Demo/pdist/RCSProxy.py +++ b/Demo/pdist/RCSProxy.py @@ -50,21 +50,21 @@ class DirSupport: def back(self): if not self._dirstack: - raise os.error, "empty directory stack" + raise os.error("empty directory stack") dir = self._dirstack[-1] os.chdir(dir) del self._dirstack[-1] def listsubdirs(self, pat = None): files = os.listdir(os.curdir) - files = filter(os.path.isdir, files) + files = list(filter(os.path.isdir, files)) return self._filter(files, pat) def isdir(self, name): return os.path.isdir(name) def mkdir(self, name): - os.mkdir(name, 0777) + os.mkdir(name, 0o777) def rmdir(self, name): os.rmdir(name) @@ -186,11 +186,11 @@ def test(): if hasattr(proxy, what): attr = getattr(proxy, what) if hasattr(attr, '__call__'): - print attr(*sys.argv[2:]) + print(attr(*sys.argv[2:])) else: - print repr(attr) + print(repr(attr)) else: - print "%s: no such attribute" % what + print("%s: no such attribute" % what) sys.exit(2) diff --git a/Demo/pdist/client.py b/Demo/pdist/client.py index 664c41b..13158f2 100755 --- a/Demo/pdist/client.py +++ b/Demo/pdist/client.py @@ -24,10 +24,10 @@ class Client: address = ('', address) self._address = address self._verbose = verbose - if self._verbose: print "Connecting to %s ..." % repr(address) + if self._verbose: print("Connecting to %s ..." % repr(address)) self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.connect(address) - if self._verbose: print "Connected." + if self._verbose: print("Connected.") self._lastid = 0 # Last id for which a reply has been received self._nextid = 1 # Id of next request self._replies = {} # Unprocessed replies @@ -53,7 +53,7 @@ class Client: method = _stub(self, name) setattr(self, name, method) # XXX circular reference return method - raise AttributeError, name + raise AttributeError(name) def _setverbose(self, verbose): self._verbose = verbose @@ -78,7 +78,7 @@ class Client: self._nextid = id+1 if not wantreply: id = -id request = (name, args, id) - if self._verbose > 1: print "sending request: %s" % repr(request) + if self._verbose > 1: print("sending request: %s" % repr(request)) wp = pickle.Pickler(self._wf) wp.dump(request) return id @@ -86,7 +86,7 @@ class Client: def _recv(self, id): exception, value, rid = self._vrecv(id) if rid != id: - raise RuntimeError, "request/reply id mismatch: %d/%d" % (id, rid) + raise RuntimeError("request/reply id mismatch: %d/%d" % (id, rid)) if exception is None: return value x = exception @@ -96,30 +96,30 @@ class Client: x = os.error if x == exception: exception = x - raise exception, value + raise exception(value) def _vrecv(self, id): self._flush() - if self._replies.has_key(id): - if self._verbose > 1: print "retrieving previous reply, id = %d" % id + if id in self._replies: + if self._verbose > 1: print("retrieving previous reply, id = %d" % id) reply = self._replies[id] del self._replies[id] return reply aid = abs(id) while 1: - if self._verbose > 1: print "waiting for reply, id = %d" % id + if self._verbose > 1: print("waiting for reply, id = %d" % id) rp = pickle.Unpickler(self._rf) reply = rp.load() del rp - if self._verbose > 1: print "got reply: %s" % repr(reply) + if self._verbose > 1: print("got reply: %s" % repr(reply)) rid = reply[2] arid = abs(rid) if arid == aid: - if self._verbose > 1: print "got it" + if self._verbose > 1: print("got it") return reply self._replies[rid] = reply if arid > aid: - if self._verbose > 1: print "got higher id, assume all ok" + if self._verbose > 1: print("got higher id, assume all ok") return (None, None, id) def _flush(self): @@ -138,7 +138,7 @@ class SecureClient(Client, Security): line = self._rf.readline() challenge = int(line.strip()) response = self._encode_challenge(challenge) - line = repr(long(response)) + line = repr(int(response)) if line[-1] in 'Ll': line = line[:-1] self._wf.write(line + '\n') self._wf.flush() diff --git a/Demo/pdist/cmdfw.py b/Demo/pdist/cmdfw.py index 47d13bc..7bcb461 100755 --- a/Demo/pdist/cmdfw.py +++ b/Demo/pdist/cmdfw.py @@ -72,11 +72,11 @@ class CommandFrameWork: """Process the options retrieved by getopt. Override this if you have any options.""" if opts: - print "-"*40 - print "Options:" + print("-"*40) + print("Options:") for o, a in opts: - print 'option', o, 'value', repr(a) - print "-"*40 + print('option', o, 'value', repr(a)) + print("-"*40) def ready(self): """Called just before calling the subcommand.""" @@ -84,14 +84,14 @@ class CommandFrameWork: def usage(self, msg = None): """Print usage message. Return suitable exit code (2).""" - if msg: print msg - print self.UsageMessage % {'name': self.__class__.__name__} + if msg: print(msg) + print(self.UsageMessage % {'name': self.__class__.__name__}) docstrings = {} c = self.__class__ while 1: for name in dir(c): if name[:3] == 'do_': - if docstrings.has_key(name): + if name in docstrings: continue try: doc = getattr(c, name).__doc__ @@ -103,19 +103,19 @@ class CommandFrameWork: break c = c.__bases__[0] if docstrings: - print "where subcommand can be:" - names = docstrings.keys() + print("where subcommand can be:") + names = list(docstrings.keys()) names.sort() for name in names: - print docstrings[name] + print(docstrings[name]) if self.PostUsageMessage: - print self.PostUsageMessage + print(self.PostUsageMessage) return 2 def default(self): """Default method, called when no subcommand is given. You should always override this.""" - print "Nobody expects the Spanish Inquisition!" + print("Nobody expects the Spanish Inquisition!") def test(): @@ -124,7 +124,7 @@ def test(): class Hello(CommandFrameWork): def do_hello(self, opts, args): "hello -- print 'hello world', needs no arguments" - print "Hello, world" + print("Hello, world") x = Hello() tests = [ [], @@ -135,9 +135,9 @@ def test(): None, ] for t in tests: - print '-'*10, t, '-'*10 + print('-'*10, t, '-'*10) sts = x.run(t) - print "Exit status:", repr(sts) + print("Exit status:", repr(sts)) if __name__ == '__main__': diff --git a/Demo/pdist/cmptree.py b/Demo/pdist/cmptree.py index 5031869..d6962e9 100755 --- a/Demo/pdist/cmptree.py +++ b/Demo/pdist/cmptree.py @@ -13,7 +13,7 @@ def raw_input(prompt): def main(): pwd = os.getcwd() - s = raw_input("chdir [%s] " % pwd) + s = input("chdir [%s] " % pwd) if s: os.chdir(s) pwd = os.getcwd() @@ -21,14 +21,14 @@ def main(): port = 4127 verbose = 1 mode = '' - print """\ + print("""\ Mode should be a string of characters, indicating what to do with differences. r - read different files to local file system w - write different files to remote file system c - create new files, either remote or local d - delete disappearing files, either remote or local -""" - s = raw_input("mode [%s] " % mode) +""") + s = input("mode [%s] " % mode) if s: mode = s address = (host, port) t1 = time.time() @@ -40,74 +40,74 @@ d - delete disappearing files, either remote or local t2 = time.time() dt = t2-t1 mins, secs = divmod(dt, 60) - print mins, "minutes and", round(secs), "seconds" - raw_input("[Return to exit] ") + print(mins, "minutes and", round(secs), "seconds") + input("[Return to exit] ") def ask(prompt, default): - s = raw_input("%s [%s] " % (prompt, default)) + s = input("%s [%s] " % (prompt, default)) return s or default def askint(prompt, default): - s = raw_input("%s [%s] " % (prompt, str(default))) + s = input("%s [%s] " % (prompt, str(default))) if s: return string.atoi(s) return default def compare(local, remote, mode): - print - print "PWD =", repr(os.getcwd()) + print() + print("PWD =", repr(os.getcwd())) sums_id = remote._send('sumlist') subdirs_id = remote._send('listsubdirs') remote._flush() - print "calculating local sums ..." + print("calculating local sums ...") lsumdict = {} for name, info in local.sumlist(): lsumdict[name] = info - print "getting remote sums ..." + print("getting remote sums ...") sums = remote._recv(sums_id) - print "got", len(sums) + print("got", len(sums)) rsumdict = {} for name, rsum in sums: rsumdict[name] = rsum - if not lsumdict.has_key(name): - print repr(name), "only remote" + if name not in lsumdict: + print(repr(name), "only remote") if 'r' in mode and 'c' in mode: recvfile(local, remote, name) else: lsum = lsumdict[name] if lsum != rsum: - print repr(name), + print(repr(name), end=' ') rmtime = remote.mtime(name) lmtime = local.mtime(name) if rmtime > lmtime: - print "remote newer", + print("remote newer", end=' ') if 'r' in mode: recvfile(local, remote, name) elif lmtime > rmtime: - print "local newer", + print("local newer", end=' ') if 'w' in mode: sendfile(local, remote, name) else: - print "same mtime but different sum?!?!", - print - for name in lsumdict.keys(): - if not rsumdict.keys(): - print repr(name), "only locally", + print("same mtime but different sum?!?!", end=' ') + print() + for name in list(lsumdict.keys()): + if not list(rsumdict.keys()): + print(repr(name), "only locally", end=' ') fl() if 'w' in mode and 'c' in mode: sendfile(local, remote, name) elif 'r' in mode and 'd' in mode: os.unlink(name) - print "removed." - print - print "gettin subdirs ..." + print("removed.") + print() + print("gettin subdirs ...") subdirs = remote._recv(subdirs_id) common = [] for name in subdirs: if local.isdir(name): - print "Common subdirectory", repr(name) + print("Common subdirectory", repr(name)) common.append(name) else: - print "Remote subdirectory", repr(name), "not found locally" + print("Remote subdirectory", repr(name), "not found locally") if 'r' in mode and 'c' in mode: pr = "Create local subdirectory %s? [y] " % \ repr(name) @@ -117,15 +117,15 @@ def compare(local, remote, mode): ok = ask(pr, "y") if ok[:1] in ('y', 'Y'): local.mkdir(name) - print "Subdirectory %s made" % \ - repr(name) + print("Subdirectory %s made" % \ + repr(name)) common.append(name) lsubdirs = local.listsubdirs() for name in lsubdirs: if name not in subdirs: - print "Local subdirectory", repr(name), "not found remotely" + print("Local subdirectory", repr(name), "not found remotely") for name in common: - print "Entering subdirectory", repr(name) + print("Entering subdirectory", repr(name)) local.cd(name) remote.cd(name) compare(local, remote, mode) @@ -136,10 +136,10 @@ def sendfile(local, remote, name): try: remote.create(name) except (IOError, os.error) as msg: - print "cannot create:", msg + print("cannot create:", msg) return - print "sending ...", + print("sending ...", end=' ') fl() data = open(name).read() @@ -152,10 +152,10 @@ def sendfile(local, remote, name): t2 = time.time() dt = t2-t1 - print len(data), "bytes in", round(dt), "seconds", + print(len(data), "bytes in", round(dt), "seconds", end=' ') if dt: - print "i.e.", round(len(data)/dt), "bytes/sec", - print + print("i.e.", round(len(data)/dt), "bytes/sec", end=' ') + print() def recvfile(local, remote, name): ok = 0 @@ -165,17 +165,17 @@ def recvfile(local, remote, name): return rv finally: if not ok: - print "*** recvfile of %r failed, deleting" % (name,) + print("*** recvfile of %r failed, deleting" % (name,)) local.delete(name) def recvfile_real(local, remote, name): try: local.create(name) except (IOError, os.error) as msg: - print "cannot create:", msg + print("cannot create:", msg) return - print "receiving ...", + print("receiving ...", end=' ') fl() f = open(name, 'w') @@ -200,10 +200,10 @@ def recvfile_real(local, remote, name): f.close() dt = t2-t1 - print size, "bytes in", round(dt), "seconds", + print(size, "bytes in", round(dt), "seconds", end=' ') if dt: - print "i.e.", int(size/dt), "bytes/sec", - print + print("i.e.", int(size/dt), "bytes/sec", end=' ') + print() remote._recv(id) # ignored def fl(): diff --git a/Demo/pdist/cvslib.py b/Demo/pdist/cvslib.py index ebcc697..8ccb616 100755 --- a/Demo/pdist/cvslib.py +++ b/Demo/pdist/cvslib.py @@ -56,7 +56,7 @@ class File: def __init__(self, file = None): if file and '/' in file: - raise ValueError, "no slash allowed in file" + raise ValueError("no slash allowed in file") self.file = file self.lseen = self.eseen = self.rseen = 0 self.proxy = None @@ -76,7 +76,7 @@ class File: def getentry(self, line): words = string.splitfields(line, '/') if self.file and words[1] != self.file: - raise ValueError, "file name mismatch" + raise ValueError("file name mismatch") self.file = words[1] self.erev = words[2] self.edeleted = 0 @@ -146,13 +146,13 @@ class File: self.extra) def report(self): - print '-'*50 + print('-'*50) def r(key, repr=repr, self=self): try: value = repr(getattr(self, key)) except AttributeError: value = "?" - print "%-15s:" % key, value + print("%-15s:" % key, value) r("file") if self.lseen: r("lsum", hexify) @@ -200,7 +200,7 @@ class CVS: if proxy is self.proxy: return self.proxy = proxy - for e in self.entries.values(): + for e in list(self.entries.values()): e.rseen = 0 def getentries(self): @@ -218,12 +218,12 @@ class CVS: def putentries(self): """Write CVS/Entries back""" f = self.cvsopen("Entries", 'w') - for e in self.values(): + for e in list(self.values()): f.write(e.putentry()) f.close() def getlocalfiles(self): - list = self.entries.keys() + list = list(self.entries.keys()) addlist = os.listdir(os.curdir) for name in addlist: if name in list: @@ -242,7 +242,7 @@ class CVS: if proxy: self.proxy = proxy if not self.proxy: - raise RuntimeError, "no RCS proxy" + raise RuntimeError("no RCS proxy") addlist = self.proxy.listfiles() for file in addlist: try: @@ -252,24 +252,24 @@ class CVS: e.getremote(self.proxy) def report(self): - for e in self.values(): + for e in list(self.values()): e.report() - print '-'*50 + print('-'*50) def keys(self): - keys = self.entries.keys() + keys = list(self.entries.keys()) keys.sort() return keys def values(self): def value(key, self=self): return self.entries[key] - return map(value, self.keys()) + return list(map(value, list(self.keys()))) def items(self): def item(key, self=self): return (key, self.entries[key]) - return map(item, self.keys()) + return list(map(item, list(self.keys()))) def cvsexists(self, file): file = os.path.join("CVS", file) @@ -328,7 +328,7 @@ def unctime(date): year = string.atoi(words[4]) month = unctime_monthmap[words[1]] day = string.atoi(words[2]) - [hh, mm, ss] = map(string.atoi, string.splitfields(words[3], ':')) + [hh, mm, ss] = list(map(string.atoi, string.splitfields(words[3], ':'))) ss = ss - time.timezone return time.mktime((year, month, day, hh, mm, ss, 0, 0, 0)) @@ -340,14 +340,14 @@ def test_unctime(): now = int(time.time()) t = time.gmtime(now) at = time.asctime(t) - print 'GMT', now, at - print 'timezone', time.timezone - print 'local', time.ctime(now) + print('GMT', now, at) + print('timezone', time.timezone) + print('local', time.ctime(now)) u = unctime(at) - print 'unctime()', u + print('unctime()', u) gu = time.gmtime(u) - print '->', gu - print time.asctime(gu) + print('->', gu) + print(time.asctime(gu)) def test(): x = CVS() diff --git a/Demo/pdist/cvslock.py b/Demo/pdist/cvslock.py index c93c3f6..a48c702 100755 --- a/Demo/pdist/cvslock.py +++ b/Demo/pdist/cvslock.py @@ -120,14 +120,14 @@ class Lock: self.cvswfl = self.join(CVSWFL + pid) def __del__(self): - print "__del__" + print("__del__") self.unlock() def setlockdir(self): while 1: try: self.lockdir = self.cvslck - os.mkdir(self.cvslck, 0777) + os.mkdir(self.cvslck, 0o777) return except os.error as msg: self.lockdir = None @@ -147,7 +147,7 @@ class Lock: def unlockfile(self): if self.lockfile: - print "unlink", self.lockfile + print("unlink", self.lockfile) try: os.unlink(self.lockfile) except os.error: @@ -156,7 +156,7 @@ class Lock: def unlockdir(self): if self.lockdir: - print "rmdir", self.lockdir + print("rmdir", self.lockdir) try: os.rmdir(self.lockdir) except os.error: @@ -179,8 +179,8 @@ def sleep(st, repository, delay): user = pwent[0] except KeyError: user = "uid %d" % uid - print "[%s]" % time.ctime(time.time())[11:19], - print "Waiting for %s's lock in" % user, repository + print("[%s]" % time.ctime(time.time())[11:19], end=' ') + print("Waiting for %s's lock in" % user, repository) time.sleep(delay) @@ -252,27 +252,27 @@ def test(): rl = None wl = None try: - print "attempting write lock ..." + print("attempting write lock ...") wl = WriteLock(repository) - print "got it." + print("got it.") wl.unlock() - print "attempting read lock ..." + print("attempting read lock ...") rl = ReadLock(repository) - print "got it." + print("got it.") rl.unlock() finally: - print [1] - print [2] + print([1]) + print([2]) if rl: rl.unlock() - print [3] + print([3]) if wl: wl.unlock() - print [4] + print([4]) rl = None - print [5] + print([5]) wl = None - print [6] + print([6]) if __name__ == '__main__': diff --git a/Demo/pdist/mac.py b/Demo/pdist/mac.py index 61cff09..beb77ec 100755 --- a/Demo/pdist/mac.py +++ b/Demo/pdist/mac.py @@ -9,7 +9,7 @@ def raw_input(prompt): def main(): while 1: try: - line = raw_input('$ ') + line = input('$ ') except EOFError: break words = line.split() diff --git a/Demo/pdist/makechangelog.py b/Demo/pdist/makechangelog.py index 1ffa588..db66e8f 100755 --- a/Demo/pdist/makechangelog.py +++ b/Demo/pdist/makechangelog.py @@ -50,25 +50,25 @@ def formatrev(rev, prefix): if parsedateprog.match(dateline) >= 0: fields = parsedateprog.group(1, 2, 3, 4, 5, 6) author = parsedateprog.group(7) - if authormap.has_key(author): author = authormap[author] - tfields = map(string.atoi, fields) + [0, 0, 0] + if author in authormap: author = authormap[author] + tfields = list(map(string.atoi, fields)) + [0, 0, 0] tfields[5] = tfields[5] - time.timezone t = time.mktime(tuple(tfields)) - print time.ctime(t), '', author + print(time.ctime(t), '', author) words = string.split(log) words[:0] = ['*', prefix + file + ':'] maxcol = 72-8 col = maxcol for word in words: if col > 0 and col + len(word) >= maxcol: - print - print '\t' + word, + print() + print('\t' + word, end=' ') col = -1 else: - print word, + print(word, end=' ') col = col + 1 + len(word) - print - print + print() + print() startprog = re.compile("^Working file: (.*)$") diff --git a/Demo/pdist/rcslib.py b/Demo/pdist/rcslib.py index 3e63869..9690f3b 100755 --- a/Demo/pdist/rcslib.py +++ b/Demo/pdist/rcslib.py @@ -90,7 +90,7 @@ class RCS: dict[key] = value status = self._closepipe(f) if status: - raise IOError, status + raise IOError(status) return dict # --- Methods that change files --- @@ -160,12 +160,12 @@ class RCS: def listfiles(self, pat = None): """Return a list of all version files matching optional PATTERN.""" files = os.listdir(os.curdir) - files = filter(self._isrcs, files) + files = list(filter(self._isrcs, files)) if os.path.isdir('RCS'): files2 = os.listdir('RCS') - files2 = filter(self._isrcs, files2) + files2 = list(filter(self._isrcs, files2)) files = files + files2 - files = map(self.realname, files) + files = list(map(self.realname, files)) return self._filter(files, pat) def isvalid(self, name): @@ -218,7 +218,7 @@ class RCS: line = f.readline() status = self._closepipe(f) if status: - raise IOError, status + raise IOError(status) if not line: return None if line[-1] == '\n': line = line[:-1] @@ -232,7 +232,7 @@ class RCS: """ name, rev = self._unmangle(name_rev) if not self.isvalid(name): - raise os.error, 'not an rcs file %r' % (name,) + raise os.error('not an rcs file %r' % (name,)) return name, rev # --- Internal methods --- @@ -269,7 +269,7 @@ class RCS: name, rev = name_rev for c in rev: if c not in self.okchars: - raise ValueError, "bad char in rev" + raise ValueError("bad char in rev") return name_rev def _closepipe(self, f): @@ -304,7 +304,7 @@ class RCS: """ cmd = cmd + " </dev/null" sts = os.system(cmd) - if sts: raise IOError, "command exit status %d" % sts + if sts: raise IOError("command exit status %d" % sts) def _filter(self, files, pat = None): """INTERNAL: Return a sorted copy of the given list of FILES. @@ -316,7 +316,7 @@ class RCS: if pat: def keep(name, pat = pat): return fnmatch.fnmatch(name, pat) - files = filter(keep, files) + files = list(filter(keep, files)) else: files = files[:] files.sort() diff --git a/Demo/pdist/rcvs.py b/Demo/pdist/rcvs.py index ab1fd87..4e2532a 100755 --- a/Demo/pdist/rcvs.py +++ b/Demo/pdist/rcvs.py @@ -90,9 +90,9 @@ class MyFile(File): else: return 'r' # Get rid of entry else: # not self.edeleted if self.rsum: - print "warning:", - print self.file, - print "was lost" + print("warning:", end=' ') + print(self.file, end=' ') + print("was lost") return 'U' else: return 'r' # Get rid of entry else: # self.lsum @@ -120,12 +120,12 @@ class MyFile(File): def update(self): code = self.action() if code == '=': return - print code, self.file + print(code, self.file) if code in ('U', 'N'): self.get() elif code == 'C': - print "%s: conflict resolution not yet implemented" % \ - self.file + print("%s: conflict resolution not yet implemented" % \ + self.file) elif code == 'D': remove(self.file) self.eseen = 0 @@ -146,11 +146,11 @@ class MyFile(File): self.put(message) return 1 elif code == 'R': - print "%s: committing removes not yet implemented" % \ - self.file + print("%s: committing removes not yet implemented" % \ + self.file) elif code == 'C': - print "%s: conflict resolution not yet implemented" % \ - self.file + print("%s: conflict resolution not yet implemented" % \ + self.file) def diff(self, opts = []): self.action() # To update lseen, rseen @@ -174,22 +174,22 @@ class MyFile(File): tf = tempfile.NamedTemporaryFile() tf.write(data) tf.flush() - print 'diff %s -r%s %s' % (flags, rev, fn) + print('diff %s -r%s %s' % (flags, rev, fn)) sts = os.system('diff %s %s %s' % (flags, tf.name, fn)) if sts: - print '='*70 + print('='*70) def commitcheck(self): return self.action() != 'C' def put(self, message = ""): - print "Checking in", self.file, "..." + print("Checking in", self.file, "...") data = open(self.file).read() if not self.enew: self.proxy.lock(self.file) messages = self.proxy.put(self.file, data, message) if messages: - print messages + print(messages) self.setentry(self.proxy.head(self.file), self.lsum) def get(self): @@ -200,7 +200,7 @@ class MyFile(File): self.setentry(self.rrev, self.rsum) def log(self, otherflags): - print self.proxy.log(self.file, otherflags) + print(self.proxy.log(self.file, otherflags)) def add(self): self.eseen = 0 # While we're hacking... @@ -256,10 +256,10 @@ class RCVS(CVS): if not e.commitcheck(): ok = 0 if not ok: - print "correct above errors first" + print("correct above errors first") return if not message: - message = raw_input("One-liner: ") + message = input("One-liner: ") committed = [] for e in list: if e.commit(message): @@ -270,20 +270,20 @@ class RCVS(CVS): towhom = "sjoerd@cwi.nl, jack@cwi.nl" # XXX mailtext = MAILFORM % (towhom, ' '.join(files), ' '.join(files), message) - print '-'*70 - print mailtext - print '-'*70 - ok = raw_input("OK to mail to %s? " % towhom) + print('-'*70) + print(mailtext) + print('-'*70) + ok = input("OK to mail to %s? " % towhom) if ok.lower().strip() in ('y', 'ye', 'yes'): p = os.popen(SENDMAIL, "w") p.write(mailtext) sts = p.close() if sts: - print "Sendmail exit status %s" % str(sts) + print("Sendmail exit status %s" % str(sts)) else: - print "Mail sent." + print("Mail sent.") else: - print "No mail sent." + print("No mail sent.") def report(self, files): for e in self.whichentries(files): @@ -295,15 +295,15 @@ class RCVS(CVS): def add(self, files): if not files: - raise RuntimeError, "'cvs add' needs at least one file" + raise RuntimeError("'cvs add' needs at least one file") list = [] for e in self.whichentries(files, 1): e.add() def rm(self, files): if not files: - raise RuntimeError, "'cvs rm' needs at least one file" - raise RuntimeError, "'cvs rm' not yet imlemented" + raise RuntimeError("'cvs rm' needs at least one file") + raise RuntimeError("'cvs rm' not yet imlemented") def log(self, files, opts): flags = '' @@ -316,23 +316,23 @@ class RCVS(CVS): if files: list = [] for file in files: - if self.entries.has_key(file): + if file in self.entries: e = self.entries[file] else: e = self.FileClass(file) self.entries[file] = e list.append(e) else: - list = self.entries.values() + list = list(self.entries.values()) for file in self.proxy.listfiles(): - if self.entries.has_key(file): + if file in self.entries: continue e = self.FileClass(file) self.entries[file] = e list.append(e) if localfilestoo: for file in os.listdir(os.curdir): - if not self.entries.has_key(file) \ + if file not in self.entries \ and not self.ignored(file): e = self.FileClass(file) self.entries[file] = e @@ -376,7 +376,7 @@ class rcvs(CommandFrameWork): continue if os.path.islink(name): continue - print "--- entering subdirectory", name, "---" + print("--- entering subdirectory", name, "---") os.chdir(name) try: if os.path.isdir("CVS"): @@ -385,7 +385,7 @@ class rcvs(CommandFrameWork): self.recurse() finally: os.chdir(os.pardir) - print "--- left subdirectory", name, "---" + print("--- left subdirectory", name, "---") def options(self, opts): self.opts = opts @@ -437,7 +437,7 @@ class rcvs(CommandFrameWork): def do_add(self, opts, files): """add file ...""" if not files: - print "'rcvs add' requires at least one file" + print("'rcvs add' requires at least one file") return self.cvs.add(files) self.cvs.putentries() @@ -445,7 +445,7 @@ class rcvs(CommandFrameWork): def do_remove(self, opts, files): """remove file ...""" if not files: - print "'rcvs remove' requires at least one file" + print("'rcvs remove' requires at least one file") return self.cvs.remove(files) self.cvs.putentries() diff --git a/Demo/pdist/rrcs.py b/Demo/pdist/rrcs.py index 540d296..8d0ef03 100755 --- a/Demo/pdist/rrcs.py +++ b/Demo/pdist/rrcs.py @@ -18,22 +18,22 @@ def main(): cmd = 'head' else: cmd, rest = rest[0], rest[1:] - if not commands.has_key(cmd): - raise getopt.error, "unknown command" + if cmd not in commands: + raise getopt.error("unknown command") coptset, func = commands[cmd] copts, files = getopt.getopt(rest, coptset) except getopt.error as msg: - print msg - print "usage: rrcs [options] command [options] [file] ..." - print "where command can be:" - print " ci|put # checkin the given files" - print " co|get # checkout" - print " info # print header info" - print " head # print revision of head branch" - print " list # list filename if valid" - print " log # print full log" - print " diff # diff rcs file and work file" - print "if no files are given, all remote rcs files are assumed" + print(msg) + print("usage: rrcs [options] command [options] [file] ...") + print("where command can be:") + print(" ci|put # checkin the given files") + print(" co|get # checkout") + print(" info # print header info") + print(" head # print revision of head branch") + print(" list # list filename if valid") + print(" log # print full log") + print(" diff # diff rcs file and work file") + print("if no files are given, all remote rcs files are assumed") sys.exit(2) x = openrcsclient(opts) if not files: @@ -42,7 +42,7 @@ def main(): try: func(x, copts, fn) except (IOError, os.error) as msg: - print "%s: %s" % (fn, msg) + print("%s: %s" % (fn, msg)) def checkin(x, copts, fn): f = open(fn) @@ -50,13 +50,13 @@ def checkin(x, copts, fn): f.close() new = not x.isvalid(fn) if not new and same(x, copts, fn, data): - print "%s: unchanged since last checkin" % fn + print("%s: unchanged since last checkin" % fn) return - print "Checking in", fn, "..." + print("Checking in", fn, "...") message = asklogmessage(new) messages = x.put(fn, data, message) if messages: - print messages + print(messages) def checkout(x, copts, fn): data = x.get(fn) @@ -72,19 +72,19 @@ def unlock(x, copts, fn): def info(x, copts, fn): dict = x.info(fn) - keys = dict.keys() + keys = list(dict.keys()) keys.sort() for key in keys: - print key + ':', dict[key] - print '='*70 + print(key + ':', dict[key]) + print('='*70) def head(x, copts, fn): head = x.head(fn) - print fn, head + print(fn, head) def list(x, copts, fn): if x.isvalid(fn): - print fn + print(fn) def log(x, copts, fn): flags = '' @@ -92,7 +92,7 @@ def log(x, copts, fn): flags = flags + ' ' + o + a flags = flags[1:] messages = x.log(fn, flags) - print messages + print(messages) def diff(x, copts, fn): if same(x, copts, fn): @@ -105,10 +105,10 @@ def diff(x, copts, fn): tf = tempfile.NamedTemporaryFile() tf.write(data) tf.flush() - print 'diff %s -r%s %s' % (flags, x.head(fn), fn) + print('diff %s -r%s %s' % (flags, x.head(fn), fn)) sts = os.system('diff %s %s %s' % (flags, tf.name, fn)) if sts: - print '='*70 + print('='*70) def same(x, copts, fn, data = None): if data is None: @@ -121,12 +121,12 @@ def same(x, copts, fn, data = None): def asklogmessage(new): if new: - print "enter description,", + print("enter description,", end=' ') else: - print "enter log message,", - print "terminate with single '.' or end of file:" + print("enter log message,", end=' ') + print("terminate with single '.' or end of file:") if new: - print "NOTE: This is NOT the log message!" + print("NOTE: This is NOT the log message!") message = "" while 1: sys.stderr.write(">> ") diff --git a/Demo/pdist/security.py b/Demo/pdist/security.py index b63081e..ffdbe2d 100755 --- a/Demo/pdist/security.py +++ b/Demo/pdist/security.py @@ -3,11 +3,11 @@ class Security: def __init__(self): import os env = os.environ - if env.has_key('PYTHON_KEYFILE'): + if 'PYTHON_KEYFILE' in env: keyfile = env['PYTHON_KEYFILE'] else: keyfile = '.python_keyfile' - if env.has_key('HOME'): + if 'HOME' in env: keyfile = os.path.join(env['HOME'], keyfile) if not os.path.exists(keyfile): import sys @@ -19,7 +19,7 @@ class Security: try: self._key = eval(open(keyfile).readline()) except IOError: - raise IOError, "python keyfile %s: cannot open" % keyfile + raise IOError("python keyfile %s: cannot open" % keyfile) def _generate_challenge(self): import random @@ -30,4 +30,4 @@ class Security: def _encode_challenge(self, challenge): p, m = self._key - return pow(long(challenge), p, m) + return pow(int(challenge), p, m) diff --git a/Demo/pdist/server.py b/Demo/pdist/server.py index 79afa8b..98a4741 100755 --- a/Demo/pdist/server.py +++ b/Demo/pdist/server.py @@ -43,11 +43,11 @@ class Server: self._serve() def _serve(self): - if self._verbose: print "Wait for connection ..." + if self._verbose: print("Wait for connection ...") conn, address = self._socket.accept() - if self._verbose: print "Accepted connection from %s" % repr(address) + if self._verbose: print("Accepted connection from %s" % repr(address)) if not self._verify(conn, address): - print "*** Connection from %s refused" % repr(address) + print("*** Connection from %s refused" % repr(address)) conn.close() return rf = conn.makefile('r') @@ -55,7 +55,7 @@ class Server: ok = 1 while ok: wf.flush() - if self._verbose > 1: print "Wait for next request ..." + if self._verbose > 1: print("Wait for next request ...") ok = self._dorequest(rf, wf) _valid = ['192.16.201.*', '192.16.197.*', '132.151.1.*', '129.6.64.*'] @@ -72,22 +72,22 @@ class Server: request = rp.load() except EOFError: return 0 - if self._verbose > 1: print "Got request: %s" % repr(request) + if self._verbose > 1: print("Got request: %s" % repr(request)) try: methodname, args, id = request if '.' in methodname: reply = (None, self._special(methodname, args), id) elif methodname[0] == '_': - raise NameError, "illegal method name %s" % repr(methodname) + raise NameError("illegal method name %s" % repr(methodname)) else: method = getattr(self, methodname) reply = (None, method(*args), id) except: reply = (sys.exc_info()[:2], id) if id < 0 and reply[:2] == (None, None): - if self._verbose > 1: print "Suppress reply" + if self._verbose > 1: print("Suppress reply") return 1 - if self._verbose > 1: print "Send reply: %s" % repr(reply) + if self._verbose > 1: print("Send reply: %s" % repr(reply)) wp = pickle.Pickler(wf) wp.dump(reply) return 1 @@ -97,16 +97,16 @@ class Server: if not hasattr(self, '_methods'): self._methods = tuple(self._listmethods()) return self._methods - raise NameError, "unrecognized special method name %s" % repr(methodname) + raise NameError("unrecognized special method name %s" % repr(methodname)) def _listmethods(self, cl=None): if not cl: cl = self.__class__ - names = cl.__dict__.keys() - names = filter(lambda x: x[0] != '_', names) + names = list(cl.__dict__.keys()) + names = [x for x in names if x[0] != '_'] names.sort() for base in cl.__bases__: basenames = self._listmethods(base) - basenames = filter(lambda x, names=names: x not in names, basenames) + basenames = list(filter(lambda x, names=names: x not in names, basenames)) names[len(names):] = basenames return names @@ -134,12 +134,12 @@ class SecureServer(Server, Security): response = string.atol(string.strip(response)) except string.atol_error: if self._verbose > 0: - print "Invalid response syntax", repr(response) + print("Invalid response syntax", repr(response)) return 0 if not self._compare_challenge_response(challenge, response): if self._verbose > 0: - print "Invalid response value", repr(response) + print("Invalid response value", repr(response)) return 0 if self._verbose > 1: - print "Response matches challenge. Go ahead!" + print("Response matches challenge. Go ahead!") return 1 diff --git a/Demo/pdist/sumtree.py b/Demo/pdist/sumtree.py index 68224df..92e7771 100755 --- a/Demo/pdist/sumtree.py +++ b/Demo/pdist/sumtree.py @@ -9,13 +9,13 @@ def main(): sumtree(proxy) proxy._close() t2 = time.time() - print t2-t1, "seconds" + print(t2-t1, "seconds") sys.stdout.write("[Return to exit] ") sys.stdout.flush() sys.stdin.readline() def sumtree(proxy): - print "PWD =", proxy.pwd() + print("PWD =", proxy.pwd()) files = proxy.listfiles() proxy.infolist(files) subdirs = proxy.listsubdirs() |