/usr/lib/python2.7/dist-packages/exifread/utils.py is in python-exif 1.4.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | """
Misc utilities.
"""
def make_string(seq):
"""
Don't throw an exception when given an out of range character.
"""
string = ''
for c in seq:
# Screen out non-printing characters
if 32 <= c and c < 256:
string += chr(c)
# If no printing chars
if not string:
return str(seq)
return string
def make_string_uc(seq):
"""
Special version to deal with the code in the first 8 bytes of a user comment.
First 8 bytes gives coding system e.g. ASCII vs. JIS vs Unicode.
"""
#code = seq[0:8]
seq = seq[8:]
# Of course, this is only correct if ASCII, and the standard explicitly
# allows JIS and Unicode.
return make_string( make_string(seq) )
def s2n_motorola(str):
"""Extract multibyte integer in Motorola format (little endian)."""
x = 0
for c in str:
x = (x << 8) | ord(c)
return x
def s2n_intel(str):
"""Extract multibyte integer in Intel format (big endian)."""
x = 0
y = 0
for c in str:
x = x | (ord(c) << y)
y = y + 8
return x
class Ratio:
"""
Ratio object that eventually will be able to reduce itself to lowest
common denominator for printing.
"""
def __init__(self, num, den):
self.num = num
self.den = den
def __repr__(self):
self.reduce()
if self.den == 1:
return str(self.num)
return '%d/%d' % (self.num, self.den)
def _gcd(self, a, b):
if b == 0:
return a
else:
return self._gcd(b, a % b)
def reduce(self):
div = self._gcd(self.num, self.den)
if div > 1:
self.num = self.num // div
self.den = self.den // div
|