[#80] Support for Python 2.6 when handling xml exceptions
This commit is contained in:
parent
2a07a144fc
commit
5739e541d7
|
@ -1,5 +1,13 @@
|
||||||
import re
|
import re
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
try:
|
||||||
|
# Python 2.7
|
||||||
|
xml_parser_exception = etree.ParseError
|
||||||
|
except AttributeError:
|
||||||
|
# Python 2.6
|
||||||
|
from xml.parsers import expat
|
||||||
|
xml_parser_exception = expat.ExpatError
|
||||||
|
|
||||||
from pylons.i18n import _
|
from pylons.i18n import _
|
||||||
|
|
||||||
from ckan import model
|
from ckan import model
|
||||||
|
@ -101,7 +109,7 @@ class ViewController(BaseController):
|
||||||
if not '<?xml' in content.split('\n')[0]:
|
if not '<?xml' in content.split('\n')[0]:
|
||||||
content = u'<?xml version="1.0" encoding="UTF-8"?>\n' + content
|
content = u'<?xml version="1.0" encoding="UTF-8"?>\n' + content
|
||||||
|
|
||||||
except etree.ParseError:
|
except xml_parser_exception:
|
||||||
try:
|
try:
|
||||||
json.loads(obj['content'])
|
json.loads(obj['content'])
|
||||||
response.content_type = 'application/json; charset=utf-8'
|
response.content_type = 'application/json; charset=utf-8'
|
||||||
|
|
Loading…
Reference in New Issue