@staticmethod
  def _ExtractMetadata(image, parse_metadata):
    """Extract EXIF metadata from the image.

    Note that this is a much simplified version of metadata extraction. After
    deployment applications have access to a more powerful parser that can
    parse hundreds of fields from images.

    Args:
      image: PIL Image object.
      parse_metadata: bool, True if metadata parsing has been requested. If
        False the result will contain image dimensions.
    Returns:
      str, JSON encoded values with various metadata fields.
    """

    def ExifTimeToUnixtime(exif_time):
      """Convert time in EXIF to unix time.

      Args:
        exif_time: str, the time from the EXIF block formated by EXIF standard.
          E.g., "2011:02:20 10:23:12", seconds are optional.

      Returns:
        Integer, the time in unix fromat: seconds since the epoch.
      """
      regexp = re.compile(r"^([0-9]{4}):([0-9]{1,2}):([0-9]{1,2})"
                          " ([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?")
      match = regexp.match(exif_time)
      if match is None: return None
      try:
        date = datetime.datetime(*map(int, filter(None, match.groups())))
      except ValueError:
        logging.info("Invalid date in EXIF: %s", exif_time)
        return None
      return int(time.mktime(date.timetuple()))

    metadata_dict = (
        parse_metadata and ImagesServiceStub._GetExifFromImage(image) or {})

    metadata_dict[256], metadata_dict[257] = image.size



    if _EXIF_DATETIMEORIGINAL_TAG in metadata_dict:
      date_ms = ExifTimeToUnixtime(metadata_dict[_EXIF_DATETIMEORIGINAL_TAG])
      if date_ms:
        metadata_dict[_EXIF_DATETIMEORIGINAL_TAG] = date_ms
      else:
        del metadata_dict[_EXIF_DATETIMEORIGINAL_TAG]
    metadata = dict([(_EXIF_TAGS[k], v)
                for k, v in metadata_dict.iteritems()
                if k in _EXIF_TAGS])
    return simplejson.dumps(metadata)
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/api/images/images_stub.py/ImagesServiceStub._ExtractMetadata/original