From 48585bed72645117836290d0e5fb6a11bfa7e80a Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Tue, 5 Apr 2011 14:10:03 +0200 Subject: utility --- src/meetingtools/ac/api.py | 13 +++++++------ 1 file 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 -- cgit v1.1