mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Detabbed.
This commit is contained in:
parent
058a84f36a
commit
0ae3220736
23 changed files with 7860 additions and 7846 deletions
|
@ -492,27 +492,27 @@ def compileaete(aete, resinfo, fname, output=None, basepkgname=None,
|
|||
fp.write("import %s\n" % modname)
|
||||
fp.write("\n\n_code_to_module = {\n")
|
||||
for code, modname in suitelist:
|
||||
fp.write("\t'%s' : %s,\n"%(ascii(code), modname))
|
||||
fp.write(" '%s' : %s,\n"%(ascii(code), modname))
|
||||
fp.write("}\n\n")
|
||||
fp.write("\n\n_code_to_fullname = {\n")
|
||||
for code, modname in suitelist:
|
||||
fp.write("\t'%s' : ('%s.%s', '%s'),\n"%(ascii(code), packagename, modname, modname))
|
||||
fp.write(" '%s' : ('%s.%s', '%s'),\n"%(ascii(code), packagename, modname, modname))
|
||||
fp.write("}\n\n")
|
||||
for code, modname in suitelist:
|
||||
fp.write("from %s import *\n"%modname)
|
||||
|
||||
# Generate property dicts and element dicts for all types declared in this module
|
||||
fp.write("\ndef getbaseclasses(v):\n")
|
||||
fp.write("\tif not getattr(v, '_propdict', None):\n")
|
||||
fp.write("\t\tv._propdict = {}\n")
|
||||
fp.write("\t\tv._elemdict = {}\n")
|
||||
fp.write("\t\tfor superclassname in getattr(v, '_superclassnames', []):\n")
|
||||
fp.write("\t\t\tsuperclass = eval(superclassname)\n")
|
||||
fp.write("\t\t\tgetbaseclasses(superclass)\n")
|
||||
fp.write("\t\t\tv._propdict.update(getattr(superclass, '_propdict', {}))\n")
|
||||
fp.write("\t\t\tv._elemdict.update(getattr(superclass, '_elemdict', {}))\n")
|
||||
fp.write("\t\tv._propdict.update(getattr(v, '_privpropdict', {}))\n")
|
||||
fp.write("\t\tv._elemdict.update(getattr(v, '_privelemdict', {}))\n")
|
||||
fp.write(" if not getattr(v, '_propdict', None):\n")
|
||||
fp.write(" v._propdict = {}\n")
|
||||
fp.write(" v._elemdict = {}\n")
|
||||
fp.write(" for superclassname in getattr(v, '_superclassnames', []):\n")
|
||||
fp.write(" superclass = eval(superclassname)\n")
|
||||
fp.write(" getbaseclasses(superclass)\n")
|
||||
fp.write(" v._propdict.update(getattr(superclass, '_propdict', {}))\n")
|
||||
fp.write(" v._elemdict.update(getattr(superclass, '_elemdict', {}))\n")
|
||||
fp.write(" v._propdict.update(getattr(v, '_privpropdict', {}))\n")
|
||||
fp.write(" v._elemdict.update(getattr(v, '_privelemdict', {}))\n")
|
||||
fp.write("\n")
|
||||
fp.write("import StdSuites\n")
|
||||
allprecompinfo.sort()
|
||||
|
@ -528,16 +528,16 @@ def compileaete(aete, resinfo, fname, output=None, basepkgname=None,
|
|||
fp.write("_classdeclarations = {\n")
|
||||
for codenamemapper in allprecompinfo:
|
||||
for k, v in codenamemapper.getall('class'):
|
||||
fp.write("\t%s : %s,\n" % (`k`, v))
|
||||
fp.write(" %s : %s,\n" % (`k`, v))
|
||||
fp.write("}\n")
|
||||
|
||||
if suitelist:
|
||||
fp.write("\n\nclass %s(%s_Events"%(packagename, suitelist[0][1]))
|
||||
for code, modname in suitelist[1:]:
|
||||
fp.write(",\n\t\t%s_Events"%modname)
|
||||
fp.write(",\n\t\taetools.TalkTo):\n")
|
||||
fp.write("\t_signature = %s\n\n"%`creatorsignature`)
|
||||
fp.write("\t_moduleName = '%s'\n\n"%packagename)
|
||||
fp.write(",\n %s_Events"%modname)
|
||||
fp.write(",\n aetools.TalkTo):\n")
|
||||
fp.write(" _signature = %s\n\n"%`creatorsignature`)
|
||||
fp.write(" _moduleName = '%s'\n\n"%packagename)
|
||||
fp.close()
|
||||
|
||||
class SuiteCompiler:
|
||||
|
@ -594,7 +594,7 @@ class SuiteCompiler:
|
|||
for event in events:
|
||||
self.findenumsinevent(event)
|
||||
|
||||
objc = ObjectCompiler(None, basemodule, interact=(self.edit_modnames is None),
|
||||
objc = ObjectCompiler(None, self.modname, basemodule, interact=(self.edit_modnames is None),
|
||||
verbose=self.verbose)
|
||||
for cls in classes:
|
||||
objc.compileclass(cls)
|
||||
|
@ -669,9 +669,9 @@ class SuiteCompiler:
|
|||
for event in events:
|
||||
self.compileevent(event)
|
||||
else:
|
||||
fp.write("\tpass\n\n")
|
||||
fp.write(" pass\n\n")
|
||||
|
||||
objc = ObjectCompiler(fp, basemodule, precompinfo, interact=(self.edit_modnames is None),
|
||||
objc = ObjectCompiler(fp, self.modname, basemodule, precompinfo, interact=(self.edit_modnames is None),
|
||||
verbose=self.verbose)
|
||||
for cls in classes:
|
||||
objc.compileclass(cls)
|
||||
|
@ -706,10 +706,10 @@ class SuiteCompiler:
|
|||
# generate name->keyword map
|
||||
#
|
||||
if arguments:
|
||||
fp.write("\t_argmap_%s = {\n"%funcname)
|
||||
fp.write(" _argmap_%s = {\n"%funcname)
|
||||
for a in arguments:
|
||||
fp.write("\t\t%s : %s,\n"%(`identify(a[0])`, `a[1]`))
|
||||
fp.write("\t}\n\n")
|
||||
fp.write(" %s : %s,\n"%(`identify(a[0])`, `a[1]`))
|
||||
fp.write(" }\n\n")
|
||||
|
||||
#
|
||||
# Generate function header
|
||||
|
@ -717,7 +717,7 @@ class SuiteCompiler:
|
|||
has_arg = (not is_null(accepts))
|
||||
opt_arg = (has_arg and is_optional(accepts))
|
||||
|
||||
fp.write("\tdef %s(self, "%funcname)
|
||||
fp.write(" def %s(self, "%funcname)
|
||||
if has_arg:
|
||||
if not opt_arg:
|
||||
fp.write("_object, ") # Include direct object, if it has one
|
||||
|
@ -730,40 +730,40 @@ class SuiteCompiler:
|
|||
# Generate doc string (important, since it may be the only
|
||||
# available documentation, due to our name-remaping)
|
||||
#
|
||||
fp.write('\t\t"""%s: %s\n'%(ascii(name), ascii(desc)))
|
||||
fp.write(' """%s: %s\n'%(ascii(name), ascii(desc)))
|
||||
if has_arg:
|
||||
fp.write("\t\tRequired argument: %s\n"%getdatadoc(accepts))
|
||||
fp.write(" Required argument: %s\n"%getdatadoc(accepts))
|
||||
elif opt_arg:
|
||||
fp.write("\t\tOptional argument: %s\n"%getdatadoc(accepts))
|
||||
fp.write(" Optional argument: %s\n"%getdatadoc(accepts))
|
||||
for arg in arguments:
|
||||
fp.write("\t\tKeyword argument %s: %s\n"%(identify(arg[0]),
|
||||
fp.write(" Keyword argument %s: %s\n"%(identify(arg[0]),
|
||||
getdatadoc(arg[2])))
|
||||
fp.write("\t\tKeyword argument _attributes: AppleEvent attribute dictionary\n")
|
||||
fp.write(" Keyword argument _attributes: AppleEvent attribute dictionary\n")
|
||||
if not is_null(returns):
|
||||
fp.write("\t\tReturns: %s\n"%getdatadoc(returns))
|
||||
fp.write('\t\t"""\n')
|
||||
fp.write(" Returns: %s\n"%getdatadoc(returns))
|
||||
fp.write(' """\n')
|
||||
#
|
||||
# Fiddle the args so everything ends up in 'arguments' dictionary
|
||||
#
|
||||
fp.write("\t\t_code = %s\n"% `code`)
|
||||
fp.write("\t\t_subcode = %s\n\n"% `subcode`)
|
||||
fp.write(" _code = %s\n"% `code`)
|
||||
fp.write(" _subcode = %s\n\n"% `subcode`)
|
||||
#
|
||||
# Do keyword name substitution
|
||||
#
|
||||
if arguments:
|
||||
fp.write("\t\taetools.keysubst(_arguments, self._argmap_%s)\n"%funcname)
|
||||
fp.write(" aetools.keysubst(_arguments, self._argmap_%s)\n"%funcname)
|
||||
else:
|
||||
fp.write("\t\tif _arguments: raise TypeError, 'No optional args expected'\n")
|
||||
fp.write(" if _arguments: raise TypeError, 'No optional args expected'\n")
|
||||
#
|
||||
# Stuff required arg (if there is one) into arguments
|
||||
#
|
||||
if has_arg:
|
||||
fp.write("\t\t_arguments['----'] = _object\n")
|
||||
fp.write(" _arguments['----'] = _object\n")
|
||||
elif opt_arg:
|
||||
fp.write("\t\tif _object:\n")
|
||||
fp.write("\t\t\t_arguments['----'] = _object\n")
|
||||
fp.write(" if _object:\n")
|
||||
fp.write(" _arguments['----'] = _object\n")
|
||||
else:
|
||||
fp.write("\t\tif _no_object != None: raise TypeError, 'No direct arg expected'\n")
|
||||
fp.write(" if _no_object != None: raise TypeError, 'No direct arg expected'\n")
|
||||
fp.write("\n")
|
||||
#
|
||||
# Do enum-name substitution
|
||||
|
@ -773,28 +773,28 @@ class SuiteCompiler:
|
|||
kname = a[1]
|
||||
ename = a[2][0]
|
||||
if ename <> '****':
|
||||
fp.write("\t\taetools.enumsubst(_arguments, %s, _Enum_%s)\n" %
|
||||
fp.write(" aetools.enumsubst(_arguments, %s, _Enum_%s)\n" %
|
||||
(`kname`, identify(ename)))
|
||||
self.enumsneeded[ename] = 1
|
||||
fp.write("\n")
|
||||
#
|
||||
# Do the transaction
|
||||
#
|
||||
fp.write("\t\t_reply, _arguments, _attributes = self.send(_code, _subcode,\n")
|
||||
fp.write("\t\t\t\t_arguments, _attributes)\n")
|
||||
fp.write(" _reply, _arguments, _attributes = self.send(_code, _subcode,\n")
|
||||
fp.write(" _arguments, _attributes)\n")
|
||||
#
|
||||
# Error handling
|
||||
#
|
||||
fp.write("\t\tif _arguments.get('errn', 0):\n")
|
||||
fp.write("\t\t\traise aetools.Error, aetools.decodeerror(_arguments)\n")
|
||||
fp.write("\t\t# XXXX Optionally decode result\n")
|
||||
fp.write(" if _arguments.get('errn', 0):\n")
|
||||
fp.write(" raise aetools.Error, aetools.decodeerror(_arguments)\n")
|
||||
fp.write(" # XXXX Optionally decode result\n")
|
||||
#
|
||||
# Decode result
|
||||
#
|
||||
fp.write("\t\tif _arguments.has_key('----'):\n")
|
||||
fp.write(" if _arguments.has_key('----'):\n")
|
||||
if is_enum(returns):
|
||||
fp.write("\t\t\t# XXXX Should do enum remapping here...\n")
|
||||
fp.write("\t\t\treturn _arguments['----']\n")
|
||||
fp.write(" # XXXX Should do enum remapping here...\n")
|
||||
fp.write(" return _arguments['----']\n")
|
||||
fp.write("\n")
|
||||
|
||||
def findenumsinevent(self, event):
|
||||
|
@ -838,8 +838,11 @@ class CodeNameMapper:
|
|||
if not self.code2name[type].has_key(code):
|
||||
self.code2name[type][code] = name
|
||||
|
||||
def hasname(self, type, name):
|
||||
return self.name2code[type].has_key(name)
|
||||
def hasname(self, name):
|
||||
for dict in self.name2code.values():
|
||||
if dict.has_key(name):
|
||||
return True
|
||||
return False
|
||||
|
||||
def hascode(self, type, code):
|
||||
return self.code2name[type].has_key(code)
|
||||
|
@ -875,12 +878,13 @@ class CodeNameMapper:
|
|||
return self
|
||||
|
||||
class ObjectCompiler:
|
||||
def __init__(self, fp, basesuite=None, othernamemappers=None, interact=1,
|
||||
def __init__(self, fp, modname, basesuite, othernamemappers=None, interact=1,
|
||||
verbose=None):
|
||||
self.fp = fp
|
||||
self.verbose = verbose
|
||||
self.basesuite = basesuite
|
||||
self.can_interact = interact
|
||||
self.modulename = modname
|
||||
self.namemappers = [CodeNameMapper(self.can_interact, self.verbose)]
|
||||
if othernamemappers:
|
||||
self.othernamemappers = othernamemappers[:]
|
||||
|
@ -925,6 +929,14 @@ class ObjectCompiler:
|
|||
mapper.addmodule(m, m.__name__, 0)
|
||||
self.namemappers.append(mapper)
|
||||
|
||||
def hasname(self, name):
|
||||
for mapper in self.othernamemappers:
|
||||
if mapper.hasname(name) and mapper.modulename != self.modulename:
|
||||
if self.verbose:
|
||||
print >>self.verbose, "Duplicate Python identifier:", name, self.modulename, mapper.modulename
|
||||
return True
|
||||
return False
|
||||
|
||||
def askdefinitionmodule(self, type, code):
|
||||
if not self.can_interact:
|
||||
if self.verbose:
|
||||
|
@ -951,8 +963,8 @@ class ObjectCompiler:
|
|||
else:
|
||||
if self.fp:
|
||||
self.fp.write('\nclass %s(aetools.ComponentItem):\n' % pname)
|
||||
self.fp.write('\t"""%s - %s """\n' % (ascii(name), ascii(desc)))
|
||||
self.fp.write('\twant = %s\n' % `code`)
|
||||
self.fp.write(' """%s - %s """\n' % (ascii(name), ascii(desc)))
|
||||
self.fp.write(' want = %s\n' % `code`)
|
||||
self.namemappers[0].addnamecode('class', pname, code)
|
||||
properties.sort()
|
||||
for prop in properties:
|
||||
|
@ -975,11 +987,13 @@ class ObjectCompiler:
|
|||
if self.fp:
|
||||
self.fp.write("\n_Prop_%s = _Prop_%s\n"%(pname, othername))
|
||||
else:
|
||||
if self.hasname(pname):
|
||||
pass
|
||||
if self.fp:
|
||||
self.fp.write("class _Prop_%s(aetools.NProperty):\n" % pname)
|
||||
self.fp.write('\t"""%s - %s """\n' % (ascii(name), ascii(what[1])))
|
||||
self.fp.write("\twhich = %s\n" % `code`)
|
||||
self.fp.write("\twant = %s\n" % `what[0]`)
|
||||
self.fp.write(' """%s - %s """\n' % (ascii(name), ascii(what[1])))
|
||||
self.fp.write(" which = %s\n" % `code`)
|
||||
self.fp.write(" want = %s\n" % `what[0]`)
|
||||
self.namemappers[0].addnamecode('property', pname, code)
|
||||
|
||||
def compileelement(self, elem):
|
||||
|
@ -1041,11 +1055,11 @@ class ObjectCompiler:
|
|||
if self.fp:
|
||||
self.fp.write("%s._privpropdict = {\n"%cname)
|
||||
for n in plist:
|
||||
self.fp.write("\t'%s' : _Prop_%s,\n"%(n, n))
|
||||
self.fp.write(" '%s' : _Prop_%s,\n"%(n, n))
|
||||
self.fp.write("}\n")
|
||||
self.fp.write("%s._privelemdict = {\n"%cname)
|
||||
for n, fulln in elist:
|
||||
self.fp.write("\t'%s' : %s,\n"%(n, fulln))
|
||||
self.fp.write(" '%s' : %s,\n"%(n, fulln))
|
||||
self.fp.write("}\n")
|
||||
|
||||
def compilecomparison(self, comp):
|
||||
|
@ -1054,7 +1068,7 @@ class ObjectCompiler:
|
|||
self.namemappers[0].addnamecode('comparison', iname, code)
|
||||
if self.fp:
|
||||
self.fp.write("class %s(aetools.NComparison):\n" % iname)
|
||||
self.fp.write('\t"""%s - %s """\n' % (ascii(name), ascii(comment)))
|
||||
self.fp.write(' """%s - %s """\n' % (ascii(name), ascii(comment)))
|
||||
|
||||
def compileenumeration(self, enum):
|
||||
[code, items] = enum
|
||||
|
@ -1069,7 +1083,7 @@ class ObjectCompiler:
|
|||
|
||||
def compileenumerator(self, item):
|
||||
[name, code, desc] = item
|
||||
self.fp.write("\t%s : %s,\t# %s\n" % (`identify(name)`, `code`, ascii(desc)))
|
||||
self.fp.write(" %s : %s,\t# %s\n" % (`identify(name)`, `code`, ascii(desc)))
|
||||
|
||||
def checkforenum(self, enum):
|
||||
"""This enum code is used by an event. Make sure it's available"""
|
||||
|
@ -1091,28 +1105,28 @@ class ObjectCompiler:
|
|||
classlist = self.namemappers[0].getall('class')
|
||||
classlist.sort()
|
||||
for k, v in classlist:
|
||||
self.fp.write("\t%s : %s,\n" % (`k`, v))
|
||||
self.fp.write(" %s : %s,\n" % (`k`, v))
|
||||
self.fp.write("}\n")
|
||||
|
||||
## self.fp.write("\n_propdeclarations = {\n")
|
||||
## proplist = self.namemappers[0].getall('property')
|
||||
## proplist.sort()
|
||||
## for k, v in proplist:
|
||||
## self.fp.write("\t%s : _Prop_%s,\n" % (`k`, v))
|
||||
## self.fp.write(" %s : _Prop_%s,\n" % (`k`, v))
|
||||
## self.fp.write("}\n")
|
||||
##
|
||||
## self.fp.write("\n_compdeclarations = {\n")
|
||||
## complist = self.namemappers[0].getall('comparison')
|
||||
## complist.sort()
|
||||
## for k, v in complist:
|
||||
## self.fp.write("\t%s : %s,\n" % (`k`, v))
|
||||
## self.fp.write(" %s : %s,\n" % (`k`, v))
|
||||
## self.fp.write("}\n")
|
||||
##
|
||||
## self.fp.write("\n_enumdeclarations = {\n")
|
||||
## enumlist = self.namemappers[0].getall('enum')
|
||||
## enumlist.sort()
|
||||
## for k, v in enumlist:
|
||||
## self.fp.write("\t%s : %s,\n" % (`k`, v))
|
||||
## self.fp.write(" %s : %s,\n" % (`k`, v))
|
||||
## self.fp.write("}\n")
|
||||
|
||||
def compiledata(data):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue