original_docstring: 
      Open and write metadata for image
      :param image: (string) image file to change metadata
      :param newData: (dict) metadata tags
      
docstring: Open and write metadata for image
docstring_tokens: Open and write metadata for image
code: def change_metadata(image, newData):
      """
      Open and write metadata for image
      :param image: (string) image file to change metadata
      :param newData: (dict) metadata tags
      """
  
      # pyexiv2 is very picky about what it allows as data in metadata tags
      # you also can't check a metadata type if it doesn't exist for an
      # image yet. Therefore, try-catches must be used to handle
      # various inputs.
      metadata = pyexiv2.ImageMetadata(image)
      metadata.read()
      try:
          for key in newData:
              if newData[key] == '':
                  try:
                      del metadata[key]
                  except KeyError:
                      # the user tried to delete a tag that doesn't exist.
                      # this is fine, just skip over it.
                      continue
              elif key.startswith('Xmp'):
                  metadata[key] = newData[key]
              else:
                  try:
                      metadata[key] = [newData[key]]
                  except ValueError:
                      try:
                          metadata[key] = [int(newData[key])]
                      except ValueError:
                          try:
                              metadata[key] = [pyexiv2.Rational.from_string(newData[key])]
                          except ValueError:
                              try:
                                  # assume value is either a date or a time
                                  descr = map(int, newData[key].split(','))
                                  metadata[key] = [datetime.date(*tuple(descr))]
                              except ValueError:
                                  try:
                                      metadata[key] = [datetime.time(*tuple(descr))]
                                  except TypeError:
                                      print('Invalid Value for this tag: ' + str(newData[key]) +
                                            '. Check input formatting. No changes were made.')
                                      sys.exit()
      except KeyError:
          print('The tag: ' + key + ' does not exist. Check input formatting. No changes were made.')
          sys.exit()
      metadata.write(preserve_timestamps=True)
code_tokens: def change_metadata ( image , newData ) : metadata = pyexiv2 . ImageMetadata ( image ) metadata . read ( ) try : for key in newData : if newData [ key ] == '' : try : del metadata [ key ] except KeyError : continue elif key . startswith ( 'Xmp' ) : metadata [ key ] = newData [ key ] else : try : metadata [ key ] = [ newData [ key ] ] except ValueError : try : metadata [ key ] = [ int ( newData [ key ] ) ] except ValueError : try : metadata [ key ] = [ pyexiv2 . Rational . from_string ( newData [ key ] ) ] except ValueError : try : descr = map ( int , newData [ key ] . split ( ',' ) ) metadata [ key ] = [ datetime . date ( * tuple ( descr ) ) ] except ValueError : try : metadata [ key ] = [ datetime . time ( * tuple ( descr ) ) ] except TypeError : print ( 'Invalid Value for this tag: ' + str ( newData [ key ] ) + '. Check input formatting. No changes were made.' ) sys . exit ( ) except KeyError : print ( 'The tag: ' + key + ' does not exist. Check input formatting. No changes were made.' ) sys . exit ( ) metadata . write ( preserve_timestamps = True )
short_docstring: Open and write metadata for image
short_docstring_tokens: Open and write metadata for image
comment: """
      Open and write metadata for image
      :param image: (string) image file to change metadata
      :param newData: (dict) metadata tags
      """$SEP$# pyexiv2 is very picky about what it allows as data in metadata tags$SEP$# you also can't check a metadata type if it doesn't exist for an$SEP$# image yet. Therefore, try-catches must be used to handle$SEP$# various inputs.$SEP$# the user tried to delete a tag that doesn't exist.$SEP$# this is fine, just skip over it.$SEP$# assume value is either a date or a time