diff options
author | Leif Johansson <leifj@sunet.se> | 2011-04-05 14:10:03 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-04-05 14:10:03 +0200 |
commit | 48585bed72645117836290d0e5fb6a11bfa7e80a (patch) | |
tree | 3dc478c45276c53ebb7ab00bc4a3e23f1a76620a | |
parent | db19695091b11c662ef20ceb46157e01fb8af074 (diff) |
utility
-rw-r--r-- | src/meetingtools/ac/api.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/meetingtools/ac/api.py b/src/meetingtools/ac/api.py index aa36067..553890b 100644 --- a/src/meetingtools/ac/api.py +++ b/src/meetingtools/ac/api.py @@ -22,11 +22,16 @@ class ACPException(Exception): def __str__(self): return etree.tostring(self.value) +def _first_or_none(x): + if not x: + return None + return x[0] + class ACPResult(): def __init__(self,content): self.et = etree.fromstring(content) - self.status = self.et.xpath('//status')[0] + self.status = _first_or_none(self.et.xpath('//status')) def is_error(self): return self.status_code() != 'ok' @@ -39,11 +44,7 @@ class ACPResult(): def get_principal(self): logger.debug(lxml.etree.tostring(self.et)) - pl = self.et.xpath('//principal') - if pl: - return pl[0] - else: - return None + return _first_or_none(self.et.xpath('//principal')) def _enc(v): ev = v |