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
Show 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 @@
...
@@ -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
import
re
from
types
import
StringType
,
ListType
,
TupleType
,
DictType
,
InstanceType
from
types
import
StringType
,
ListType
,
TupleType
,
DictType
,
InstanceType
from
DateTime
import
DateTime
from
DateTime
import
DateTime
SequenceTypes
=
(
TupleType
,
ListType
)
class
parseIndexRequest
:
class
parseIndexRequest
:
"""
"""
This class provides functionality to hide the internals of a request
This class provides functionality to hide the internals of a request
...
@@ -125,7 +127,7 @@ class parseIndexRequest:
...
@@ -125,7 +127,7 @@ class parseIndexRequest:
ParserException
=
'IndexRequestParseError'
ParserException
=
'IndexRequestParseError'
def
__init__
(
self
,
request
,
iid
,
options
=
[]):
def
__init__
(
self
,
request
,
iid
,
options
=
[]):
""" parse a request from the ZPublisher and return a uniform
""" parse a request from the ZPublisher and return a uniform
datastructure back to the _apply_index() method of the index
datastructure back to the _apply_index() method of the index
...
@@ -135,80 +137,75 @@ class parseIndexRequest:
...
@@ -135,80 +137,75 @@ class parseIndexRequest:
"""
"""
self
.
id
=
iid
self
.
id
=
iid
self
.
keys
=
None
if
not
request
.
has_key
(
iid
):
return
if
not
request
.
has_key
(
iid
):
self
.
keys
=
None
return
# We keep this for backward compatility
# We keep this for backward compatility
if
request
.
has_key
(
iid
+
'_usage'
):
usage_param
=
iid
+
'_usage'
self
.
usage
=
request
[
iid
+
'_usage'
]
if
request
.
has_key
(
usage_param
):
self
.
usage
=
request
[
usage_param
]
keys
=
request
[
iid
]
if
type
(
keys
)
==
InstanceType
:
if
isinstance
(
keys
,
DateTime
):
param
=
request
[
iid
]
"""query is a DateTime instance"""
keys
=
None
t
=
type
(
param
)
self
.
keys
=
keys
if
t
is
InstanceType
and
not
isinstance
(
param
,
DateTime
):
else
:
""" query is of type record """
""" query is of type record """
record
=
keys
if
hasattr
(
record
,
'query'
):
record
=
param
if
not
hasattr
(
record
,
'query'
):
raise
self
.
ParserException
,
(
"record for '%s' *must* contain a "
"'query' attribute"
%
self
.
id
)
keys
=
record
.
query
keys
=
record
.
query
else
:
raise
self
.
ParserException
,
\
"record for '%s' *must* contain a 'query' attribute"
%
self
.
id
if
type
(
keys
)
==
StringType
:
if
type
(
keys
)
is
StringType
:
self
.
keys
=
[
keys
.
strip
()]
keys
=
[
keys
.
strip
()]
elif
type
(
keys
)
==
ListType
:
self
.
keys
=
keys
for
op
in
options
:
for
op
in
options
:
if
op
in
[
"query"
]:
continue
if
op
==
"query"
:
continue
if
hasattr
(
record
,
op
):
if
hasattr
(
record
,
op
):
setattr
(
self
,
k
,
getattr
(
record
,
k
))
setattr
(
self
,
op
,
getattr
(
record
,
op
))
elif
t
is
DictType
:
elif
type
(
keys
)
==
DictType
:
""" query is a dictionary containing all parameters """
""" query is a dictionary containing all parameters """
query
=
keys
.
get
(
"query"
,[]
)
query
=
param
.
get
(
"query"
,
()
)
if
type
(
query
)
in
[
TupleType
,
ListType
]
:
if
type
(
query
)
in
SequenceTypes
:
self
.
keys
=
query
keys
=
query
else
:
else
:
self
.
keys
=
[
query
]
keys
=
[
query
]
for
op
in
options
:
for
op
in
options
:
if
op
in
[
"query"
]:
continue
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
:
else
:
""" query is tuple, list
or string
"""
""" query is tuple, list
, string, number, or something else
"""
if
t
ype
(
keys
)
in
[
TupleType
,
ListType
]
:
if
t
in
SequenceTypes
:
self
.
keys
=
keys
keys
=
param
else
:
else
:
self
.
keys
=
[
keys
]
keys
=
[
param
]
for
op
in
options
:
for
op
in
options
:
if
request
.
has_key
(
iid
+
"_"
+
op
):
field
=
iid
+
"_"
+
op
setattr
(
self
,
op
,
request
[
iid
+
"_"
+
op
])
if
request
.
has_key
(
field
):
setattr
(
self
,
op
,
request
[
field
])
if
self
.
keys
!=
None
:
if
keys
is
not
None
:
self
.
keys
=
filter
(
lambda
x
:
len
(
str
(
x
))
>
0
,
self
.
keys
)
# Filter out empty strings.
keys
=
filter
(
lambda
key
:
key
!=
''
,
keys
)
if
len
(
self
.
keys
)
==
0
:
self
.
keys
=
None
if
not
keys
:
keys
=
None
self
.
keys
=
keys
def
get
(
self
,
k
,
default_v
=
None
):
def
get
(
self
,
k
,
default_v
=
None
):
...
...
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