zc.catalog 4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zc/catalog/__init__.py +14 -0
- zc/catalog/browser/README.rst +88 -0
- zc/catalog/browser/__init__.py +1 -0
- zc/catalog/browser/configure.zcml +69 -0
- zc/catalog/browser/ftesting.zcml +161 -0
- zc/catalog/browser/tests.py +65 -0
- zc/catalog/callablewrapper.rst +47 -0
- zc/catalog/catalogindex.py +77 -0
- zc/catalog/configure.zcml +72 -0
- zc/catalog/extentcatalog.py +233 -0
- zc/catalog/extentcatalog.rst +566 -0
- zc/catalog/globber.py +44 -0
- zc/catalog/globber.rst +16 -0
- zc/catalog/i18n.py +32 -0
- zc/catalog/index.py +590 -0
- zc/catalog/interfaces.py +328 -0
- zc/catalog/legacy.rst +188 -0
- zc/catalog/normalizedindex.rst +356 -0
- zc/catalog/setindex.rst +261 -0
- zc/catalog/stemmer.py +84 -0
- zc/catalog/stemmer.rst +54 -0
- zc/catalog/tests.py +242 -0
- zc/catalog/valueindex.rst +264 -0
- zc.catalog-4.0-py3.11-nspkg.pth +1 -0
- zc.catalog-4.0.dist-info/LICENSE.txt +44 -0
- zc.catalog-4.0.dist-info/METADATA +2185 -0
- zc.catalog-4.0.dist-info/RECORD +30 -0
- zc.catalog-4.0.dist-info/WHEEL +5 -0
- zc.catalog-4.0.dist-info/namespace_packages.txt +1 -0
- zc.catalog-4.0.dist-info/top_level.txt +1 -0
zc/catalog/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2007 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
"""zc.catalog package"""
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
============================
|
|
2
|
+
zc.catalog Browser Support
|
|
3
|
+
============================
|
|
4
|
+
|
|
5
|
+
The zc.catalog.browser package adds simple TTW addition/inspection for SetIndex
|
|
6
|
+
and ValueIndex.
|
|
7
|
+
|
|
8
|
+
First, we need a browser so we can test the web UI.
|
|
9
|
+
|
|
10
|
+
>>> from zope.testbrowser.wsgi import Browser
|
|
11
|
+
>>> browser = Browser()
|
|
12
|
+
>>> browser.handleErrors = False
|
|
13
|
+
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
|
|
14
|
+
>>> browser.addHeader('Accept-Language', 'en-US')
|
|
15
|
+
>>> browser.open('http://localhost/')
|
|
16
|
+
|
|
17
|
+
Now we need to add the catalog that these indexes are going to reside within.
|
|
18
|
+
|
|
19
|
+
>>> browser.open('http://localhost/++etc++site/default/@@+/')
|
|
20
|
+
>>> browser.getControl('Catalog').click()
|
|
21
|
+
>>> browser.getControl(name='id').value = 'catalog'
|
|
22
|
+
>>> browser.getControl('Add').click()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
SetIndex
|
|
26
|
+
========
|
|
27
|
+
|
|
28
|
+
Add the SetIndex to the catalog.
|
|
29
|
+
|
|
30
|
+
>>> browser.open(browser.getLink('Add').url + '/')
|
|
31
|
+
>>> browser.getControl('Set Index').click()
|
|
32
|
+
>>> browser.getControl(name='id').value = 'set_index'
|
|
33
|
+
>>> browser.getControl('Add').click()
|
|
34
|
+
|
|
35
|
+
The add form needs values for what interface to adapt candidate objects to, and
|
|
36
|
+
what field name to use, and whether-or-not that field is a callable. (We'll use
|
|
37
|
+
a simple interfaces for demonstration purposes, it's not really significant.)
|
|
38
|
+
|
|
39
|
+
>>> browser.getControl('Interface', index=0).displayValue = [
|
|
40
|
+
... 'zope.size.interfaces.ISized']
|
|
41
|
+
>>> browser.getControl('Field Name').value = 'sizeForDisplay'
|
|
42
|
+
>>> browser.getControl('Field Callable').click()
|
|
43
|
+
>>> browser.getControl(name='add_input_name').value = 'set_index'
|
|
44
|
+
>>> browser.getControl('Add').click()
|
|
45
|
+
|
|
46
|
+
Now we can look at the index and see how is is configured.
|
|
47
|
+
|
|
48
|
+
>>> browser.getLink('set_index').click()
|
|
49
|
+
>>> print(browser.contents)
|
|
50
|
+
<...
|
|
51
|
+
...Interface...zope.size.interfaces.ISized...
|
|
52
|
+
...Field Name...sizeForDisplay...
|
|
53
|
+
...Field Callable...True...
|
|
54
|
+
|
|
55
|
+
We need to go back to the catalog so we can add a different index.
|
|
56
|
+
|
|
57
|
+
>>> browser.open('/++etc++site/default/catalog/@@contents.html')
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
ValueIndex
|
|
61
|
+
==========
|
|
62
|
+
|
|
63
|
+
Add the ValueIndex to the catalog.
|
|
64
|
+
|
|
65
|
+
>>> browser.open(browser.getLink('Add').url + '/')
|
|
66
|
+
>>> browser.getControl('Value Index').click()
|
|
67
|
+
>>> browser.getControl(name='id').value = 'value_index'
|
|
68
|
+
>>> browser.getControl('Add').click()
|
|
69
|
+
|
|
70
|
+
The add form needs values for what interface to adapt candidate objects to, and
|
|
71
|
+
what field name to use, and whether-or-not that field is a callable. (We'll use
|
|
72
|
+
a simple interfaces for demonstration purposes, it's not really significant.)
|
|
73
|
+
|
|
74
|
+
>>> browser.getControl('Interface', index=0).displayValue = [
|
|
75
|
+
... 'zope.size.interfaces.ISized']
|
|
76
|
+
>>> browser.getControl('Field Name').value = 'sizeForDisplay'
|
|
77
|
+
>>> browser.getControl('Field Callable').click()
|
|
78
|
+
>>> browser.getControl(name='add_input_name').value = 'value_index'
|
|
79
|
+
>>> browser.getControl('Add').click()
|
|
80
|
+
|
|
81
|
+
Now we can look at the index and see how is is configured.
|
|
82
|
+
|
|
83
|
+
>>> browser.getLink('value_index').click()
|
|
84
|
+
>>> print(browser.contents)
|
|
85
|
+
<...
|
|
86
|
+
...Interface...zope.size.interfaces.ISized...
|
|
87
|
+
...Field Name...sizeForDisplay...
|
|
88
|
+
...Field Callable...True...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<zope:configure
|
|
2
|
+
xmlns:zope="http://namespaces.zope.org/zope"
|
|
3
|
+
xmlns="http://namespaces.zope.org/browser"
|
|
4
|
+
i18n_domain="zope"
|
|
5
|
+
>
|
|
6
|
+
|
|
7
|
+
<!-- UI for SetIndex -->
|
|
8
|
+
<include package="zope.app.form.browser" file="meta.zcml" />
|
|
9
|
+
<include package="zope.app.form.browser"/>
|
|
10
|
+
<include package="zope.browsermenu" file="meta.zcml" />
|
|
11
|
+
<include package="zope.browsermenu"/>
|
|
12
|
+
|
|
13
|
+
<addform
|
|
14
|
+
name="AddSetIndex"
|
|
15
|
+
label="Add a set index"
|
|
16
|
+
schema="zope.catalog.interfaces.IAttributeIndex"
|
|
17
|
+
permission="zope.ManageServices"
|
|
18
|
+
content_factory="..catalogindex.SetIndex"
|
|
19
|
+
arguments="field_name"
|
|
20
|
+
keyword_arguments="interface field_callable"
|
|
21
|
+
/>
|
|
22
|
+
|
|
23
|
+
<addMenuItem
|
|
24
|
+
title="Set Index"
|
|
25
|
+
description="Index items based on a set of values"
|
|
26
|
+
class="..catalogindex.SetIndex"
|
|
27
|
+
permission="zope.ManageServices"
|
|
28
|
+
view="AddSetIndex"
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
<schemadisplay
|
|
32
|
+
name="index.html"
|
|
33
|
+
schema="..interfaces.ICatalogSetIndex"
|
|
34
|
+
label="Set Index"
|
|
35
|
+
fields="interface field_name field_callable"
|
|
36
|
+
permission="zope.ManageServices"
|
|
37
|
+
menu="zmi_views" title="Configuration"
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<!-- UI for ValueIndex -->
|
|
41
|
+
|
|
42
|
+
<addform
|
|
43
|
+
name="AddValueIndex"
|
|
44
|
+
label="Add a value index"
|
|
45
|
+
schema="zope.catalog.interfaces.IAttributeIndex"
|
|
46
|
+
permission="zope.ManageServices"
|
|
47
|
+
content_factory="..catalogindex.ValueIndex"
|
|
48
|
+
arguments="field_name"
|
|
49
|
+
keyword_arguments="interface field_callable"
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<addMenuItem
|
|
53
|
+
title="Value Index"
|
|
54
|
+
description="Index items based on a value"
|
|
55
|
+
class="..catalogindex.ValueIndex"
|
|
56
|
+
permission="zope.ManageServices"
|
|
57
|
+
view="AddValueIndex"
|
|
58
|
+
/>
|
|
59
|
+
|
|
60
|
+
<schemadisplay
|
|
61
|
+
name="index.html"
|
|
62
|
+
schema="..interfaces.ICatalogValueIndex"
|
|
63
|
+
label="Value Index"
|
|
64
|
+
fields="interface field_name field_callable"
|
|
65
|
+
permission="zope.ManageServices"
|
|
66
|
+
menu="zmi_views" title="Configuration"
|
|
67
|
+
/>
|
|
68
|
+
|
|
69
|
+
</zope:configure>
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<configure
|
|
2
|
+
xmlns="http://namespaces.zope.org/zope"
|
|
3
|
+
xmlns:browser="http://namespaces.zope.org/browser"
|
|
4
|
+
i18n_domain="zope">
|
|
5
|
+
|
|
6
|
+
<include package="zope.component" file="meta.zcml" />
|
|
7
|
+
<!-- view directive -->
|
|
8
|
+
<include package="zope.browserpage" file="meta.zcml" />
|
|
9
|
+
<!-- resource directive -->
|
|
10
|
+
<include package="zope.browserresource" file="meta.zcml" />
|
|
11
|
+
<!-- publisher directivie -->
|
|
12
|
+
<include package="zope.app.publication" file="meta.zcml" />
|
|
13
|
+
<!-- grant directives -->
|
|
14
|
+
<include package="zope.securitypolicy" file="meta.zcml" />
|
|
15
|
+
<!-- principal directives -->
|
|
16
|
+
<include package="zope.security" file="meta.zcml" />
|
|
17
|
+
<include package="zope.principalregistry" file="meta.zcml" />
|
|
18
|
+
|
|
19
|
+
<!-- defaultView directive -->
|
|
20
|
+
<include package="zope.publisher" file="meta.zcml" />
|
|
21
|
+
|
|
22
|
+
<!-- menu/addMenuItem directive -->
|
|
23
|
+
<include package="zope.browsermenu" file="meta.zcml" />
|
|
24
|
+
|
|
25
|
+
<!-- containerViews directive -->
|
|
26
|
+
<include package="zope.app.container.browser" file="meta.zcml" />
|
|
27
|
+
|
|
28
|
+
<!-- addform directive -->
|
|
29
|
+
<include package="zope.app.form.browser" file="meta.zcml" />
|
|
30
|
+
|
|
31
|
+
<utility factory="zope.app.schema.vocabulary.ZopeVocabularyRegistry" />
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<include package="zope.annotation" />
|
|
35
|
+
<include package="zope.browsermenu" />
|
|
36
|
+
<include package="zope.container" />
|
|
37
|
+
<include package="zope.component" />
|
|
38
|
+
<!-- IPrincipalClipboard adapter -->
|
|
39
|
+
<include package="zope.copypastemove" />
|
|
40
|
+
<include package="zope.location" />
|
|
41
|
+
<include package="zope.login" />
|
|
42
|
+
<include package="zope.password" />
|
|
43
|
+
<include package="zope.principalregistry" />
|
|
44
|
+
<include package="zope.principalannotation" />
|
|
45
|
+
<include package="zope.publisher" />
|
|
46
|
+
<include package="zope.security" />
|
|
47
|
+
<include package="zope.securitypolicy" />
|
|
48
|
+
<include package="zope.site" />
|
|
49
|
+
<include package="zope.traversing" />
|
|
50
|
+
<include package="zope.traversing.browser" />
|
|
51
|
+
<include package="zope.keyreference" />
|
|
52
|
+
<include package="zope.intid" />
|
|
53
|
+
|
|
54
|
+
<!-- These normally come from zope.app.zcmlfiles/menus.zcml -->
|
|
55
|
+
<browser:menu
|
|
56
|
+
id="zmi_views"
|
|
57
|
+
title="Views"
|
|
58
|
+
description="Menu for displaying alternate representations of an object"
|
|
59
|
+
/>
|
|
60
|
+
<browser:menu
|
|
61
|
+
id="zmi_actions"
|
|
62
|
+
title="Actions"
|
|
63
|
+
description="Menu for displaying actions to be performed"
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
<browser:menu
|
|
67
|
+
id="add_component"
|
|
68
|
+
title="Add"
|
|
69
|
+
description="Menu of objects to be added to site management folders"
|
|
70
|
+
/>
|
|
71
|
+
<browser:menu
|
|
72
|
+
id="zope.app.container.add"
|
|
73
|
+
title="Add"
|
|
74
|
+
description="Menu for objects to be added according to
|
|
75
|
+
containment constraints"
|
|
76
|
+
interface="zope.browsermenu.interfaces.AddMenu"
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
<!-- Register the Application folder -->
|
|
80
|
+
<include package="zope.app.appsetup" />
|
|
81
|
+
|
|
82
|
+
<!-- @@standard_macros -->
|
|
83
|
+
<include package="zope.app.basicskin" />
|
|
84
|
+
|
|
85
|
+
<!-- Normally done in zope.app.principalannotation's bootstrap
|
|
86
|
+
subscriber -->
|
|
87
|
+
<utility
|
|
88
|
+
factory="zope.principalannotation.utility.PrincipalAnnotationUtility"
|
|
89
|
+
provides="zope.principalannotation.interfaces.IPrincipalAnnotationUtility"
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
<!-- security access for __call__ on PageTemplate -->
|
|
93
|
+
<include package="zope.app.pagetemplate" />
|
|
94
|
+
|
|
95
|
+
<include package="zope.app.container" />
|
|
96
|
+
<include package="zope.app.component" />
|
|
97
|
+
<include package="zope.app.container.browser" />
|
|
98
|
+
<include package="zope.app.component.browser" />
|
|
99
|
+
<include package="zope.app.catalog" />
|
|
100
|
+
<include package="zope.app.rotterdam" />
|
|
101
|
+
<include package="zope.app.catalog.browser" />
|
|
102
|
+
<include package="zope.app.publication" />
|
|
103
|
+
<include package="zope.app.form.browser" />
|
|
104
|
+
<!-- @@SelectedManagementView.html -->
|
|
105
|
+
<include package="zope.app.publisher.browser" />
|
|
106
|
+
|
|
107
|
+
<include package="zc.catalog" />
|
|
108
|
+
<include package="zc.catalog.browser" />
|
|
109
|
+
<subscriber handler="zc.catalog.browser.tests.initializeIntIds" />
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
<browser:defaultView name="index.html" />
|
|
113
|
+
<!-- render the menus -->
|
|
114
|
+
<browser:defaultSkin name="Rotterdam" />
|
|
115
|
+
|
|
116
|
+
<!-- login_logout view -->
|
|
117
|
+
<!-- Normally comes from zope.app.security -->
|
|
118
|
+
<browser:page
|
|
119
|
+
name="login_logout"
|
|
120
|
+
for="*"
|
|
121
|
+
class=".tests.LoginLogout"
|
|
122
|
+
permission="zope.Public"
|
|
123
|
+
/>
|
|
124
|
+
<browser:pages
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
for="zope.site.interfaces.IFolder"
|
|
128
|
+
permission="zope.ManageSite"
|
|
129
|
+
class="zope.app.container.browser.adding.Adding"
|
|
130
|
+
>
|
|
131
|
+
<browser:page name="index.html" attribute="index"/>
|
|
132
|
+
<browser:page name="action.html" attribute="action"/>
|
|
133
|
+
</browser:pages>
|
|
134
|
+
<!-- Security setup -->
|
|
135
|
+
<securityPolicy
|
|
136
|
+
component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
|
|
137
|
+
|
|
138
|
+
<role
|
|
139
|
+
id="zope.Anonymous"
|
|
140
|
+
title="Everybody"
|
|
141
|
+
description="All users have this role implicitly"
|
|
142
|
+
/>
|
|
143
|
+
<role id="zope.Manager" title="Site Manager" />
|
|
144
|
+
<role id="zope.Member" title="Site Member" />
|
|
145
|
+
|
|
146
|
+
<!-- Replace the following directive if you don't want public access -->
|
|
147
|
+
<grant
|
|
148
|
+
permission="zope.View"
|
|
149
|
+
role="zope.Member"
|
|
150
|
+
/>
|
|
151
|
+
|
|
152
|
+
<grantAll role="zope.Manager" />
|
|
153
|
+
|
|
154
|
+
<unauthenticatedPrincipal id="zope.anybody" title="Unauthenticated User" />
|
|
155
|
+
|
|
156
|
+
<principal id="zope.mgr" title="Manager" login="mgr" password="mgrpw" />
|
|
157
|
+
|
|
158
|
+
<grant role="zope.Manager" principal="zope.mgr" />
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
</configure>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2004 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
"""Functional tests for `zc.catalog.browser`.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
import doctest
|
|
18
|
+
|
|
19
|
+
import transaction
|
|
20
|
+
import zope.app.appsetup.bootstrap
|
|
21
|
+
import zope.intid
|
|
22
|
+
import zope.intid.interfaces
|
|
23
|
+
from zope.app.wsgi.testlayer import BrowserLayer
|
|
24
|
+
from zope.processlifetime import IDatabaseOpenedWithRoot
|
|
25
|
+
from zope.testbrowser.wsgi import TestBrowserLayer
|
|
26
|
+
|
|
27
|
+
import zc.catalog.browser
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class _ZcCatalogLayer(TestBrowserLayer,
|
|
31
|
+
BrowserLayer):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
ZcCatalogLayer = _ZcCatalogLayer(zc.catalog.browser)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@zope.component.adapter(IDatabaseOpenedWithRoot)
|
|
39
|
+
def initializeIntIds(event):
|
|
40
|
+
_db, connection, _root, root_folder = (
|
|
41
|
+
zope.app.appsetup.bootstrap.getInformationFromEvent(event))
|
|
42
|
+
sm = root_folder.getSiteManager()
|
|
43
|
+
if 'test-int-ids' not in sm['default']:
|
|
44
|
+
intids = zope.intid.IntIds()
|
|
45
|
+
|
|
46
|
+
sm["default"]["test-int-ids"] = intids
|
|
47
|
+
sm.registerUtility(
|
|
48
|
+
intids,
|
|
49
|
+
zope.intid.interfaces.IIntIds)
|
|
50
|
+
transaction.commit()
|
|
51
|
+
connection.close()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_suite():
|
|
55
|
+
suite = doctest.DocFileSuite(
|
|
56
|
+
"README.rst",
|
|
57
|
+
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
|
|
58
|
+
suite.layer = ZcCatalogLayer
|
|
59
|
+
return suite
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class LoginLogout:
|
|
63
|
+
# dummy to avoid dep on zope.app.security
|
|
64
|
+
def __call__(self):
|
|
65
|
+
return
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
================
|
|
2
|
+
Callable Wrapper
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
If we want to index some value that is easily derivable from a
|
|
6
|
+
document, we have to define an interface with this value as an
|
|
7
|
+
attribute, and create an adapter that calculates this value and
|
|
8
|
+
implements this interface. All this is too much hassle if the want to
|
|
9
|
+
store a single easily derivable value. CallableWrapper solves this
|
|
10
|
+
problem, by converting the document to the indexed value with a
|
|
11
|
+
callable converter.
|
|
12
|
+
|
|
13
|
+
Here's a contrived example. Suppose we have cars that know their
|
|
14
|
+
mileage expressed in miles per gallon, but we want to index their
|
|
15
|
+
economy in litres per 100 km.
|
|
16
|
+
|
|
17
|
+
>>> class Car(object):
|
|
18
|
+
... def __init__(self, mpg):
|
|
19
|
+
... self.mpg = mpg
|
|
20
|
+
|
|
21
|
+
>>> def mpg2lp100(car):
|
|
22
|
+
... return 100.0/(1.609344/3.7854118 * car.mpg)
|
|
23
|
+
|
|
24
|
+
Let's create an index that would index cars' l/100 km rating.
|
|
25
|
+
|
|
26
|
+
>>> from zc.catalog import index, catalogindex
|
|
27
|
+
>>> idx = catalogindex.CallableWrapper(index.ValueIndex(), mpg2lp100)
|
|
28
|
+
|
|
29
|
+
Let's add a couple of cars to the index!
|
|
30
|
+
|
|
31
|
+
>>> hummer = Car(10.0)
|
|
32
|
+
>>> beamer = Car(22.0)
|
|
33
|
+
>>> civic = Car(45.0)
|
|
34
|
+
|
|
35
|
+
>>> idx.index_doc(1, hummer)
|
|
36
|
+
>>> idx.index_doc(2, beamer)
|
|
37
|
+
>>> idx.index_doc(3, civic)
|
|
38
|
+
|
|
39
|
+
The indexed values should be the converted l/100 km ratings:
|
|
40
|
+
|
|
41
|
+
>>> list(idx.values()) # doctest: +ELLIPSIS
|
|
42
|
+
[5.22699076283393..., 10.691572014887601, 23.521458432752723]
|
|
43
|
+
|
|
44
|
+
We can query for cars that consume fuel in some range:
|
|
45
|
+
|
|
46
|
+
>>> list(idx.apply({'between': (5.0, 7.0)}))
|
|
47
|
+
[3]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2006 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
"""Indexes appropriate for zope.catalog
|
|
15
|
+
"""
|
|
16
|
+
import zope.catalog.attribute
|
|
17
|
+
import zope.container.contained
|
|
18
|
+
import zope.index.interfaces
|
|
19
|
+
import zope.interface
|
|
20
|
+
|
|
21
|
+
import zc.catalog.index
|
|
22
|
+
import zc.catalog.interfaces
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@zope.interface.implementer(zc.catalog.interfaces.ICatalogValueIndex)
|
|
26
|
+
class ValueIndex(zope.catalog.attribute.AttributeIndex,
|
|
27
|
+
zc.catalog.index.ValueIndex,
|
|
28
|
+
zope.container.contained.Contained):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@zope.interface.implementer(zc.catalog.interfaces.ICatalogSetIndex)
|
|
33
|
+
class SetIndex(zope.catalog.attribute.AttributeIndex,
|
|
34
|
+
zc.catalog.index.SetIndex,
|
|
35
|
+
zope.container.contained.Contained):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class NormalizationWrapper(
|
|
40
|
+
zope.catalog.attribute.AttributeIndex,
|
|
41
|
+
zc.catalog.index.NormalizationWrapper,
|
|
42
|
+
zope.container.contained.Contained):
|
|
43
|
+
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@zope.interface.implementer(zc.catalog.interfaces.ICallableWrapper)
|
|
48
|
+
class CallableWrapper(zc.catalog.index.CallableWrapper,
|
|
49
|
+
zope.container.contained.Contained):
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@zope.interface.implementer(
|
|
54
|
+
zope.interface.implementedBy(NormalizationWrapper),
|
|
55
|
+
zc.catalog.interfaces.IValueIndex,
|
|
56
|
+
zope.index.interfaces.IIndexSort)
|
|
57
|
+
def DateTimeValueIndex(
|
|
58
|
+
field_name=None, interface=None, field_callable=False,
|
|
59
|
+
resolution=2): # hour; good for per-day searches
|
|
60
|
+
ix = NormalizationWrapper(
|
|
61
|
+
field_name, interface, field_callable, zc.catalog.index.ValueIndex(),
|
|
62
|
+
zc.catalog.index.DateTimeNormalizer(resolution), False)
|
|
63
|
+
zope.interface.alsoProvides(ix, zc.catalog.interfaces.IValueIndex)
|
|
64
|
+
return ix
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@zope.interface.implementer(
|
|
68
|
+
zope.interface.implementedBy(NormalizationWrapper),
|
|
69
|
+
zc.catalog.interfaces.ISetIndex)
|
|
70
|
+
def DateTimeSetIndex(
|
|
71
|
+
field_name=None, interface=None, field_callable=False,
|
|
72
|
+
resolution=2): # hour; good for per-day searches
|
|
73
|
+
ix = NormalizationWrapper(
|
|
74
|
+
field_name, interface, field_callable, zc.catalog.index.SetIndex(),
|
|
75
|
+
zc.catalog.index.DateTimeNormalizer(resolution), True)
|
|
76
|
+
zope.interface.alsoProvides(ix, zc.catalog.interfaces.ISetIndex)
|
|
77
|
+
return ix
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<configure
|
|
2
|
+
xmlns="http://namespaces.zope.org/zope"
|
|
3
|
+
xmlns:browser="http://namespaces.zope.org/browser"
|
|
4
|
+
xmlns:zcml="http://namespaces.zope.org/zcml"
|
|
5
|
+
i18n_domain="zope"
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
<class class=".extentcatalog.Catalog">
|
|
9
|
+
<factory
|
|
10
|
+
id="zc.catalog.extentcatalog"
|
|
11
|
+
/>
|
|
12
|
+
<require
|
|
13
|
+
interface="zope.catalog.interfaces.ICatalogQuery"
|
|
14
|
+
permission="zope.Public"
|
|
15
|
+
/>
|
|
16
|
+
<require
|
|
17
|
+
interface="zope.catalog.interfaces.ICatalogEdit"
|
|
18
|
+
permission="zope.ManageServices"
|
|
19
|
+
/>
|
|
20
|
+
<require
|
|
21
|
+
interface="zope.container.interfaces.IContainer"
|
|
22
|
+
permission="zope.ManageServices"
|
|
23
|
+
/>
|
|
24
|
+
</class>
|
|
25
|
+
|
|
26
|
+
<class class=".extentcatalog.FilterExtent">
|
|
27
|
+
<require
|
|
28
|
+
attributes="addable __iter__ __or__ __ror__ union __and__ __rand__
|
|
29
|
+
intersection __sub__ difference __rsub__ rdifference
|
|
30
|
+
__nonzero__ __contains__"
|
|
31
|
+
permission="zope.View"/>
|
|
32
|
+
<require
|
|
33
|
+
attributes="add remove discard clear"
|
|
34
|
+
permission="zope.ManageServices"
|
|
35
|
+
/>
|
|
36
|
+
</class>
|
|
37
|
+
|
|
38
|
+
<class class=".catalogindex.ValueIndex">
|
|
39
|
+
<require
|
|
40
|
+
permission="zope.ManageServices"
|
|
41
|
+
interface="zope.catalog.interfaces.IAttributeIndex
|
|
42
|
+
zope.index.interfaces.IStatistics"
|
|
43
|
+
set_schema="zope.catalog.interfaces.IAttributeIndex"
|
|
44
|
+
/>
|
|
45
|
+
</class>
|
|
46
|
+
|
|
47
|
+
<class class=".catalogindex.SetIndex">
|
|
48
|
+
<require
|
|
49
|
+
permission="zope.ManageServices"
|
|
50
|
+
interface="zope.catalog.interfaces.IAttributeIndex
|
|
51
|
+
zope.index.interfaces.IStatistics"
|
|
52
|
+
set_schema="zope.catalog.interfaces.IAttributeIndex"
|
|
53
|
+
/>
|
|
54
|
+
</class>
|
|
55
|
+
|
|
56
|
+
<class class=".catalogindex.NormalizationWrapper">
|
|
57
|
+
<require
|
|
58
|
+
permission="zope.ManageServices"
|
|
59
|
+
interface="zope.catalog.interfaces.IAttributeIndex
|
|
60
|
+
zope.index.interfaces.IStatistics"
|
|
61
|
+
set_schema="zope.catalog.interfaces.IAttributeIndex"
|
|
62
|
+
/>
|
|
63
|
+
</class>
|
|
64
|
+
|
|
65
|
+
<class class="BTrees.Length.Length">
|
|
66
|
+
<require
|
|
67
|
+
permission="zope.ManageServices"
|
|
68
|
+
attributes="__call__"
|
|
69
|
+
/>
|
|
70
|
+
</class>
|
|
71
|
+
|
|
72
|
+
</configure>
|