/apidocs/pyechonest.decorators-pysrc.html
http://echo-nest-remix.googlecode.com/ · HTML · 139 lines · 108 code · 10 blank · 21 comment · 0 complexity · 21b04fb8cc5f9435d8041d20cf5d8a24 MD5 · raw file
- <?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>pyechonest.decorators</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">
- <!-- Tree link -->
- <th> <a
- href="module-tree.html">Trees</a> </th>
- <!-- Index link -->
- <th> <a
- href="identifier-index.html">Indices</a> </th>
- <!-- Help link -->
- <th> <a
- href="help.html">Help</a> </th>
- <!-- Project homepage -->
- <th class="navbar" align="right" width="100%">
- <table border="0" cellpadding="0" cellspacing="0">
- <tr><th class="navbar" align="center"
- ><a class="navbar" target="_top" href="http://code.google.com/p/echo-nest-remix/">The Echo Nest Remix API, SVN Revision: 448</a></th>
- </tr></table></th>
- </tr>
- </table>
- <table width="100%" cellpadding="0" cellspacing="0">
- <tr valign="top">
- <td width="100%">
- <span class="breadcrumbs">
- <a href="pyechonest-module.html">Package pyechonest</a> ::
- Module decorators
- </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 private</a>]</span></td></tr>
- <tr><td align="right"><span class="options"
- >[<a href="frames.html" target="_top">frames</a
- >] | <a href="pyechonest.decorators-pysrc.html"
- target="_top">no frames</a>]</span></td></tr>
- </table>
- </td>
- </tr>
- </table>
- <h1 class="epydoc">Source Code for <a href="pyechonest.decorators-module.html">Module pyechonest.decorators</a></h1>
- <pre class="py-src">
- <a name="L1"></a><tt class="py-lineno"> 1</tt> <tt class="py-line"><tt class="py-comment"># from http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize</tt> </tt>
- <a name="memoized"></a><div id="memoized-def"><a name="L2"></a><tt class="py-lineno"> 2</tt> <a class="py-toggle" href="#" id="memoized-toggle" onclick="return toggle('memoized');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="pyechonest.decorators.memoized-class.html">memoized</a><tt class="py-op">(</tt><tt class="py-base-class">object</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
- </div><div id="memoized-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="memoized-expanded"><a name="L3"></a><tt class="py-lineno"> 3</tt> <tt class="py-line"> <tt class="py-docstring">"""Decorator that caches a function's return value each time it is called.</tt> </tt>
- <a name="L4"></a><tt class="py-lineno"> 4</tt> <tt class="py-line"><tt class="py-docstring"> If called later with the same arguments, the cached value is returned, and</tt> </tt>
- <a name="L5"></a><tt class="py-lineno"> 5</tt> <tt class="py-line"><tt class="py-docstring"> not re-evaluated.</tt> </tt>
- <a name="L6"></a><tt class="py-lineno"> 6</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
- <a name="memoized.__init__"></a><div id="memoized.__init__-def"><a name="L7"></a><tt class="py-lineno"> 7</tt> <a class="py-toggle" href="#" id="memoized.__init__-toggle" onclick="return toggle('memoized.__init__');">-</a><tt class="py-line"> <tt class="py-keyword">def</tt> <a class="py-def-name" href="pyechonest.decorators.memoized-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">func</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
- </div><div id="memoized.__init__-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="memoized.__init__-expanded"><a name="L8"></a><tt class="py-lineno"> 8</tt> <tt class="py-line"> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">func</tt> <tt class="py-op">=</tt> <tt class="py-name">func</tt> </tt>
- <a name="L9"></a><tt class="py-lineno"> 9</tt> <tt class="py-line"> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">cache</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-op">}</tt> </tt>
- </div><a name="L10"></a><tt class="py-lineno">10</tt> <tt class="py-line"> </tt>
- <a name="memoized.__call__"></a><div id="memoized.__call__-def"><a name="L11"></a><tt class="py-lineno">11</tt> <a class="py-toggle" href="#" id="memoized.__call__-toggle" onclick="return toggle('memoized.__call__');">-</a><tt class="py-line"> <tt class="py-keyword">def</tt> <a class="py-def-name" href="pyechonest.decorators.memoized-class.html#__call__">__call__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-op">*</tt><tt class="py-param">args</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
- </div><div id="memoized.__call__-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="memoized.__call__-expanded"><a name="L12"></a><tt class="py-lineno">12</tt> <tt class="py-line"> <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
- <a name="L13"></a><tt class="py-lineno">13</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">cache</tt><tt class="py-op">[</tt><tt class="py-name">args</tt><tt class="py-op">]</tt> </tt>
- <a name="L14"></a><tt class="py-lineno">14</tt> <tt class="py-line"> <tt class="py-keyword">except</tt> <tt class="py-name">KeyError</tt><tt class="py-op">:</tt> </tt>
- <a name="L15"></a><tt class="py-lineno">15</tt> <tt class="py-line"> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">cache</tt><tt class="py-op">[</tt><tt class="py-name">args</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">value</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">func</tt><tt class="py-op">(</tt><tt class="py-op">*</tt><tt class="py-name">args</tt><tt class="py-op">)</tt> </tt>
- <a name="L16"></a><tt class="py-lineno">16</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">value</tt> </tt>
- <a name="L17"></a><tt class="py-lineno">17</tt> <tt class="py-line"> <tt class="py-keyword">except</tt> <tt class="py-name">TypeError</tt><tt class="py-op">:</tt> </tt>
- <a name="L18"></a><tt class="py-lineno">18</tt> <tt class="py-line"> <tt class="py-comment"># uncachable -- for instance, passing a list as an argument.</tt> </tt>
- <a name="L19"></a><tt class="py-lineno">19</tt> <tt class="py-line"> <tt class="py-comment"># Better to not cache than to blow up entirely.</tt> </tt>
- <a name="L20"></a><tt class="py-lineno">20</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">func</tt><tt class="py-op">(</tt><tt class="py-op">*</tt><tt class="py-name">args</tt><tt class="py-op">)</tt> </tt>
- </div><a name="L21"></a><tt class="py-lineno">21</tt> <tt class="py-line"> </tt>
- <a name="memoized.__repr__"></a><div id="memoized.__repr__-def"><a name="L22"></a><tt class="py-lineno">22</tt> <a class="py-toggle" href="#" id="memoized.__repr__-toggle" onclick="return toggle('memoized.__repr__');">-</a><tt class="py-line"> <tt class="py-keyword">def</tt> <a class="py-def-name" href="pyechonest.decorators.memoized-class.html#__repr__">__repr__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
- </div><div id="memoized.__repr__-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="memoized.__repr__-expanded"><a name="L23"></a><tt class="py-lineno">23</tt> <tt class="py-line"> <tt class="py-docstring">"""Return the function's docstring."""</tt> </tt>
- <a name="L24"></a><tt class="py-lineno">24</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">func</tt><tt class="py-op">.</tt><tt class="py-name">__doc__</tt> </tt>
- </div></div><a name="L25"></a><tt class="py-lineno">25</tt> <tt class="py-line"> </tt><script type="text/javascript">
- <!--
- expandto(location.href);
- // -->
- </script>
- </pre>
- <br />
- <!-- ==================== NAVIGATION BAR ==================== -->
- <table class="navbar" border="0" width="100%" cellpadding="0"
- bgcolor="#a0c0ff" cellspacing="0">
- <tr valign="middle">
- <!-- Tree link -->
- <th> <a
- href="module-tree.html">Trees</a> </th>
- <!-- Index link -->
- <th> <a
- href="identifier-index.html">Indices</a> </th>
- <!-- Help link -->
- <th> <a
- href="help.html">Help</a> </th>
- <!-- Project homepage -->
- <th class="navbar" align="right" width="100%">
- <table border="0" cellpadding="0" cellspacing="0">
- <tr><th class="navbar" align="center"
- ><a class="navbar" target="_top" href="http://code.google.com/p/echo-nest-remix/">The Echo Nest Remix API, SVN Revision: 448</a></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 Wed May 26 12:18:03 2010
- </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>