def sparse_header_chunk(self, index): if index < len(self.sparsemap): return b''.join([ tarfile.itn(self.sparsemap[index][0], 12, tarfile.GNU_FORMAT), tarfile.itn(self.sparsemap[index][1], 12, tarfile.GNU_FORMAT), ]) return b'\0' * 12 * 2
def test_number_field_limits(self): with self.assertRaises(ValueError): tarfile.itn(-1, 8, tarfile.USTAR_FORMAT) with self.assertRaises(ValueError): tarfile.itn(0o10000000, 8, tarfile.USTAR_FORMAT) with self.assertRaises(ValueError): tarfile.itn(-0x10000000001, 6, tarfile.GNU_FORMAT) with self.assertRaises(ValueError): tarfile.itn(0x10000000000, 6, tarfile.GNU_FORMAT)
def get_gnu_header(self): '''Part placed in 'prefix' field of posix header''' parts = [ tarfile.itn(self.mtime, 12, tarfile.GNU_FORMAT), # atime tarfile.itn(self.mtime, 12, tarfile.GNU_FORMAT), # ctime tarfile.itn(0, 12, tarfile.GNU_FORMAT), # offset tarfile.stn('', 4, tarfile.ENCODING, 'surrogateescape'), #longnames b'\0', # unused_pad2 ] parts += [self.sparse_header_chunk(i) for i in range(4)] parts += [ b'\1' if len(self.sparsemap) > 4 else b'\0', # isextended tarfile.itn(self.realsize, 12, tarfile.GNU_FORMAT), # realsize ] return b''.join(parts)
def _create_header(info, format_, encoding, errors): """Return a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. """ parts = [ tarfile.stn(info.get("name", ""), 100, encoding, errors), tarfile.itn(info.get("mode", 0), 8, format_), tarfile.itn(info.get("uid", 0), 8, format_), tarfile.itn(info.get("gid", 0), 8, format_), tarfile.itn(info.get("size", 0), 12, format_), tarfile.itn(info.get("mtime", 0), 12, format_), b" " * 8, # checksum field info.get("type", tarfile.REGTYPE), tarfile.stn(info.get("linkname", ""), 100, encoding, errors), info.get("magic", tarfile.POSIX_MAGIC), tarfile.stn(info.get("uname", ""), 32, encoding, errors), tarfile.stn(info.get("gname", ""), 32, encoding, errors), tarfile.itn(info.get("devmajor", 0), 8, format_), tarfile.itn(info.get("devminor", 0), 8, format_), tarfile.stn(info.get("prefix", ""), 155, encoding, errors) ] buf = struct.pack("%ds" % tarfile.BLOCKSIZE, b"".join(parts)) chksum = tarfile.calc_chksums(buf[-tarfile.BLOCKSIZE:])[0] buf = buf[:-364] + bytes("%06o\0" % chksum, "ascii") + buf[-357:] return buf
def test_write_number_fields(self): self.assertEqual(tarfile.itn(1), b"0000001\x00") self.assertEqual(tarfile.itn(0o7777777), b"7777777\x00") self.assertEqual(tarfile.itn(0o10000000), b"\x80\x00\x00\x00\x00\x20\x00\x00") self.assertEqual(tarfile.itn(0xffffffff), b"\x80\x00\x00\x00\xff\xff\xff\xff") self.assertEqual(tarfile.itn(-1), b"\xff\xff\xff\xff\xff\xff\xff\xff") self.assertEqual(tarfile.itn(-100), b"\xff\xff\xff\xff\xff\xff\xff\x9c") self.assertEqual(tarfile.itn(-0x100000000000000), b"\xff\x00\x00\x00\x00\x00\x00\x00")
def update_event(self, inp=-1): self.set_output_val(0, tarfile.itn(self.input(0), self.input(1), self.input(2)))
def test_number_fields(self): self.assertEqual(tarfile.itn(1), b"0000001\x00") self.assertEqual(tarfile.itn(0xffffffff), b"\x80\x00\x00\x00\xff\xff\xff\xff")
def test_number_fields(self): self.assertEqual(tarfile.itn(1), b"0000001\x00") self.assertEqual(tarfile.itn(0xffffffff), b"\x80\x00\x00\x00\xff\xff\xff\xff")