"""Wrapper around the exif library to extract and convert some information.
"""

from gi.repository import GExiv2


class Exif(object):

    OrientationXlate = {
        1: 'Horizontal (normal)',
        2: 'Mirror horizontal',
        3: 'Rotate 180',
        4: 'Mirror vertical',
        5: 'Mirror horizontal and rotate 270 CW',
        6: 'Rotate 90 CW',
        7: 'Mirror horizontal and rotate 90 CW',
        8: 'Rotate 270 CW',
    }

    def __init__(self, filename):
        self._exif = GExiv2.Metadata(filename)
        try:
            self.createdate = self._exif.get_date_time()
        except KeyError:
            self.createdate = None
        try:
            orientation = self._exif.get_orientation()
            self.orientation = self.OrientationXlate[int(orientation)]
        except KeyError:
            self.orientation = None
        if ('Exif.GPSInfo.GPSLatitude' in self._exif and
            'Exif.GPSInfo.GPSLongitude' in self._exif):
            lat = self._exif.get_gps_latitude()
            lon = self._exif.get_gps_longitude()
            latref = 'N' if lat >= 0.0 else 'S'
            lonref = 'E' if lon >= 0.0 else 'W'
            self.gpsPosition = { latref:abs(lat), lonref:abs(lon) }
        else:
            self.gpsPosition = None


@@ -530,40 +530,208 @@
     
-try:%0A            self.createdate
+self.createdate = self._get_date_time()%0A        self.orientation = self._get_orientation()%0A        self.gpsPosition = self._get_gpsPosition()%0A%0A    def _get_date_time(self):%0A        try:%0A            dt
  = s
@@ -797,30 +797,70 @@
     
-self.createdate = None
+return None%0A        return dt%0A%0A    def _get_orientation(self):
 %0A   
@@ -936,34 +936,22 @@
         
-self.orientation =
+return
  self.Or
@@ -1024,31 +1024,52 @@
     
-self.orientation = None
+return None%0A%0A    def _get_gpsPosition(self):
 %0A   
@@ -1383,34 +1383,22 @@
         
-self.gpsPosition =
+return
  %7B latre
@@ -1453,33 +1453,21 @@
         
-self.gpsPosition =
+return
  None%0A%0A

Move extraction of exif attributes in individual helper functions.