diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-07 20:52:31 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-07 20:52:31 -0400 |
commit | 0f58ab39bf6753492e565a85f9f436d476a550b1 (patch) | |
tree | 241293f5643da3d12148af15af3c81a79ea8c59e /mako/ast.py | |
parent | 936efb91e23058a0450eea823489514f4d422a51 (diff) | |
download | external_python_mako-0f58ab39bf6753492e565a85f9f436d476a550b1.tar.gz external_python_mako-0f58ab39bf6753492e565a85f9f436d476a550b1.tar.bz2 external_python_mako-0f58ab39bf6753492e565a85f9f436d476a550b1.zip |
epic trailing whitespace removal
Diffstat (limited to 'mako/ast.py')
-rw-r--r-- | mako/ast.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/mako/ast.py b/mako/ast.py index d6fa215..76311e9 100644 --- a/mako/ast.py +++ b/mako/ast.py @@ -4,7 +4,7 @@ # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -"""utilities for analyzing expressions and blocks of Python +"""utilities for analyzing expressions and blocks of Python code, as well as generating Python from AST nodes""" from mako import exceptions, pyparser, util @@ -14,23 +14,23 @@ class PythonCode(object): """represents information about a string containing Python code""" def __init__(self, code, **exception_kwargs): self.code = code - + # represents all identifiers which are assigned to at some point in # the code self.declared_identifiers = set() - + # represents all identifiers which are referenced before their # assignment, if any self.undeclared_identifiers = set() - + # note that an identifier can be in both the undeclared and declared # lists. - # using AST to parse instead of using code.co_varnames, + # using AST to parse instead of using code.co_varnames, # code.co_names has several advantages: - # - we can locate an identifier as "undeclared" even if + # - we can locate an identifier as "undeclared" even if # its declared later in the same block of code - # - AST is less likely to break with version changes + # - AST is less likely to break with version changes # (for example, the behavior of co_names changed a little bit # in python version 2.5) if isinstance(code, basestring): @@ -59,12 +59,12 @@ class ArgumentList(object): f = pyparser.FindTuple(self, PythonCode, **exception_kwargs) f.visit(expr) - + class PythonFragment(PythonCode): """extends PythonCode to provide identifier lookups in partial control statements - - e.g. + + e.g. for x in 5: elif y==9: except (MyException, e): @@ -74,7 +74,7 @@ class PythonFragment(PythonCode): m = re.match(r'^(\w+)(?:\s+(.*?))?:\s*(#|$)', code.strip(), re.S) if not m: raise exceptions.CompileException( - "Fragment '%s' is not a partial control statement" % + "Fragment '%s' is not a partial control statement" % code, **exception_kwargs) if m.group(3): code = code[:m.start(3)] @@ -91,17 +91,17 @@ class PythonFragment(PythonCode): code = code + "pass" else: raise exceptions.CompileException( - "Unsupported control keyword: '%s'" % + "Unsupported control keyword: '%s'" % keyword, **exception_kwargs) super(PythonFragment, self).__init__(code, **exception_kwargs) - - + + class FunctionDecl(object): """function declaration""" def __init__(self, code, allow_kwargs=True, **exception_kwargs): self.code = code expr = pyparser.parse(code, "exec", **exception_kwargs) - + f = pyparser.ParseFunc(self, **exception_kwargs) f.visit(expr) if not hasattr(self, 'funcname'): @@ -110,13 +110,13 @@ class FunctionDecl(object): **exception_kwargs) if not allow_kwargs and self.kwargs: raise exceptions.CompileException( - "'**%s' keyword argument not allowed here" % + "'**%s' keyword argument not allowed here" % self.argnames[-1], **exception_kwargs) - + def get_argument_expressions(self, include_defaults=True): """return the argument declarations of this FunctionDecl as a printable list.""" - + namedecls = [] defaults = [d for d in self.defaults] kwargs = self.kwargs @@ -134,8 +134,8 @@ class FunctionDecl(object): else: default = len(defaults) and defaults.pop() or None if include_defaults and default: - namedecls.insert(0, "%s=%s" % - (arg, + namedecls.insert(0, "%s=%s" % + (arg, pyparser.ExpressionGenerator(default).value() ) ) @@ -145,7 +145,7 @@ class FunctionDecl(object): class FunctionArgs(FunctionDecl): """the argument portion of a function declaration""" - + def __init__(self, code, **kwargs): super(FunctionArgs, self).__init__("def ANON(%s):pass" % code, **kwargs) |