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
ff16522b
Commit
ff16522b
authored
Jun 24, 2010
by
Christian Zagrodnick
Browse files
Options
Browse Files
Download
Plain Diff
Port from 2.12:
- LP #597594: Performance optimization in OFS.subscriber.maybeWarnDeprecated.
parents
23e9a894
9a31a165
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
5 deletions
+98
-5
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
src/OFS/subscribers.py
src/OFS/subscribers.py
+8
-5
src/OFS/tests/test_subscribers.py
src/OFS/tests/test_subscribers.py
+88
-0
No files found.
doc/CHANGES.rst
View file @
ff16522b
...
...
@@ -204,6 +204,8 @@ Features Added
Bugs Fixed
++++++++++
- LP #597594: Performance optimization in OFS.subscriber.maybeWarnDeprecated.
- LP #143639: When the last cache manager in a container is
deleted, we need to remove all traces of it from the
container.
...
...
src/OFS/subscribers.py
View file @
ff16522b
##############################################################################
#
# Copyright (c) 2005 Zope Foundation and Contributors.
# Copyright (c) 2005
,2010
Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -56,13 +56,16 @@ def maybeWarnDeprecated(ob, method_name):
if
not
deprecatedManageAddDeleteClasses
:
# Directives not fully loaded
return
for
cls
in
deprecatedManageAddDeleteClasses
:
if
isinstance
(
ob
,
cls
):
# Already deprecated through zcml
return
if
getattr
(
getattr
(
ob
,
method_name
),
'__five_method__'
,
False
):
# Method knows it's deprecated
return
ob_type
=
type
(
ob
)
# Quick check for directly deprecated classes
if
ob_type
in
deprecatedManageAddDeleteClasses
:
return
if
any
(
issubclass
(
ob_type
,
cls
)
for
cls
in
deprecatedManageAddDeleteClasses
):
return
class_
=
ob
.
__class__
LOG
.
debug
(
"%s.%s.%s is discouraged. You should use event subscribers instead."
%
...
...
src/OFS/tests/test_subscribers.py
0 → 100644
View file @
ff16522b
##############################################################################
#
# Copyright (c) 2010 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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
StringIO
import
logging
import
unittest
class
TestMaybeWarnDeprecated
(
unittest
.
TestCase
):
def
setUp
(
self
):
# Make a copy so we can freely modify the contents
from
OFS.subscribers
import
deprecatedManageAddDeleteClasses
self
.
_orig_deprecatedManageAddDeleteClasses
=
(
deprecatedManageAddDeleteClasses
[:])
self
.
deprecatedManageAddDeleteClasses
=
(
deprecatedManageAddDeleteClasses
)
# Add a class to make sure there is at least one because an empty
# deprecatedManageAddDeleteClasses list is special cased
self
.
deprecatedManageAddDeleteClasses
.
append
(
int
)
# Pick up log messages
self
.
logfile
=
StringIO
.
StringIO
()
self
.
log_handler
=
logging
.
StreamHandler
(
self
.
logfile
)
logging
.
root
.
addHandler
(
self
.
log_handler
)
self
.
old_log_level
=
logging
.
root
.
level
logging
.
root
.
setLevel
(
logging
.
DEBUG
)
def
tearDown
(
self
):
self
.
deprecatedManageAddDeleteClasses
[:]
=
(
self
.
_orig_deprecatedManageAddDeleteClasses
)
logging
.
root
.
removeHandler
(
self
.
log_handler
)
logging
.
root
.
setLevel
(
self
.
old_log_level
)
def
assertLog
(
self
,
class_
,
expected
):
from
OFS.subscribers
import
maybeWarnDeprecated
maybeWarnDeprecated
(
class_
(),
'manage_afterAdd'
)
self
.
assertEquals
(
expected
,
self
.
logfile
.
getvalue
())
def
test_method_deprecated
(
self
):
class
Deprecated
(
object
):
def
manage_afterAdd
(
self
):
pass
manage_afterAdd
.
__five_method__
=
True
self
.
assertLog
(
Deprecated
,
''
)
def
test_class_deprecated
(
self
):
class
Deprecated
(
object
):
def
manage_afterAdd
(
self
):
pass
self
.
deprecatedManageAddDeleteClasses
.
append
(
Deprecated
)
self
.
assertLog
(
Deprecated
,
''
)
def
test_subclass_deprecated
(
self
):
class
Deprecated
(
object
):
def
manage_afterAdd
(
self
):
pass
class
ASubClass
(
Deprecated
):
pass
self
.
deprecatedManageAddDeleteClasses
.
append
(
Deprecated
)
self
.
assertLog
(
ASubClass
,
''
)
def
test_not_deprecated
(
self
):
class
Deprecated
(
object
):
def
manage_afterAdd
(
self
):
pass
self
.
assertLog
(
Deprecated
,
'OFS.tests.test_subscribers.Deprecated.manage_afterAdd is '
'discouraged. You should use event subscribers instead.
\
n
'
)
def
test_not_deprecated_when_there_are_no_classes
(
self
):
class
Deprecated
(
object
):
def
manage_afterAdd
(
self
):
pass
self
.
deprecatedManageAddDeleteClasses
[:]
=
[]
self
.
assertLog
(
Deprecated
,
''
)
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