|
28 | 28 | from __future__ import division |
29 | 29 | from __future__ import unicode_literals |
30 | 30 |
|
31 | | -from unittest import TestCase as TestCaseClass |
32 | | - |
33 | 31 | import filecmp |
| 32 | +from functools import partial |
34 | 33 | import os |
35 | 34 | import shutil |
36 | 35 | import stat |
37 | 36 | import sys |
38 | 37 | import tarfile |
| 38 | +from unittest import TestCase as TestCaseClass |
39 | 39 | import zipfile |
40 | 40 |
|
41 | 41 | from commoncode import fileutils |
@@ -278,19 +278,27 @@ def extract_test_tar(self, test_path, verbatim=False): |
278 | 278 | def extract_test_tar_raw(self, test_path, *args, **kwargs): |
279 | 279 | return self.__extract(test_path, extract_tar_raw) |
280 | 280 |
|
| 281 | + def extract_test_tar_unicode(self, test_path, *args, **kwargs): |
| 282 | + return self.__extract(test_path, extract_tar_uni) |
281 | 283 |
|
282 | | -def extract_tar_raw(test_path, target_dir, *args, **kwargs): |
| 284 | + |
| 285 | +def _extract_tar_raw(test_path, target_dir, to_bytes, *args, **kwargs): |
283 | 286 | """ |
284 | 287 | Raw simplified extract for certain really weird paths and file |
285 | 288 | names. |
286 | 289 | """ |
287 | | - # use bytes for paths on ALL OSes (though this may fail on macOS) |
288 | | - target_dir = path_to_bytes(target_dir) |
289 | | - test_path = path_to_bytes(test_path) |
| 290 | + if to_bytes: |
| 291 | + # use bytes for paths on ALL OSes (though this may fail on macOS) |
| 292 | + target_dir = path_to_bytes(target_dir) |
| 293 | + test_path = path_to_bytes(test_path) |
290 | 294 | tar = tarfile.open(test_path) |
291 | 295 | tar.extractall(path=target_dir) |
292 | 296 | tar.close() |
293 | 297 |
|
| 298 | +extract_tar_raw = partial(_extract_tar_raw, to_bytes=True) |
| 299 | + |
| 300 | +extract_tar_uni = partial(_extract_tar_raw, to_bytes=False) |
| 301 | + |
294 | 302 |
|
295 | 303 | def extract_tar(location, target_dir, verbatim=False, *args, **kwargs): |
296 | 304 | """ |
|
0 commit comments