From f2779197b13fdbbd0d42e48215c51d24d86ee91b Mon Sep 17 00:00:00 2001 From: Diego Roversi Date: Thu, 12 Sep 2019 21:33:58 +0200 Subject: 2to3 of display module --- display/caching.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'display/caching.py') diff --git a/display/caching.py b/display/caching.py index 27d772c..bdbfdea 100644 --- a/display/caching.py +++ b/display/caching.py @@ -1,4 +1,4 @@ -from __future__ import generators + import os, md5, sys #import common.debug @@ -18,7 +18,7 @@ class FileCache: del self.cache[filename] if filename not in self.cache: if len(self.cache) >= FileCache.MAX_FILES: - (time, mode, f), k = min([(v,k) for (k,v) in self.cache.items()]) + (time, mode, f), k = min([(v,k) for (k,v) in list(self.cache.items())]) f.close() del self.cache[k] try: @@ -54,13 +54,13 @@ class FileBlock: def overwrite(self, newdata): self.memorydata = newdata if self.readonly: - print >> sys.stderr, "cannot overwrite file", self.filename + print("cannot overwrite file", self.filename, file=sys.stderr) return try: f = Data.Cache.access(self.filename, self.position, writing=1) f.write(newdata) except (IOError, OSError): - print >> sys.stderr, "cache write error:", self.filename + print("cache write error:", self.filename, file=sys.stderr) return self.complete = 1 del self.memorydata @@ -107,7 +107,7 @@ class Data: f.write(data) f.flush() except (IOError, OSError): - print >> sys.stderr, "cache write error:", self.backupfile + print("cache write error:", self.backupfile, file=sys.stderr) def loadfrom(self, filename, position, length, checksum): """Try to load data from the given filename, with the given @@ -128,19 +128,19 @@ class Data: # correct data self.store(position, data, name, readonly) return 1 - if self.content is not None and not self.content.has_key(position): + if self.content is not None and position not in self.content: self.content[position] = FileBlock(cachename, position, length, readonly=0, complete=0) elif self.readonly: - print >> sys.stderr, "Note: the music data has changed. You can get" - print >> sys.stderr, "the server's version by deleting", directname + print("Note: the music data has changed. You can get", file=sys.stderr) + print("the server's version by deleting", directname, file=sys.stderr) return 1 # incorrect data, but ignored return 0 def read(self): """Return the data as built so far.""" if self.content is not None: - items = self.content.items() + items = list(self.content.items()) items.sort() result = '' for position, block in items: @@ -155,7 +155,7 @@ class Data: def fopen(self): if self.content is not None: - from cStringIO import StringIO + from io import StringIO return StringIO(self.read()) else: return Data.Cache.access(self.backupfile, 0) @@ -166,19 +166,19 @@ class Data: the file that we want.""" if not self.backupfile: files = {} - for position, block in self.content.items(): + for position, block in list(self.content.items()): if not isinstance(block, FileBlock): break if block.complete: files[block.filename] = block else: if len(files) == 1: - self.backupfile, block = files.items()[0] + self.backupfile, block = list(files.items())[0] self.readonly = block.readonly if not self.backupfile: self.backupfile = mktemp(fileexthint) f = Data.Cache.access(self.backupfile, 0, writing=1) - for position, block in self.content.items(): + for position, block in list(self.content.items()): f.seek(position) f.write(block.read()) f.flush() @@ -258,4 +258,4 @@ def enumtempfiles(): i += 1 def mktemp(fileext, gen = enumtempfiles()): - return gen.next() + fileext + return next(gen) + fileext -- cgit v1.2.3