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
74261752
Commit
74261752
authored
Aug 01, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final PEP8 fixes
parent
f7bdb451
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
71 deletions
+90
-71
src/Products/ZCatalog/Catalog.py
src/Products/ZCatalog/Catalog.py
+50
-47
src/Products/ZCatalog/CatalogAwareness.py
src/Products/ZCatalog/CatalogAwareness.py
+26
-18
src/Products/ZCatalog/CatalogPathAwareness.py
src/Products/ZCatalog/CatalogPathAwareness.py
+12
-6
src/Products/ZCatalog/__init__.py
src/Products/ZCatalog/__init__.py
+1
-0
src/Products/ZCatalog/interfaces.py
src/Products/ZCatalog/interfaces.py
+1
-0
No files found.
src/Products/ZCatalog/Catalog.py
View file @
74261752
...
...
@@ -54,6 +54,7 @@ except ImportError:
class
CatalogError
(
Exception
):
pass
class
Catalog
(
Persistent
,
Acquisition
.
Implicit
,
ExtensionClass
.
Base
):
""" An Object Catalog
...
...
@@ -171,25 +172,24 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
schema
=
self
.
schema
names
=
list
(
self
.
names
)
if
schema
.
has_key
(
name
)
:
raise
CatalogError
,
'The column %s already exists'
%
name
if
name
in
schema
:
raise
CatalogError
(
'The column %s already exists'
%
name
)
if
name
[
0
]
==
'_'
:
raise
CatalogError
,
\
'Cannot cache fields beginning with "_"'
raise
CatalogError
(
'Cannot cache fields beginning with "_"'
)
if
not
schema
.
has_key
(
name
):
if
schema
.
values
()
:
schema
[
name
]
=
max
(
schema
.
values
())
+
1
values
=
schema
.
values
()
if
values
:
schema
[
name
]
=
max
(
values
)
+
1
else
:
schema
[
name
]
=
0
names
.
append
(
name
)
if
default_value
i
s
None
or
default_value
==
''
:
if
default_value
i
n
(
None
,
''
)
:
default_value
=
MV
for
key
in
self
.
data
.
key
s
():
rec
=
list
(
self
.
data
[
key
]
)
for
key
,
value
in
self
.
data
.
item
s
():
rec
=
list
(
value
)
rec
.
append
(
default_value
)
self
.
data
[
key
]
=
tuple
(
rec
)
...
...
@@ -208,14 +208,16 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
names
=
list
(
self
.
names
)
_index
=
names
.
index
(
name
)
if
not
self
.
schema
.
has_key
(
name
):
LOG
.
error
(
'delColumn attempted to delete nonexistent column %s.'
%
str
(
name
))
if
not
name
in
self
.
schema
:
LOG
.
error
(
'delColumn attempted to delete nonexistent '
'column %s.'
%
str
(
name
))
return
del
names
[
_index
]
# rebuild the schema
i
=
0
;
schema
=
{}
i
=
0
schema
=
{}
for
name
in
names
:
schema
[
name
]
=
i
i
=
i
+
1
...
...
@@ -227,8 +229,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self
.
updateBrains
()
# remove the column value from each record
for
key
in
self
.
data
.
key
s
():
rec
=
list
(
self
.
data
[
key
]
)
for
key
,
value
in
self
.
data
.
item
s
():
rec
=
list
(
value
)
del
rec
[
_index
]
self
.
data
[
key
]
=
tuple
(
rec
)
...
...
@@ -236,37 +238,36 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
"""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
and passed in to addIndex.
'KeywordIndex' is no longer valid; the actual index must be
instantiated
and passed in to addIndex.
New format: index_type is the actual index object to be stored.
"""
if
self
.
indexes
.
has_key
(
name
)
:
raise
CatalogError
,
'The index %s already exists'
%
name
if
name
in
self
.
indexes
:
raise
CatalogError
(
'The index %s already exists'
%
name
)
if
name
.
startswith
(
'_'
):
raise
CatalogError
,
'Cannot index fields beginning with "_"'
raise
CatalogError
(
'Cannot index fields beginning with "_"'
)
if
not
name
:
raise
CatalogError
,
'Name of index is empty'
raise
CatalogError
(
'Name of index is empty'
)
indexes
=
self
.
indexes
if
isinstance
(
index_type
,
str
):
raise
TypeError
,
"""Catalog addIndex now requires the index type to
be resolved prior to adding; create the proper index in the caller."""
indexes
[
name
]
=
index_type
;
raise
TypeError
(
"Catalog addIndex now requires the index type to"
"be resolved prior to adding; create the proper "
"index in the caller."
)
indexes
[
name
]
=
index_type
self
.
indexes
=
indexes
def
delIndex
(
self
,
name
):
""" deletes an index """
if
not
self
.
indexes
.
has_key
(
name
)
:
raise
CatalogError
,
'The index %s does not exist'
%
name
if
not
name
in
self
.
indexes
:
raise
CatalogError
(
'The index %s does not exist'
%
name
)
indexes
=
self
.
indexes
del
indexes
[
name
]
...
...
@@ -354,11 +355,12 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self
.
updateMetadata
(
object
,
uid
)
# do indexing
total
=
0
if
idxs
==
[]:
use_indexes
=
self
.
indexes
.
keys
()
else
:
use_indexes
=
idxs
if
idxs
==
[]:
use_indexes
=
self
.
indexes
.
keys
()
else
:
use_indexes
=
idxs
for
name
in
use_indexes
:
x
=
self
.
getIndex
(
name
)
...
...
@@ -366,7 +368,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
blah
=
x
.
index_object
(
index
,
object
,
threshold
)
total
=
total
+
blah
else
:
LOG
.
error
(
'catalogObject was passed bad index object %s.'
%
str
(
x
))
LOG
.
error
(
'catalogObject was passed bad index '
'object %s.'
%
str
(
x
))
return
total
...
...
@@ -417,19 +420,19 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
def
recordify
(
self
,
object
):
""" turns an object into a record tuple """
record
=
[]
# the unique id is al
l
ways the first element
# the unique id is always the first element
for
x
in
self
.
names
:
attr
=
getattr
(
object
,
x
,
MV
)
if
(
attr
is
not
MV
and
safe_callable
(
attr
)):
attr
=
attr
()
attr
=
getattr
(
object
,
x
,
MV
)
if
(
attr
is
not
MV
and
safe_callable
(
attr
)):
attr
=
attr
()
record
.
append
(
attr
)
return
tuple
(
record
)
def
instantiate
(
self
,
record
):
r
=
self
.
_v_result_class
(
record
[
1
])
r
=
self
.
_v_result_class
(
record
[
1
])
r
.
data_record_id_
=
record
[
0
]
return
r
.
__of__
(
self
)
def
getMetadataForRID
(
self
,
rid
):
record
=
self
.
data
[
rid
]
result
=
{}
...
...
@@ -777,13 +780,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# self.indexes is always a dict, so get() w/ 1 arg works
sort_index
=
self
.
indexes
.
get
(
sort_index_name
)
if
sort_index
is
None
:
raise
CatalogError
,
'Unknown sort_on index (%s)'
%
sort_index_name
raise
CatalogError
(
'Unknown sort_on index (%s)'
%
sort_index_name
)
else
:
if
not
hasattr
(
sort_index
,
'documentToKeyMap'
):
raise
CatalogError
(
'The index chosen for sort_on (%s) is not capable of '
'being used as a sort index.'
%
sort_index_name
)
'being used as a sort index.'
%
sort_index_name
)
return
sort_index
else
:
return
None
...
...
src/Products/ZCatalog/CatalogAwareness.py
View file @
74261752
...
...
@@ -22,6 +22,7 @@ import warnings
from
Acquisition
import
aq_base
from
App.special_dtml
import
DTMLFile
class
CatalogAware
:
""" This is a Mix-In class to make objects automaticly catalog and
uncatalog themselves in Zope, and to provide some other basic
...
...
@@ -58,7 +59,8 @@ class CatalogAware:
except
Exception
:
s
=
0
object
.
manage_afterAdd
(
item
,
container
)
if
s
is
None
:
object
.
_p_deactivate
()
if
s
is
None
:
object
.
_p_deactivate
()
def
manage_afterClone
(
self
,
item
):
self
.
index_object
()
...
...
@@ -68,7 +70,8 @@ class CatalogAware:
except
Exception
:
s
=
0
object
.
manage_afterClone
(
item
)
if
s
is
None
:
object
.
_p_deactivate
()
if
s
is
None
:
object
.
_p_deactivate
()
def
manage_beforeDelete
(
self
,
item
,
container
):
self
.
unindex_object
()
...
...
@@ -78,7 +81,8 @@ class CatalogAware:
except
Exception
:
s
=
0
object
.
manage_beforeDelete
(
item
,
container
)
if
s
is
None
:
object
.
_p_deactivate
()
if
s
is
None
:
object
.
_p_deactivate
()
def
creator
(
self
):
"""Return a sequence of user names who have the local
...
...
@@ -100,13 +104,13 @@ class CatalogAware:
if
hasattr
(
self
,
'DestinationURL'
)
and
\
callable
(
self
.
DestinationURL
):
url
=
'%s/%s'
%
(
self
.
DestinationURL
(),
self
.
id
)
else
:
url
=
self
.
absolute_url
()
type
,
uri
=
ftype
(
url
)
host
,
uri
=
fhost
(
uri
)
script_name
=
self
.
REQUEST
[
'SCRIPT_NAME'
]
__traceback_info__
=
(
`uri`
,
`script_name`
)
else
:
url
=
self
.
absolute_url
(
)
type
,
uri
=
ftype
(
url
)
host
,
uri
=
fhost
(
uri
)
script_name
=
self
.
REQUEST
[
'SCRIPT_NAME'
]
if
script_name
:
uri
=
filter
(
None
,
uri
.
split
(
script_name
))[
0
]
uri
=
filter
(
None
,
uri
.
split
(
script_name
))[
0
]
if
not
uri
:
uri
=
'/'
if
uri
[
0
]
!=
'/'
:
...
...
@@ -117,24 +121,27 @@ class CatalogAware:
"""Return a summary of the text content of the object."""
if
not
hasattr
(
self
,
'text_content'
):
return
''
attr
=
getattr
(
self
,
'text_content'
)
attr
=
getattr
(
self
,
'text_content'
)
if
callable
(
attr
):
text
=
attr
()
else
:
text
=
attr
n
=
min
(
num
,
len
(
text
))
text
=
attr
()
else
:
text
=
attr
n
=
min
(
num
,
len
(
text
))
return
text
[:
n
]
def
index_object
(
self
):
"""A common method to allow Findables to index themselves."""
self
.
_warn_deprecated
()
if
hasattr
(
self
,
self
.
default_catalog
):
getattr
(
self
,
self
.
default_catalog
).
catalog_object
(
self
,
self
.
url
())
catalog
=
getattr
(
self
,
self
.
default_catalog
,
None
)
if
catalog
is
not
None
:
catalog
.
catalog_object
(
self
,
self
.
url
())
def
unindex_object
(
self
):
"""A common method to allow Findables to unindex themselves."""
self
.
_warn_deprecated
()
if
hasattr
(
self
,
self
.
default_catalog
):
getattr
(
self
,
self
.
default_catalog
).
uncatalog_object
(
self
.
url
())
catalog
=
getattr
(
self
,
self
.
default_catalog
,
None
)
if
catalog
is
not
None
:
catalog
.
uncatalog_object
(
self
.
url
())
def
reindex_object
(
self
):
""" Suprisingly useful """
...
...
@@ -143,7 +150,8 @@ class CatalogAware:
def
reindex_all
(
self
,
obj
=
None
):
""" """
if
obj
is
None
:
obj
=
self
if
obj
is
None
:
obj
=
self
if
hasattr
(
aq_base
(
obj
),
'index_object'
):
obj
.
index_object
()
if
hasattr
(
aq_base
(
obj
),
'objectValues'
):
...
...
src/Products/ZCatalog/CatalogPathAwareness.py
View file @
74261752
...
...
@@ -18,6 +18,7 @@ import warnings
from
Acquisition
import
aq_base
from
App.special_dtml
import
DTMLFile
class
CatalogAware
:
""" This is a Mix-In class to make objects automaticly catalog and
uncatalog themselves in Zope, and to provide some other basic
...
...
@@ -54,7 +55,8 @@ class CatalogAware:
except
Exception
:
s
=
0
object
.
manage_afterAdd
(
item
,
container
)
if
s
is
None
:
object
.
_p_deactivate
()
if
s
is
None
:
object
.
_p_deactivate
()
def
manage_afterClone
(
self
,
item
):
self
.
index_object
()
...
...
@@ -64,7 +66,8 @@ class CatalogAware:
except
Exception
:
s
=
0
object
.
manage_afterClone
(
item
)
if
s
is
None
:
object
.
_p_deactivate
()
if
s
is
None
:
object
.
_p_deactivate
()
def
manage_beforeDelete
(
self
,
item
,
container
):
self
.
unindex_object
()
...
...
@@ -74,7 +77,8 @@ class CatalogAware:
except
Exception
:
s
=
0
object
.
manage_beforeDelete
(
item
,
container
)
if
s
is
None
:
object
.
_p_deactivate
()
if
s
is
None
:
object
.
_p_deactivate
()
def
creator
(
self
):
"""Return a sequence of user names who have the local
...
...
@@ -102,8 +106,9 @@ class CatalogAware:
attr
=
getattr
(
self
,
'text_content'
)
if
callable
(
attr
):
text
=
attr
()
else
:
text
=
attr
n
=
min
(
num
,
len
(
text
))
else
:
text
=
attr
n
=
min
(
num
,
len
(
text
))
return
text
[:
n
]
def
index_object
(
self
):
...
...
@@ -127,7 +132,8 @@ class CatalogAware:
def
reindex_all
(
self
,
obj
=
None
):
""" """
if
obj
is
None
:
obj
=
self
if
obj
is
None
:
obj
=
self
if
hasattr
(
aq_base
(
obj
),
'index_object'
):
obj
.
index_object
()
if
hasattr
(
aq_base
(
obj
),
'objectValues'
):
...
...
src/Products/ZCatalog/__init__.py
View file @
74261752
...
...
@@ -15,6 +15,7 @@
import
ZCatalog
def
initialize
(
context
):
context
.
registerClass
(
ZCatalog
.
ZCatalog
,
...
...
src/Products/ZCatalog/interfaces.py
View file @
74261752
...
...
@@ -246,6 +246,7 @@ class IZCatalog(Interface):
"""
# This should inherit from an IRecord interface, if there ever is one.
class
ICatalogBrain
(
Interface
):
"""Catalog brain that handles looking up attributes as
required, and provides just enough smarts to let us get the URL, path,
...
...
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