blob: be751f90e06035377acb84b0e6c945719c314d7e [file] [log] [blame]
<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>TestON.core.ast</title>
<link rel="stylesheet" href="epydoc.css" type="text/css" />
<script type="text/javascript" src="epydoc.js"></script>
</head>
<body bgcolor="white" text="black" link="blue" vlink="#204080"
alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
bgcolor="#a0c0ff" cellspacing="0">
<tr valign="middle">
<!-- Home link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="TestON-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Tree link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Index link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Help link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Project homepage -->
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center"
>TestON</th>
</tr></table></th>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="100%">
<span class="breadcrumbs">
<a href="TestON-module.html">Package&nbsp;TestON</a> ::
<a href="TestON.core-module.html">Package&nbsp;core</a> ::
Module&nbsp;ast
</span>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<!-- hide/show private -->
<tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
<tr><td align="right"><span class="options"
>[<a href="frames.html" target="_top">frames</a
>]&nbsp;|&nbsp;<a href="TestON.core.ast-module.html"
target="_top">no&nbsp;frames</a>]</span></td></tr>
</table>
</td>
</tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module ast</h1><p class="nomargin-top"><span class="codelink"><a href="TestON.core.ast-pysrc.html">source&nbsp;code</a></span></p>
<pre class="literalblock">
ast
~~~
The `ast` module helps Python applications to process trees of the Python
abstract syntax grammar. The abstract syntax itself might change with
each Python release; this module helps to find out programmatically what
the current grammar looks like and allows modifications of it.
An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as
a flag to the `compile()` builtin function or by using the `parse()`
function from this module. The result will be a tree of objects whose
classes all inherit from `ast.AST`.
A modified abstract syntax tree can be compiled into a Python code object
using the built-in `compile()` function.
Additionally various helper functions are provided that make working with
the trees simpler. The main intention of the helper functions and this
module in general is to provide an easy to use interface for libraries
that work tightly with the python syntax (template engines for example).
:copyright: Copyright 2008 by Armin Ronacher.
:license: Python License.
</pre>
<hr />
<div class="fields"> <p><strong>Version:</strong>
82160
</p>
</div><!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Classes</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-Classes"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a href="TestON.core.ast.NodeVisitor-class.html" class="summary-name">NodeVisitor</a><br />
A node visitor base class that walks the abstract syntax tree and
calls a visitor function for every node found.
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a href="TestON.core.ast.NodeTransformer-class.html" class="summary-name">NodeTransformer</a><br />
A :class:`NodeVisitor` subclass that walks the abstract syntax tree
and allows modification of nodes.
</td>
</tr>
</table>
<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Functions</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-Functions"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#parse" class="summary-sig-name">parse</a>(<span class="summary-sig-arg">source</span>,
<span class="summary-sig-arg">filename</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">&lt;unknown&gt;</code><code class="variable-quote">'</code></span>,
<span class="summary-sig-arg">mode</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">exec</code><code class="variable-quote">'</code></span>)</span><br />
Parse the source into an AST node.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#parse">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#literal_eval" class="summary-sig-name">literal_eval</a>(<span class="summary-sig-arg">node_or_string</span>)</span><br />
Safely evaluate an expression node or a string containing a Python
expression.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#literal_eval">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#dump" class="summary-sig-name">dump</a>(<span class="summary-sig-arg">node</span>,
<span class="summary-sig-arg">annotate_fields</span>=<span class="summary-sig-default">True</span>,
<span class="summary-sig-arg">include_attributes</span>=<span class="summary-sig-default">False</span>)</span><br />
Return a formatted dump of the tree in *node*.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#dump">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="copy_location"></a><span class="summary-sig-name">copy_location</span>(<span class="summary-sig-arg">new_node</span>,
<span class="summary-sig-arg">old_node</span>)</span><br />
Copy source location (`lineno` and `col_offset` attributes) from
*old_node* to *new_node* if possible, and return *new_node*.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#copy_location">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#fix_missing_locations" class="summary-sig-name">fix_missing_locations</a>(<span class="summary-sig-arg">node</span>)</span><br />
When you compile a node tree with compile(), the compiler expects
lineno and col_offset attributes for every node that supports them.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#fix_missing_locations">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#increment_lineno" class="summary-sig-name">increment_lineno</a>(<span class="summary-sig-arg">node</span>,
<span class="summary-sig-arg">n</span>=<span class="summary-sig-default">1</span>)</span><br />
Increment the line number of each node in the tree starting at *node*
by *n*.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#increment_lineno">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="iter_fields"></a><span class="summary-sig-name">iter_fields</span>(<span class="summary-sig-arg">node</span>)</span><br />
Yield a tuple of ``(fieldname, value)`` for each field in
``node._fields`` that is present on *node*.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#iter_fields">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a name="iter_child_nodes"></a><span class="summary-sig-name">iter_child_nodes</span>(<span class="summary-sig-arg">node</span>)</span><br />
Yield all direct child nodes of *node*, that is, all fields that are
nodes and all items of fields that are lists of nodes.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#iter_child_nodes">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#get_docstring" class="summary-sig-name">get_docstring</a>(<span class="summary-sig-arg">node</span>,
<span class="summary-sig-arg">clean</span>=<span class="summary-sig-default">True</span>)</span><br />
Return the docstring for the given node or None if no docstring can
be found.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#get_docstring">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="TestON.core.ast-module.html#walk" class="summary-sig-name">walk</a>(<span class="summary-sig-arg">node</span>)</span><br />
Recursively yield all descendant nodes in the tree starting at *node*
(including *node* itself), in no specified order.</td>
<td align="right" valign="top">
<span class="codelink"><a href="TestON.core.ast-pysrc.html#walk">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Variables</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-Variables"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="PyCF_ONLY_AST"></a><span class="summary-name">PyCF_ONLY_AST</span> = <code title="1024">1024</code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="__package__"></a><span class="summary-name">__package__</span> = <code title="'TestON.core'"><code class="variable-quote">'</code><code class="variable-string">TestON.core</code><code class="variable-quote">'</code></code>
</td>
</tr>
</table>
<!-- ==================== FUNCTION DETAILS ==================== -->
<a name="section-FunctionDetails"></a>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
<td colspan="2" class="table-header">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td align="left"><span class="table-header">Function Details</span></td>
<td align="right" valign="top"
><span class="options">[<a href="#section-FunctionDetails"
class="privatelink" onclick="toggle_private();"
>hide private</a>]</span></td>
</tr>
</table>
</td>
</tr>
</table>
<a name="parse"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">parse</span>(<span class="sig-arg">source</span>,
<span class="sig-arg">filename</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">&lt;unknown&gt;</code><code class="variable-quote">'</code></span>,
<span class="sig-arg">mode</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">exec</code><code class="variable-quote">'</code></span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#parse">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Parse the source into an AST node. Equivalent to compile(source,
filename, mode, PyCF_ONLY_AST).</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="literal_eval"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">literal_eval</span>(<span class="sig-arg">node_or_string</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#literal_eval">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Safely evaluate an expression node or a string containing a Python
expression. The string or node provided may only consist of the
following Python literal structures: strings, numbers, tuples, lists,
dicts, booleans, and None.</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="dump"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">dump</span>(<span class="sig-arg">node</span>,
<span class="sig-arg">annotate_fields</span>=<span class="sig-default">True</span>,
<span class="sig-arg">include_attributes</span>=<span class="sig-default">False</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#dump">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Return a formatted dump of the tree in *node*. This is mainly useful
for debugging purposes. The returned string will show the names and the
values for fields. This makes the code impossible to evaluate, so if
evaluation is wanted *annotate_fields* must be set to False. Attributes
such as line numbers and column offsets are not dumped by default. If
this is wanted, *include_attributes* can be set to True.</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="fix_missing_locations"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">fix_missing_locations</span>(<span class="sig-arg">node</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#fix_missing_locations">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>When you compile a node tree with compile(), the compiler expects
lineno and col_offset attributes for every node that supports them. This
is rather tedious to fill in for generated nodes, so this helper adds
these attributes recursively where not already set, by setting them to
the values of the parent node. It works recursively starting at
*node*.</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="increment_lineno"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">increment_lineno</span>(<span class="sig-arg">node</span>,
<span class="sig-arg">n</span>=<span class="sig-default">1</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#increment_lineno">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Increment the line number of each node in the tree starting at *node*
by *n*. This is useful to &quot;move code&quot; to a different location
in a file.</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="get_docstring"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">get_docstring</span>(<span class="sig-arg">node</span>,
<span class="sig-arg">clean</span>=<span class="sig-default">True</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#get_docstring">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Return the docstring for the given node or None if no docstring can be
found. If the node provided does not have docstrings a TypeError will be
raised.</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<a name="walk"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">walk</span>(<span class="sig-arg">node</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="TestON.core.ast-pysrc.html#walk">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Recursively yield all descendant nodes in the tree starting at *node*
(including *node* itself), in no specified order. This is useful if you
only want to modify nodes in place and don't care about the context.</p>
<dl class="fields">
</dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
bgcolor="#a0c0ff" cellspacing="0">
<tr valign="middle">
<!-- Home link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="TestON-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Tree link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Index link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Help link -->
<th>&nbsp;&nbsp;&nbsp;<a
href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
<!-- Project homepage -->
<th class="navbar" align="right" width="100%">
<table border="0" cellpadding="0" cellspacing="0">
<tr><th class="navbar" align="center"
>TestON</th>
</tr></table></th>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Mon Aug 10 11:12:34 2015
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
>http://epydoc.sourceforge.net</a>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
// Private objects are initially displayed (because if
// javascript is turned off then we want them to be
// visible); but by default, we want to hide them. So hide
// them unless we have a cookie that says to show them.
checkCookie();
// -->
</script>
</body>
</html>