ws: fixed compatibility with python 2.6 when catching XML parse errors coming from ElementTree
python < 2.7 raise ExpatError python >= 2.7 raise ElementTree.ParseError
This commit is contained in:
parent
c24fc52845
commit
5dbe50613b
|
@ -19,6 +19,13 @@ Category = collections.namedtuple('Category',
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PARSE_ERRORS = (ExpatError, )
|
||||
try:
|
||||
from xml.etree.ElementTree import ParseError
|
||||
PARSE_ERRORS += (ParseError,)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def bool2str(b):
|
||||
return 'YES' if b else 'NO'
|
||||
|
||||
|
@ -43,8 +50,8 @@ class BlackboardConnector(object):
|
|||
if r.status_code == 200 and r.content.startswith('<'):
|
||||
try:
|
||||
x = etree.XML(r.content.replace('ISO-8859-1', 'UTF-8'))
|
||||
except ExpatError:
|
||||
logger.exception('ExpatError')
|
||||
except PARSE_ERRORS:
|
||||
logger.exception('XML Parsing error request to %s', r.url)
|
||||
return False, 'Erreur BlackBoard'
|
||||
info_message_elt = x.find('infoMessage')
|
||||
course_elts = x.findall('*/course')
|
||||
|
@ -141,8 +148,8 @@ class BlackboardConnector(object):
|
|||
if r.status_code == 200 and r.content.startswith('<'):
|
||||
try:
|
||||
x = etree.XML(r.content.replace('ISO-8859-1', 'UTF-8'))
|
||||
except ExpatError:
|
||||
logger.exception('ExpatError %s', r.content)
|
||||
except PARSE_ERRORS:
|
||||
logger.exception('XML Parsing error request to %s', r.url)
|
||||
return False, 'Erreur BlackBoard'
|
||||
info_message_elt = x.find('infoMessage')
|
||||
category_elts = x.findall('categories/category')
|
||||
|
|
Reference in New Issue