[Python-checkins] CVS: python/dist/src/Lib warnings.py,1.9,1.10
Walter D?rwald
doerwalter@users.sourceforge.net
Thu, 21 Mar 2002 02:38:42 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv27021/Lib
Modified Files:
warnings.py
Log Message:
[Apply SF patch #504943]
This patch makes it possible to pass Warning instances as the first
argument to warnings.warn. In this case the category argument
will be ignored. The message text used will be str(warninginstance).
Index: warnings.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/warnings.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** warnings.py 31 Aug 2001 17:46:35 -0000 1.9
--- warnings.py 21 Mar 2002 10:38:40 -0000 1.10
***************
*** 12,15 ****
--- 12,18 ----
def warn(message, category=None, stacklevel=1):
"""Issue a warning, or maybe ignore it or raise an exception."""
+ # Check if message is already a Warning object
+ if isinstance(message, Warning):
+ category = message.__class__
# Check category argument
if category is None:
***************
*** 50,54 ****
if registry is None:
registry = {}
! key = (message, category, lineno)
# Quick test for common case
if registry.get(key):
--- 53,63 ----
if registry is None:
registry = {}
! if isinstance(message, Warning):
! text = str(message)
! category = message.__class__
! else:
! text = message
! message = category(message)
! key = (text, category, lineno)
# Quick test for common case
if registry.get(key):
***************
*** 57,61 ****
for item in filters:
action, msg, cat, mod, ln = item
! if (msg.match(message) and
issubclass(category, cat) and
mod.match(module) and
--- 66,70 ----
for item in filters:
action, msg, cat, mod, ln = item
! if (msg.match(text) and
issubclass(category, cat) and
mod.match(module) and
***************
*** 69,77 ****
return
if action == "error":
! raise category(message)
# Other actions
if action == "once":
registry[key] = 1
! oncekey = (message, category)
if onceregistry.get(oncekey):
return
--- 78,86 ----
return
if action == "error":
! raise message
# Other actions
if action == "once":
registry[key] = 1
! oncekey = (text, category)
if onceregistry.get(oncekey):
return
***************
*** 81,85 ****
elif action == "module":
registry[key] = 1
! altkey = (message, category, 0)
if registry.get(altkey):
return
--- 90,94 ----
elif action == "module":
registry[key] = 1
! altkey = (text, category, 0)
if registry.get(altkey):
return