Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit 'abbeyj/performance' into performance

  • Loading branch information...
commit f8c53e6fdaf28e1461456bf844c59a10e15bee68 2 parents c38cbeb + 6429c3a
@rtyler authored
Showing with 74 additions and 33 deletions.
  1. +33 −31 src/Compiler.py
  2. +38 −1 src/Parser.py
  3. +3 −1 src/Tests/Template.py
View
64 src/Compiler.py
@@ -1739,38 +1739,40 @@ def setBaseClass(self, baseClassName):
# - We also assume that the final . separates the classname from the
# module name. This might break if people do something really fancy
# with their dots and namespaces.
- chunks = baseClassName.split('.')
- if len(chunks)==1:
- self._getActiveClassCompiler().setBaseClass(baseClassName)
- if baseClassName not in self.importedVarNames():
- modName = baseClassName
- # we assume the class name to be the module name
- # and that it's not a builtin:
- importStatement = "from %s import %s" % (modName, baseClassName)
- self.addImportStatement(importStatement)
- self.addImportedVarNames( [baseClassName,] )
- else:
- needToAddImport = True
- modName = chunks[0]
- #print chunks, ':', self.importedVarNames()
- for chunk in chunks[1:-1]:
- if modName in self.importedVarNames():
- needToAddImport = False
- finalBaseClassName = baseClassName.replace(modName+'.', '')
- self._getActiveClassCompiler().setBaseClass(finalBaseClassName)
- break
- else:
- modName += '.'+chunk
- if needToAddImport:
- modName, finalClassName = '.'.join(chunks[:-1]), chunks[-1]
- #if finalClassName != chunks[:-1][-1]:
- if finalClassName != chunks[-2]:
+ baseclasses = baseClassName.split(',')
+ for klass in baseclasses:
+ chunks = klass.split('.')
+ if len(chunks)==1:
+ self._getActiveClassCompiler().setBaseClass(klass)
+ if klass not in self.importedVarNames():
+ modName = klass
# we assume the class name to be the module name
- modName = '.'.join(chunks)
- self._getActiveClassCompiler().setBaseClass(finalClassName)
- importStatement = "from %s import %s" % (modName, finalClassName)
- self.addImportStatement(importStatement)
- self.addImportedVarNames( [finalClassName,] )
+ # and that it's not a builtin:
+ importStatement = "from %s import %s" % (modName, klass)
+ self.addImportStatement(importStatement)
+ self.addImportedVarNames((klass,))
+ else:
+ needToAddImport = True
+ modName = chunks[0]
+ #print chunks, ':', self.importedVarNames()
+ for chunk in chunks[1:-1]:
+ if modName in self.importedVarNames():
+ needToAddImport = False
+ finalBaseClassName = klass.replace(modName+'.', '')
+ self._getActiveClassCompiler().setBaseClass(finalBaseClassName)
+ break
+ else:
+ modName += '.'+chunk
+ if needToAddImport:
+ modName, finalClassName = '.'.join(chunks[:-1]), chunks[-1]
+ #if finalClassName != chunks[:-1][-1]:
+ if finalClassName != chunks[-2]:
+ # we assume the class name to be the module name
+ modName = '.'.join(chunks)
+ self._getActiveClassCompiler().setBaseClass(finalClassName)
+ importStatement = "from %s import %s" % (modName, finalClassName)
+ self.addImportStatement(importStatement)
+ self.addImportedVarNames( [finalClassName,] )
def setCompilerSetting(self, key, valueExpr):
self.setSetting(key, eval(valueExpr) )
View
39 src/Parser.py
@@ -596,6 +596,42 @@ def getMultiLineCommentEndToken(self):
if not match:
raise ParseError(self, msg='Invalid multi-line comment end token')
return self.readTo(match.end())
+
+ def getCommaSeparatedSymbols(self):
+ """
+ Loosely based on getDottedName to pull out comma separated
+ named chunks
+ """
+ srcLen = len(self)
+ pieces = []
+ nameChunks = []
+
+ if not self.peek() in identchars:
+ raise ParseError(self)
+
+ while self.pos() < srcLen:
+ c = self.peek()
+ if c in namechars:
+ nameChunk = self.getIdentifier()
+ nameChunks.append(nameChunk)
+ elif c == '.':
+ if self.pos()+1 <srcLen and self.peek(1) in identchars:
+ nameChunks.append(self.getc())
+ else:
+ break
+ elif c == ',':
+ self.getc()
+ pieces.append(''.join(nameChunks))
+ nameChunks = []
+ elif c in (' ', '\t'):
+ self.getc()
+ else:
+ break
+
+ if nameChunks:
+ pieces.append(''.join(nameChunks))
+
+ return pieces
def getDottedName(self):
srcLen = len(self)
@@ -2037,7 +2073,8 @@ def eatExtends(self):
if self.setting('allowExpressionsInExtendsDirective'):
baseName = self.getExpression()
else:
- baseName = self.getDottedName()
+ baseName = self.getCommaSeparatedSymbols()
+ baseName = ', '.join(baseName)
baseName = self._applyExpressionFilters(baseName, 'extends', startPos=startPos)
self._compiler.setBaseClass(baseName) # in compiler
View
4 src/Tests/Template.py
@@ -338,7 +338,9 @@ def runTest(self):
#return [4,5] + $boink()
#end def
'''
- template = Template.compile(template)
+ template = Template.compile(template,
+ moduleGlobals={'Useless' : Useless},
+ compilerSettings={'autoImportForExtendsDirective' : False})
template = template()
result = template.foo()
print result

0 comments on commit f8c53e6

Please sign in to comment.
Something went wrong with that request. Please try again.