Skip to content

Commit ea29bac

Browse files
committed
Replace Ratio with Fraction
1 parent cb24f68 commit ea29bac

File tree

3 files changed

+7
-37
lines changed

3 files changed

+7
-37
lines changed

exifread/classes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import re
22
import struct
3+
from fractions import Fraction
34
from typing import BinaryIO, Dict, Any
45

56
from exifread.exif_log import get_logger
6-
from exifread.utils import Ratio
77
from exifread.tags import EXIF_TAGS, DEFAULT_STOP_TAG, FIELD_TYPES, IGNORE_TAGS, makernote
88

99
logger = get_logger()
@@ -152,7 +152,7 @@ def _process_field(self, tag_name, count, field_type, type_length, offset):
152152
for _ in range(count):
153153
if field_type in (5, 10):
154154
# a ratio
155-
value = Ratio(
155+
value = Fraction(
156156
self.s2n(offset, 4, signed),
157157
self.s2n(offset + 4, 4, signed)
158158
)
@@ -496,14 +496,14 @@ def decode_maker_note(self) -> None:
496496
self.dump_ifd(0, 'MakerNote', tag_dict=makernote.apple.TAGS)
497497
self.offset = offset
498498
return
499-
499+
500500
if make == 'DJI':
501501
offset = self.offset
502502
self.offset += note.field_offset
503503
self.dump_ifd(0, 'MakerNote', tag_dict=makernote.dji.TAGS)
504504
self.offset = offset
505505
return
506-
506+
507507
# Canon
508508
if make == 'Canon':
509509
self.dump_ifd(note.field_offset, 'MakerNote',

exifread/tags/makernote/nikon.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from fractions import Fraction
12

2-
from exifread.utils import make_string, Ratio
3+
from exifread.utils import make_string
34

45

56
def ev_bias(seq) -> str:
@@ -46,7 +47,7 @@ def ev_bias(seq) -> str:
4647
if i == 0:
4748
ret_str += 'EV'
4849
else:
49-
ratio = Ratio(i, step)
50+
ratio = Fraction(i, step)
5051
ret_str = ret_str + str(ratio) + ' EV'
5152
return ret_str
5253

exifread/utils.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,34 +79,3 @@ def get_gps_coords(tags: dict) -> tuple:
7979
lat_coord *= (-1) ** (lat_ref_val == 'S')
8080

8181
return (lat_coord, lng_coord)
82-
83-
84-
class Ratio(Fraction):
85-
"""
86-
Ratio object that eventually will be able to reduce itself to lowest
87-
common denominator for printing.
88-
"""
89-
90-
# We're immutable, so use __new__ not __init__
91-
def __new__(cls, numerator=0, denominator=None):
92-
try:
93-
self = super(Ratio, cls).__new__(cls, numerator, denominator)
94-
except ZeroDivisionError:
95-
self = super(Ratio, cls).__new__(cls)
96-
self._numerator = numerator
97-
self._denominator = denominator
98-
return self
99-
100-
def __repr__(self) -> str:
101-
return str(self)
102-
103-
@property
104-
def num(self):
105-
return self.numerator
106-
107-
@property
108-
def den(self):
109-
return self.denominator
110-
111-
def decimal(self) -> float:
112-
return float(self)

0 commit comments

Comments
 (0)