PageRenderTime 205ms CodeModel.GetById 100ms app.highlight 17ms RepoModel.GetById 84ms app.codeStats 0ms

/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
  1<?xml version="1.0" encoding="ascii"?>
  2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3          "DTD/xhtml1-transitional.dtd">
  4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5<head>
  6  <title>pyechonest.decorators</title>
  7  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  8  <script type="text/javascript" src="epydoc.js"></script>
  9</head>
 10
 11<body bgcolor="white" text="black" link="blue" vlink="#204080"
 12      alink="#204080">
 13<!-- ==================== NAVIGATION BAR ==================== -->
 14<table class="navbar" border="0" width="100%" cellpadding="0"
 15       bgcolor="#a0c0ff" cellspacing="0">
 16  <tr valign="middle">
 17
 18  <!-- Tree link -->
 19      <th>&nbsp;&nbsp;&nbsp;<a
 20        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
 21
 22  <!-- Index link -->
 23      <th>&nbsp;&nbsp;&nbsp;<a
 24        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
 25
 26  <!-- Help link -->
 27      <th>&nbsp;&nbsp;&nbsp;<a
 28        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
 29
 30  <!-- Project homepage -->
 31      <th class="navbar" align="right" width="100%">
 32        <table border="0" cellpadding="0" cellspacing="0">
 33          <tr><th class="navbar" align="center"
 34            ><a class="navbar" target="_top" href="http://code.google.com/p/echo-nest-remix/">The Echo Nest Remix API, SVN Revision: 448</a></th>
 35          </tr></table></th>
 36  </tr>
 37</table>
 38<table width="100%" cellpadding="0" cellspacing="0">
 39  <tr valign="top">
 40    <td width="100%">
 41      <span class="breadcrumbs">
 42        <a href="pyechonest-module.html">Package&nbsp;pyechonest</a> ::
 43        Module&nbsp;decorators
 44      </span>
 45    </td>
 46    <td>
 47      <table cellpadding="0" cellspacing="0">
 48        <!-- hide/show private -->
 49        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
 50    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
 51        <tr><td align="right"><span class="options"
 52            >[<a href="frames.html" target="_top">frames</a
 53            >]&nbsp;|&nbsp;<a href="pyechonest.decorators-pysrc.html"
 54            target="_top">no&nbsp;frames</a>]</span></td></tr>
 55      </table>
 56    </td>
 57  </tr>
 58</table>
 59<h1 class="epydoc">Source Code for <a href="pyechonest.decorators-module.html">Module pyechonest.decorators</a></h1>
 60<pre class="py-src">
 61<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>
 62<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>
 63</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>
 64<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>
 65<a name="L5"></a><tt class="py-lineno"> 5</tt>  <tt class="py-line"><tt class="py-docstring">    not re-evaluated.</tt> </tt>
 66<a name="L6"></a><tt class="py-lineno"> 6</tt>  <tt class="py-line"><tt class="py-docstring">    """</tt> </tt>
 67<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>
 68</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>
 69<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>
 70</div><a name="L10"></a><tt class="py-lineno">10</tt>  <tt class="py-line">     </tt>
 71<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>
 72</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>
 73<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>
 74<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>
 75<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>
 76<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>
 77<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>
 78<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>
 79<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>
 80<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>
 81</div><a name="L21"></a><tt class="py-lineno">21</tt>  <tt class="py-line">     </tt>
 82<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>
 83</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>
 84<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>
 85</div></div><a name="L25"></a><tt class="py-lineno">25</tt>  <tt class="py-line"> </tt><script type="text/javascript">
 86<!--
 87expandto(location.href);
 88// -->
 89</script>
 90</pre>
 91<br />
 92<!-- ==================== NAVIGATION BAR ==================== -->
 93<table class="navbar" border="0" width="100%" cellpadding="0"
 94       bgcolor="#a0c0ff" cellspacing="0">
 95  <tr valign="middle">
 96
 97  <!-- Tree link -->
 98      <th>&nbsp;&nbsp;&nbsp;<a
 99        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
100
101  <!-- Index link -->
102      <th>&nbsp;&nbsp;&nbsp;<a
103        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
104
105  <!-- Help link -->
106      <th>&nbsp;&nbsp;&nbsp;<a
107        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
108
109  <!-- Project homepage -->
110      <th class="navbar" align="right" width="100%">
111        <table border="0" cellpadding="0" cellspacing="0">
112          <tr><th class="navbar" align="center"
113            ><a class="navbar" target="_top" href="http://code.google.com/p/echo-nest-remix/">The Echo Nest Remix API, SVN Revision: 448</a></th>
114          </tr></table></th>
115  </tr>
116</table>
117<table border="0" cellpadding="0" cellspacing="0" width="100%%">
118  <tr>
119    <td align="left" class="footer">
120    Generated by Epydoc 3.0.1 on Wed May 26 12:18:03 2010
121    </td>
122    <td align="right" class="footer">
123      <a target="mainFrame" href="http://epydoc.sourceforge.net"
124        >http://epydoc.sourceforge.net</a>
125    </td>
126  </tr>
127</table>
128
129<script type="text/javascript">
130  <!--
131  // Private objects are initially displayed (because if
132  // javascript is turned off then we want them to be
133  // visible); but by default, we want to hide them.  So hide
134  // them unless we have a cookie that says to show them.
135  checkCookie();
136  // -->
137</script>
138</body>
139</html>