Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:chajain
python-xmlschema
0004-Make-compatible-with-python2.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0004-Make-compatible-with-python2.patch of Package python-xmlschema
From ac119efc33f9e06a7b4550b9a5cb2707db7dd8f3 Mon Sep 17 00:00:00 2001 From: Jan Zerebecki <jan.suse@zerebecki.de> Date: Tue, 16 Feb 2021 18:42:01 +0100 Subject: [PATCH 4/4] Make compatible with python2 The previous backported patches were only for python3. Replace 'with' keyword with its python2 version. Make an assertion text compatible with python2. Replace subprocess.run with Popen for python2. This was introduced in 6994da5173a60e770163cd5fc65f73b24066c0a5 in 1.0.14. --- xmlschema/resources.py | 15 +++++++++------ xmlschema/tests/test_etree.py | 10 ++++++---- xmlschema/tests/test_resources.py | 6 ++++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/xmlschema/resources.py b/xmlschema/resources.py index 2a2c55e..7ffa91a 100644 --- a/xmlschema/resources.py +++ b/xmlschema/resources.py @@ -431,12 +431,15 @@ class XMLResource(object): self._access_control(url) _url, self._url = self._url, url try: - with urlopen(url, timeout=self.timeout) as resource: - if self._lazy: - for _, root in self.iterparse(resource, events=('start',)): - return root, None, url - else: - return self.parse(resource).getroot(), None, url + resource = urlopen(url, timeout=self.timeout) + if self._lazy: + for _, root in self.iterparse(resource, events=('start',)): + resource.close() + return root, None, url + else: + result = self.parse(resource).getroot() + resource.close() + return result, None, url finally: self._url = _url diff --git a/xmlschema/tests/test_etree.py b/xmlschema/tests/test_etree.py index 22e42a9..a35743e 100644 --- a/xmlschema/tests/test_etree.py +++ b/xmlschema/tests/test_etree.py @@ -57,13 +57,15 @@ class TestElementTree(unittest.TestCase): test_dir = os.path.dirname(__file__) or '.' cmd = [os.path.join(test_dir, 'check_etree_import.py')] - process = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - output = process.stdout.decode('utf-8') + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, _ = process.communicate() + output = stdout.decode('utf-8') self.assertTrue("\nTest OK:" in output, msg="Wrong import of ElementTree after xmlschema") cmd.append('--before') - process = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - output = process.stdout.decode('utf-8') + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, _ = process.communicate() + output = stdout.decode('utf-8') self.assertTrue("\nTest OK:" in output, msg="Wrong import of ElementTree before xmlschema") def test_safe_xml_parser(self): diff --git a/xmlschema/tests/test_resources.py b/xmlschema/tests/test_resources.py index 51c0c20..1febe1f 100644 --- a/xmlschema/tests/test_resources.py +++ b/xmlschema/tests/test_resources.py @@ -418,8 +418,10 @@ class TestResources(unittest.TestCase): with self.assertRaises(TypeError) as ctx: XMLResource("https://xmlschema.test/vehicles.xsd", allow=None) - self.assertEqual(str(ctx.exception), - "invalid type <class 'NoneType'> for the attribute 'allow'") + self.assertTrue(str(ctx.exception) == + "invalid type <class 'NoneType'> for the attribute 'allow'" + or str(ctx.exception) == + "invalid type <type 'NoneType'> for the attribute 'allow'") with self.assertRaises(ValueError) as ctx: XMLResource("https://xmlschema.test/vehicles.xsd", allow='any') -- 2.29.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor