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