コード例 #1
0
 def __init__(self, args, template, namespaces=None, lineno=-1, offset=-1):
     Directive.__init__(self, None, template, namespaces, lineno, offset)
     ast = _parse(args).body
     self.args = []
     self.star_args = None
     self.dstar_args = None
     self.defaults = {}
     if isinstance(ast, _ast.Call):
         self.name = ast.func.id
         for arg in ast.args:
             if hasattr(_ast, 'Starred') and isinstance(arg, _ast.Starred):
                 # Python 3.5+
                 self.star_args = arg.value.id
             else:
                 # only names
                 self.args.append(arg.id)
         for kwd in ast.keywords:
             if kwd.arg is None:
                 # Python 3.5+
                 self.dstar_args = kwd.value.id
             else:
                 self.args.append(kwd.arg)
                 exp = Expression(kwd.value, template.filepath,
                                  lineno, lookup=template.lookup)
                 self.defaults[kwd.arg] = exp
         if getattr(ast, 'starargs', None):
             self.star_args = ast.starargs.id
         if getattr(ast, 'kwargs', None):
             self.dstar_args = ast.kwargs.id
     else:
         self.name = ast.id
コード例 #2
0
ファイル: directives.py プロジェクト: edgewall/genshi
 def __init__(self, args, template, namespaces=None, lineno=-1, offset=-1):
     Directive.__init__(self, None, template, namespaces, lineno, offset)
     ast = _parse(args).body
     self.args = []
     self.star_args = None
     self.dstar_args = None
     self.defaults = {}
     if isinstance(ast, _ast.Call):
         self.name = ast.func.id
         for arg in ast.args:
             if hasattr(_ast, 'Starred') and isinstance(arg, _ast.Starred):
                 # Python 3.5+
                 self.star_args = arg.value.id
             else:
                 # only names
                 self.args.append(arg.id)
         for kwd in ast.keywords:
             if kwd.arg is None:
                 # Python 3.5+
                 self.dstar_args = kwd.value.id
             else:
                 self.args.append(kwd.arg)
                 exp = Expression(kwd.value, template.filepath,
                                  lineno, lookup=template.lookup)
                 self.defaults[kwd.arg] = exp
         if getattr(ast, 'starargs', None):
             self.star_args = ast.starargs.id
         if getattr(ast, 'kwargs', None):
             self.dstar_args = ast.kwargs.id
     else:
         self.name = ast.id
コード例 #3
0
 def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
     if ' in ' not in value:
         raise TemplateSyntaxError('"in" keyword missing in "for" directive',
                                   template.filepath, lineno, offset)
     assign, value = value.split(' in ', 1)
     ast = _parse(assign, 'exec')
     value = 'iter(%s)' % value.strip()
     self.assign = _assignment(ast.body[0].value)
     self.filename = template.filepath
     Directive.__init__(self, value, template, namespaces, lineno, offset)
コード例 #4
0
ファイル: directives.py プロジェクト: kamroot/mc27
 def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
     if ' in ' not in value:
         raise TemplateSyntaxError('"in" keyword missing in "for" directive',
                                   template.filepath, lineno, offset)
     assign, value = value.split(' in ', 1)
     ast = _parse(assign, 'exec')
     value = 'iter(%s)' % value.strip()
     self.assign = _assignment(ast.body[0].value)
     self.filename = template.filepath
     Directive.__init__(self, value, template, namespaces, lineno, offset)
コード例 #5
0
ファイル: directives.py プロジェクト: jacoco/www.eclemma.org
 def __init__(self, args, template, namespaces=None, lineno=-1, offset=-1):
     Directive.__init__(self, None, template, namespaces, lineno, offset)
     ast = _parse(args).node
     self.args = []
     self.defaults = {}
     if isinstance(ast, compiler.ast.CallFunc):
         self.name = ast.node.name
         for arg in ast.args:
             if isinstance(arg, compiler.ast.Keyword):
                 self.args.append(arg.name)
                 self.defaults[arg.name] = Expression(arg.expr,
                                                      template.filepath,
                                                      lineno,
                                                      lookup=template.lookup)
             else:
                 self.args.append(arg.name)
     else:
         self.name = ast.name
コード例 #6
0
 def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
     Directive.__init__(self, None, template, namespaces, lineno, offset)
     self.vars = []
     value = value.strip()
     try:
         ast = _parse(value, 'exec')
         for node in ast.body:
             if not isinstance(node, _ast.Assign):
                 raise TemplateSyntaxError('only assignment allowed in '
                                           'value of the "with" directive',
                                           template.filepath, lineno, offset)
             self.vars.append(([_assignment(n) for n in node.targets],
                               Expression(node.value, template.filepath,
                                          lineno, lookup=template.lookup)))
     except SyntaxError as err:
         err.msg += ' in expression "%s" of "%s" directive' % (value,
                                                               self.tagname)
         raise TemplateSyntaxError(err, template.filepath, lineno,
                                   offset + (err.offset or 0))
コード例 #7
0
ファイル: directives.py プロジェクト: kamroot/mc27
 def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
     Directive.__init__(self, None, template, namespaces, lineno, offset)
     self.vars = []
     value = value.strip()
     try:
         ast = _parse(value, 'exec')
         for node in ast.body:
             if not isinstance(node, _ast.Assign):
                 raise TemplateSyntaxError('only assignment allowed in '
                                           'value of the "with" directive',
                                           template.filepath, lineno, offset)
             self.vars.append(([_assignment(n) for n in node.targets],
                               Expression(node.value, template.filepath,
                                          lineno, lookup=template.lookup)))
     except SyntaxError, err:
         err.msg += ' in expression "%s" of "%s" directive' % (value,
                                                               self.tagname)
         raise TemplateSyntaxError(err, template.filepath, lineno,
                                   offset + (err.offset or 0))