From 1791a15e07ad1ffe0ead981ea64ed6e29f6837d5 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 17 May 2022 17:35:30 -0400 Subject: [PATCH 1/4] wip --- src/ucis/xml/__init__.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ucis/xml/__init__.py b/src/ucis/xml/__init__.py index dc6c01d..bda3169 100644 --- a/src/ucis/xml/__init__.py +++ b/src/ucis/xml/__init__.py @@ -22,48 +22,50 @@ def validate_ucis_xml(file_or_filename): - + xml_pkg_dir = os.path.dirname(os.path.abspath(__file__)) schema_dir = os.path.join(xml_pkg_dir, "schema") ucis_xsd = os.path.join(schema_dir, "ucis.xsd") - + with open(ucis_xsd, "r") as xsd_fp: ucis_xsd_doc = etree.parse(xsd_fp) - + # print("schema_doc: " + tounicode(ucis_xsd_doc, pretty_print=True)) - + ucis_schema = etree.XMLSchema(ucis_xsd_doc) - + # print("schema: " + str(ucis_schema)) - + if type(file_or_filename) == str: print("open file") fp = open(file_or_filename, "r") else: fp = file_or_filename - + ret = False try: doc = etree.parse(fp) - + root = doc.getroot() # There is some inconsistency in whether # elements should be namespace-qualified or not. # The official schema indicates that they should be, # while the examples indicate they shouldn't be. The - # (apparently) simplest way around this is to remove + # (apparently) simplest way around this is to remove # namespace qualification entirely. for elem in root.getiterator(): if not hasattr(elem.tag, 'find'): continue # (1) i = elem.tag.find('}') if i >= 0: - elem.tag = elem.tag[i+1:] - + elem.tag = elem.tag[i+1:] + ret = ucis_schema.assertValid(doc) + print('ret is ', ret) + finally: if type(file_or_filename) == str: fp.close() - return ret \ No newline at end of file + return ret From 05d0b208e6b466c2db6e092ed279a7359bf257d8 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 17 May 2022 17:39:45 -0400 Subject: [PATCH 2/4] wip --- src/ucis/xml/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ucis/xml/__init__.py b/src/ucis/xml/__init__.py index bda3169..27ad6f8 100644 --- a/src/ucis/xml/__init__.py +++ b/src/ucis/xml/__init__.py @@ -61,8 +61,16 @@ def validate_ucis_xml(file_or_filename): if i >= 0: elem.tag = elem.tag[i+1:] - ret = ucis_schema.assertValid(doc) + # TODO: fix this hack + # ret is None. + # set to True print('ret is ', ret) + ret = ucis_schema.assertValid(doc) + ret = True + + except: + print('An exception occured') + ret = False finally: if type(file_or_filename) == str: From 4530910464329ee3f83bd493ca31c6703e980b04 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 17 May 2022 17:42:13 -0400 Subject: [PATCH 3/4] wip --- src/ucis/xml/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ucis/xml/__init__.py b/src/ucis/xml/__init__.py index 27ad6f8..58ef79a 100644 --- a/src/ucis/xml/__init__.py +++ b/src/ucis/xml/__init__.py @@ -64,9 +64,10 @@ def validate_ucis_xml(file_or_filename): # TODO: fix this hack # ret is None. # set to True - print('ret is ', ret) ret = ucis_schema.assertValid(doc) + print('ret is ', ret) ret = True + print('ret is now ', ret) except: print('An exception occured') From 043d98bb96e934e3e47f28136db5e3c3401258af Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Wed, 18 May 2022 10:40:38 -0400 Subject: [PATCH 4/4] mod per Matthew regarding return --- src/ucis/xml/__init__.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ucis/xml/__init__.py b/src/ucis/xml/__init__.py index 58ef79a..4becfb3 100644 --- a/src/ucis/xml/__init__.py +++ b/src/ucis/xml/__init__.py @@ -61,17 +61,8 @@ def validate_ucis_xml(file_or_filename): if i >= 0: elem.tag = elem.tag[i+1:] - # TODO: fix this hack - # ret is None. - # set to True ret = ucis_schema.assertValid(doc) - print('ret is ', ret) ret = True - print('ret is now ', ret) - - except: - print('An exception occured') - ret = False finally: if type(file_or_filename) == str: