~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/dirdbm.html

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
 
2
  <head>
 
3
<title>Twisted Documentation: DirDBM: Directory-based Storage</title>
 
4
<link href="stylesheet.css" rel="stylesheet" type="text/css"/>
 
5
  </head>
 
6
 
 
7
  <body bgcolor="white">
 
8
    <h1 class="title">DirDBM: Directory-based Storage</h1>
 
9
    <div class="toc"><ol><li><a href="#auto0">dirdbm.DirDBM</a></li><li><a href="#auto1">dirdbm.Shelf</a></li></ol></div>
 
10
    <div class="content">
 
11
<span/>
 
12
 
 
13
<h2>dirdbm.DirDBM<a name="auto0"/></h2>
 
14
 
 
15
<p><code class="API"><a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.persisted.dirdbm.DirDBM.html" title="twisted.persisted.dirdbm.DirDBM">twisted.persisted.dirdbm.DirDBM</a></code> is a DBM-like storage system. 
 
16
That is, it stores mappings between keys
 
17
and values, like a Python dictionary, except that it stores the values in files
 
18
in a directory - each entry is a different file. The keys must always be strings,
 
19
as are the values. Other than that, <code class="API"><a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.persisted.dirdbm.DirDBM.html" title="twisted.persisted.dirdbm.DirDBM">DirDBM</a></code>
 
20
objects act just like Python dictionaries.</p>
 
21
 
 
22
<p><code class="API"><a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.persisted.dirdbm.DirDBM.html" title="twisted.persisted.dirdbm.DirDBM">DirDBM</a></code> is useful for cases
 
23
when you want to store small amounts of data in an organized fashion, without having
 
24
to deal with the complexity of a RDBMS or other sophisticated database. It is simple,
 
25
easy to use, cross-platform, and doesn't require any external C libraries, unlike
 
26
Python's built-in DBM modules.</p>
 
27
 
 
28
<pre class="python-interpreter" xml:space="preserve">
 
29
&gt;&gt;&gt; from twisted.persisted import dirdbm
 
30
&gt;&gt;&gt; d = dirdbm.DirDBM(&quot;/tmp/dir&quot;)
 
31
&gt;&gt;&gt; d[&quot;librarian&quot;] = &quot;ook&quot;
 
32
&gt;&gt;&gt; d[&quot;librarian&quot;]        
 
33
'ook'
 
34
&gt;&gt;&gt; d.keys()
 
35
['librarian']
 
36
&gt;&gt;&gt; del d[&quot;librarian&quot;]
 
37
&gt;&gt;&gt; d.items()
 
38
[]
 
39
</pre>
 
40
 
 
41
<h2>dirdbm.Shelf<a name="auto1"/></h2>
 
42
 
 
43
<p>Sometimes it is neccessary to persist more complicated objects than strings.
 
44
With some care, <code class="API"><a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.persisted.dirdbm.Shelf.html" title="twisted.persisted.dirdbm.Shelf">dirdbm.Shelf</a></code>
 
45
can transparently persist
 
46
them. <code>Shelf</code> works exactly like <code>DirDBM</code>, except that
 
47
the values (but not the keys) can be arbitrary picklable objects. However,
 
48
notice that mutating an object after it has been stored in the
 
49
<code>Shelf</code> has no effect on the Shelf.
 
50
When mutating objects, it is neccessary to explictly store them back in the <code>Shelf</code>
 
51
afterwards:</p>
 
52
 
 
53
<pre class="python-interpreter" xml:space="preserve">
 
54
&gt;&gt;&gt; from twisted.persisted import dirdbm
 
55
&gt;&gt;&gt; d = dirdbm.Shelf(&quot;/tmp/dir2&quot;)
 
56
&gt;&gt;&gt; d[&quot;key&quot;] = [1, 2]
 
57
&gt;&gt;&gt; d[&quot;key&quot;]
 
58
[1, 2]
 
59
&gt;&gt;&gt; l = d[&quot;key&quot;]
 
60
&gt;&gt;&gt; l.append(3)
 
61
&gt;&gt;&gt; d[&quot;key&quot;]
 
62
[1, 2]
 
63
&gt;&gt;&gt; d[&quot;key&quot;] = l
 
64
&gt;&gt;&gt; d[&quot;key&quot;]
 
65
[1, 2, 3]
 
66
</pre>
 
67
 
 
68
 
 
69
 
 
70
 
 
71
 
 
72
  </div>
 
73
 
 
74
    <p><a href="index.html">Index</a></p>
 
75
    <span class="version">Version: 10.0.0</span>
 
76
  </body>
 
77
</html>
 
 
b'\\ No newline at end of file'