From 3e29e3cf5ff9d996faa88642e286d914b005177b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Thu, 4 Feb 2010 08:25:43 +0000 Subject: [PATCH] Handle possible None values for obj when the element is optional --- ChangeLog | 5 +++++ pisi/pxml/autoxml.py | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2b20813..45fc86c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-04 Ozan Çağlayan + * pisi/pxml/autoxml.py (format): Some optional elements may be None + during formatting, handle those situations. We still have a formatting + issue caused by the automagical output representation of autoxml. + 2010-02-02 Ozan Çağlayan * pisi/component.py(Maintainer): Add Maintainer tag to components.xml. diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index f381047c..615d6665 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -727,11 +727,16 @@ class autoxml(oo.autosuper, oo.autoprop): return obj.errors(where) def format(obj, f, errs): - try: - obj.format(f, errs) - except Error: + if obj: + try: + obj.format(f, errs) + except Error: + if req == mandatory: + errs.append(_('Object cannot be formatted')) + else: if req == mandatory: errs.append(_('Mandatory argument not available')) + return (init, decode, encode, errors, format) def gen_list_tag(cls, tag, spec): @@ -841,9 +846,13 @@ class autoxml(oo.autosuper, oo.autoprop): return obj.errors(where) def format(obj, f, errs): - try: - obj.format(f, errs) - except Error: + if obj: + try: + obj.format(f, errs) + except Error: + if req == mandatory: + errs.append(_('Object cannot be formatted')) + else: if req == mandatory: errs.append(_('Mandatory argument not available'))