trivial: use logger .warning() instead of deprecated .warn() (#46990)

This commit is contained in:
Frédéric Péters 2020-09-24 08:42:07 +02:00
parent 659243f9c7
commit 51fd23a435
8 changed files with 19 additions and 18 deletions

View File

@ -54,7 +54,7 @@ class Condition(object):
return self.unsafe_evaluate()
except Exception as e:
if self.log_errors:
get_logger().warn('failed to evaluate %r (%r)', self, e)
get_logger().warning('failed to evaluate %r (%r)', self, e)
if self.record_errors:
from wcs.logged_errors import LoggedError
summary = _('Failed to evaluate condition')

View File

@ -199,7 +199,7 @@ def get_structured_items(data_source, mode=None):
try:
value = eval(data_source.get('value'), global_eval_dict, variables)
if not isinstance(value, collections.Iterable):
get_logger().warn('Python data source (%r) gave a non-iterable result' %
get_logger().warning('Python data source (%r) gave a non-iterable result' %
data_source.get('value'))
return []
if len(value) == 0:
@ -217,7 +217,7 @@ def get_structured_items(data_source, mode=None):
return [{'id': x, 'text': x} for x in value]
return value
except:
get_logger().warn('Failed to eval() Python data source (%r)' % data_source.get('value'))
get_logger().warning('Failed to eval() Python data source (%r)' % data_source.get('value'))
return []
elif data_source.get('type') in ['json', 'geojson']:
# the content available at a json URL, it must answer with a dict with
@ -393,7 +393,7 @@ class NamedDataSource(XmlStorableObject):
objects = [x for x in cls.select() if x.slug == slug]
if objects:
return objects[0]
get_logger().warn("data source '%s' does not exist" % slug)
get_logger().warning("data source '%s' does not exist" % slug)
return StubNamedDataSource(name=slug)
def get_json_query_url(self):

View File

@ -86,5 +86,5 @@ class MailTemplate(XmlStorableObject):
objects = [x for x in cls.select() if x.slug == slug]
if objects:
return objects[0]
get_logger().warn("mail template '%s' does not exist" % slug)
get_logger().warning("mail template '%s' does not exist" % slug)
return None

View File

@ -155,7 +155,7 @@ def convert_to_mime(attachment):
part.add_header('Content-Disposition', 'attachment',
filename=attachment.base_filename)
return part
get_logger().warn('Failed to build MIME part from %r', attachment)
get_logger().warning('Failed to build MIME part from %r', attachment)
def email(subject, mail_body, email_rcpt, replyto=None, bcc=None,

View File

@ -93,7 +93,7 @@ def get_lasso_server():
try:
server.setEncryptionPrivateKey(encryption_privatekey)
except lasso.Error as error:
get_logger().warn('Failed to set encryption private key')
get_logger().warning('Failed to set encryption private key')
for klp, idp in sorted(get_cfg('idp', {}).items(), key=lambda k: k[0]):
try:

View File

@ -765,11 +765,11 @@ class QommonPublisher(Publisher, object):
try:
tree = ET.parse(open(filename))
except:
self.get_app_logger().warn('failed to import config from; failed to parse: %s', filename)
self.get_app_logger().warning('failed to import config from; failed to parse: %s', filename)
raise
if tree.getroot().tag != 'settings':
self.get_app_logger().warn('failed to import config; not a settings file: %s', filename)
self.get_app_logger().warning('failed to import config; not a settings file: %s', filename)
return
cfg = {}

View File

@ -61,10 +61,10 @@ def soap_call(url, msg, client_cert = None):
cert_file=client_cert)
except errors.ConnectionError as err:
# exception could be raised by request
get_logger().warn('SOAP error (on %s): %s' % (url, err))
get_logger().warning('SOAP error (on %s): %s' % (url, err))
raise SOAPException(url)
if status not in (200, 204): # 204 ok for federation termination
get_logger().warn('SOAP error (%s) (on %s)' % (status, url))
get_logger().warning('SOAP error (%s) (on %s)' % (status, url))
raise SOAPException(url)
return data
@ -409,7 +409,7 @@ class Saml2Directory(Directory):
try:
assertion = lasso_session.getAssertions(None)[0]
except:
get_logger().warn('no assertion')
get_logger().warning('no assertion')
return None
d = {}
@ -481,7 +481,7 @@ class Saml2Directory(Directory):
for uuid in m['role-slug']:
role = Role.resolve(uuid)
if not role:
logger.warn('role uuid %s is unknown', uuid)
logger.warning('role uuid %s is unknown', uuid)
continue
role_ids.append(force_str(role.id))
names.append(force_str(role.name))
@ -550,7 +550,7 @@ class Saml2Directory(Directory):
if not user.name:
# we didn't get useful attributes, forget it.
get_logger().warn('failed to get useful attributes from the assertion')
get_logger().warning('failed to get useful attributes from the assertion')
return None
user.store()
@ -606,7 +606,7 @@ class Saml2Directory(Directory):
except lasso.Error as error:
self.log_profile_error(logout, error, 'logout.processResponseMsg')
if error[0] == lasso.LOGOUT_ERROR_UNKNOWN_PRINCIPAL:
get_logger().warn('Unknown principal on logout, probably session stopped already on IdP')
get_logger().warning('Unknown principal on logout, probably session stopped already on IdP')
# XXX: wouldn't work when logged on two IdP
session.lasso_session_dump = None
else:
@ -645,12 +645,12 @@ class Saml2Directory(Directory):
request = get_request()
ctype = request.environ.get('CONTENT_TYPE')
if not ctype:
get_logger().warn('SOAP Endpoint got message without content-type')
get_logger().warning('SOAP Endpoint got message without content-type')
raise SOAPException()
ctype, ctype_params = parse_header(ctype)
if ctype not in ('text/xml', 'application/vnd.paos+xml'):
get_logger().warn('SOAP Endpoint got message with wrong content-type (%s)' % ctype)
get_logger().warning('SOAP Endpoint got message with wrong content-type (%s)' % ctype)
raise SOAPException()
length = int(request.environ.get('CONTENT_LENGTH'))

View File

@ -31,7 +31,8 @@ class Script(object):
script_path = os.path.join(path, script_name + '.py')
if os.path.exists(script_path):
self.__file__ = script_path
self.code = open(script_path).read()
with open(script_path) as fd:
self.code = fd.read()
break
else:
raise ValueError()