parameters: (filename)
return_statement: return exif
docstring: Slices JPEG meta data into a list from JPEG binary data.
docstring_summary: Slices JPEG meta data into a list from JPEG binary data.
docstring_tokens: Slices JPEG meta data into a list from JPEG binary data .
function: def read_exif_from_file(filename):
      """Slices JPEG meta data into a list from JPEG binary data.
      """
      f = open(filename, "rb")
      data = f.read(6)
  
      if data[0:2] != b"\xff\xd8":
          raise InvalidImageDataError("Given data isn't JPEG.")
  
      head = data[2:6]
      HEAD_LENGTH = 4
      exif = None
      while len(head) == HEAD_LENGTH:
          length = struct.unpack(">H", head[2: 4])[0]
  
          if head[:2] == b"\xff\xe1":
              segment_data = f.read(length - 2)
              if segment_data[:4] != b'Exif':
                  head = f.read(HEAD_LENGTH)
                  continue
              exif = head + segment_data
              break
          elif head[0:1] == b"\xff":
              f.read(length - 2)
              head = f.read(HEAD_LENGTH)
          else:
              break
  
      f.close()
      return exif
function_tokens: def read_exif_from_file ( filename ) : f = open ( filename , "rb" ) data = f . read ( 6 ) if data [ 0 : 2 ] != b"\xff\xd8" : raise InvalidImageDataError ( "Given data isn't JPEG." ) head = data [ 2 : 6 ] HEAD_LENGTH = 4 exif = None while len ( head ) == HEAD_LENGTH : length = struct . unpack ( ">H" , head [ 2 : 4 ] ) [ 0 ] if head [ : 2 ] == b"\xff\xe1" : segment_data = f . read ( length - 2 ) if segment_data [ : 4 ] != b'Exif' : head = f . read ( HEAD_LENGTH ) continue exif = head + segment_data break elif head [ 0 : 1 ] == b"\xff" : f . read ( length - 2 ) head = f . read ( HEAD_LENGTH ) else : break f . close ( ) return exif