Skip to content

Commit f348b33

Browse files
committed
Python3 porting driven by extension of test coverage
2 parents 5bf5a82 + 31c56a7 commit f348b33

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
pip install -r requirements-dev.txt
2222
# FIXME: branding.py still has no permanent home
2323
curl https://gist.github.com/ydirson/3c36a7e19d762cc529a6c82340894ccc/raw/5ca39f621b1feab813e171f535c1aad1bd483f1d/branding.py -O -L
24-
pip install pyliblzma
24+
pip install pyliblzma configparser
2525
pip install -e .
2626
command -v xz
2727

tests/test_xmlunwrap.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ def test(self):
1818

1919
self.assertEqual([getText(el)
2020
for el in getElementsByTagName(self.top_el, ["fred"])],
21-
["text1", "text2"])
21+
[b"text1", b"text2"])
2222

23-
x = getMapAttribute(self.top_el, ["mode"], [('test', 42), ('stuff', 77)])
23+
x = getMapAttribute(self.top_el, ["mode"], [(b'test', 42), (b'stuff', 77)])
2424
self.assertEqual(x, 42)
25-
x = getMapAttribute(self.top_el, ["made"], [('test', 42), ('stuff', 77)],
26-
default='stuff')
25+
x = getMapAttribute(self.top_el, ["made"], [(b'test', 42), (b'stuff', 77)],
26+
default=b'stuff')
2727
self.assertEqual(x, 77)
2828

2929
x = getStrAttribute(self.top_el, ["mode"])
30-
self.assertEqual(x, "test")
30+
self.assertEqual(x, b"test")
3131
x = getStrAttribute(self.top_el, ["made"])
32-
self.assertEqual(x, "")
32+
self.assertEqual(x, b"")
3333
x = getStrAttribute(self.top_el, ["made"], None)
3434
self.assertEqual(x, None)
3535

xcp/cpiofile.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,15 +1418,17 @@ def extractall(self, path=".", members=None):
14181418
# Extract directory with a safe mode, so that
14191419
# all files below can be extracted as well.
14201420
try:
1421-
os.makedirs(os.path.join(path, cpioinfo.name), 0o777)
1421+
os.makedirs(
1422+
os.path.join(path, six.ensure_text(cpioinfo.name)),
1423+
0o777)
14221424
except EnvironmentError:
14231425
pass
14241426
directories.append(cpioinfo)
14251427
else:
14261428
self.extract(cpioinfo, path)
14271429

14281430
# Reverse sort directories.
1429-
directories.sort(lambda a, b: cmp(a.name, b.name))
1431+
directories.sort(key=lambda x: x.name)
14301432
directories.reverse()
14311433

14321434
# Set correct owner, mtime and filemode on directories.
@@ -1461,7 +1463,8 @@ def extract(self, member, path=""):
14611463
cpioinfo._link_path = path
14621464

14631465
try:
1464-
self._extract_member(cpioinfo, os.path.join(path, cpioinfo.name))
1466+
self._extract_member(
1467+
cpioinfo, os.path.join(path, six.ensure_text(cpioinfo.name)))
14651468
except EnvironmentError as e:
14661469
if self.errorlevel > 0:
14671470
raise

xcp/repository.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2424
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

26-
import md5
26+
from hashlib import md5
2727
import os.path
2828
import xml.dom.minidom
29-
import ConfigParser
29+
import configparser
3030

3131
import six
3232

@@ -181,8 +181,8 @@ def _getVersion(cls, access, category):
181181
access.start()
182182
try:
183183
treeinfofp = access.openAddress(cls.TREEINFO_FILENAME)
184-
treeinfo = ConfigParser.SafeConfigParser()
185-
treeinfo.readfp(treeinfofp)
184+
treeinfo = configparser.ConfigParser()
185+
treeinfo.read_file(treeinfofp)
186186
treeinfofp.close()
187187
if treeinfo.has_section('system-v1'):
188188
ver_str = treeinfo.get('system-v1', category_map[category])
@@ -247,7 +247,7 @@ def findRepositories(cls, access):
247247
def __init__(self, access, base, is_group = False):
248248
BaseRepository.__init__(self, access, base)
249249
self.is_group = is_group
250-
self._md5 = md5.new()
250+
self._md5 = md5()
251251
self.requires = []
252252
self.packages = []
253253

@@ -289,7 +289,7 @@ def _parse_repofile(self, repofile):
289289
repofile.close()
290290

291291
# update md5sum for repo
292-
self._md5.update(repofile_contents)
292+
self._md5.update(repofile_contents.encode())
293293

294294
# build xml doc object
295295
try:

xcp/xmlunwrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def getElementsByTagName(el, tags, mandatory = False):
4444
raise XmlUnwrapError("Missing mandatory element %s" % tags[0])
4545
return matching
4646

47-
def getStrAttribute(el, attrs, default = '', mandatory = False):
47+
def getStrAttribute(el, attrs, default=b'', mandatory=False):
4848
matching = []
4949
for attr in attrs:
5050
val = el.getAttribute(attr).encode()
51-
if val != '':
51+
if val != b'':
5252
matching.append(val)
5353
if len(matching) == 0:
5454
if mandatory:

0 commit comments

Comments
 (0)