Current lxml.etree.parse implementation allows using HTTP, but not HTTPS. When user tries to use HTTPS URL, it crashes on IOException.
This patch fixes that by checking if the URL starts with HTTPS and uses urlopen to open the HTTPS page. This allows lxml.etree.parse method to parse the XML from the HTTPS URL.
urllib2 is already used Common/Path and is available since Python2.6 so no new dependency is added.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Controller/XmlParser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/XmlParser.py b/lnst/Controller/XmlParser.py index afc2cda..355b5e8 100644 --- a/lnst/Controller/XmlParser.py +++ b/lnst/Controller/XmlParser.py @@ -15,6 +15,7 @@ import re import sys import copy from lxml import etree +from urllib2 import urlopen from lnst.Common.Config import lnst_config from lnst.Controller.XmlTemplates import XmlTemplates from lnst.Controller.XmlProcessing import XmlProcessingError @@ -79,7 +80,10 @@ class XmlParser(object):
def _parse(self, path): try: - doc = etree.parse(path) + if path.startswith('https'): + doc = etree.parse(urlopen(path)) + else: + doc = etree.parse(path) except etree.LxmlError as err: # A workaround for cases when lxml (quite strangely) # sets the filename to <string>.
Fri, Mar 11, 2016 at 11:24:22AM CET, jprochaz@redhat.com wrote:
Current lxml.etree.parse implementation allows using HTTP, but not HTTPS. When user tries to use HTTPS URL, it crashes on IOException.
This patch fixes that by checking if the URL starts with HTTPS and uses urlopen to open the HTTPS page. This allows lxml.etree.parse method to parse the XML from the HTTPS URL.
urllib2 is already used Common/Path and is available since Python2.6 so no new dependency is added.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
lnst/Controller/XmlParser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/XmlParser.py b/lnst/Controller/XmlParser.py index afc2cda..355b5e8 100644 --- a/lnst/Controller/XmlParser.py +++ b/lnst/Controller/XmlParser.py @@ -15,6 +15,7 @@ import re import sys import copy from lxml import etree +from urllib2 import urlopen from lnst.Common.Config import lnst_config from lnst.Controller.XmlTemplates import XmlTemplates from lnst.Controller.XmlProcessing import XmlProcessingError @@ -79,7 +80,10 @@ class XmlParser(object):
def _parse(self, path): try:
doc = etree.parse(path)
if path.startswith('https'):
doc = etree.parse(urlopen(path))
else:
doc = etree.parse(path) except etree.LxmlError as err: # A workaround for cases when lxml (quite strangely) # sets the filename to <string>.
-- 2.4.3 _______________________________________________ LNST-developers mailing list lnst-developers@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahoste...
Acked-by: Jan Tluka jtluka@redhat.com
On Fri, Mar 11, 2016 at 11:24:22AM +0100, Jiri Prochazka wrote:
Current lxml.etree.parse implementation allows using HTTP, but not HTTPS. When user tries to use HTTPS URL, it crashes on IOException.
This patch fixes that by checking if the URL starts with HTTPS and uses urlopen to open the HTTPS page. This allows lxml.etree.parse method to parse the XML from the HTTPS URL.
urllib2 is already used Common/Path and is available since Python2.6 so no new dependency is added.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
Acked-by: Ondrej Lichtner olichtne@redhat.com
Fri, Mar 11, 2016 at 11:24:22AM CET, jprochaz@redhat.com wrote:
Current lxml.etree.parse implementation allows using HTTP, but not HTTPS. When user tries to use HTTPS URL, it crashes on IOException.
This patch fixes that by checking if the URL starts with HTTPS and uses urlopen to open the HTTPS page. This allows lxml.etree.parse method to parse the XML from the HTTPS URL.
urllib2 is already used Common/Path and is available since Python2.6 so no new dependency is added.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
Applied. Thanks!
-Jan
lnst-developers@lists.fedorahosted.org