Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
hMatoba committed Feb 15, 2015
1 parent 60e6329 commit 981ef90
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions piexif/_load_and_dump.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import copy
import io
import numbers
import struct
import sys

from ._common import *
from ._exif import *


if sys.version_info[0] == 2:
NUMBER_TYPE = (int, long)
else:
NUMBER_TYPE = int


TYPES = {"Byte": 1,
"Ascii": 2,
"Short": 3,
Expand Down Expand Up @@ -444,7 +438,7 @@ def value_to_bytes(raw_value, value_type, offset):
else:
value_str = new_value + b"\x00" * (4 - length)
elif value_type == "Rational":
if isinstance(raw_value[0], NUMBER_TYPE):
if isinstance(raw_value[0], numbers.Integral):
length = 1
num, den = raw_value
new_value = struct.pack(">L", num) + struct.pack(">L", den)
Expand All @@ -458,7 +452,7 @@ def value_to_bytes(raw_value, value_type, offset):
value_str = struct.pack(">I", offset)
four_bytes_over = new_value
elif value_type == "SRational":
if isinstance(raw_value[0], NUMBER_TYPE):
if isinstance(raw_value[0], numbers.Integral):
length = 1
num, den = raw_value
new_value = struct.pack(">l", num) + struct.pack(">l", den)
Expand Down Expand Up @@ -506,7 +500,7 @@ def dict_to_bytes(ifd_dict, ifd, ifd_offset):
type_str = struct.pack(">H", TYPES[value_type])
four_bytes_over = b""

if isinstance(raw_value, NUMBER_TYPE):
if isinstance(raw_value, numbers.Integral):
raw_value = (raw_value,)
offset = TIFF_HEADER_LENGTH + entries_length + ifd_offset + len(values)

Expand Down

0 comments on commit 981ef90

Please sign in to comment.