diff options
author | Filipp Lepalaan <f@230.to> | 2013-03-29 12:16:15 +0200 |
---|---|---|
committer | Filipp Lepalaan <f@230.to> | 2013-03-29 12:16:15 +0200 |
commit | 4621f14bae1487c0eb1bfd57d64b3c16a08072a7 (patch) | |
tree | c62bc8b933f7be59e192c9c225a8b53e827d4a1f | |
parent | 013e6ce6ff126e892e5af824aa1c3c3ab268a11d (diff) | |
download | py-gsxws-4621f14bae1487c0eb1bfd57d64b3c16a08072a7.tar.gz py-gsxws-4621f14bae1487c0eb1bfd57d64b3c16a08072a7.tar.bz2 py-gsxws-4621f14bae1487c0eb1bfd57d64b3c16a08072a7.zip |
Fixed CompTIA.fetch
-rwxr-xr-x | gsxws.py | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -206,15 +206,21 @@ class GsxObject(object): class CompTIA: - """ + ''' Stores and accesses CompTIA codes. - """ + ''' 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 __getattr__(self, name): + try: + return self.groups[name] + except KeyError, e: + raise e('Unknown component code: %s' % name) + def fetch(self): ''' Here we must resort to raw XML parsing since SUDS throws this: @@ -224,13 +230,23 @@ class CompTIA: 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] + + try: + xml = CLIENT.service.CompTIACodes(dt) + except suds.WebFault, e: + raise GsxError(fault=e) + root = ET.fromstring(xml).findall('.//%s' % 'comptiaInfo')[0] + for el in root.findall('.//comptiaGroup'): - for i in element.iter(): - setattr(obj, i.tag, i.text) - self.groups.append(self.__process(el, dt)) + comp_id = el[0].text + group = {'id': comp_id, 'name': el[1].text} + group['codes'] = dict() + + for ci in el.findall('comptiaCodeInfo'): + group['codes'][ci[0].text] = ci[1].text + + self.groups[comp_id] = group for el in root.findall('.//comptiaModifier'): descr, code = list(el) @@ -243,6 +259,7 @@ class CompTIA: r = list() for k, v in symptoms[component].items(): r.append((k, v)) + return r return symptoms |