Skip to content
Browse files

New docs update

  • Loading branch information...
1 parent b0e7760 commit 89c6b45fe70560d5e0a633190dfdab603925cacb @sudorandom sudorandom committed Apr 4, 2012
Showing with 12,168 additions and 1 deletion.
  1. +92 −0 _modules/index.html
  2. +145 −0 _modules/object_storage.html
  3. +460 −0 _modules/object_storage/client.html
  4. +410 −0 _modules/object_storage/container.html
  5. +509 −0 _modules/object_storage/storage_object.html
  6. +14 −0 _sources/client.txt
  7. +9 −0 _sources/container.txt
  8. +31 −0 _sources/index.txt
  9. +34 −0 _sources/license.txt
  10. +9 −0 _sources/object.txt
  11. +509 −0 _static/basic.css
  12. +255 −0 _static/default.css
  13. +247 −0 _static/doctools.js
  14. BIN _static/file.png
  15. +4,376 −0 _static/jquery.js
  16. BIN _static/minus.png
  17. BIN _static/plus.png
  18. +61 −0 _static/pygments.css
  19. +518 −0 _static/searchtools.js
  20. +147 −0 _static/sidebar.js
  21. +16 −0 _static/underscore.js
  22. +47 −0 build/lib.linux-i686-2.6/object_storage/__init__.py
  23. +370 −0 build/lib.linux-i686-2.6/object_storage/client.py
  24. +40 −0 build/lib.linux-i686-2.6/object_storage/consts.py
  25. +316 −0 build/lib.linux-i686-2.6/object_storage/container.py
  26. +51 −0 build/lib.linux-i686-2.6/object_storage/errors.py
  27. +415 −0 build/lib.linux-i686-2.6/object_storage/storage_object.py
  28. +184 −0 build/lib.linux-i686-2.6/object_storage/transport/__init__.py
  29. +111 −0 build/lib.linux-i686-2.6/object_storage/transport/httplib2conn.py
  30. +115 −0 build/lib.linux-i686-2.6/object_storage/transport/requestsconn.py
  31. +291 −0 build/lib.linux-i686-2.6/object_storage/transport/twist.py
  32. +28 −0 build/lib.linux-i686-2.6/object_storage/utils.py
  33. 0 build/lib.linux-i686-2.6/tests/__init__.py
  34. 0 build/lib.linux-i686-2.6/tests/integration/__init__.py
  35. +135 −0 build/lib.linux-i686-2.6/tests/integration/httplib.py
  36. +1 −0 build/lib.linux-i686-2.6/tests/integration/requests.py
  37. 0 build/lib.linux-i686-2.6/tests/integration/twist.py
  38. 0 build/lib.linux-i686-2.6/tests/unit/__init__.py
  39. +17 −0 build/lib.linux-i686-2.6/tests/unit/authentication.py
  40. +125 −0 build/lib.linux-i686-2.6/tests/unit/client.py
  41. +97 −0 build/lib.linux-i686-2.6/tests/unit/container.py
  42. +92 −0 build/lib.linux-i686-2.6/tests/unit/storage_object.py
  43. +381 −0 client.html
  44. +338 −0 container.html
  45. BIN dist/softlayer_object_storage-0.4.1-py2.6.egg
  46. +348 −0 genindex.html
  47. +133 −0 index.html
  48. +118 −0 license.html
  49. +359 −0 object.html
  50. BIN objects.inv
  51. +0 −1 params.json
  52. +111 −0 py-modindex.html
  53. +102 −0 search.html
  54. +1 −0 searchindex.js
View
92 _modules/index.html
@@ -0,0 +1,92 @@
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Overview: module code &mdash; SoftLayer Object Storage v0.4 documentation</title>
+ <link rel="stylesheet" href="../_static/default.css" type="text/css" />
+ <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: '../',
+ VERSION: '0.4',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="../_static/jquery.js"></script>
+ <script type="text/javascript" src="../_static/underscore.js"></script>
+ <script type="text/javascript" src="../_static/doctools.js"></script>
+ <link rel="top" title="SoftLayer Object Storage v0.4 documentation" href="../index.html" />
+ </head>
+ <body>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ </ul>
+ </div>
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="bodywrapper">
+ <div class="body">
+
+ <h1>All modules for which code is available</h1>
+<ul><li><a href="object_storage.html">object_storage</a></li>
+<ul><li><a href="object_storage/client.html">object_storage.client</a></li>
+<li><a href="object_storage/container.html">object_storage.container</a></li>
+<li><a href="object_storage/storage_object.html">object_storage.storage_object</a></li>
+</ul></ul>
+
+ </div>
+ </div>
+ </div>
+ <div class="sphinxsidebar">
+ <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none">
+ <h3>Quick search</h3>
+ <form class="search" action="../search.html" method="get">
+ <input type="text" name="q" size="18" />
+ <input type="submit" value="Go" />
+ <input type="hidden" name="check_keywords" value="yes" />
+ <input type="hidden" name="area" value="default" />
+ </form>
+ <p class="searchtip" style="font-size: 90%">
+ Enter search terms or a module, class or function name.
+ </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ </ul>
+ </div>
+ <div class="footer">
+ &copy; Copyright 2012 SoftLayer Technologies, Inc..
+ Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
+ </div>
+ </body>
+</html>
View
145 _modules/object_storage.html
@@ -0,0 +1,145 @@
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>object_storage &mdash; SoftLayer Object Storage v0.4 documentation</title>
+ <link rel="stylesheet" href="../_static/default.css" type="text/css" />
+ <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: '../',
+ VERSION: '0.4',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="../_static/jquery.js"></script>
+ <script type="text/javascript" src="../_static/underscore.js"></script>
+ <script type="text/javascript" src="../_static/doctools.js"></script>
+ <link rel="top" title="SoftLayer Object Storage v0.4 documentation" href="../index.html" />
+ <link rel="up" title="Module code" href="index.html" />
+ </head>
+ <body>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li>
+ </ul>
+ </div>
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="bodywrapper">
+ <div class="body">
+
+ <h1>Source code for object_storage</h1><div class="highlight"><pre>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd"> SoftLayer Object Storage python client.</span>
+<span class="sd"> </span>
+<span class="sd"> See COPYING for license information</span>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="kn">from</span> <span class="nn">object_storage.client</span> <span class="kn">import</span> <span class="n">Client</span>
+<span class="kn">from</span> <span class="nn">object_storage.consts</span> <span class="kn">import</span> <span class="n">__version__</span>
+
+<div class="viewcode-block" id="get_client"><a class="viewcode-back" href="../client.html#object_storage.get_client">[docs]</a><span class="k">def</span> <span class="nf">get_client</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns an Object Storage client (using httplib2)</span>
+
+<span class="sd"> @param username: username for Object Storage</span>
+<span class="sd"> @param password: password or api key for Object Storage</span>
+<span class="sd"> @param auth_url: Auth URL for Object Storage</span>
+<span class="sd"> @param auth_token: If provided, bypasses authentication and uses the given auth_token</span>
+<span class="sd"> @return: `object_storage.client.Client` </span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="n">get_httplib2_client</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="get_httplib2_client"><a class="viewcode-back" href="../client.html#object_storage.get_httplib2_client">[docs]</a><span class="k">def</span> <span class="nf">get_httplib2_client</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">auth_url</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">auth_token</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns an Object Storage client (using httplib2)</span>
+
+<span class="sd"> @param username: username for Object Storage</span>
+<span class="sd"> @param password: password or api key for Object Storage</span>
+<span class="sd"> @param auth_url: Auth URL for Object Storage</span>
+<span class="sd"> @param auth_token: If provided, bypasses authentication and uses the given auth_token</span>
+<span class="sd"> @return: `object_storage.client.Client` </span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="kn">from</span> <span class="nn">object_storage.transport.httplib2conn</span> <span class="kn">import</span> <span class="n">AuthenticatedConnection</span><span class="p">,</span> <span class="n">Authentication</span>
+
+ <span class="n">auth</span> <span class="o">=</span> <span class="n">Authentication</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">auth_url</span><span class="o">=</span><span class="n">auth_url</span><span class="p">,</span> <span class="n">auth_token</span><span class="o">=</span><span class="n">auth_token</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+ <span class="n">conn</span> <span class="o">=</span> <span class="n">AuthenticatedConnection</span><span class="p">(</span><span class="n">auth</span><span class="p">)</span>
+ <span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">connection</span><span class="o">=</span><span class="n">conn</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">client</span>
+</div>
+<div class="viewcode-block" id="get_requests_client"><a class="viewcode-back" href="../client.html#object_storage.get_requests_client">[docs]</a><span class="k">def</span> <span class="nf">get_requests_client</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">auth_url</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">auth_token</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns an Object Storage client (using Requests) &quot;&quot;&quot;</span>
+ <span class="kn">from</span> <span class="nn">object_storage.transport.requestsconn</span> <span class="kn">import</span> <span class="n">AuthenticatedConnection</span><span class="p">,</span> <span class="n">Authentication</span>
+
+ <span class="n">auth</span> <span class="o">=</span> <span class="n">Authentication</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">auth_url</span><span class="o">=</span><span class="n">auth_url</span><span class="p">,</span> <span class="n">auth_token</span><span class="o">=</span><span class="n">auth_token</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+ <span class="n">conn</span> <span class="o">=</span> <span class="n">AuthenticatedConnection</span><span class="p">(</span><span class="n">auth</span><span class="p">)</span>
+ <span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">connection</span><span class="o">=</span><span class="n">conn</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">client</span>
+</div>
+<div class="viewcode-block" id="get_twisted_client"><a class="viewcode-back" href="../client.html#object_storage.get_twisted_client">[docs]</a><span class="k">def</span> <span class="nf">get_twisted_client</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">auth_url</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">auth_token</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns an Object Storage client (using Twisted) &quot;&quot;&quot;</span>
+ <span class="kn">from</span> <span class="nn">object_storage.transport.twist</span> <span class="kn">import</span> <span class="n">AuthenticatedConnection</span><span class="p">,</span> <span class="n">Authentication</span>
+
+ <span class="n">auth</span> <span class="o">=</span> <span class="n">Authentication</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">auth_url</span><span class="o">=</span><span class="n">auth_url</span><span class="p">,</span> <span class="n">auth_token</span><span class="o">=</span><span class="n">auth_token</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+ <span class="n">conn</span> <span class="o">=</span> <span class="n">AuthenticatedConnection</span><span class="p">(</span><span class="n">auth</span><span class="p">)</span>
+ <span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">connection</span><span class="o">=</span><span class="n">conn</span><span class="p">)</span>
+
+ <span class="n">d</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">authenticate</span><span class="p">()</span><span class="o">.</span><span class="n">addCallback</span><span class="p">(</span><span class="k">lambda</span> <span class="n">r</span><span class="p">:</span> <span class="n">client</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">d</span></div>
+</pre></div>
+
+ </div>
+ </div>
+ </div>
+ <div class="sphinxsidebar">
+ <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none">
+ <h3>Quick search</h3>
+ <form class="search" action="../search.html" method="get">
+ <input type="text" name="q" size="18" />
+ <input type="submit" value="Go" />
+ <input type="hidden" name="check_keywords" value="yes" />
+ <input type="hidden" name="area" value="default" />
+ </form>
+ <p class="searchtip" style="font-size: 90%">
+ Enter search terms or a module, class or function name.
+ </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ <li><a href="index.html" >Module code</a> &raquo;</li>
+ </ul>
+ </div>
+ <div class="footer">
+ &copy; Copyright 2012 SoftLayer Technologies, Inc..
+ Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
+ </div>
+ </body>
+</html>
View
460 _modules/object_storage/client.html
@@ -0,0 +1,460 @@
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>object_storage.client &mdash; SoftLayer Object Storage v0.4 documentation</title>
+ <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
+ <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: '../../',
+ VERSION: '0.4',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="../../_static/jquery.js"></script>
+ <script type="text/javascript" src="../../_static/underscore.js"></script>
+ <script type="text/javascript" src="../../_static/doctools.js"></script>
+ <link rel="top" title="SoftLayer Object Storage v0.4 documentation" href="../../index.html" />
+ <link rel="up" title="object_storage" href="../object_storage.html" />
+ </head>
+ <body>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../../genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="../../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ <li><a href="../index.html" >Module code</a> &raquo;</li>
+ <li><a href="../object_storage.html" accesskey="U">object_storage</a> &raquo;</li>
+ </ul>
+ </div>
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="bodywrapper">
+ <div class="body">
+
+ <h1>Source code for object_storage.client</h1><div class="highlight"><pre>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd"> Client module. Contains the primary interface for the client.</span>
+
+<span class="sd"> See COPYING for license information.</span>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="k">try</span><span class="p">:</span>
+ <span class="kn">import</span> <span class="nn">simplejson</span> <span class="kn">as</span> <span class="nn">json</span>
+<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
+ <span class="kn">import</span> <span class="nn">json</span>
+
+<span class="kn">from</span> <span class="nn">object_storage.container</span> <span class="kn">import</span> <span class="n">Container</span>
+<span class="kn">from</span> <span class="nn">object_storage.storage_object</span> <span class="kn">import</span> <span class="n">StorageObject</span>
+<span class="kn">from</span> <span class="nn">object_storage.utils</span> <span class="kn">import</span> <span class="n">get_path</span>
+
+<span class="kn">from</span> <span class="nn">object_storage</span> <span class="kn">import</span> <span class="n">errors</span>
+
+<span class="kn">import</span> <span class="nn">logging</span>
+<span class="kn">import</span> <span class="nn">UserDict</span>
+<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
+
+<span class="k">class</span> <span class="nc">AccountModel</span><span class="p">(</span><span class="n">UserDict</span><span class="o">.</span><span class="n">UserDict</span><span class="p">):</span>
+ <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">controller</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{}):</span>
+ <span class="n">_headers</span> <span class="o">=</span> <span class="p">{}</span>
+
+ <span class="c"># Lowercase headers</span>
+ <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">headers</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="n">_key</span> <span class="o">=</span> <span class="n">key</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
+ <span class="n">_headers</span><span class="p">[</span><span class="n">_key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span> <span class="o">=</span> <span class="n">_headers</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span> <span class="o">=</span> <span class="bp">None</span>
+
+ <span class="n">_properties</span> <span class="o">=</span> <span class="p">{}</span>
+
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;container_count&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-account-container-count&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;count&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;object_count&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-account-object-count&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;object_count&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;size&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-account-bytes-used&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;size&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span>
+
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">controller</span><span class="o">.</span><span class="n">path</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;url&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">controller</span><span class="o">.</span><span class="n">url</span>
+
+ <span class="n">meta</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="k">if</span> <span class="n">key</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;meta_&#39;</span><span class="p">):</span>
+ <span class="n">meta</span><span class="p">[</span><span class="n">key</span><span class="p">[</span><span class="mi">5</span><span class="p">:]]</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="k">elif</span> <span class="n">key</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;x-account-meta-&#39;</span><span class="p">):</span>
+ <span class="n">meta</span><span class="p">[</span><span class="n">key</span><span class="p">[</span><span class="mi">15</span><span class="p">:]]</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">meta</span> <span class="o">=</span> <span class="n">meta</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;meta&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">meta</span>
+
+ <span class="bp">self</span><span class="o">.</span><span class="n">properties</span> <span class="o">=</span> <span class="n">_properties</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span>
+
+<div class="viewcode-block" id="Client"><a class="viewcode-back" href="../../client.html#object_storage.client.Client">[docs]</a><span class="k">class</span> <span class="nc">Client</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd"> Client class. Primary interface for the client.</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
+ <span class="n">api_key</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
+ <span class="n">connection</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
+ <span class="n">delimiter</span><span class="o">=</span><span class="s">&#39;/&#39;</span><span class="p">,</span>
+ <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; constructor for Client object</span>
+
+<span class="sd"> @param username: the username</span>
+<span class="sd"> @param api_key: api_key for Object Storage</span>
+<span class="sd"> @param connection: `object_storage.transport.AuthenticatedConnection` </span>
+<span class="sd"> instance.</span>
+<span class="sd"> @param delimiter: the symbol to use to divid up hiearchical divisions </span>
+<span class="sd"> for objects.</span>
+<span class="sd"> @param container_class: factory or class for Container constructing</span>
+<span class="sd"> @param object_class: factory or class for StorageObject constructing</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">api_key</span> <span class="o">=</span> <span class="n">api_key</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span> <span class="o">=</span> <span class="n">delimiter</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">container_class</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;container_class&#39;</span><span class="p">,</span> <span class="n">Container</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">object_class</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;object_class&#39;</span><span class="p">,</span> <span class="n">StorageObject</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">storage_url</span> <span class="o">=</span> <span class="bp">None</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">conn</span> <span class="o">=</span> <span class="n">connection</span>
+
+ <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="bp">None</span>
+
+<div class="viewcode-block" id="Client.load"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.load">[docs]</a> <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; load data for the account </span>
+
+<span class="sd"> @return: object_storage.client, self</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">AccountModel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">res</span><span class="o">.</span><span class="n">headers</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;HEAD&#39;</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.get_info"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.get_info">[docs]</a> <span class="k">def</span> <span class="nf">get_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the properties &quot;&quot;&quot;</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">properties</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Client.properties"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.properties">[docs]</a> <span class="k">def</span> <span class="nf">properties</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the properties &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_info</span><span class="p">()</span></div>
+ <span class="n">props</span> <span class="o">=</span> <span class="n">properties</span>
+
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Client.headers"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.headers">[docs]</a> <span class="k">def</span> <span class="nf">headers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the raw headers for the account &quot;&quot;&quot;</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">headers</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Client.meta"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.meta">[docs]</a> <span class="k">def</span> <span class="nf">meta</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the metadata for the account &quot;&quot;&quot;</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">meta</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Client.path"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.path">[docs]</a> <span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns the file-path. Always returns an empty string. &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="s">&#39;&#39;</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Client.url"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.url">[docs]</a> <span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns the url of the resource. &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_url</span><span class="p">()</span>
+</div>
+<div class="viewcode-block" id="Client.is_dir"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.is_dir">[docs]</a> <span class="k">def</span> <span class="nf">is_dir</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns whether or not this is a directory. Always True. &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">True</span>
+</div>
+<div class="viewcode-block" id="Client.search"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.search">[docs]</a> <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Access the search interface. </span>
+<span class="sd"> @param q: the search query. This can be None.</span>
+<span class="sd"> @param options: options for the search API. Valid options:</span>
+<span class="sd"> q.[fieldname] -&gt; define search query for a specific field.</span>
+<span class="sd"> field -&gt; field name (when using q)</span>
+<span class="sd"> type -&gt; &#39;object&#39; or &#39;container&#39;; default shows both.</span>
+<span class="sd"> recursive -&gt; whether to search recursively or to limit to </span>
+<span class="sd"> one level; default=true</span>
+<span class="sd"> @param **kwargs: to be merged into the options param. </span>
+<span class="sd"> Provides a nicer interface for the same thing.</span>
+
+<span class="sd"> More information on options:</span>
+<span class="sd"> http://sldn.softlayer.com/article/API-Operations-Search-Services</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">default_params</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="s">&#39;format&#39;</span><span class="p">:</span> <span class="s">&#39;json&#39;</span><span class="p">,</span>
+ <span class="s">&#39;q&#39;</span><span class="p">:</span> <span class="n">q</span>
+ <span class="p">}</span>
+ <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="n">options</span> <span class="o">=</span> <span class="n">options</span> <span class="ow">or</span> <span class="p">{}</span>
+ <span class="n">options</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
+ <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">options</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="k">if</span> <span class="n">key</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;q_&#39;</span><span class="p">):</span>
+ <span class="n">params</span><span class="p">[</span><span class="s">&quot;q.</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="p">[</span><span class="mi">2</span><span class="p">:]]</span> <span class="o">=</span> <span class="n">val</span>
+ <span class="k">else</span><span class="p">:</span>
+ <span class="n">params</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
+ <span class="n">params</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">default_params</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="o">+</span> <span class="n">params</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
+ <span class="n">headers</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;X-Context&#39;</span><span class="p">:</span> <span class="s">&#39;search&#39;</span><span class="p">}</span>
+ <span class="n">_path</span> <span class="o">=</span> <span class="bp">None</span>
+ <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">&#39;container&#39;</span><span class="p">):</span>
+ <span class="n">_path</span> <span class="o">=</span> <span class="p">[</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;container&#39;</span><span class="p">]]</span>
+ <span class="k">if</span> <span class="s">&#39;path&#39;</span> <span class="ow">in</span> <span class="n">options</span> <span class="ow">and</span> <span class="nb">type</span><span class="p">(</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;path&#39;</span><span class="p">])</span> <span class="ow">is</span> <span class="ow">not</span> <span class="nb">dict</span><span class="p">:</span>
+ <span class="n">_path</span> <span class="o">=</span> <span class="p">[</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;path&#39;</span><span class="p">]]</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">response</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Formats search results. &quot;&quot;&quot;</span>
+ <span class="n">headers</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span>
+ <span class="n">content</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span>
+ <span class="n">items</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">content</span><span class="p">)</span>
+ <span class="n">objs</span> <span class="o">=</span> <span class="p">[]</span>
+ <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
+ <span class="k">if</span> <span class="s">&#39;type&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">item</span> <span class="ow">or</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;container&#39;</span><span class="p">:</span>
+ <span class="n">objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">container</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">],</span> <span class="n">headers</span><span class="o">=</span><span class="n">item</span><span class="p">))</span>
+ <span class="k">elif</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;object&#39;</span><span class="p">:</span>
+ <span class="n">obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">storage_object</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;container&#39;</span><span class="p">],</span>
+ <span class="n">item</span><span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">],</span>
+ <span class="n">headers</span><span class="o">=</span><span class="n">item</span><span class="p">)</span>
+ <span class="n">objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
+ <span class="n">count</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-search-items-count&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
+ <span class="n">total</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-search-items-total&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
+ <span class="k">return</span> <span class="p">{</span><span class="s">&#39;count&#39;</span><span class="p">:</span> <span class="n">count</span><span class="p">,</span> <span class="s">&#39;total&#39;</span><span class="p">:</span> <span class="n">total</span><span class="p">,</span> <span class="s">&#39;results&#39;</span><span class="p">:</span> <span class="n">objs</span><span class="p">}</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;GET&#39;</span><span class="p">,</span> <span class="n">_path</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span>
+ <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">,</span>
+ <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.set_delimiter"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.set_delimiter">[docs]</a> <span class="k">def</span> <span class="nf">set_delimiter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">delimiter</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Sets the delimiter for pseudo hierarchical directory structure. </span>
+<span class="sd"> @param delimiter: delimiter to use</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">delimiter</span> <span class="o">=</span> <span class="n">delimiter</span>
+</div>
+<div class="viewcode-block" id="Client.set_storage_url"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.set_storage_url">[docs]</a> <span class="k">def</span> <span class="nf">set_storage_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Sets the storage URL. After authentication, the URL is automatically </span>
+<span class="sd"> populated, but the default value can be overwritten.</span>
+
+<span class="sd"> @param url: url to use to call the Object Storage API.</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">storage_url</span> <span class="o">=</span> <span class="n">url</span>
+</div>
+<div class="viewcode-block" id="Client.container"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.container">[docs]</a> <span class="k">def</span> <span class="nf">container</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Initializes container object. </span>
+<span class="sd"> </span>
+<span class="sd"> @param name: name of the container</span>
+<span class="sd"> @param headers: initial headers to use to initialize the object</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">container_class</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">client</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.get_container"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.get_container">[docs]</a> <span class="k">def</span> <span class="nf">get_container</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Makes a container object and calls load() on it. </span>
+<span class="sd"> @param name: container name</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">container</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+</div>
+<div class="viewcode-block" id="Client.set_metadata"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.set_metadata">[docs]</a> <span class="k">def</span> <span class="nf">set_metadata</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{}):</span>
+ <span class="sd">&quot;&quot;&quot; Sets metadata for the account</span>
+
+<span class="sd"> @param meta: dict of metadata on the account</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">meta_headers</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">headers</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="n">meta_headers</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
+ <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">meta</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="n">meta_headers</span><span class="p">[</span><span class="s">&quot;x-account-meta-{0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">)]</span> <span class="o">=</span> <span class="n">v</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;POST&#39;</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">meta_headers</span><span class="p">)</span>
+ </div>
+<div class="viewcode-block" id="Client.create_container"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.create_container">[docs]</a> <span class="k">def</span> <span class="nf">create_container</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Creates a new container</span>
+<span class="sd"> </span>
+<span class="sd"> @param name: container name</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">container</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>
+</div>
+<div class="viewcode-block" id="Client.delete_container"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.delete_container">[docs]</a> <span class="k">def</span> <span class="nf">delete_container</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">recursive</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Deletes a container.</span>
+<span class="sd"> </span>
+<span class="sd"> @param name: container name</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> @raises ContainerNotEmpty if container is not empty</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">if</span> <span class="n">recursive</span><span class="p">:</span>
+ <span class="n">params</span><span class="p">[</span><span class="s">&#39;recursive&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
+ <span class="k">if</span> <span class="n">res</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">is</span> <span class="mi">409</span><span class="p">:</span>
+ <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">ContainerNotEmpty</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">True</span>
+
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;DELETE&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">name</span><span class="p">],</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">)</span>
+ </div>
+<div class="viewcode-block" id="Client.containers"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.containers">[docs]</a> <span class="k">def</span> <span class="nf">containers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">marker</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Lists containers</span>
+<span class="sd"> </span>
+<span class="sd"> @param marker: start listing after this container name</span>
+<span class="sd"> @param headers: extra headers to use when making the listing call</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;format&#39;</span><span class="p">:</span> <span class="s">&#39;json&#39;</span><span class="p">}</span>
+ <span class="k">if</span> <span class="n">marker</span><span class="p">:</span>
+ <span class="n">params</span><span class="p">[</span><span class="s">&#39;marker&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">marker</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
+ <span class="n">containers</span> <span class="o">=</span> <span class="p">[]</span>
+ <span class="k">if</span> <span class="n">res</span><span class="o">.</span><span class="n">content</span><span class="p">:</span>
+ <span class="n">items</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">res</span><span class="o">.</span><span class="n">content</span><span class="p">)</span>
+ <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
+ <span class="n">name</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
+ <span class="n">containers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">container</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">item</span><span class="p">))</span>
+ <span class="k">return</span> <span class="n">containers</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;GET&#39;</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.public_containers"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.public_containers">[docs]</a> <span class="k">def</span> <span class="nf">public_containers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Lists public containers. Same interface as self.containers()</span>
+
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;headers&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;X-Context&#39;</span><span class="p">:</span> <span class="s">&#39;cdn&#39;</span><span class="p">}</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">containers</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.storage_object"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.storage_object">[docs]</a> <span class="k">def</span> <span class="nf">storage_object</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">container</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Initialize a StorageObject instance</span>
+<span class="sd"> </span>
+<span class="sd"> @param container: container name</span>
+<span class="sd"> @param name: object name</span>
+<span class="sd"> @param headers: initial headers to use to initialize the object</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_class</span><span class="p">(</span><span class="n">container</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span>
+ <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">client</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
+ </div>
+<div class="viewcode-block" id="Client.get_object"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.get_object">[docs]</a> <span class="k">def</span> <span class="nf">get_object</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">container</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Load an object from swift</span>
+<span class="sd"> </span>
+<span class="sd"> @param container: container name</span>
+<span class="sd"> @param name: object name</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">storage_object</span><span class="p">(</span><span class="n">container</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ </div>
+<div class="viewcode-block" id="Client.delete_object"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.delete_object">[docs]</a> <span class="k">def</span> <span class="nf">delete_object</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">container</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Delete an object from swift</span>
+<span class="sd"> </span>
+<span class="sd"> @param container: container name</span>
+<span class="sd"> @param name: object name</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;DELETE&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">container</span><span class="p">,</span> <span class="n">name</span><span class="p">],</span> <span class="n">formatter</span><span class="o">=</span><span class="k">lambda</span> <span class="n">r</span><span class="p">:</span> <span class="bp">True</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.get_url"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.get_url">[docs]</a> <span class="k">def</span> <span class="nf">get_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns the url of the resource</span>
+<span class="sd"> </span>
+<span class="sd"> @param path: path to append to the end of the URL</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">storage_url</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="n">url</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">storage_url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conn</span><span class="o">.</span><span class="n">storage_url</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">storage_url</span>
+ <span class="k">if</span> <span class="n">path</span><span class="p">:</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">/</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">get_path</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
+ <span class="k">return</span> <span class="n">url</span>
+</div>
+<div class="viewcode-block" id="Client.make_request"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.make_request">[docs]</a> <span class="k">def</span> <span class="nf">make_request</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">method</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Make an HTTP request</span>
+<span class="sd"> </span>
+<span class="sd"> @param method: HTTP method (GET, HEAD, POST, PUT, ...)</span>
+<span class="sd"> @param path: path</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_url</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
+ <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conn</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="n">method</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">result</span>
+</div>
+<div class="viewcode-block" id="Client.chunk_download"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.chunk_download">[docs]</a> <span class="k">def</span> <span class="nf">chunk_download</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">chunk_size</span><span class="o">=</span><span class="mi">10</span><span class="o">*</span><span class="mi">1024</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns a chunk download generator</span>
+<span class="sd"> </span>
+<span class="sd"> @param path: path</span>
+<span class="sd"> @param chunk_size: the max size in bytes to return on each yield</span>
+<span class="sd"> @param headers: extra headers to use with this request</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_url</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">conn</span><span class="o">.</span><span class="n">chunk_download</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">chunk_size</span><span class="o">=</span><span class="n">chunk_size</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Client.chunk_upload"><a class="viewcode-back" href="../../client.html#object_storage.client.Client.chunk_upload">[docs]</a> <span class="k">def</span> <span class="nf">chunk_upload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns a chunkable connection object at the given path</span>
+<span class="sd"> </span>
+<span class="sd"> @param path: path</span>
+<span class="sd"> @param headers: extra headers to use with this request</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_url</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">conn</span><span class="o">.</span><span class="n">chunk_upload</span><span class="p">(</span><span class="s">&#39;PUT&#39;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">headers</span><span class="p">)</span>
+</div>
+ <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns a container object with the given name &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">container</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
+
+ <span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns an interator based on results of self.containers() &quot;&quot;&quot;</span>
+ <span class="n">listing</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">containers</span><span class="p">()</span>
+ <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="n">listing</span><span class="p">:</span>
+ <span class="k">yield</span> <span class="n">obj</span></div>
+</pre></div>
+
+ </div>
+ </div>
+ </div>
+ <div class="sphinxsidebar">
+ <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none">
+ <h3>Quick search</h3>
+ <form class="search" action="../../search.html" method="get">
+ <input type="text" name="q" size="18" />
+ <input type="submit" value="Go" />
+ <input type="hidden" name="check_keywords" value="yes" />
+ <input type="hidden" name="area" value="default" />
+ </form>
+ <p class="searchtip" style="font-size: 90%">
+ Enter search terms or a module, class or function name.
+ </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../../genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="../../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ <li><a href="../index.html" >Module code</a> &raquo;</li>
+ <li><a href="../object_storage.html" >object_storage</a> &raquo;</li>
+ </ul>
+ </div>
+ <div class="footer">
+ &copy; Copyright 2012 SoftLayer Technologies, Inc..
+ Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
+ </div>
+ </body>
+</html>
View
410 _modules/object_storage/container.html
@@ -0,0 +1,410 @@
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>object_storage.container &mdash; SoftLayer Object Storage v0.4 documentation</title>
+ <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
+ <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: '../../',
+ VERSION: '0.4',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="../../_static/jquery.js"></script>
+ <script type="text/javascript" src="../../_static/underscore.js"></script>
+ <script type="text/javascript" src="../../_static/doctools.js"></script>
+ <link rel="top" title="SoftLayer Object Storage v0.4 documentation" href="../../index.html" />
+ <link rel="up" title="object_storage" href="../object_storage.html" />
+ </head>
+ <body>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="../../genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="../../py-modindex.html" title="Python Module Index"
+ >modules</a> |</li>
+ <li><a href="../../index.html">SoftLayer Object Storage v0.4 documentation</a> &raquo;</li>
+ <li><a href="../index.html" >Module code</a> &raquo;</li>
+ <li><a href="../object_storage.html" accesskey="U">object_storage</a> &raquo;</li>
+ </ul>
+ </div>
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="bodywrapper">
+ <div class="body">
+
+ <h1>Source code for object_storage.container</h1><div class="highlight"><pre>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd"> Container module</span>
+
+<span class="sd"> See COPYING for license information</span>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="kn">import</span> <span class="nn">json</span>
+<span class="kn">import</span> <span class="nn">os</span>
+<span class="kn">import</span> <span class="nn">UserDict</span>
+<span class="kn">from</span> <span class="nn">object_storage</span> <span class="kn">import</span> <span class="n">errors</span>
+<span class="kn">from</span> <span class="nn">object_storage.storage_object</span> <span class="kn">import</span> <span class="n">StorageObject</span>
+<span class="kn">from</span> <span class="nn">object_storage.utils</span> <span class="kn">import</span> <span class="n">get_path</span>
+
+<span class="k">class</span> <span class="nc">ContainerModel</span><span class="p">(</span><span class="n">UserDict</span><span class="o">.</span><span class="n">UserDict</span><span class="p">):</span>
+ <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">controller</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{}):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
+ <span class="n">_headers</span> <span class="o">=</span> <span class="p">{}</span>
+
+ <span class="c"># Lowercase headers</span>
+ <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">headers</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="n">_key</span> <span class="o">=</span> <span class="n">key</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
+ <span class="n">_headers</span><span class="p">[</span><span class="n">_key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span> <span class="o">=</span> <span class="n">_headers</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span> <span class="o">=</span> <span class="bp">None</span>
+
+ <span class="n">_properties</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">}</span>
+
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;count&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-container-object-count&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;count&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;object_count&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;count&#39;</span><span class="p">]</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;size&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-container-bytes-used&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;size&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;read&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-container-read&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;read&#39;</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;write&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-container-read&#39;</span><span class="p">)</span> <span class="ow">or</span>\
+ <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;read&#39;</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-cdn-ttl&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;date&#39;</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;cdn_url&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-cdn-url&#39;</span><span class="p">)</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;cdn_ssl_url&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;x-cdn-ssl-url&#39;</span><span class="p">)</span>
+
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">controller</span><span class="o">.</span><span class="n">path</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;url&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">controller</span><span class="o">.</span><span class="n">url</span>
+
+ <span class="n">meta</span> <span class="o">=</span> <span class="p">{}</span>
+
+ <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="k">if</span> <span class="n">key</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;meta_&#39;</span><span class="p">):</span>
+ <span class="n">meta</span><span class="p">[</span><span class="n">key</span><span class="p">[</span><span class="mi">5</span><span class="p">:]]</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="k">elif</span> <span class="n">key</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;x-container-meta-&#39;</span><span class="p">):</span>
+ <span class="n">meta</span><span class="p">[</span><span class="n">key</span><span class="p">[</span><span class="mi">17</span><span class="p">:]]</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">meta</span> <span class="o">=</span> <span class="n">meta</span>
+ <span class="n">_properties</span><span class="p">[</span><span class="s">&#39;meta&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">meta</span>
+
+ <span class="bp">self</span><span class="o">.</span><span class="n">properties</span> <span class="o">=</span> <span class="n">_properties</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span>
+
+<div class="viewcode-block" id="Container"><a class="viewcode-back" href="../../container.html#object_storage.container.Container">[docs]</a><span class="k">class</span> <span class="nc">Container</span><span class="p">:</span>
+ <span class="sd">&quot;&quot;&quot; Container class. Encapsulates Storage containers. &quot;&quot;&quot;</span>
+ <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">client</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; constructor for Container</span>
+
+<span class="sd"> @param name: container name</span>
+<span class="sd"> @param headers: init headers to use when initializing the container</span>
+<span class="sd"> @param client: `object_storage.client` instance.</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">client</span> <span class="o">=</span> <span class="n">client</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="bp">None</span>
+ <span class="k">if</span> <span class="n">headers</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">ContainerModel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">headers</span><span class="p">)</span>
+
+<div class="viewcode-block" id="Container.exists"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.exists">[docs]</a> <span class="k">def</span> <span class="nf">exists</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Tries to load the container to check existance</span>
+
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> @return: boolean, true if exists else false</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">ContainerModel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">res</span><span class="o">.</span><span class="n">headers</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">True</span>
+ <span class="k">try</span><span class="p">:</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;HEAD&#39;</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">)</span>
+ <span class="k">except</span> <span class="n">errors</span><span class="o">.</span><span class="n">NotFound</span><span class="p">:</span>
+ <span class="k">return</span> <span class="bp">False</span>
+</div>
+<div class="viewcode-block" id="Container.load"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.load">[docs]</a> <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cdn</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; load data for the container</span>
+
+<span class="sd"> @param cdn: True if you want CDN information; default=True</span>
+<span class="sd"> @return: object_storage.container, self</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">headers</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">if</span> <span class="n">cdn</span><span class="p">:</span>
+ <span class="n">headers</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s">&#39;X-Context&#39;</span><span class="p">,</span> <span class="s">&#39;cdn&#39;</span><span class="p">)</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">ContainerModel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">res</span><span class="o">.</span><span class="n">headers</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;HEAD&#39;</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Container.get_info"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.get_info">[docs]</a> <span class="k">def</span> <span class="nf">get_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the properties &quot;&quot;&quot;</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">properties</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Container.properties"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.properties">[docs]</a> <span class="k">def</span> <span class="nf">properties</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the properties &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_info</span><span class="p">()</span></div>
+ <span class="n">props</span> <span class="o">=</span> <span class="n">properties</span>
+
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Container.headers"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.headers">[docs]</a> <span class="k">def</span> <span class="nf">headers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the raw headers for the container &quot;&quot;&quot;</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">headers</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Container.meta"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.meta">[docs]</a> <span class="k">def</span> <span class="nf">meta</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; loads data if not already available and returns the metadata for the container &quot;&quot;&quot;</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">:</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">meta</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Container.path"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.path">[docs]</a> <span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; returns path of the container &quot;&quot;&quot;</span>
+ <span class="n">path</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
+ <span class="k">return</span> <span class="n">get_path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
+</div>
+ <span class="nd">@property</span>
+<div class="viewcode-block" id="Container.url"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.url">[docs]</a> <span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns the url of the container &quot;&quot;&quot;</span>
+ <span class="n">path</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">get_url</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Container.is_dir"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.is_dir">[docs]</a> <span class="k">def</span> <span class="nf">is_dir</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Returns if the container is a directory (always True) &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">True</span>
+</div>
+<div class="viewcode-block" id="Container.set_metadata"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.set_metadata">[docs]</a> <span class="k">def</span> <span class="nf">set_metadata</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">meta</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Sets metadata for the container</span>
+
+<span class="sd"> @param meta: dict of metadata on the container</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">meta_headers</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">meta</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+ <span class="n">meta_headers</span><span class="p">[</span><span class="s">&quot;x-container-meta-{0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">)]</span> <span class="o">=</span> <span class="n">v</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;POST&#39;</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">meta_headers</span><span class="p">)</span>
+</div>
+<div class="viewcode-block" id="Container.create"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.create">[docs]</a> <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Create container</span>
+<span class="sd"> </span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> @return: Containert - self</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">def</span> <span class="nf">_formatter</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
+ <span class="k">return</span> <span class="bp">self</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">make_request</span><span class="p">(</span><span class="s">&#39;PUT&#39;</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="n">_formatter</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;Content-Length&#39;</span><span class="p">:</span> <span class="s">&#39;0&#39;</span><span class="p">})</span>
+</div>
+<div class="viewcode-block" id="Container.delete"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.delete">[docs]</a> <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">recursive</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Delete container</span>
+<span class="sd"> </span>
+<span class="sd"> @param recursive: true if you want to delete all of the </span>
+<span class="sd"> objects in the container as well.</span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> @return: True</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">delete_container</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">recursive</span><span class="o">=</span><span class="n">recursive</span><span class="p">)</span>
+ </div>
+<div class="viewcode-block" id="Container.delete_all_objects"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.delete_all_objects">[docs]</a> <span class="k">def</span> <span class="nf">delete_all_objects</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Deletes all objects in the container</span>
+<span class="sd"> </span>
+<span class="sd"> @raises ResponseError</span>
+<span class="sd"> &quot;&quot;&quot;</span>
+ <span class="n">resps</span> <span class="o">=</span> <span class="p">[]</span>
+ <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">list</span><span class="p">():</span>
+ <span class="n">resps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">delete</span><span class="p">())</span>
+ <span class="k">return</span> <span class="n">resps</span>
+ </div>
+<div class="viewcode-block" id="Container.delete_object"><a class="viewcode-back" href="../../container.html#object_storage.container.Container.delete_object">[docs]</a> <span class="k">def</span> <span class="nf">delete_object</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
+ <span class="sd">&quot;&quot;&quot; Deletes an object in the container</span>
+<span class="sd"> </span>
+<