diff options
author | Guido van Rossum <guido@python.org> | 1998-03-26 20:23:01 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-03-26 20:23:01 (GMT) |
commit | fa6e254b34b7a0f85cb34a9fd99b5a6400714940 (patch) | |
tree | 24ed8bb2e2ad1dde47eca4ddb52763dd25ce54a2 /Lib/plat-irix6 | |
parent | 1847d064936deb81b9ab300221a1ac7749061142 (diff) | |
download | cpython-fa6e254b34b7a0f85cb34a9fd99b5a6400714940.zip cpython-fa6e254b34b7a0f85cb34a9fd99b5a6400714940.tar.gz cpython-fa6e254b34b7a0f85cb34a9fd99b5a6400714940.tar.bz2 |
Mass check-in after untabifying all files that need it.
Diffstat (limited to 'Lib/plat-irix6')
-rw-r--r-- | Lib/plat-irix6/flp.py | 280 |
1 files changed, 140 insertions, 140 deletions
diff --git a/Lib/plat-irix6/flp.py b/Lib/plat-irix6/flp.py index f713a92..484c8ff 100644 --- a/Lib/plat-irix6/flp.py +++ b/Lib/plat-irix6/flp.py @@ -24,11 +24,11 @@ error = 'flp.error' def parse_form(filename, formname): forms = checkcache(filename) if forms is None: - forms = parse_forms(filename) + forms = parse_forms(filename) if forms.has_key(formname): - return forms[formname] + return forms[formname] else: - raise error, 'No such form in fd file' + raise error, 'No such form in fd file' # # Externally visible function. Load all forms. @@ -40,8 +40,8 @@ def parse_forms(filename): nforms = _parse_fd_header(fp) forms = {} for i in range(nforms): - form = _parse_fd_form(fp, None) - forms[form[0].Name] = form + form = _parse_fd_form(fp, None) + forms[form[0].Name] = form writecache(filename, forms) return forms @@ -49,48 +49,48 @@ def parse_forms(filename): # Internal: see if a cached version of the file exists # MAGIC = '.fdc' -_internal_cache = {} # Used by frozen scripts only +_internal_cache = {} # Used by frozen scripts only def checkcache(filename): if _internal_cache.has_key(filename): - altforms = _internal_cache[filename] - return _unpack_cache(altforms) + altforms = _internal_cache[filename] + return _unpack_cache(altforms) import marshal fp, filename = _open_formfile2(filename) fp.close() cachename = filename + 'c' try: - fp = open(cachename, 'r') + fp = open(cachename, 'r') except IOError: - #print 'flp: no cache file', cachename - return None + #print 'flp: no cache file', cachename + return None try: - if fp.read(4) != MAGIC: - print 'flp: bad magic word in cache file', cachename - return None - cache_mtime = rdlong(fp) - file_mtime = getmtime(filename) - if cache_mtime != file_mtime: - #print 'flp: outdated cache file', cachename - return None - #print 'flp: valid cache file', cachename - altforms = marshal.load(fp) - return _unpack_cache(altforms) + if fp.read(4) != MAGIC: + print 'flp: bad magic word in cache file', cachename + return None + cache_mtime = rdlong(fp) + file_mtime = getmtime(filename) + if cache_mtime != file_mtime: + #print 'flp: outdated cache file', cachename + return None + #print 'flp: valid cache file', cachename + altforms = marshal.load(fp) + return _unpack_cache(altforms) finally: - fp.close() + fp.close() def _unpack_cache(altforms): - forms = {} - for name in altforms.keys(): - altobj, altlist = altforms[name] - obj = _newobj() - obj.make(altobj) - list = [] - for altobj in altlist: - nobj = _newobj() - nobj.make(altobj) - list.append(nobj) - forms[name] = obj, list - return forms + forms = {} + for name in altforms.keys(): + altobj, altlist = altforms[name] + obj = _newobj() + obj.make(altobj) + list = [] + for altobj in altlist: + nobj = _newobj() + nobj.make(altobj) + list.append(nobj) + forms[name] = obj, list + return forms def rdlong(fp): s = fp.read(4) @@ -106,9 +106,9 @@ def getmtime(filename): import os from stat import ST_MTIME try: - return os.stat(filename)[ST_MTIME] + return os.stat(filename)[ST_MTIME] except os.error: - return None + return None # # Internal: write cached version of the form (parsing is too slow!) @@ -119,10 +119,10 @@ def writecache(filename, forms): fp.close() cachename = filename + 'c' try: - fp = open(cachename, 'w') + fp = open(cachename, 'w') except IOError: - print 'flp: can\'t create cache file', cachename - return # Never mind + print 'flp: can\'t create cache file', cachename + return # Never mind fp.write('\0\0\0\0') # Seek back and write MAGIC when done wrlong(fp, getmtime(filename)) altforms = _pack_cache(forms) @@ -153,11 +153,11 @@ def freeze(filename): def _pack_cache(forms): altforms = {} for name in forms.keys(): - obj, list = forms[name] - altobj = obj.__dict__ - altlist = [] - for obj in list: altlist.append(obj.__dict__) - altforms[name] = altobj, altlist + obj, list = forms[name] + altobj = obj.__dict__ + altlist = [] + for obj in list: altlist.append(obj.__dict__) + altforms[name] = altobj, altlist return altforms # @@ -168,23 +168,23 @@ def _open_formfile(filename): def _open_formfile2(filename): if filename[-3:] <> '.fd': - filename = filename + '.fd' + filename = filename + '.fd' if filename[0] == '/': - try: - fp = open(filename,'r') - except IOError: - fp = None + try: + fp = open(filename,'r') + except IOError: + fp = None else: - for pc in sys.path: - pn = os.path.join(pc, filename) - try: - fp = open(pn, 'r') - filename = pn - break - except IOError: - fp = None + for pc in sys.path: + pn = os.path.join(pc, filename) + try: + fp = open(pn, 'r') + filename = pn + break + except IOError: + fp = None if fp == None: - raise error, 'Cannot find forms file ' + filename + raise error, 'Cannot find forms file ' + filename return fp, filename # @@ -194,12 +194,12 @@ def _parse_fd_header(file): # First read the magic header line datum = _parse_1_line(file) if datum <> ('Magic', 12321): - raise error, 'Not a forms definition file' + raise error, 'Not a forms definition file' # Now skip until we know number of forms while 1: - datum = _parse_1_line(file) - if type(datum) == type(()) and datum[0] == 'Numberofforms': - break + datum = _parse_1_line(file) + if type(datum) == type(()) and datum[0] == 'Numberofforms': + break return datum[1] # # Internal: parse fd form, or skip if name doesn't match. @@ -208,17 +208,17 @@ def _parse_fd_header(file): def _parse_fd_form(file, name): datum = _parse_1_line(file) if datum <> FORMLINE: - raise error, 'Missing === FORM === line' + raise error, 'Missing === FORM === line' form = _parse_object(file) if form.Name == name or name == None: - objs = [] - for j in range(form.Numberofobjects): - obj = _parse_object(file) - objs.append(obj) - return (form, objs) + objs = [] + for j in range(form.Numberofobjects): + obj = _parse_object(file) + objs.append(obj) + return (form, objs) else: - for j in range(form.Numberofobjects): - _skip_object(file) + for j in range(form.Numberofobjects): + _skip_object(file) return None # @@ -226,21 +226,21 @@ def _parse_fd_form(file, name): # class _newobj: def add(self, name, value): - self.__dict__[name] = value + self.__dict__[name] = value def make(self, dict): - for name in dict.keys(): - self.add(name, dict[name]) + for name in dict.keys(): + self.add(name, dict[name]) # # Internal parsing routines. # def _parse_string(str): if '\\' in str: - s = '\'' + str + '\'' - try: - return eval(s) - except: - pass + s = '\'' + str + '\'' + try: + return eval(s) + except: + pass return str def _parse_num(str): @@ -250,19 +250,19 @@ def _parse_numlist(str): slist = string.split(str) nlist = [] for i in slist: - nlist.append(_parse_num(i)) + nlist.append(_parse_num(i)) return nlist # This dictionary maps item names to parsing routines. # If no routine is given '_parse_num' is default. _parse_func = { \ - 'Name': _parse_string, \ - 'Box': _parse_numlist, \ - 'Colors': _parse_numlist, \ - 'Label': _parse_string, \ - 'Name': _parse_string, \ - 'Callback': _parse_string, \ - 'Argument': _parse_string } + 'Name': _parse_string, \ + 'Box': _parse_numlist, \ + 'Colors': _parse_numlist, \ + 'Label': _parse_string, \ + 'Name': _parse_string, \ + 'Callback': _parse_string, \ + 'Argument': _parse_string } # This function parses a line, and returns either # a string or a tuple (name,value) @@ -273,51 +273,51 @@ prog = re.compile('^([^:]*): *(.*)') def _parse_line(line): match = prog.match(line) if not match: - return line + return line name, value = match.group(1, 2) if name[0] == 'N': - name = string.join(string.split(name),'') - name = string.lower(name) + name = string.join(string.split(name),'') + name = string.lower(name) name = string.capitalize(name) try: - pf = _parse_func[name] + pf = _parse_func[name] except KeyError: - pf = _parse_num + pf = _parse_num value = pf(value) return (name, value) def _readline(file): line = file.readline() if not line: - raise EOFError + raise EOFError return line[:-1] - + def _parse_1_line(file): line = _readline(file) while line == '': - line = _readline(file) + line = _readline(file) return _parse_line(line) def _skip_object(file): line = '' while not line in (SPLITLINE, FORMLINE, ENDLINE): - pos = file.tell() - line = _readline(file) + pos = file.tell() + line = _readline(file) if line == FORMLINE: - file.seek(pos) + file.seek(pos) def _parse_object(file): obj = _newobj() while 1: - pos = file.tell() - datum = _parse_1_line(file) - if datum in (SPLITLINE, FORMLINE, ENDLINE): - if datum == FORMLINE: - file.seek(pos) - return obj - if type(datum) <> type(()) or len(datum) <> 2: - raise error, 'Parse error, illegal line in object: '+datum - obj.add(datum[0], datum[1]) + pos = file.tell() + datum = _parse_1_line(file) + if datum in (SPLITLINE, FORMLINE, ENDLINE): + if datum == FORMLINE: + file.seek(pos) + return obj + if type(datum) <> type(()) or len(datum) <> 2: + raise error, 'Parse error, illegal line in object: '+datum + obj.add(datum[0], datum[1]) ################################################################# # Part 2 - High-level object/form creation routines # @@ -330,7 +330,7 @@ def create_full_form(inst, (fdata, odatalist)): form = create_form(fdata) exec 'inst.'+fdata.Name+' = form\n' for odata in odatalist: - create_object_instance(inst, form, odata) + create_object_instance(inst, form, odata) # # External - Merge a form into an existing form in an instance @@ -339,9 +339,9 @@ def create_full_form(inst, (fdata, odatalist)): def merge_full_form(inst, form, (fdata, odatalist)): exec 'inst.'+fdata.Name+' = form\n' if odatalist[0].Class <> FL.BOX: - raise error, 'merge_full_form() expects FL.BOX as first obj' + raise error, 'merge_full_form() expects FL.BOX as first obj' for odata in odatalist[1:]: - create_object_instance(inst, form, odata) + create_object_instance(inst, form, odata) ################################################################# @@ -362,7 +362,7 @@ def create_form(fdata): def create_object(form, odata): obj = _create_object(form, odata) if odata.Callback: - raise error, 'Creating free object with callback' + raise error, 'Creating free object with callback' return obj # # External create_object_instance - Create object in an instance. @@ -370,25 +370,25 @@ def create_object(form, odata): def create_object_instance(inst, form, odata): obj = _create_object(form, odata) if odata.Callback: - cbfunc = eval('inst.'+odata.Callback) - obj.set_call_back(cbfunc, odata.Argument) + cbfunc = eval('inst.'+odata.Callback) + obj.set_call_back(cbfunc, odata.Argument) if odata.Name: - exec 'inst.' + odata.Name + ' = obj\n' + exec 'inst.' + odata.Name + ' = obj\n' # # Internal _create_object: Create the object and fill options # def _create_object(form, odata): crfunc = _select_crfunc(form, odata.Class) obj = crfunc(odata.Type, odata.Box[0], odata.Box[1], odata.Box[2], \ - odata.Box[3], odata.Label) + odata.Box[3], odata.Label) if not odata.Class in (FL.BEGIN_GROUP, FL.END_GROUP): - obj.boxtype = odata.Boxtype - obj.col1 = odata.Colors[0] - obj.col2 = odata.Colors[1] - obj.align = odata.Alignment - obj.lstyle = odata.Style - obj.lsize = odata.Size - obj.lcol = odata.Lcol + obj.boxtype = odata.Boxtype + obj.col1 = odata.Colors[0] + obj.col2 = odata.Colors[1] + obj.align = odata.Alignment + obj.lstyle = odata.Style + obj.lsize = odata.Size + obj.lcol = odata.Lcol return obj # # Internal crfunc: helper function that returns correct create function @@ -416,35 +416,35 @@ def _select_crfunc(fm, cl): elif cl == FL.TEXT: return fm.add_text elif cl == FL.TIMER: return fm.add_timer else: - raise error, 'Unknown object type: ' + `cl` + raise error, 'Unknown object type: ' + `cl` def test(): import time t0 = time.time() if len(sys.argv) == 2: - forms = parse_forms(sys.argv[1]) - t1 = time.time() - print 'parse time:', 0.001*(t1-t0), 'sec.' - keys = forms.keys() - keys.sort() - for i in keys: - _printform(forms[i]) + forms = parse_forms(sys.argv[1]) + t1 = time.time() + print 'parse time:', 0.001*(t1-t0), 'sec.' + keys = forms.keys() + keys.sort() + for i in keys: + _printform(forms[i]) elif len(sys.argv) == 3: - form = parse_form(sys.argv[1], sys.argv[2]) - t1 = time.time() - print 'parse time:', round(t1-t0, 3), 'sec.' - _printform(form) + form = parse_form(sys.argv[1], sys.argv[2]) + t1 = time.time() + print 'parse time:', round(t1-t0, 3), 'sec.' + _printform(form) else: - print 'Usage: test fdfile [form]' + print 'Usage: test fdfile [form]' def _printform(form): f = form[0] objs = form[1] print 'Form ', f.Name, ', size: ', f.Width, f.Height, ' Nobj ', f.Numberofobjects for i in objs: - print ' Obj ', i.Name, ' type ', i.Class, i.Type - print ' Box ', i.Box, ' btype ', i.Boxtype - print ' Label ', i.Label, ' size/style/col/align ', i.Size,i.Style, i.Lcol, i.Alignment - print ' cols ', i.Colors - print ' cback ', i.Callback, i.Argument + print ' Obj ', i.Name, ' type ', i.Class, i.Type + print ' Box ', i.Box, ' btype ', i.Boxtype + print ' Label ', i.Label, ' size/style/col/align ', i.Size,i.Style, i.Lcol, i.Alignment + print ' cols ', i.Colors + print ' cback ', i.Callback, i.Argument |