[Yum-devel] [PATCH 2/2] Hide invalid XML errors for updateinfo, BZ 663378
seth vidal
skvidal at fedoraproject.org
Fri Feb 4 16:31:48 UTC 2011
On Fri, 2011-02-04 at 11:24 -0500, James Antill wrote:
> ---
> yum/update_md.py | 11 ++++++++++-
> 1 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/yum/update_md.py b/yum/update_md.py
> index 83e56c6..619250e 100644
> --- a/yum/update_md.py
> +++ b/yum/update_md.py
> @@ -32,6 +32,15 @@ import Errors
>
> import rpmUtils.miscutils
>
> +
> +def safe_iterparse(filename):
> + """ Works like iterparse, but hides XML errors (prints a warning). """
> + try:
> + for event, elem in safe_iterparse(infile):
> + yield event, elem
> + except SyntaxError: # Bad XML
> + print >> sys.stderr, "File is not valid XML:", filename
> +
> class UpdateNoticeException(Exception):
> """ An exception thrown for bad UpdateNotice data. """
> pass
> @@ -445,7 +454,7 @@ class UpdateMetadata(object):
> else: # obj is a file object
> infile = obj
>
> - for event, elem in iterparse(infile):
> + for event, elem in safe_iterparse(infile):
> if elem.tag == 'update':
> try:
> un = UpdateNotice(elem)
maybe worth putting the safe_iterparse in misc and using it in comps.py,
repoMDObject.py?
-sv
More information about the Yum-devel
mailing list