Conform to strict str/bytes distinction.
This commit is contained in:
parent
6665cefb85
commit
a280ca7594
|
@ -214,7 +214,7 @@ def itn(n, digits=8, format=DEFAULT_FORMAT):
|
||||||
# encoding, the following digits-1 bytes are a big-endian
|
# encoding, the following digits-1 bytes are a big-endian
|
||||||
# representation. This allows values up to (256**(digits-1))-1.
|
# representation. This allows values up to (256**(digits-1))-1.
|
||||||
if 0 <= n < 8 ** (digits - 1):
|
if 0 <= n < 8 ** (digits - 1):
|
||||||
s = bytes("%0*o" % (digits - 1, n)) + NUL
|
s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL
|
||||||
else:
|
else:
|
||||||
if format != GNU_FORMAT or n >= 256 ** (digits - 1):
|
if format != GNU_FORMAT or n >= 256 ** (digits - 1):
|
||||||
raise ValueError("overflow in number field")
|
raise ValueError("overflow in number field")
|
||||||
|
@ -604,7 +604,7 @@ class _StreamProxy(object):
|
||||||
def getcomptype(self):
|
def getcomptype(self):
|
||||||
if self.buf.startswith(b"\037\213\010"):
|
if self.buf.startswith(b"\037\213\010"):
|
||||||
return "gz"
|
return "gz"
|
||||||
if self.buf.startswith("BZh91"):
|
if self.buf.startswith(b"BZh91"):
|
||||||
return "bz2"
|
return "bz2"
|
||||||
return "tar"
|
return "tar"
|
||||||
|
|
||||||
|
@ -1108,7 +1108,7 @@ class TarInfo(object):
|
||||||
|
|
||||||
buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
|
buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
|
||||||
chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
|
chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
|
||||||
buf = buf[:-364] + bytes("%06o\0" % chksum) + buf[-357:]
|
buf = buf[:-364] + bytes("%06o\0" % chksum, "ascii") + buf[-357:]
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1155,7 +1155,7 @@ class TarInfo(object):
|
||||||
if n == p:
|
if n == p:
|
||||||
break
|
break
|
||||||
p = n
|
p = n
|
||||||
records += bytes(str(p)) + b" " + keyword + b"=" + value + b"\n"
|
records += bytes(str(p), "ascii") + b" " + keyword + b"=" + value + b"\n"
|
||||||
|
|
||||||
# We use a hardcoded "././@PaxHeader" name like star does
|
# We use a hardcoded "././@PaxHeader" name like star does
|
||||||
# instead of the one that POSIX recommends.
|
# instead of the one that POSIX recommends.
|
||||||
|
|
|
@ -481,7 +481,7 @@ class WriteTest(unittest.TestCase):
|
||||||
tar = tarfile.open(tmpname, self.mode)
|
tar = tarfile.open(tmpname, self.mode)
|
||||||
path = os.path.join(TEMPDIR, "file")
|
path = os.path.join(TEMPDIR, "file")
|
||||||
fobj = open(path, "wb")
|
fobj = open(path, "wb")
|
||||||
fobj.write("aaa")
|
fobj.write(b"aaa")
|
||||||
fobj.close()
|
fobj.close()
|
||||||
tar.add(path)
|
tar.add(path)
|
||||||
tar.close()
|
tar.close()
|
||||||
|
@ -499,7 +499,7 @@ class WriteTest(unittest.TestCase):
|
||||||
self.assertEqual(tarinfo.size, 0)
|
self.assertEqual(tarinfo.size, 0)
|
||||||
|
|
||||||
fobj = open(path, "wb")
|
fobj = open(path, "wb")
|
||||||
fobj.write("aaa")
|
fobj.write(b"aaa")
|
||||||
fobj.close()
|
fobj.close()
|
||||||
tarinfo = tar.gettarinfo(path)
|
tarinfo = tar.gettarinfo(path)
|
||||||
self.assertEqual(tarinfo.size, 3)
|
self.assertEqual(tarinfo.size, 3)
|
||||||
|
@ -603,7 +603,7 @@ class StreamWriteTest(unittest.TestCase):
|
||||||
data = fobj.read()
|
data = fobj.read()
|
||||||
fobj.close()
|
fobj.close()
|
||||||
|
|
||||||
self.assert_(data.count("\0") == tarfile.RECORDSIZE,
|
self.assert_(data.count(b"\0") == tarfile.RECORDSIZE,
|
||||||
"incorrect zero padding")
|
"incorrect zero padding")
|
||||||
|
|
||||||
|
|
||||||
|
@ -693,7 +693,7 @@ class HardlinkTest(unittest.TestCase):
|
||||||
self.bar = os.path.join(TEMPDIR, "bar")
|
self.bar = os.path.join(TEMPDIR, "bar")
|
||||||
|
|
||||||
fobj = open(self.foo, "wb")
|
fobj = open(self.foo, "wb")
|
||||||
fobj.write("foo")
|
fobj.write(b"foo")
|
||||||
fobj.close()
|
fobj.close()
|
||||||
|
|
||||||
os.link(self.foo, self.bar)
|
os.link(self.foo, self.bar)
|
||||||
|
|
Loading…
Reference in New Issue