| 1 |
Fromscip-debian debian piexif 1.1.3-2 piexif/patches/`194add490168100e2a68d8669adeb065a2acf256.patch`#From.: "jim.meyer" <no-replyscip-debian . . . identity/no-reply.> |
| 2 |
Datescip-debian debian piexif 1.1.3-2 piexif/patches/`194add490168100e2a68d8669adeb065a2acf256.patch`#Date.: Sun, 14 Jun 2020 19:02:11 -0500 |
| 3 |
Subjectscip-debian debian piexif 1.1.3-2 piexif/patches/`194add490168100e2a68d8669adeb065a2acf256.patch`#Subject.: Fixed unassigned variable error. Also don't both re-writing image file if it hasn't changed. |
| 4 |
|
| 5 |
--- |
| 6 |
piexif/_remove.py | 56 +++++++++++++++++++---------------- |
| 7 |
tests/images/not_an_image.txt | 1 + |
| 8 |
tests/s_test.py | 8 +++++ |
| 9 |
3 files changed, 39 insertions(+), 26 deletions(-) |
| 10 |
create mode 100644 tests/images/not_an_image.txt |
| 11 |
|
| 12 |
--- a/piexif/_remove.pyscip-debian debian piexif 1.1.3-2 piexif/upstream/`piexif/_remove.py`: |
| 13 |
+++ b/piexif/_remove.pyscip-debian debian piexif 1.1.3-2 piexif/upstream/`piexif/_remove.py`: |
| 14 |
@@ -26,31 +26,35 @@ def remove(src, new_file=None): |
| 15 |
file_type = "jpeg" |
| 16 |
elif src_data[0:4] == b"RIFF" and src_data[8:12] == b"WEBP": |
| 17 |
file_type = "webp" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
else: |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
+ file_type = None |
| 35 |
+ |
| 36 |
+ if file_type is not None: |
| 37 |
+ if file_type == "jpeg": |
| 38 |
+ segments = split_into_segments(src_data) |
| 39 |
+ exif = get_exif_seg(segments) |
| 40 |
+ if exif: |
| 41 |
+ new_data = src_data.replace(exif, b"") |
| 42 |
+ else: |
| 43 |
+ new_data = src_data |
| 44 |
+ elif file_type == "webp": |
| 45 |
+ try: |
| 46 |
+ new_data = _webp.remove(src_data) |
| 47 |
+ except ValueError: |
| 48 |
+ new_data = src_data |
| 49 |
+ except e: |
| 50 |
+ print(e.args) |
| 51 |
+ raise ValueError("Error occurred.") |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
+ if isinstance(new_file, io.BytesIO): |
| 66 |
+ new_file.write(new_data) |
| 67 |
+ new_file.seek(0) |
| 68 |
+ elif new_file: |
| 69 |
+ with open(new_file, "wb+") as f: |
| 70 |
+ f.write(new_data) |
| 71 |
+ elif output_is_file: |
| 72 |
+ if new_data is not src_data: |
| 73 |
+ with open(src, "wb+") as f: |
| 74 |
+ f.write(new_data) |
| 75 |
+ else: |
| 76 |
+ raise ValueError("Give a second argument to 'remove' to output file") |
| 77 |
|
| 78 |
--- /dev/nullscip-debian debian piexif 1.1.3-2 piexif/upstream/`/dev/null`: |
| 79 |
+++ b/tests/images/not_an_image.txtscip-debian debian piexif 1.1.3-2 piexif/upstream/`tests/images/not_an_image.txt`: |
| 80 |
@@ -0,0 +1 @@ |
| 81 |
+This tests _remove() handling of files that are not jpgs or webp |
| 82 |
--- a/tests/s_test.pyscip-debian debian piexif 1.1.3-2 piexif/upstream/`tests/s_test.py`: |
| 83 |
+++ b/tests/s_test.pyscip-debian debian piexif 1.1.3-2 piexif/upstream/`tests/s_test.py`: |
| 84 |
@@ -1010,6 +1010,14 @@ class WebpTests(unittest.TestCase): |
| 85 |
piexif.remove(IMAGE_DIR + filename, OUT_DIR + "rr_" + filename) |
| 86 |
Image.open(OUT_DIR + "rr_" + filename) |
| 87 |
|
| 88 |
+ def test_remove_unknown_image_type(self): |
| 89 |
+ """Does remove ignore unknown image types?""" |
| 90 |
+ IMAGE_DIR = "tests/images/" |
| 91 |
+ OUT_DIR = "tests/images/out/" |
| 92 |
+ filename = "not_an_image.txt" |
| 93 |
+ piexif.remove(IMAGE_DIR + filename, OUT_DIR + "rr_" + filename) |
| 94 |
+ self.assertFalse(os.path.isfile(OUT_DIR + "rr_" + filename)) |
| 95 |
+ |
| 96 |
def test_insert(self): |
| 97 |
"""Can PIL open WebP that is inserted exif?""" |
| 98 |
IMAGE_DIR = "tests/images/" |