def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        oargs = args = DTUtil.tagCall(tag, ['module', ('items', 'None'),
                                            ('as', 'None')])
        args = DTCompilerUtil.pyifyArgs(tag, args)
        module = DTCompilerUtil.checkName(tag, 'module', args['module'],
                                          oargs['module'])

        if oargs['as'] != None:
            asname = DTCompilerUtil.checkName(tag, 'as', args['as'],
                                              oargs['as'])
            asStr = " as %s" % asname
        else:
            asStr = ''
            
        if oargs['items'] != None:
            items = DTCompilerUtil.checkName('import', 'items', args['items'],
                                             oargs['items'])
            # allow items to be separated by commas or spaces
            if ',' in items:
                formattedItems=','.join(_splitter.split(items))
            else:
                formattedItems=','.join(items.split())
            codeout.write(indent,
                          'from %s import %s%s' % (module,
                                                   formattedItems,
                                                   asStr))
        else:
            codeout.write(indent, 'import %s%s' % (module, asStr))
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        oargs = args = DTUtil.tagCall(
            tag, ['module', ('items', 'None'), ('as', 'None')])
        args = DTCompilerUtil.pyifyArgs(tag, args)
        module = DTCompilerUtil.checkName(tag, 'module', args['module'],
                                          oargs['module'])

        if oargs['as'] != None:
            asname = DTCompilerUtil.checkName(tag, 'as', args['as'],
                                              oargs['as'])
            asStr = " as %s" % asname
        else:
            asStr = ''

        if oargs['items'] != None:
            items = DTCompilerUtil.checkName('import', 'items', args['items'],
                                             oargs['items'])
            # allow items to be separated by commas or spaces
            if ',' in items:
                formattedItems = ','.join(_splitter.split(items))
            else:
                formattedItems = ','.join(items.split())
            codeout.write(
                indent,
                'from %s import %s%s' % (module, formattedItems, asStr))
        else:
            codeout.write(indent, 'import %s%s' % (module, asStr))
 def genCode(self, indent, codeout, tagreg, tag):
     DTCompilerUtil.tagDebug(indent, codeout, tag)
     pargs = args = DTUtil.tagCall(tag, ['name', 'value'])
     args = DTCompilerUtil.pyifyArgs(tag, args)
     name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                     pargs['name'])
     codeout.write(indent, '%s = (%s)' % (name, args['value']))
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        tagargs = ['name']
        if self._attend_to_comments:
            tagargs.append(('comments', None))
        pargs = args = DTUtil.tagCall(tag, tagargs)
        args = DTCompilerUtil.pyifyArgs(tag, args)
        if self._attend_to_comments and args['comments'] is not None:
            self._testCommentLevel(indent, codeout, args['comments'])
            stuff = self._pushCommentLevel(indent, codeout, args['comments'])

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])

        oldout = DTCompilerUtil.getTempName()
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        for i in node.children[1:-1]:
            DTCompilerUtil.genCodeChild(indent, codeout, tagreg, i, meta)
        codeout.write(indent, '%s = __h.OUTPUT.getvalue()' % name)
        codeout.write(indent, '__h.OUTPUT = %s' % oldout)
        codeout.write(indent, 'del %s' % oldout)
        if self._attend_to_comments and args['comments'] is not None:
            self._popCommentLevel(indent, codeout, *stuff)
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag,
                                      ['expr', ('name', '"sequence_item"')])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])
        exprval = DTCompilerUtil.getTempName()

        codeout.write(indent, '%s = %s' % (exprval, args['expr']))
        codeout.write(indent, 'if %s:' % exprval)
        codeout.write(indent + 4, 'for %s in %s:' % (name, exprval))
        #do main loop shit
        for i in node.children[1:-1]:
            if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                    and i.tagname == 'else'):
                break
            else:
                DTCompilerUtil.genCodeChild(indent + 8, codeout, tagreg, i,
                                            meta)
        codeout.write(indent, 'else:')
        codeout.write(indent + 4, 'pass')
        #do else clause
        on = 0
        for i in node.children[1:-1]:
            if (type(i) == InstanceType and i.__class__ == DTLexer.DTToken
                    and i.tagname == 'else'):
                on = 1
            elif on:
                DTCompilerUtil.genCodeChild(indent + 4, codeout, tagreg, i,
                                            meta)
        codeout.write(indent, 'del %s' % exprval)
 def genCode(self, indent, codeout, tagreg, tag):
     DTCompilerUtil.tagDebug(indent, codeout, tag)
     pargs=args=DTUtil.tagCall(tag, ['name', 'value'])
     args=DTCompilerUtil.pyifyArgs(tag, args)
     name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                     pargs['name'])
     codeout.write(indent, '%s = (%s)' % (name, args['value']))
    def genCode(self, indent, codeout, tagreg, node, meta):
        tag=node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs=args=DTUtil.tagCall(tag, ['expr', ('name','"sequence_item"')])
        args=DTCompilerUtil.pyifyArgs(tag, args)

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])
        exprval=DTCompilerUtil.getTempName()

        codeout.write(indent, '%s = %s' % (exprval, args['expr']))
        codeout.write(indent, 'if %s:' % exprval)
        codeout.write(indent+4, 'for %s in %s:' % (name, exprval))
        #do main loop shit
        for i in node.children[1:-1]:
            if (type(i) == InstanceType
                and i.__class__ == DTLexer.DTToken
                and i.tagname == 'else'):
                break
            else:
                DTCompilerUtil.genCodeChild(indent+8, codeout, tagreg, i, meta)
        codeout.write(indent, 'else:')
        codeout.write(indent+4, 'pass')
        #do else clause
        on=0
        for i in node.children[1:-1]:
            if (type(i) == InstanceType
                and i.__class__ == DTLexer.DTToken
                and i.tagname == 'else'):
                on=1
            elif on:
                DTCompilerUtil.genCodeChild(indent+4, codeout, tagreg, i, meta)
        codeout.write(indent, 'del %s' % exprval)
    def genCode ( self, indent, codeout, tagreg, node, meta):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        tagargs=['name']
        if self._attend_to_comments:
            tagargs.append(('comments', None))
        pargs = args = DTUtil.tagCall(tag, tagargs)
        args = DTCompilerUtil.pyifyArgs(tag, args)
        if self._attend_to_comments and args['comments'] is not None:
            self._testCommentLevel(indent, codeout, args['comments'])
            stuff=self._pushCommentLevel(indent, codeout, args['comments'])

        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])
        
        oldout = DTCompilerUtil.getTempName()
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        for i in node.children[1:-1]:
            DTCompilerUtil.genCodeChild(indent, codeout, tagreg, i, meta)
        codeout.write(indent, '%s = __h.OUTPUT.getvalue()' % name)
        codeout.write(indent, '__h.OUTPUT = %s' % oldout)
        codeout.write(indent, 'del %s' % oldout)
        if self._attend_to_comments and args['comments'] is not None:
            self._popCommentLevel(indent, codeout, *stuff)
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag, [('expr', 'None')])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        try:
            DTCompilerUtil.checkName(tag, 'expr', args['expr'], pargs['expr'])
        except:
            pass
        else:
            raise DTExcept.DTCompileError(tag, 'cannot call a string')

        stmt = args['expr'] + '\n'

        try:
            compile(stmt, stmt, 'exec')
        except SyntaxError:
            raise DTExcept.DTCompileError(
                tag, 'syntax error in statement "%s"' % stmt)

        codeout.writemultiline(indent, stmt)
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug ( indent, codeout, tag )
        pargs = args = DTUtil.tagCall(tag, [('expr', 'None')])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        try:
            DTCompilerUtil.checkName(tag, 'expr', args['expr'], pargs['expr'])
        except:
            pass
        else:
            raise DTExcept.DTCompileError( tag, 'cannot call a string')

        stmt = args['expr'] + '\n'

        try:
            compile(stmt, stmt, 'exec')
        except SyntaxError:
            raise DTExcept.DTCompileError ( tag, 
                                  'syntax error in statement "%s"' % stmt )

        codeout.writemultiline(indent, stmt)
 def genCode(self, indent, codeout, tagreg, tag):
     DTCompilerUtil.tagDebug(indent, codeout, tag)
     pargs = args = DTUtil.tagCall(tag, ['name', ('value', '""')])
     args = DTCompilerUtil.pyifyArgs(tag, args)
     name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                     pargs['name'])
     codeout.write(indent, 'try:')
     codeout.write(indent + 4, '%s' % name)
     codeout.write(indent, 'except (NameError, AttributeError):')
     codeout.write(indent + 4, '%s = %s' % (name, args['value']))
     codeout.write(indent, 'else:')
     codeout.write(indent + 4, 'if %s is None:' % name)
     codeout.write(indent + 8, '%s = %s' % (name, args['value']))
 def genCode(self, indent, codeout, tagreg, tag):
     DTCompilerUtil.tagDebug(indent, codeout, tag)
     pargs=args=DTUtil.tagCall(tag, ['name', ('value', '""')])
     args=DTCompilerUtil.pyifyArgs(tag, args)
     name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                     pargs['name'])
     codeout.write(indent, 'try:')
     codeout.write(indent+4, '%s' % name)
     codeout.write(indent, 'except (NameError, AttributeError):')
     codeout.write(indent+4, '%s = %s' % (name, args['value']))
     codeout.write(indent, 'else:')
     codeout.write(indent+4, 'if %s is None:' % name)
     codeout.write(indent+8, '%s = %s' % (name, args['value']))
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        oargs = args = DTUtil.tagCall(
            tag, ['module', ('items', 'None'), ('as', 'None')])
        args = DTCompilerUtil.pyifyArgs(tag, args)
        module = DTCompilerUtil.checkName(tag, 'module', args['module'],
                                          oargs['module'])

        if oargs['as'] != None:
            asname = DTCompilerUtil.checkName(tag, 'as', args['as'],
                                              oargs['as'])
            asStr = " as %s" % asname
        else:
            asStr = ''

        if oargs['items'] != None:
            items = DTCompilerUtil.checkName('import', 'items', args['items'],
                                             oargs['items'])
            codeout.write(
                indent, 'from %s import %s%s' %
                (module, string.join(string.split(items), ','), asStr))
        else:
            codeout.write(indent, 'import %s%s' % (module, asStr))
    def genCode(self, indent, codeout, tagreg, node):
        tag = node.children[0]
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag, ['name'])
        args = DTCompilerUtil.pyifyArgs(tag, args)
        name = DTCompilerUtil.checkName(tag, 'name', args['name'],
                                        pargs['name'])

        oldout = DTCompilerUtil.getTempName()
        codeout.write(indent, '%s = __h.OUTPUT' % oldout)
        codeout.write(indent, '__h.OUTPUT=__h.NEWOUTPUT()')
        for i in node.children[1:-1]:
            DTCompilerUtil.genCodeChild(indent, codeout, tagreg, i)
        codeout.write(indent, '%s = __h.OUTPUT.getvalue()' % name)
        codeout.write(indent, '__h.OUTPUT = %s' % oldout)
        codeout.write(indent, 'del %s' % oldout)
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag, ['var'], 'plainArgs', 'kwArgs')
        kwargs = DTCompilerUtil.pyifyArgs(tag, args['kwArgs'])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        varname = DTCompilerUtil.checkName(tag, 'var', args['var'],
                                           pargs['var'])
        # First, generate the plain args
        out = []
        for _j in args['plainArgs']:
            out.append('"%s": %s' % (_j, _j))

        codeout.write(indent,
                      '%s = { %s }' % (varname, string.join(out, ', ')))

        # Now, add the keyword arguments
        codeout.write(indent, '%s.update(%s)' % (varname, str(args['kwArgs'])))
    def genCode(self, indent, codeout, tagreg, tag):
        DTCompilerUtil.tagDebug(indent, codeout, tag)
        pargs = args = DTUtil.tagCall(tag, ['var'], 'plainArgs', 'kwArgs' )
        kwargs = DTCompilerUtil.pyifyArgs(tag, args['kwArgs'])
        args = DTCompilerUtil.pyifyArgs(tag, args)

        varname = DTCompilerUtil.checkName(tag, 'var', args['var'],
                                           pargs['var'])
        # First, generate the plain args
        out = []
        for _j in args['plainArgs']:
            out.append ( '"%s": %s' % ( _j, _j ) )

        codeout.write ( indent, '%s = { %s }' % ( varname,
                                                  string.join ( out, ', ' )) )

        # Now, add the keyword arguments
        codeout.write ( indent, '%s.update(%s)' % ( varname,
                                                    str(args['kwArgs']) ))