From 013e6ce6ff126e892e5af824aa1c3c3ab268a11d Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 28 Mar 2013 18:49:36 +0200 Subject: Fixing CompTIA.fetch() --- gsxws.py | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'gsxws.py') diff --git a/gsxws.py b/gsxws.py index a913ebe..7eb6ecc 100755 --- a/gsxws.py +++ b/gsxws.py @@ -212,43 +212,29 @@ class CompTIA: def __init__(self): df = open(os.path.join(os.path.dirname(__file__), 'comptia.json')) self.data = json.load(df) + self.groups = dict() + self.modifiers = dict() def fetch(self): - """ + ''' Here we must resort to raw XML parsing since SUDS throws this: suds.TypeNotFound: Type not found: 'comptiaDescription' when calling CompTIACodes()... - """ + ''' CLIENT.set_options(retxml=True) dt = CLIENT.factory.create('ns3:comptiaCodeLookupRequestType') dt.userSession = SESSION xml = CLIENT.service.CompTIACodes(dt) - root = ET.fromstring(xml).findall('.//%s' % 'comptiaInfo')[0] - - # Process CompTIA Groups - class ComptiaGroup: - pass - - class ComptiaModifier: - pass - - self.groups = list() - self.modifiers = list() - + for el in root.findall('.//comptiaGroup'): - dt = ComptiaGroup() + for i in element.iter(): + setattr(obj, i.tag, i.text) self.groups.append(self.__process(el, dt)) - + for el in root.findall('.//comptiaModifier'): - mod = ComptiaModifier() - self.modifiers.append(self.__process(el, mod)) - - def __process(self, element, obj): - for i in element.iter(): - setattr(obj, i.tag, i.text) - - return obj + descr, code = list(el) + self.modifiers[code.text] = descr.text def symptoms(self, component=None): symptoms = self.data['symptoms'] -- cgit v1.2.3