Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
2639fcb7
Commit
2639fcb7
authored
Aug 14, 2002
by
Martijn Pieters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up indentation and trailing whitespace.
parent
bdb3057e
Changes
102
Hide whitespace changes
Inline
Side-by-side
Showing
102 changed files
with
1007 additions
and
1086 deletions
+1007
-1086
lib/python/DocumentTemplate/DT_HTML.py
lib/python/DocumentTemplate/DT_HTML.py
+9
-9
lib/python/DocumentTemplate/DT_If.py
lib/python/DocumentTemplate/DT_If.py
+13
-13
lib/python/DocumentTemplate/DT_In.py
lib/python/DocumentTemplate/DT_In.py
+78
-78
lib/python/DocumentTemplate/DT_InSV.py
lib/python/DocumentTemplate/DT_InSV.py
+27
-27
lib/python/DocumentTemplate/DT_Let.py
lib/python/DocumentTemplate/DT_Let.py
+7
-8
lib/python/DocumentTemplate/DT_Raise.py
lib/python/DocumentTemplate/DT_Raise.py
+8
-8
lib/python/DocumentTemplate/DT_Return.py
lib/python/DocumentTemplate/DT_Return.py
+4
-4
lib/python/DocumentTemplate/DT_String.py
lib/python/DocumentTemplate/DT_String.py
+16
-16
lib/python/DocumentTemplate/DT_Try.py
lib/python/DocumentTemplate/DT_Try.py
+21
-21
lib/python/DocumentTemplate/DT_UI.py
lib/python/DocumentTemplate/DT_UI.py
+10
-10
lib/python/DocumentTemplate/DT_Util.py
lib/python/DocumentTemplate/DT_Util.py
+19
-19
lib/python/DocumentTemplate/DT_Var.py
lib/python/DocumentTemplate/DT_Var.py
+25
-25
lib/python/DocumentTemplate/DT_With.py
lib/python/DocumentTemplate/DT_With.py
+6
-6
lib/python/DocumentTemplate/DTtestExpr.py
lib/python/DocumentTemplate/DTtestExpr.py
+5
-5
lib/python/DocumentTemplate/DocumentTemplate.py
lib/python/DocumentTemplate/DocumentTemplate.py
+4
-4
lib/python/DocumentTemplate/VSEval.py
lib/python/DocumentTemplate/VSEval.py
+0
-1
lib/python/DocumentTemplate/__init__.py
lib/python/DocumentTemplate/__init__.py
+4
-4
lib/python/DocumentTemplate/html_quote.py
lib/python/DocumentTemplate/html_quote.py
+0
-1
lib/python/DocumentTemplate/pDocumentTemplate.py
lib/python/DocumentTemplate/pDocumentTemplate.py
+12
-12
lib/python/DocumentTemplate/sequence/SortEx.py
lib/python/DocumentTemplate/sequence/SortEx.py
+29
-31
lib/python/DocumentTemplate/sequence/__init__.py
lib/python/DocumentTemplate/sequence/__init__.py
+2
-2
lib/python/DocumentTemplate/sequence/tests/testSequence.py
lib/python/DocumentTemplate/sequence/tests/testSequence.py
+5
-5
lib/python/DocumentTemplate/sequence/tests/ztestlib.py
lib/python/DocumentTemplate/sequence/tests/ztestlib.py
+12
-14
lib/python/DocumentTemplate/tests/testDTML.py
lib/python/DocumentTemplate/tests/testDTML.py
+9
-9
lib/python/DocumentTemplate/tests/testDTMLUnicode.py
lib/python/DocumentTemplate/tests/testDTMLUnicode.py
+4
-4
lib/python/DocumentTemplate/tests/testustr.py
lib/python/DocumentTemplate/tests/testustr.py
+4
-4
lib/python/Products/PythonScripts/Extensions/RemotePS.py
lib/python/Products/PythonScripts/Extensions/RemotePS.py
+1
-1
lib/python/Products/PythonScripts/PythonScript.py
lib/python/Products/PythonScripts/PythonScript.py
+11
-11
lib/python/Products/PythonScripts/Utility.py
lib/python/Products/PythonScripts/Utility.py
+3
-3
lib/python/Products/PythonScripts/__init__.py
lib/python/Products/PythonScripts/__init__.py
+5
-5
lib/python/Products/PythonScripts/help/PythonScript.py
lib/python/Products/PythonScripts/help/PythonScript.py
+3
-8
lib/python/Products/PythonScripts/help/Script.py
lib/python/Products/PythonScripts/help/Script.py
+2
-2
lib/python/Products/PythonScripts/help/standard.py
lib/python/Products/PythonScripts/help/standard.py
+5
-5
lib/python/Products/PythonScripts/module_access_examples.py
lib/python/Products/PythonScripts/module_access_examples.py
+0
-5
lib/python/Products/PythonScripts/standard.py
lib/python/Products/PythonScripts/standard.py
+3
-4
lib/python/Products/PythonScripts/tests/testPythonScript.py
lib/python/Products/PythonScripts/tests/testPythonScript.py
+8
-9
lib/python/Products/Sessions/BrowserIdManager.py
lib/python/Products/Sessions/BrowserIdManager.py
+11
-11
lib/python/Products/Sessions/SessionDataManager.py
lib/python/Products/Sessions/SessionDataManager.py
+5
-5
lib/python/Products/Sessions/SessionInterfaces.py
lib/python/Products/Sessions/SessionInterfaces.py
+4
-4
lib/python/Products/Sessions/SessionPermissions.py
lib/python/Products/Sessions/SessionPermissions.py
+1
-1
lib/python/Products/Sessions/__init__.py
lib/python/Products/Sessions/__init__.py
+3
-3
lib/python/Products/Sessions/common.py
lib/python/Products/Sessions/common.py
+1
-1
lib/python/Products/Sessions/help/SessionInterfaces.py
lib/python/Products/Sessions/help/SessionInterfaces.py
+4
-4
lib/python/Products/Sessions/stresstests/stresstestMultiThread.py
...on/Products/Sessions/stresstests/stresstestMultiThread.py
+5
-6
lib/python/Products/Sessions/tests/testBrowserIdManager.py
lib/python/Products/Sessions/tests/testBrowserIdManager.py
+10
-10
lib/python/Products/Sessions/tests/testSessionDataManager.py
lib/python/Products/Sessions/tests/testSessionDataManager.py
+5
-6
lib/python/Products/SiteAccess/AccessRule.py
lib/python/Products/SiteAccess/AccessRule.py
+3
-3
lib/python/Products/SiteAccess/Extensions/updata.py
lib/python/Products/SiteAccess/Extensions/updata.py
+1
-1
lib/python/Products/SiteAccess/SiteRoot.py
lib/python/Products/SiteAccess/SiteRoot.py
+7
-7
lib/python/Products/SiteAccess/VirtualHostMonster.py
lib/python/Products/SiteAccess/VirtualHostMonster.py
+2
-2
lib/python/Products/SiteAccess/__init__.py
lib/python/Products/SiteAccess/__init__.py
+12
-12
lib/python/Products/SiteErrorLog/SiteErrorLog.py
lib/python/Products/SiteErrorLog/SiteErrorLog.py
+6
-7
lib/python/Products/SiteErrorLog/__init__.py
lib/python/Products/SiteErrorLog/__init__.py
+3
-4
lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
...ucts/StandardCacheManagers/AcceleratedHTTPCacheManager.py
+4
-4
lib/python/Products/StandardCacheManagers/RAMCacheManager.py
lib/python/Products/StandardCacheManagers/RAMCacheManager.py
+6
-6
lib/python/Products/StandardCacheManagers/__init__.py
lib/python/Products/StandardCacheManagers/__init__.py
+2
-2
lib/python/Products/TemporaryFolder/LowConflictConnection.py
lib/python/Products/TemporaryFolder/LowConflictConnection.py
+2
-4
lib/python/Products/TemporaryFolder/TemporaryFolder.py
lib/python/Products/TemporaryFolder/TemporaryFolder.py
+8
-8
lib/python/Products/TemporaryFolder/TemporaryStorage.py
lib/python/Products/TemporaryFolder/TemporaryStorage.py
+9
-15
lib/python/Products/TemporaryFolder/__init__.py
lib/python/Products/TemporaryFolder/__init__.py
+3
-3
lib/python/Products/TemporaryFolder/patchfs.py
lib/python/Products/TemporaryFolder/patchfs.py
+2
-2
lib/python/Products/TemporaryFolder/tests/testTemporaryStorage.py
...on/Products/TemporaryFolder/tests/testTemporaryStorage.py
+6
-7
lib/python/Products/Transience/Transience.py
lib/python/Products/Transience/Transience.py
+13
-13
lib/python/Products/Transience/TransienceInterfaces.py
lib/python/Products/Transience/TransienceInterfaces.py
+4
-4
lib/python/Products/Transience/TransientObject.py
lib/python/Products/Transience/TransientObject.py
+7
-7
lib/python/Products/Transience/__init__.py
lib/python/Products/Transience/__init__.py
+4
-5
lib/python/Products/Transience/help/TransienceInterfaces.py
lib/python/Products/Transience/help/TransienceInterfaces.py
+5
-7
lib/python/Products/Transience/tests/fauxtime.py
lib/python/Products/Transience/tests/fauxtime.py
+0
-1
lib/python/Products/Transience/tests/testTimeoutRelated.py
lib/python/Products/Transience/tests/testTimeoutRelated.py
+1
-1
lib/python/Products/Transience/tests/testTransientObject.py
lib/python/Products/Transience/tests/testTransientObject.py
+7
-8
lib/python/Products/Transience/tests/testTransientObjectContainer.py
...Products/Transience/tests/testTransientObjectContainer.py
+11
-12
lib/python/Products/ZCTextIndex/BaseIndex.py
lib/python/Products/ZCTextIndex/BaseIndex.py
+4
-4
lib/python/Products/ZCTextIndex/IIndex.py
lib/python/Products/ZCTextIndex/IIndex.py
+1
-1
lib/python/Products/ZCTextIndex/ZCTextIndex.py
lib/python/Products/ZCTextIndex/ZCTextIndex.py
+22
-22
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
+13
-13
lib/python/Products/ZCatalog/Catalog.py
lib/python/Products/ZCatalog/Catalog.py
+42
-43
lib/python/Products/ZCatalog/CatalogAwareness.py
lib/python/Products/ZCatalog/CatalogAwareness.py
+4
-13
lib/python/Products/ZCatalog/CatalogBrains.py
lib/python/Products/ZCatalog/CatalogBrains.py
+5
-5
lib/python/Products/ZCatalog/CatalogPathAwareness.py
lib/python/Products/ZCatalog/CatalogPathAwareness.py
+5
-13
lib/python/Products/ZCatalog/IZCatalog.py
lib/python/Products/ZCatalog/IZCatalog.py
+12
-12
lib/python/Products/ZCatalog/Lazy.py
lib/python/Products/ZCatalog/Lazy.py
+7
-7
lib/python/Products/ZCatalog/ZCatalog.py
lib/python/Products/ZCatalog/ZCatalog.py
+63
-63
lib/python/Products/ZCatalog/ZCatalogIndexes.py
lib/python/Products/ZCatalog/ZCatalogIndexes.py
+13
-15
lib/python/Products/ZCatalog/__init__.py
lib/python/Products/ZCatalog/__init__.py
+4
-5
lib/python/Products/ZCatalog/help/Vocabulary.py
lib/python/Products/ZCatalog/help/Vocabulary.py
+6
-8
lib/python/Products/ZCatalog/help/ZCatalog.py
lib/python/Products/ZCatalog/help/ZCatalog.py
+20
-21
lib/python/Products/ZCatalog/regressiontests/keywords.py
lib/python/Products/ZCatalog/regressiontests/keywords.py
+12
-14
lib/python/Products/ZCatalog/regressiontests/loadmail.py
lib/python/Products/ZCatalog/regressiontests/loadmail.py
+13
-13
lib/python/Products/ZCatalog/regressiontests/regressionCatalog.py
...on/Products/ZCatalog/regressiontests/regressionCatalog.py
+93
-94
lib/python/Products/ZCatalog/regressiontests/regressionCatalogTiming.py
...ducts/ZCatalog/regressiontests/regressionCatalogTiming.py
+9
-10
lib/python/Products/ZCatalog/regressiontests/regressionUnicode.py
...on/Products/ZCatalog/regressiontests/regressionUnicode.py
+4
-4
lib/python/Products/ZCatalog/regressiontests/unittest_patched.py
...hon/Products/ZCatalog/regressiontests/unittest_patched.py
+18
-18
lib/python/Products/ZCatalog/tests/testCatalog.py
lib/python/Products/ZCatalog/tests/testCatalog.py
+15
-15
lib/python/Products/ZGadflyDA/DA.py
lib/python/Products/ZGadflyDA/DA.py
+10
-11
lib/python/Products/ZGadflyDA/DABase.py
lib/python/Products/ZGadflyDA/DABase.py
+8
-8
lib/python/Products/ZGadflyDA/__init__.py
lib/python/Products/ZGadflyDA/__init__.py
+5
-5
lib/python/Products/ZGadflyDA/db.py
lib/python/Products/ZGadflyDA/db.py
+8
-8
lib/python/Products/ZSQLMethods/SQL.py
lib/python/Products/ZSQLMethods/SQL.py
+7
-7
lib/python/Products/ZSQLMethods/__init__.py
lib/python/Products/ZSQLMethods/__init__.py
+4
-4
lib/python/Products/ZSQLMethods/help/ZSQLMethod.py
lib/python/Products/ZSQLMethods/help/ZSQLMethod.py
+5
-17
lib/python/Products/ZopeTutorial/TutorialTopic.py
lib/python/Products/ZopeTutorial/TutorialTopic.py
+15
-15
lib/python/Products/ZopeTutorial/__init__.py
lib/python/Products/ZopeTutorial/__init__.py
+9
-9
No files found.
lib/python/DocumentTemplate/DT_HTML.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.3
1 2001/11/28 15:50:54 matt
Exp $"""
$Id: DT_HTML.py,v 1.3
2 2002/08/14 22:29:52 mj
Exp $"""
from
DT_String
import
String
,
FileMixin
import
DT_String
,
re
...
...
@@ -71,7 +71,7 @@ class dtml_re_class:
else
:
if
text
[
s
:
s
+
5
]
==
'&dtml'
and
text
[
s
+
5
]
in
'.-'
:
n
=
s
+
6
e
=
text
.
find
(
';'
,
n
)
e
=
text
.
find
(
';'
,
n
)
if
e
>=
0
:
args
=
text
[
n
:
e
]
l
=
len
(
args
)
...
...
@@ -97,7 +97,7 @@ class dtml_re_class:
d
[
3
]
=
d
[
'args'
]
=
args
self
.
_start
=
s
return
self
start
=
s
+
1
continue
...
...
@@ -106,7 +106,7 @@ class dtml_re_class:
mo
=
name_match
(
text
,
n
)
if
mo
is
None
:
return
None
l
=
mo
.
end
(
0
)
-
mo
.
start
(
0
)
a
=
n
+
l
name
=
text
[
n
:
a
].
strip
()
...
...
@@ -177,7 +177,7 @@ class HTML(DT_String.String):
if
not
(
args
==
sargs
or
args
==
sargs
[:
l
]
and
sargs
[
l
:
l
+
1
]
in
'
\
t
\
n
'
):
return
tag
,
args
,
self
.
commands
[
name
],
None
return
tag
,
args
,
None
,
name
try
:
return
tag
,
args
,
self
.
commands
[
name
],
None
...
...
@@ -225,7 +225,7 @@ class HTML(DT_String.String):
manage_editForm__roles__
=
()
def
manage_editForm
(
self
,
URL1
,
REQUEST
):
'''Display doc template editing form'''
#"
return
self
.
_manage_editForm
(
self
,
mapping
=
REQUEST
,
...
...
@@ -302,7 +302,7 @@ class HTMLFile(FileMixin, HTML):
if
data
.
find
(
'
\
r
'
):
data
=
'
\
n
\
r
'
.
join
(
data
.
split
(
'
\
r
\
n
'
))
data
=
'
\
n
'
.
join
(
data
.
split
(
'
\
n
\
r
'
))
if
self
.
edited_source
:
self
.
edited_source
=
data
self
.
_v_cooked
=
self
.
cook
()
...
...
lib/python/DocumentTemplate/DT_If.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Conditional insertion
...
...
@@ -19,14 +19,14 @@ __doc__='''Conditional insertion
format, use::
%(if name)[
text
text
%(if name)]
To include text when an object is true using the HTML
format, use::
<!--#if name-->
text
text
<!--#/if name-->
where 'name' is the name bound to the object.
...
...
@@ -35,14 +35,14 @@ __doc__='''Conditional insertion
format, use::
%(else name)[
text
text
%(else name)]
To include text when an object is false using the HTML
format, use::
<!--#else name-->
text
text
<!--#/else name-->
Finally to include text when an object is true and to
...
...
@@ -50,10 +50,10 @@ __doc__='''Conditional insertion
EPFS format, use::
%(if name)[
true text
true text
%(if name)]
%(else name)[
false text
false text
%(else name)]
and to include text when an object is true and to
...
...
@@ -61,9 +61,9 @@ __doc__='''Conditional insertion
HTML format, use::
<!--#if name-->
true text
true text
<!--#else name-->
false text
false text
<!--#/if name-->
Notes:
...
...
@@ -74,9 +74,9 @@ __doc__='''Conditional insertion
is used inside the tag, including in enclosed tags, the
variable is not reevaluated.
'''
__rcs_id__
=
'$Id: DT_If.py,v 1.1
8 2001/11/28 15:50:54 matt
Exp $'
__version__
=
'$Revision: 1.1
8
$'
[
11
:
-
2
]
'''
__rcs_id__
=
'$Id: DT_If.py,v 1.1
9 2002/08/14 22:29:52 mj
Exp $'
__version__
=
'$Revision: 1.1
9
$'
[
11
:
-
2
]
from
DT_Util
import
ParseError
,
parse_params
,
name_param
,
str
...
...
lib/python/DocumentTemplate/DT_In.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''Sequence insertion
A sequence may be inserted using an 'in' command. The 'in'
command specifies the name of a sequence object and text to
be inserted for each element in the sequence.
be inserted for each element in the sequence.
The EPFS syntax for the in command is::
...
...
@@ -25,7 +25,7 @@
The HTML syntax for the in command is::
<!--#in name-->
text
text
<!--#/in name-->
See the example below that shows how 'if', 'else', and 'in' commands
...
...
@@ -70,7 +70,7 @@
sort_expr -- This allows an expression to control sort order.
reverse -- Reverse the sequence (may be combined with sort). Note
that this can cause a huge memory use in lazy activation instances.
that this can cause a huge memory use in lazy activation instances.
reverse_expr -- This calculated parameter allows you to calculate the
need of reversing on the fly.
...
...
@@ -160,7 +160,7 @@
parameter is 0.
'overlap' -- The desired overlap between batches. The
default is no overlap.
default is no overlap.
Typically, only 'start' and 'size' will be specified.
...
...
@@ -331,8 +331,8 @@
'''
#'
__rcs_id__
=
'$Id: DT_In.py,v 1.
59 2002/05/07 17:55:37 htrd
Exp $'
__version__
=
'$Revision: 1.
59
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_In.py,v 1.
60 2002/08/14 22:29:52 mj
Exp $'
__version__
=
'$Revision: 1.
60
$'
[
11
:
-
2
]
import
sys
from
DT_Util
import
ParseError
,
parse_params
,
name_param
,
str
,
join_unicode
...
...
@@ -360,7 +360,7 @@ class InClass:
start_name_re
=
None
reverse
=
None
sort_expr
=
reverse_expr
=
None
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
start
=
'1'
,
end
=
'-1'
,
size
=
'10'
,
...
...
@@ -385,10 +385,10 @@ class InClass:
if
has_key
(
'reverse'
):
self
.
reverse
=
args
[
'reverse'
]
if
has_key
(
'no_push_item'
):
self
.
no_push_item
=
args
[
'no_push_item'
]
if
has_key
(
'mapping'
):
self
.
mapping
=
args
[
'mapping'
]
for
n
in
'start'
,
'size'
,
'end'
:
if
has_key
(
n
):
self
.
batch
=
1
...
...
@@ -397,7 +397,7 @@ class InClass:
if
prefix
and
not
simple_name
(
prefix
):
raise
ParseError
,
_tm
(
'prefix is not a simple name'
,
'in'
)
for
n
in
'orphan'
,
'overlap'
,
'previous'
,
'next'
:
if
has_key
(
n
)
and
not
self
.
batch
:
raise
ParseError
,
(
...
...
@@ -417,7 +417,7 @@ class InClass:
'&+'
+
''
.
join
([
"[%s]"
%
c
for
c
in
v
])
+
'=[0-9]+&+'
)
name
,
expr
=
name_param
(
args
,
'in'
,
1
)
if
expr
is
not
None
:
expr
=
expr
.
eval
self
.
__name__
,
self
.
expr
=
name
,
expr
...
...
@@ -433,7 +433,7 @@ class InClass:
raise
ParseError
,
(
'name in else does not match in'
,
'in'
)
self
.
elses
=
section
.
blocks
def
renderwb
(
self
,
md
):
expr
=
self
.
expr
...
...
@@ -456,7 +456,7 @@ class InClass:
section
=
self
.
section
params
=
self
.
args
mapping
=
self
.
mapping
no_push_item
=
self
.
no_push_item
...
...
@@ -470,7 +470,7 @@ class InClass:
sequence
=
self
.
reverse_sequence
(
sequence
)
elif
self
.
reverse
is
not
None
:
sequence
=
self
.
reverse_sequence
(
sequence
)
next
=
previous
=
0
try
:
start
=
int_param
(
params
,
md
,
'start'
,
0
)
except
:
start
=
1
...
...
@@ -570,7 +570,7 @@ class InClass:
pkw
[
'next-sequence-end-index'
]
=
pend
-
1
pkw
[
'next-sequence-size'
]
=
pend
+
1
-
pstart
except
:
pass
if
index
==
last
:
pkw
[
'sequence-end'
]
=
1
if
guarded_getitem
is
not
None
:
...
...
@@ -636,7 +636,7 @@ class InClass:
raise
'InError'
,
(
'Strings are not allowed as input to the in tag.'
)
section
=
self
.
section
section
=
self
.
section
mapping
=
self
.
mapping
no_push_item
=
self
.
no_push_item
...
...
@@ -669,46 +669,46 @@ class InClass:
if
cache
:
push
(
cache
)
push
(
vars
)
try
:
result
=
[]
append
=
result
.
append
guarded_getitem
=
getattr
(
md
,
'guarded_getitem'
,
None
)
for
index
in
range
(
l
):
if
index
==
last
:
pkw
[
'sequence-end'
]
=
1
if
guarded_getitem
is
not
None
:
try
:
client
=
guarded_getitem
(
sequence
,
index
)
except
ValidationError
,
vv
:
if
(
self
.
args
.
has_key
(
'skip_unauthorized'
)
and
self
.
args
[
'skip_unauthorized'
]):
if
index
==
1
:
pkw
[
'sequence-start'
]
=
0
continue
raise
ValidationError
,
'(item %s): %s'
%
(
index
,
vv
),
sys
.
exc_info
()[
2
]
else
:
client
=
sequence
[
index
]
pkw
[
'sequence-index'
]
=
index
t
=
type
(
client
)
if
t
is
TupleType
and
len
(
client
)
==
2
:
client
=
client
[
1
]
if
no_push_item
:
pushed
=
0
elif
mapping
:
pushed
=
1
push
(
client
)
elif
t
in
StringTypes
:
pushed
=
0
else
:
pushed
=
1
push
(
InstanceDict
(
client
,
md
))
result
=
[]
append
=
result
.
append
guarded_getitem
=
getattr
(
md
,
'guarded_getitem'
,
None
)
for
index
in
range
(
l
):
if
index
==
last
:
pkw
[
'sequence-end'
]
=
1
if
guarded_getitem
is
not
None
:
try
:
client
=
guarded_getitem
(
sequence
,
index
)
except
ValidationError
,
vv
:
if
(
self
.
args
.
has_key
(
'skip_unauthorized'
)
and
self
.
args
[
'skip_unauthorized'
]):
if
index
==
1
:
pkw
[
'sequence-start'
]
=
0
continue
raise
ValidationError
,
'(item %s): %s'
%
(
index
,
vv
),
sys
.
exc_info
()[
2
]
else
:
client
=
sequence
[
index
]
pkw
[
'sequence-index'
]
=
index
t
=
type
(
client
)
if
t
is
TupleType
and
len
(
client
)
==
2
:
client
=
client
[
1
]
if
no_push_item
:
pushed
=
0
elif
mapping
:
pushed
=
1
push
(
client
)
elif
t
in
StringTypes
:
pushed
=
0
else
:
pushed
=
1
push
(
InstanceDict
(
client
,
md
))
try
:
append
(
render
(
section
,
md
))
finally
:
if
pushed
:
pop
()
if
index
==
0
:
pkw
[
'sequence-start'
]
=
0
try
:
append
(
render
(
section
,
md
))
finally
:
if
pushed
:
pop
()
if
index
==
0
:
pkw
[
'sequence-start'
]
=
0
result
=
join_unicode
(
result
)
result
=
join_unicode
(
result
)
finally
:
if
cache
:
pop
()
...
...
@@ -721,7 +721,7 @@ class InClass:
# Modified with multiple sort fields by Ross Lazarus
# April 7 2000 rossl@med.usyd.edu.au
# eg <dtml-in "foo" sort="akey,anotherkey">
# Modified with advanced sort functions by
# Oleg Broytmann <phd@phd.pp.ru> 30 Mar 2001
# eg <dtml-in "foo" sort="akey/nocase,anotherkey/cmp/desc">
...
...
@@ -729,7 +729,7 @@ class InClass:
sort
=
self
.
sort
need_sortfunc
=
sort
.
find
(
'/'
)
>=
0
sortfields
=
sort
.
split
(
','
)
# multi sort = key1,key2
sortfields
=
sort
.
split
(
','
)
# multi sort = key1,key2
multsort
=
len
(
sortfields
)
>
1
# flag: is multiple sort
if
need_sortfunc
:
...
...
@@ -756,25 +756,25 @@ class InClass:
v
=
client
if
sort
:
if
multsort
:
# More than one sort key.
k
=
[]
for
sk
in
sortfields
:
try
:
if
mapping
:
akey
=
v
[
sk
]
else
:
akey
=
getattr
(
v
,
sk
)
except
AttributeError
,
KeyError
:
akey
=
None
if
not
basic_type
(
akey
):
try
:
akey
=
akey
()
except
:
pass
k
.
append
(
akey
)
else
:
# One sort key.
try
:
if
mapping
:
k
=
v
[
sort
]
else
:
k
=
getattr
(
v
,
sort
)
except
AttributeError
,
KeyError
:
k
=
None
if
not
basic_type
(
type
(
k
)):
try
:
k
=
k
()
except
:
pass
if
multsort
:
# More than one sort key.
k
=
[]
for
sk
in
sortfields
:
try
:
if
mapping
:
akey
=
v
[
sk
]
else
:
akey
=
getattr
(
v
,
sk
)
except
AttributeError
,
KeyError
:
akey
=
None
if
not
basic_type
(
akey
):
try
:
akey
=
akey
()
except
:
pass
k
.
append
(
akey
)
else
:
# One sort key.
try
:
if
mapping
:
k
=
v
[
sort
]
else
:
k
=
getattr
(
v
,
sort
)
except
AttributeError
,
KeyError
:
k
=
None
if
not
basic_type
(
type
(
k
)):
try
:
k
=
k
()
except
:
pass
s
.
append
((
k
,
client
))
...
...
@@ -786,7 +786,7 @@ class InClass:
sequence
=
[]
for
k
,
client
in
s
:
sequence
.
append
(
client
)
sequence
.
append
(
client
)
return
sequence
def
reverse_sequence
(
self
,
sequence
):
...
...
lib/python/DocumentTemplate/DT_InSV.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Sequence variables support
$Id: DT_InSV.py,v 1.2
1 2001/11/28 15:50:54 matt
Exp $'''
__version__
=
'$Revision: 1.2
1
$'
[
11
:
-
2
]
$Id: DT_InSV.py,v 1.2
2 2002/08/14 22:29:52 mj
Exp $'''
__version__
=
'$Revision: 1.2
2
$'
[
11
:
-
2
]
from
math
import
sqrt
import
re
...
...
@@ -28,10 +28,10 @@ except: mv=None
class
sequence_variables
:
alt_prefix
=
None
def
__init__
(
self
,
items
=
None
,
query_string
=
''
,
start_name_re
=
None
,
alt_prefix
=
''
):
self
.
items
=
items
self
.
query_string
=
query_string
self
.
start_name_re
=
start_name_re
...
...
@@ -68,35 +68,35 @@ class sequence_variables:
roman
=
''
while
num
>=
1000
:
num
=
num
-
1000
roman
=
'%sM'
%
roman
num
=
num
-
1000
roman
=
'%sM'
%
roman
while
num
>=
500
:
num
=
num
-
500
roman
=
'%sD'
%
roman
num
=
num
-
500
roman
=
'%sD'
%
roman
while
num
>=
100
:
num
=
num
-
100
roman
=
'%sC'
%
roman
num
=
num
-
100
roman
=
'%sC'
%
roman
while
num
>=
50
:
num
=
num
-
50
roman
=
'%sL'
%
roman
num
=
num
-
50
roman
=
'%sL'
%
roman
while
num
>=
10
:
num
=
num
-
10
roman
=
'%sX'
%
roman
num
=
num
-
10
roman
=
'%sX'
%
roman
while
num
>=
5
:
num
=
num
-
5
roman
=
'%sV'
%
roman
num
=
num
-
5
roman
=
'%sV'
%
roman
while
num
<
5
and
num
>=
1
:
num
=
num
-
1
roman
=
'%sI'
%
roman
num
=
num
-
1
roman
=
'%sI'
%
roman
# Replaces special cases in Roman Numerals
roman
=
roman
.
replace
(
'DCCCC'
,
'CM'
)
roman
=
roman
.
replace
(
'CCCC'
,
'CD'
)
roman
=
roman
.
replace
(
'LXXXX'
,
'XC'
)
...
...
@@ -132,7 +132,7 @@ class sequence_variables:
return
l
def
query
(
self
,
*
ignored
):
if
self
.
start_name_re
is
None
:
raise
KeyError
,
'sequence-query'
query_string
=
self
.
query_string
while
query_string
and
query_string
[:
1
]
in
'?&'
:
...
...
@@ -140,7 +140,7 @@ class sequence_variables:
while
query_string
[
-
1
:]
==
'&'
:
query_string
=
query_string
[:
-
1
]
if
query_string
:
query_string
=
'&%s&'
%
query_string
query_string
=
'&%s&'
%
query_string
reg
=
self
.
start_name_re
if
type
(
reg
)
==
type
(
re
.
compile
(
r""
)):
...
...
@@ -160,9 +160,9 @@ class sequence_variables:
query_string
=
'?'
+
query_string
[
1
:]
else
:
query_string
=
'?'
self
[
'sequence-query'
]
=
query_string
return
query_string
statistic_names
=
(
'total'
,
'count'
,
'min'
,
'max'
,
'median'
,
'mean'
,
...
...
@@ -225,7 +225,7 @@ class sequence_variables:
if
count
>
1
:
sumsq
=
sumsq
*
n
/
(
n
-
1
)
data
[
'variance-%s'
%
name
]
=
sumsq
data
[
'standard-deviation-%s'
%
name
]
=
sqrt
(
sumsq
)
data
[
'standard-deviation-%s'
%
name
]
=
sqrt
(
sumsq
)
else
:
data
[
'variance-%s'
%
name
]
=
''
data
[
'standard-deviation-%s'
%
name
]
=
''
...
...
@@ -368,7 +368,7 @@ class sequence_variables:
except
:
pass
if
key
==
'sequence-query'
:
return
self
.
query
()
raise
KeyError
,
key
...
...
lib/python/DocumentTemplate/DT_Let.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
''' The Let tag was contributed to Zope by and is copyright, 1999
Phillip J. Eby. Permission has been granted to release the Let tag
under the Zope Public License.
Let name=value...
...
...
@@ -38,7 +38,7 @@
Variables are processed in sequence, so later assignments can
reference and/or overwrite the results of previous assignments,
as desired.
'''
'''
from
DT_Util
import
render_blocks
,
Eval
,
ParseError
from
DT_Util
import
str
# Probably needed due to hysterical pickles.
...
...
@@ -48,7 +48,7 @@ import re
class
Let
:
blockContinuations
=
()
name
=
'let'
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
self
.
__name__
=
args
...
...
@@ -58,7 +58,7 @@ class Let:
for
i
in
range
(
len
(
args
)):
name
,
expr
=
args
[
i
]
if
expr
[:
1
]
==
'"'
and
expr
[
-
1
:]
==
'"'
and
len
(
expr
)
>
1
:
# expr shorthand
# expr shorthand
expr
=
expr
[
1
:
-
1
]
try
:
args
[
i
]
=
name
,
Eval
(
expr
).
eval
except
SyntaxError
,
v
:
...
...
@@ -85,7 +85,7 @@ def parse_let_params(text,
parmre
=
re
.
compile
(
'([
\
000
- ]*([^
\
000
- ="]+)=([^
\
000
- ="]+))'
),
qparmre
=
re
.
compile
(
'([
\
000
- ]*([^
\
000
- ="]+)="([^"]*)")'
),
**
parms
):
result
=
result
or
[]
mo
=
parmre
.
match
(
text
)
...
...
@@ -108,4 +108,3 @@ def parse_let_params(text,
text
=
text
[
l
:].
strip
()
if
text
:
return
apply
(
parse_let_params
,(
text
,
result
,
tag
),
parms
)
else
:
return
result
lib/python/DocumentTemplate/DT_Raise.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''Raising exceptions
...
...
@@ -22,9 +22,9 @@
<!--#/raise-->
<!--#/if-->
'''
__rcs_id__
=
'$Id: DT_Raise.py,v 1.1
2 2001/11/28 15:50:55 matt
Exp $'
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
'''
__rcs_id__
=
'$Id: DT_Raise.py,v 1.1
3 2002/08/14 22:29:52 mj
Exp $'
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
render_blocks
,
str
...
...
@@ -43,9 +43,9 @@ class Raise:
def
render
(
self
,
md
):
expr
=
self
.
expr
if
expr
is
None
:
t
=
self
.
__name__
if
t
[
-
5
:]
==
'Error'
and
__builtins__
.
has_key
(
t
):
t
=
__builtins__
[
t
]
t
=
self
.
__name__
if
t
[
-
5
:]
==
'Error'
and
__builtins__
.
has_key
(
t
):
t
=
__builtins__
[
t
]
else
:
try
:
t
=
expr
.
eval
(
md
)
except
:
t
=
'Invalid Error Type Expression'
...
...
lib/python/DocumentTemplate/DT_Return.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
str
import
sys
class
ReturnTag
:
class
ReturnTag
:
name
=
'return'
expr
=
None
...
...
lib/python/DocumentTemplate/DT_String.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"$Id: DT_String.py,v 1.5
0 2002/08/01 16:00:39
mj Exp $"
"$Id: DT_String.py,v 1.5
1 2002/08/14 22:29:52
mj Exp $"
import
thread
,
re
,
exceptions
,
os
...
...
@@ -36,7 +36,7 @@ class String:
%(name)s
%(in results)]
"""
"""
isDocTemp
=
1
...
...
@@ -46,7 +46,7 @@ class String:
func_code
.
co_varnames
=
'self'
,
'REQUEST'
func_code
.
co_argcount
=
2
func_code
.
__roles__
=
()
func_defaults__roles__
=
()
func_defaults
=
()
...
...
@@ -186,7 +186,7 @@ class String:
def
skip_eol
(
self
,
text
,
start
,
eol
=
re
.
compile
(
'[
\
t
]*
\
n
'
)):
# if block open is followed by newline, then skip past newline
mo
=
eol
.
match
(
text
,
start
)
if
mo
is
not
None
:
if
mo
is
not
None
:
start
=
start
+
mo
.
end
(
0
)
-
mo
.
start
(
0
)
return
start
...
...
@@ -210,7 +210,7 @@ class String:
try
:
tag
,
args
,
command
,
coname
=
self
.
_parseTag
(
mo
,
scommand
,
sa
)
except
ParseError
,
m
:
self
.
parse_error
(
m
[
0
],
m
[
1
],
text
,
l
)
if
command
:
start
=
l
+
len
(
tag
)
if
hasattr
(
command
,
'blockContinuations'
):
...
...
@@ -223,7 +223,7 @@ class String:
section
.
_v_blocks
=
section
.
blocks
=
self
.
parse
(
text
[:
l
],
sstart
)
section
.
_v_cooked
=
None
blocks
.
append
((
tname
,
sargs
,
section
))
start
=
self
.
skip_eol
(
text
,
l
+
len
(
tag
))
if
coname
:
...
...
@@ -315,7 +315,7 @@ class String:
"""
if
mapping
is
not
None
or
vars
:
self
.
initvars
(
mapping
,
vars
)
if
source_string
is
not
None
:
if
source_string
is
not
None
:
self
.
raw
=
source_string
self
.
cook
()
...
...
@@ -371,13 +371,13 @@ class String:
containing values to be looked up. Values will be looked up
using getattr, so inheritence of values is supported. Note
that names beginning with '_' will not be looked up from the
client.
client.
The optional argument, 'mapping' is used to specify a mapping
object containing values to be inserted.
Values to be inserted may also be specified using keyword
arguments.
arguments.
Values will be inserted from one of several sources. The
sources, in the order in which they are consulted, are:
...
...
@@ -392,7 +392,7 @@ class String:
created, and
o The 'mapping' argument provided when the template was
created.
created.
'''
# print '============================================================'
...
...
@@ -459,8 +459,8 @@ class String:
# otherwise its just a normal client object.
push
(
InstanceDict
(
client
,
md
))
# Circ. Ref. 8-|
pushed
=
pushed
+
1
if
self
.
_vars
:
if
self
.
_vars
:
push
(
self
.
_vars
)
pushed
=
pushed
+
1
...
...
@@ -498,7 +498,7 @@ class String:
class
FileMixin
:
# Mix-in class to abstract certain file-related attributes
edited_source
=
''
def
__init__
(
self
,
file_name
=
''
,
mapping
=
None
,
__name__
=
''
,
**
vars
):
"""
\
Create a document template based on a named file.
...
...
@@ -515,7 +515,7 @@ class FileMixin:
if
self
.
edited_source
:
return
self
.
edited_source
if
not
os
.
path
.
exists
(
self
.
raw
):
print
'file not found: %s'
%
self
.
raw
if
self
.
raw
:
return
open
(
self
.
raw
,
'r'
).
read
()
return
''
...
...
lib/python/DocumentTemplate/DT_Try.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
sys
,
traceback
...
...
@@ -19,41 +19,41 @@ from DT_Return import DTReturn
class
Try
:
"""Zope DTML Exception handling
usage:
<!--#try-->
<!--#except SomeError AnotherError-->
<!--#except YetAnotherError-->
<!--#except-->
<!--#else-->
<!--#/try-->
or:
<!--#try-->
<!--#finally-->
<!--#/try-->
The DTML try tag functions quite like Python's try command.
The contents of the try tag are rendered. If an exception is raised,
then control switches to the except blocks. The first except block to
match the type of the error raised is rendered. If an except block has
no name then it matches all raised errors.
The try tag understands class-based exceptions, as well as string-based
exceptions. Note: the 'raise' tag raises string-based exceptions.
Inside the except blocks information about the error is available via
three variables.
'error_type' -- This variable is the name of the exception caught.
'error_value' -- This is the caught exception's value.
'error_tb' -- This is a traceback for the caught exception.
The optional else block is rendered when no exception occurs in the
try block. Exceptions in the else block are not handled by the preceding
except blocks.
...
...
@@ -78,10 +78,10 @@ class Try:
lost.
Original version by Jordan B. Baker.
Try..finally and try..else implementation by Martijn Pieters.
"""
name
=
'try'
blockContinuations
=
'except'
,
'else'
,
'finally'
finallyBlock
=
None
...
...
@@ -158,7 +158,7 @@ class Try:
errname
=
t
.
__name__
handler
=
self
.
find_handler
(
t
)
if
handler
is
None
:
# we didn't find a handler, so reraise the error
raise
...
...
@@ -181,7 +181,7 @@ class Try:
return
result
else
:
return
result
+
render_blocks
(
self
.
elseBlock
,
md
)
def
render_try_finally
(
self
,
md
):
result
=
''
# first try to render the first block
...
...
@@ -202,13 +202,13 @@ class Try:
return
None
for
e
,
h
in
self
.
handlers
:
if
e
==
exception
.
__name__
or
e
==
''
or
self
.
match_base
(
exception
,
e
):
return
h
return
None
return
h
return
None
def
match_base
(
self
,
exception
,
name
):
for
base
in
exception
.
__bases__
:
if
base
.
__name__
==
name
or
self
.
match_base
(
base
,
name
):
return
1
return
None
__call__
=
render
lib/python/DocumentTemplate/DT_UI.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Machinery to support through-the-web editing
$Id: DT_UI.py,v 1.1
1 2001/11/28 15:50:55 matt Exp $'''
__version__
=
'$Revision: 1.1
1
$'
[
11
:
-
2
]
$Id: DT_UI.py,v 1.1
2 2002/08/14 22:29:52 mj Exp $'''
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
from
DT_HTML
import
HTML
...
...
@@ -35,13 +35,13 @@ HTML._manage_editForm = HTML(
</HEAD>
<BODY bgcolor="#FFFFFF">
<!--#var document_template_edit_header-->
<FORM name="editform" ACTION="<!--#var URL1-->/manage_edit" METHOD="POST">
<!--#var document_template_form_header-->
Document template source:
<center>
<br>
<TEXTAREA NAME="data:text" cols="<!--#var document_template_edit_width-->"
<TEXTAREA NAME="data:text" cols="<!--#var document_template_edit_width-->"
rows="20"><!--#var __str__--></TEXTAREA>
<br>
...
...
@@ -50,12 +50,12 @@ HTML._manage_editForm = HTML(
<INPUT NAME="dt_edit_name" TYPE="HIDDEN"
VALUE="<!--#var URL1-->">
<!--#if FactoryDefaultString-->
<INPUT NAME=SUBMIT TYPE="SUBMIT"
<INPUT NAME=SUBMIT TYPE="SUBMIT"
VALUE="<!--#var FactoryDefaultString-->">
<!--#/if FactoryDefaultString-->
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancel">
<!--#if HTTP_REFERER-->
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var HTTP_REFERER-->">
<!--#else HTTP_REFERER-->
<!--#if URL1-->
...
...
@@ -65,10 +65,10 @@ HTML._manage_editForm = HTML(
<!--#/if HTTP_REFERER-->
</center>
</FORM>
<BR CLEAR="ALL">
<!--#var document_template_edit_footer-->
</BODY>
</HTML>"""
,)
...
...
lib/python/DocumentTemplate/DT_Util.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''$Id: DT_Util.py,v 1.8
7 2002/08/01 16:00:39 mj Exp $'''
__version__
=
'$Revision: 1.8
7
$'
[
11
:
-
2
]
'''$Id: DT_Util.py,v 1.8
8 2002/08/14 22:29:52 mj Exp $'''
__version__
=
'$Revision: 1.8
8
$'
[
11
:
-
2
]
import
re
,
os
from
html_quote
import
html_quote
,
ustr
# for import by other modules, dont remove!
...
...
@@ -234,7 +234,7 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
# # Fix up something like: <!--#in expr="whatever" mapping-->
# params[params['']]=default_unnamed
# del params['']
if
used
(
''
):
v
=
params
[
''
]
...
...
@@ -257,7 +257,7 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
'that doesn
\
'
t support expr attributes.'
,
tag
)
else
:
# name shorthand
else
:
# name shorthand
if
used
(
attr
):
raise
ParseError
,
(
'Two %s values were given'
%
attr
,
tag
)
if
expr
:
...
...
@@ -277,7 +277,7 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
name
=
params
[
'expr'
]
expr
=
Eval
(
name
)
return
name
,
expr
raise
ParseError
,
(
'No %s given'
%
attr
,
tag
)
Expr_doc
=
"""
...
...
@@ -308,20 +308,20 @@ Python expression support
mapping object. This variable can be useful for accessing objects
in a document template namespace that have names that are not legal
Python variable names::
<!--#var expr="_['sequence-number']*5"-->
This variable also has attributes that provide access to standard
utility objects. These attributes include:
- The objects: 'None', 'abs', 'chr', 'divmod', 'float', 'hash',
'hex', 'int', 'len', 'max', 'min', 'oct', 'ord', 'pow',
'round', and 'str' from the standard Python builtin module.
- Special security-aware versions of 'getattr' and 'hasattr',
- The Python 'string', 'math', and 'whrandom' modules, and
- A special function, 'test', that supports if-then expressions.
The 'test' function accepts any number of arguments. If the
first argument is true, then the second argument is returned,
...
...
@@ -329,10 +329,10 @@ Python expression support
argument is returned, and so on. If there is an odd number of
arguments, then the last argument is returned in the case that
none of the tested arguments is true, otherwise None is
returned.
returned.
For example, to convert a value to lower case::
<!--#var expr="_.string.lower(title)"-->
"""
...
...
@@ -370,7 +370,7 @@ def parse_params(text,
result
=
result
or
{}
# HACK - we precalculate all matches. Maybe we don't need them
# HACK - we precalculate all matches. Maybe we don't need them
# all. This should be fixed for performance issues
mo_p
=
parmre
.
match
(
text
)
...
...
@@ -393,7 +393,7 @@ def parse_params(text,
if
parms
.
has_key
(
name
):
if
parms
[
name
]
is
None
:
raise
ParseError
,
(
'Attribute %s requires a value'
%
name
,
tag
)
result
[
name
]
=
parms
[
name
]
else
:
raise
ParseError
,
(
'Invalid attribute name, "%s"'
%
name
,
tag
)
...
...
@@ -410,7 +410,7 @@ def parse_params(text,
else
:
if
not
text
or
not
text
.
strip
():
return
result
raise
ParseError
,
(
'invalid parameter: "%s"'
%
text
,
tag
)
if
not
parms
.
has_key
(
name
):
raise
ParseError
,
(
'Invalid attribute name, "%s"'
%
name
,
tag
)
...
...
@@ -420,7 +420,7 @@ def parse_params(text,
if
type
(
p
)
is
not
ListType
or
p
:
raise
ParseError
,
(
'Duplicate values for attribute "%s"'
%
name
,
tag
)
result
[
name
]
=
value
text
=
text
[
l
:].
strip
()
...
...
lib/python/DocumentTemplate/DT_Var.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Variable insertion parameters
...
...
@@ -58,7 +58,7 @@ __doc__='''Variable insertion parameters
- Cannot be formatted with the specified format, and
- Are either the special Python value 'None' or
- Are either the special Python value 'None' or
are false and yield an empty string when converted to
a string.
...
...
@@ -89,12 +89,12 @@ __doc__='''Variable insertion parameters
value after formatting has been applied. These parameters
are supplied without arguments.
'lower' -- cause all upper-case letters to be converted to lower case.
'lower' -- cause all upper-case letters to be converted to lower case.
'upper' -- cause all upper-case letters to be converted to lower case.
'upper' -- cause all upper-case letters to be converted to lower case.
'capitalize' -- cause the first character of the inserted value
to be converted to upper case.
to be converted to upper case.
'spacify' -- cause underscores in the inserted value to be
converted to spaces.
...
...
@@ -140,7 +140,7 @@ __doc__='''Variable insertion parameters
truncation, the value given for the 'etc' attribute is added to
the string. If the 'etc' attribute is not provided, then '...'
is used. For example, if the value of spam is
'"blah blah blah blah"', then the tag
'"blah blah blah blah"', then the tag
'<dtml-var spam size=10>' inserts '"blah blah ..."'.
...
...
@@ -148,11 +148,11 @@ Evaluating expressions without rendering results
A 'call' tag is provided for evaluating named objects or expressions
without rendering the result.
'''
# '
__rcs_id__
=
'$Id: DT_Var.py,v 1.5
6 2002/08/14 16:34:20 rdmurray
Exp $'
__version__
=
'$Revision: 1.5
6
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_Var.py,v 1.5
7 2002/08/14 22:29:52 mj
Exp $'
__version__
=
'$Revision: 1.5
7
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
str
,
ustr
import
os
,
string
,
re
,
sys
...
...
@@ -163,7 +163,7 @@ from types import StringType
from
Acquisition
import
aq_base
from
ZPublisher.TaintedString
import
TaintedString
class
Var
:
class
Var
:
name
=
'var'
expr
=
None
...
...
@@ -177,7 +177,7 @@ class Var:
url_unquote_plus
=
1
,
missing
=
''
,
newline_to_br
=
1
,
url
=
1
)
self
.
args
=
args
self
.
modifiers
=
tuple
(
map
(
lambda
t
:
t
[
1
],
filter
(
lambda
m
,
args
=
args
,
used
=
args
.
has_key
:
...
...
@@ -226,7 +226,7 @@ class Var:
if
have_arg
(
'null'
)
and
not
val
and
val
!=
0
:
# check for null (false but not zero, including None, [], '')
return
args
[
'null'
]
# handle special formats defined using fmt= first
if
have_arg
(
'fmt'
):
...
...
@@ -248,7 +248,7 @@ class Var:
else
:
val
=
special_formats
[
fmt
](
val
,
name
,
md
)
elif
fmt
==
''
:
val
=
''
else
:
else
:
if
isinstance
(
val
,
TaintedString
):
val
=
TaintedString
(
fmt
%
val
)
else
:
...
...
@@ -317,12 +317,12 @@ class Var:
if
isinstance
(
val
,
TaintedString
):
val
=
val
.
quoted
()
return
val
__call__
=
render
class
Call
:
class
Call
:
name
=
'call'
expr
=
None
...
...
@@ -379,7 +379,7 @@ def thousands_commas(v, name='(Unknown name)', md={},
v
=
v
[:
l
+
1
]
+
','
+
v
[
l
+
1
:]
mo
=
thou
(
v
)
return
v
+
s
def
whole_dollars_with_commas
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
try
:
v
=
"$%d"
%
v
except
:
v
=
''
...
...
@@ -399,7 +399,7 @@ def len_comma(v, name='(Unknown name)', md={}):
StructuredText
=
None
def
structured_text
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
global
StructuredText
if
StructuredText
is
None
:
if
StructuredText
is
None
:
from
StructuredText.StructuredText
import
HTML
if
isinstance
(
v
,
StringType
):
txt
=
v
...
...
@@ -408,11 +408,11 @@ def structured_text(v, name='(Unknown name)', md={}):
txt
=
aq_base
(
v
).
read_raw
()
else
:
txt
=
str
(
v
)
return
HTML
(
txt
,
return
HTML
(
txt
,
level
=
int
(
os
.
environ
.
get
(
'STX_DEFAULT_LEVEL'
,
3
)),
header
=
0
)
def
sql_quote
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
"""Quote single quotes in a string by doubling them.
...
...
@@ -457,15 +457,15 @@ class Comment:
The 'comment' tag can be used to simply include comments
in DTML source.
For example::
<!--#comment-->
This text is not rendered.
<!--#/comment-->
'''
'''
name
=
'comment'
blockContinuations
=
()
...
...
lib/python/DocumentTemplate/DT_With.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''Nested namespace access
...
...
@@ -31,10 +31,10 @@
should be treated as mapping object, rather than as an object with
named attributes.
'''
'''
__rcs_id__
=
'$Id: DT_With.py,v 1.1
4 2001/11/28 15:50:55 matt
Exp $'
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_With.py,v 1.1
5 2002/08/14 22:29:52 mj
Exp $'
__version__
=
'$Revision: 1.1
5
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
InstanceDict
,
render_blocks
,
str
from
DT_Util
import
TemplateDict
...
...
@@ -43,7 +43,7 @@ class With:
name
=
'with'
mapping
=
None
only
=
0
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
,
mapping
=
1
,
only
=
1
)
...
...
lib/python/DocumentTemplate/DTtestExpr.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''short description
$Id: DTtestExpr.py,v 1.
7 2001/11/28 15:50:55 matt
Exp $'''
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
$Id: DTtestExpr.py,v 1.
8 2002/08/14 22:29:52 mj
Exp $'''
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
from
DocumentTemplate
import
*
import
sys
...
...
@@ -47,7 +47,7 @@ def test4():
print
'-'
*
77
print
i
,
h
(
level
=
i
)
print
'-'
*
77
if
__name__
==
"__main__"
:
try
:
command
=
sys
.
argv
[
1
]
...
...
lib/python/DocumentTemplate/DocumentTemplate.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''Document templates with fill-in fields
...
...
@@ -60,7 +60,7 @@ Two source formats are supported:
<!--#var total fmt=12.2f-->
is used to insert the variable 'total' with the C format
'12.2f'.
'12.2f'.
Document templates support conditional and sequence insertion
...
...
@@ -105,7 +105,7 @@ Document Templates may be created 4 ways:
'''
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
ParseError
=
'Document Template Parse Error'
...
...
lib/python/DocumentTemplate/VSEval.py
View file @
2639fcb7
...
...
@@ -7,4 +7,3 @@ def careful_mul(env, *factors):
for
factor
in
factors
:
r
=
r
*
factor
return
r
lib/python/DocumentTemplate/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Package wrapper for Document Template
This wrapper allows the (now many) document template modules to be
segregated in a separate package.
$Id: __init__.py,v 1.1
6 2001/11/28 15:50:55 matt
Exp $'''
__version__
=
'$Revision: 1.1
6
$'
[
11
:
-
2
]
$Id: __init__.py,v 1.1
7 2002/08/14 22:29:53 mj
Exp $'''
__version__
=
'$Revision: 1.1
7
$'
[
11
:
-
2
]
import
ExtensionClass
# work-around for import bug.
from
DocumentTemplate
import
String
,
File
,
HTML
,
HTMLDefault
,
HTMLFile
lib/python/DocumentTemplate/html_quote.py
View file @
2639fcb7
...
...
@@ -5,4 +5,3 @@ from ustr import ustr
def
html_quote
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
return
escape
(
ustr
(
v
),
1
)
lib/python/DocumentTemplate/pDocumentTemplate.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Python implementations of document template some features
$Id: pDocumentTemplate.py,v 1.3
5 2002/03/27 10:14:02 htrd
Exp $'''
__version__
=
'$Revision: 1.3
5
$'
[
11
:
-
2
]
$Id: pDocumentTemplate.py,v 1.3
6 2002/08/14 22:29:53 mj
Exp $'''
__version__
=
'$Revision: 1.3
6
$'
[
11
:
-
2
]
import
sys
,
types
...
...
@@ -69,7 +69,7 @@ class InstanceDict:
cache
=
self
.
cache
if
cache
.
has_key
(
key
):
return
cache
[
key
]
inst
=
self
.
self
if
key
[:
1
]
==
'_'
:
...
...
@@ -115,14 +115,14 @@ class MultiMapping:
return
kz
class
DictInstance
:
def
__init__
(
self
,
mapping
):
self
.
__d
=
mapping
def
__getattr__
(
self
,
name
):
try
:
return
self
.
__d
[
name
]
except
KeyError
:
raise
AttributeError
,
name
class
TemplateDict
:
level
=
0
...
...
@@ -152,10 +152,10 @@ class TemplateDict:
return
v
def
__len__
(
self
):
total
=
0
for
d
in
self
.
dicts
.
dicts
:
total
=
total
+
len
(
d
)
return
total
total
=
0
for
d
in
self
.
dicts
.
dicts
:
total
=
total
+
len
(
d
)
return
total
def
has_key
(
self
,
key
):
try
:
...
...
@@ -163,7 +163,7 @@ class TemplateDict:
except
KeyError
:
return
0
return
1
getitem
=
__getitem__
def
__call__
(
self
,
*
args
,
**
kw
):
...
...
lib/python/DocumentTemplate/sequence/SortEx.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Advanced sort support by Oleg Broytmann <phd@@phd.pp.ru> 23 Apr 2001
eg Sort(sequence, (("akey", "nocase"), ("anotherkey", "cmp", "desc")))
$Id: SortEx.py,v 1.
4 2002/02/07 17:47:42 andreasjung
Exp $
$Id: SortEx.py,v 1.
5 2002/08/14 22:29:53 mj
Exp $
"""
...
...
@@ -36,19 +36,19 @@ def sort(sequence, sort=(), _=None, mapping=0):
allowed values:
- "cmp" -- the standard comparison function (default)
- "nocase" -- case-insensitive comparison
- "strcoll" or "locale" -- locale-aware string comparison
- "strcoll_nocase" or "locale_nocase" -- locale-aware case-insensitive
string comparison
- "xxx" -- a user-defined comparison function
- direction -- defines the sort direction for the key (optional).
(allowed values: "asc" (default) , "desc")
"""
"""
...
...
@@ -60,7 +60,7 @@ def sort(sequence, sort=(), _=None, mapping=0):
need_sortfunc
=
1
break
sortfields
=
sort
# multi sort = key1,key2
sortfields
=
sort
# multi sort = key1,key2
multsort
=
len
(
sortfields
)
>
1
# flag: is multiple sort
if
need_sortfunc
:
...
...
@@ -92,25 +92,25 @@ def sort(sequence, sort=(), _=None, mapping=0):
v
=
client
if
sort
:
if
multsort
:
# More than one sort key.
k
=
[]
for
sk
in
sortfields
:
try
:
if
mapping
:
akey
=
v
[
sk
]
else
:
akey
=
getattr
(
v
,
sk
)
except
AttributeError
,
KeyError
:
akey
=
None
if
not
basic_type
(
akey
):
try
:
akey
=
akey
()
except
:
pass
k
.
append
(
akey
)
else
:
# One sort key.
try
:
if
mapping
:
k
=
v
[
sort
]
else
:
k
=
getattr
(
v
,
sort
)
except
AttributeError
,
KeyError
:
k
=
None
if
not
basic_type
(
type
(
k
)):
try
:
k
=
k
()
except
:
pass
if
multsort
:
# More than one sort key.
k
=
[]
for
sk
in
sortfields
:
try
:
if
mapping
:
akey
=
v
[
sk
]
else
:
akey
=
getattr
(
v
,
sk
)
except
AttributeError
,
KeyError
:
akey
=
None
if
not
basic_type
(
akey
):
try
:
akey
=
akey
()
except
:
pass
k
.
append
(
akey
)
else
:
# One sort key.
try
:
if
mapping
:
k
=
v
[
sort
]
else
:
k
=
getattr
(
v
,
sort
)
except
AttributeError
,
KeyError
:
k
=
None
if
not
basic_type
(
type
(
k
)):
try
:
k
=
k
()
except
:
pass
s
.
append
((
k
,
client
))
...
...
@@ -122,7 +122,7 @@ def sort(sequence, sort=(), _=None, mapping=0):
sequence
=
[]
for
k
,
client
in
s
:
sequence
.
append
(
client
)
sequence
.
append
(
client
)
return
sequence
...
...
@@ -219,5 +219,3 @@ class SortBy:
# all functions returned 0 - identical sequences
return
0
lib/python/DocumentTemplate/sequence/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
...
...
lib/python/DocumentTemplate/sequence/tests/testSequence.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
os
,
sys
,
unittest
...
...
@@ -30,7 +30,7 @@ class TestCase( unittest.TestCase ):
def
tearDown
(
self
):
"""
"""
def
test1
(
self
):
"test1"
assert
res1
==
SortEx
(
wordlist
)
...
...
@@ -42,7 +42,7 @@ class TestCase( unittest.TestCase ):
def
test3
(
self
):
"test3"
assert
res3
==
SortEx
(
wordlist
,
((
"key"
,
"cmp"
),),
mapping
=
1
)
def
test4
(
self
):
"test4"
assert
res4
==
SortEx
(
wordlist
,
((
"key"
,
"cmp"
,
"desc"
),),
mapping
=
1
)
...
...
@@ -60,7 +60,7 @@ class TestCase( unittest.TestCase ):
"test7"
def
myCmp
(
s1
,
s2
):
return
-
cmp
(
s1
,
s2
)
return
-
cmp
(
s1
,
s2
)
# Create namespace...
from
DocumentTemplate.DT_Util
import
TemplateDict
...
...
lib/python/DocumentTemplate/sequence/tests/ztestlib.py
View file @
2639fcb7
class
standard_html
:
# Base class for using with ZTemplates
def
__init__
(
self
,
title
):
self
.
standard_html_header
=
"""<HTML>
def
__init__
(
self
,
title
):
self
.
standard_html_header
=
"""<HTML>
<HEAD>
<TITLE>
%s
...
...
@@ -11,25 +9,25 @@ class standard_html: # Base class for using with ZTemplates
<BODY>"""
%
title
self
.
standard_html_footer
=
"""</BODY>
self
.
standard_html_footer
=
"""</BODY>
</HTML>"""
self
.
title
=
title
self
.
title
=
title
def
test
(
s
):
outfile
=
open
(
"test.out"
,
'w'
)
outfile
.
write
(
s
)
outfile
.
close
()
outfile
=
open
(
"test.out"
,
'w'
)
outfile
.
write
(
s
)
outfile
.
close
()
def
exception
():
import
sys
,
traceback
exc_type
,
exc_value
,
exc_tb
=
sys
.
exc_info
()
import
sys
,
traceback
exc_type
,
exc_value
,
exc_tb
=
sys
.
exc_info
()
outfile
=
open
(
"test.err"
,
'w'
)
traceback
.
print_exception
(
exc_type
,
exc_value
,
exc_tb
,
None
,
outfile
)
outfile
.
close
()
outfile
=
open
(
"test.err"
,
'w'
)
traceback
.
print_exception
(
exc_type
,
exc_value
,
exc_tb
,
None
,
outfile
)
outfile
.
close
()
wordlist
=
[
...
...
lib/python/DocumentTemplate/tests/testDTML.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Document Template Tests
"""
__rcs_id__
=
'$Id: testDTML.py,v 1.1
3 2002/08/14 15:46:58 chrism
Exp $'
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: testDTML.py,v 1.1
4 2002/08/14 22:29:53 mj
Exp $'
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
import
sys
,
os
import
unittest
...
...
@@ -259,7 +259,7 @@ class DTMLTests (unittest.TestCase):
<dtml-var expr="'http%3A%2F%2Fwww.zope.org%3Fa%3Db+123'" fmt=url-unquote-plus>
"""
)
expected
=
(
"""
http://www.zope.org?a=b 123
...
...
@@ -277,7 +277,7 @@ class DTMLTests (unittest.TestCase):
<dtml-var expr="'http%3A%2F%2Fwww.zope.org%3Fa%3Db+123'" url_unquote_plus>
"""
)
expected
=
(
"""
http://www.zope.org?a=b 123
...
...
@@ -285,7 +285,7 @@ class DTMLTests (unittest.TestCase):
)
self
.
assertEqual
(
html1
(),
expected
)
self
.
assertEqual
(
html2
(),
expected
)
def
test_fmt
(
self
):
html
=
self
.
doc_class
(
...
...
@@ -499,7 +499,7 @@ foo bar
"""
result
=
self
.
doc_class
(
html
)(
xxx
=
xxx
,
data
=
{})
assert
result
==
expected
,
result
def
testBasicStringIn
(
self
):
data
=
(
d
(
name
=
'jim'
,
age
=
39
),
...
...
@@ -522,7 +522,7 @@ foo bar
"""
result
=
String
(
s
)(
data
=
data
)
assert
expected
==
result
,
result
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
DTMLTests
)
)
...
...
lib/python/DocumentTemplate/tests/testDTMLUnicode.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Document Template Tests
"""
__rcs_id__
=
'$Id: testDTMLUnicode.py,v 1.
2 2002/03/27 10:14:02 htrd
Exp $'
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: testDTMLUnicode.py,v 1.
3 2002/08/14 22:29:53 mj
Exp $'
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
import
sys
,
os
import
unittest
...
...
lib/python/DocumentTemplate/tests/testustr.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Document Template Tests
"""
__rcs_id__
=
'$Id: testustr.py,v 1.
2 2002/03/27 10:14:02 htrd
Exp $'
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: testustr.py,v 1.
3 2002/08/14 22:29:53 mj
Exp $'
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
import
sys
,
os
import
unittest
...
...
lib/python/Products/PythonScripts/Extensions/RemotePS.py
View file @
2639fcb7
...
...
@@ -8,7 +8,7 @@
foobarsize = s.foo.bar.restricted_exec('len(context.objectIds())')
'''
from
Products.PythonScripts.PythonScript
import
PythonScript
from
string
import
join
...
...
lib/python/Products/PythonScripts/PythonScript.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Python Scripts Product
...
...
@@ -17,7 +17,7 @@ This product provides support for Script objects containing restricted
Python code.
"""
__version__
=
'$Revision: 1.4
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.4
3
$'
[
11
:
-
2
]
import
sys
,
os
,
traceback
,
re
,
marshal
from
Globals
import
DTMLFile
,
MessageDialog
,
package_home
...
...
@@ -153,11 +153,11 @@ class PythonScript(Script, Historical, Cacheable):
"""Replace the body of the script with the text in file."""
if
self
.
wl_isLocked
():
raise
ResourceLockedError
,
"The script is locked via WebDAV."
if
type
(
file
)
is
not
type
(
''
):
if
type
(
file
)
is
not
type
(
''
):
if
not
file
:
raise
ValueError
,
'File not specified'
file
=
file
.
read
()
self
.
write
(
file
)
message
=
'Saved changes.'
return
self
.
ZPythonScriptHTML_editForm
(
self
,
REQUEST
,
...
...
@@ -183,7 +183,7 @@ class PythonScript(Script, Historical, Cacheable):
"""Parameters to test the script with."""
param_names
=
[]
for
name
in
self
.
_params
.
split
(
','
):
name
=
name
.
strip
()
if
name
and
name
[
0
]
!=
'*'
and
re
.
match
(
'
\
w
'
,name):
param_names.append(name.split('
=
', 1)[0])
...
...
@@ -201,7 +201,7 @@ class PythonScript(Script, Historical, Cacheable):
getattr(self, '
Script_magic
', None) != Script_magic):
global _log_complaint
if _log_complaint:
LOG(self.meta_type, INFO, _log_complaint)
LOG(self.meta_type, INFO, _log_complaint)
_log_complaint = 0
# Changes here won'
t
get
saved
,
unless
this
Script
is
edited
.
body
=
self
.
_body
.
rstrip
()
...
...
@@ -329,7 +329,7 @@ class PythonScript(Script, Historical, Cacheable):
if
user
is
not
None
and
user
.
allowed
(
self
,
roles
):
return
raise
'Forbidden'
,
(
'You are not authorized to change <em>%s</em> '
'because you do not have proxy roles.
\
n
<!--%s, %s-->'
'because you do not have proxy roles.
\
n
<!--%s, %s-->'
%
(
self
.
id
,
user
,
roles
))
security
.
declareProtected
(
'Change proxy roles'
,
...
...
@@ -358,7 +358,7 @@ class PythonScript(Script, Historical, Cacheable):
self
.
dav__simpleifhandler
(
REQUEST
,
RESPONSE
,
refresh
=
1
)
self
.
write
(
REQUEST
.
get
(
'BODY'
,
''
))
RESPONSE
.
setStatus
(
204
)
return
RESPONSE
return
RESPONSE
manage_FTPput
=
PUT
...
...
@@ -449,7 +449,7 @@ class PythonScript(Script, Historical, Cacheable):
hlines
=
[
'%s %s "%s"'
%
(
prefix
,
self
.
meta_type
,
self
.
id
)]
mm
=
self
.
_metadata_map
().
items
()
mm
.
sort
()
for
kv
in
mm
:
for
kv
in
mm
:
hlines
.
append
(
'%s=%s'
%
kv
)
if
self
.
errors
:
hlines
.
append
(
''
)
...
...
lib/python/Products/PythonScripts/Utility.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Utility module for making simple security assertions for
Python scripts."""
__version__
=
'$Revision: 1.
5
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
# These have been relocated, and should be imported from AccessControl
...
...
lib/python/Products/PythonScripts/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Python Scripts Product Initialization
$Id: __init__.py,v 1.1
2 2002/06/20 14:48:38 Brian
Exp $'''
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
$Id: __init__.py,v 1.1
3 2002/08/14 22:25:08 mj
Exp $'''
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
import
PythonScript
try
:
...
...
@@ -43,7 +43,7 @@ def initialize(context):
global
_m
_m
[
'recompile'
]
=
recompile
_m
[
'recompile__roles__'
]
=
(
'Manager'
,)
# utility stuff
def
recompile
(
self
):
...
...
lib/python/Products/PythonScripts/help/PythonScript.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
def
manage_addPythonScript
(
id
,
REQUEST
=
None
):
...
...
@@ -136,7 +136,7 @@ class PythonScript:
__extends__
=
(
'PythonScripts.Script.Script'
,
)
def
ZPythonScriptHTML_editAction
(
REQUEST
,
title
,
params
,
body
):
"""
...
...
@@ -230,8 +230,3 @@ class PythonScript:
'text/plain' set on the RESPONSE.
"""
lib/python/Products/PythonScripts/help/Script.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
class
Script
:
...
...
lib/python/Products/PythonScripts/help/standard.py
View file @
2639fcb7
...
...
@@ -3,7 +3,7 @@ Products.PythonScripts.standard: Utility functions and classes
The functions and classes in this module are available from
Python-based scripts, DTML, and Page Templates.
"""
def
whole_dollars
(
number
):
...
...
@@ -23,7 +23,7 @@ def structured_text(s):
See Also
"Structured-Text Rules":http://dev.zope.org/Members/jim/StructuredTextWiki/StructuredTextNGRules
"""
def
sql_quote
(
s
):
...
...
@@ -41,7 +41,7 @@ def html_quote(s):
"Python 'cgi' module":http://www.python.org/doc/current/lib/Functions_in_cgi_module.html
'escape' function.
"""
def
url_quote
(
s
):
...
...
@@ -123,7 +123,7 @@ class DTML:
def
call
(
client
=
None
,
REQUEST
=
{},
**
kw
):
"""
Render the DTML.
To accomplish its task, DTML often needs to resolve various
names into objects. For example, when the code <dtml-var
spam> is executed, the DTML engine tries to resolve the
...
...
@@ -148,5 +148,5 @@ class DTML:
three methods. You can pass any number of them or none at
all. Names will be looked up first in the keyword argument,
next in the client and finally in the mapping.
"""
lib/python/Products/PythonScripts/module_access_examples.py
View file @
2639fcb7
...
...
@@ -65,8 +65,3 @@ from Globals import InitializeClass
# 'error_reply', 'error_temp', 'error_perm', 'error_proto')
# from httplib import NNTP
# allow_class(NNTP)
lib/python/Products/PythonScripts/standard.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""Python Scripts standard utility module
...
...
@@ -18,7 +18,7 @@ Scripts. It can be accessed from Python with the statement
"import Products.PythonScripts.standard"
"""
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
9
$'
[
11
:
-
2
]
from
AccessControl
import
ModuleSecurityInfo
,
getSecurityManager
security
=
ModuleSecurityInfo
()
...
...
@@ -53,4 +53,3 @@ class DTML(RestrictedDTML, HTML):
finally
:
security
.
removeContext
(
self
)
security
.
apply
(
globals
())
lib/python/Products/PythonScripts/tests/testPythonScript.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
os
,
sys
,
unittest
...
...
@@ -74,9 +74,9 @@ class TestPythonScriptNoAq(unittest.TestCase):
assert
txt
==
'txt'
,
txt
def
testParam2
(
self
):
one
,
two
=
self
.
_newPS
(
'##parameters=x,y
\
n
return x,y'
)(
'one'
,
'two'
)
assert
one
==
'one'
assert
two
==
'two'
one
,
two
=
self
.
_newPS
(
'##parameters=x,y
\
n
return x,y'
)(
'one'
,
'two'
)
assert
one
==
'one'
assert
two
==
'two'
def
testParam26
(
self
):
import
string
...
...
@@ -85,7 +85,7 @@ class TestPythonScriptNoAq(unittest.TestCase):
tup
=
apply
(
self
.
_newPS
(
'##parameters=%s
\
n
return %s'
%
(
sparams
,
sparams
)),
params
)
assert
tup
==
tuple
(
params
),
(
tup
,
params
)
def
testArithmetic
(
self
):
one
=
self
.
_newPS
(
'return 1 * 5 + 4 / 2 - 6'
)()
assert
one
==
1
,
one
...
...
@@ -103,7 +103,7 @@ class TestPythonScriptNoAq(unittest.TestCase):
def
testForLoop
(
self
):
ten
=
self
.
_newPS
(
readf
(
'for_loop'
))()
assert
ten
==
10
def
testMutateLiterals
(
self
):
l
,
d
=
self
.
_newPS
(
readf
(
'mutate_literals'
))()
assert
l
==
[
2
],
l
...
...
@@ -122,7 +122,7 @@ class TestPythonScriptNoAq(unittest.TestCase):
a
,
b
=
self
.
_newPS
(
readf
(
'try_except'
))()
assert
a
==
1
assert
b
==
1
def
testBigBoolean
(
self
):
true
=
self
.
_newPS
(
readf
(
'big_boolean'
))()
assert
true
,
true
...
...
@@ -166,4 +166,3 @@ def main():
if
__name__
==
'__main__'
:
main
()
lib/python/Products/Sessions/BrowserIdManager.py
View file @
2639fcb7
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -11,7 +11,7 @@
#
############################################################################
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
import
Globals
from
Persistence
import
Persistent
from
ZODB
import
TimeStamp
...
...
@@ -53,9 +53,9 @@ def constructBrowserIdManager(
ob = self._getOb(id)
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
class BrowserIdManagerErr(Exception): pass
class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
""" browser id management class """
...
...
@@ -99,7 +99,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
not create a browser id for the current request if one doesn'
t
already
exist
"""
if self.getBrowserId(create=0): return 1
security.declareProtected(ACCESS_CONTENTS_PERM, 'getBrowserId')
def getBrowserId(self, create=1):
"""
...
...
@@ -120,7 +120,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
# somebody screwed with the REQUEST instance during
# this request.
raise BrowserIdManagerErr, (
'Ill-formed browserid in REQUEST.browser_id_: %s' %
'Ill-formed browserid in REQUEST.browser_id_: %s' %
escape(bid)
)
return bid
...
...
@@ -194,7 +194,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
# ns will be None if new, negating None below returns 1, which
# would indicate that it'
s
new
on
this
request
return
not
getattr
(
self
.
REQUEST
,
'browser_id_ns_'
)
security
.
declareProtected
(
ACCESS_CONTENTS_PERM
,
'encodeUrl'
)
def
encodeUrl
(
self
,
url
,
create
=
1
):
"""
...
...
@@ -313,7 +313,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
if
not
(
type
(
path
)
is
type
(
''
)
and
not
badcookiecharsin
(
path
)):
raise
BrowserIdManagerErr
,
'Bad cookie path %s'
%
escape
(
repr
(
path
))
self
.
cookie_path
=
path
security
.
declareProtected
(
ACCESS_CONTENTS_PERM
,
'getCookiePath'
)
def
getCookiePath
(
self
):
""" """
...
...
@@ -397,7 +397,7 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
A == leading-0-padded 8-char string-rep'd random integer
B == modified base64-encoded 11-char timestamp
To be URL-compatible, base64 encoding is modified as follows:
'=' end-padding is stripped off
'+' is translated to '-'
...
...
@@ -428,14 +428,14 @@ class BrowserIdManager(Item, Persistent, Implicit, RoleManager, Owned, Tabs):
return
# should we raise an exception?
if
string
.
split
(
URL1
,
':'
)[
0
]
!=
'https'
:
return
# should we raise an exception?
cookies
=
REQUEST
.
RESPONSE
.
cookies
cookie
=
cookies
[
self
.
browserid_name
]
=
{}
for
k
,
v
in
d
.
items
():
if
v
:
cookie
[
k
]
=
v
#only stuff things with true values
cookie
[
'value'
]
=
bid
def
_getB64TStamp
(
self
,
b2a
=
binascii
.
b2a_base64
,
gmtime
=
time
.
gmtime
,
time
=
time
.
time
,
b64_trans
=
b64_trans
,
split
=
string
.
split
,
...
...
lib/python/Products/Sessions/SessionDataManager.py
View file @
2639fcb7
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -103,7 +103,7 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
security.declareProtected(ARBITRARY_SESSIONDATA_PERM,'
getSessionDataByKey
')
def getSessionDataByKey(self, key):
return self._getSessionDataObjectByKey(key)
security.declareProtected(ACCESS_CONTENTS_PERM, '
getBrowserIdManager
')
def getBrowserIdManager(self):
""" """
...
...
@@ -115,7 +115,7 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
return mgr
# END INTERFACE METHODS
def __init__(self, id, path=None, title='', requestName=None):
self.id = id
self.setContainerPath(path)
...
...
@@ -160,14 +160,14 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
self.obpath = list(path) # sequence
else:
raise SessionDataManagerErr, ('
Bad
path
value
%
s
' % path)
security.declareProtected(MGMT_SCREEN_PERM, '
getContainerPath
')
def getContainerPath(self):
""" """
if self.obpath is not None:
return string.join(self.obpath, '
/
')
return '' # blank string represents undefined state
def _hasSessionDataObject(self, key):
""" """
c = self._getSessionDataContainer()
...
...
lib/python/Products/Sessions/SessionInterfaces.py
View file @
2639fcb7
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -81,7 +81,7 @@ class BrowserIdManagerInterface(
"""
Returns true if browser id is 'new'. A browser id is 'new'
when it is first created and the client has therefore not sent it
back to the server in any request.
back to the server in any request.
Permission required: Access contents information
...
...
@@ -111,7 +111,7 @@ class BrowserIdManagerInterface(
"""
Deletes the browser id cookie from the client browser, iff the
'cookies' browser id namespace is being used.
Permission required: Access contents information
Raises: BrowserIdManagerErr. If the 'cookies' namespace isn't
...
...
@@ -123,7 +123,7 @@ class BrowserIdManagerInterface(
Sets the browser id cookie to browser id 'bid' by force.
Useful when you need to 'chain' browser id cookies across domains
for the same user (perhaps temporarily using query strings).
Permission required: Access contents information
Raises: BrowserIdManagerErr. If the 'cookies' namespace isn't
...
...
lib/python/Products/Sessions/SessionPermissions.py
View file @
2639fcb7
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
lib/python/Products/Sessions/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Session initialization routines
$Id: __init__.py,v 1.
6 2001/11/28 15:51:07 matt
Exp $
$Id: __init__.py,v 1.
7 2002/08/14 22:25:09 mj
Exp $
"""
import
ZODB
# this is for testrunner to be happy
...
...
lib/python/Products/Sessions/common.py
View file @
2639fcb7
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
lib/python/Products/Sessions/help/SessionInterfaces.py
View file @
2639fcb7
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -81,7 +81,7 @@ class BrowserIdManagerInterface(
"""
Returns true if browser id is 'new'. A browser id is 'new'
when it is first created and the client has therefore not sent it
back to the server in any request.
back to the server in any request.
Permission required: Access contents information
...
...
@@ -111,7 +111,7 @@ class BrowserIdManagerInterface(
"""
Deletes the browser id cookie from the client browser, iff the
'cookies' browser id namespace is being used.
Permission required: Access contents information
Raises: BrowserIdManagerErr. If the 'cookies' namespace isn't
...
...
@@ -123,7 +123,7 @@ class BrowserIdManagerInterface(
Sets the browser id cookie to browser id 'bid' by force.
Useful when you need to 'chain' browser id cookies across domains
for the same user (perhaps temporarily using query strings).
Permission required: Access contents information
Raises: BrowserIdManagerErr. If the 'cookies' namespace isn't
...
...
lib/python/Products/Sessions/stresstests/stresstestMultiThread.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
sys
,
os
,
time
if
__name__
==
"__main__"
:
...
...
@@ -117,7 +117,7 @@ class TestMultiThread(TestCase):
time
.
sleep
(
0.1
)
while
threading
.
activeCount
()
>
1
:
time
.
sleep
(
1
)
def
testNonOverlappingBrowserIds
(
self
):
readers
=
[]
writers
=
[]
...
...
@@ -143,7 +143,7 @@ class TestMultiThread(TestCase):
time
.
sleep
(
0.1
)
while
threading
.
activeCount
()
>
1
:
time
.
sleep
(
1
)
class
BaseReaderWriter
(
threading
.
Thread
):
def
__init__
(
self
,
db
,
iters
,
sdm_name
):
self
.
conn
=
db
.
open
()
...
...
@@ -180,7 +180,7 @@ class BaseReaderWriter(threading.Thread):
self
.
conn
.
close
()
del
self
.
app
print
i
class
ReaderThread
(
BaseReaderWriter
):
def
run1
(
self
):
session_data_manager
=
getattr
(
self
.
app
,
self
.
sdm_name
)
...
...
@@ -216,4 +216,3 @@ def test_suite():
if
__name__
==
'__main__'
:
runner
=
TextTestRunner
(
verbosity
=
9
,
descriptions
=
9
)
runner
.
run
(
test_suite
())
lib/python/Products/Sessions/tests/testBrowserIdManager.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Test suite for session id manager.
$Id: testBrowserIdManager.py,v 1.1
0 2002/08/10 19:28:38 chrism
Exp $
$Id: testBrowserIdManager.py,v 1.1
1 2002/08/14 22:25:10 mj
Exp $
"""
__version__
=
"$Revision: 1.1
0
$"
[
11
:
-
2
]
__version__
=
"$Revision: 1.1
1
$"
[
11
:
-
2
]
import
sys
import
ZODB
...
...
@@ -34,7 +34,7 @@ class TestBrowserIdManager(TestCase):
environ
[
'SERVER_PORT'
]
=
'80'
req
=
HTTPRequest
(
stdin
,
environ
,
resp
)
self
.
m
.
REQUEST
=
req
def
tearDown
(
self
):
del
self
.
m
...
...
@@ -114,7 +114,7 @@ class TestBrowserIdManager(TestCase):
self
.
m
.
setCookieDomain
(
'.zope.org'
)
setdomain
=
self
.
m
.
getCookieDomain
()
self
.
failUnless
(
setdomain
==
'.zope.org'
,
"%s"
%
setdomain
)
def
testSetCookieSecure
(
self
):
self
.
m
.
setCookieSecure
(
1
)
self
.
failUnless
(
self
.
m
.
getCookieSecure
()
==
1
)
...
...
@@ -143,7 +143,7 @@ class TestBrowserIdManager(TestCase):
self
.
failUnless
(
not
self
.
m
.
hasBrowserId
()
)
a
=
self
.
m
.
getBrowserId
()
self
.
failUnless
(
self
.
m
.
hasBrowserId
()
)
def
testBrowserIdIsNew
(
self
):
a
=
self
.
m
.
getBrowserId
()
self
.
failUnless
(
self
.
m
.
isBrowserIdNew
()
)
...
...
@@ -178,7 +178,7 @@ class TestBrowserIdManager(TestCase):
a
=
self
.
m
.
getBrowserId
()
self
.
failUnless
(
self
.
m
.
isBrowserIdFromCookie
()
)
self
.
failUnless
(
not
self
.
m
.
isBrowserIdFromForm
()
)
def
testIsBrowserIdFromFormOnly
(
self
):
token
=
self
.
m
.
getBrowserId
()
self
.
m
.
REQUEST
.
browser_id_
=
token
...
...
@@ -202,7 +202,7 @@ class TestBrowserIdManager(TestCase):
self
.
m
.
flushBrowserIdCookie
()
c
=
self
.
m
.
REQUEST
.
RESPONSE
.
cookies
[
tokenkey
]
self
.
failUnless
(
c
[
'value'
]
==
'deleted'
)
def
testSetBrowserIdCookieByForce
(
self
):
token
=
self
.
m
.
getBrowserId
()
self
.
m
.
REQUEST
.
browser_id_
=
token
...
...
@@ -238,7 +238,7 @@ class TestBrowserIdManager(TestCase):
def
test_suite
():
testsuite
=
makeSuite
(
TestBrowserIdManager
,
'test'
)
return
testsuite
if
__name__
==
'__main__'
:
runner
=
TextTestRunner
(
verbosity
=
9
)
runner
.
run
(
test_suite
())
lib/python/Products/Sessions/tests/testSessionDataManager.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
sys
,
os
,
time
...
...
@@ -92,11 +92,11 @@ def _populate(app):
app
.
temp_folder
.
_setObject
(
toc_name
,
toc
)
get_transaction
().
commit
()
# index_html necessary for publishing emulation for testAutoReqPopulate
app
.
_setObject
(
'index_html'
,
DTMLMethod
(
''
,
__name__
=
'foo'
))
get_transaction
().
commit
()
class
TestBase
(
TestCase
):
def
setUp
(
self
):
db
=
_getDB
()
...
...
@@ -137,7 +137,7 @@ class TestSessionManager(TestBase):
sd
=
self
.
app
.
session_data_manager
.
getSessionData
(
1
)
sdm
=
aq_base
(
getattr
(
self
.
app
,
sdm_name
))
toc
=
aq_base
(
getattr
(
self
.
app
.
temp_folder
,
toc_name
))
self
.
failUnless
(
aq_base
(
sd
.
aq_parent
)
is
sdm
)
self
.
failUnless
(
aq_base
(
sd
.
aq_parent
.
aq_parent
)
is
toc
)
...
...
@@ -229,4 +229,3 @@ def test_suite():
if
__name__
==
'__main__'
:
runner
=
TextTestRunner
(
verbosity
=
9
,
descriptions
=
9
)
runner
.
run
(
test_suite
())
lib/python/Products/SiteAccess/AccessRule.py
View file @
2639fcb7
...
...
@@ -34,7 +34,7 @@ def _swallow(request, prefix):
def
manage_addAccessRule
(
self
,
method_id
=
None
,
REQUEST
=
None
,
**
ignored
):
"""Point a __before_traverse__ entry at the specified method"""
# We want the original object, not stuff in between, and no acquisition
self
=
self
.
this
()
self
=
self
.
this
()
self
=
getattr
(
self
,
'aq_base'
,
self
)
priority
=
(
1
,
'AccessRule'
)
...
...
@@ -54,7 +54,7 @@ def manage_addAccessRule(self, method_id=None, REQUEST=None, **ignored):
except
:
pass
hook
=
AccessRule
(
method_id
)
registerBeforeTraverse
(
self
,
hook
,
'AccessRule'
,
1
)
try
:
try
:
getattr
(
self
,
method_id
).
icon
=
'misc_/SiteAccess/AccessRule.gif'
except
:
pass
if
REQUEST
:
...
...
@@ -70,7 +70,7 @@ def manage_addAccessRule(self, method_id=None, REQUEST=None, **ignored):
def
getAccessRule
(
self
,
REQUEST
=
None
):
"Return the name of the current AccessRule, if any"
self
=
self
.
this
()
self
=
self
.
this
()
rules
=
queryBeforeTraverse
(
self
,
'AccessRule'
)
if
rules
:
return
rules
[
0
][
1
].
name
...
...
lib/python/Products/SiteAccess/Extensions/updata.py
View file @
2639fcb7
...
...
@@ -28,7 +28,7 @@ def _cvt_btr(app):
btr
[
k
]
=
NameCaller
(
v
)
if
touched
:
rewriteBeforeTraverse
(
o
,
btr
)
if
__name__
==
'__main__'
:
print
"Converting SiteAccess objects from 1.x to 2.x ..."
app
=
Zope
.
app
()
...
...
lib/python/Products/SiteAccess/SiteRoot.py
View file @
2639fcb7
...
...
@@ -36,9 +36,9 @@ class Traverser(Persistent, Item):
message
=
'This object already contains a %s'
%
self
.
meta_type
,
action
=
nextURL
)
self
.
addToContainer
(
container
)
if
nextURL
:
if
nextURL
:
return
MessageDialog
(
title
=
'Item Added'
,
message
=
'This object now has a %s'
%
self
.
meta_type
,
message
=
'This object now has a %s'
%
self
.
meta_type
,
action
=
nextURL
)
def
manage_beforeDelete
(
self
,
item
,
container
):
...
...
@@ -96,11 +96,11 @@ class SiteRoot(Traverser, Implicit):
'''Set the title, base, and path'''
self
.
__init__
(
title
,
base
,
path
)
if
REQUEST
:
return
MessageDialog
(
title
=
'SiteRoot changed.'
,
message
=
'The title is now "%s"<br>'
'The base is now "%s"<br>'
'The path is now "%s"<br>'
%
(
title
,
base
,
path
),
action
=
'%s/manage_main'
%
REQUEST
[
'URL1'
])
return
MessageDialog
(
title
=
'SiteRoot changed.'
,
message
=
'The title is now "%s"<br>'
'The base is now "%s"<br>'
'The path is now "%s"<br>'
%
(
title
,
base
,
path
),
action
=
'%s/manage_main'
%
REQUEST
[
'URL1'
])
def
__call__
(
self
,
client
,
request
,
response
=
None
):
'''Traversing'''
...
...
lib/python/Products/SiteAccess/VirtualHostMonster.py
View file @
2639fcb7
...
...
@@ -97,9 +97,9 @@ class VirtualHostMonster(Persistent, Item, Implicit):
def
manage_addToContainer
(
self
,
container
,
nextURL
=
''
):
self
.
addToContainer
(
container
)
if
nextURL
:
if
nextURL
:
return
MessageDialog
(
title
=
'Item Added'
,
message
=
'This object now has a %s'
%
self
.
meta_type
,
message
=
'This object now has a %s'
%
self
.
meta_type
,
action
=
nextURL
)
def
manage_beforeDelete
(
self
,
item
,
container
):
...
...
lib/python/Products/SiteAccess/__init__.py
View file @
2639fcb7
...
...
@@ -3,15 +3,15 @@ __doc__="""SiteAccess product"""
import
SiteRoot
,
AccessRule
,
VirtualHostMonster
def
initialize
(
context
):
context
.
registerClass
(
instance_class
=
SiteRoot
.
SiteRoot
,
permission
=
'Add Site Roots'
,
constructors
=
SiteRoot
.
constructors
,
legacy
=
SiteRoot
.
constructors
,
icon
=
'www/SiteRoot.gif'
)
context
.
registerClass
(
instance_class
=
AccessRule
.
AccessRule
,
permission
=
'Manage Access Rules'
,
constructors
=
AccessRule
.
constructors
,
icon
=
'www/AccessRule.gif'
)
context
.
registerClass
(
instance_class
=
VirtualHostMonster
.
VirtualHostMonster
,
permission
=
'Add Virtual Host Monsters'
,
constructors
=
VirtualHostMonster
.
constructors
,
icon
=
'www/VirtualHostMonster.gif'
)
context
.
registerHelp
()
context
.
registerClass
(
instance_class
=
SiteRoot
.
SiteRoot
,
permission
=
'Add Site Roots'
,
constructors
=
SiteRoot
.
constructors
,
legacy
=
SiteRoot
.
constructors
,
icon
=
'www/SiteRoot.gif'
)
context
.
registerClass
(
instance_class
=
AccessRule
.
AccessRule
,
permission
=
'Manage Access Rules'
,
constructors
=
AccessRule
.
constructors
,
icon
=
'www/AccessRule.gif'
)
context
.
registerClass
(
instance_class
=
VirtualHostMonster
.
VirtualHostMonster
,
permission
=
'Add Virtual Host Monsters'
,
constructors
=
VirtualHostMonster
.
constructors
,
icon
=
'www/VirtualHostMonster.gif'
)
context
.
registerHelp
()
lib/python/Products/SiteErrorLog/SiteErrorLog.py
View file @
2639fcb7
...
...
@@ -2,18 +2,18 @@
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
"""Site error log module.
$Id: SiteErrorLog.py,v 1.
9 2002/06/29 18:46:45 chrism
Exp $
$Id: SiteErrorLog.py,v 1.
10 2002/08/14 22:25:11 mj
Exp $
"""
import
os
...
...
@@ -46,7 +46,7 @@ log_to_event_log = 'Log to the Event Log'
_rate_restrict_pool
=
{}
# The number of seconds that must elapse on average between sending two
# exceptions of the same name into the the Event Log. one per minute.
# exceptions of the same name into the the Event Log. one per minute.
_rate_restrict_period
=
60
# The number of exceptions to allow in a burst before the above limit
...
...
@@ -136,7 +136,7 @@ class SiteErrorLog (SimpleItem):
strtype
=
str
(
getattr
(
info
[
0
],
'__name__'
,
info
[
0
]))
if
strtype
in
self
.
_ignored_exceptions
:
return
if
not
isinstance
(
info
[
2
],
StringType
)
and
not
isinstance
(
info
[
2
],
UnicodeType
):
tb_text
=
''
.
join
(
...
...
@@ -227,7 +227,7 @@ class SiteErrorLog (SimpleItem):
RESPONSE
.
redirect
(
'%s/manage_main?manage_tabs_message=Changed+properties.'
%
self
.
absolute_url
())
security
.
declareProtected
(
use_error_logging
,
'getLogEntries'
)
def
getLogEntries
(
self
):
"""Returns the entries in the log.
...
...
@@ -272,4 +272,3 @@ def manage_addErrorLog(dispatcher, RESPONSE=None):
RESPONSE
.
redirect
(
dispatcher
.
DestinationURL
()
+
'/manage_main?manage_tabs_message=Error+Log+Added.'
)
lib/python/Products/SiteErrorLog/__init__.py
View file @
2639fcb7
...
...
@@ -2,18 +2,18 @@
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
"""Site error log product.
$Id: __init__.py,v 1.
2 2002/04/03 20:43:55 shane
Exp $
$Id: __init__.py,v 1.
3 2002/08/14 22:25:11 mj
Exp $
"""
import
SiteErrorLog
...
...
@@ -23,4 +23,3 @@ def initialize(context):
constructors
=
(
SiteErrorLog
.
manage_addErrorLog
,),
permission
=
SiteErrorLog
.
use_error_logging
,
icon
=
'www/error.gif'
)
lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''
Accelerated HTTP cache manager --
...
...
@@ -138,7 +138,7 @@ class AcceleratedHTTPCacheManager (CacheManager, SimpleItem):
def
getId
(
self
):
' '
return
self
.
id
ZCacheManager_getCache__roles__
=
()
def
ZCacheManager_getCache
(
self
):
cacheid
=
self
.
__cacheid
...
...
@@ -181,7 +181,7 @@ class AcceleratedHTTPCacheManager (CacheManager, SimpleItem):
req
=
self
.
REQUEST
sort_by
=
req
.
get
(
'sort_by'
,
'anon'
)
sort_reverse
=
int
(
req
.
get
(
'sort_reverse'
,
1
))
return
sort_by
,
sort_reverse
return
sort_by
,
sort_reverse
def
getCacheReport
(
self
):
"""
...
...
lib/python/Products/StandardCacheManagers/RAMCacheManager.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''
RAM cache manager --
...
...
@@ -145,7 +145,7 @@ class RAMCache (Cache):
else
:
return
None
return
oc
def
countAllEntries
(
self
):
'''
Returns the count of all cache entries.
...
...
@@ -296,7 +296,7 @@ class RAMCache (Cache):
oc
.
hits
=
oc
.
hits
+
1
entry
.
access_count
=
entry
.
access_count
+
1
return
entry
.
data
def
ZCache_set
(
self
,
ob
,
data
,
view_name
=
''
,
keywords
=
None
,
mtime_func
=
None
):
'''
...
...
@@ -356,7 +356,7 @@ class RAMCacheManager (CacheManager, SimpleItem):
def
getId
(
self
):
' '
return
self
.
id
ZCacheManager_getCache__roles__
=
()
def
ZCacheManager_getCache
(
self
):
cacheid
=
self
.
__cacheid
...
...
@@ -406,7 +406,7 @@ class RAMCacheManager (CacheManager, SimpleItem):
req
=
self
.
REQUEST
sort_by
=
req
.
get
(
'sort_by'
,
'hits'
)
sort_reverse
=
int
(
req
.
get
(
'sort_reverse'
,
1
))
return
sort_by
,
sort_reverse
return
sort_by
,
sort_reverse
def
getCacheReport
(
self
):
"""
...
...
lib/python/Products/StandardCacheManagers/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''
Some standard Zope cache managers from Digital Creations.
...
...
lib/python/Products/TemporaryFolder/LowConflictConnection.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
from
ZODB.Connection
import
Connection
...
...
@@ -43,5 +43,3 @@ class LowConflictConnection(Connection):
d
=
object
.
__dict__
for
k
,
v
in
state
.
items
():
d
[
k
]
=
v
object
.
_p_serial
=
serial
lib/python/Products/TemporaryFolder/TemporaryFolder.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Mounted database support
...
...
@@ -22,9 +22,9 @@ lives in another ZODB.
To understand this fully, you'll need to read the source of
ZODB.Mount.MountPoint.
$Id: TemporaryFolder.py,v 1.
6 2002/08/12 21:14:15 chrism
Exp $
$Id: TemporaryFolder.py,v 1.
7 2002/08/14 22:25:13 mj
Exp $
"""
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
import
Globals
from
Globals
import
HTMLFile
...
...
@@ -38,7 +38,7 @@ from LowConflictConnection import LowConflictConnection
ADD_TEMPORARY_FOLDER_PERM
=
"Add Temporary Folder"
def
constructTemporaryFolder
(
self
,
id
,
title
=
None
,
REQUEST
=
None
):
""" """
ms
=
MountedTemporaryFolder
(
id
,
title
)
...
...
@@ -58,7 +58,7 @@ class MountedTemporaryFolder(MountPoint, OFS.SimpleItem.Item):
icon
=
'p_/broken'
manage_options
=
({
'label'
:
'Traceback'
,
'action'
:
'manage_traceback'
},)
meta_type
=
'Broken Temporary Folder'
def
__init__
(
self
,
id
,
title
=
''
,
params
=
None
):
self
.
id
=
str
(
id
)
self
.
title
=
title
...
...
@@ -71,7 +71,7 @@ class MountedTemporaryFolder(MountPoint, OFS.SimpleItem.Item):
db
=
DB
(
TemporaryStorage
())
db
.
klass
=
LowConflictConnection
return
db
def
_getMountRoot
(
self
,
root
):
sdc
=
root
.
get
(
'folder'
,
None
)
if
sdc
is
None
:
...
...
@@ -79,7 +79,7 @@ class MountedTemporaryFolder(MountPoint, OFS.SimpleItem.Item):
self
.
_populate
(
sdc
,
root
)
return
sdc
def
mount_error_
(
self
):
return
self
.
_v_connect_error
...
...
lib/python/Products/TemporaryFolder/TemporaryStorage.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
...
...
@@ -17,10 +17,10 @@ MappingStorage. Unlike MappingStorage, it needs not be packed to get rid of
non-cyclic garbage and it does rudimentary conflict resolution. This is a
ripoff of Jim's Packless bsddb3 storage.
$Id: TemporaryStorage.py,v 1.
9 2002/06/30 18:23:15 chrism
Exp $
$Id: TemporaryStorage.py,v 1.
10 2002/08/14 22:25:13 mj
Exp $
"""
__version__
=
'$Revision: 1.
9
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
10
$'
[
11
:
-
2
]
from
zLOG
import
LOG
,
BLATHER
from
ZODB.referencesf
import
referencesf
...
...
@@ -82,12 +82,12 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
del
self
.
_conflict_cache
[
k
]
self
.
_last_cache_gc
=
now
self
.
_tmp
=
[]
def
close
(
self
):
"""
Close the storage
"""
def
load
(
self
,
oid
,
version
):
self
.
_lock_acquire
()
try
:
...
...
@@ -112,7 +112,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
return
data
[
0
]
# data here is actually (data, t)
finally
:
self
.
_lock_release
()
def
store
(
self
,
oid
,
serial
,
data
,
version
,
transaction
):
if
transaction
is
not
self
.
_transaction
:
raise
POSException
.
StorageTransactionError
(
self
,
transaction
)
...
...
@@ -217,7 +217,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
self
.
_takeOutGarbage
(
oid
)
self
.
_tmp
=
[]
def
_takeOutGarbage
(
self
,
oid
):
# take out the garbage.
referenceCount
=
self
.
_referenceCount
...
...
@@ -246,7 +246,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
referenceCount
[
roid
]
=
rc
-
1
try
:
del
self
.
_oreferences
[
oid
]
except
:
pass
def
pack
(
self
,
t
,
referencesf
):
self
.
_lock_acquire
()
try
:
...
...
@@ -268,9 +268,3 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
self
.
_takeOutGarbage
(
oid
)
finally
:
self
.
_lock_release
()
lib/python/Products/TemporaryFolder/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Temporary Folder initialization routines
$Id: __init__.py,v 1.
5 2002/01/11 14:53:38 chrism
Exp $
$Id: __init__.py,v 1.
6 2002/08/14 22:25:13 mj
Exp $
"""
import
ZODB
# for testrunner to be happy
...
...
lib/python/Products/TemporaryFolder/patchfs.py
View file @
2639fcb7
# Utility program to patch Data.fs.in to include a temporary folder, browser
# id manager, and session data manager
############################################################################
#
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -18,7 +18,7 @@ import Globals
from
ZODB
import
FileStorage
,
DB
import
Products.Sessions.BrowserIdManager
import
Products.Sessions.SessionDataManager
import
Products.TemporaryFolder.TemporaryFolder
import
Products.TemporaryFolder.TemporaryFolder
import
os.path
import
sys
...
...
lib/python/Products/TemporaryFolder/tests/testTemporaryStorage.py
View file @
2639fcb7
import
ZODB
from
ZODB.tests.MinPO
import
MinPO
from
Products.TemporaryFolder
import
TemporaryStorage
...
...
@@ -47,7 +46,7 @@ class TemporaryStorageTests(
oid4
=
self
.
_storage
.
new_oid
()
self
.
_dostore
(
oid4
,
data
=
MinPO
(
11
))
assert
len
(
self
.
_storage
.
_conflict_cache
)
==
1
finally
:
TemporaryStorage
.
CONFLICT_CACHE_GCEVERY
=
old_gcevery
TemporaryStorage
.
CONFLICT_CACHE_MAXAGE
=
old_maxage
...
...
@@ -64,14 +63,14 @@ def main():
runner
.
run
(
alltests
)
def
debug
():
test_suite
().
debug
()
test_suite
().
debug
()
def
pdebug
():
import
pdb
pdb
.
run
(
'debug()'
)
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
>
1
:
globals
()[
sys
.
argv
[
1
]]()
else
:
main
()
if
len
(
sys
.
argv
)
>
1
:
globals
()[
sys
.
argv
[
1
]]()
else
:
main
()
lib/python/Products/Transience/Transience.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Transient Object Container Class ('timeslice'-based design).
$Id: Transience.py,v 1.2
7 2002/08/07 14:48:48 chrism
Exp $
$Id: Transience.py,v 1.2
8 2002/08/14 22:25:13 mj
Exp $
"""
__version__
=
'$Revision: 1.2
7
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
8
$'
[
11
:
-
2
]
import
Globals
from
Globals
import
HTMLFile
...
...
@@ -127,7 +127,7 @@ class TransientObjectContainer(SimpleItem):
{
'label'
:
'Manage'
,
'action'
:
'manage_container'
,
'help'
:
(
'Transience'
,
'Transience.stx'
)
},
},
{
'label'
:
'Security'
,
'action'
:
'manage_access'
},
...
...
@@ -229,7 +229,7 @@ class TransientObjectContainer(SimpleItem):
def
setAddNotificationTarget
(
self
,
f
):
# We should assert that the callback function 'f' implements
# the TransientNotification interface
self
.
_addCallback
=
f
self
.
_addCallback
=
f
security
.
declareProtected
(
MGMT_SCREEN_PERM
,
'getDelNotificationTarget'
)
def
getDelNotificationTarget
(
self
):
...
...
@@ -252,7 +252,7 @@ class TransientObjectContainer(SimpleItem):
def
_notify
(
self
,
items
,
kind
):
if
not
type
(
items
)
in
[
type
([]),
type
(())]:
items
=
[
items
]
if
kind
==
'add'
:
name
=
'notifyAdd'
callback
=
self
.
_addCallback
...
...
@@ -437,7 +437,7 @@ class TransientObjectContainer(SimpleItem):
self
.
_deindex_next
=
Increaser
(
self
.
_getCurrentTimeslice
())
finally
:
self
.
lock
.
release
()
def
_getCurrentBucket
(
self
):
"""
Do housekeeping if necessary, then return the 'current' bucket.
...
...
@@ -673,7 +673,7 @@ class TransientObjectContainer(SimpleItem):
data
[
i
]
=
OOBTree
()
except
Queue
.
Empty
:
DEBUG
and
TLOG
(
'replentish queue empty'
)
# gc the stale buckets at the "beginning" of _data ("garbage collect")
# iterate over the keys in data that have no minimum value and
# a maximum value of delete_end (note: ordered set)
...
...
@@ -741,7 +741,7 @@ class TransientObjectContainer(SimpleItem):
finally
:
self
.
lock
.
release
()
def
__getitem__
(
self
,
k
):
self
.
lock
.
acquire
()
try
:
...
...
@@ -803,7 +803,7 @@ class TransientObjectContainer(SimpleItem):
# we accessed the object, so it becomes current
# by moving it to the current bucket
del
self
.
_data
[
b
][
k
]
# delete the item from the old bucket.
self
.
_data
[
current
][
k
]
=
v
# add the value to the current
self
.
_data
[
current
][
k
]
=
v
# add the value to the current
self
.
_setLastAccessed
(
v
)
index
[
k
]
=
current
# change the index to the current buck.
...
...
@@ -812,7 +812,7 @@ class TransientObjectContainer(SimpleItem):
return
v
finally
:
self
.
lock
.
release
()
def
_setLastAccessed
(
self
,
transientObject
):
self
.
lock
.
acquire
()
try
:
...
...
@@ -860,7 +860,7 @@ class Increaser(Persistent):
def
set
(
self
,
v
):
self
.
value
=
v
def
__getstate__
(
self
):
return
self
.
value
...
...
lib/python/Products/Transience/TransienceInterfaces.py
View file @
2639fcb7
##########################################################################
##########################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
...
...
@@ -9,7 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##########################################################################
##########################################################################
"""
Transient Objects
...
...
@@ -66,7 +66,7 @@ Transient Objects
class Foo(Persistence.Persistent):
pass
transient_object = transient_data_container.new('t')
foo = transient_object['foo'] = Foo()
foo.bar = 1
...
...
@@ -270,7 +270,7 @@ class StringKeyedHomogeneousItemContainer(HomogeneousItemContainer):
Returned object is acquisition-wrapped in self.
"""
class
TransientItemContainer
(
Interface
.
Base
):
def
setTimeoutMinutes
(
timeout_mins
):
"""
...
...
lib/python/Products/Transience/TransientObject.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Simple ZODB-based transient object implementation.
$Id: TransientObject.py,v 1.
8 2002/06/24 19:31:16 chrism
Exp $
$Id: TransientObject.py,v 1.
9 2002/08/14 22:25:13 mj
Exp $
"""
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
9
$'
[
11
:
-
2
]
from
Persistence
import
Persistent
from
Acquisition
import
Implicit
...
...
@@ -114,7 +114,7 @@ class TransientObject(Persistent, Implicit):
def
getContainerKey
(
self
):
return
self
.
token
# -----------------------------------------------------------------
# DictionaryLike
#
...
...
@@ -132,7 +132,7 @@ class TransientObject(Persistent, Implicit):
v
=
self
.
_container
.
get
(
k
,
default
)
if
v
is
_notfound
:
return
None
return
v
def
has_key
(
self
,
k
):
if
self
.
_container
.
get
(
k
,
_notfound
)
is
not
_notfound
:
return
1
return
0
...
...
@@ -243,7 +243,7 @@ class TransientObject(Persistent, Implicit):
'Conflict resolution error in TransientObject'
,
''
,
sys
.
exc_info
()
)
getName
=
getId
# this is for SQLSession compatibility
def
_generateUniqueId
(
self
):
...
...
lib/python/Products/Transience/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""
Transience initialization routines
$Id: __init__.py,v 1.
6 2001/11/28 15:51:09 matt
Exp $
$Id: __init__.py,v 1.
7 2002/08/14 22:25:13 mj
Exp $
"""
import
ZODB
# this is to help out testrunner, don't remove.
...
...
@@ -21,7 +21,7 @@ import Transience
# import of MaxTransientObjectsExceeded for easy import from scripts,
# this is protected by a module security info declaration in the
# Sessions package.
from
Transience
import
MaxTransientObjectsExceeded
from
Transience
import
MaxTransientObjectsExceeded
def
initialize
(
context
):
context
.
registerClass
(
...
...
@@ -33,4 +33,3 @@ def initialize(context):
)
context
.
registerHelp
()
context
.
registerHelpTitle
(
'Zope Help'
)
lib/python/Products/Transience/help/TransienceInterfaces.py
View file @
2639fcb7
##########################################################################
##########################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
...
...
@@ -9,7 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##########################################################################
##########################################################################
"""
Transient Objects
...
...
@@ -24,7 +24,7 @@ class TransientObjectContainer:
container. You'll almost always deal with a TransientObject
itself which you'll usually get as 'REQUEST.SESSION'.
"""
def
getId
(
self
):
"""
Returns a meaningful unique id for the object.
...
...
@@ -79,7 +79,7 @@ class TransientObjectContainer:
Permission -- 'Create Transient Objects'
"""
def
setTimeoutMinutes
(
self
,
timeout_mins
):
"""
Set the number of minutes of inactivity allowable for subobjects
...
...
@@ -182,7 +182,7 @@ class TransientObject:
Permission -- Always available
"""
def
invalidate
(
self
):
"""
Invalidate (expire) the transient object.
...
...
@@ -291,5 +291,3 @@ class MaxTransientObjectsExceeded:
from Products.Transience import MaxTransientObjectsExceeded
"""
lib/python/Products/Transience/tests/fauxtime.py
View file @
2639fcb7
...
...
@@ -9,4 +9,3 @@ def time():
def
sleep
(
duration
):
""" False sleep -- sleep for 1/10 the time specifed """
origtime
.
sleep
(
duration
/
10.0
)
lib/python/Products/Transience/tests/testTimeoutRelated.py
View file @
2639fcb7
...
...
@@ -72,7 +72,7 @@ class TestBase(TestCase):
del
self
.
app
Products
.
Transience
.
Transience
.
time
=
oldtime
Products
.
Transience
.
TransientObject
.
time
=
oldtime
class
TestLastAccessed
(
TestBase
):
def
testLastAccessed
(
self
):
sdo
=
self
.
app
.
sm
.
new_or_existing
(
'TempObject'
)
...
...
lib/python/Products/Transience/tests/testTransientObject.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
sys
,
os
,
unittest
...
...
@@ -34,7 +34,7 @@ class TestTransientObject(TestCase):
Products
.
Transience
.
TransientObject
.
time
=
oldtime
self
.
t
=
None
del
self
.
t
def
test_id
(
self
):
t
=
self
.
t
.
new
(
'xyzzy'
)
assert
t
.
getId
()
!=
'xyzzy'
...
...
@@ -99,10 +99,10 @@ class TestTransientObject(TestCase):
assert
t
.
get
(
'foobie'
)
is
None
self
.
assertRaises
(
AttributeError
,
self
.
_genLenError
,
t
)
assert
t
.
get
(
'foobie'
,
None
)
is
None
assert
t
.
has_key
(
'a'
)
assert
not
t
.
has_key
(
'foobie'
)
assert
t
.
has_key
(
'a'
)
assert
not
t
.
has_key
(
'foobie'
)
t
.
clear
()
assert
not
len
(
t
.
keys
())
assert
not
len
(
t
.
keys
())
def
test_TTWDictionary
(
self
):
t
=
self
.
t
.
new
(
'mouthfultest'
)
...
...
@@ -111,7 +111,7 @@ class TestTransientObject(TestCase):
assert
t
.
get
(
'foo'
)
==
'bar'
t
.
set
(
'foobie'
,
'blech'
)
t
.
delete
(
'foobie'
)
assert
t
.
get
(
'foobie'
)
is
None
assert
t
.
get
(
'foobie'
)
is
None
def
test_suite
():
...
...
@@ -130,4 +130,3 @@ data = {
if
__name__
==
'__main__'
:
runner
=
TextTestRunner
(
verbosity
=
9
)
runner
.
run
(
test_suite
())
lib/python/Products/Transience/tests/testTransientObjectContainer.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
sys
,
os
,
time
,
random
,
unittest
...
...
@@ -75,7 +75,7 @@ class TestTransientObjectContainer(TestBase):
for
x
in
v
:
assert
x
==
i
i
=
i
+
1
def
testKeysWorks
(
self
):
for
x
in
range
(
10
,
110
):
self
.
t
[
x
]
=
x
...
...
@@ -137,7 +137,7 @@ class TestTransientObjectContainer(TestBase):
self
.
t
[
4
]
=
99
del
self
.
t
[
2
]
assert
lsubtract
(
self
.
t
.
keys
(),[
1
,
3
,
4
,
5
,
6
,
10
])
==
[],
`self.t.keys()`
def
donttestDeleteTwoChildrenInorderSuccessorWorks
(
self
):
self
.
t
[
5
]
=
6
self
.
t
[
2
]
=
10
...
...
@@ -325,7 +325,7 @@ class TestTransientObjectContainer(TestBase):
# we should still have 100 - 199
for
x
in
range
(
110
,
210
):
assert
self
.
t
[
x
]
==
x
# but we shouldn't have 0 - 100
# but we shouldn't have 0 - 100
for
x
in
range
(
10
,
110
):
try
:
self
.
t
[
x
]
except
KeyError
:
pass
...
...
@@ -439,13 +439,13 @@ class TestTransientObjectContainer(TestBase):
for
x
in
range
(
11
):
self
.
t
.
new
(
str
(
x
))
def
lsubtract
(
l1
,
l2
):
l1
=
list
(
l1
)
l2
=
list
(
l2
)
l
=
filter
(
lambda
x
,
l1
=
l1
:
x
not
in
l1
,
l2
)
l
=
l
+
filter
(
lambda
x
,
l2
=
l2
:
x
not
in
l2
,
l1
)
return
l
l1
=
list
(
l1
)
l2
=
list
(
l2
)
l
=
filter
(
lambda
x
,
l1
=
l1
:
x
not
in
l1
,
l2
)
l
=
l
+
filter
(
lambda
x
,
l2
=
l2
:
x
not
in
l2
,
l1
)
return
l
def
test_suite
():
testsuite
=
makeSuite
(
TestTransientObjectContainer
,
'test'
)
...
...
@@ -456,4 +456,3 @@ def test_suite():
if
__name__
==
'__main__'
:
runner
=
TextTestRunner
(
verbosity
=
9
)
runner
.
run
(
test_suite
())
lib/python/Products/ZCTextIndex/BaseIndex.py
View file @
2639fcb7
...
...
@@ -81,10 +81,10 @@ class BaseIndex(Persistent):
# docid -> WidCode'd list of wids
# Used for un-indexing, and for phrase search.
self
.
_docwords
=
IOBTree
()
# Use a BTree length for efficient length computation w/o conflicts
self
.
length
=
BTrees
.
Length
.
Length
()
def
length
(
self
):
"""Return the number of words in the index."""
# This is overridden per instance
...
...
@@ -155,7 +155,7 @@ class BaseIndex(Persistent):
# The wid->weight mappings are fed into _add_wordinfo, and docweight
# becomes the value of _docweight[docid].
raise
NotImplementedError
def
has_doc
(
self
,
docid
):
return
self
.
_docwords
.
has_key
(
docid
)
...
...
@@ -281,7 +281,7 @@ class BaseIndex(Persistent):
doc2score
[
docid
]
=
weight
self
.
_wordinfo
[
wid
]
=
doc2score
# not redundant: Persistency!
self
.
length
.
change
(
new_word_count
)
def
_del_wordinfo
(
self
,
wid
,
docid
):
doc2score
=
self
.
_wordinfo
[
wid
]
...
...
lib/python/Products/ZCTextIndex/IIndex.py
View file @
2639fcb7
...
...
@@ -66,6 +66,6 @@ class IIndex(Interface.Base):
def
unindex_doc
(
docid
):
"XXX"
def
has_doc
(
docid
):
"""Returns true if docid is an id of a document in the index"""
lib/python/Products/ZCTextIndex/ZCTextIndex.py
View file @
2639fcb7
...
...
@@ -56,7 +56,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
)
query_options
=
[
'query'
]
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
manage_zcatalog_indexes
)
...
...
@@ -65,11 +65,11 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
def
__init__
(
self
,
id
,
extra
=
None
,
caller
=
None
,
index_factory
=
None
,
field_name
=
None
,
lexicon_id
=
None
):
self
.
id
=
id
# Arguments can be passed directly to the constructor or
# via the silly "extra" record.
self
.
_fieldname
=
field_name
or
getattr
(
extra
,
'doc_attr'
,
''
)
or
id
lexicon_id
=
lexicon_id
or
extra
.
lexicon_idp
lexicon
=
getattr
(
caller
,
lexicon_id
,
None
)
...
...
@@ -94,11 +94,11 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
self
.
_index_factory
=
index_factory
self
.
index
=
self
.
_index_factory
(
self
.
getLexicon
())
## Private Methods ##
security
.
declarePrivate
(
'getLexicon'
)
def
getLexicon
(
self
):
"""Get the lexicon for this index
"""
...
...
@@ -108,7 +108,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
lexicon
=
getattr
(
self
.
aq_parent
,
self
.
lexicon
.
getId
())
self
.
lexicon_path
=
lexicon
.
getPhysicalPath
()
del
self
.
lexicon
try
:
return
self
.
_v_lexicon
except
AttributeError
:
...
...
@@ -122,7 +122,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## External methods not in the Pluggable Index API ##
security
.
declareProtected
(
'query'
,
search_zcatalog
)
def
query
(
self
,
query
,
nbest
=
10
):
"""Return pair (mapping from docids to scores, num results).
...
...
@@ -196,8 +196,8 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
"""reinitialize the index (but not the lexicon)"""
try
:
# Remove the cached reference to the lexicon
# So that it is refreshed
del
self
.
_v_lexicon
# So that it is refreshed
del
self
.
_v_lexicon
except
(
AttributeError
,
KeyError
):
pass
self
.
index
=
self
.
_index_factory
(
self
.
getLexicon
())
...
...
@@ -209,11 +209,11 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
def
getIndexType
(
self
):
"""Return index type string"""
return
getattr
(
self
,
'_index_type'
,
self
.
_index_factory
.
__name__
)
def
getFieldName
(
self
):
"""Return indexed attribute name"""
return
self
.
_fieldname
def
getLexiconPath
(
self
):
"""Return the path of the lexicon used by the index"""
try
:
...
...
@@ -268,7 +268,7 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
manage_options
=
({
'label'
:
'Overview'
,
'action'
:
'manage_main'
},
{
'label'
:
'Query'
,
'action'
:
'queryLexicon'
},
)
+
SimpleItem
.
manage_options
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
LexiconQueryPerm
)
...
...
@@ -282,11 +282,11 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
def
getPipelineNames
(
self
):
"""Return list of names of pipeline element classes"""
return
[
element
.
__class__
.
__name__
for
element
in
self
.
_pipeline
]
_queryLexicon
=
DTMLFile
(
'dtml/queryLexicon'
,
globals
())
security
.
declareProtected
(
LexiconQueryPerm
,
'queryLexicon'
)
def
queryLexicon
(
self
,
REQUEST
,
words
=
None
,
page
=
0
,
rows
=
20
,
cols
=
4
):
"""Lexicon browser/query user interface
"""
...
...
@@ -297,7 +297,7 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
words
=
[
self
.
get_word
(
wid
)
for
wid
in
wids
]
else
:
words
=
self
.
words
()
word_count
=
len
(
words
)
rows
=
max
(
min
(
rows
,
500
),
1
)
cols
=
max
(
min
(
cols
,
12
),
1
)
...
...
@@ -306,18 +306,18 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
page
=
max
(
min
(
page
,
page_count
-
1
),
0
)
start
=
rows
*
cols
*
page
end
=
min
(
rows
*
cols
*
(
page
+
1
),
word_count
)
if
word_count
:
words
=
list
(
words
[
start
:
end
])
else
:
words
=
[]
columns
=
[]
i
=
0
while
i
<
len
(
words
):
columns
.
append
(
words
[
i
:
i
+
rows
])
i
+=
rows
return
self
.
_queryLexicon
(
self
,
REQUEST
,
page
=
page
,
rows
=
rows
,
...
...
@@ -328,8 +328,8 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
page_count
=
page_count
,
page_range
=
xrange
(
page_count
),
page_columns
=
columns
)
security
.
declareProtected
(
LexiconMgmtPerm
,
'manage_main'
)
security
.
declareProtected
(
LexiconMgmtPerm
,
'manage_main'
)
manage_main
=
DTMLFile
(
'dtml/manageLexicon'
,
globals
())
InitializeClass
(
PLexicon
)
lib/python/Products/ZCTextIndex/tests/testZCTextIndex.py
View file @
2639fcb7
...
...
@@ -41,10 +41,10 @@ class Indexable:
class
LexiconHolder
(
Acquisition
.
Implicit
):
def
__init__
(
self
,
lexicon
):
self
.
lexicon
=
lexicon
def
getPhysicalPath
(
self
):
return
(
''
,)
# Pretend to be the root
def
dummyUnrestrictedTraverse
(
self
,
path
):
if
path
==
(
''
,
'lexicon'
,):
return
self
.
lexicon
...
...
@@ -102,13 +102,13 @@ class ZCIndexTestsBase:
def
setUp
(
self
):
self
.
lexicon
=
PLexicon
(
'lexicon'
,
''
,
Splitter
(),
CaseNormalizer
(),
Splitter
(),
CaseNormalizer
(),
StopWordRemover
())
caller
=
LexiconHolder
(
self
.
lexicon
)
self
.
zc_index
=
ZCTextIndex
(
'name'
,
None
,
caller
,
self
.
zc_index
=
ZCTextIndex
(
'name'
,
None
,
caller
,
self
.
IndexFactory
,
'text'
,
'lexicon'
)
...
...
@@ -466,14 +466,14 @@ class QueryTestsBase(testQueryEngine.TestQueryEngine,
def setUp(self):
self.lexicon = PLexicon('lexicon', '',
Splitter(),
CaseNormalizer(),
Splitter(),
CaseNormalizer(),
StopWordRemover())
caller = LexiconHolder(self.lexicon)
self.zc_index = ZCTextIndex('name',
None,
caller,
self.zc_index = ZCTextIndex('name',
None,
caller,
self.IndexFactory,
'text',
'lexicon')
...
...
lib/python/Products/ZCatalog/Catalog.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
from
Persistence
import
Persistent
...
...
@@ -67,12 +67,12 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if
brains
is
not
None
:
self
.
_v_brains
=
brains
self
.
updateBrains
()
def
clear
(
self
):
""" clear catalog """
self
.
data
=
IOBTree
()
# mapping of rid to meta_data
self
.
uids
=
OIBTree
()
# mapping of uid to rid
self
.
paths
=
IOBTree
()
# mapping of rid to uid
...
...
@@ -118,7 +118,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
def
__getitem__
(
self
,
index
,
ttype
=
type
(())):
"""
Returns instances of self._v_brains, or whatever is passed
Returns instances of self._v_brains, or whatever is passed
into self.useBrains.
"""
if
type
(
index
)
is
ttype
:
...
...
@@ -150,7 +150,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
class
mybrains
(
AbstractCatalogBrain
,
brains
):
pass
scopy
=
self
.
schema
.
copy
()
scopy
[
'data_record_id_'
]
=
len
(
self
.
schema
.
keys
())
...
...
@@ -166,7 +166,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
"""
adds a row to the meta data schema
"""
schema
=
self
.
schema
names
=
list
(
self
.
names
)
...
...
@@ -176,7 +176,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if
name
[
0
]
==
'_'
:
raise
'Invalid Meta-Data Name'
,
\
'Cannot cache fields beginning with "_"'
if
not
schema
.
has_key
(
name
):
if
schema
.
values
():
schema
[
name
]
=
max
(
schema
.
values
())
+
1
...
...
@@ -197,9 +197,9 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# new column? update the brain
self
.
updateBrains
()
self
.
__changed__
(
1
)
#why?
def
delColumn
(
self
,
name
):
"""
deletes a row from the meta data schema
...
...
@@ -233,7 +233,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self
.
data
[
key
]
=
tuple
(
rec
)
def
addIndex
(
self
,
name
,
index_type
):
"""Create a new index, given a name and a index_type.
"""Create a new index, given a name and a index_type.
Old format: index_type was a string, 'FieldIndex' 'TextIndex' or
'KeywordIndex' is no longer valid; the actual index must be instantiated
...
...
@@ -248,7 +248,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if
name
.
startswith
(
'_'
):
raise
'Invalid Index Name'
,
'Cannot index fields beginning with "_"'
if
not
name
:
raise
'Invalid Index Name'
,
'Name of index is empty'
...
...
@@ -271,15 +271,15 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
indexes
=
self
.
indexes
del
indexes
[
name
]
self
.
indexes
=
indexes
def
getIndex
(
self
,
name
):
""" get an index wrapped in the catalog """
return
self
.
indexes
[
name
].
__of__
(
self
)
# the cataloging API
def
catalogObject
(
self
,
object
,
uid
,
threshold
=
None
,
idxs
=
[]):
"""
"""
Adds an object to the Catalog by iteratively applying it
all indexes.
...
...
@@ -288,7 +288,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
'uid' is the unique Catalog identifier for this object
"""
data
=
self
.
data
# meta_data is stored as a tuple for efficiency
...
...
@@ -297,17 +297,17 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
index
=
self
.
uids
.
get
(
uid
,
None
)
if
index
is
not
None
:
# old data
if
data
.
get
(
index
,
0
)
!=
newDataRecord
:
# Update the meta-data, if necessary
data
[
index
]
=
newDataRecord
else
:
# new data
if
type
(
data
)
is
IOBTree
:
# New style, get radom id
index
=
getattr
(
self
,
'_v_nextid'
,
0
)
if
index
%
4000
==
0
:
index
=
randid
()
while
not
data
.
insert
(
index
,
newDataRecord
):
...
...
@@ -332,10 +332,10 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
try
:
self
.
__len__
.
change
(
1
)
except
AttributeError
:
pass
# No managed length (old-style)
self
.
uids
[
uid
]
=
index
self
.
paths
[
index
]
=
uid
total
=
0
if
idxs
==
[]:
use_indexes
=
self
.
indexes
.
keys
()
...
...
@@ -353,7 +353,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
return
total
def
uncatalogObject
(
self
,
uid
):
"""
"""
Uncatalog and object from the Catalog. and 'uid' is a unique
Catalog identifier
...
...
@@ -384,7 +384,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
LOG
(
'Catalog'
,
ERROR
,
(
'uncatalogObject unsuccessfully '
'attempted to uncatalog an object '
'with a uid of %s. '
%
uid
))
def
uniqueValuesFor
(
self
,
name
):
""" return unique values for FieldIndex name """
...
...
@@ -422,7 +422,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
for
name
in
self
.
indexes
.
keys
():
result
[
name
]
=
self
.
getIndex
(
name
).
getEntryForObject
(
rid
,
""
)
return
result
## This is the Catalog search engine. Most of the heavy lifting happens below
def
_indexedSearch
(
self
,
request
,
sort_index
,
append
,
used
):
...
...
@@ -433,19 +433,19 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
data
=
self
.
data
# Indexes fulfill a fairly large contract here. We hand each
# index the request mapping we are given (which may be composed
# index the request mapping we are given (which may be composed
# of some combination of web request, kw mappings or plain old dicts)
# and the index decides what to do with it. If the index finds work
# for itself in the request, it returns the results and a tuple of
# the attributes that were used. If the index finds nothing for it
# to do then it returns None.
# For hysterical reasons, if all indexes return None for a given
# request (and no attributes were used) then we append all results
# in the Catalog. This generally happens when the search values
# in request are all empty strings or do not coorespond to any of
# the indexes.
# Note that if the indexes find query arguments, but the end result
# is an empty sequence, we do nothing
...
...
@@ -490,13 +490,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# it, compute the normalized score, and Lazify it.
rset
=
rs
.
byValue
(
0
)
# sort it by score
max
=
float
(
rset
[
0
][
0
])
# Here we define our getter function inline so that
# we can conveniently store the max value as a default arg
# and make the normalized score computation lazy
def
getScoredResult
(
item
,
max
=
max
,
self
=
self
):
"""
Returns instances of self._v_brains, or whatever is passed
Returns instances of self._v_brains, or whatever is passed
into self.useBrains.
"""
score
,
key
=
item
...
...
@@ -506,14 +506,14 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
r
.
data_record_score_
=
score
r
.
data_record_normalized_score_
=
int
(
100.
*
score
/
max
)
return
r
# Lazify the results
append
(
LazyMap
(
getScoredResult
,
rset
))
elif
sort_index
is
None
and
not
hasattr
(
rs
,
'values'
):
# no scores? Just Lazify.
if
hasattr
(
rs
,
'keys'
):
rs
=
rs
.
keys
()
rs
=
rs
.
keys
()
append
(
LazyMap
(
self
.
__getitem__
,
rs
))
else
:
# sort. If there are scores, then this block is not
...
...
@@ -658,18 +658,18 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
class
CatalogError
(
Exception
):
pass
class
CatalogSearchArgumentsMap
:
"""Multimap catalog arguments coming simultaneously from keywords
"""Multimap catalog arguments coming simultaneously from keywords
and request.
Values that are empty strings are treated as non-existent. This is
to ignore empty values, thereby ignoring empty form fields to be
to ignore empty values, thereby ignoring empty form fields to be
consistent with hysterical behavior.
"""
def
__init__
(
self
,
request
,
keywords
):
self
.
request
=
request
or
{}
self
.
keywords
=
keywords
or
{}
def
__getitem__
(
self
,
key
):
marker
=
[]
v
=
self
.
keywords
.
get
(
key
,
marker
)
...
...
@@ -678,7 +678,7 @@ class CatalogSearchArgumentsMap:
if
v
==
''
:
raise
KeyError
(
key
)
return
v
def
get
(
self
,
key
,
default
=
None
):
try
:
v
=
self
[
key
]
...
...
@@ -686,7 +686,7 @@ class CatalogSearchArgumentsMap:
return
default
else
:
return
v
def
has_key
(
self
,
key
):
try
:
self
[
key
]
...
...
@@ -694,8 +694,8 @@ class CatalogSearchArgumentsMap:
return
0
else
:
return
1
def
mergeResults
(
r
,
has_sort_keys
,
reverse
):
"""Sort/merge sub-results, generating a flat sequence.
...
...
@@ -728,4 +728,3 @@ def mergeResults(r, has_sort_keys, reverse):
tmp
.
append
(
elt
)
size
+=
len
(
elt
)
return
LazyCat
(
tmp
,
size
)
lib/python/Products/ZCatalog/CatalogAwareness.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""ZCatalog Findable class
...
...
@@ -28,7 +28,7 @@ class CatalogAware:
it is added or copied in Zope. If you make changes to your own
object, you are responsible for calling your object's index_object
method. """
meta_type
=
'CatalogAware'
default_catalog
=
'Catalog'
...
...
@@ -40,7 +40,7 @@ class CatalogAware:
message
=
"Your changes have been saved"
if
REQUEST
is
not
None
:
return
self
.
manage_main
(
self
,
REQUEST
,
manage_tabs_message
=
message
)
def
manage_afterAdd
(
self
,
item
,
container
):
self
.
index_object
()
...
...
@@ -135,12 +135,3 @@ class CatalogAware:
for
item
in
obj
.
objectValues
():
self
.
reindex_all
(
self
,
item
)
return
'done!'
lib/python/Products/ZCatalog/CatalogBrains.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__version__
=
"$Revision$"
[
11
:
-
2
]
...
...
@@ -28,7 +28,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
def
getPath
(
self
):
"""Get the physical path for this record"""
return
self
.
aq_parent
.
getpath
(
self
.
data_record_id_
)
def
getURL
(
self
):
"""Try to generate a URL for this record"""
try
:
...
...
@@ -49,11 +49,11 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
zLOG
.
LOG
(
'CatalogBrains'
,
zLOG
.
INFO
,
'getObject raised an error'
,
error
=
sys
.
exc_info
())
pass
def
getRID
(
self
):
"""Return the record ID for this object."""
return
self
.
data_record_id_
class
NoBrainer
:
""" This is an empty class to use when no brain is specified. """
pass
lib/python/Products/ZCatalog/CatalogPathAwareness.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""ZCatalog Findable class"""
...
...
@@ -25,7 +25,7 @@ class CatalogAware:
it is added or copied in Zope. If you make changes to your own
object, you are responsible for calling your object's index_object
method. """
meta_type
=
'CatalogAware'
default_catalog
=
'Catalog'
...
...
@@ -37,7 +37,7 @@ class CatalogAware:
message
=
"Your changes have been saved"
if
REQUEST
is
not
None
:
return
self
.
manage_main
(
self
,
REQUEST
,
manage_tabs_message
=
message
)
def
manage_afterAdd
(
self
,
item
,
container
):
self
.
index_object
()
...
...
@@ -81,7 +81,7 @@ class CatalogAware:
def
getPath
(
self
):
"""Return the physical path for an object."""
return
'/'
.
join
(
self
.
getPhysicalPath
())
def
summary
(
self
,
num
=
200
):
"""Return a summary of the text content of the object."""
if
not
hasattr
(
self
,
'text_content'
):
...
...
@@ -133,11 +133,3 @@ class CatalogPathAware(CatalogAware):
nontrivial, we don't want to spend a lot of time on ZClasses, and
this works.
"""
lib/python/Products/ZCatalog/IZCatalog.py
View file @
2639fcb7
...
...
@@ -2,17 +2,17 @@
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
##############################################################################
"""
$Id: IZCatalog.py,v 1.
2 2002/08/14 19:10:14 caseman
Exp $
$Id: IZCatalog.py,v 1.
3 2002/08/14 22:25:15 mj
Exp $
"""
from
Interface
import
Interface
...
...
@@ -35,20 +35,20 @@ class IZCatalog(Interface):
Keyword -- Keyword indexes index sequences of values. The index
can be used to search for objects that match one or more of the
search terms.
Path -- Path indexes index URI paths. They allow you to find objects
based on their placement in a hierarchy.
Date -- Date indexes index date and type data. They are a type of field
index specifically optimized for indexing dates.
Date Range -- Date range indexes index time intervals. They are designed
for efficient searching of dates falling between two boundaries
(such as effective / expiration dates).
Topic -- Topic indexes store prefiltered sets of documents. They are used
to optimize complex queries into a single fast query by prefiltering
documents by an expression
to optimize complex queries into a single fast query by prefiltering
documents by an expression
The ZCatalog can maintain a table of extra data about cataloged
objects. This information can be used on search result pages to
...
...
@@ -61,7 +61,7 @@ class IZCatalog(Interface):
ZCatalog does not store references to the objects themselves, but
rather to a unique identifier that defines how to get to the
object. In Zope, this unique identifier is the object's relative
path to the ZCatalog (since two Zope objects cannot have the same
path to the ZCatalog (since two Zope objects cannot have the same
URL, this is an excellent unique qualifier in Zope).
"""
...
...
@@ -108,11 +108,11 @@ class IZCatalog(Interface):
def
index_objects
():
"""Returns a sequence of actual index objects.
NOTE: This returns unwrapped indexes! You should probably use
getIndexObjects instead. Some indexes expect to be wrapped.
"""
def
getIndexObjects
():
"""Returns a list of acquisition wrapped index objects
"""
...
...
@@ -184,7 +184,7 @@ class IZCatalog(Interface):
documented in The Zope Book.
"""
def
__call__
(
REQUEST
=
None
,
**
kw
):
"""Search the catalog, the same way as 'searchResults'.
"""
...
...
lib/python/Products/ZCatalog/Lazy.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''$Id: Lazy.py,v 1.
6 2001/11/28 15:51:09 matt
Exp $'''
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
__doc__
=
'''$Id: Lazy.py,v 1.
7 2002/08/14 22:25:15 mj
Exp $'''
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
class
Lazy
:
...
...
@@ -20,7 +20,7 @@ class Lazy:
__allow_access_to_unprotected_subobjects__
=
1
def
__repr__
(
self
):
return
`list(self)`
def
__len__
(
self
):
try
:
return
self
.
_len
...
...
@@ -62,7 +62,7 @@ class Lazy:
seq
.
append
(
other
)
return
LazyCat
(
seq
)
def
__getslice__
(
self
,
i1
,
i2
):
r
=
[]
for
i
in
xrange
(
i1
,
i2
):
...
...
@@ -75,7 +75,7 @@ class Lazy:
class
LazyCat
(
Lazy
):
# Lazy concatenation of one or more sequences. Should be handy
# for accessing small parts of big searches.
def
__init__
(
self
,
sequences
,
length
=
None
):
self
.
_seq
=
sequences
self
.
_data
=
[]
...
...
lib/python/Products/ZCatalog/ZCatalog.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""ZCatalog product"""
...
...
@@ -46,7 +46,7 @@ def manage_addZCatalog(self, id, title,
"""Add a ZCatalog object
"""
id
=
str
(
id
)
title
=
str
(
title
)
title
=
str
(
title
)
c
=
ZCatalog
(
id
,
title
,
vocab_id
,
self
)
self
.
_setObject
(
id
,
c
)
if
REQUEST
is
not
None
:
...
...
@@ -59,13 +59,13 @@ class ZCatalog(Folder, Persistent, Implicit):
"""ZCatalog object
A ZCatalog contains arbirary index like references to Zope
objects. ZCatalog's can index either 'Field' values of object, or
objects. ZCatalog's can index either 'Field' values of object, or
'Text' values.
ZCatalog does not store references to the objects themselves, but
rather to a unique identifier that defines how to get to the
object. In Zope, this unique idenfier is the object's relative
path to the ZCatalog (since two Zope object's cannot have the same
path to the ZCatalog (since two Zope object's cannot have the same
URL, this is an excellent unique qualifier in Zope).
Most of the dirty work is done in the _catalog object, which is an
...
...
@@ -92,13 +92,13 @@ class ZCatalog(Folder, Persistent, Implicit):
'action'
:
'manage_catalogIndexes'
,
'help'
:
(
'ZCatalog'
,
'ZCatalog_Indexes.stx'
)},
{
'label'
:
'Metadata'
,
# TAB: Metadata
'action'
:
'manage_catalogSchema'
,
'action'
:
'manage_catalogSchema'
,
'help'
:(
'ZCatalog'
,
'ZCatalog_MetaData-Table.stx'
)},
{
'label'
:
'Find Objects'
,
# TAB: Find Objects
'action'
:
'manage_catalogFind'
,
'action'
:
'manage_catalogFind'
,
'help'
:(
'ZCatalog'
,
'ZCatalog_Find-Items-to-ZCatalog.stx'
)},
{
'label'
:
'Advanced'
,
# TAB: Advanced
'action'
:
'manage_catalogAdvanced'
,
'action'
:
'manage_catalogAdvanced'
,
'help'
:(
'ZCatalog'
,
'ZCatalog_Advanced.stx'
)},
{
'label'
:
'Undo'
,
# TAB: Undo
'action'
:
'manage_UndoForm'
,
...
...
@@ -116,19 +116,19 @@ class ZCatalog(Folder, Persistent, Implicit):
(
'Manage ZCatalog Entries'
,
[
'manage_catalogObject'
,
'manage_uncatalogObject'
,
'catalog_object'
,
'uncatalog_object'
,
'refreshCatalog'
,
'manage_catalogView'
,
'manage_catalogFind'
,
'manage_catalogSchema'
,
'manage_catalogIndexes'
,
'manage_catalogAdvanced'
,
'manage_objectInformation'
,
'manage_catalogReindex'
,
'manage_catalogFoundItems'
,
'manage_catalogClear'
,
'manage_addColumn'
,
'manage_delColumn'
,
'manage_addIndex'
,
'manage_delIndex'
,
'manage_clearIndex'
,
'manage_reindexIndex'
,
'manage_main'
,
'availableSplitters'
,
# these two are deprecated:
'manage_delColumns'
,
'manage_deleteIndex'
],
],
[
'Manager'
]),
(
'Search ZCatalog'
,
...
...
@@ -136,7 +136,7 @@ class ZCatalog(Folder, Persistent, Implicit):
'getpath'
,
'schema'
,
'indexes'
,
'index_objects'
,
'getIndexObjects'
'all_meta_types'
,
'valid_roles'
,
'resolve_url'
,
'getobject'
],
[
'Anonymous'
,
'Manager'
]),
[
'Anonymous'
,
'Manager'
]),
)
...
...
@@ -154,21 +154,21 @@ class ZCatalog(Folder, Persistent, Implicit):
threshold
=
10000
_v_total
=
0
_v_transaction
=
None
def
__init__
(
self
,
id
,
title
=
''
,
vocab_id
=
None
,
container
=
None
):
# ZCatalog no longer cares about vocabularies
# so the vocab_id argument is ignored (Casey)
if
container
is
not
None
:
self
=
self
.
__of__
(
container
)
self
.
id
=
id
self
.
title
=
title
# vocabulary and vocab_id are left for backwards
# vocabulary and vocab_id are left for backwards
# compatibility only, they are not used anymore
self
.
vocabulary
=
None
self
.
vocab_id
=
''
self
.
vocab_id
=
''
self
.
threshold
=
10000
self
.
_v_total
=
0
...
...
@@ -176,8 +176,8 @@ class ZCatalog(Folder, Persistent, Implicit):
def
__len__
(
self
):
return
len
(
self
.
_catalog
)
# getVocabulary method is no longer supported
# def getVocabulary(self):
# """ more ack! """
...
...
@@ -200,7 +200,7 @@ class ZCatalog(Folder, Persistent, Implicit):
self
.
threshold
=
None
else
:
self
.
threshold
=
10000
RESPONSE
.
redirect
(
URL1
+
'/manage_catalogAdvanced?manage_tabs_message=Catalog%20Changed'
)
...
...
@@ -210,12 +210,12 @@ class ZCatalog(Folder, Persistent, Implicit):
if
urls
:
if
isinstance
(
urls
,
types
.
StringType
):
urls
=
(
urls
,)
for
url
in
urls
:
obj
=
self
.
resolve_path
(
url
)
if
not
obj
:
obj
=
self
.
resolve_url
(
url
,
REQUEST
)
if
obj
is
not
None
:
if
obj
is
not
None
:
self
.
catalog_object
(
obj
,
url
)
RESPONSE
.
redirect
(
...
...
@@ -248,14 +248,14 @@ class ZCatalog(Folder, Persistent, Implicit):
elapse
=
time
.
time
()
-
elapse
c_elapse
=
time
.
clock
()
-
c_elapse
RESPONSE
.
redirect
(
URL1
+
'/manage_catalogAdvanced?manage_tabs_message='
+
urllib
.
quote
(
'Catalog Updated
\
n
'
'Total time: %s
\
n
'
'Total CPU time: %s'
%
(
`elapse`
,
`c_elapse`
)))
def
refreshCatalog
(
self
,
clear
=
0
):
""" re-index everything we can find """
...
...
@@ -289,18 +289,18 @@ class ZCatalog(Folder, Persistent, Implicit):
obj_expr
=
None
,
obj_mtime
=
None
,
obj_mspec
=
None
,
obj_roles
=
None
,
obj_permission
=
None
):
""" Find object according to search criteria and Catalog them
"""
elapse
=
time
.
time
()
c_elapse
=
time
.
clock
()
words
=
0
obj
=
REQUEST
.
PARENTS
[
1
]
path
=
'/'
.
join
(
obj
.
getPhysicalPath
())
results
=
self
.
ZopeFindAndApply
(
obj
,
obj_metatypes
=
obj_metatypes
,
obj_ids
=
obj_ids
,
...
...
@@ -317,16 +317,16 @@ class ZCatalog(Folder, Persistent, Implicit):
elapse
=
time
.
time
()
-
elapse
c_elapse
=
time
.
clock
()
-
c_elapse
RESPONSE
.
redirect
(
URL1
+
'/manage_catalogView?manage_tabs_message='
+
urllib
.
quote
(
'Catalog Updated
\
n
'
'Total time: %s
\
n
'
'Total CPU time: %s'
'Total CPU time: %s'
%
(
`elapse`
,
`c_elapse`
))
)
def
manage_addColumn
(
self
,
name
,
REQUEST
=
None
,
RESPONSE
=
None
,
URL1
=
None
):
""" add a column """
...
...
@@ -351,7 +351,7 @@ class ZCatalog(Folder, Persistent, Implicit):
"
\
n
"
"Please use instead the manage_delColumn method.
\
n
"
,
DeprecationWarning
)
self
.
manage_delColumn
(
names
,
REQUEST
=
REQUEST
,
RESPONSE
=
RESPONSE
,
URL1
=
URL1
)
...
...
@@ -360,7 +360,7 @@ class ZCatalog(Folder, Persistent, Implicit):
""" delete a column or some columns """
if
isinstance
(
names
,
types
.
StringType
):
names
=
(
names
,)
for
name
in
names
:
self
.
delColumn
(
name
)
...
...
@@ -379,7 +379,7 @@ class ZCatalog(Folder, Persistent, Implicit):
RESPONSE
.
redirect
(
URL1
+
'/manage_catalogIndexes?manage_tabs_message=Index%20Added'
)
def
manage_deleteIndex
(
self
,
ids
=
None
,
REQUEST
=
None
,
RESPONSE
=
None
,
URL1
=
None
):
...
...
@@ -395,7 +395,7 @@ class ZCatalog(Folder, Persistent, Implicit):
"
\
n
"
"Please use instead the manage_delIndex method.
\
n
"
,
DeprecationWarning
)
self
.
manage_delIndex
(
ids
=
ids
,
REQUEST
=
REQUEST
,
RESPONSE
=
RESPONSE
,
URL1
=
URL1
)
...
...
@@ -413,7 +413,7 @@ class ZCatalog(Folder, Persistent, Implicit):
for
name
in
ids
:
self
.
delIndex
(
name
)
if
REQUEST
and
RESPONSE
:
RESPONSE
.
redirect
(
URL1
+
...
...
@@ -433,7 +433,7 @@ class ZCatalog(Folder, Persistent, Implicit):
for
name
in
ids
:
self
.
clearIndex
(
name
)
if
REQUEST
and
RESPONSE
:
RESPONSE
.
redirect
(
URL1
+
...
...
@@ -441,7 +441,7 @@ class ZCatalog(Folder, Persistent, Implicit):
def
reindexIndex
(
self
,
name
,
REQUEST
):
paths
=
tuple
(
self
.
_catalog
.
paths
.
values
())
for
p
in
paths
:
...
...
@@ -449,7 +449,7 @@ class ZCatalog(Folder, Persistent, Implicit):
if
not
obj
:
obj
=
self
.
resolve_url
(
p
,
REQUEST
)
if
obj
is
not
None
:
self
.
catalog_object
(
obj
,
p
,
idxs
=
[
name
])
self
.
catalog_object
(
obj
,
p
,
idxs
=
[
name
])
def
manage_reindexIndex
(
self
,
ids
=
None
,
REQUEST
=
None
,
RESPONSE
=
None
,
...
...
@@ -459,7 +459,7 @@ class ZCatalog(Folder, Persistent, Implicit):
return
MessageDialog
(
title
=
'No items specified'
,
message
=
'No items were specified!'
,
action
=
"./manage_catalogIndexes"
,)
if
isinstance
(
ids
,
types
.
StringType
):
ids
=
(
ids
,)
...
...
@@ -498,7 +498,7 @@ class ZCatalog(Folder, Persistent, Implicit):
# indexing code. We throw away the result of the call to
# catalogObject (which is a word count), because it's
# worthless to us here.
if
self
.
threshold
is
not
None
:
# figure out whether or not to commit a subtransaction.
t
=
id
(
get_transaction
())
...
...
@@ -555,7 +555,7 @@ class ZCatalog(Folder, Persistent, Implicit):
def
getIndexDataForRID
(
self
,
rid
):
"""return the current index contents for the specific rid"""
return
self
.
_catalog
.
getIndexDataForRID
(
rid
)
def
schema
(
self
):
return
self
.
_catalog
.
schema
.
keys
()
...
...
@@ -566,7 +566,7 @@ class ZCatalog(Folder, Persistent, Implicit):
# This method returns unwrapped indexes!
# You should probably use getIndexObjects instead
return
self
.
_catalog
.
indexes
.
values
()
def
getIndexObjects
(
self
):
# Return a list of wrapped(!) indexes
catalog
=
self
.
_catalog
...
...
@@ -596,9 +596,9 @@ class ZCatalog(Folder, Persistent, Implicit):
def
searchResults
(
self
,
REQUEST
=
None
,
used
=
None
,
**
kw
):
"""Search the catalog according to the ZTables search interface.
Search terms can be passed in the REQUEST or as keyword
arguments.
arguments.
"""
return
self
.
_catalog
.
searchResults
(
REQUEST
,
used
,
**
kw
)
...
...
@@ -608,7 +608,7 @@ class ZCatalog(Folder, Persistent, Implicit):
## this stuff is so the find machinery works
meta_types
=
()
# Sub-object types that are specific to this object
# Dont need this anymore -- we inherit from object manager
#def all_meta_types(self):
# pmt=()
...
...
@@ -649,7 +649,7 @@ class ZCatalog(Folder, Persistent, Implicit):
This is a *great* hack. Zope find just doesn't do what we
need here; the ability to apply a method to all the objects
*as they're found* and the need to pass the object's path into
*as they're found* and the need to pass the object's path into
that method.
"""
...
...
@@ -659,7 +659,7 @@ class ZCatalog(Folder, Persistent, Implicit):
if
obj_metatypes
and
'all'
in
obj_metatypes
:
obj_metatypes
=
None
if
obj_mtime
and
type
(
obj_mtime
)
==
type
(
's'
):
obj_mtime
=
DateTime
(
obj_mtime
).
timeTime
()
...
...
@@ -668,7 +668,7 @@ class ZCatalog(Folder, Persistent, Implicit):
if
obj_roles
and
type
(
obj_roles
)
is
type
(
's'
):
obj_roles
=
[
obj_roles
]
if
obj_expr
:
# Setup expr machinations
md
=
td
()
...
...
@@ -690,7 +690,7 @@ class ZCatalog(Folder, Persistent, Implicit):
for
id
,
ob
in
items
:
if
pre
:
p
=
"%s/%s"
%
(
pre
,
id
)
else
:
p
=
id
dflag
=
0
if
hasattr
(
ob
,
'_p_changed'
)
and
(
ob
.
_p_changed
==
None
):
dflag
=
1
...
...
@@ -723,7 +723,7 @@ class ZCatalog(Folder, Persistent, Implicit):
else
:
add_result
((
p
,
ob
))
dflag
=
0
if
search_sub
and
hasattr
(
bs
,
'objectItems'
):
self
.
ZopeFindAndApply
(
ob
,
obj_ids
,
obj_metatypes
,
obj_searchterm
,
obj_expr
,
...
...
@@ -737,7 +737,7 @@ class ZCatalog(Folder, Persistent, Implicit):
return
result
def
resolve_url
(
self
,
path
,
REQUEST
):
"""
"""
Attempt to resolve a url into an object in the Zope
namespace. The url may be absolute or a catalog path
style url. If no object is found, None is returned.
...
...
@@ -745,12 +745,12 @@ class ZCatalog(Folder, Persistent, Implicit):
"""
script
=
REQUEST
.
script
if
path
.
find
(
script
)
!=
0
:
path
=
'%s/%s'
%
(
script
,
path
)
path
=
'%s/%s'
%
(
script
,
path
)
try
:
return
REQUEST
.
resolve_url
(
path
)
except
:
pass
def
resolve_path
(
self
,
path
):
"""
"""
Attempt to resolve a url into an object in the Zope
namespace. The url may be absolute or a catalog path
style url. If no object is found, None is returned.
...
...
@@ -813,7 +813,7 @@ class ZCatalog(Folder, Persistent, Implicit):
def
manage_convertIndex
(
self
,
ids
,
REQUEST
=
None
,
RESPONSE
=
None
,
URL1
=
None
):
"""convert old-style indexes to new-style indexes"""
from
Products.PluginIndexes.KeywordIndex
import
KeywordIndex
from
Products.PluginIndexes.KeywordIndex
import
KeywordIndex
from
Products.PluginIndexes.FieldIndex
import
FieldIndex
from
Products.PluginIndexes.TextIndex
import
TextIndex
...
...
@@ -845,10 +845,10 @@ class ZCatalog(Folder, Persistent, Implicit):
'/manage_main?'
'manage_tabs_message='
'No%20indexes%20found%20to%20be%20converted'
)
#
# Indexing methods
# Indexing methods
#
def
addIndex
(
self
,
name
,
type
,
extra
=
None
):
...
...
@@ -861,7 +861,7 @@ class ZCatalog(Folder, Persistent, Implicit):
p
=
None
for
prod
in
products
:
if
prod
[
'name'
]
==
type
:
if
prod
[
'name'
]
==
type
:
p
=
prod
break
...
...
@@ -882,7 +882,7 @@ class ZCatalog(Folder, Persistent, Implicit):
index
=
apply
(
base
,(
name
,),
{
"extra"
:
extra
,
"caller"
:
self
})
else
:
index
=
base
(
name
,
self
)
self
.
_catalog
.
addIndex
(
name
,
index
)
...
...
@@ -899,7 +899,7 @@ class ZCatalog(Folder, Persistent, Implicit):
def
delColumn
(
self
,
name
):
return
self
.
_catalog
.
delColumn
(
name
)
Globals
.
default__class_init__
(
ZCatalog
)
...
...
@@ -924,13 +924,13 @@ def expr_match(ob, ed, c=InstanceDict, r=0):
def
mtime_match
(
ob
,
t
,
q
,
fn
=
hasattr
):
if
not
fn
(
ob
,
'_p_mtime'
):
return
0
return
0
return
q
==
'<'
and
(
ob
.
_p_mtime
<
t
)
or
(
ob
.
_p_mtime
>
t
)
def
role_match
(
ob
,
permission
,
roles
,
lt
=
type
([]),
tt
=
type
(())):
pr
=
[]
fn
=
pr
.
append
while
1
:
if
hasattr
(
ob
,
permission
):
p
=
getattr
(
ob
,
permission
)
...
...
lib/python/Products/ZCatalog/ZCatalogIndexes.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""$Id: ZCatalogIndexes.py,v 1.
7 2002/06/28 17:25:23 caseman
Exp $
"""$Id: ZCatalogIndexes.py,v 1.
8 2002/08/14 22:25:15 mj
Exp $
"""
from
Globals
import
DTMLFile
,
InitializeClass
...
...
@@ -42,19 +42,19 @@ class ZCatalogIndexes (IFAwareObjectManager, Folder, Persistent, Implicit):
meta_type
=
"ZCatalogIndex"
manage_options
=
()
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
manage_zcatalog_indexes
)
security
.
setPermissionDefault
(
manage_zcatalog_indexes
,
(
'Manager'
,))
security
.
declareProtected
(
manage_zcatalog_indexes
,
'addIndexForm'
)
addIndexForm
=
DTMLFile
(
'dtml/addIndexForm'
,
globals
())
# You no longer manage the Indexes here, they are managed from ZCatalog
def
manage_main
(
self
,
REQUEST
,
RESPONSE
):
"""Redirect to the parent where the management screen now lives"""
RESPONSE
.
redirect
(
'../manage_catalogIndexes'
)
manage_workspace
=
manage_main
#
...
...
@@ -62,7 +62,7 @@ class ZCatalogIndexes (IFAwareObjectManager, Folder, Persistent, Implicit):
#
# base accessors loop back through our dictionary interface
def
_setOb
(
self
,
id
,
object
):
def
_setOb
(
self
,
id
,
object
):
indexes
=
self
.
aq_parent
.
_catalog
.
indexes
indexes
[
id
]
=
object
self
.
aq_parent
.
_indexes
=
indexes
...
...
@@ -74,14 +74,14 @@ class ZCatalogIndexes (IFAwareObjectManager, Folder, Persistent, Implicit):
self
.
aq_parent
.
_indexes
=
indexes
#self.aq_parent._p_changed = 1
def
_getOb
(
self
,
id
,
default
=
_marker
):
def
_getOb
(
self
,
id
,
default
=
_marker
):
indexes
=
self
.
aq_parent
.
_catalog
.
indexes
if
default
is
_marker
:
return
indexes
.
get
(
id
)
return
indexes
.
get
(
id
,
default
)
security
.
declareProtected
(
manage_zcatalog_indexes
,
'objectIds'
)
def
objectIds
(
self
,
spec
=
None
):
indexes
=
self
.
aq_parent
.
_catalog
.
indexes
if
spec
is
not
None
:
if
type
(
spec
)
==
type
(
's'
):
...
...
@@ -121,15 +121,13 @@ InitializeClass(ZCatalogIndexes)
class
OldCatalogWrapperObject
(
SimpleItem
,
Implicit
):
manage_options
=
(
{
'label'
:
'Settings'
,
{
'label'
:
'Settings'
,
'action'
:
'manage_main'
},
)
manage_main
=
DTMLFile
(
'dtml/manageOldindex'
,
globals
())
manage_main
.
_setName
(
'manage_main'
)
manage_workspace
=
manage_main
def
__init__
(
self
,
o
):
self
.
index
=
o
lib/python/Products/ZCatalog/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
"""ZCatalog product"""
...
...
@@ -26,7 +26,7 @@ createZClassForBase( CatalogPathAwareness.CatalogPathAware, globals()
def
initialize
(
context
):
context
.
registerClass
(
ZCatalog
.
ZCatalog
,
ZCatalog
.
ZCatalog
,
permission
=
'Add ZCatalogs'
,
constructors
=
(
ZCatalog
.
manage_addZCatalogForm
,
ZCatalog
.
manage_addZCatalog
),
...
...
@@ -40,7 +40,6 @@ def initialize(context):
Vocabulary
.
manage_addVocabulary
),
icon
=
'www/Vocabulary.gif'
,
)
context
.
registerHelp
()
context
.
registerHelpTitle
(
'Zope Help'
)
lib/python/Products/ZCatalog/help/Vocabulary.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
def
manage_addVocabulary
(
id
,
title
,
globbing
=
None
,
REQUEST
=
None
):
"""
Add a Vocabulary object to an ObjectManager.
"""
...
...
@@ -28,7 +28,7 @@ class Vocabulary:
A Vocabulary manages words and language rules for text indexing.
Text indexing is done by the ZCatalog and other third party
Products.
"""
__constructor__
=
manage_addVocabulary
...
...
@@ -39,7 +39,7 @@ class Vocabulary:
Query Vocabulary for words matching pattern.
"""
def
insert
(
word
):
"""
...
...
@@ -47,12 +47,10 @@ class Vocabulary:
Insert a word in the Vocabulary.
"""
def
words
():
"""
Return list of words.
"""
lib/python/Products/ZCatalog/help/ZCatalog.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
def
manage_addZCatalog
(
id
,
title
,
vocab_id
=
None
):
...
...
@@ -43,20 +43,20 @@ class ZCatalog:
Keyword -- Keyword indexes index sequences of values. The index
can be used to search for objects that match one or more of the
search terms.
Path -- Path indexes index URI paths. They allow you to find objects
based on their placement in a hierarchy.
Date -- Date indexes index date and type data. They are a type of field
index specifically optimized for indexing dates.
Date Range -- Date range indexes index time intervals. They are designed
for efficient searching of dates falling between two boundaries
(such as effective / expiration dates).
Topic -- Topic indexes store prefiltered sets of documents. They are used
to optimize complex queries into a single fast query by prefiltering
documents by an expression
to optimize complex queries into a single fast query by prefiltering
documents by an expression
The ZCatalog can maintain a table of extra data about cataloged
objects. This information can be used on search result pages to
...
...
@@ -69,7 +69,7 @@ class ZCatalog:
ZCatalog does not store references to the objects themselves, but
rather to a unique identifier that defines how to get to the
object. In Zope, this unique identifier is the object's relative
path to the ZCatalog (since two Zope objects cannot have the same
path to the ZCatalog (since two Zope objects cannot have the same
URL, this is an excellent unique qualifier in Zope).
"""
...
...
@@ -99,18 +99,18 @@ class ZCatalog:
def
getpath
(
rid
):
"""
Return the path to a cataloged object given a
'data_record_id_'
"""
def
getobject
(
rid
,
REQUEST
=
None
):
"""
Return a cataloged object given a 'data_record_id_'
"""
def
schema
():
...
...
@@ -123,24 +123,24 @@ class ZCatalog:
def
index_objects
():
"""
Returns a sequence of actual index objects.
NOTE: This returns unwrapped indexes! You should probably use
getIndexObjects instead. Some indexes expect to be wrapped.
"""
def
getIndexObjects
():
"""
Returns a list of acquisition wrapped index objects
"""
def
searchResults
(
REQUEST
=
None
,
**
kw
):
"""
Search the catalog. Search terms can be passed in the REQUEST
or as keyword arguments.
...
...
@@ -206,9 +206,8 @@ class ZCatalog:
documented in The Zope Book.
"""
def
__call__
(
REQUEST
=
None
,
**
kw
):
"""
Search the catalog, the same way as 'searchResults'.
"""
lib/python/Products/ZCatalog/regressiontests/keywords.py
View file @
2639fcb7
...
...
@@ -8,41 +8,39 @@ class Keywords:
def
__init__
(
self
):
self
.
kw
=
[]
def
build
(
self
,
mbox
,
limit
):
mb
=
mailbox
.
UnixMailbox
(
open
(
mbox
))
msg
=
mb
.
next
()
while
msg
and
len
(
self
.
kw
)
<
limit
:
sub
=
msg
.
dict
.
get
(
"subject"
,
""
).
split
(
' '
)
for
f
in
sub
:
ok
=
1
for
c
in
f
:
for
c
in
f
:
if
not
c
in
string
.
letters
:
ok
=
0
if
ok
==
1
and
not
f
in
self
.
kw
:
self
.
kw
.
append
(
f
)
msg
=
mb
.
next
()
P
=
cPickle
.
Pickler
(
open
(
'data/keywords'
,
'w'
))
P
.
dump
(
self
.
kw
)
def
reload
(
self
):
P
=
cPickle
.
Unpickler
(
open
(
'data/keywords'
,
'r'
))
self
.
kw
=
P
.
load
()
def
keywords
(
self
):
return
self
.
kw
if
__name__
==
"__main__"
:
k
=
Keywords
()
k
.
build
(
"/home/andreas/zope.mbox"
,
1000
)
lib/python/Products/ZCatalog/regressiontests/loadmail.py
View file @
2639fcb7
...
...
@@ -89,13 +89,13 @@ Commands:
3.41 (0, 1)
as described above.
pdebug command args
Run one of the other commands in the Python debugger.
sample suite of tests::
cd lib/python
python Products/ZCatalog/regressiontests/loadmail.py base ~/zope.mbox 1000
python Products/ZCatalog/regressiontests/loadmail.py index 100
...
...
@@ -162,7 +162,7 @@ def loadmail(dest, name, mbox, printstat=0, max=-1):
dest
.
manage_addFolder
(
name
)
else
:
Products
.
BTreeFolder
.
BTreeFolder
.
manage_addBTreeFolder
(
dest
,
name
)
dest
=
getattr
(
dest
,
name
)
f
=
open
(
mbox
)
mb
=
mailbox
.
UnixMailbox
(
f
)
...
...
@@ -186,7 +186,7 @@ def loadmail(dest, name, mbox, printstat=0, max=-1):
message
=
mb
.
next
()
dest
.
number_of_messages
=
i
print
print
get_transaction
().
commit
()
def
loadinc
(
name
,
mb
,
printstat
=
0
,
max
=
99999999
,
wait
=
1
):
...
...
@@ -233,8 +233,8 @@ def loadinc(name, mb, printstat=0, max=99999999, wait=1):
doc
=
app
=
mdest
=
0
jar
.
close
()
if
printstat
:
sys
.
stdout
.
write
(
"
\
t
%s
\
t
%s
\
t
\
n
"
%
(
i
,
f
.
tell
()))
sys
.
stdout
.
flush
()
return
rconflicts
,
wconflicts
...
...
@@ -259,7 +259,7 @@ def indexf(app):
r
.
PARENTS
=
[
0
,
app
.
mail
]
app
.
cat
.
manage_catalogFoundItems
(
r
,
r
,
''
,
''
,[
'DTML Document'
])
get_transaction
().
commit
()
def
index
():
os
.
environ
[
'STUPID_LOG_FILE'
]
=
''
os
.
environ
[
'STUPID_LOG_SEVERITY'
]
=
'-111'
...
...
@@ -276,16 +276,16 @@ def index():
import
PLexicon
from
Products.ZCTextIndex.Lexicon
\
import
Splitter
,
CaseNormalizer
app
.
cat
.
_setObject
(
'lex'
,
PLexicon
(
'lex'
,
''
,
Splitter
(),
CaseNormalizer
())
)
class
extra
:
doc_attr
=
'PrincipiaSearchSource'
lexicon_id
=
'lex'
index_type
=
'Okapi BM25 Rank'
app
.
cat
.
addIndex
(
'PrincipiaSearchSource'
,
'ZCTextIndex'
,
extra
)
get_transaction
().
commit
()
...
...
@@ -377,7 +377,7 @@ def inc():
print
t
,
c
,
size
,
mem
#hist("%s-%s-%s" % (omin, count, threads))
Zope
.
DB
.
close
()
words
=
[
'banishment'
,
'indirectly'
,
'imprecise'
,
'peeks'
,
...
...
@@ -608,7 +608,7 @@ def incedit(edits, wait, ndel=20, nins=20):
doc
=
app
=
0
jar
.
close
()
return
rconflicts
,
wconflicts
def
edit
():
...
...
@@ -671,7 +671,7 @@ def edit():
print
t
,
c
,
size
,
mem
#hist("e%s" % (threads))
Zope
.
DB
.
close
()
def
VmSize
():
...
...
lib/python/Products/ZCatalog/regressiontests/regressionCatalog.py
View file @
2639fcb7
...
...
@@ -59,28 +59,28 @@ class testZODB:
""" some wrapper stuff around ZODB """
def
__init__
(
self
,
file
=
"data/work/Data.fs"
,
open
=
1
):
self
.
db
=
ZODB
.
DB
(
ZODB
.
FileStorage
.
FileStorage
(
file
)
)
if
open
==
1
:
self
.
connection
=
self
.
db
.
open
()
self
.
root
=
self
.
connection
.
root
()
def
write
(
self
,
name
,
obj
):
self
.
root
[
name
]
=
obj
get_transaction
().
commit
()
def
read
(
self
,
name
):
return
self
.
root
[
name
]
def
__del__
(
self
):
self
.
db
.
close
()
class
testCatalog
(
Persistence
.
Persistent
,
unittest
.
TestCase
):
""" Wrapper around the catalog stuff """
...
...
@@ -89,7 +89,7 @@ class testCatalog(Persistence.Persistent,unittest.TestCase):
self
.
num_files
=
0
self
.
keywords
=
[]
self
.
maxfiles
=
maxfiles
self
.
_vocabulary
=
Vocabulary
.
Vocabulary
(
'Vocabulary'
,
'Vocabulary'
,
globbing
=
1
)
self
.
_catalog
=
ZCatalog
.
ZCatalog
(
"zcatalog"
)
...
...
@@ -118,7 +118,7 @@ class testCatalog(Persistence.Persistent,unittest.TestCase):
try
:
self
.
catMessage
(
msg
)
self
.
msg_ids
.
append
(
msg
.
dict
[
"message-id"
])
except
:
except
:
msg
=
mb
.
next
()
continue
...
...
@@ -133,20 +133,20 @@ class testCatalog(Persistence.Persistent,unittest.TestCase):
msg
=
mb
.
next
()
continue
for
s
in
sub
:
for
s
in
sub
:
if
not
s
in
self
.
keywords
:
self
.
keywords
.
append
(
s
)
self
.
_catalog
.
aq_parent
=
None
def
catMessage
(
self
,
m
):
self
.
_catalog
.
catalogObject
(
testMessage
(
m
)
,
self
.
_catalog
.
catalogObject
(
testMessage
(
m
)
,
m
.
dict
[
"message-id"
]
)
def
uncatMessage
(
self
,
uid
):
self
.
_catalog
.
uncatalogObject
(
uid
)
class
testMessage
(
ExtensionClass
.
Base
):
def
__init__
(
self
,
msg
,
modify_doc
=
0
):
...
...
@@ -159,28 +159,28 @@ class testMessage(ExtensionClass.Base):
if
modify_doc
!=
0
:
self
.
keywords
=
map
(
self
.
reverse
,
self
.
keywords
)
self
.
file_id
=
msg
.
dict
.
get
(
"message-id"
,
""
)
self
.
length
=
len
(
str
(
msg
))
date
=
msg
.
dict
.
get
(
"date"
,
""
)
try
:
self
.
date
=
time
.
mktime
(
rfc822
.
parsedate
(
date
)[:
9
])
except
:
pass
except
:
pass
def
reverse
(
self
,
s
):
l
=
list
(
s
)
l
.
reverse
()
return
string
.
join
(
l
,
""
)
def
__del__
(
self
):
pass
pass
class
BuildEnv
(
dispatcher
.
Dispatcher
,
unittest
.
TestCase
):
""" build environment """
""" build environment """
def
__init__
(
self
,
func
,
*
args
,
**
kw
):
...
...
@@ -190,16 +190,16 @@ class BuildEnv(dispatcher.Dispatcher,unittest.TestCase):
self
.
init_phase
=
0
self
.
setlog
(
open
(
"dispatcher.log"
,
"a"
)
)
self
.
logn
(
'treads=%d searchiterations=%d'
%
self
.
logn
(
'treads=%d searchiterations=%d'
%
(
numThreads
,
searchIterations
))
self
.
logn
(
'updateiterations=%d maxfiles=%d'
%
self
.
logn
(
'updateiterations=%d maxfiles=%d'
%
(
updateIterations
,
maxFiles
))
#############################################################
#############################################################
# Build up ZODB
#############################################################
#############################################################
def
buildTestEnvironment
(
self
,
args
,
kw
):
self
.
init_phase
=
1
self
.
dispatcher
(
"funcTestEnvironment"
,(
"funcTestEnvironment"
,
1
,
args
,
kw
))
...
...
@@ -210,13 +210,13 @@ class BuildEnv(dispatcher.Dispatcher,unittest.TestCase):
env
=
self
.
th_setup
()
if
not
os
.
path
.
exists
(
dataDir
):
os
.
makedirs
(
dataDir
)
os
.
system
(
"rm -f %s/*"
%
dataDir
)
zodb
=
testZODB
(
"%s/Data_orig.fs"
%
dataDir
)
print
"parsing and reading mailbox file %s....please wait"
%
mbox
tc
=
testCatalog
(
mbox
,
maxFiles
)
print
"writing Catalog to ZODB"
zodb
.
write
(
"catalog"
,
tc
)
...
...
@@ -224,25 +224,25 @@ class BuildEnv(dispatcher.Dispatcher,unittest.TestCase):
kw
=
keywords
.
Keywords
()
kw
.
build
(
mbox
,
1000
)
print
tc
.
num_files
,
"files read"
print
"Initalization complete"
self
.
th_teardown
(
env
)
class
testSearches
(
dispatcher
.
Dispatcher
,
unittest
.
TestCase
):
""" test searches """
def
__init__
(
self
,
func
,
*
args
,
**
kw
):
unittest
.
TestCase
.
__init__
(
self
,
func
,
args
,
kw
)
unittest
.
TestCase
.
__init__
(
self
,
func
,
args
,
kw
)
dispatcher
.
Dispatcher
.
__init__
(
self
,
func
)
self
.
init_phase
=
0
self
.
setlog
(
open
(
"dispatcher.log"
,
"a"
)
)
def
setUp
(
self
):
...
...
@@ -250,19 +250,19 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
if
not
os
.
path
.
exists
(
"data/work"
):
os
.
makedirs
(
"data/work"
)
assert
os
.
system
(
"cp %s/Data_orig.fs data/work/Data.fs"
%
dataDir
)
==
0
,
\
"Error while replicating original data"
self
.
zodb
=
testZODB
(
"data/work/Data.fs"
,
open
=
0
)
self
.
threads
=
{}
self
.
zodb
=
testZODB
(
"data/work/Data.fs"
,
open
=
0
)
self
.
threads
=
{}
self
.
init_zodb_size
=
self
.
zodb_size
()
kw
=
keywords
.
Keywords
()
kw
.
reload
()
self
.
keywords
=
kw
.
keywords
()
self
.
keywords
=
kw
.
keywords
()
self
.
logn
(
"-"
*
80
)
self
.
logn
(
'treads=%d searchiterations=%d'
%
self
.
logn
(
'treads=%d searchiterations=%d'
%
(
numThreads
,
searchIterations
))
self
.
logn
(
'updateiterations=%d maxfiles=%d'
%
self
.
logn
(
'updateiterations=%d maxfiles=%d'
%
(
updateIterations
,
maxFiles
))
...
...
@@ -270,7 +270,7 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
self
.
log_zodb_size
(
"before"
,
self
.
init_zodb_size
)
self
.
log_zodb_size
(
"after "
,
self
.
zodb_size
())
del
self
.
zodb
self
.
zodb
=
self
.
catalog
=
None
self
.
zodb
=
self
.
catalog
=
None
def
log_zodb_size
(
self
,
s
,
n
):
self
.
logn
(
"Size of ZODB (data/work/Data.fs) %s test : %s"
%
(
s
,
n
)
)
...
...
@@ -285,16 +285,16 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
if
n
<
1024.0
*
1024.0
:
return
"%8.3lf KB"
%
(
1.0
*
n
/
1024.0
)
if
n
<
1024.0
*
1024.0
*
1024.0
:
return
"%8.3lf MB"
%
(
1.0
*
n
/
1024.0
/
1024.0
)
#############################################################
#############################################################
# Fulltext test
#############################################################
#############################################################
def
testFulltextIndex
(
self
,
args
,
kw
):
""" benchmark FulltextIndex """
self
.
dispatcher
(
'funcFulltextIndex'
,
self
.
dispatcher
(
'funcFulltextIndex'
,
(
'funcFulltextIndex'
,
kw
[
"numThreads"
]
,
()
,
{}
)
)
...
...
@@ -311,13 +311,13 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
self
.
th_teardown
(
env
)
#############################################################
#############################################################
# Field index test
#############################################################
#############################################################
def
testFieldIndex
(
self
,
args
,
kw
):
""" benchmark field index"""
self
.
dispatcher
(
'funcFieldIndex'
,
self
.
dispatcher
(
'funcFieldIndex'
,
(
'funcFieldIndex'
,
kw
[
"numThreads"
]
,
()
,
{}
)
)
...
...
@@ -329,21 +329,21 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
env
=
self
.
th_setup
()
for
i
in
range
(
0
,
searchIterations
):
res
=
cat
.
searchResults
(
{
"length"
:
i
}
)
for
r
in
res
:
assert
i
==
r
.
length
,
"%s should have size %d but is %s"
%
\
(
r
.
file_id
,
i
,
r
.
length
)
self
.
th_teardown
(
env
)
#############################################################
#############################################################
# Keyword index test
#############################################################
#############################################################
def
testKeywordIndex
(
self
,
args
,
kw
):
""" benchmark Keyword index"""
self
.
dispatcher
(
'funcKeywordIndex'
,
self
.
dispatcher
(
'funcKeywordIndex'
,
(
'funcKeywordIndex'
,
kw
[
"numThreads"
]
,
()
,
{}
)
)
...
...
@@ -351,22 +351,22 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
""" benchmark KeywordIndex """
cat
,
msg_ids
=
self
.
get_catalog
()
env
=
self
.
th_setup
()
for
kw
in
self
.
keywords
:
res
=
cat
.
searchResults
(
{
"subject"
:
kw
}
)
# assert len(res) != 0 , "Search result for keyword '%s' is empty" % kw
self
.
th_teardown
(
env
)
#############################################################
#############################################################
# Field range index test
#############################################################
#############################################################
def
testFieldRangeIndex
(
self
,
args
,
kw
):
""" benchmark field range index"""
self
.
dispatcher
(
'funcFieldRangeIndex'
,
self
.
dispatcher
(
'funcFieldRangeIndex'
,
(
'funcFieldRangeIndex'
,
kw
[
"numThreads"
]
,
()
,
{}
)
)
...
...
@@ -379,7 +379,7 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
rg
=
[]
for
i
in
range
(
searchIterations
):
m
=
whrandom
.
randint
(
0
,
10000
)
m
=
whrandom
.
randint
(
0
,
10000
)
n
=
m
+
200
rg
.
append
((
m
,
n
))
...
...
@@ -394,13 +394,13 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
#############################################################
#############################################################
# Keyword + range index test
#############################################################
#############################################################
def
testKeywordRangeIndex
(
self
,
args
,
kw
):
""" benchmark Keyword range index"""
self
.
dispatcher
(
'funcKeywordRangeIndex'
,
self
.
dispatcher
(
'funcKeywordRangeIndex'
,
(
'funcKeywordRangeIndex'
,
kw
[
"numThreads"
]
,
()
,
{}
)
)
...
...
@@ -411,15 +411,15 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
rg
=
[]
for
i
in
range
(
len
(
self
.
keywords
)):
m
=
whrandom
.
randint
(
0
,
10000
)
m
=
whrandom
.
randint
(
0
,
10000
)
n
=
m
+
200
rg
.
append
(
(
m
,
n
)
)
env
=
self
.
th_setup
()
results
=
[]
results
=
[]
for
i
in
range
(
len
(
self
.
keywords
)):
results
.
append
(
cat
.
searchResults
(
{
"keywords"
:
self
.
keywords
[
i
],
results
.
append
(
cat
.
searchResults
(
{
"keywords"
:
self
.
keywords
[
i
],
"length"
:
rg
[
i
],
"length_usage"
:
"range:min:max"
}
)
)
...
...
@@ -427,13 +427,13 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
self
.
th_teardown
(
env
)
#############################################################
#############################################################
# Test full reindexing
#############################################################
#############################################################
def
testUpdates
(
self
,
args
,
kw
):
""" benchmark concurrent catalog/uncatalog operations """
self
.
dispatcher
(
"testUpdates"
,
self
.
dispatcher
(
"testUpdates"
,
(
"funcUpdates"
,
kw
[
"numThreads"
]
,
args
,
kw
))
...
...
@@ -463,7 +463,7 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
cat
.
uncatalog_object
(
mid
)
if
kw
.
get
(
"commit"
,
1
)
==
1
:
get_transaction
().
commit
()
get_transaction
().
commit
()
time
.
sleep
(
0.1
)
except
ZODB
.
POSException
.
ConflictError
:
uncat_conflicts
=
uncat_conflicts
+
1
...
...
@@ -472,14 +472,14 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
cat
.
catalog_object
(
obj
,
mid
)
if
kw
.
get
(
"commit"
,
1
)
==
1
:
get_transaction
().
commit
()
get_transaction
().
commit
()
time
.
sleep
(
0.1
)
except
ZODB
.
POSException
.
ConflictError
:
cat_conflicts
=
cat_conflicts
+
1
try
:
get_transaction
().
commit
()
get_transaction
().
commit
()
except
:
pass
...
...
@@ -501,30 +501,30 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
while
msg
and
i
<
numUpdates
:
obj
=
testMessage
(
msg
)
mid
=
msg
.
dict
.
get
(
"message-id"
,
None
)
if
mid
:
dict
[
mid
]
=
obj
dict
[
mid
]
=
obj
i
=
i
+
1
msg
=
mb
.
next
()
return
dict
return
dict
#############################################################
#############################################################
# Test full reindexing
#############################################################
#############################################################
def
testReindexing
(
self
,
args
,
kw
):
""" test reindexing of existing data """
self
.
dispatcher
(
"testReindexing"
,
self
.
dispatcher
(
"testReindexing"
,
(
"funcReindexing"
,
kw
[
"numThreads"
]
,
(
mbox
,
1000
)
,
{}
))
def
testReindexingAndModify
(
self
,
args
,
kw
):
""" test reindexing of existing data but with modifications"""
self
.
dispatcher
(
"testReindexing"
,
self
.
dispatcher
(
"testReindexing"
,
(
"funcReindexing"
,
kw
[
"numThreads"
]
,
(
mbox
,
1000
,
1
)
,
{}
))
...
...
@@ -563,13 +563,13 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
self
.
th_teardown
(
env
,
cat_conflicts
=
cat_conflicts
)
#############################################################
#############################################################
# Test full reindexing
#############################################################
#############################################################
def
testIncrementalIndexing
(
self
,
args
,
kw
):
""" testing incremental indexing """
self
.
dispatcher
(
"testIncrementalIndexing"
,
self
.
dispatcher
(
"testIncrementalIndexing"
,
(
"funcReindexing"
,
kw
[
"numThreads"
],
(
mbox2
,
1000
)
,
{}))
...
...
@@ -581,7 +581,7 @@ class testSearches(dispatcher.Dispatcher,unittest.TestCase):
connection
=
self
.
zodb
.
db
.
open
()
root
=
connection
.
root
()
cat
=
root
[
"catalog"
].
_catalog
cat
=
root
[
"catalog"
].
_catalog
msg_ids
=
root
[
'catalog'
].
msg_ids
return
cat
,
msg_ids
...
...
@@ -594,7 +594,7 @@ def usage(program):
print
"initalize the test catalog: %s -i -f <maximum number files to use> "
%
program
print
"to run the basic tests: %s -b -f <maximum number files to use> "
%
program
print
"to run the advanced tests: %s -a -f <maximum number files to use> "
%
program
def
main
():
...
...
@@ -606,7 +606,7 @@ def main():
optsLst
=
map
(
lambda
x
:
x
[
0
],
opts
)
if
optsLst
==
[]:
usage
(
os
.
path
.
basename
(
sys
.
argv
[
0
]));
sys
.
exit
(
0
)
for
k
,
v
in
opts
:
if
k
in
[
'-h'
,
'--help'
]
:
usage
(
os
.
path
.
basename
(
sys
.
argv
[
0
]));
sys
.
exit
(
0
)
if
k
==
"-f"
:
maxFiles
=
string
.
atoi
(
v
)
...
...
@@ -616,7 +616,7 @@ def main():
if
'-i'
in
optsLst
:
unittest
.
TextTestRunner
().
run
(
get_tests
(
'init'
))
if
'-b'
in
optsLst
:
unittest
.
TextTestRunner
().
run
(
get_tests
(
'bench1'
))
...
...
@@ -680,8 +680,8 @@ def get_tests(what):
testSearches
(
"testReindexingAndModify"
,
numThreads
=
1
),
# testSearches("testUpdates",numThreads=10,numUpdates=100),
)
init_tests
=
(
init_tests
=
(
BuildEnv
(
"buildTestEnvironment"
,
dataDir
,
maxFiles
)
,
)
...
...
@@ -698,13 +698,12 @@ def pdebug():
test_suite
()
def
debug
():
test_suite
().
debug
()
test_suite
().
debug
()
def
pdebug
():
import
pdb
pdb
.
run
(
'debug()'
)
if
__name__
==
'__main__'
:
main
()
main
()
lib/python/Products/ZCatalog/regressiontests/regressionCatalogTiming.py
View file @
2639fcb7
...
...
@@ -51,7 +51,7 @@ class TestTimeIndex(TestCase):
c
.
manage_addIndex
(
'from'
,
'TextIndex'
)
c
.
manage_addIndex
(
'date'
,
'FieldIndex'
)
c
.
manage_addIndex
(
'raw'
,
'TextIndex'
)
def
tearDown
(
self
):
try
:
self
.
app
.
_delObject
(
'catalogtest'
)
except
AttributeError
:
pass
...
...
@@ -61,7 +61,7 @@ class TestTimeIndex(TestCase):
except
AttributeError
:
pass
self
.
app
=
None
del
self
.
app
def
checkTimeBulkIndex
(
self
):
print
c
=
self
.
app
.
catalogtest
.
catalog
...
...
@@ -109,7 +109,7 @@ class TestTimeIndex(TestCase):
assert
len
(
c
({
'raw'
:
'chris'
}))
!=
0
assert
len
(
c
({
'raw'
:
'gghdjkasjdsda'
}))
==
0
assert
c
({
'PrincipiaSearchSource'
:
'the*'
})
def
checkTimeSubcommit
(
self
):
print
for
x
in
(
None
,
100
,
500
,
1000
,
10000
):
...
...
@@ -190,7 +190,7 @@ def out(s):
def
test_suite
():
s1
=
makeSuite
(
TestTimeIndex
,
'check'
)
testsuite
=
TestSuite
((
s1
,))
return
testsuite
...
...
@@ -199,7 +199,7 @@ def main():
if
not
os
.
path
.
isfile
(
mb
):
print
"do you want to get the zope.mbox file from lists.zope.org?"
print
"it's required for testing (98MB, ~ 30mins on fast conn)"
print
"it's also available at korak:/home/chrism/zope.mbox"
print
"it's also available at korak:/home/chrism/zope.mbox"
print
"-- type 'Y' or 'N'"
a
=
raw_input
()
if
lower
(
a
[:
1
])
==
'y'
:
...
...
@@ -235,8 +235,7 @@ def debug():
test_suite
().
debug
()
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
>
1
:
globals
()[
sys
.
argv
[
1
]]()
else
:
main
()
if
len
(
sys
.
argv
)
>
1
:
globals
()[
sys
.
argv
[
1
]]()
else
:
main
()
lib/python/Products/ZCatalog/regressiontests/regressionUnicode.py
View file @
2639fcb7
...
...
@@ -37,15 +37,15 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase):
t4
=
TO
(
'i am a brown '
+
unicode
(
'fox'
)
+
' dancing with a future alien'
,[])
t5
=
TO
(
"""
Die USA und Grobritannien knnen nach der Zerstrung der
afghanischen Luftabwehr nun rund um die Uhr Angriffe fliegen. Das gab
afghanischen Luftabwehr nun rund um die Uhr Angriffe fliegen. Das gab
Verteidigungsminister Donald Rumsfeld bekannt. Bei den dreitgigen Angriffen
seien auch bis auf einen alle Flugpltze der Taliban zerstrt worden. Rumsfeld
erklrte weiter, er knne die Berichte nicht besttigen, wonach bei den
erklrte weiter, er knne die Berichte nicht besttigen, wonach bei den
amerikanischen Angriffen vier afghanische Mitarbeiter einer von den UN
finanzierten Hilfsorganisation gettet wurden. Diese knnten auch durch
Gegenfeuer der Taliban gettet worden sein.
"""
,[
unicode
(
'dreitgigen'
,
'latin1'
),
'zerstrt'
])
self
.
cat
.
catalog_object
(
t1
,
"o1"
)
self
.
cat
.
catalog_object
(
t2
,
"o2"
)
...
...
@@ -59,7 +59,7 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase):
(
'dreitgigen'
,(
'o5'
,))
]
self
.
kw_tests
=
[
(
'quick'
,(
'o1'
,)
),
(
'zerstrt'
,(
'o3'
,
'o5'
)),
(
'dreitgigen'
,(
'o5'
,))
...
...
lib/python/Products/ZCatalog/regressiontests/unittest_patched.py
View file @
2639fcb7
...
...
@@ -31,14 +31,14 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
# This is patched version of unittest.py and allows to pass additional
# parameters to the TestCase constructor.
# This special version is only need to run the regression test
# This special version is only need to run the regression test
# in testCatalog.py#
#
# ajung
__author__
=
"Steve Purcell"
__email__
=
"stephen_purcell@yahoo.com"
__version__
=
"$Revision: 1.
2
$"
[
11
:
-
2
]
__version__
=
"$Revision: 1.
3
$"
[
11
:
-
2
]
import
time
import
sys
...
...
@@ -101,7 +101,7 @@ class TestResult:
def
stop
(
self
):
"Indicates that the tests should be aborted"
self
.
shouldStop
=
1
def
__repr__
(
self
):
return
"<%s run=%i errors=%i failures=%i>"
%
\
(
self
.
__class__
,
self
.
testsRun
,
len
(
self
.
errors
),
...
...
@@ -111,14 +111,14 @@ class TestResult:
class
TestCase
:
"""A class whose instances are single test cases.
Test authors should subclass TestCase for their own tests. Construction
Test authors should subclass TestCase for their own tests. Construction
and deconstruction of the test's environment ('fixture') can be
implemented by overriding the 'setUp' and 'tearDown' methods respectively.
By default, the test code itself should be placed in a method named
'runTest'.
If the fixture may be used for many test cases, create as
If the fixture may be used for many test cases, create as
many test methods as are needed. When instantiating such a TestCase
subclass, specify in the constructor arguments the name of the test method
that the instance is to execute.
...
...
@@ -131,7 +131,7 @@ class TestCase:
method when executed. Raises a ValueError if the instance does
not have a method with the specified name.
"""
try
:
self
.
__testMethodName
=
methodName
testMethod
=
getattr
(
self
,
methodName
)
...
...
@@ -250,7 +250,7 @@ class TestCase:
def
fail
(
self
,
msg
=
None
):
"""Fail immediately, with the given message."""
raise
AssertionError
,
msg
def
__exc_info
(
self
):
"""Return a version of sys.exc_info() with the traceback frame
minimised; usually the top level of the traceback frame is not
...
...
@@ -465,7 +465,7 @@ class _WritelnDecorator:
if
args
:
apply
(
self
.
write
,
args
)
self
.
write
(
self
.
linesep
)
class
_JUnitTextTestResult
(
TestResult
):
"""A test result class that can print formatted text results to a stream.
...
...
@@ -481,12 +481,12 @@ class _JUnitTextTestResult(TestResult):
self
.
stream
.
flush
()
if
error
[
0
]
is
KeyboardInterrupt
:
self
.
shouldStop
=
1
def
addFailure
(
self
,
test
,
error
):
TestResult
.
addFailure
(
self
,
test
,
error
)
self
.
stream
.
write
(
'F'
)
self
.
stream
.
flush
()
def
startTest
(
self
,
test
):
TestResult
.
startTest
(
self
,
test
)
self
.
stream
.
write
(
'.'
)
...
...
@@ -505,7 +505,7 @@ class _JUnitTextTestResult(TestResult):
self
.
stream
.
writeln
(
"%i) %s"
%
(
i
,
test
))
self
.
stream
.
writeln
(
errString
)
i
=
i
+
1
def
printErrors
(
self
):
self
.
printNumberedErrors
(
"error"
,
self
.
errors
)
...
...
@@ -523,7 +523,7 @@ class _JUnitTextTestResult(TestResult):
self
.
stream
.
writeln
(
"Run: %i ; Failures: %i ; Errors: %i"
%
(
self
.
testsRun
,
len
(
self
.
failures
),
len
(
self
.
errors
)))
def
printResult
(
self
):
self
.
printHeader
()
self
.
printErrors
()
...
...
@@ -532,7 +532,7 @@ class _JUnitTextTestResult(TestResult):
class
JUnitTextTestRunner
:
"""A test runner class that displays results in textual form.
The display format approximates that of JUnit's 'textui' test runner.
This test runner may be removed in a future version of PyUnit.
"""
...
...
@@ -565,7 +565,7 @@ class _VerboseTextTestResult(TestResult):
self
.
stream
=
stream
self
.
lastFailure
=
None
self
.
descriptions
=
descriptions
def
startTest
(
self
,
test
):
TestResult
.
startTest
(
self
,
test
)
if
self
.
descriptions
:
...
...
@@ -608,7 +608,7 @@ class _VerboseTextTestResult(TestResult):
class
VerboseTextTestRunner
:
"""A test runner class that displays results in textual form.
It prints out the names of tests as they are run, errors as they
occur, and a summary of the results at the end of the test run.
"""
...
...
@@ -640,7 +640,7 @@ class VerboseTextTestRunner:
else
:
self
.
stream
.
writeln
(
"OK"
)
return
result
# Which flavour of TextTestRunner is the default?
TextTestRunner
=
VerboseTextTestRunner
...
...
@@ -717,7 +717,7 @@ Examples:
if
self
.
testRunner
is
None
:
self
.
testRunner
=
TextTestRunner
()
result
=
self
.
testRunner
.
run
(
self
.
test
)
sys
.
exit
(
not
result
.
wasSuccessful
())
sys
.
exit
(
not
result
.
wasSuccessful
())
main
=
TestProgram
...
...
lib/python/Products/ZCatalog/tests/testCatalog.py
View file @
2639fcb7
...
...
@@ -109,13 +109,13 @@ class TestAddDelIndexes(CatalogBase, unittest.TestCase):
self
.
_catalog
.
addIndex
(
'id'
,
idx
)
self
.
_catalog
.
delIndex
(
'id'
)
assert
self
.
_catalog
.
indexes
.
has_key
(
'id'
)
!=
1
,
'del index failed'
def
testDelTextIndex
(
self
):
idx
=
TextIndex
(
'id'
)
self
.
_catalog
.
addIndex
(
'id'
,
idx
)
self
.
_catalog
.
delIndex
(
'id'
)
assert
self
.
_catalog
.
indexes
.
has_key
(
'id'
)
!=
1
,
'del index failed'
def
testDelKeywordIndex
(
self
):
idx
=
KeywordIndex
(
'id'
)
self
.
_catalog
.
addIndex
(
'id'
,
idx
)
...
...
@@ -138,7 +138,7 @@ class TestCatalogObject(unittest.TestCase):
self
.
_catalog
.
addIndex
(
'col1'
,
col1
)
self
.
_catalog
.
addIndex
(
'col2'
,
col2
)
self
.
_catalog
.
addIndex
(
'col3'
,
col3
)
self
.
_catalog
.
addColumn
(
'col1'
)
self
.
_catalog
.
addColumn
(
'col1'
)
self
.
_catalog
.
addColumn
(
'col2'
)
self
.
_catalog
.
addColumn
(
'col3'
)
...
...
@@ -146,12 +146,12 @@ class TestCatalogObject(unittest.TestCase):
att2
=
TextIndex
(
'att2'
)
att3
=
KeywordIndex
(
'att3'
)
num
=
FieldIndex
(
'num'
)
self
.
_catalog
.
addIndex
(
'att1'
,
att1
)
self
.
_catalog
.
addIndex
(
'att2'
,
att2
)
self
.
_catalog
.
addIndex
(
'att3'
,
att3
)
self
.
_catalog
.
addIndex
(
'num'
,
num
)
self
.
_catalog
.
addColumn
(
'att1'
)
self
.
_catalog
.
addColumn
(
'att1'
)
self
.
_catalog
.
addColumn
(
'att2'
)
self
.
_catalog
.
addColumn
(
'att3'
)
self
.
_catalog
.
addColumn
(
'num'
)
...
...
@@ -163,7 +163,7 @@ class TestCatalogObject(unittest.TestCase):
att3
=
[
'att3'
]
def
__init__
(
self
,
num
):
self
.
num
=
num
def
col1
(
self
):
return
'col1'
...
...
@@ -173,7 +173,7 @@ class TestCatalogObject(unittest.TestCase):
def
col3
(
self
):
return
[
'col3'
]
for
x
in
range
(
0
,
self
.
upper
):
self
.
_catalog
.
catalogObject
(
dummy
(
x
),
`x`
)
self
.
_catalog
.
aq_parent
=
dummy
(
'foo'
)
# fake out acquisition
...
...
@@ -208,11 +208,11 @@ class TestCatalogObject(unittest.TestCase):
assert
len
(
a
)
==
self
.
upper
,
'should be %s, but is %s'
%
(
self
.
upper
,
len
(
a
))
def
testUncatalogFieldIndex
(
self
):
def
testUncatalogFieldIndex
(
self
):
self
.
uncatalog
()
a
=
self
.
_catalog
(
att1
=
'att1'
)
assert
len
(
a
)
==
0
,
'len: %s'
%
(
len
(
a
))
def
testUncatalogTextIndex
(
self
):
self
.
uncatalog
()
a
=
self
.
_catalog
(
att2
=
'att2'
)
...
...
@@ -259,7 +259,7 @@ class TestCatalogObject(unittest.TestCase):
assert
len
(
a
)
==
upper
,
'length should be %s, its %s'
%
(
upper
,
len
(
a
))
for
x
in
range
(
self
.
upper
):
assert
a
[
x
].
num
==
x
,
x
def
testBadSortIndex
(
self
):
self
.
assertRaises
(
CatalogError
,
self
.
badsortindex
)
...
...
@@ -313,7 +313,7 @@ class TestCatalogObject(unittest.TestCase):
# set is much larger than the sort index.
a
=
self
.
_catalog
(
sort_on
=
'att1'
)
self
.
assertEqual
(
len
(
a
),
self
.
upper
)
class
objRS
(
ExtensionClass
.
Base
):
...
...
@@ -330,16 +330,16 @@ class testRS(unittest.TestCase):
self
.
_catalog
.
addIndex
(
'number'
,
index
)
self
.
_catalog
.
addColumn
(
'number'
)
for
i
in
range
(
5000
):
for
i
in
range
(
5000
):
obj
=
objRS
(
whrandom
.
randint
(
0
,
20000
))
self
.
_catalog
.
catalogObject
(
obj
,
i
)
self
.
_catalog
.
aq_parent
=
objRS
(
200
)
def
testRangeSearch
(
self
):
for
i
in
range
(
10000
):
for
i
in
range
(
10000
):
m
=
whrandom
.
randint
(
0
,
20000
)
m
=
whrandom
.
randint
(
0
,
20000
)
n
=
m
+
1000
for
r
in
self
.
_catalog
.
searchResults
(
...
...
lib/python/Products/ZGadflyDA/DA.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
database_type
=
'Gadfly'
__doc__
=
'''%s Database Connection
$Id: DA.py,v 1.1
4 2002/05/27 12:27:25 chrisw
Exp $'''
%
database_type
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
$Id: DA.py,v 1.1
5 2002/08/14 22:25:17 mj
Exp $'''
%
database_type
__version__
=
'$Revision: 1.1
5
$'
[
11
:
-
2
]
from
db
import
DB
,
manage_DataSources
import
sys
,
DABase
,
Globals
...
...
@@ -31,7 +31,7 @@ def manage_addZGadflyConnection(
self
,
id
,
title
,
connection
,
check
=
None
,
REQUEST
=
None
):
"""Add a DB connection to a folder"""
# Note - type checking is taken care of by _setObject
# Note - type checking is taken care of by _setObject
# and the Connection object constructor.
self
.
_setObject
(
id
,
Connection
(
id
,
title
,
connection
,
check
))
...
...
@@ -51,13 +51,13 @@ class Connection(DABase.Connection):
if
hasattr
(
self
,
'_v_database_connection'
):
return
self
.
_v_database_connection
.
opened
return
''
def
title_and_id
(
self
):
s
=
_Connection
.
inheritedAttribute
(
'title_and_id'
)(
self
)
if
(
hasattr
(
self
,
'_v_database_connection'
)
and
self
.
_v_database_connection
.
opened
):
s
=
"%s, which is connected"
%
s
else
:
else
:
s
=
"%s, which is <font color=red> not connected</font>"
%
s
return
s
...
...
@@ -66,7 +66,7 @@ class Connection(DABase.Connection):
if
(
hasattr
(
self
,
'_v_database_connection'
)
and
self
.
_v_database_connection
.
opened
):
s
=
"%s (connected)"
%
s
else
:
else
:
s
=
"%s (<font color=red> not connected</font>)"
%
s
return
s
...
...
@@ -78,7 +78,7 @@ class Connection(DABase.Connection):
c
=
self
.
_v_database_connection
=
c
[
s
]
if
not
c
.
opened
:
c
.
open
()
return
self
try
:
try
:
self
.
_v_database_connection
=
c
[
s
]
=
DB
(
s
)
...
...
@@ -90,8 +90,7 @@ class Connection(DABase.Connection):
'<!--
\
n
%s
\
n
%s
\
n
-->
\
n
'
%
(
s
,
t
,
v
)),
tb
finally
:
tb
=
None
return
self
finally
:
_connections_lock
.
release
()
lib/python/Products/ZGadflyDA/DABase.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Database Connection
$Id: DABase.py,v 1.1
1 2001/11/28 15:51:10 matt
Exp $'''
__version__
=
'$Revision: 1.1
1
$'
[
11
:
-
2
]
$Id: DABase.py,v 1.1
2 2002/08/14 22:25:17 mj
Exp $'''
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
from
db
import
manage_DataSources
import
Shared.DC.ZRDB.Connection
,
sys
...
...
@@ -33,7 +33,7 @@ class Connection(Shared.DC.ZRDB.Connection.Connection):
manage_browse
=
HTMLFile
(
'dtml/browse'
,
globals
())
info
=
None
def
tpValues
(
self
):
#if hasattr(self, '_v_tpValues'): return self._v_tpValues
r
=
[]
...
...
@@ -104,7 +104,7 @@ class TableBrowser(Browser, Acquisition.Implicit):
b
.
TABLE_NAME
=
tname
r
.
append
(
b
)
return
r
def
tpId
(
self
):
return
self
.
_d
[
'TABLE_NAME'
]
def
tpURL
(
self
):
return
"Table/%s"
%
self
.
_d
[
'TABLE_NAME'
]
def
Name
(
self
):
return
self
.
_d
[
'TABLE_NAME'
]
...
...
@@ -144,8 +144,8 @@ class TableBrowser(Browser, Acquisition.Implicit):
raise
ValueError
,
(
'no default was given for <em>%s</em>'
%
n
)
class
ColumnBrowser
(
Browser
):
icon
=
'field'
...
...
lib/python/Products/ZGadflyDA/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''Generic Database Adapter Package Registration
$Id: __init__.py,v 1.1
3 2001/11/28 15:51:10 matt
Exp $'''
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
$Id: __init__.py,v 1.1
4 2002/08/14 22:25:17 mj
Exp $'''
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
import
Globals
,
os
...
...
@@ -57,7 +57,7 @@ def manage_addZGadflyConnectionForm(self, REQUEST, *args, **kw):
self
,
self
,
REQUEST
,
database_type
=
database_type
,
data_sources
=
DA
.
data_sources
)
def
manage_addZGadflyConnection
(
self
,
id
,
title
,
connection
,
check
=
None
,
REQUEST
=
None
):
" "
...
...
lib/python/Products/ZGadflyDA/db.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
'''$Id: db.py,v 1.1
2 2001/11/28 15:51:10 matt
Exp $'''
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
'''$Id: db.py,v 1.1
3 2002/08/14 22:25:17 mj
Exp $'''
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
import
os
from
string
import
strip
,
split
...
...
@@ -23,7 +23,7 @@ from DateTime import DateTime
data_dir
=
os
.
path
.
join
(
Globals
.
data_dir
,
'gadfly'
)
def
manage_DataSources
():
if
not
os
.
path
.
exists
(
data_dir
):
try
:
os
.
mkdir
(
data_dir
)
...
...
@@ -42,7 +42,7 @@ def manage_DataSources():
existence of the directory, <code>%s</code>. This
exists, but is not a directory.
"""
%
data_dir
)
return
map
(
lambda
d
:
(
d
,
''
),
filter
(
lambda
f
,
i
=
os
.
path
.
isdir
,
d
=
data_dir
,
j
=
os
.
path
.
join
:
...
...
@@ -112,7 +112,7 @@ class DB(Shared.DC.ZRDB.THUNK.THUNKED_TM):
'Multiple incompatible selects in '
'multiple sql-statement query'
)
if
not
result
:
result
=
c
.
fetchmany
(
max_rows
)
elif
len
(
result
)
<
max_rows
:
result
=
result
+
c
.
fetchmany
(
max_rows
-
len
(
result
))
...
...
@@ -134,7 +134,7 @@ class DB(Shared.DC.ZRDB.THUNK.THUNKED_TM):
'null'
:
null_ok
,
})
return
items
,
result
# Gadfly needs the extra checkpoint call.
def
_abort
(
self
):
self
.
db
.
rollback
()
...
...
lib/python/Products/ZSQLMethods/SQL.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''SQL Methods
$Id: SQL.py,v 1.2
0 2001/11/28 15:51:10 matt
Exp $'''
__version__
=
'$Revision: 1.2
0
$'
[
11
:
-
2
]
$Id: SQL.py,v 1.2
1 2002/08/14 22:25:18 mj
Exp $'''
__version__
=
'$Revision: 1.2
1
$'
[
11
:
-
2
]
import
Shared.DC.ZRDB.DA
from
Globals
import
DTMLFile
...
...
@@ -75,7 +75,7 @@ def manage_addZSQLMethod(self, id, title,
u
=
"%s/%s/manage_testForm"
%
(
u
,
id
)
else
:
u
=
u
+
'/manage_main'
REQUEST
.
RESPONSE
.
redirect
(
u
)
return
''
...
...
@@ -102,7 +102,7 @@ class SQL(Shared.DC.ZRDB.DA.DA):
and result data.
For more information, see the searchable-object interface
specification.
specification.
- Containment
...
...
@@ -119,7 +119,7 @@ class SQL(Shared.DC.ZRDB.DA.DA):
"""
__implements__
=
(
WriteLockInterface
,)
meta_type
=
'Z SQL Method'
manage
=
manage_main
=
DTMLFile
(
'dtml/edit'
,
globals
())
manage_main
.
_setName
(
'manage_main'
)
...
...
lib/python/Products/ZSQLMethods/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
__doc__
=
'''SQL Method Product
$Id: __init__.py,v 1.1
7 2001/11/28 15:51:10 matt
Exp $'''
__version__
=
'$Revision: 1.1
7
$'
[
11
:
-
2
]
$Id: __init__.py,v 1.1
8 2002/08/14 22:25:18 mj
Exp $'''
__version__
=
'$Revision: 1.1
8
$'
[
11
:
-
2
]
import
Shared.DC.ZRDB.Search
,
Shared
.
DC
.
ZRDB
.
Aqueduct
,
SQL
import
Shared.DC.ZRDB.RDB
import
Shared.DC.ZRDB.sqlvar
,
Shared
.
DC
.
ZRDB
.
sqlgroup
,
Shared
.
DC
.
ZRDB
.
sqltest
...
...
lib/python/Products/ZSQLMethods/help/ZSQLMethod.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
def
manage_addZSQLMethod
(
id
,
title
,
...
...
@@ -26,7 +26,7 @@ def manage_addZSQLMethod(id, title,
The 'template' argument is a string containing the source for the
SQL Template.
"""
...
...
@@ -47,7 +47,7 @@ class ZSQLMethod:
and result data.
For more information, see the searchable-object interface
specification.
specification.
Database methods support URL traversal to access and invoke
methods on individual record objects. For example, suppose you
...
...
@@ -81,7 +81,7 @@ class ZSQLMethod:
The returned value is a sequence of record objects.
"""
def
manage_edit
(
title
,
connection_id
,
arguments
,
template
):
"""
...
...
@@ -100,15 +100,3 @@ class ZSQLMethod:
the SQL Template.
"""
lib/python/Products/ZopeTutorial/TutorialTopic.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
OFS.Folder
from
HelpSys.HelpTopic
import
TextTopic
...
...
@@ -32,7 +32,7 @@ class TutorialTopic(TextTopic):
self
.
title
=
title
text
=
str
(
StructuredText
.
HTML
(
text
))
self
.
obj
=
HTML
(
pre_pat
.
sub
(
clean_pre
,
text
))
index_html
=
DTMLFile
(
'dtml/lessonView'
,
globals
())
def
checkInstallation
(
self
,
REQUEST
):
...
...
@@ -56,7 +56,7 @@ class TutorialTopic(TextTopic):
if
not
ok
:
REQUEST
.
set
(
'hide_next'
,
1
)
return
ok
def
lessonURL
(
self
,
id
,
REQUEST
):
"""
URL of the examples for a lesson
...
...
@@ -65,7 +65,7 @@ class TutorialTopic(TextTopic):
return
'%s/lesson%d'
%
(
REQUEST
[
'tutorialExamplesURL'
],
id
)
except
KeyError
:
return
""
def
tutorialShowLesson
(
self
,
id
,
REQUEST
):
"""
Navigate management frame to a given lesson's screen.
...
...
@@ -87,7 +87,7 @@ follow along manually, or reinstall the tutorial examples.
Note: make sure that you have cookies turned on in your browser.
</p>
"""
return
"""
\
<SCRIPT LANGUAGE="javascript">
<!--
...
...
@@ -115,7 +115,7 @@ class GlossaryTopic(TutorialTopic):
self
.
obj
=
HTML
(
text
)
index_html
=
DTMLFile
(
'dtml/glossaryView'
,
globals
())
def
formatted_content
(
self
,
REQUEST
):
"""
Custom stx formatting for tutorial topics
...
...
@@ -168,11 +168,11 @@ def addTutorial(self, id, REQUEST=None, RESPONSE=None):
except
:
folder
.
_p_jar
=
self
.
Destination
().
_p_jar
folder
.
manage_importObject
(
tutorialExamplesFile
)
# acquire REQUEST if necessary
if
REQUEST
is
None
:
REQUEST
=
self
.
REQUEST
# Set local roles on examples
changeOwner
(
folder
,
REQUEST
[
'AUTHENTICATED_USER'
])
...
...
@@ -197,11 +197,11 @@ def changeOwner(obj, owner):
for
user
,
roles
in
obj
.
get_local_roles
():
if
'Owner'
in
roles
:
obj
.
manage_delLocalRoles
([
user
])
break
break
obj
.
manage_setLocalRoles
(
owner
.
getUserName
(),
[
'Owner'
])
for
subobj
in
obj
.
objectValues
():
changeOwner
(
subobj
,
owner
)
def
clean_pre
(
match
):
"""
Reformat a pre tag to get rid of extra indentation
...
...
@@ -215,20 +215,20 @@ def clean_pre(match):
indent
=
len
(
line
)
-
len
(
line
.
lstrip
())
if
min_indent
is
None
or
indent
<
min_indent
:
if
line
.
strip
():
min_indent
=
indent
min_indent
=
indent
for
line
in
lines
:
nlines
.
append
(
line
[
min_indent
:])
while
1
:
if
not
nlines
[
0
].
strip
():
nlines
.
pop
(
0
)
else
:
break
while
1
:
if
not
nlines
[
-
1
].
strip
():
nlines
.
pop
()
else
:
break
return
"<PRE>%s</PRE>"
%
'
\
n
'
.
join
(
nlines
)
lib/python/Products/ZopeTutorial/__init__.py
View file @
2639fcb7
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
import
TutorialTopic
import
App.Common
...
...
@@ -41,15 +41,15 @@ def initialize(context):
help
.
lastRegistered
>=
DateTime
(
os
.
stat
(
lesson_path
)[
stat
.
ST_MTIME
]):
return
help
.
lastRegistered
=
DateTime
()
# delete old help topics
for
id
in
help
.
objectIds
(
'Help Topic'
):
help
.
_delObject
(
id
)
# create glossary
text
=
open
(
glossary_path
).
read
()
text
=
term_pat
.
sub
(
defineTerm
,
text
)
glossary
=
TutorialTopic
.
GlossaryTopic
(
'tutorialGlossary'
,
'Zope Tutorial Glossary'
,
text
)
context
.
registerHelpTopic
(
'tutorialGlossary'
,
glossary
)
...
...
@@ -58,7 +58,7 @@ def initialize(context):
f
=
open
(
lesson_path
)
lines
=
[]
id
=
0
while
1
:
line
=
f
.
readline
()
if
(
line
.
strip
()
and
line
.
find
(
' '
)
!=
0
)
or
line
==
''
:
...
...
@@ -69,7 +69,7 @@ def initialize(context):
text
=
''
.
join
(
lines
[
1
:])
text
=
term_pat
.
sub
(
glossaryTerm
,
text
)
topic
=
TutorialTopic
.
TutorialTopic
(
topic_id
,
lines
[
0
].
strip
(),
spacestrip
(
text
))
context
.
registerHelpTopic
(
topic_id
,
topic
)
context
.
registerHelpTopic
(
topic_id
,
topic
)
lines
=
[
line
]
else
:
lines
.
append
(
line
)
...
...
@@ -81,12 +81,12 @@ def initialize(context):
def
spacestrip
(
txt
):
""" dedent text by 2 spaces !
We need this to workaround a nasty bug in STXNG.
We need this to workaround a nasty bug in STXNG.
STXNG creates empty <pre>..</pre> when then text start
if a level > 1. This fix is lame. The problem should be fixed
inside STXNG
"""
l
=
[]
for
x
in
txt
.
split
(
"
\
n
"
):
if
len
(
x
)
>
2
and
x
[:
2
]
==
' '
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment