Commit 9775ec28 authored by Julien Muchembled's avatar Julien Muchembled

* Log 'warning.*' to zope log instead of stderr

* Add new 'deprecated' decorator for deprecated functions/methods

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28769 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3e8b181a
......@@ -32,6 +32,7 @@ import os
import re
import string
import time
import warnings
from md5 import new as md5_new
from sha import new as sha_new
......@@ -163,7 +164,27 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
value_list.sort(**sort_kw)
return value_list
#####################################################
# Logging
#####################################################
def _showwarning(message, category, filename, lineno, file=None):
if file is None:
LOG("%s:%u %s: %s" % (filename, lineno, category.__name__, message),
WARNING, '')
else:
file.write(warnings.formatwarning(message, category, filename, lineno))
warnings.showwarning = _showwarning
def deprecated(wrapped):
message = "Use of '%s' function (%s, line %s) is deprecated." % (
wrapped.__name__, wrapped.__module__, wrapped.func_code.co_firstlineno)
def wrapper(*args, **kw):
warnings.warn(message, DeprecationWarning, 2)
return wrapped(*args, **kw)
return wrapper
#####################################################
# Useful methods
#####################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment