parameters: (plist, add_keys)
docstring: Adds PDF support to the document types list. If add_keys is True, it will
    add the type information dictionary. If it is False, it will remove it if
    present.
docstring_summary: Adds PDF support to the document types list. If add_keys is True, it will
    add the type information dictionary. If it is False, it will remove it if
    present.
docstring_tokens: Adds PDF support to the document types list . If add_keys is True it will add the type information dictionary . If it is False it will remove it if present .
function: def _DoPDFKeys(plist, add_keys):
    """Adds PDF support to the document types list. If add_keys is True, it will
    add the type information dictionary. If it is False, it will remove it if
    present."""
  
    PDF_FILE_EXTENSION = 'pdf'
  
    def __AddPDFKeys(sub_plist):
      """Writes the keys into a sub-dictionary of the plist."""
      sub_plist['CFBundleTypeExtensions'] = [PDF_FILE_EXTENSION]
      sub_plist['CFBundleTypeIconFile'] = 'document.icns'
      sub_plist['CFBundleTypeMIMETypes'] = 'application/pdf'
      sub_plist['CFBundleTypeName'] = 'PDF Document'
      sub_plist['CFBundleTypeRole'] = 'Viewer'
  
    DOCUMENT_TYPES_KEY = 'CFBundleDocumentTypes'
  
    # First get the list of document types, creating it if necessary.
    try:
      extensions = plist[DOCUMENT_TYPES_KEY]
    except KeyError:
      # If this plist doesn't have a type dictionary, create one if set to add the
      # keys. If not, bail.
      if not add_keys:
        return
      extensions = plist[DOCUMENT_TYPES_KEY] = []
  
    # Loop over each entry in the list, looking for one that handles PDF types.
    for i, ext in enumerate(extensions):
      # If an entry for .pdf files is found...
      if 'CFBundleTypeExtensions' not in ext:
        continue
      if PDF_FILE_EXTENSION in ext['CFBundleTypeExtensions']:
        if add_keys:
          # Overwrite the existing keys with new ones.
          __AddPDFKeys(ext)
        else:
          # Otherwise, delete the entry entirely.
          del extensions[i]
        return
  
    # No PDF entry exists. If one needs to be added, do so now.
    if add_keys:
      pdf_entry = {}
      __AddPDFKeys(pdf_entry)
      extensions.append(pdf_entry)
function_tokens: def _DoPDFKeys ( plist , add_keys ) : PDF_FILE_EXTENSION = 'pdf' def __AddPDFKeys ( sub_plist ) : """Writes the keys into a sub-dictionary of the plist.""" sub_plist [ 'CFBundleTypeExtensions' ] = [ PDF_FILE_EXTENSION ] sub_plist [ 'CFBundleTypeIconFile' ] = 'document.icns' sub_plist [ 'CFBundleTypeMIMETypes' ] = 'application/pdf' sub_plist [ 'CFBundleTypeName' ] = 'PDF Document' sub_plist [ 'CFBundleTypeRole' ] = 'Viewer' DOCUMENT_TYPES_KEY = 'CFBundleDocumentTypes' # First get the list of document types, creating it if necessary. try : extensions = plist [ DOCUMENT_TYPES_KEY ] except KeyError : # If this plist doesn't have a type dictionary, create one if set to add the # keys. If not, bail. if not add_keys : return extensions = plist [ DOCUMENT_TYPES_KEY ] = [ ] # Loop over each entry in the list, looking for one that handles PDF types. for i , ext in enumerate ( extensions ) : # If an entry for .pdf files is found... if 'CFBundleTypeExtensions' not in ext : continue if PDF_FILE_EXTENSION in ext [ 'CFBundleTypeExtensions' ] : if add_keys : # Overwrite the existing keys with new ones. __AddPDFKeys ( ext ) else : # Otherwise, delete the entry entirely. del extensions [ i ] return # No PDF entry exists. If one needs to be added, do so now. if add_keys : pdf_entry = { } __AddPDFKeys ( pdf_entry ) extensions . append ( pdf_entry )