Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added compiled docs to the repo. Better documented public methods. Ch…

…anged search api back to accepting a query string as the first param and either kwargs or the second parameter to define options. Fixed tests.
  • Loading branch information...
commit d237ba7b14a8135171bb57a7da192eef7d99e174 1 parent 50bfaac
@sudorandom sudorandom authored
Showing with 10,097 additions and 90 deletions.
  1. +0 −1  .gitignore
  2. +4 −4 README.markdown
  3. BIN  docs/build/doctrees/client.doctree
  4. BIN  docs/build/doctrees/container.doctree
  5. BIN  docs/build/doctrees/environment.pickle
  6. BIN  docs/build/doctrees/index.doctree
  7. BIN  docs/build/doctrees/license.doctree
  8. BIN  docs/build/doctrees/object.doctree
  9. +4 −0 docs/build/html/.buildinfo
  10. +92 −0 docs/build/html/_modules/index.html
  11. +145 −0 docs/build/html/_modules/object_storage.html
  12. +460 −0 docs/build/html/_modules/object_storage/client.html
  13. +410 −0 docs/build/html/_modules/object_storage/container.html
  14. +509 −0 docs/build/html/_modules/object_storage/storage_object.html
  15. +14 −0 docs/build/html/_sources/client.txt
  16. +9 −0 docs/build/html/_sources/container.txt
  17. +31 −0 docs/build/html/_sources/index.txt
  18. +34 −0 docs/build/html/_sources/license.txt
  19. +9 −0 docs/build/html/_sources/object.txt
  20. +509 −0 docs/build/html/_static/basic.css
  21. +255 −0 docs/build/html/_static/default.css
  22. +247 −0 docs/build/html/_static/doctools.js
  23. BIN  docs/build/html/_static/file.png
  24. +4,376 −0 docs/build/html/_static/jquery.js
  25. BIN  docs/build/html/_static/minus.png
  26. BIN  docs/build/html/_static/plus.png
  27. +61 −0 docs/build/html/_static/pygments.css
  28. +518 −0 docs/build/html/_static/searchtools.js
  29. +147 −0 docs/build/html/_static/sidebar.js
  30. +16 −0 docs/build/html/_static/underscore.js
  31. +381 −0 docs/build/html/client.html
  32. +338 −0 docs/build/html/container.html
  33. +348 −0 docs/build/html/genindex.html
  34. +133 −0 docs/build/html/index.html
  35. +118 −0 docs/build/html/license.html
  36. +359 −0 docs/build/html/object.html
  37. BIN  docs/build/html/objects.inv
  38. +111 −0 docs/build/html/py-modindex.html
  39. +102 −0 docs/build/html/search.html
  40. +1 −0  docs/build/html/searchindex.js
  41. +5 −5 docs/source/object.rst
  42. +16 −2 object_storage/__init__.py
  43. +123 −33 object_storage/client.py
  44. +88 −8 object_storage/container.py
  45. +116 −27 object_storage/storage_object.py
  46. +6 −6 tests/integration/httplib.py
  47. +0 −1  tests/unit/authentication.py
  48. +2 −3 tests/unit/container.py
View
1  .gitignore
@@ -1,6 +1,5 @@
*.swp
*.pyc
-build
dist
*.log
*.egg-info
View
8 README.markdown
@@ -58,16 +58,16 @@ sl_storage['foo'].delete()
Search Usage
------------
```python
-sl_storage.search({'q': 'foo'})
+sl_storage.search('foo')
# {'count': 2, 'total': 2, 'results': [Container(foo), StorageObject(bar, foo)]}
-sl_storage['foo'].search({'q': 'bar.txt'})
+sl_storage['foo'].search('bar.txt')
# {'count': 1, 'total': 1, 'results': [StorageObject(foo, bar.txt)]}
-sl_storage.search({'q': 'foo', 'type': 'container'})
+sl_storage.search('foo', type='container')
# {'count': 1, 'total': 1, 'results': [Container(foo)]}
-sl_storage.search({'q': 'foo*baz'})
+sl_storage.search('foo*baz')
# {'count': 1, 'total': 1, 'results': [Container(foobarbaz)]}
```
View
BIN  docs/build/doctrees/client.doctree
Binary file not shown
View
BIN  docs/build/doctrees/container.doctree
Binary file not shown
View
BIN  docs/build/doctrees/environment.pickle
Binary file not shown
View
BIN  docs/build/doctrees/index.doctree
Binary file not shown
View
BIN  docs/build/doctrees/license.doctree
Binary file not shown
View
BIN  docs/build/doctrees/object.doctree
Binary file not shown
View
4 docs/build/html/.buildinfo
@@ -0,0 +1,4 @@
+# Sphinx build info version 1
+# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
+config:
+tags:
View
92 docs/build/html/_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 docs/build/html/_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 docs/build/html/_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 docs/build/html/_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=