# Path: image_filer/utils/pexif.py
# MAX_HEADER_SIZE = 64 * 1024
# DELIM = 0xff
# EOI = 0xd9
# SOI_MARKER = chr(DELIM) + '\xd8'
# EOI_MARKER = chr(DELIM) + '\xd9'
# EXIF_OFFSET = 0x8769
# GPSIFD = 0x8825
# TIFF_OFFSET = 6
# TIFF_TAG = 0x2a
# DEBUG = 0
# BYTE = ExifType(1, "byte", 1).id
# ASCII = ExifType(2, "ascii", 1).id
# SHORT = ExifType(3, "short", 2).id
# LONG = ExifType(4, "long", 4).id
# RATIONAL = ExifType(5, "rational", 8).id
# UNDEFINED = ExifType(7, "undefined", 1).id
# SLONG = ExifType(9, "slong", 4).id
# SRATIONAL = ExifType(10, "srational", 8).id
# APP1 = 0xe1
#     SEC_DEN = 50000000
# def debug(*debug_string):
#     def __init__(self, marker, fd, data, mode):
#     def write(self, fd):
#     def get_data(self):
#     def parse_data(self, data):
#     def dump(self, fd):
#     def __init__(self, marker, fd, data, mode):
#     def write(self, fd):
#     def dump(self, fd):
#     def __init__(self, type_id, name, size):
# def exif_type_size(exif_type):
#     def __init__(self, num, den):
#     def __repr__(self):
#     def as_tuple(self):
#     def special_handler(self, tag, data):
#     def ifd_handler(self, data):
#     def extra_ifd_data(self, offset):
#     def has_key(self, key):
#     def __setattr__(self, name, value):
#     def __delattr__(self, name):
#     def __getattr__(self, name):
#     def __getitem__(self, key):
#     def __delitem__(self, key):
#     def __setitem__(self, key, value):
#     def __init__(self, e, offset, exif_file, mode, data = None):
#     def isifd(self, other):
#     def getdata(self, e, offset, last = 0):
#     def dump(self, f, indent = ""):
#     def getdata(self, e, offset, last = 0):
# def ifd_maker_note(e, offset, exif_file, mode, data):
#     def __init__(self, e, offset, exif_file, mode, data = None):
#     def special_handler(self, tag, data):
#     def new_gps(self):
#     def ifd_handler(self, data):
#     def extra_ifd_data(self, offset):
#     def __init__(self, marker, fd, data, mode):
#     def parse_data(self, data):
#     def dump(self, fd):
#     def get_data(self):
#     def get_primary(self, create=False):
#     def _get_property(self):
#     def fromFile(filename, mode="rw"):
#     def fromString(str, mode="rw"):
#     def fromFd(fd, mode="rw"):
#     def __init__(self, input, filename=None, mode="rw"):
#     def writeString(self):
#     def writeFile(self, filename):
#     def writeFd(self, output):
#     def dump(self, f = sys.stdout):
#     def get_exif(self, create=False):
#     def add_exif(self):
#     def _get_exif(self):
#     def get_geo(self):
#         def convert(x):
#     def _parse(val):
#     def set_geo(self, lat, lng):
# class DefaultSegment:
#     class InvalidSegment(Exception):
# class StartOfScanSegment(DefaultSegment):
# class ExifType:
# class Rational:
# class IfdData:
# class IfdInterop(IfdData):
# class CanonIFD(IfdData):
# class FujiIFD(IfdData):
# class IfdGPS(IfdData):
# class IfdExtendedEXIF(IfdData):
# class IfdTIFF(IfdData):
# class IfdThumbnail(IfdTIFF):
# class ExifSegment(DefaultSegment):
# class JpegFile:
#     class InvalidFile(Exception):
#     class NoSection(Exception):


    import Image
    import ExifTags
import StringIO
        from PIL import Image
        from PIL import ExifTags
from image_filer.utils import pexif
try:
except ImportError:
    try:
    except ImportError:
        raise ImportError("The Python Imaging Library was not found.")

def get_exif(im):
    try:
        exif_raw = im._getexif() or {}
    except:
        return {}
    ret={}
    for tag, value in exif_raw.items():
        decoded = ExifTags.TAGS.get(tag, tag)
        ret[decoded] = value
    return ret
def get_exif_for_file(file):
    im = Image.open(file,'r')
    return get_exif(im)
def get_subject_location(exif_data):
    try:
        r = ( int(exif_data['SubjectLocation'][0]), int(exif_data['SubjectLocation'][1]), )
    except:
        r = None
    return r

def set_exif_subject_location(xy, fd_source, out_path):
    try:
        img = pexif.JpegFile.fromFd(fd_source)

# Path: image_filer/utils/pexif.py
# MAX_HEADER_SIZE = 64 * 1024
# DELIM = 0xff
# EOI = 0xd9
# SOI_MARKER = chr(DELIM) + '\xd8'
# EOI_MARKER = chr(DELIM) + '\xd9'
# EXIF_OFFSET = 0x8769
# GPSIFD = 0x8825
# TIFF_OFFSET = 6
# TIFF_TAG = 0x2a
# DEBUG = 0
# BYTE = ExifType(1, "byte", 1).id
# ASCII = ExifType(2, "ascii", 1).id
# SHORT = ExifType(3, "short", 2).id
# LONG = ExifType(4, "long", 4).id
# RATIONAL = ExifType(5, "rational", 8).id
# UNDEFINED = ExifType(7, "undefined", 1).id
# SLONG = ExifType(9, "slong", 4).id
# SRATIONAL = ExifType(10, "srational", 8).id
# APP1 = 0xe1
#     SEC_DEN = 50000000
# def debug(*debug_string):
#     def __init__(self, marker, fd, data, mode):
#     def write(self, fd):
#     def get_data(self):
#     def parse_data(self, data):
#     def dump(self, fd):
#     def __init__(self, marker, fd, data, mode):
#     def write(self, fd):
#     def dump(self, fd):
#     def __init__(self, type_id, name, size):
# def exif_type_size(exif_type):
#     def __init__(self, num, den):
#     def __repr__(self):
#     def as_tuple(self):
#     def special_handler(self, tag, data):
#     def ifd_handler(self, data):
#     def extra_ifd_data(self, offset):
#     def has_key(self, key):
#     def __setattr__(self, name, value):
#     def __delattr__(self, name):
#     def __getattr__(self, name):
#     def __getitem__(self, key):
#     def __delitem__(self, key):
#     def __setitem__(self, key, value):
#     def __init__(self, e, offset, exif_file, mode, data = None):
#     def isifd(self, other):
#     def getdata(self, e, offset, last = 0):
#     def dump(self, f, indent = ""):
#     def getdata(self, e, offset, last = 0):
# def ifd_maker_note(e, offset, exif_file, mode, data):
#     def __init__(self, e, offset, exif_file, mode, data = None):
#     def special_handler(self, tag, data):
#     def new_gps(self):
#     def ifd_handler(self, data):
#     def extra_ifd_data(self, offset):
#     def __init__(self, marker, fd, data, mode):
#     def parse_data(self, data):
#     def dump(self, fd):
#     def get_data(self):
#     def get_primary(self, create=False):
#     def _get_property(self):
#     def fromFile(filename, mode="rw"):
#     def fromString(str, mode="rw"):
#     def fromFd(fd, mode="rw"):
#     def __init__(self, input, filename=None, mode="rw"):
#     def writeString(self):
#     def writeFile(self, filename):
#     def writeFd(self, output):
#     def dump(self, f = sys.stdout):
#     def get_exif(self, create=False):
#     def add_exif(self):
#     def _get_exif(self):
#     def get_geo(self):
#         def convert(x):
#     def _parse(val):
#     def set_geo(self, lat, lng):
# class DefaultSegment:
#     class InvalidSegment(Exception):
# class StartOfScanSegment(DefaultSegment):
# class ExifType:
# class Rational:
# class IfdData:
# class IfdInterop(IfdData):
# class CanonIFD(IfdData):
# class FujiIFD(IfdData):
# class IfdGPS(IfdData):
# class IfdExtendedEXIF(IfdData):
# class IfdTIFF(IfdData):
# class IfdThumbnail(IfdTIFF):
# class ExifSegment(DefaultSegment):
# class JpegFile:
#     class InvalidFile(Exception):
#     class NoSection(Exception):


# Path: image_filer/utils/pil_exif.py
    import Image
    import ExifTags
import StringIO
        from PIL import Image
        from PIL import ExifTags
from image_filer.utils import pexif

try:
except ImportError:
    try:
    except ImportError:
        raise ImportError("The Python Imaging Library was not found.")

def get_exif(im):
    try:
        exif_raw = im._getexif() or {}
    except:
        return {}
    ret={}
    for tag, value in exif_raw.items():
        decoded = ExifTags.TAGS.get(tag, tag)
        ret[decoded] = value
    return ret
def get_exif_for_file(file):
    im = Image.open(file,'r')
    return get_exif(im)
def get_subject_location(exif_data):
    try:
        r = ( int(exif_data['SubjectLocation'][0]), int(exif_data['SubjectLocation'][1]), )
    except:
        r = None
    return r

def set_exif_subject_location(xy, fd_source, out_path):
    try:
        img = pexif.JpegFile.fromFd(fd_source)

    except pexif.JpegFile.InvalidFile, e: