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
aa2e2e54
Commit
aa2e2e54
authored
Jun 13, 2001
by
Shane Hathaway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Corrected issues with DateTime.
- Optimized slightly. - Clarified by using more variable names.
parent
89de4892
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
53 deletions
+50
-53
lib/python/Products/PluginIndexes/common/util.py
lib/python/Products/PluginIndexes/common/util.py
+50
-53
No files found.
lib/python/Products/PluginIndexes/common/util.py
View file @
aa2e2e54
...
...
@@ -83,13 +83,15 @@
#
#############################################################################
__version__
=
'$Id: util.py,v 1.
5 2001/06/11 16:04:21 andreas
Exp $'
__version__
=
'$Id: util.py,v 1.
6 2001/06/13 14:22:52 shane
Exp $'
import
re
from
types
import
StringType
,
ListType
,
TupleType
,
DictType
,
InstanceType
from
DateTime
import
DateTime
SequenceTypes
=
(
TupleType
,
ListType
)
class
parseIndexRequest
:
"""
This class provides functionality to hide the internals of a request
...
...
@@ -125,7 +127,7 @@ class parseIndexRequest:
ParserException
=
'IndexRequestParseError'
def
__init__
(
self
,
request
,
iid
,
options
=
[]):
def
__init__
(
self
,
request
,
iid
,
options
=
[]):
""" parse a request from the ZPublisher and return a uniform
datastructure back to the _apply_index() method of the index
...
...
@@ -134,83 +136,78 @@ class parseIndexRequest:
options -- a list of options the index is interested in
"""
self
.
id
=
iid
self
.
keys
=
None
self
.
id
=
iid
if
not
request
.
has_key
(
iid
):
return
if
not
request
.
has_key
(
iid
):
self
.
keys
=
None
return
# We keep this for backward compatility
if
request
.
has_key
(
iid
+
'_usage'
):
self
.
usage
=
request
[
iid
+
'_usage'
]
usage_param
=
iid
+
'_usage'
if
request
.
has_key
(
usage_param
):
self
.
usage
=
request
[
usage_param
]
keys
=
request
[
iid
]
param
=
request
[
iid
]
keys
=
None
t
=
type
(
param
)
if
type
(
keys
)
==
InstanceType
:
if
t
is
InstanceType
and
not
isinstance
(
param
,
DateTime
):
""" query is of type record """
if
isinstance
(
keys
,
DateTime
):
"""query is a DateTime instance"""
record
=
param
self
.
keys
=
keys
if
not
hasattr
(
record
,
'query'
):
raise
self
.
ParserException
,
(
"record for '%s' *must* contain a "
"'query' attribute"
%
self
.
id
)
keys
=
record
.
query
if
type
(
keys
)
is
StringType
:
keys
=
[
keys
.
strip
()]
else
:
""" query is of type record """
record
=
keys
if
hasattr
(
record
,
'query'
):
keys
=
record
.
query
else
:
raise
self
.
ParserException
,
\
"record for '%s' *must* contain a 'query' attribute"
%
self
.
id
if
type
(
keys
)
==
StringType
:
self
.
keys
=
[
keys
.
strip
()]
elif
type
(
keys
)
==
ListType
:
self
.
keys
=
keys
for
op
in
options
:
if
op
in
[
"query"
]:
continue
if
hasattr
(
record
,
op
):
setattr
(
self
,
k
,
getattr
(
record
,
k
))
for
op
in
options
:
if
op
==
"query"
:
continue
if
hasattr
(
record
,
op
):
setattr
(
self
,
op
,
getattr
(
record
,
op
))
elif
t
ype
(
keys
)
==
DictType
:
elif
t
is
DictType
:
""" query is a dictionary containing all parameters """
query
=
keys
.
get
(
"query"
,[]
)
if
type
(
query
)
in
[
TupleType
,
ListType
]
:
self
.
keys
=
query
query
=
param
.
get
(
"query"
,
()
)
if
type
(
query
)
in
SequenceTypes
:
keys
=
query
else
:
self
.
keys
=
[
query
]
keys
=
[
query
]
for
op
in
options
:
if
op
in
[
"query"
]
:
continue
for
op
in
options
:
if
op
==
"query"
:
continue
if
keys
.
has_key
(
op
):
setattr
(
self
,
op
,
keys
[
op
])
if
param
.
has_key
(
op
):
setattr
(
self
,
op
,
param
[
op
])
else
:
""" query is tuple, list
or string
"""
""" query is tuple, list
, string, number, or something else
"""
if
t
ype
(
keys
)
in
[
TupleType
,
ListType
]
:
self
.
keys
=
keys
if
t
in
SequenceTypes
:
keys
=
param
else
:
self
.
keys
=
[
keys
]
keys
=
[
param
]
for
op
in
options
:
if
request
.
has_key
(
iid
+
"_"
+
op
):
setattr
(
self
,
op
,
request
[
iid
+
"_"
+
op
])
field
=
iid
+
"_"
+
op
if
request
.
has_key
(
field
):
setattr
(
self
,
op
,
request
[
field
])
if
keys
is
not
None
:
# Filter out empty strings.
keys
=
filter
(
lambda
key
:
key
!=
''
,
keys
)
if
not
keys
:
keys
=
None
if
self
.
keys
!=
None
:
self
.
keys
=
filter
(
lambda
x
:
len
(
str
(
x
))
>
0
,
self
.
keys
)
self
.
keys
=
keys
if
len
(
self
.
keys
)
==
0
:
self
.
keys
=
None
def
get
(
self
,
k
,
default_v
=
None
):
if
hasattr
(
self
,
k
):
...
...
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