#50118 Issue 50032 - Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated in Python 3.7
Closed 2 years ago by spichugi. Opened 3 years ago by vashirov.
vashirov/389-ds-base fix_deprecation_warnings  into  master

@@ -212,7 +212,7 @@ 

      log.info('parse the access logs')

      access_log_lines = topology_st.standalone.ds_access_log.readlines()

      assert len(access_log_lines) > 0

-     assert topology_st.standalone.ds_access_log.match('^\[.+\d{9}.+\].+')

+     assert topology_st.standalone.ds_access_log.match(r'^\[.+\d{9}.+\].+')

  

  

  @pytest.mark.bz1273549
@@ -261,7 +261,7 @@ 

      log.info('check access log that microseconds are not present')

      access_log_lines = topology_st.standalone.ds_access_log.readlines()

      assert len(access_log_lines) > 0

-     assert not topology_st.standalone.ds_access_log.match('^\[.+\d{9}.+\].+')

+     assert not topology_st.standalone.ds_access_log.match(r'^\[.+\d{9}.+\].+')

  

  

  @pytest.mark.bz1358706

@@ -31,7 +31,7 @@ 

           1. Add a test user with an '*' in its attribute value

              i.e. 'cn=test * me'

           2. Add another similar test user without '*' in its attribute value

-          3. Search test user using search filter "cn=*\**"

+          3. Search test user using search filter "cn=*\\**"

      :expectedresults:

           1. This should pass

           2. This should pass
@@ -64,9 +64,9 @@ 

          assert False

  

      try:

-         entry = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'cn=*\**')

+         entry = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'cn=*\\**')

          if not entry or len(entry) > 1:

-             log.fatal('test_filter_escaped: Entry was not found using "cn=*\**"')

+             log.fatal('test_filter_escaped: Entry was not found using "cn=*\\**"')

              assert False

      except ldap.LDAPError as e:

          log.fatal('test_filter_escaped: Failed to search for user(%s), error: %s' %

@@ -43,7 +43,7 @@ 

      """

  

      if os.geteuid() != 0:

-         log.warn('This script must be run as root')

+         log.warning('This script must be run as root')

          return

  

      os.system('setenforce 0')
@@ -62,7 +62,7 @@ 

      try:

          shutil.copy('%s/libwhoami-plugin.la' % plugin_dir, tmp_dir)

      except IOError as e:

-         log.warn('Failed to copy ' + plugin_dir +

+         log.warning('Failed to copy ' + plugin_dir +

                   '/libwhoami-plugin.la to the tmp directory, error: '

                   + e.strerror)

  

@@ -24,7 +24,7 @@ 

  

  log = logging.getLogger(__name__)

  

- ESCAPED_RDN_BASE = "foo\,oo"

+ ESCAPED_RDN_BASE = "foo\\,oo"

  def _user_get_dn(no):

      uid = '%s%d' % (ESCAPED_RDN_BASE, no)

      dn = 'uid=%s,%s' % (uid, SUFFIX)

@@ -234,7 +234,7 @@ 

      assert master_schema_csn == consumer_schema_csn

  

      # Check the error log of the supplier does not contain an error

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

      if res is not None:

          assert False
@@ -294,7 +294,7 @@ 

  

      # Check the error log of the supplier does not contain an error

      # This message may happen during the learning phase

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

  

  
@@ -341,7 +341,7 @@ 

      assert master_schema_csn == consumer_schema_csn

  

      # Check the error log of the supplier does not contain an error

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

      if res is not None:

          assert False
@@ -390,7 +390,7 @@ 

      assert master_schema_csn == consumer_schema_csn

  

      # Check the error log of the supplier does not contain an error

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

      if res is not None:

          assert False
@@ -457,7 +457,7 @@ 

  

      # Check the error log of the supplier does not contain an error

      # This message may happen during the learning phase

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

  

  
@@ -510,7 +510,7 @@ 

  

      # Check the error log of the supplier does not contain an error

      # This message may happen during the learning phase

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

      if res is not None:

          assert False
@@ -563,7 +563,7 @@ 

      assert master_schema_csn == consumer_schema_csn

  

      # Check the error log of the supplier does not contain an error

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

      if res is not None:

          assert False
@@ -630,7 +630,7 @@ 

  

      # Check the error log of the supplier does not contain an error

      # This message may happen during the learning phase

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

  

  
@@ -686,7 +686,7 @@ 

      assert master_schema_csn == consumer_schema_csn

  

      # Check the error log of the supplier does not contain an error

-     regex = re.compile("must not be overwritten \(set replication log for additional info\)")

+     regex = re.compile(r"must not be overwritten \(set replication log for additional info\)")

      res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex)

      if res is not None:

          assert False

@@ -132,7 +132,7 @@ 

              if fschema is None:

                  raise Exception("Empty schema file %s" % fn)

          except:

-             log.warn("Unable to parse %s as a schema file - skipping" % fn)

+             log.warning("Unable to parse %s as a schema file - skipping" % fn)

              continue

          log.info("Parsed %s as a schema file - checking" % fn)

          for oid in fschema.listall(occlass):

@@ -70,7 +70,7 @@ 

      try:

          topology_st.standalone.add_s(entry_2)

      except:

-         topology_st.standalone.log.warn("Adding %s failed" % entry_dn_2)

+         topology_st.standalone.log.warning("Adding %s failed" % entry_dn_2)

          pass

  

      topology_st.standalone.log.info("\n\n######################### IS SERVER UP? ######################\n")

@@ -48,7 +48,7 @@ 

  import glob

  import tarfile

  import subprocess

- import collections

+ from collections.abc import Callable

  import signal

  import errno

  import pwd
@@ -1769,7 +1769,7 @@ 

          wrap entries in an Entry class that provides some useful methods"""

          for name in dir(self.__class__.__bases__[0]):

              attr = getattr(self, name)

-             if isinstance(attr, collections.Callable):

+             if isinstance(attr, Callable):

                  setattr(self, name, wrapper(attr, name))

  

      def addLDIF(self, input_file, cont=False):
@@ -2109,7 +2109,7 @@ 

          try:

              self.add_s(ent)

          except ldap.ALREADY_EXISTS:

-             self.log.warn("Entry %s already exists", binddn)

+             self.log.warning("Entry %s already exists", binddn)

  

          try:

              entry = self._test_entry(binddn, ldap.SCOPE_BASE)
@@ -2247,11 +2247,11 @@ 

          except ldap.NO_SUCH_OBJECT:

              entry = None

          if entry:

-             self.log.warn("Agreement exists:", dn_agreement)

+             self.log.warning("Agreement exists:", dn_agreement)

              self.suffixes.setdefault(nsuffix, {})[str(consumer)] = dn_agreement

              return dn_agreement

          if (nsuffix in self.agmt) and (consumer in self.agmt[nsuffix]):

-             self.log.warn("Agreement exists:", dn_agreement)

+             self.log.warning("Agreement exists:", dn_agreement)

              return dn_agreement

  

          # In a separate function in this scope?
@@ -2445,7 +2445,7 @@ 

                  })

              self.setupBindDN(*attrs)

          except ldap.ALREADY_EXISTS:

-             self.log.warn("User already exists: %r ", user)

+             self.log.warning("User already exists: %r ", user)

  

          # setup replica

          # map old style args to new style replica args

file modified
+1 -1
@@ -370,7 +370,7 @@ 

          try:

              self.add_s(ent)

          except ldap.ALREADY_EXISTS:

-             log.warn("Entry %s already exists" % entry_dn)

+             log.warning("Entry %s already exists" % entry_dn)

  

          try:

              entry = self._test_entry(entry_dn, ldap.SCOPE_BASE)

@@ -944,7 +944,7 @@ 

          # we can just raise ALREADY_EXISTS

          try:

              entry = self.conn.getEntry(dn_agreement, ldap.SCOPE_BASE)

-             self.log.warn("Agreement already exists: %r", dn_agreement)

+             self.log.warning("Agreement already exists: %r", dn_agreement)

              return dn_agreement

          except ldap.NO_SUCH_OBJECT:

              entry = None

@@ -128,7 +128,7 @@ 

          try:

              self.conn.add_s(entry)

          except ldap.ALREADY_EXISTS:

-             self.log.warn("entry %s already exists", dn)

+             self.log.warning("entry %s already exists", dn)

          return dn

  

      def delete(self):

@@ -9,7 +9,7 @@ 

  import os

  import re

  import sys

- import collections

+ from collections.abc import Callable

  

  

  class DSDecorator(object):
@@ -81,7 +81,7 @@ 

                  # for each function from module create decorated one

                  for attr in dir(module):

                      fun = getattr(module, attr)

-                     if isinstance(fun, collections.Callable):

+                     if isinstance(fun, Callable):

                          decorated = DSDecorator(fun, ds)

                          setattr(proxy, attr, decorated)

                  setattr(obj, item, proxy)

file modified
+3 -3
@@ -130,7 +130,7 @@ 

                       'passwordExpirationTime': '20381010000000Z'}

              self.conn.setupBindDN(repl_manager_dn, repl_manager_pw, attrs)

          except ldap.ALREADY_EXISTS:

-             self.log.warn("User already exists (weird we just checked: %s ",

+             self.log.warning("User already exists (weird we just checked: %s ",

                            repl_manager_dn)

  

      def list(self, suffix=None, replica_dn=None):
@@ -384,7 +384,7 @@ 

          dn_replica = ','.join((RDN_REPLICA, mtent.dn))

          try:

              entry = self.conn.getEntry(dn_replica, ldap.SCOPE_BASE)

-             self.log.warn("Already setup replica for suffix %r", nsuffix)

+             self.log.warning("Already setup replica for suffix %r", nsuffix)

              self.conn.suffixes.setdefault(nsuffix, {})

              self.conn.replica.setProperties(replica_dn=dn_replica,

                                              properties=properties)
@@ -662,7 +662,7 @@ 

          if ents and (len(ents) > 0):

              ent = ents[0]

          elif tryrepl:

-             self.log.warn("Could not get RUV from %r entry -"

+             self.log.warning("Could not get RUV from %r entry -"

                            " trying cn=replica", suffix)

              ensuffix = escapeDNValue(normalizeDN(suffix))

              dn = ','.join(("cn=replica", "cn=%s" % ensuffix, DN_MAPPING_TREE))

@@ -168,7 +168,7 @@ 

              for inst in all_replicas:

                  replObj = inst.replicas.get(suffix)

                  if replObj is None:

-                     inst.log.warn('(%s) not setup for replication of (%s)' %

+                     inst.log.warning('(%s) not setup for replication of (%s)' %

                                     (inst.serverid, suffix))

                      continue

                  ctime = _getCSNTime(inst, csnstr)

@@ -46,7 +46,7 @@ 

          try:

              conn.delete_s(e)

          except ldap.NO_SUCH_OBJECT:

-             log.warn("entry not found %r" % e)

+             log.warning("entry not found %r" % e)

  

  

  def bind_test():

Bug Description:
Deprecation warnings are issued by Python for the following changes:
1. https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior
https://bugs.python.org/issue27364 - Deprecate invalid escape sequences in str/bytes
2. https://docs.python.org/3/whatsnew/3.7.html#deprecated-python-behavior
https://bugs.python.org/issue25988 - collections.abc.Indexable
3. https://docs.python.org/3/library/logging.html#logging.warning
https://bugs.python.org/issue13235 - logging.warn() is not documented

Fix Description:
1. Use correct escape sequences or raw strings where needed.
2. Import Callable from collections.abc instead of collections module directly.
3. Use logging.warning() instead of logging.warn().

https://pagure.io/389-ds-base/issue/50032

Reviewed by: ???

Just a small nitpick - the commit subject is too long.
The rest looks good to me.

Hey @vashirov I think this can be merged?

rebased onto 7a0b8ae

3 years ago

Pull-Request has been merged by vashirov

3 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3177

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

2 years ago