diff options
Diffstat (limited to 'Lib/irix5')
-rwxr-xr-x | Lib/irix5/cddb.py | 2 | ||||
-rwxr-xr-x | Lib/irix5/cdplayer.py | 2 | ||||
-rwxr-xr-x | Lib/irix5/flp.py | 45 | ||||
-rwxr-xr-x | Lib/irix5/readcd.py | 2 |
4 files changed, 40 insertions, 11 deletions
diff --git a/Lib/irix5/cddb.py b/Lib/irix5/cddb.py index d07a63e..fa03ed3 100755 --- a/Lib/irix5/cddb.py +++ b/Lib/irix5/cddb.py @@ -25,7 +25,7 @@ def _dbid(v): else: return _dbid_map[v] -class Cddb(): +class Cddb: def init(self, tracklist): self.artist = '' self.title = '' diff --git a/Lib/irix5/cdplayer.py b/Lib/irix5/cdplayer.py index deec996..2685a42 100755 --- a/Lib/irix5/cdplayer.py +++ b/Lib/irix5/cdplayer.py @@ -16,7 +16,7 @@ cdplayerrc = '.cdplayerrc' -class Cdplayer(): +class Cdplayer: def init(self, tracklist): import string self.artist = '' diff --git a/Lib/irix5/flp.py b/Lib/irix5/flp.py index 0904efe..ced5598 100755 --- a/Lib/irix5/flp.py +++ b/Lib/irix5/flp.py @@ -59,7 +59,11 @@ def parse_forms(filename): # Internal: see if a cached version of the file exists # MAGIC = '.fdc' +_internal_cache = {} # Used by frozen scripts only def checkcache(filename): + if _internal_cache.has_key(filename): + altforms = _internal_cache[filename] + return _unpack_cache(altforms) import marshal fp, filename = _open_formfile2(filename) fp.close() @@ -80,6 +84,11 @@ def checkcache(filename): return None #print 'flp: valid cache file', cachename altforms = marshal.load(fp) + return _unpack_cache(altforms) + finally: + fp.close() + +def _unpack_cache(altforms): forms = {} for name in altforms.keys(): altobj, altlist = altforms[name] @@ -92,8 +101,6 @@ def checkcache(filename): list.append(nobj) forms[name] = obj, list return forms - finally: - fp.close() def rdlong(fp): s = fp.read(4) @@ -128,6 +135,32 @@ def writecache(filename, forms): return # Never mind fp.write('\0\0\0\0') # Seek back and write MAGIC when done wrlong(fp, getmtime(filename)) + altforms = _pack_cache(forms) + marshal.dump(altforms, fp) + fp.seek(0) + fp.write(MAGIC) + fp.close() + #print 'flp: wrote cache file', cachename + +# +# External: print some statements that set up the internal cache. +# This is for use with the "freeze" script. You should call +# flp.freeze(filename) for all forms used by the script, and collect +# the output on a file in a module file named "frozenforms.py". Then +# in the main program of the script import frozenforms. +# (Don't forget to take this out when using the unfrozen version of +# the script!) +# +def freeze(filename): + forms = parse_forms(filename) + altforms = _pack_cache(forms) + print 'import flp' + print 'flp._internal_cache[', `filename`, '] =', altforms + +# +# Internal: create the data structure to be placed in the cache +# +def _pack_cache(forms): altforms = {} for name in forms.keys(): obj, list = forms[name] @@ -135,12 +168,8 @@ def writecache(filename, forms): altlist = [] for obj in list: altlist.append(obj.__dict__) altforms[name] = altobj, altlist - marshal.dump(altforms, fp) - fp.seek(0) - fp.write(MAGIC) - fp.close() - #print 'flp: wrote cache file', cachename - + return altforms + # # Internal: Locate form file (using PYTHONPATH) and open file # diff --git a/Lib/irix5/readcd.py b/Lib/irix5/readcd.py index 6fe21a7..23c00ed 100755 --- a/Lib/irix5/readcd.py +++ b/Lib/irix5/readcd.py @@ -21,7 +21,7 @@ def _dopnum(self, cb_type, data): if func: func(arg, cb_type, data) -class Readcd(): +class Readcd: def init(self, *arg): if len(arg) == 0: self.player = cd.open() |