egencache: implement XMLParser.doctype()
authorZac Medico <zmedico@gentoo.org>
Sat, 27 Aug 2011 19:01:06 +0000 (12:01 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 27 Aug 2011 19:01:06 +0000 (12:01 -0700)
This is prevents "DeprecationWarning: This method of XMLParser is
deprecated.  Define doctype() method on the TreeBuilder target."
warnings. The code is copied from repoman, commit
5a5e51a2737a0855bb562683f50c57cc31587460.

bin/egencache

index 6d8df35b5a0b3e8dfb1f977afdd7d8c747f908a2..a87394c0d8d62c5a8a4bb7e15391b277b65f16f1 100755 (executable)
@@ -368,6 +368,14 @@ class GenCache(object):
                                        "committing target: %s\n" % (ce,),
                                        level=logging.ERROR, noiselevel=-1)
 
+class _MetadataTreeBuilder(ElementTree.TreeBuilder):
+       """
+       Implements doctype() as required to avoid deprecation warnings with
+       >=python-2.7.
+       """
+       def doctype(self, name, pubid, system):
+               pass
+
 class GenUseLocalDesc(object):
        def __init__(self, portdb, output=None,
                        preserve_comments=False):
@@ -475,7 +483,9 @@ class GenUseLocalDesc(object):
                for cp in self._portdb.cp_all():
                        metadata_path = os.path.join(repo_path, cp, 'metadata.xml')
                        try:
-                               metadata = ElementTree.parse(metadata_path)
+                               metadata = ElementTree.parse(metadata_path,
+                                       parser=ElementTree.XMLParser(
+                                       target=_MetadataTreeBuilder()))
                        except IOError:
                                pass
                        except (ExpatError, EnvironmentError) as e: