annotate roundup/hyperdb.py @ 1550:905f92b97d4e maint-0.5

backport of mail address case problem from HEAD
author Richard Jones <richard@users.sourceforge.net>
date Mon, 24 Mar 2003 04:53:15 +0000
parents 83f33642d220
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1356
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 # This module is free software, and you may redistribute it and/or modify
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4 # under the same terms as Python, so long as this copyright message and
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
5 # disclaimer are retained in their original form.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
6 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
10 # POSSIBILITY OF SUCH DAMAGE.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
18 # $Id: hyperdb.py,v 1.84 2002-10-07 00:52:51 richard Exp $
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
19
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
20 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
21 Hyperdatabase implementation, especially field types.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
22 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
24 # standard python modules
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25 import sys, os, time, re
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
26
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
27 # roundup modules
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
28 import date, password
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
29
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
30 # configure up the DEBUG and TRACE captures
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
31 class Sink:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
32 def write(self, content):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
33 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
34 DEBUG = os.environ.get('HYPERDBDEBUG', '')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
35 if DEBUG and __debug__:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
36 if DEBUG == 'stdout':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
37 DEBUG = sys.stdout
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
38 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
39 DEBUG = open(DEBUG, 'a')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
40 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
41 DEBUG = Sink()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
42 TRACE = os.environ.get('HYPERDBTRACE', '')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
43 if TRACE and __debug__:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
44 if TRACE == 'stdout':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
45 TRACE = sys.stdout
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
46 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
47 TRACE = open(TRACE, 'w')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
49 TRACE = Sink()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
50 def traceMark():
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
51 print >>TRACE, '**MARK', time.ctime()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
52 del Sink
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
53
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
54 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
55 # Types
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
56 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
57 class String:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
58 """An object designating a String property."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
59 def __init__(self, indexme='no'):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
60 self.indexme = indexme == 'yes'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
61 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
62 ' more useful for dumps '
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
63 return '<%s>'%self.__class__
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
64
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
65 class Password:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
66 """An object designating a Password property."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
67 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
68 ' more useful for dumps '
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
69 return '<%s>'%self.__class__
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
70
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
71 class Date:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
72 """An object designating a Date property."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
73 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
74 ' more useful for dumps '
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
75 return '<%s>'%self.__class__
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
76
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
77 class Interval:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
78 """An object designating an Interval property."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
79 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
80 ' more useful for dumps '
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
81 return '<%s>'%self.__class__
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
82
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
83 class Link:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
84 """An object designating a Link property that links to a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
85 node in a specified class."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
86 def __init__(self, classname, do_journal='yes'):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
87 ''' Default is to not journal link and unlink events
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
88 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
89 self.classname = classname
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
90 self.do_journal = do_journal == 'yes'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
91 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
92 ' more useful for dumps '
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
93 return '<%s to "%s">'%(self.__class__, self.classname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
94
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
95 class Multilink:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
96 """An object designating a Multilink property that links
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97 to nodes in a specified class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
98
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
99 "classname" indicates the class to link to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
100
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
101 "do_journal" indicates whether the linked-to nodes should have
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
102 'link' and 'unlink' events placed in their journal
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
103 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
104 def __init__(self, classname, do_journal='yes'):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
105 ''' Default is to not journal link and unlink events
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
106 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
107 self.classname = classname
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
108 self.do_journal = do_journal == 'yes'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
109 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
110 ' more useful for dumps '
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
111 return '<%s to "%s">'%(self.__class__, self.classname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
112
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
113 class Boolean:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
114 """An object designating a boolean property"""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
115 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
116 'more useful for dumps'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
117 return '<%s>' % self.__class__
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
118
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
119 class Number:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
120 """An object designating a numeric property"""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
121 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
122 'more useful for dumps'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
123 return '<%s>' % self.__class__
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
124 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
125 # Support for splitting designators
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
126 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
127 class DesignatorError(ValueError):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
128 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
129 def splitDesignator(designator, dre=re.compile(r'([^\d]+)(\d+)')):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
130 ''' Take a foo123 and return ('foo', 123)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
132 m = dre.match(designator)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
133 if m is None:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
134 raise DesignatorError, '"%s" not a node designator'%designator
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
135 return m.group(1), m.group(2)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
136
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
137 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
138 # the base Database class
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
139 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
140 class DatabaseError(ValueError):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
141 '''Error to be raised when there is some problem in the database code
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
142 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
143 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
144 class Database:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
145 '''A database for storing records containing flexible data types.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
146
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
147 This class defines a hyperdatabase storage layer, which the Classes use to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
148 store their data.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
149
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
150
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
151 Transactions
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
152 ------------
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
153 The Database should support transactions through the commit() and
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
154 rollback() methods. All other Database methods should be transaction-aware,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
155 using data from the current transaction before looking up the database.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
156
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
157 An implementation must provide an override for the get() method so that the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
158 in-database value is returned in preference to the in-transaction value.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
159 This is necessary to determine if any values have changed during a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
160 transaction.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
161
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
162
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
163 Implementation
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
164 --------------
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
165
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
166 All methods except __repr__ and getnode must be implemented by a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
167 concrete backend Class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
168
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
169 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
170
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
171 # flag to set on retired entries
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
172 RETIRED_FLAG = '__hyperdb_retired'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
173
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
174 def __init__(self, config, journaltag=None):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
175 """Open a hyperdatabase given a specifier to some storage.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
176
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
177 The 'storagelocator' is obtained from config.DATABASE.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
178 The meaning of 'storagelocator' depends on the particular
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
179 implementation of the hyperdatabase. It could be a file name,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
180 a directory path, a socket descriptor for a connection to a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
181 database over the network, etc.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
182
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
183 The 'journaltag' is a token that will be attached to the journal
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
184 entries for any edits done on the database. If 'journaltag' is
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
185 None, the database is opened in read-only mode: the Class.create(),
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
186 Class.set(), and Class.retire() methods are disabled.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
187 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
188 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
189
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
190 def post_init(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
191 """Called once the schema initialisation has finished."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
192 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
193
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
194 def __getattr__(self, classname):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
195 """A convenient way of calling self.getclass(classname)."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
196 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
197
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
198 def addclass(self, cl):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
199 '''Add a Class to the hyperdatabase.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
200 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
201 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
202
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
203 def getclasses(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
204 """Return a list of the names of all existing classes."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
205 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
206
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
207 def getclass(self, classname):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
208 """Get the Class object representing a particular class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
209
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
210 If 'classname' is not a valid class name, a KeyError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
211 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
212 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
213
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
214 def clear(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
215 '''Delete all database contents.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
216 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
217 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
218
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
219 def getclassdb(self, classname, mode='r'):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
220 '''Obtain a connection to the class db that will be used for
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
221 multiple actions.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
222 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
223 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
224
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
225 def addnode(self, classname, nodeid, node):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
226 '''Add the specified node to its class's db.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
227 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
228 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
229
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
230 def serialise(self, classname, node):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
231 '''Copy the node contents, converting non-marshallable data into
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
232 marshallable data.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
233 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
234 return node
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
235
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
236 def setnode(self, classname, nodeid, node):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
237 '''Change the specified node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
238 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
239 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
240
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
241 def unserialise(self, classname, node):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
242 '''Decode the marshalled node data
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
243 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
244 return node
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
245
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
246 def getnode(self, classname, nodeid, db=None, cache=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
247 '''Get a node from the database.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
248 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
249 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
250
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
251 def hasnode(self, classname, nodeid, db=None):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
252 '''Determine if the database has a given node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
253 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
254 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
255
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
256 def countnodes(self, classname, db=None):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
257 '''Count the number of nodes that exist for a particular Class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
258 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
259 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
260
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
261 def getnodeids(self, classname, db=None):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
262 '''Retrieve all the ids of the nodes for a particular Class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
263 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
264 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
265
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
266 def storefile(self, classname, nodeid, property, content):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
267 '''Store the content of the file in the database.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
268
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
269 The property may be None, in which case the filename does not
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
270 indicate which property is being saved.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
271 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
272 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
273
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
274 def getfile(self, classname, nodeid, property):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
275 '''Store the content of the file in the database.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
276 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
277 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
278
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
279 def addjournal(self, classname, nodeid, action, params):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
280 ''' Journal the Action
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
281 'action' may be:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
282
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
283 'create' or 'set' -- 'params' is a dictionary of property values
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
284 'link' or 'unlink' -- 'params' is (classname, nodeid, propname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
285 'retire' -- 'params' is None
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
286 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
287 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
288
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
289 def getjournal(self, classname, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
290 ''' get the journal for id
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
291 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
292 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
293
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
294 def pack(self, pack_before):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
295 ''' pack the database
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
296 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
297 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
298
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
299 def commit(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
300 ''' Commit the current transactions.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
301
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
302 Save all data changed since the database was opened or since the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
303 last commit() or rollback().
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
304 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
305 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
306
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
307 def rollback(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
308 ''' Reverse all actions from the current transaction.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
309
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
310 Undo all the changes made since the database was opened or the last
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
311 commit() or rollback() was performed.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
312 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
313 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
314
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
315 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
316 # The base Class class
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
317 #
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
318 class Class:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
319 """ The handle to a particular class of nodes in a hyperdatabase.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
320
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
321 All methods except __repr__ and getnode must be implemented by a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
322 concrete backend Class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
323 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
324
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
325 def __init__(self, db, classname, **properties):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
326 """Create a new class with a given name and property specification.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
327
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
328 'classname' must not collide with the name of an existing class,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
329 or a ValueError is raised. The keyword arguments in 'properties'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
330 must map names to property objects, or a TypeError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
331 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
332 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
333
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
334 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
335 '''Slightly more useful representation
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
336 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
337 return '<hyperdb.Class "%s">'%self.classname
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
338
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
339 # Editing nodes:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
340
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
341 def create(self, **propvalues):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
342 """Create a new node of this class and return its id.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
343
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
344 The keyword arguments in 'propvalues' map property names to values.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
345
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
346 The values of arguments must be acceptable for the types of their
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
347 corresponding properties or a TypeError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
348
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
349 If this class has a key property, it must be present and its value
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
350 must not collide with other key strings or a ValueError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
351
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
352 Any other properties on this class that are missing from the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
353 'propvalues' dictionary are set to None.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
354
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
355 If an id in a link or multilink property does not refer to a valid
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
356 node, an IndexError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
357 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
358 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
359
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
360 _marker = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
361 def get(self, nodeid, propname, default=_marker, cache=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
362 """Get the value of a property on an existing node of this class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
363
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
364 'nodeid' must be the id of an existing node of this class or an
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
365 IndexError is raised. 'propname' must be the name of a property
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
366 of this class or a KeyError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
367
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
368 'cache' indicates whether the transaction cache should be queried
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
369 for the node. If the node has been modified and you need to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
370 determine what its values prior to modification are, you need to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
371 set cache=0.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
372 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
373 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
374
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
375 def getnode(self, nodeid, cache=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
376 ''' Return a convenience wrapper for the node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
377
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
378 'nodeid' must be the id of an existing node of this class or an
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
379 IndexError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
380
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
381 'cache' indicates whether the transaction cache should be queried
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
382 for the node. If the node has been modified and you need to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
383 determine what its values prior to modification are, you need to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
384 set cache=0.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
385 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
386 return Node(self, nodeid, cache=cache)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
387
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
388 def set(self, nodeid, **propvalues):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
389 """Modify a property on an existing node of this class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
390
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
391 'nodeid' must be the id of an existing node of this class or an
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
392 IndexError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
393
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
394 Each key in 'propvalues' must be the name of a property of this
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
395 class or a KeyError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
396
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
397 All values in 'propvalues' must be acceptable types for their
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
398 corresponding properties or a TypeError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
399
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
400 If the value of the key property is set, it must not collide with
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
401 other key strings or a ValueError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
402
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
403 If the value of a Link or Multilink property contains an invalid
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
404 node id, a ValueError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
405 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
406 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
407
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
408 def retire(self, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
409 """Retire a node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
410
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
411 The properties on the node remain available from the get() method,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
412 and the node's id is never reused.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
413
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
414 Retired nodes are not returned by the find(), list(), or lookup()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
415 methods, and other nodes may reuse the values of their key properties.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
416 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
417 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
418
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
419 def is_retired(self, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
420 '''Return true if the node is rerired
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
421 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
422 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
423
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
424 def destroy(self, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
425 """Destroy a node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
426
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
427 WARNING: this method should never be used except in extremely rare
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
428 situations where there could never be links to the node being
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
429 deleted
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
430 WARNING: use retire() instead
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
431 WARNING: the properties of this node will not be available ever again
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
432 WARNING: really, use retire() instead
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
433
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
434 Well, I think that's enough warnings. This method exists mostly to
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
435 support the session storage of the cgi interface.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
436
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
437 The node is completely removed from the hyperdb, including all journal
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
438 entries. It will no longer be available, and will generally break code
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
439 if there are any references to the node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
440 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
441
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
442 def history(self, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
443 """Retrieve the journal of edits on a particular node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
444
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
445 'nodeid' must be the id of an existing node of this class or an
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
446 IndexError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
447
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
448 The returned list contains tuples of the form
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
449
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
450 (date, tag, action, params)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
451
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
452 'date' is a Timestamp object specifying the time of the change and
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
453 'tag' is the journaltag specified when the database was opened.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
454 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
455 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
456
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
457 # Locating nodes:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
458 def hasnode(self, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
459 '''Determine if the given nodeid actually exists
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
460 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
461 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
462
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
463 def setkey(self, propname):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
464 """Select a String property of this class to be the key property.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
465
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
466 'propname' must be the name of a String property of this class or
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
467 None, or a TypeError is raised. The values of the key property on
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
468 all existing nodes must be unique or a ValueError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
469 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
470 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
471
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
472 def getkey(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
473 """Return the name of the key property for this class or None."""
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
474 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
475
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
476 def labelprop(self, default_to_id=0):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
477 ''' Return the property name for a label for the given node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
478
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
479 This method attempts to generate a consistent label for the node.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
480 It tries the following in order:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
481 1. key property
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
482 2. "name" property
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
483 3. "title" property
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
484 4. first property from the sorted property name list
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
485 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
486 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
487
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
488 def lookup(self, keyvalue):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
489 """Locate a particular node by its key property and return its id.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
490
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
491 If this class has no key property, a TypeError is raised. If the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
492 'keyvalue' matches one of the values for the key property among
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
493 the nodes in this class, the matching node's id is returned;
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
494 otherwise a KeyError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
495 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
496 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
497
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
498 def find(self, **propspec):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
499 """Get the ids of nodes in this class which link to the given nodes.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
500
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
501 'propspec' consists of keyword args propname={nodeid:1,}
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
502 'propname' must be the name of a property in this class, or a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
503 KeyError is raised. That property must be a Link or Multilink
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
504 property, or a TypeError is raised.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
505
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
506 Any node in this class whose 'propname' property links to any of the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
507 nodeids will be returned. Used by the full text indexing, which knows
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
508 that "foo" occurs in msg1, msg3 and file7, so we have hits on these
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
509 issues:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
510
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
511 db.issue.find(messages={'1':1,'3':1}, files={'7':1})
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
512 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
513 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
514
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
515 def filter(self, search_matches, filterspec, sort=(None,None),
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
516 group=(None,None)):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
517 ''' Return a list of the ids of the active nodes in this class that
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
518 match the 'filter' spec, sorted by the group spec and then the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
519 sort spec.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
520
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
521 "filterspec" is {propname: value(s)}
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
522 "sort" and "group" are (dir, prop) where dir is '+', '-' or None
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
523 and prop is a prop name or None
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
524 "search_matches" is {nodeid: marker}
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
525
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
526 The filter must match all properties specificed - but if the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
527 property value to match is a list, any one of the values in the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
528 list may match for that property to match.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
529 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
530 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
531
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
532 def count(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
533 """Get the number of nodes in this class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
534
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
535 If the returned integer is 'numnodes', the ids of all the nodes
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
536 in this class run from 1 to numnodes, and numnodes+1 will be the
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
537 id of the next node to be created in this class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
538 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
539 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
540
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
541 # Manipulating properties:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
542 def getprops(self, protected=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
543 """Return a dictionary mapping property names to property objects.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
544 If the "protected" flag is true, we include protected properties -
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
545 those which may not be modified.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
546 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
547 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
548
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
549 def addprop(self, **properties):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
550 """Add properties to this class.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
551
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
552 The keyword arguments in 'properties' must map names to property
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
553 objects, or a TypeError is raised. None of the keys in 'properties'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
554 may collide with the names of existing properties, or a ValueError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
555 is raised before any properties have been added.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
556 """
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
557 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
558
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
559 def index(self, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
560 '''Add (or refresh) the node to search indexes
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
561 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
562 raise NotImplementedError
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
563
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
564 class Node:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
565 ''' A convenience wrapper for the given node
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
566 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
567 def __init__(self, cl, nodeid, cache=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
568 self.__dict__['cl'] = cl
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
569 self.__dict__['nodeid'] = nodeid
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
570 self.__dict__['cache'] = cache
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
571 def keys(self, protected=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
572 return self.cl.getprops(protected=protected).keys()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
573 def values(self, protected=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
574 l = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
575 for name in self.cl.getprops(protected=protected).keys():
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
576 l.append(self.cl.get(self.nodeid, name, cache=self.cache))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
577 return l
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
578 def items(self, protected=1):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
579 l = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
580 for name in self.cl.getprops(protected=protected).keys():
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
581 l.append((name, self.cl.get(self.nodeid, name, cache=self.cache)))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
582 return l
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
583 def has_key(self, name):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
584 return self.cl.getprops().has_key(name)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
585 def __getattr__(self, name):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
586 if self.__dict__.has_key(name):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
587 return self.__dict__[name]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
588 try:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
589 return self.cl.get(self.nodeid, name, cache=self.cache)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
590 except KeyError, value:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
591 # we trap this but re-raise it as AttributeError - all other
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
592 # exceptions should pass through untrapped
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
593 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
594 # nope, no such attribute
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
595 raise AttributeError, str(value)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
596 def __getitem__(self, name):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
597 return self.cl.get(self.nodeid, name, cache=self.cache)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
598 def __setattr__(self, name, value):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
599 try:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
600 return self.cl.set(self.nodeid, **{name: value})
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
601 except KeyError, value:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
602 raise AttributeError, str(value)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
603 def __setitem__(self, name, value):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
604 self.cl.set(self.nodeid, **{name: value})
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
605 def history(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
606 return self.cl.history(self.nodeid)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
607 def retire(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
608 return self.cl.retire(self.nodeid)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
609
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
610
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
611 def Choice(name, db, *options):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
612 '''Quick helper to create a simple class with choices
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
613 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
614 cl = Class(db, name, name=String(), order=String())
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
615 for i in range(len(options)):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
616 cl.create(name=options[i], order=i)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
617 return hyperdb.Link(name)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
618
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
619 # vim: set filetype=python ts=4 sw=4 et si

Roundup Issue Tracker: http://roundup-tracker.org/