示例#1
0
 def test_extract(self):
     for v in (True, False):
         with TempDir() as tdir:
             tdir = os.path.join(tdir, 'a' * 250)
             os.makedirs(make_long_path_useable(tdir))
             extract(simple_rar, tdir, verify_data=v)
             h = {
                 normalize(
                     os.path.abspath(os.path.join(tdir, h['filename']))): h
                 for h in headers(simple_rar)
             }
             data = {}
             for dirpath, dirnames, filenames in os.walk(tdir):
                 for f in filenames:
                     path = normalize(os.path.join(dirpath, f))
                     data[os.path.relpath(path, tdir).replace(
                         os.sep, '/')] = d = open(path, 'rb').read()
                     if f == 'one.txt':
                         self.ae(os.path.getmtime(path), 1098472879)
                     self.ae(h[path]['unpack_size'], len(d))
                     self.ae(h[path]['file_crc'] & 0xffffffff,
                             crc32(d) & 0xffffffff)
         q = {k: v for k, v in sr_data.items() if v}
         del q['symlink']
         self.ae(data, q)
示例#2
0
 def get_mem_use(num):
     collect()
     start = memory()
     for i in range(num):
         extract(simple_rar, tdir)
     collect()
     return max(0, memory(start))
示例#3
0
 def test_password(self):
     with TempDir() as tdir:
         self.assertRaises(PasswordRequired, extract, password_rar, tdir)
         self.assertRaises(BadPassword,
                           extract,
                           password_rar,
                           tdir,
                           password='******')
         extract(password_rar, tdir, password='******')
示例#4
0
 def test_multipart(self):
     self.ae(list(names(multipart_rar)), ['Fifteen_Feet_of_Time.pdf'])
     for v in (True, False):
         with TempDir() as tdir:
             extract(multipart_rar, tdir, verify_data=v)
             h = next(headers(multipart_rar))
             raw = open(os.path.join(tdir, h['filename']), 'rb').read()
             self.ae(len(raw), h['unpack_size'])
             self.ae(hashlib.sha1(raw).hexdigest(), 'a9fc6a11d000044f17fcdf65816348ce0be3b145')
示例#5
0
 def do_test(stream):
     c = comment(stream)
     if c != b'some comment\n':
         raise ValueError('Comment not read: %r != %r' % (c, b'some comment\n'))
     if set(names(stream)) != {
         '1/sub-one', 'one.txt', '2/sub-two.txt', '诶比屁.txt', 'Füße.txt',
         'uncompressed', 'max-compressed'}:
         raise ValueError('Name list does not match')
     with TemporaryDirectory('test-unrar') as tdir:
         extract(stream, tdir)
         for name in tdata:
             if name not in '1 2 symlink'.split():
                 with open(os.path.join(tdir, name), 'rb') as s:
                     if s.read() != tdata[name]:
                         raise ValueError('Did not extract %s properly' % name)
     for name in tdata:
         if name not in '1 2 symlink'.split():
             d = extract_member(stream, name=name)
             if d is None or d[1] != tdata[name]:
                 raise ValueError(
                     'Failed to extract %s %r != %r' % (name, d, tdata[name]))
示例#6
0
文件: unrar.py 项目: MarioJC/calibre
 def do_test(stream):
     c = comment(stream)
     if c != b'some comment\n':
         raise ValueError('Comment not read: %r != %r' % (c, b'some comment\n'))
     if set(names(stream)) != {
         '1/sub-one', 'one.txt', '2/sub-two.txt', '诶比屁.txt', 'Füße.txt',
         'uncompressed', 'max-compressed'}:
         raise ValueError('Name list does not match')
     with TemporaryDirectory('test-unrar') as tdir:
         extract(stream, tdir)
         for name in tdata:
             if name not in '1 2 symlink'.split():
                 with open(os.path.join(tdir, name), 'rb') as s:
                     if s.read() != tdata[name]:
                         raise ValueError('Did not extract %s properly' % name)
     for name in tdata:
         if name not in '1 2 symlink'.split():
             d = extract_member(stream, name=name)
             if d is None or d[1] != tdata[name]:
                 raise ValueError(
                     'Failed to extract %s %r != %r' % (name, d, tdata[name]))
示例#7
0
def extract(path_or_stream, location):
    from unrardll import extract
    with StreamAsPath(path_or_stream) as path:
        return extract(path, location)
示例#8
0
文件: unrar.py 项目: j-howell/calibre
def extract(path_or_stream, location):
    from unrardll import extract
    with StreamAsPath(path_or_stream) as path:
        return extract(path, location)