Mercurial > p > roundup > code
annotate roundup/hyperdb.py @ 8300:b99e76e76496
Make native date and number elements configurable
Now for Number() and Integer() properties the browser-native number
format can be configured with the use_browser_number_input config item
in seciont [web]. The default is 'yes'. For Date() properties the config
item is use_browser_date_input (also in section [web]) but the default
is 'no'.
In addition when defining Date() properties, these now have a parameter
'display_time' which defaults to 'yes' and a 'format' parameter which
defaults to None. These set defaults for the field() method of the
DateHTMLProperty which have the same parameters (but the display_time
parameter of field() takes a boolean, not 'yes'/'no').
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Wed, 19 Feb 2025 12:38:06 +0100 |
| parents | de58ff07890e |
| children | 24549122f9b1 |
| rev | line source |
|---|---|
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
1 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
3 # This module is free software, and you may redistribute it and/or modify |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
4 # under the same terms as Python, so long as this copyright message and |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
5 # disclaimer are retained in their original form. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
6 # |
| 214 | 7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
10 # POSSIBILITY OF SUCH DAMAGE. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
11 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
188
diff
changeset
|
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
17 # |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
398
diff
changeset
|
18 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
19 """Hyperdatabase implementation, especially field types. |
|
1244
8dd4f736370b
merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents:
1085
diff
changeset
|
20 """ |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
21 __docformat__ = 'restructuredtext' |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 # standard python modules |
| 6967 | 24 import logging |
| 25 import os | |
| 26 import re | |
| 27 import shutil | |
| 28 import sys | |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
29 import traceback |
| 6967 | 30 import weakref |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 # roundup modules |
|
5388
d26921b851c3
Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
33 from . import date, password |
|
d26921b851c3
Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
34 from .support import ensureParentsExist, PrioList |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
35 from roundup.mlink_expr import Expression |
|
3925
603ec9630b08
i18n for hyperdb and backend errors
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3924
diff
changeset
|
36 from roundup.i18n import _ |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
37 from roundup.cgi.exceptions import DetectorError |
|
5481
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5466
diff
changeset
|
38 from roundup.anypy.cmp_ import NoneAndDictComparable |
|
5525
bb7865241f8a
Make CSV import/export compatible across Python versions (also RDBMS journals) (issue 2550976, issue 2550975).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5481
diff
changeset
|
39 from roundup.anypy.strings import eval_import |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
41 logger = logging.getLogger('roundup.hyperdb') |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
42 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
43 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
44 # |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 # Types |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 # |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
47 class _Type(object): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
48 """A roundup property type.""" |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
49 def __init__(self, required=False, default_value=None, quiet=False): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
50 self.required = required |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
51 self.__default_value = default_value |
|
5112
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5101
diff
changeset
|
52 self.quiet = quiet |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
53 # We do not allow updates if self.computed is True |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
54 # For now only Multilinks (using the rev_multilink) can be computed |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
55 self.computed = False |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
56 |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
57 def __repr__(self): |
|
657
e0a1cc7538e9
more pychecker warnings removed
Richard Jones <richard@users.sourceforge.net>
parents:
648
diff
changeset
|
58 ' more useful for dumps ' |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
59 return '<%s.%s>' % (self.__class__.__module__, self.__class__.__name__) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
60 |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
61 def get_default_value(self): |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
62 """The default value when creating a new instance of this property.""" |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
63 return self.__default_value |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
64 |
| 6967 | 65 def register(self, cls, propname): |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
66 """Register myself to the class of which we are a property |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
67 the given propname is the name we have in our class. |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
68 """ |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
69 assert not getattr(self, 'cls', None) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
70 self.name = propname |
| 6967 | 71 self.cls = cls |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
72 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
73 def sort_repr(self, cls, val, name): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
74 """Representation used for sorting. This should be a python |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
75 built-in type, otherwise sorting will take ages. Note that |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
76 individual backends may chose to use something different for |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
77 sorting as long as the outcome is the same. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
78 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
79 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
80 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
81 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
82 class String(_Type): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
83 """An object designating a String property.""" |
|
6463
8e06194ff0b0
fix isset() for StringHTMLProperty
John Rouillard <rouilj@ieee.org>
parents:
6413
diff
changeset
|
84 def __init__(self, indexme='no', required=False, default_value=None, |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
85 quiet=False): |
|
5112
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5101
diff
changeset
|
86 super(String, self).__init__(required, default_value, quiet) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
87 self.indexme = indexme == 'yes' |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
88 |
|
3992
fe2af84a5ca5
allow binary data for "content" props through rawToHyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
3925
diff
changeset
|
89 def from_raw(self, value, propname='', **kw): |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
90 """fix the CRLF/CR -> LF stuff""" |
|
3992
fe2af84a5ca5
allow binary data for "content" props through rawToHyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
3925
diff
changeset
|
91 if propname == 'content': |
|
fe2af84a5ca5
allow binary data for "content" props through rawToHyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
3925
diff
changeset
|
92 # Why oh why wasn't the FileClass content property a File |
|
fe2af84a5ca5
allow binary data for "content" props through rawToHyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
3925
diff
changeset
|
93 # type from the beginning? |
|
fe2af84a5ca5
allow binary data for "content" props through rawToHyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
3925
diff
changeset
|
94 return value |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
95 return fixNewlines(value) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
96 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
97 def sort_repr(self, cls, val, name): |
|
3684
bffa231ec3bc
Fixes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3682
diff
changeset
|
98 if not val: |
|
bffa231ec3bc
Fixes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3682
diff
changeset
|
99 return val |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
100 if name == 'id': |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
101 return int(val) |
|
3684
bffa231ec3bc
Fixes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3682
diff
changeset
|
102 return val.lower() |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
103 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
104 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
105 class Password(_Type): |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
264
diff
changeset
|
106 """An object designating a Password property.""" |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
107 def __init__(self, scheme=None, required=False, default_value=None, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
108 quiet=False): |
|
5112
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5101
diff
changeset
|
109 super(Password, self).__init__(required, default_value, quiet) |
|
5053
9792b18e0b19
issue 2550880: Ability to choose password store scheme and SSHA support.
John Rouillard <rouilj@ieee.org>
parents:
4995
diff
changeset
|
110 self.scheme = scheme |
|
9792b18e0b19
issue 2550880: Ability to choose password store scheme and SSHA support.
John Rouillard <rouilj@ieee.org>
parents:
4995
diff
changeset
|
111 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
112 def from_raw(self, value, **kw): |
|
3668
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
113 if not value: |
|
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
114 return None |
|
4480
1613754d2646
Fix first part of Password handling security issue2550688
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4472
diff
changeset
|
115 try: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
116 return password.Password(encrypted=value, scheme=self.scheme, |
|
7212
76a21cf791b9
Add config argument for one more call
John Rouillard <rouilj@ieee.org>
parents:
7114
diff
changeset
|
117 strict=True, |
|
76a21cf791b9
Add config argument for one more call
John Rouillard <rouilj@ieee.org>
parents:
7114
diff
changeset
|
118 config=kw['db'].config) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
119 except password.PasswordValueError as message: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
120 raise HyperdbValueError(_('property %(property)s: %(errormsg)s') % |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
121 {'property': kw['propname'], |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
122 'errormsg': message}) |
|
4480
1613754d2646
Fix first part of Password handling security issue2550688
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4472
diff
changeset
|
123 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
124 def sort_repr(self, cls, val, name): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
125 if not val: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
126 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
127 return str(val) |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
264
diff
changeset
|
128 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
129 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
130 class Date(_Type): |
|
8300
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
131 """An object designating a Date property. |
|
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
132 The display_time parameter specifies if we want date and time or |
|
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
133 date only. Both display_time and format are defaults for the |
|
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
134 field method of the DateHTMLProperty (for rendering html). |
|
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
135 """ |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
136 def __init__(self, offset=None, required=False, default_value=None, |
|
8300
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
137 quiet=False, display_time='yes', format=None): |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
138 super(Date, self).__init__(required=required, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
139 default_value=default_value, |
|
5112
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5101
diff
changeset
|
140 quiet=quiet) |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
141 self._offset = offset |
|
8300
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
142 self.display_time = display_time == 'yes' |
|
b99e76e76496
Make native date and number elements configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8139
diff
changeset
|
143 self.format = format |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
144 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
145 def offset(self, db): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
146 if self._offset is not None: |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
147 return self._offset |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
148 return db.getUserTimezone() |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
149 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
150 def from_raw(self, value, db, **kw): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
151 try: |
|
3621
77ed6c517793
timezone support (patch [SF#1465296])
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3601
diff
changeset
|
152 value = date.Date(value, self.offset(db)) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
153 except ValueError as message: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
154 raise HyperdbValueError(_( |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
155 'property %(property)s: %(value)r is an invalid ' |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
156 'date (%(errormsg)s)') % {'property': kw['propname'], |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
157 'value': value, |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
158 'errormsg': message}) |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
159 return value |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
160 |
|
3586
f47bddab5a49
date spec wasn't allowing week intervals
Richard Jones <richard@users.sourceforge.net>
parents:
3545
diff
changeset
|
161 def range_from_raw(self, value, db): |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
162 """return Range value from given raw value with offset correction""" |
|
3586
f47bddab5a49
date spec wasn't allowing week intervals
Richard Jones <richard@users.sourceforge.net>
parents:
3545
diff
changeset
|
163 return date.Range(value, date.Date, offset=self.offset(db)) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
164 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
165 def sort_repr(self, cls, val, name): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
166 if not val: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
167 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
168 return str(val) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
169 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
170 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
171 class Interval(_Type): |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
172 """An object designating an Interval property.""" |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
173 def from_raw(self, value, **kw): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
174 try: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
175 value = date.Interval(value) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
176 except ValueError as message: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
177 raise HyperdbValueError(_( |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
178 'property %(property)s: %(value)r is an invalid ' |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
179 'date interval (%(errormsg)s)') % |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
180 {'property': kw['propname'], |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
181 'value': value, |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
182 'errormsg': message}) |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
183 return value |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
184 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
185 def sort_repr(self, cls, val, name): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
186 if not val: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
187 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
188 return val.as_seconds() |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
189 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
190 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
191 class _Pointer(_Type): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
192 """An object designating a Pointer property that links or multilinks |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
193 to a node in a specified class.""" |
|
4877
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
194 def __init__(self, classname, do_journal='yes', try_id_parsing='yes', |
|
5063
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
195 required=False, default_value=None, |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
196 msg_header_property=None, quiet=False, rev_multilink=None): |
|
7526
b8dc16d9624a
Reformat docstring for _Pointer::__init__
John Rouillard <rouilj@ieee.org>
parents:
7212
diff
changeset
|
197 """ The base class used by Link and Multilink classes. |
|
b8dc16d9624a
Reformat docstring for _Pointer::__init__
John Rouillard <rouilj@ieee.org>
parents:
7212
diff
changeset
|
198 |
|
b8dc16d9624a
Reformat docstring for _Pointer::__init__
John Rouillard <rouilj@ieee.org>
parents:
7212
diff
changeset
|
199 Default is to journal link and unlink events. |
|
b8dc16d9624a
Reformat docstring for _Pointer::__init__
John Rouillard <rouilj@ieee.org>
parents:
7212
diff
changeset
|
200 |
|
4877
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
201 When try_id_parsing is false, we don't allow IDs in input |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
202 fields (the key of the Link or Multilink property must be |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
203 given instead). This is useful when the name of a property |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
204 can be numeric. It will only work if the linked item has a |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
205 key property and is a questionable feature for multilinks. |
|
7526
b8dc16d9624a
Reformat docstring for _Pointer::__init__
John Rouillard <rouilj@ieee.org>
parents:
7212
diff
changeset
|
206 |
|
5063
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
207 The msg_header_property is used in the mail gateway when |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
208 sending out messages: By default roundup creates headers of |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
209 the form: 'X-Roundup-issue-prop: value' for all properties |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
210 prop of issue that have a 'name' property. This definition |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
211 allows to override the 'name' property. A common use-case is |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
212 adding a mail-header with the assigned_to property to allow |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
213 user mail-filtering of issue-emails for which they're |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
214 responsible. In that case setting |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
215 'msg_header_property="username"' for the assigned_to |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
216 property will generated message headers of the form: |
|
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
217 'X-Roundup-issue-assigned_to: joe_user'. |
|
7526
b8dc16d9624a
Reformat docstring for _Pointer::__init__
John Rouillard <rouilj@ieee.org>
parents:
7212
diff
changeset
|
218 |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
219 The rev_multilink is used to inject a reverse multilink into |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
220 the Class linked by a Link or Multilink property. Note that |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
221 the result is always a Multilink. The name given with |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
222 rev_multilink is the name in the class where it is injected. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
223 """ |
|
5112
8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
John Rouillard <rouilj@ieee.org>
parents:
5101
diff
changeset
|
224 super(_Pointer, self).__init__(required, default_value, quiet) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
225 self.classname = classname |
|
555
5fd94347c6f2
Journal entries for link and multilink properties can now be switched on or off.
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
543
diff
changeset
|
226 self.do_journal = do_journal == 'yes' |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
227 self.try_id_parsing = try_id_parsing == 'yes' |
|
5063
2840a9e86ef2
New Link/Multilink attribute 'msg_header_property'
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5053
diff
changeset
|
228 self.msg_header_property = msg_header_property |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
229 self.rev_multilink = rev_multilink |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
230 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
231 def __repr__(self): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
232 """more useful for dumps. But beware: This is also used in schema |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
233 storage in SQL backends! |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
234 """ |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
235 return '<%s.%s to "%s">' % (self.__class__.__module__, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
236 self.__class__.__name__, self.classname) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
237 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
238 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
239 class Link(_Pointer): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
240 """An object designating a Link property that links to a |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
241 node in a specified class.""" |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
242 def from_raw(self, value, db, propname, **kw): |
|
4877
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
243 if (self.try_id_parsing and value == '-1') or not value: |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
244 value = None |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
245 else: |
|
4877
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
246 if self.try_id_parsing: |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
247 value = convertLinkValue(db, propname, self, value) |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
248 else: |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
249 value = convertLinkValue(db, propname, self, value, None) |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
250 return value |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
251 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
252 def sort_repr(self, cls, val, name): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
253 if not val: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
254 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
255 op = cls.labelprop() |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
256 if op == 'id': |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
257 return int(cls.get(val, op)) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
258 return cls.get(val, op) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
259 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
260 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
261 class Multilink(_Pointer): |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
262 """An object designating a Multilink property that links |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
263 to nodes in a specified class. |
|
557
dfac856502d1
brief docco on the do_journal argument
Richard Jones <richard@users.sourceforge.net>
parents:
555
diff
changeset
|
264 |
|
dfac856502d1
brief docco on the do_journal argument
Richard Jones <richard@users.sourceforge.net>
parents:
555
diff
changeset
|
265 "classname" indicates the class to link to |
|
dfac856502d1
brief docco on the do_journal argument
Richard Jones <richard@users.sourceforge.net>
parents:
555
diff
changeset
|
266 |
|
dfac856502d1
brief docco on the do_journal argument
Richard Jones <richard@users.sourceforge.net>
parents:
555
diff
changeset
|
267 "do_journal" indicates whether the linked-to nodes should have |
|
dfac856502d1
brief docco on the do_journal argument
Richard Jones <richard@users.sourceforge.net>
parents:
555
diff
changeset
|
268 'link' and 'unlink' events placed in their journal |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
269 "rev_property" is used when injecting reverse multilinks. By |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
270 default (for a normal multilink) the table name is |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
271 <name_of_linking_class>_<name_of_link_property> |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
272 e.g. for the messages multilink in issue in the |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
273 classic schema it would be "issue_messages". The |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
274 multilink table in that case has two columns, the |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
275 nodeid contains the ID of the linking class while |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
276 the linkid contains the ID of the linked-to class. |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
277 When injecting backlinks, for a backlink resulting |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
278 from a Link or Multilink the table_name, |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
279 linkid_name, and nodeid_name must be explicitly |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
280 specified. So when specifying a rev_multilink |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
281 property for the messages attribute in the example |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
282 above, we would get 'issue_messages' for the |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
283 table_name, 'nodeid' for the linkid_name and |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
284 'linkid' for the nodeid_name (note the reversal). |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
285 For a rev_multilink resulting, e.g. from the |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
286 standard 'status' Link in the Class 'issue' in the |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
287 classic template we would set table_name to '_issue' |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
288 (table names in the database get a leading |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
289 underscore), the nodeid_name to 'status' and the |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
290 linkid_name to 'id'. With these settings we can use |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
291 the standard query engine (with minor modifications |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
292 for the computed names) to resolve reverse |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
293 multilinks. |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
294 """ |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
295 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
296 def __init__(self, classname, do_journal='yes', required=False, |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
297 quiet=False, try_id_parsing='yes', rev_multilink=None, |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
298 rev_property=None): |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
299 |
|
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
300 super(Multilink, self).__init__(classname, |
|
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
301 do_journal, |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
302 required=required, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
303 default_value=[], quiet=quiet, |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
304 try_id_parsing=try_id_parsing, |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
305 rev_multilink=rev_multilink) |
| 6967 | 306 self.rev_property = rev_property |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
307 self.rev_classname = None |
| 6967 | 308 self.rev_propname = None |
| 309 self.table_name = None # computed in 'register' below | |
| 310 self.linkid_name = 'linkid' | |
| 311 self.nodeid_name = 'nodeid' | |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
312 if self.rev_property: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
313 # Do not allow updates if this is a reverse multilink |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
314 self.computed = True |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
315 self.rev_classname = rev_property.cls.classname |
| 6967 | 316 self.rev_propname = rev_property.name |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
317 if isinstance(self.rev_property, Link): |
| 6967 | 318 self.table_name = '_' + self.rev_classname |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
319 self.linkid_name = 'id' |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
320 self.nodeid_name = '_' + self.rev_propname |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
321 else: |
| 6967 | 322 self.table_name = self.rev_classname + '_' + self.rev_propname |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
323 self.linkid_name = 'nodeid' |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
324 self.nodeid_name = 'linkid' |
|
4481
9bbf3758c16a
Allow default value declaration in DB schema.
Stefan Seefeld <stefan@seefeld.name>
parents:
4480
diff
changeset
|
325 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
326 def from_raw(self, value, db, klass, propname, itemid, **kw): |
|
3668
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
327 if not value: |
|
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
328 return [] |
|
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
329 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
330 # get the current item value if it's not a new item |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
331 if itemid and not itemid.startswith('-'): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
332 curvalue = klass.get(itemid, propname) |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
333 else: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
334 curvalue = [] |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
335 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
336 # if the value is a comma-separated string then split it now |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
337 if isinstance(value, type('')): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
338 value = value.split(',') |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
339 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
340 # handle each add/remove in turn |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
341 # keep an extra list for all items that are |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
342 # definitely in the new list (in case of e.g. |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
343 # <propname>=A,+B, which should replace the old |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
344 # list with A,B) |
|
4089
eddb82d0964c
Add compatibility package to allow us to deal with Python versions 2.3..2.6.
Richard Jones <richard@users.sourceforge.net>
parents:
4063
diff
changeset
|
345 do_set = 1 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
346 newvalue = [] |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
347 for item in value: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
348 item = item.strip() |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
349 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
350 # skip blanks |
| 6967 | 351 if not item: continue # noqa: E701 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
352 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
353 # handle +/- |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
354 remove = 0 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
355 if item.startswith('-'): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
356 remove = 1 |
|
5069
2706b66675bf
issue2550763 Strip whitespace from Multilink values after + or -.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
357 item = item[1:].strip() |
|
4089
eddb82d0964c
Add compatibility package to allow us to deal with Python versions 2.3..2.6.
Richard Jones <richard@users.sourceforge.net>
parents:
4063
diff
changeset
|
358 do_set = 0 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
359 elif item.startswith('+'): |
|
5069
2706b66675bf
issue2550763 Strip whitespace from Multilink values after + or -.
John Rouillard <rouilj@ieee.org>
parents:
5067
diff
changeset
|
360 item = item[1:].strip() |
|
4089
eddb82d0964c
Add compatibility package to allow us to deal with Python versions 2.3..2.6.
Richard Jones <richard@users.sourceforge.net>
parents:
4063
diff
changeset
|
361 do_set = 0 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
362 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
363 # look up the value |
|
4877
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
364 if self.try_id_parsing: |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
365 itemid = convertLinkValue(db, propname, self, item) |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
366 else: |
|
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
367 itemid = convertLinkValue(db, propname, self, item, None) |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
368 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
369 # perform the add/remove |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
370 if remove: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
371 try: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
372 curvalue.remove(itemid) |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
373 except ValueError: |
|
5548
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5527
diff
changeset
|
374 # This can occur if the edit adding the element |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5527
diff
changeset
|
375 # produced an error, so the form has it in the |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5527
diff
changeset
|
376 # "no selection" choice but it's not set in the |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5527
diff
changeset
|
377 # database. |
|
fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5527
diff
changeset
|
378 pass |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
379 else: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
380 newvalue.append(itemid) |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
381 if itemid not in curvalue: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
382 curvalue.append(itemid) |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
383 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
384 # that's it, set the new Multilink property value, |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
385 # or overwrite it completely |
|
4089
eddb82d0964c
Add compatibility package to allow us to deal with Python versions 2.3..2.6.
Richard Jones <richard@users.sourceforge.net>
parents:
4063
diff
changeset
|
386 if do_set: |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
387 value = newvalue |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
388 else: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
389 value = curvalue |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
390 |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
391 # TODO: one day, we'll switch to numeric ids and this will be |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
392 # unnecessary :( |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
393 value = [int(x) for x in value] |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
394 value.sort() |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
395 value = [str(x) for x in value] |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
396 return value |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
397 |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
398 def register(self, cls, propname): |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
399 super(Multilink, self).register(cls, propname) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
400 if self.table_name is None: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
401 self.table_name = self.cls.classname + '_' + self.name |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
402 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
403 def sort_repr(self, cls, val, name): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
404 if not val: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
405 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
406 op = cls.labelprop() |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
407 if op == 'id': |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
408 return [int(cls.get(v, op)) for v in val] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
409 return [cls.get(v, op) for v in val] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
410 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
411 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
412 class Boolean(_Type): |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
858
diff
changeset
|
413 """An object designating a boolean property""" |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
414 def from_raw(self, value, **kw): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
415 value = value.strip() |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
416 # checked is a common HTML checkbox value |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
417 value = value.lower() in ('checked', 'yes', 'true', 'on', '1') |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
418 return value |
|
2603
5ccd99777869
fix metakit handling of filter on Link==None; fix some unit tests
Richard Jones <richard@users.sourceforge.net>
parents:
2571
diff
changeset
|
419 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
420 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
421 class Number(_Type): |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
858
diff
changeset
|
422 """An object designating a numeric property""" |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
423 def __init__(self, use_double=False, **kw): |
|
5175
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
424 """ The value use_double tells the database backend to use a |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
425 floating-point format with more precision than the default. |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
426 Usually implemented by type 'double precision' in the sql |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
427 backend. The default is to use single-precision float (aka |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
428 'real') in the db. Note that sqlite already uses 8-byte for |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
429 floating point numbers. |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
430 """ |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
431 self.use_double = use_double |
|
e1e40674a0bc
Implement double-precision Number
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5169
diff
changeset
|
432 super(Number, self).__init__(**kw) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
433 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
434 def from_raw(self, value, **kw): |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
435 value = value.strip() |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
436 try: |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
437 value = float(value) |
|
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
438 except ValueError: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
439 raise HyperdbValueError(_( |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
440 'property %(property)s: %(value)r is not a number') % |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
441 {'property': kw['propname'], |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
442 'value': value}) |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
443 return value |
|
5067
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
444 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
445 |
|
5067
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
446 class Integer(_Type): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
447 """An object designating an integer property""" |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
448 def from_raw(self, value, **kw): |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
449 value = value.strip() |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
450 try: |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
451 value = int(value) |
|
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
452 except ValueError: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
453 raise HyperdbValueError(_( |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
454 'property %(property)s: %(value)r is not an integer') % { |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
455 'property': kw['propname'], |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
456 'value': value}) |
|
5067
e424987d294a
Add support for an integer type to join the existing number type.
John Rouillard <rouilj@ieee.org>
parents:
5063
diff
changeset
|
457 return value |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
458 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
459 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
460 # |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
461 # Support for splitting designators |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
462 # |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
463 class DesignatorError(ValueError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
464 pass |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
465 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
466 |
| 6967 | 467 dre = re.compile(r'^([A-Za-z](?:[A-Za-z_0-9]*[A-Za-z_]+)?)(\d+)$') |
| 468 | |
| 469 | |
|
6238
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
470 def splitDesignator(designator, |
| 6967 | 471 dre=dre): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
472 """ Take a foo123 and return ('foo', 123) |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
473 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
474 m = dre.match(designator) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
475 if m is None: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
476 raise DesignatorError(_('"%s" not a node designator') % designator) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
477 return m.group(1), m.group(2) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
478 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
479 |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
480 class Exact_Match(object): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
481 """ Used to encapsulate exact match semantics search values |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
482 """ |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
483 def __init__(self, value): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
484 self.value = value |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
485 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
486 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
487 class Proptree(object): |
|
4935
adb8b787e157
Attempt to clarify hyperdb.Proptree meaning
anatoly techtonik <techtonik@gmail.com>
parents:
4877
diff
changeset
|
488 """ Simple tree data structure for property lookup. Each node in |
|
adb8b787e157
Attempt to clarify hyperdb.Proptree meaning
anatoly techtonik <techtonik@gmail.com>
parents:
4877
diff
changeset
|
489 the tree is a roundup Class Property that has to be navigated to |
|
adb8b787e157
Attempt to clarify hyperdb.Proptree meaning
anatoly techtonik <techtonik@gmail.com>
parents:
4877
diff
changeset
|
490 find given property. The need_for attribute is used to mark nodes |
|
adb8b787e157
Attempt to clarify hyperdb.Proptree meaning
anatoly techtonik <techtonik@gmail.com>
parents:
4877
diff
changeset
|
491 that are used for sorting, searching or retrieval: The attribute |
|
adb8b787e157
Attempt to clarify hyperdb.Proptree meaning
anatoly techtonik <techtonik@gmail.com>
parents:
4877
diff
changeset
|
492 is a dictionary containing one or several of the values 'sort', |
|
adb8b787e157
Attempt to clarify hyperdb.Proptree meaning
anatoly techtonik <techtonik@gmail.com>
parents:
4877
diff
changeset
|
493 'search', 'retrieve'. |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
494 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
495 The Proptree is also used for transitively searching attributes for |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
496 backends that do not support transitive search (e.g. anydbm). The |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
497 val attribute with set_val is used for this. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
498 """ |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
499 |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
500 def __init__(self, db, cls, name, props, parent=None, retr=False): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
501 self.db = db |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
502 self.name = name |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
503 self.props = props |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
504 self.parent = parent |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
505 self.val = None |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
506 self.has_values = False |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
507 self.has_result = False |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
508 self.cls = cls |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
509 self.classname = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
510 self.uniqname = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
511 self.children = [] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
512 self.sortattr = [] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
513 self.propdict = {} |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
514 self.need_for = {'search': True} |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
515 self.sort_direction = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
516 self.sort_ids = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
517 self.sort_ids_needed = False |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
518 self.sort_result = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
519 self.attr_sort_done = False |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
520 self.tree_sort_done = False |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
521 self.propclass = None |
|
3695
01ea89743311
Add an attribute for sort-order fix in rdbms backends
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3687
diff
changeset
|
522 self.orderby = [] |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
523 self.sql_idx = None # index of retrieved column in sql result |
|
6179
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
524 self.need_retired = False |
|
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
525 self.need_child_retired = False |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
526 if parent: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
527 self.root = parent.root |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
528 self.depth = parent.depth + 1 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
529 else: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
530 self.root = self |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
531 self.seqno = 1 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
532 self.depth = 0 |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
533 self.need_for['sort'] = True |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
534 self.id = self.root.seqno |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
535 self.root.seqno += 1 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
536 if self.cls: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
537 self.classname = self.cls.classname |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
538 self.uniqname = '%s%s' % (self.cls.classname, self.id) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
539 if not self.parent: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
540 self.uniqname = self.cls.classname |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
541 if retr: |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
542 self.append_retr_props() |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
543 |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
544 def append(self, name, need_for='search', retr=False): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
545 """Append a property to self.children. Will create a new |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
546 propclass for the child. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
547 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
548 if name in self.propdict: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
549 pt = self.propdict[name] |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
550 pt.need_for[need_for] = True |
|
6413
7b1b6dffc7ed
Fix searching+sorting for Link properties
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6412
diff
changeset
|
551 # For now we do not recursively retrieve Link properties |
| 6967 | 552 # if retr and isinstance(pt.propclass, Link): |
|
6413
7b1b6dffc7ed
Fix searching+sorting for Link properties
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6412
diff
changeset
|
553 # pt.append_retr_props() |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
554 return pt |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
555 propclass = self.props[name] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
556 cls = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
557 props = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
558 if isinstance(propclass, (Link, Multilink)): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
559 cls = self.db.getclass(propclass.classname) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
560 props = cls.getprops() |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
561 child = self.__class__(self.db, cls, name, props, parent=self) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
562 child.need_for = {need_for: True} |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
563 child.propclass = propclass |
|
6179
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
564 if isinstance(propclass, Multilink) and self.props[name].computed: |
|
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
565 if isinstance(self.props[name].rev_property, Link): |
|
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
566 child.need_retired = True |
|
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
567 else: |
|
a701c9c81597
Fix rev_multilink properties search/retrieval
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6148
diff
changeset
|
568 child.need_child_retired = True |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
569 self.children.append(child) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
570 self.propdict[name] = child |
|
6413
7b1b6dffc7ed
Fix searching+sorting for Link properties
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6412
diff
changeset
|
571 # For now we do not recursively retrieve Link properties |
| 6967 | 572 # if retr and isinstance(child.propclass, Link): |
|
6413
7b1b6dffc7ed
Fix searching+sorting for Link properties
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6412
diff
changeset
|
573 # child.append_retr_props() |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
574 return child |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
575 |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
576 def append_retr_props(self): |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
577 """Append properties for retrieval.""" |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
578 for name, prop in self.cls.getprops(protected=1).items(): |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
579 if isinstance(prop, Multilink): |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
580 continue |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
581 self.append(name, need_for='retrieve') |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
582 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
583 def compute_sort_done(self, mlseen=False): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
584 """ Recursively check if attribute is needed for sorting |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
585 ('sort' in self.need_for) or all children have tree_sort_done set and |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
586 sort_ids_needed unset: set self.tree_sort_done if one of the conditions |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
587 holds. Also remove sort_ids_needed recursively once having seen a |
|
4850
6998ad77841e
Fix bug in SQL generation
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4687
diff
changeset
|
588 Multilink that is used for sorting. |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
589 """ |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
590 if isinstance(self.propclass, Multilink) and 'sort' in self.need_for: |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
591 mlseen = True |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
592 if mlseen: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
593 self.sort_ids_needed = False |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
594 self.tree_sort_done = True |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
595 for p in self.children: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
596 p.compute_sort_done(mlseen) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
597 if not p.tree_sort_done: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
598 self.tree_sort_done = False |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
599 if 'sort' not in self.need_for: |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
600 self.tree_sort_done = True |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
601 if mlseen: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
602 self.tree_sort_done = False |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
603 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
604 def ancestors(self): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
605 p = self |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
606 while p.parent: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
607 yield p |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
608 p = p.parent |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
609 |
|
5318
506c7ee9a385
Add a 'retired' parameter to Class.filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5315
diff
changeset
|
610 def search(self, search_matches=None, sort=True, retired=False): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
611 """ Recursively search for the given properties in a proptree. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
612 Once all properties are non-transitive, the search generates a |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
613 simple _filter call which does the real work |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
614 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
615 filterspec = {} |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
616 exact_match_spec = {} |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
617 for p in self.children: |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
618 if 'search' in p.need_for: |
|
6412
a0c0ee3ed8b1
Tests for Link expressions
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6410
diff
changeset
|
619 x = [c for c in p.children if 'search' in c.need_for] |
|
a0c0ee3ed8b1
Tests for Link expressions
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6410
diff
changeset
|
620 if x: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
621 p.search(sort=False) |
| 6967 | 622 if getattr(p.propclass, 'rev_property', None): |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
623 pn = p.propclass.rev_property.name |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
624 cl = p.propclass.rev_property.cls |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
625 if not isinstance(p.val, type([])): |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
626 p.val = [p.val] |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
627 nval = [int(i) for i in p.val] |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
628 pval = [str(i) for i in nval if i >= 0] |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
629 items = set() |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
630 if not nval or min(nval) >= -1: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
631 if -1 in nval: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
632 s1 = set(self.cls.getnodeids(retired=False)) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
633 s2 = set() |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
634 for id in cl.getnodeids(retired=False): |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
635 node = cl.getnode(id) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
636 if node[pn]: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
637 if isinstance(node[pn], type([])): |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
638 s2.update(node[pn]) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
639 else: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
640 s2.add(node[pn]) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
641 items |= s1.difference(s2) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
642 if isinstance(p.propclass.rev_property, Link): |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
643 items |= set(cl.get(x, pn) for x in pval |
| 6967 | 644 if not cl.is_retired(x)) |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
645 else: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
646 items |= set().union(*(cl.get(x, pn) for x in pval |
| 6967 | 647 if not cl.is_retired(x))) |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
648 else: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
649 # Expression: materialize rev multilinks and run |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
650 # expression on them |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
651 expr = Expression(nval) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
652 by_id = {} |
|
6402
619807d9a2df
Make rev multilink for Link work
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6401
diff
changeset
|
653 for id in self.cls.getnodeids(retired=False): |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
654 by_id[id] = set() |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
655 items = set() |
|
6402
619807d9a2df
Make rev multilink for Link work
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6401
diff
changeset
|
656 for id in cl.getnodeids(retired=False): |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
657 node = cl.getnode(id) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
658 if node[pn]: |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
659 v = node[pn] |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
660 if not isinstance(v, type([])): |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
661 v = [v] |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
662 for x in v: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
663 if x not in by_id: |
|
6402
619807d9a2df
Make rev multilink for Link work
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6401
diff
changeset
|
664 continue |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
665 by_id[x].add(id) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
666 for k in by_id: |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
667 if expr.evaluate(by_id[k]): |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
668 items.add(k) |
|
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
669 |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
670 # The subquery has found nothing. So it doesn't make |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
671 # sense to search further. |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
672 if not items: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
673 self.set_val([], force=True) |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
674 return self.val |
|
6401
8bc5faeb7677
Make rev multilink expressions work for anydbm
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6250
diff
changeset
|
675 filterspec[p.name] = list(sorted(items, key=int)) |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
676 elif isinstance(p.val, type([])): |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
677 exact = [] |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
678 subst = [] |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
679 for v in p.val: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
680 if isinstance(v, Exact_Match): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
681 exact.append(v.value) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
682 else: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
683 subst.append(v) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
684 if exact: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
685 exact_match_spec[p.name] = exact |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
686 if subst: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
687 filterspec[p.name] = subst |
| 6967 | 688 elif not exact: # don't set if we have exact criteria |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
689 if p.has_result: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
690 # A subquery already has found nothing. So |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
691 # it doesn't make sense to search further. |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
692 self.set_val([], force=True) |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
693 return self.val |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
694 else: |
| 6967 | 695 filterspec[p.name] = ['-1'] # no match was found |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
696 else: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
697 assert not isinstance(p.val, Exact_Match) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
698 filterspec[p.name] = p.val |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
699 self.set_val(self.cls._filter(search_matches, filterspec, |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
700 sort and self, |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
701 retired=retired, |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
702 exact_match_spec=exact_match_spec)) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
703 return self.val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
704 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
705 def sort(self, ids=None): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
706 """ Sort ids by the order information stored in self. With |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
707 optimisations: Some order attributes may be precomputed (by the |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
708 backend) and some properties may already be sorted. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
709 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
710 if ids is None: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
711 ids = self.val |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
712 if self.sortattr and [s for s in self.sortattr |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
713 if not s.attr_sort_done]: |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
714 return self._searchsort(ids, True, True) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
715 return ids |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
716 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
717 def sortable_children(self, intermediate=False): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
718 """ All children needed for sorting. If intermediate is True, |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
719 intermediate nodes (not being a sort attribute) are returned, |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
720 too. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
721 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
722 return [p for p in self.children |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
723 if 'sort' in p.need_for and (intermediate or p.sort_direction)] |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
724 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
725 def __iter__(self): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
726 """ Yield nodes in depth-first order -- visited nodes first """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
727 for p in self.children: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
728 yield p |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
729 for c in p: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
730 yield c |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
731 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
732 def _get(self, ids): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
733 """Lookup given ids -- possibly a list of list. We recurse until |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
734 we have a list of ids. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
735 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
736 if not ids: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
737 return ids |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
738 if isinstance(ids[0], list): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
739 cids = [self._get(i) for i in ids] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
740 else: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
741 cids = [i and self.parent.cls.get(i, self.name) for i in ids] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
742 if self.sortattr: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
743 cids = [self._searchsort(i, False, True) for i in cids] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
744 return cids |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
745 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
746 def _searchsort(self, ids=None, update=True, dosort=True): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
747 """ Recursively compute the sort attributes. Note that ids |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
748 may be a deeply nested list of lists of ids if several |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
749 multilinks are encountered on the way from the root to an |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
750 individual attribute. We make sure that everything is properly |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
751 sorted on the way up. Note that the individual backend may |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
752 already have precomputed self.result or self.sort_ids. In this |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
753 case we do nothing for existing sa.result and recurse further if |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
754 self.sort_ids is available. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
755 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
756 Yech, Multilinks: This gets especially complicated if somebody |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
757 sorts by different attributes of the same multilink (or |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
758 transitively across several multilinks). My use-case is sorting |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
759 by issue.messages.author and (reverse) by issue.messages.date. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
760 In this case we sort the messages by author and date and use |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
761 this sorted list twice for sorting issues. This means that |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
762 issues are sorted by author and then by the time of the messages |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
763 *of this author*. Probably what the user intends in that case, |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
764 so we do *not* use two sorted lists of messages, one sorted by |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
765 author and one sorted by date for sorting issues. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
766 """ |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
767 for pt in self.sortable_children(intermediate=True): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
768 # ids can be an empty list |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
769 if pt.tree_sort_done or not ids: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
770 continue |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
771 if pt.sort_ids: # cached or computed by backend |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
772 cids = pt.sort_ids |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
773 else: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
774 cids = pt._get(ids) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
775 if pt.sort_direction and not pt.sort_result: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
776 sortrep = pt.propclass.sort_repr |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
777 pt.sort_result = pt._sort_repr(sortrep, cids) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
778 pt.sort_ids = cids |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
779 if pt.children: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
780 pt._searchsort(cids, update, False) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
781 if self.sortattr and dosort: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
782 ids = self._sort(ids) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
783 if not update: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
784 for pt in self.sortable_children(intermediate=True): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
785 pt.sort_ids = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
786 for pt in self.sortattr: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
787 pt.sort_result = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
788 return ids |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
789 |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
790 def set_val(self, val, force=False, result=True): |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
791 """ Check if self.val is already defined (it is not None and |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
792 has_values is True). If yes, we compute the |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
793 intersection of the old and the new value(s) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
794 Note: If self is a Leaf node we need to compute a |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
795 union: Normally we intersect (logical and) different |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
796 subqueries into a Link or Multilink property. But for |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
797 leaves we might have a part of a query in a filterspec and |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
798 in an exact_match_spec. These have to be all there, the |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
799 generated search will ensure a logical and of all tests for |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
800 equality/substring search. |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
801 """ |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
802 if force: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
803 assert val == [] |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
804 assert result |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
805 self.val = val |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
806 self.has_values = True |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
807 self.has_result = True |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
808 return |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
809 if self.has_values: |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
810 v = self.val |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
811 if not isinstance(self.val, type([])): |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
812 v = [self.val] |
|
4089
eddb82d0964c
Add compatibility package to allow us to deal with Python versions 2.3..2.6.
Richard Jones <richard@users.sourceforge.net>
parents:
4063
diff
changeset
|
813 vals = set(v) |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
814 if not isinstance(val, type([])): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
815 val = [val] |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
816 if self.has_result: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
817 assert result |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
818 # if cls is None we're a leaf |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
819 if self.cls: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
820 vals.intersection_update(val) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
821 else: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
822 vals.update(val) |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
823 self.val = list(vals) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
824 else: |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
825 # If a subquery found nothing we don't care if there is an |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
826 # expression |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
827 if not self.has_values or not val: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
828 self.val = val |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
829 if result: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
830 self.has_result = True |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
831 else: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
832 if not result: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
833 assert not self.cls |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
834 vals.update(val) |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
835 self.val = list(vals) |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
836 else: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
837 assert self.cls |
|
6410
66ccddb034f2
Bug-fix in expression parser
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6409
diff
changeset
|
838 is_expression = \ |
|
66ccddb034f2
Bug-fix in expression parser
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6409
diff
changeset
|
839 self.val and min(int(i) for i in self.val) < -1 |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
840 if is_expression: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
841 # Tag on the ORed values with an AND |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
842 l = val |
| 6967 | 843 for _i in range(len(val)-1): |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
844 l.append('-4') |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
845 l.append('-3') |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
846 self.val = self.val + l |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
847 else: |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
848 vals.intersection_update(val) |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
849 self.val = list(vals) |
|
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
850 self.has_result = True |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
851 self.has_values = True |
|
3924
21d3d7eeea8c
assorted pyflakes fixes
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3802
diff
changeset
|
852 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
853 def _sort(self, val): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
854 """Finally sort by the given sortattr.sort_result. Note that we |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
855 do not sort by attrs having attr_sort_done set. The caller is |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
856 responsible for setting attr_sort_done only for trailing |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
857 attributes (otherwise the sort order is wrong). Since pythons |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
858 sort is stable, we can sort already sorted lists without |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
859 destroying the sort-order for items that compare equal with the |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
860 current sort. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
861 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
862 Sorting-Strategy: We sort repeatedly by different sort-keys from |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
863 right to left. Since pythons sort is stable, we can safely do |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
864 that. An optimisation is a "run-length encoding" of the |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
865 sort-directions: If several sort attributes sort in the same |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
866 direction we can combine them into a single sort. Note that |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
867 repeated sorting is probably more efficient than using |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
868 compare-methods in python due to the overhead added by compare |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
869 methods. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
870 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
871 if not val: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
872 return val |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
873 sortattr = [] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
874 directions = [] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
875 dir_idx = [] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
876 idx = 0 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
877 curdir = None |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
878 for sa in self.sortattr: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
879 if sa.attr_sort_done: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
880 break |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
881 if sortattr: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
882 assert len(sortattr[0]) == len(sa.sort_result) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
883 sortattr.append(sa.sort_result) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
884 if curdir != sa.sort_direction: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
885 dir_idx.append(idx) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
886 directions.append(sa.sort_direction) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
887 curdir = sa.sort_direction |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
888 idx += 1 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
889 sortattr.append(val) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
890 sortattr = zip(*sortattr) |
|
5397
f2c5e0f6506e
Python 3 preparation: use list() around zip() as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5395
diff
changeset
|
891 for dir, i in reversed(list(zip(directions, dir_idx))): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
892 rev = dir == '-' |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
893 sortattr = sorted(sortattr, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
894 key=lambda x: NoneAndDictComparable(x[i:idx]), |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
895 reverse=rev) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
896 idx = i |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
897 return [x[-1] for x in sortattr] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
898 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
899 def _sort_repr(self, sortrep, ids): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
900 """Call sortrep for given ids -- possibly a list of list. We |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
901 recurse until we have a list of ids. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
902 """ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
903 if not ids: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
904 return ids |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
905 if isinstance(ids[0], list): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
906 res = [self._sort_repr(sortrep, i) for i in ids] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
907 else: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
908 res = [sortrep(self.cls, i, self.name) for i in ids] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
909 return res |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
910 |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
911 def __repr__(self): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
912 r = ["proptree:" + self.name] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
913 for n in self: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
914 r.append("proptree:" + " " * n.depth + n.name) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
915 return '\n'.join(r) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
916 __str__ = __repr__ |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
917 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
918 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
919 # |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
920 # the base Database class |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
921 # |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
922 class DatabaseError(ValueError): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
923 """Error to be raised when there is some problem in the database code |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
924 """ |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
925 pass |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
926 |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
927 |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
928 class Database(object): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
929 """A database for storing records containing flexible data types. |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
930 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
931 This class defines a hyperdatabase storage layer, which the Classes use to |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
932 store their data. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
933 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
934 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
935 Transactions |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
936 ------------ |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
937 The Database should support transactions through the commit() and |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
938 rollback() methods. All other Database methods should be transaction-aware, |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
939 using data from the current transaction before looking up the database. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
940 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
941 An implementation must provide an override for the get() method so that the |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
942 in-database value is returned in preference to the in-transaction value. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
943 This is necessary to determine if any values have changed during a |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
944 transaction. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
945 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
946 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
947 Implementation |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
948 -------------- |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
949 |
|
1926
3bdd34547fa7
Remove implementations of Class.getnode from back_anydbm and rdbms_common...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1905
diff
changeset
|
950 All methods except __repr__ must be implemented by a concrete backend Database. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
951 |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
952 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
953 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
954 # flag to set on retired entries |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
955 RETIRED_FLAG = '__hyperdb_retired' |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
956 |
|
3491
0e5f15520e70
fix detection of "missing" existing values in CGI form parser [SF#1414149]
Richard Jones <richard@users.sourceforge.net>
parents:
3488
diff
changeset
|
957 BACKEND_MISSING_STRING = None |
|
0e5f15520e70
fix detection of "missing" existing values in CGI form parser [SF#1414149]
Richard Jones <richard@users.sourceforge.net>
parents:
3488
diff
changeset
|
958 BACKEND_MISSING_NUMBER = None |
|
0e5f15520e70
fix detection of "missing" existing values in CGI form parser [SF#1414149]
Richard Jones <richard@users.sourceforge.net>
parents:
3488
diff
changeset
|
959 BACKEND_MISSING_BOOLEAN = None |
|
0e5f15520e70
fix detection of "missing" existing values in CGI form parser [SF#1414149]
Richard Jones <richard@users.sourceforge.net>
parents:
3488
diff
changeset
|
960 |
|
524
dce4c75bef5a
changed all config accesses...
Richard Jones <richard@users.sourceforge.net>
parents:
490
diff
changeset
|
961 def __init__(self, config, journaltag=None): |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
962 """Open a hyperdatabase given a specifier to some storage. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
963 |
|
524
dce4c75bef5a
changed all config accesses...
Richard Jones <richard@users.sourceforge.net>
parents:
490
diff
changeset
|
964 The 'storagelocator' is obtained from config.DATABASE. |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
965 The meaning of 'storagelocator' depends on the particular |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
966 implementation of the hyperdatabase. It could be a file name, |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
967 a directory path, a socket descriptor for a connection to a |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
968 database over the network, etc. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
969 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
970 The 'journaltag' is a token that will be attached to the journal |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
971 entries for any edits done on the database. If 'journaltag' is |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
972 None, the database is opened in read-only mode: the Class.create(), |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
973 Class.set(), and Class.retire() methods are disabled. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
974 """ |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
975 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
976 |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
805
diff
changeset
|
977 def post_init(self): |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
978 """Called once the schema initialisation has finished. |
|
1840
91a4619b1a14
hyperdb grows a refresh_database() method.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1780
diff
changeset
|
979 If 'refresh' is true, we want to rebuild the backend |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
980 structures. Note that post_init can be called multiple times, |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
981 at least during regression testing. |
|
1840
91a4619b1a14
hyperdb grows a refresh_database() method.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1780
diff
changeset
|
982 """ |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
983 done = getattr(self, 'post_init_done', None) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
984 for cn in self.getclasses(): |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
985 cl = self.getclass(cn) |
|
6228
f40c6b5de370
Fix reverse multilink iteration
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6183
diff
changeset
|
986 # This will change properties if a back-multilink happens to |
|
6516
3e6c2039d0a8
Fix dict being changed during iteration
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6463
diff
changeset
|
987 # have the same class, so we need to iterate over a list made |
|
3e6c2039d0a8
Fix dict being changed during iteration
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6463
diff
changeset
|
988 # from .keys() |
|
3e6c2039d0a8
Fix dict being changed during iteration
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6463
diff
changeset
|
989 for p in list(cl.properties.keys()): |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
990 prop = cl.properties[p] |
| 6967 | 991 if not isinstance(prop, (Link, Multilink)): |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
992 continue |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
993 if prop.rev_multilink: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
994 linkcls = self.getclass(prop.classname) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
995 if prop.rev_multilink in linkcls.properties: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
996 if not done: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
997 raise ValueError( |
| 6967 | 998 "%s already a property of class %s" % |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
999 (prop.rev_multilink, linkcls.classname)) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1000 else: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1001 linkcls.properties[prop.rev_multilink] = Multilink( |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1002 cl.classname, rev_property=prop) |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1003 self.post_init_done = True |
|
1840
91a4619b1a14
hyperdb grows a refresh_database() method.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1780
diff
changeset
|
1004 |
|
91a4619b1a14
hyperdb grows a refresh_database() method.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1780
diff
changeset
|
1005 def refresh_database(self): |
|
91a4619b1a14
hyperdb grows a refresh_database() method.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1780
diff
changeset
|
1006 """Called to indicate that the backend should rebuild all tables |
|
91a4619b1a14
hyperdb grows a refresh_database() method.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1780
diff
changeset
|
1007 and structures. Not called in normal usage.""" |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
805
diff
changeset
|
1008 raise NotImplementedError |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
805
diff
changeset
|
1009 |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1010 def __getattr__(self, classname): |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1011 """A convenient way of calling self.getclass(classname).""" |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1012 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1013 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1014 def addclass(self, cl): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1015 """Add a Class to the hyperdatabase. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1016 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1017 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1018 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1019 def getclasses(self): |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1020 """Return a list of the names of all existing classes.""" |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1021 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1022 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1023 def getclass(self, classname): |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1024 """Get the Class object representing a particular class. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1025 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1026 If 'classname' is not a valid class name, a KeyError is raised. |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1027 """ |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1028 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1029 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1030 def clear(self): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1031 """Delete all database contents. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1032 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1033 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1034 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1035 def getclassdb(self, classname, mode='r'): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1036 """Obtain a connection to the class db that will be used for |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1037 multiple actions. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1038 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1039 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1040 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1041 def addnode(self, classname, nodeid, node): |
|
1928
7c1ddebe7589
Small readability improvements.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1927
diff
changeset
|
1042 """Add the specified node to its class's db. |
|
7c1ddebe7589
Small readability improvements.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1927
diff
changeset
|
1043 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1044 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1045 |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
657
diff
changeset
|
1046 def serialise(self, classname, node): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1047 """Copy the node contents, converting non-marshallable data into |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
657
diff
changeset
|
1048 marshallable data. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1049 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1050 return node |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
657
diff
changeset
|
1051 |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1052 def setnode(self, classname, nodeid, node): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1053 """Change the specified node. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1054 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1055 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1056 |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
657
diff
changeset
|
1057 def unserialise(self, classname, node): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1058 """Decode the marshalled node data |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1059 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1060 return node |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
657
diff
changeset
|
1061 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1062 def getnode(self, classname, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1063 """Get a node from the database. |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1064 |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1065 'cache' exists for backwards compatibility, and is not used. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1066 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1067 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1068 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1069 def hasnode(self, classname, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1070 """Determine if the database has a given node. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1071 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1072 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1073 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1074 def countnodes(self, classname): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1075 """Count the number of nodes that exist for a particular Class. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1076 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1077 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1078 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1079 def storefile(self, classname, nodeid, property, content): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1080 """Store the content of the file in the database. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1081 |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1082 The property may be None, in which case the filename does not |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1083 indicate which property is being saved. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1084 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1085 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1086 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1087 def getfile(self, classname, nodeid, property): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1088 """Get the content of the file in the database. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1089 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1090 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1091 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1092 def addjournal(self, classname, nodeid, action, params): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1093 """ Journal the Action |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1094 'action' may be: |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1095 |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1096 'set' -- 'params' is a dictionary of property values |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1097 'create' -- 'params' is an empty dictionary as of |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1098 Wed Nov 06 11:38:43 2002 +0000 |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1099 'link' or 'unlink' -- 'params' is (classname, nodeid, propname) |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1100 'retired' or 'restored'-- 'params' is None |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1101 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1102 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1103 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1104 def getjournal(self, classname, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1105 """ get the journal for id |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1106 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1107 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1108 |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
557
diff
changeset
|
1109 def pack(self, pack_before): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1110 """ pack the database |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1111 """ |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
557
diff
changeset
|
1112 raise NotImplementedError |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
557
diff
changeset
|
1113 |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1114 def commit(self): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1115 """ Commit the current transactions. |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1116 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1117 Save all data changed since the database was opened or since the |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1118 last commit() or rollback(). |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1119 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1120 raise NotImplementedError |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1121 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1122 def rollback(self): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1123 """ Reverse all actions from the current transaction. |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1124 |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1125 Undo all the changes made since the database was opened or the last |
|
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1126 commit() or rollback() was performed. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1127 """ |
|
477
05a46da7293a
hyperdb docstrings
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
1128 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1129 |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1130 def close(self): |
|
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1131 """Close the database. |
|
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1132 |
|
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1133 This method must be called at the end of processing. |
|
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1134 |
|
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1135 """ |
|
6621
6f35be77324c
Database class close method was not raising NotImplementedError
John Rouillard <rouilj@ieee.org>
parents:
6516
diff
changeset
|
1136 raise NotImplementedError |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1137 |
| 6967 | 1138 |
|
4306
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1139 def iter_roles(roles): |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1140 ''' handle the text processing of turning the roles list |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1141 into something python can use more easily |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1142 ''' |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1143 if not roles or not roles.strip(): |
|
5807
0467d80eaeec
Try to deal with this warning/error: DeprecationWarning: generator
John Rouillard <rouilj@ieee.org>
parents:
5697
diff
changeset
|
1144 return |
|
4306
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1145 for role in [x.lower().strip() for x in roles.split(',')]: |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1146 yield role |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1147 |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1148 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1149 # |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1150 # The base Class class |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1151 # |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1152 class Class: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1153 """ The handle to a particular class of nodes in a hyperdatabase. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1154 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1155 All methods except __repr__ and getnode must be implemented by a |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1156 concrete backend Class. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1157 """ |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1158 |
|
6238
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1159 class_re = r'^([A-Za-z](?:[A-Za-z_0-9]*[A-Za-z_]+)?)$' |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1160 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1161 def __init__(self, db, classname, **properties): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1162 """Create a new class with a given name and property specification. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1163 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1164 'classname' must not collide with the name of an existing class, |
|
6238
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1165 or a ValueError is raised. 'classname' must start with an |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1166 alphabetic letter. It must end with an alphabetic letter or '_'. |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1167 Internal characters can be alphanumeric or '_'. ValueError is |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1168 raised if the classname is not correct. |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1169 The keyword arguments in 'properties' must map names to property |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1170 objects, or a TypeError is raised. |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1171 """ |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1172 for name in 'creation activity creator actor'.split(): |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
1173 if name in properties: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1174 raise ValueError('"creation", "activity", "creator" and ' |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1175 '"actor" are reserved') |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1176 |
|
6238
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1177 if not re.match(self.class_re, classname): |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1178 raise ValueError('Class name %s is not valid. It must start ' |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1179 'with a letter, end with a letter or "_", and ' |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1180 'only have alphanumerics and "_" in the ' |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1181 'middle.' % (classname,)) |
|
6834bb5473da
Summary: Constrain format of classname and document
John Rouillard <rouilj@ieee.org>
parents:
6228
diff
changeset
|
1182 |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1183 self.classname = classname |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1184 self.properties = properties |
|
6148
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1185 # Make the class and property name known to the property |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1186 for p in properties: |
|
8497bf3f23a1
Allow to define reverse Multilinks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6006
diff
changeset
|
1187 properties[p].register(self, p) |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1188 self.db = weakref.proxy(db) # use a weak ref to avoid circularity |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1189 self.key = '' |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1190 |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1191 # should we journal changes (default yes) |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1192 self.do_journal = 1 |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1193 |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1194 # do the db-related init stuff |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1195 db.addclass(self) |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1196 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1197 actions = "create set retire restore".split() |
|
7114
33eb82ad26ba
issue2551250: Fix sorting of detectors
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7056
diff
changeset
|
1198 skey = lambda x: x[:2] |
|
33eb82ad26ba
issue2551250: Fix sorting of detectors
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7056
diff
changeset
|
1199 self.auditors = dict([(a, PrioList(key=skey)) for a in actions]) |
|
33eb82ad26ba
issue2551250: Fix sorting of detectors
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7056
diff
changeset
|
1200 self.reactors = dict([(a, PrioList(key=skey)) for a in actions]) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1201 |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
1202 def __repr__(self): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1203 """Slightly more useful representation |
|
6183
bb198596f85c
Fix __repr__ of hyperdb.Class
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6179
diff
changeset
|
1204 Note that an error message can be raised at a point |
|
bb198596f85c
Fix __repr__ of hyperdb.Class
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6179
diff
changeset
|
1205 where self.classname isn't known yet if the error |
|
bb198596f85c
Fix __repr__ of hyperdb.Class
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6179
diff
changeset
|
1206 occurs during schema parsing. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1207 """ |
| 6967 | 1208 cn = getattr(self, 'classname', 'Unknown') |
|
6183
bb198596f85c
Fix __repr__ of hyperdb.Class
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6179
diff
changeset
|
1209 return '<hyperdb.Class "%s">' % cn |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
1210 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1211 # Editing nodes: |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1212 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1213 def create(self, **propvalues): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1214 """Create a new node of this class and return its id. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1215 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1216 The keyword arguments in 'propvalues' map property names to values. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1217 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1218 The values of arguments must be acceptable for the types of their |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1219 corresponding properties or a TypeError is raised. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1220 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1221 If this class has a key property, it must be present and its value |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1222 must not collide with other key strings or a ValueError is raised. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1223 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1224 Any other properties on this class that are missing from the |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1225 'propvalues' dictionary are set to None. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1226 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1227 If an id in a link or multilink property does not refer to a valid |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1228 node, an IndexError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1229 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1230 raise NotImplementedError |
|
775
4409798dfa15
Can debug to stdout now
Richard Jones <richard@users.sourceforge.net>
parents:
764
diff
changeset
|
1231 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1232 _marker = [] |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1233 |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
1234 def get(self, nodeid, propname, default=_marker, cache=1): |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1235 """Get the value of a property on an existing node of this class. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1236 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1237 'nodeid' must be the id of an existing node of this class or an |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1238 IndexError is raised. 'propname' must be the name of a property |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1239 of this class or a KeyError is raised. |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
1240 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1241 'cache' exists for backwards compatibility, and is not used. |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1242 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1243 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1244 |
|
1926
3bdd34547fa7
Remove implementations of Class.getnode from back_anydbm and rdbms_common...
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1905
diff
changeset
|
1245 # not in spec |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1246 def getnode(self, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1247 """ Return a convenience wrapper for the node. |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
1248 |
|
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
1249 'nodeid' must be the id of an existing node of this class or an |
|
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
1250 IndexError is raised. |
|
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
1251 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1252 'cache' exists for backwards compatibility, and is not used. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1253 """ |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1254 return Node(self, nodeid) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1255 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1256 def getnodeids(self, retired=None): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1257 """Retrieve all the ids of the nodes for a particular Class. |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1258 """ |
|
1864
969a14faf707
Fixed "documentation" of getnodeids in roundup.hyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
1840
diff
changeset
|
1259 raise NotImplementedError |
|
969a14faf707
Fixed "documentation" of getnodeids in roundup.hyperdb
Richard Jones <richard@users.sourceforge.net>
parents:
1840
diff
changeset
|
1260 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1261 def set(self, nodeid, **propvalues): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1262 """Modify a property on an existing node of this class. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1263 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1264 'nodeid' must be the id of an existing node of this class or an |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1265 IndexError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1266 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1267 Each key in 'propvalues' must be the name of a property of this |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1268 class or a KeyError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1269 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1270 All values in 'propvalues' must be acceptable types for their |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1271 corresponding properties or a TypeError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1272 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1273 If the value of the key property is set, it must not collide with |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1274 other key strings or a ValueError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1275 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1276 If the value of a Link or Multilink property contains an invalid |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1277 node id, a ValueError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1278 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1279 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1280 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1281 def retire(self, nodeid): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1282 """Retire a node. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1283 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1284 The properties on the node remain available from the get() method, |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1285 and the node's id is never reused. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1286 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1287 Retired nodes are not returned by the find(), list(), or lookup() |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1288 methods, and other nodes may reuse the values of their key properties. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1289 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1290 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1291 |
|
1523
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1470
diff
changeset
|
1292 def restore(self, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1293 """Restpre a retired node. |
|
1523
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1470
diff
changeset
|
1294 |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1470
diff
changeset
|
1295 Make node available for all operations like it was before retirement. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1296 """ |
|
1523
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1470
diff
changeset
|
1297 raise NotImplementedError |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1298 |
|
940
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
910
diff
changeset
|
1299 def is_retired(self, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1300 """Return true if the node is rerired |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1301 """ |
|
940
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
910
diff
changeset
|
1302 raise NotImplementedError |
|
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
910
diff
changeset
|
1303 |
|
894
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1304 def destroy(self, nodeid): |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1305 """Destroy a node. |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1306 |
|
894
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1307 WARNING: this method should never be used except in extremely rare |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1308 situations where there could never be links to the node being |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1309 deleted |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1310 |
|
894
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1311 WARNING: use retire() instead |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1312 |
|
894
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1313 WARNING: the properties of this node will not be available ever again |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1314 |
|
894
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1315 WARNING: really, use retire() instead |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1316 |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1317 Well, I think that's enough warnings. This method exists mostly to |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1318 support the session storage of the cgi interface. |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1319 |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1320 The node is completely removed from the hyperdb, including all journal |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1321 entries. It will no longer be available, and will generally break code |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1322 if there are any references to the node. |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1323 """ |
|
cbefecea6c74
Gordon, does this help?
Richard Jones <richard@users.sourceforge.net>
parents:
883
diff
changeset
|
1324 |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1325 def history(self, nodeid, enforceperm=True, skipquiet=True): |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1326 """Retrieve the journal of edits on a particular node. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1327 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1328 'nodeid' must be the id of an existing node of this class or an |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1329 IndexError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1330 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1331 The returned list contains tuples of the form |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1332 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1333 (date, tag, action, params) |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1334 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1335 'date' is a Timestamp object specifying the time of the change and |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1336 'tag' is the journaltag specified when the database was opened. |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1337 |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1338 If the property to be displayed is a quiet property, it will |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1339 not be shown. This can be disabled by setting skipquiet=False. |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1340 |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1341 If the user requesting the history does not have View access |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1342 to the property, the journal entry will not be shown. This can |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1343 be disabled by setting enforceperm=False. |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1344 |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1345 Note that there is a check for obsolete properties and classes |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1346 resulting from history changes. These are also only checked if |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1347 enforceperm is True. |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1348 """ |
|
4483
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1349 if not self.do_journal: |
|
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1350 raise ValueError('Journalling is disabled for this class') |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1351 |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1352 perm = self.db.security.hasPermission |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1353 journal = [] |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1354 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1355 uid = self.db.getuid() # id of the person requesting the history |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1356 |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1357 # Roles of the user and the configured obsolete_history_roles |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1358 hr = set(iter_roles(self.db.config.OBSOLETE_HISTORY_ROLES)) |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1359 ur = set(self.db.user.get_roles(uid)) |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1360 allow_obsolete = bool(hr & ur) |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1361 |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1362 for j in self.db.getjournal(self.classname, nodeid): |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1363 # hide/remove journal entry if: |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1364 # property is quiet |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1365 # property is not (viewable or editable) |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1366 # property is obsolete and not allow_obsolete |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1367 id, evt_date, user, action, args = j |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1368 if logger.isEnabledFor(logging.DEBUG): |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1369 j_repr = "%s" % (j,) |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1370 else: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1371 j_repr = '' |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1372 if args and isinstance(args, type({})): |
|
5460
87f22a5d65ca
container modification while iterating over it
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5397
diff
changeset
|
1373 for key in list(args.keys()): |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1374 if key not in self.properties: |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1375 if enforceperm and not allow_obsolete: |
|
5460
87f22a5d65ca
container modification while iterating over it
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5397
diff
changeset
|
1376 del args[key] |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1377 continue |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1378 if skipquiet and self.properties[key].quiet: |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1379 logger.debug("skipping quiet property" |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1380 " %s::%s in %s", |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1381 self.classname, key, j_repr) |
|
5460
87f22a5d65ca
container modification while iterating over it
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5397
diff
changeset
|
1382 del args[key] |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1383 continue |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1384 if enforceperm and not (perm("View", |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1385 uid, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1386 self.classname, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1387 property=key) or |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1388 perm("Edit", |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1389 uid, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1390 self.classname, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1391 property=key)): |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1392 logger.debug("skipping unaccessible property " |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1393 "%s::%s seen by user%s in %s", |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1394 self.classname, key, uid, j_repr) |
|
5460
87f22a5d65ca
container modification while iterating over it
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5397
diff
changeset
|
1395 del args[key] |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1396 continue |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1397 if not args: |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1398 logger.debug("Omitting journal entry for %s%s" |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1399 " all props removed in: %s", |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1400 self.classname, nodeid, j_repr) |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1401 continue |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1402 journal.append(j) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1403 elif action in ['link', 'unlink'] and isinstance(args, type(())): |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1404 # definitions: |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1405 # myself - object whose history is being filtered |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1406 # linkee - object/class whose property is changing to |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1407 # include/remove myself |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1408 # link property - property of the linkee class that is changing |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1409 # |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1410 # Remove the history item if |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1411 # linkee.link property (key) is quiet |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1412 # linkee class.link property is not (viewable or editable) |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1413 # to user |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1414 # [ should linkee object.link property is not |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1415 # (viewable or editable) to user be included?? ] |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1416 # linkee object (linkcl, linkid) is not |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1417 # (viewable or editable) to user |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1418 if len(args) == 3: |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1419 # e.g. for issue3 blockedby adds link to issue5 with: |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1420 # j = id, evt_date, user, action, args |
|
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1421 # 3|20170528045201.484|5|link|('issue', '5', 'blockedby') |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1422 linkcl, linkid, key = args |
|
5315
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1423 cls = None |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1424 try: |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1425 cls = self.db.getclass(linkcl) |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1426 except KeyError: |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1427 pass |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1428 # obsolete property or class |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1429 if not cls or key not in cls.properties: |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1430 if not enforceperm or allow_obsolete: |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1431 journal.append(j) |
|
5a014410f254
Fix issue2550954: History display breaks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5309
diff
changeset
|
1432 continue |
|
5527
a7c3cd2edf51
No traceback for non-existent items in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5525
diff
changeset
|
1433 # obsolete linked-to item |
|
a7c3cd2edf51
No traceback for non-existent items in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5525
diff
changeset
|
1434 try: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1435 cls.get(linkid, key) # does linkid exist |
|
5527
a7c3cd2edf51
No traceback for non-existent items in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5525
diff
changeset
|
1436 except IndexError: |
|
a7c3cd2edf51
No traceback for non-existent items in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5525
diff
changeset
|
1437 if not enforceperm or allow_obsolete: |
|
a7c3cd2edf51
No traceback for non-existent items in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5525
diff
changeset
|
1438 journal.append(j) |
|
a7c3cd2edf51
No traceback for non-existent items in history
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5525
diff
changeset
|
1439 continue |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1440 # is the updated property quiet? |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1441 if skipquiet and cls.properties[key].quiet: |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1442 logger.debug("skipping quiet property: " |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1443 "%s %sed %s%s", |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1444 j_repr, action, self.classname, nodeid) |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1445 continue |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1446 # can user view the property in linkee class |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1447 if enforceperm and not (perm("View", |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1448 uid, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1449 linkcl, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1450 property=key) or |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1451 perm("Edit", |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1452 uid, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1453 linkcl, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1454 property=key)): |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1455 logger.debug("skipping unaccessible property: " |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1456 "%s with uid %s %sed %s%s", |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1457 j_repr, uid, action, |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1458 self.classname, nodeid) |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1459 continue |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1460 # check access to linkee object |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1461 if enforceperm and not (perm("View", |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1462 uid, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1463 cls.classname, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1464 itemid=linkid) or |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1465 perm("Edit", |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1466 uid, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1467 cls.classname, |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1468 itemid=linkid)): |
|
5261
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1469 logger.debug("skipping unaccessible object: " |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1470 "%s uid %s %sed %s%s", |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1471 j_repr, uid, action, |
|
53a853c06e9a
Fixed quiet history filter for linked items. Test for same fixed.
John Rouillard <rouilj@ieee.org>
parents:
5260
diff
changeset
|
1472 self.classname, nodeid) |
|
5257
928512faf565
- issue2550864: Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5248
diff
changeset
|
1473 continue |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1474 journal.append(j) |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1475 else: |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1476 logger.error("Invalid %s journal entry for %s%s: %s", |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1477 action, self.classname, nodeid, j) |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1478 elif action in ['create', 'retired', 'restored']: |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1479 journal.append(j) |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1480 else: |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1481 logger.warning("Possibly malformed journal for %s%s %s", |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1482 self.classname, nodeid, j) |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
1483 return journal |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1484 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1485 # Locating nodes: |
|
627
952679be9e2c
Added simple editing for classes that don't define a templated interface.
Richard Jones <richard@users.sourceforge.net>
parents:
618
diff
changeset
|
1486 def hasnode(self, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1487 """Determine if the given nodeid actually exists |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
1488 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1489 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1490 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1491 def setkey(self, propname): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1492 """Select a String property of this class to be the key property. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1493 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1494 'propname' must be the name of a String property of this class or |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1495 None, or a TypeError is raised. The values of the key property on |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1496 all existing nodes must be unique or a ValueError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1497 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1498 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1499 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1500 def setlabelprop(self, labelprop): |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1501 """Set the label property. Used for override of labelprop |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1502 resolution order. |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1503 """ |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1504 if labelprop not in self.getprops(): |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5327
diff
changeset
|
1505 raise ValueError(_("Not a property name: %s") % labelprop) |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1506 self._labelprop = labelprop |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1507 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1508 def setorderprop(self, orderprop): |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1509 """Set the order property. Used for override of orderprop |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1510 resolution order |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1511 """ |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1512 if orderprop not in self.getprops(): |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5327
diff
changeset
|
1513 raise ValueError(_("Not a property name: %s") % orderprop) |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1514 self._orderprop = orderprop |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1515 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1516 def getkey(self): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1517 """Return the name of the key property for this class or None.""" |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1518 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1519 |
|
188
1536be43d2fa
Roundupdb now appends "mailing list" information to its messages...
Richard Jones <richard@users.sourceforge.net>
parents:
172
diff
changeset
|
1520 def labelprop(self, default_to_id=0): |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1521 """Return the property name for a label for the given node. |
|
123
51cce9671db0
Cleanup of the link label generation.
Richard Jones <richard@users.sourceforge.net>
parents:
118
diff
changeset
|
1522 |
|
51cce9671db0
Cleanup of the link label generation.
Richard Jones <richard@users.sourceforge.net>
parents:
118
diff
changeset
|
1523 This method attempts to generate a consistent label for the node. |
|
51cce9671db0
Cleanup of the link label generation.
Richard Jones <richard@users.sourceforge.net>
parents:
118
diff
changeset
|
1524 It tries the following in order: |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1525 |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1526 0. self._labelprop if set |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1527 1. key property |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1528 2. "name" property |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1529 3. "title" property |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1530 4. first property from the sorted property name list |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1531 """ |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1532 if hasattr(self, '_labelprop'): |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1533 return self._labelprop |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1534 k = self.getkey() |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1535 if k: |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1536 return k |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1537 props = self.getprops() |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
1538 if 'name' in props: |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1539 return 'name' |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
1540 elif 'title' in props: |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1541 return 'title' |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1542 if default_to_id: |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1543 return 'id' |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
1544 props = sorted(props.keys()) |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1545 return props[0] |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1546 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1547 def orderprop(self): |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1548 """Return the property name to use for sorting for the given node. |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1549 |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1550 This method computes the property for sorting. |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1551 It tries the following in order: |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1552 |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1553 0. self._orderprop if set |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1554 1. "order" property |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1555 2. self.labelprop() |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1556 """ |
|
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1557 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1558 if hasattr(self, '_orderprop'): |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1559 return self._orderprop |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1560 props = self.getprops() |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
1561 if 'order' in props: |
|
3476
1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
Richard Jones <richard@users.sourceforge.net>
parents:
3455
diff
changeset
|
1562 return 'order' |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1563 return self.labelprop() |
|
123
51cce9671db0
Cleanup of the link label generation.
Richard Jones <richard@users.sourceforge.net>
parents:
118
diff
changeset
|
1564 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1565 def lookup(self, keyvalue): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1566 """Locate a particular node by its key property and return its id. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1567 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1568 If this class has no key property, a TypeError is raised. If the |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1569 'keyvalue' matches one of the values for the key property among |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1570 the nodes in this class, the matching node's id is returned; |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1571 otherwise a KeyError is raised. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1572 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1573 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1574 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1575 def find(self, **propspec): |
|
834
568eed5fb4fd
Optimize Class.find so that the propspec can contain a set of ids to match.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
825
diff
changeset
|
1576 """Get the ids of nodes in this class which link to the given nodes. |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1577 |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
1578 'propspec' consists of keyword args propname={nodeid:1,} |
| 883 | 1579 'propname' must be the name of a property in this class, or a |
| 1580 KeyError is raised. That property must be a Link or Multilink | |
| 1581 property, or a TypeError is raised. | |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1582 |
|
834
568eed5fb4fd
Optimize Class.find so that the propspec can contain a set of ids to match.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
825
diff
changeset
|
1583 Any node in this class whose 'propname' property links to any of the |
|
568eed5fb4fd
Optimize Class.find so that the propspec can contain a set of ids to match.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
825
diff
changeset
|
1584 nodeids will be returned. Used by the full text indexing, which knows |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1585 that "foo" occurs in msg1, msg3 and file7, so we have hits on these |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1586 issues: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1587 |
|
834
568eed5fb4fd
Optimize Class.find so that the propspec can contain a set of ids to match.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
825
diff
changeset
|
1588 db.issue.find(messages={'1':1,'3':1}, files={'7':1}) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1589 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1590 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1591 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1592 def _filter(self, search_matches, filterspec, sort=(None, None), |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1593 group=(None, None), retired=False, exact_match_spec={}): |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1594 """For some backends this implements the non-transitive |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1595 search, for more information see the filter method. |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1596 """ |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1597 raise NotImplementedError |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1598 |
| 6967 | 1599 def _proptree(self, filterspec, exact_match_spec=None, sortattr=None, |
|
5871
acc4a128ab9b
Backwards-compatible signature of _proptree method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5869
diff
changeset
|
1600 retr=False): |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1601 """Build a tree of all transitive properties in the given |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1602 exact_match_spec/filterspec. |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1603 If we retrieve (retr is True) linked items we don't follow |
|
6413
7b1b6dffc7ed
Fix searching+sorting for Link properties
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6412
diff
changeset
|
1604 across multilinks or links. |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1605 """ |
|
6677
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1606 if filterspec is None: |
|
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1607 filterspec = {} |
| 6967 | 1608 if exact_match_spec is None: |
| 1609 exact_match_spec = {} | |
| 1610 if sortattr is None: | |
| 1611 sortattr = [] | |
|
6677
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1612 |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1613 proptree = Proptree(self.db, self, '', self.getprops(), retr=retr) |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1614 for exact, spec in enumerate((filterspec, exact_match_spec)): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1615 for key, v in spec.items(): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1616 keys = key.split('.') |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1617 p = proptree |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1618 mlseen = False |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1619 for k in keys: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1620 if isinstance(p.propclass, Multilink): |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1621 mlseen = True |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1622 isnull = v == '-1' or v is None |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1623 islist = isinstance(v, type([])) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1624 nullin = islist and ('-1' in v or None in v) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1625 r = retr and not mlseen and not isnull and not nullin |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1626 p = p.append(k, retr=r) |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1627 if exact: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1628 if isinstance(v, type([])): |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1629 vv = [] |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1630 for x in v: |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1631 vv.append(Exact_Match(x)) |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
1632 p.set_val(vv, result=False) |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1633 else: |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
1634 p.set_val([Exact_Match(v)], result=False) |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1635 else: |
|
6403
9957d8d10783
Tests and bug-fix for issue2551119
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6402
diff
changeset
|
1636 p.set_val(v, result=False) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1637 multilinks = {} |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1638 for s in sortattr: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1639 keys = s[1].split('.') |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1640 p = proptree |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1641 mlseen = False |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1642 for k in keys: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1643 if isinstance(p.propclass, Multilink): |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1644 mlseen = True |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1645 r = retr and not mlseen |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1646 p = p.append(k, need_for='sort', retr=r) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1647 if isinstance(p.propclass, Multilink): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1648 multilinks[p] = True |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1649 if p.cls: |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1650 p = p.append(p.cls.orderprop(), need_for='sort') |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1651 if p.sort_direction: # if orderprop is also specified explicitly |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1652 continue |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1653 p.sort_direction = s[0] |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1654 proptree.sortattr.append(p) |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
1655 for p in multilinks.keys(): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1656 sattr = {} |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1657 for c in p: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1658 if c.sort_direction: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1659 sattr[c] = True |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1660 for sa in proptree.sortattr: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1661 if sa in sattr: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1662 p.sortattr.append(sa) |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1663 return proptree |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1664 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1665 def get_transitive_prop(self, propname_path, default=None): |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1666 """Expand a transitive property (individual property names |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1667 separated by '.' into a new property at the end of the path. If |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1668 one of the names does not refer to a valid property, we return |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1669 None. |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1670 Example propname_path (for class issue): "messages.author" |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1671 """ |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1672 props = self.db.getclass(self.classname).getprops() |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1673 for k in propname_path.split('.'): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1674 try: |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1675 prop = props[k] |
|
4408
06af6d5bedbe
fix for incorrect except: syntax, issue2550661
Richard Jones <richard@users.sourceforge.net>
parents:
4306
diff
changeset
|
1676 except (KeyError, TypeError): |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1677 return default |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1678 cl = getattr(prop, 'classname', None) |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1679 props = None |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1680 if cl: |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1681 props = self.db.getclass(cl).getprops() |
|
3635
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1682 return prop |
|
53987aa153d2
Transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3634
diff
changeset
|
1683 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1684 def _sortattr(self, sort=[], group=[]): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1685 """Build a single list of sort attributes in the correct order |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1686 with sanity checks (no duplicate properties) included. Always |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1687 sort last by id -- if id is not already in sortattr. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1688 """ |
|
6677
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1689 if sort is None: |
| 6967 | 1690 sort = [(None, None)] |
|
6677
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1691 if group is None: |
|
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1692 group = [(None, None)] |
|
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1693 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1694 seen = {} |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1695 sortattr = [] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1696 for srt in group, sort: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1697 if not isinstance(srt, list): |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1698 srt = [srt] |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1699 for s in srt: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1700 if s[1] and s[1] not in seen: |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1701 sortattr.append((s[0] or '+', s[1])) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1702 seen[s[1]] = True |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1703 if 'id' not in seen: |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1704 sortattr.append(('+', 'id')) |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1705 return sortattr |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1706 |
|
5318
506c7ee9a385
Add a 'retired' parameter to Class.filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5315
diff
changeset
|
1707 def filter(self, search_matches, filterspec, sort=[], group=[], |
|
5869
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1708 retired=False, exact_match_spec={}, limit=None, offset=None): |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1709 """Return a list of the ids of the active nodes in this class that |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1710 match the 'filter' spec, sorted by the group spec and then the |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1711 sort spec. |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1712 |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1713 "search_matches" is a container type which by default is None |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1714 and optionally contains IDs of items to match. If non-empty only |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1715 IDs of the initial set are returned. |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1716 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1717 "filterspec" is {propname: value(s)} |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1718 "exact_match_spec" is the same format as "filterspec" but |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1719 specifies exact match for the given propnames. This only makes a |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1720 difference for String properties, these specify case insensitive |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1721 substring search when in "filterspec" and exact match when in |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1722 exact_match_spec. |
|
1249
6c24a86a12ae
Fixes for SourceForge tracker bugs.
Richard Jones <richard@users.sourceforge.net>
parents:
1244
diff
changeset
|
1723 |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1724 "sort" and "group" are [(dir, prop), ...] where dir is '+', '-' |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1725 or None and prop is a prop name or None. Note that for |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1726 backward-compatibility reasons a single (dir, prop) tuple is |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1727 also allowed. |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1728 |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1729 The parameter retired when set to False, returns only live |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1730 (un-retired) results. When setting it to True, only retired |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1731 items are returned. If None, both retired and unretired items |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1732 are returned. The default is False, i.e. only live items are |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1733 returned by default. |
|
1249
6c24a86a12ae
Fixes for SourceForge tracker bugs.
Richard Jones <richard@users.sourceforge.net>
parents:
1244
diff
changeset
|
1734 |
|
5869
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1735 The "limit" and "offset" parameters define a limit on the number |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1736 of results returned and an offset before returning any results, |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1737 respectively. These can be used when displaying a number of |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1738 items in a pagination application or similar. A common use-case |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1739 is returning the first item of a sorted search by specifying |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1740 limit=1 (i.e. the maximum or minimum depending on sort order). |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1741 |
|
6677
8ab98de22df0
issue2551159 - cl.filter fails if filterspec is None ...
John Rouillard <rouilj@ieee.org>
parents:
6621
diff
changeset
|
1742 The filter must match all properties specified. If the property |
|
3455
e01bc6d65fa9
fixed documentation of filter()...
Richard Jones <richard@users.sourceforge.net>
parents:
3399
diff
changeset
|
1743 value to match is a list: |
|
e01bc6d65fa9
fixed documentation of filter()...
Richard Jones <richard@users.sourceforge.net>
parents:
3399
diff
changeset
|
1744 |
|
e01bc6d65fa9
fixed documentation of filter()...
Richard Jones <richard@users.sourceforge.net>
parents:
3399
diff
changeset
|
1745 1. String properties must match all elements in the list, and |
|
e01bc6d65fa9
fixed documentation of filter()...
Richard Jones <richard@users.sourceforge.net>
parents:
3399
diff
changeset
|
1746 2. Other properties must match any of the elements in the list. |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1747 |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1748 This also means that for strings in exact_match_spec it doesn't |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1749 make sense to specify multiple values because those cannot all |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1750 be matched exactly. |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1751 |
|
6409
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1752 For Link and Multilink properties the special ID value '-1' |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1753 matches empty Link or Multilink fields. For Multilinks a postfix |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1754 expression syntax using negative ID numbers (as strings) as |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1755 operators is supported. Each non-negative number (or '-1') is |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1756 pushed on an operand stack. A negative number pops the required |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1757 number of arguments from the stack, applies the operator, and |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1758 pushes the result. The following operators are supported: |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1759 - -2 stands for 'NOT' and takes one argument |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1760 - -3 stands for 'AND' and takes two arguments |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1761 - -4 stands for 'OR' and takes two arguments |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1762 Note that this special handling of ID arguments is applied only |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1763 when a negative number smaller than -1 is encountered as an ID |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1764 in the filter call. Otherwise the implicit OR default applies. |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1765 Examples of using Multilink expressions would be |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1766 - '1', '2', '-4', '3', '4', '-4', '-3' |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1767 would search for IDs (1 or 2) and (3 or 4) |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1768 - '-1' '-2' would search for all non-empty Multilinks |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1769 |
|
ce99e0d39262
Add documentation for multilink expression syntax
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6403
diff
changeset
|
1770 |
|
5867
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1771 The propname in filterspec and prop in a sort/group spec may be |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1772 transitive, i.e., it may contain properties of the form |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1773 link.link.link.name, e.g. you can search for all issues where a |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1774 message was added by a certain user in the last week with a |
|
ee2e8f8d6648
Implement exact string search
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5809
diff
changeset
|
1775 filterspec of |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1776 {'messages.author' : '42', 'messages.creation' : '.-1w;'} |
|
3924
21d3d7eeea8c
assorted pyflakes fixes
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3802
diff
changeset
|
1777 |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1778 Implementation note: |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1779 This implements a non-optimized version of Transitive search |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1780 using _filter implemented in a backend class. A more efficient |
|
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1781 version can be implemented in the individual backends -- e.g., |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1782 an SQL backend will want to create a single SQL statement and |
|
3634
57c66056ffe4
Implemented what I'll call for now "transitive searching"...
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3621
diff
changeset
|
1783 override the filter method instead of implementing _filter. |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1929
diff
changeset
|
1784 """ |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1785 sortattr = self._sortattr(sort=sort, group=group) |
|
5871
acc4a128ab9b
Backwards-compatible signature of _proptree method
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5869
diff
changeset
|
1786 proptree = self._proptree(filterspec, exact_match_spec, sortattr) |
|
5318
506c7ee9a385
Add a 'retired' parameter to Class.filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5315
diff
changeset
|
1787 proptree.search(search_matches, retired=retired) |
|
5869
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1788 if offset is not None or limit is not None: |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1789 items = proptree.sort() |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1790 if limit and offset: |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1791 return items[offset:offset+limit] |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1792 elif offset is not None: |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1793 return items[offset:] |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1794 else: |
|
16e1255b16cf
Implement limit and offset for filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5867
diff
changeset
|
1795 return items[:limit] |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1796 return proptree.sort() |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1797 |
|
4472
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1798 # non-optimized filter_iter, a backend may chose to implement a |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1799 # better version that provides a real iterator that pre-fills the |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1800 # cache for each id returned. Note that the filter_iter doesn't |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1801 # promise to correctly sort by multilink (which isn't sane to do |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1802 # anyway). |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1803 filter_iter = filter |
|
34dce76bb202
Multilink fixes and optimizations:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4431
diff
changeset
|
1804 |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1805 def filter_with_permissions(self, search_matches, filterspec, sort=[], |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1806 group=[], retired=False, exact_match_spec={}, |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1807 limit=None, offset=None, |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1808 permission='View', userid=None): |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1809 """ Do the same as filter but return only the items the user is |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1810 entitled to see, running the results through security checks. |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1811 The userid defaults to the current database user. |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1812 """ |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1813 if userid is None: |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1814 userid = self.db.getuid() |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1815 cn = self.classname |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1816 sec = self.db.security |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1817 filterspec = sec.filterFilterspec(userid, cn, filterspec) |
|
8129
627871650f4f
Filter exact_match_spec in filter_with_permissions
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8126
diff
changeset
|
1818 if exact_match_spec: |
|
627871650f4f
Filter exact_match_spec in filter_with_permissions
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8126
diff
changeset
|
1819 exact_match_spec = sec.filterFilterspec(userid, cn, |
|
627871650f4f
Filter exact_match_spec in filter_with_permissions
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8126
diff
changeset
|
1820 exact_match_spec) |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1821 sort = sec.filterSortspec(userid, cn, sort) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1822 group = sec.filterSortspec(userid, cn, group) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1823 item_ids = self.filter(search_matches, filterspec, sort, group, |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1824 retired, exact_match_spec, limit, offset) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1825 check = sec.hasPermission |
|
8139
de58ff07890e
Rename parameter of hasPermission
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8136
diff
changeset
|
1826 if check(permission, userid, cn, skip_permissions_with_check = True): |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1827 allowed = item_ids |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1828 else: |
|
8136
5a2b9435a04d
Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8135
diff
changeset
|
1829 debug = self.db.config.RDBMS_DEBUG_FILTER |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1830 # Note that is_filterable returns True if no permissions are |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1831 # found. This makes it fail early (with an empty allowed list) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1832 # instead of running through all ids with an empty |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1833 # permission list. |
|
8136
5a2b9435a04d
Make permission filter functions configurable
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8135
diff
changeset
|
1834 if not debug and sec.is_filterable(permission, userid, cn): |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1835 new_ids = set(item_ids) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1836 confirmed = set() |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1837 for perm in sec.filter_iter(permission, userid, cn): |
|
8135
aa5ae3f84889
Test new filter function in security checks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8129
diff
changeset
|
1838 fargs = perm.filter(self.db, userid, self) |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1839 for farg in fargs: |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1840 farg.update(sort=[], group=[], retired=None) |
|
8135
aa5ae3f84889
Test new filter function in security checks
Ralf Schlatterbeck <rsc@runtux.com>
parents:
8129
diff
changeset
|
1841 result = self.filter(list(new_ids), **farg) |
|
8126
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1842 new_ids.difference_update(result) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1843 confirmed.update(result) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1844 # all allowed? |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1845 if not new_ids: |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1846 break |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1847 # all allowed? |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1848 if not new_ids: |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1849 break |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1850 # Need to sort again in database |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1851 allowed = self.filter(confirmed, {}, sort=sort, group=group, |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1852 retired=None) |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1853 else: # Last resort: filter in python |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1854 allowed = [id for id in item_ids |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1855 if check(permission, userid, cn, itemid=id)] |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1856 return allowed |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1857 |
|
f7bd22bdef9d
Move permission check code to hyperdb
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7526
diff
changeset
|
1858 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1859 def count(self): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1860 """Get the number of nodes in this class. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1861 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1862 If the returned integer is 'numnodes', the ids of all the nodes |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1863 in this class run from 1 to numnodes, and numnodes+1 will be the |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1864 id of the next node to be created in this class. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1865 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1866 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1867 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1868 # Manipulating properties: |
|
262
ab921dc53ccd
Added nicer command-line item adding:
Richard Jones <richard@users.sourceforge.net>
parents:
236
diff
changeset
|
1869 def getprops(self, protected=1): |
|
ab921dc53ccd
Added nicer command-line item adding:
Richard Jones <richard@users.sourceforge.net>
parents:
236
diff
changeset
|
1870 """Return a dictionary mapping property names to property objects. |
|
ab921dc53ccd
Added nicer command-line item adding:
Richard Jones <richard@users.sourceforge.net>
parents:
236
diff
changeset
|
1871 If the "protected" flag is true, we include protected properties - |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1872 those which may not be modified. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1873 """ |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1874 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1875 |
| 6967 | 1876 def get_required_props(self, propnames=None): |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1877 """Return a dict of property names mapping to property objects. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1878 All properties that have the "required" flag set will be |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1879 returned in addition to all properties in the propnames |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1880 parameter. |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1881 """ |
| 6967 | 1882 if propnames is None: |
| 1883 propnames = [] | |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1884 props = self.getprops(protected=False) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1885 pdict = dict([(p, props[p]) for p in propnames]) |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
1886 pdict.update([(k, v) for k, v in props.items() if v.required]) |
|
3682
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1887 return pdict |
|
193f316dbbe9
More transitive-property support.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3668
diff
changeset
|
1888 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1889 def addprop(self, **properties): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1890 """Add properties to this class. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1891 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1892 The keyword arguments in 'properties' must map names to property |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1893 objects, or a TypeError is raised. None of the keys in 'properties' |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1894 may collide with the names of existing properties, or a ValueError |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1895 is raised before any properties have been added. |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1896 """ |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1897 raise NotImplementedError |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1898 |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
805
diff
changeset
|
1899 def index(self, nodeid): |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1900 """Add (or refresh) the node to search indexes""" |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
841
diff
changeset
|
1901 raise NotImplementedError |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
805
diff
changeset
|
1902 |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1903 # |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1904 # Detector interface |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1905 # |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1906 def audit(self, event, detector, priority=100): |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1907 """Register an auditor detector""" |
|
3743
e754cc14e76a
fix unstable ordering of detectors [SF#1585378]
Richard Jones <richard@users.sourceforge.net>
parents:
3695
diff
changeset
|
1908 self.auditors[event].append((priority, detector.__name__, detector)) |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1909 |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1910 def fireAuditors(self, event, nodeid, newvalues): |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1911 """Fire all registered auditors""" |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1912 for _prio, _name, audit in self.auditors[event]: |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1913 try: |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1914 audit(self.db, self, nodeid, newvalues) |
|
5084
675b3b3d88f0
Fix issue2550826 third try. This limits the capture of exceptions to
John Rouillard <rouilj@ieee.org>
parents:
5080
diff
changeset
|
1915 except (EnvironmentError, ArithmeticError) as e: |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1916 tb = traceback.format_exc() |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1917 html = ("<h1>Traceback</h1>" + str(tb).replace('\n', '<br>'). |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1918 replace(' ', ' ')) |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1919 txt = 'Caught exception %s: %s\n%s' % (str(type(e)), e, tb) |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1920 exc_info = sys.exc_info() |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1921 subject = "Error: %s" % exc_info[1] |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1922 raise DetectorError(subject, html, txt) |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1923 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1924 def react(self, event, detector, priority=100): |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1925 """Register a reactor detector""" |
|
3743
e754cc14e76a
fix unstable ordering of detectors [SF#1585378]
Richard Jones <richard@users.sourceforge.net>
parents:
3695
diff
changeset
|
1926 self.reactors[event].append((priority, detector.__name__, detector)) |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1927 |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1928 def fireReactors(self, event, nodeid, oldvalues): |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1929 """Fire all registered reactors""" |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1930 for _prio, _name, react in self.reactors[event]: |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1931 try: |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1932 react(self.db, self, nodeid, oldvalues) |
|
5084
675b3b3d88f0
Fix issue2550826 third try. This limits the capture of exceptions to
John Rouillard <rouilj@ieee.org>
parents:
5080
diff
changeset
|
1933 except (EnvironmentError, ArithmeticError) as e: |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1934 tb = traceback.format_exc() |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1935 html = ("<h1>Traceback</h1>" + str(tb).replace('\n', '<br>'). |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1936 replace(' ', ' ')) |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1937 txt = 'Caught exception %s: %s\n%s' % (str(type(e)), e, tb) |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1938 exc_info = sys.exc_info() |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1939 subject = "Error: %s" % exc_info[1] |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
5069
diff
changeset
|
1940 raise DetectorError(subject, html, txt) |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1941 |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1942 # |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1943 # import / export support |
|
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1944 # |
| 2496 | 1945 def export_propnames(self): |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
1946 """List the property names for export from this Class""" |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
1947 propnames = sorted(self.getprops().keys()) |
| 2496 | 1948 return propnames |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1949 |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1950 def import_journals(self, entries): |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1951 """Import a class's journal. |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1952 |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1953 Uses setjournal() to set the journal for each item. |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1954 Strategy for import: Sort first by id, then import journals for |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1955 each id, this way the memory footprint is a lot smaller than the |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1956 initial implementation which stored everything in a big hash by |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1957 id and then proceeded to import journals for each id.""" |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1958 properties = self.getprops() |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1959 a = [] |
| 6967 | 1960 for entry in entries: |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1961 # first element in sorted list is the (numeric) id |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1962 # in python2.4 and up we would use sorted with a key... |
| 6967 | 1963 a.append((int(entry[0].strip("'")), entry)) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
1964 a.sort() |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1965 |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1966 last = 0 |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1967 r = [] |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1968 for n, l in a: |
|
5525
bb7865241f8a
Make CSV import/export compatible across Python versions (also RDBMS journals) (issue 2550976, issue 2550975).
Joseph Myers <jsm@polyomino.org.uk>
parents:
5481
diff
changeset
|
1969 nodeid, jdate, user, action, params = map(eval_import, l) |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1970 assert (str(n) == nodeid) |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1971 if n != last: |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1972 if r: |
|
4431
9b619dcb030a
- fix import (now passes for memorydb, too)
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4430
diff
changeset
|
1973 self.db.setjournal(self.classname, str(last), r) |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1974 last = n |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1975 r = [] |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1976 |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1977 if action == 'set': |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
1978 for propname, value in params.items(): |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1979 prop = properties[propname] |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1980 if value is None: |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1981 pass |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1982 elif isinstance(prop, Date): |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1983 value = date.Date(value) |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1984 elif isinstance(prop, Interval): |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1985 value = date.Interval(value) |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1986 elif isinstance(prop, Password): |
|
4483
22bc0426e348
Second patch from issue2550688 -- with some changes:
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4481
diff
changeset
|
1987 value = password.JournalPassword(encrypted=value) |
|
4430
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1988 params[propname] = value |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1989 elif action == 'create' and params: |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1990 # old tracker with data stored in the create! |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1991 params = {} |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1992 r.append((nodeid, date.Date(jdate), user, action, params)) |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1993 if r: |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1994 self.db.setjournal(self.classname, nodeid, r) |
|
f2f2904fe6ce
- refactor: move import_journal to hyperdb
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4408
diff
changeset
|
1995 |
|
4306
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1996 # |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1997 # convenience methods |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1998 # |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
1999 def get_roles(self, nodeid): |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2000 """Return iterator for all roles for this nodeid. |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2001 |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2002 Yields string-processed roles. |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2003 This method can be overridden to provide a hook where we can |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2004 insert other permission models (e.g. get roles from database) |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2005 In standard schemas only a user has a roles property but |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2006 this may be different in customized schemas. |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2007 Note that this is the *central place* where role |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2008 processing happens! |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2009 """ |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2010 node = self.db.getnode(self.classname, nodeid) |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2011 return iter_roles(node['roles']) |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2012 |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2013 def has_role(self, nodeid, *roles): |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2014 '''See if this node has any roles that appear in roles. |
|
4480
1613754d2646
Fix first part of Password handling security issue2550688
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4472
diff
changeset
|
2015 |
|
4306
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2016 For convenience reasons we take a list. |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2017 In standard schemas only a user has a roles property but |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2018 this may be different in customized schemas. |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2019 ''' |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2020 roles = dict.fromkeys([r.strip().lower() for r in roles]) |
|
4306
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2021 for role in self.get_roles(nodeid): |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2022 if role in roles: |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2023 return True |
|
966592263fb8
Clean up all the places where role processing occurs.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4089
diff
changeset
|
2024 return False |
| 2496 | 2025 |
| 2026 | |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2027 class HyperdbValueError(ValueError): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2028 """ Error converting a raw value into a Hyperdb value """ |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2029 pass |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2030 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2031 |
| 6967 | 2032 id_regex = re.compile(r'^\d+$') |
| 2033 | |
| 2034 | |
| 2035 def convertLinkValue(db, propname, prop, value, idre=id_regex): | |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2036 """ Convert the link value (may be id or key value) to an id value. """ |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2037 linkcl = db.classes[prop.classname] |
|
4877
2ba982dcdf2c
New Link / Multilink option "try_id_parsing"
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4850
diff
changeset
|
2038 if not idre or not idre.match(value): |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2039 if linkcl.getkey(): |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2040 try: |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2041 value = linkcl.lookup(value) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2042 except KeyError: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2043 raise HyperdbValueError(_( |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2044 'property %(property)s: %(value)r ' |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2045 'is not a %(classname)s.') % { |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2046 'property': propname, |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2047 'value': value, |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2048 'classname': prop.classname}) |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2049 else: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2050 raise HyperdbValueError(_('you may only enter ID values ' |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2051 'for property %s') % propname) |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2052 return value |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2053 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2054 |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2055 def fixNewlines(text): |
|
1928
7c1ddebe7589
Small readability improvements.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1927
diff
changeset
|
2056 """ Homogenise line endings. |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2057 |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2058 Different web clients send different line ending values, but |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2059 other systems (eg. email) don't necessarily handle those line |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2060 endings. Our solution is to convert all line endings to LF. |
|
1928
7c1ddebe7589
Small readability improvements.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
1927
diff
changeset
|
2061 """ |
|
5309
20084e2b48c3
Fix bug where unsetting a text value triggered an exception because
John Rouillard <rouilj@ieee.org>
parents:
5261
diff
changeset
|
2062 if text is not None: |
|
20084e2b48c3
Fix bug where unsetting a text value triggered an exception because
John Rouillard <rouilj@ieee.org>
parents:
5261
diff
changeset
|
2063 text = text.replace('\r\n', '\n') |
|
20084e2b48c3
Fix bug where unsetting a text value triggered an exception because
John Rouillard <rouilj@ieee.org>
parents:
5261
diff
changeset
|
2064 return text.replace('\r', '\n') |
|
20084e2b48c3
Fix bug where unsetting a text value triggered an exception because
John Rouillard <rouilj@ieee.org>
parents:
5261
diff
changeset
|
2065 return text |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2066 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2067 |
|
3383
c1c67c62b699
applied patch [SF#236087]
Richard Jones <richard@users.sourceforge.net>
parents:
3019
diff
changeset
|
2068 def rawToHyperdb(db, klass, itemid, propname, value, **kw): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2069 """ Convert the raw (user-input) value to a hyperdb-storable value. The |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2070 value is for the "propname" property on itemid (may be None for a |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2071 new item) of "klass" in "db". |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2072 |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2073 The value is usually a string, but in the case of multilink inputs |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2074 it may be either a list of strings or a string with comma-separated |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2075 values. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2076 """ |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2077 properties = klass.getprops() |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2078 |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2079 # ensure it's a valid property name |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2080 propname = propname.strip() |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2081 try: |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2082 proptype = properties[propname] |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2083 except KeyError: |
|
7056
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2084 raise HyperdbValueError(_( |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2085 '%(property)r is not a property of %(classname)s') % { |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2086 'property': propname, |
|
9b4bd9bc9bdc
Fix internationalized strings with multiple unlabeled % replacements.
John Rouillard <rouilj@ieee.org>
parents:
6967
diff
changeset
|
2087 'classname': klass.classname}) |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2088 |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2089 # if we got a string, strip it now |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2090 if isinstance(value, type('')): |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2091 value = value.strip() |
|
3668
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
2092 |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2093 # convert the input value to a real property value |
|
3668
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
2094 value = proptype.from_raw(value, db=db, klass=klass, |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2095 propname=propname, itemid=itemid, **kw) |
|
3668
a15c15510e99
hyperdb handling of empty raw values for Multilink and Password [SF#1507814]
Richard Jones <richard@users.sourceforge.net>
parents:
3635
diff
changeset
|
2096 |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2097 return value |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1864
diff
changeset
|
2098 |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2099 |
|
1442
b42fa71754c9
don't attempt to create FileClass items if no content is supplied
Richard Jones <richard@users.sourceforge.net>
parents:
1249
diff
changeset
|
2100 class FileClass: |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2101 """ A class that requires the "content" property and stores it on |
|
1442
b42fa71754c9
don't attempt to create FileClass items if no content is supplied
Richard Jones <richard@users.sourceforge.net>
parents:
1249
diff
changeset
|
2102 disk. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2103 """ |
|
3601
7b25567f0f54
indexing may be turned off for FileClass "content" now
Richard Jones <richard@users.sourceforge.net>
parents:
3586
diff
changeset
|
2104 default_mime_type = 'text/plain' |
|
7b25567f0f54
indexing may be turned off for FileClass "content" now
Richard Jones <richard@users.sourceforge.net>
parents:
3586
diff
changeset
|
2105 |
|
7b25567f0f54
indexing may be turned off for FileClass "content" now
Richard Jones <richard@users.sourceforge.net>
parents:
3586
diff
changeset
|
2106 def __init__(self, db, classname, **properties): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2107 """The newly-created class automatically includes the "content" |
|
3601
7b25567f0f54
indexing may be turned off for FileClass "content" now
Richard Jones <richard@users.sourceforge.net>
parents:
3586
diff
changeset
|
2108 property. |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2109 """ |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
2110 if 'content' not in properties: |
|
3924
21d3d7eeea8c
assorted pyflakes fixes
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3802
diff
changeset
|
2111 properties['content'] = String(indexme='yes') |
|
3601
7b25567f0f54
indexing may be turned off for FileClass "content" now
Richard Jones <richard@users.sourceforge.net>
parents:
3586
diff
changeset
|
2112 |
| 2496 | 2113 def export_propnames(self): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2114 """ Don't export the "content" property |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2115 """ |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
2116 propnames = list(self.getprops().keys()) |
| 2496 | 2117 propnames.remove('content') |
| 2118 propnames.sort() | |
| 2119 return propnames | |
| 2120 | |
|
3019
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2121 def exportFilename(self, dirname, nodeid): |
|
5101
d043a09952db
Tried to explain the use of hyperdb's exportFilename
John Rouillard <rouilj@ieee.org>
parents:
5084
diff
changeset
|
2122 """ Returns destination filename for a exported file |
|
d043a09952db
Tried to explain the use of hyperdb's exportFilename
John Rouillard <rouilj@ieee.org>
parents:
5084
diff
changeset
|
2123 |
|
d043a09952db
Tried to explain the use of hyperdb's exportFilename
John Rouillard <rouilj@ieee.org>
parents:
5084
diff
changeset
|
2124 Called by export function in roundup admin to generate |
|
d043a09952db
Tried to explain the use of hyperdb's exportFilename
John Rouillard <rouilj@ieee.org>
parents:
5084
diff
changeset
|
2125 the <class>-files subdirectory |
|
d043a09952db
Tried to explain the use of hyperdb's exportFilename
John Rouillard <rouilj@ieee.org>
parents:
5084
diff
changeset
|
2126 """ |
|
3019
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2127 subdir_filename = self.db.subdirFilename(self.classname, nodeid) |
|
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2128 return os.path.join(dirname, self.classname+'-files', subdir_filename) |
|
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2129 |
| 2496 | 2130 def export_files(self, dirname, nodeid): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2131 """ Export the "content" property as a file, not csv column |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2132 """ |
| 2496 | 2133 source = self.db.filename(self.classname, nodeid) |
|
3019
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2134 |
|
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2135 dest = self.exportFilename(dirname, nodeid) |
|
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2136 ensureParentsExist(dest) |
|
3488
e4177cf4d30d
common initialization code and detectors interface...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
3476
diff
changeset
|
2137 shutil.copyfile(source, dest) |
| 2496 | 2138 |
| 2139 def import_files(self, dirname, nodeid): | |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2140 """ Import the "content" property as a file |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2141 """ |
|
3019
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2142 source = self.exportFilename(dirname, nodeid) |
|
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2143 |
|
2962
4607f58a007b
py2.1 compatibility
Richard Jones <richard@users.sourceforge.net>
parents:
2909
diff
changeset
|
2144 dest = self.db.filename(self.classname, nodeid, create=1) |
|
3019
293a17149765
First cut at exporting/importing file content from and to the hyperdb.
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
2962
diff
changeset
|
2145 ensureParentsExist(dest) |
| 2496 | 2146 shutil.copyfile(source, dest) |
|
1442
b42fa71754c9
don't attempt to create FileClass items if no content is supplied
Richard Jones <richard@users.sourceforge.net>
parents:
1249
diff
changeset
|
2147 |
|
3544
5cd1c83dea50
Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3491
diff
changeset
|
2148 mime_type = None |
|
3802
c3af8c6a6b5b
Bug-fix: Only index the content property if it has the indexme attribute set
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3743
diff
changeset
|
2149 props = self.getprops() |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
2150 if 'type' in props: |
|
3545
507b2df02956
fixes to import_files
Richard Jones <richard@users.sourceforge.net>
parents:
3544
diff
changeset
|
2151 mime_type = self.get(nodeid, 'type') |
|
3544
5cd1c83dea50
Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3491
diff
changeset
|
2152 if not mime_type: |
|
5cd1c83dea50
Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3491
diff
changeset
|
2153 mime_type = self.default_mime_type |
|
3802
c3af8c6a6b5b
Bug-fix: Only index the content property if it has the indexme attribute set
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3743
diff
changeset
|
2154 if props['content'].indexme: |
|
5648
a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
2155 index_content = self.get(nodeid, 'binary_content') |
|
a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
2156 if bytes != str and isinstance(index_content, bytes): |
|
a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
2157 index_content = index_content.decode('utf-8', errors='ignore') |
|
a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
2158 # indexer will only index text mime type. It will skip |
|
a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
2159 # other types. So if mime type of file is correct, we |
|
a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
John Rouillard <rouilj@ieee.org>
parents:
5548
diff
changeset
|
2160 # call add_text on content. |
|
3802
c3af8c6a6b5b
Bug-fix: Only index the content property if it has the indexme attribute set
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3743
diff
changeset
|
2161 self.db.indexer.add_text((self.classname, nodeid, 'content'), |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2162 index_content, mime_type) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2163 |
|
3544
5cd1c83dea50
Features and fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
3491
diff
changeset
|
2164 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2165 class Node: |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2166 """ A convenience wrapper for the given node |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2167 """ |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
466
diff
changeset
|
2168 def __init__(self, cl, nodeid, cache=1): |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2169 self.__dict__['cl'] = cl |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2170 self.__dict__['nodeid'] = nodeid |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2171 |
|
278
a5dabf2430c5
Added database importing and exporting through CSV files.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
2172 def keys(self, protected=1): |
|
5395
23b8e6067f7c
Python 3 preparation: update calls to dict methods.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5388
diff
changeset
|
2173 return list(self.cl.getprops(protected=protected).keys()) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2174 |
|
278
a5dabf2430c5
Added database importing and exporting through CSV files.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
2175 def values(self, protected=1): |
| 6967 | 2176 value_list = [] |
|
278
a5dabf2430c5
Added database importing and exporting through CSV files.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
2177 for name in self.cl.getprops(protected=protected).keys(): |
| 6967 | 2178 value_list.append(self.cl.get(self.nodeid, name)) |
| 2179 return value_list | |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2180 |
|
278
a5dabf2430c5
Added database importing and exporting through CSV files.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
2181 def items(self, protected=1): |
| 6967 | 2182 item_list = [] |
|
278
a5dabf2430c5
Added database importing and exporting through CSV files.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
2183 for name in self.cl.getprops(protected=protected).keys(): |
| 6967 | 2184 item_list.append((name, self.cl.get(self.nodeid, name))) |
| 2185 return item_list | |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2186 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2187 def has_key(self, name): |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
2188 return name in self.cl.getprops() |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2189 |
|
2909
2fc6c508b537
Database instances must have method close()
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2906
diff
changeset
|
2190 def get(self, name, default=None): |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
2191 if name in self: |
|
1470
9ccd69fbe33e
applied patch [SF#688595]
Richard Jones <richard@users.sourceforge.net>
parents:
1442
diff
changeset
|
2192 return self[name] |
|
9ccd69fbe33e
applied patch [SF#688595]
Richard Jones <richard@users.sourceforge.net>
parents:
1442
diff
changeset
|
2193 else: |
|
9ccd69fbe33e
applied patch [SF#688595]
Richard Jones <richard@users.sourceforge.net>
parents:
1442
diff
changeset
|
2194 return default |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2195 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2196 def __getattr__(self, name): |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5378
diff
changeset
|
2197 if name in self.__dict__: |
|
278
a5dabf2430c5
Added database importing and exporting through CSV files.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
2198 return self.__dict__[name] |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2199 try: |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
2200 return self.cl.get(self.nodeid, name) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
2201 except KeyError as value: |
|
460
9c895b44240a
take a copy of the node dict...
Richard Jones <richard@users.sourceforge.net>
parents:
457
diff
changeset
|
2202 # we trap this but re-raise it as AttributeError - all other |
|
9c895b44240a
take a copy of the node dict...
Richard Jones <richard@users.sourceforge.net>
parents:
457
diff
changeset
|
2203 # exceptions should pass through untrapped |
|
5697
5a9159ad773f
Properly handle mapping of KeyError to AttributeError in __getattr__
John Rouillard <rouilj@ieee.org>
parents:
5648
diff
changeset
|
2204 raise AttributeError(str(value)) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2205 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2206 def __getitem__(self, name): |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
2207 return self.cl.get(self.nodeid, name) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2208 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2209 def __setattr__(self, name, value): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2210 try: |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2211 return self.cl.set(self.nodeid, **{name: value}) |
|
5248
198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Eric S. Raymond <esr@thyrsus.com>
parents:
5232
diff
changeset
|
2212 except KeyError as value: |
|
5697
5a9159ad773f
Properly handle mapping of KeyError to AttributeError in __getattr__
John Rouillard <rouilj@ieee.org>
parents:
5648
diff
changeset
|
2213 # we trap this but re-raise it as AttributeError - all other |
|
5a9159ad773f
Properly handle mapping of KeyError to AttributeError in __getattr__
John Rouillard <rouilj@ieee.org>
parents:
5648
diff
changeset
|
2214 # exceptions should pass through untrapped |
|
5378
35ea9b1efc14
Python 3 preparation: "raise" syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5327
diff
changeset
|
2215 raise AttributeError(str(value)) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2216 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2217 def __setitem__(self, name, value): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2218 self.cl.set(self.nodeid, **{name: value}) |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2219 |
|
5232
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
2220 def history(self, enforceperm=True, skipquiet=True): |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
2221 return self.cl.history(self.nodeid, |
|
462b0f76fce8
issue2550864 - Potential information leakage via journal/history
John Rouillard <rouilj@ieee.org>
parents:
5175
diff
changeset
|
2222 enforceperm=enforceperm, |
|
6006
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2223 skipquiet=skipquiet) |
|
cf800f1febe6
Flake8 fixes; use isinstance rather than type equality.
John Rouillard <rouilj@ieee.org>
parents:
5871
diff
changeset
|
2224 |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2225 def retire(self): |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2226 return self.cl.retire(self.nodeid) |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2227 |
|
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2228 |
|
648
07422fe57db2
Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents:
628
diff
changeset
|
2229 def Choice(name, db, *options): |
|
4063
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2230 """Quick helper to create a simple class with choices |
|
625915ce35b8
Uniformly use """...""" instead of '''...''' for comments.
Stefan Seefeld <stefan@seefeld.name>
parents:
4048
diff
changeset
|
2231 """ |
|
648
07422fe57db2
Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents:
628
diff
changeset
|
2232 cl = Class(db, name, name=String(), order=String()) |
|
25
4cf1daf2f2eb
More Grande Splite
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2233 for i in range(len(options)): |
|
648
07422fe57db2
Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents:
628
diff
changeset
|
2234 cl.create(name=options[i], order=i) |
|
3924
21d3d7eeea8c
assorted pyflakes fixes
Justus Pendleton <jpend@users.sourceforge.net>
parents:
3802
diff
changeset
|
2235 return Link(name) |
