class_docstr: Class for embedding local file links in an IPython session, based on path
  
  e.g. to embed links to files that were generated in the IPython notebook
  under ``my/data``, you would do::
  
      local_files = FileLinks("my/data")
      display(local_files)
  
  or in the HTML notebook, just::
  
      FileLinks("my/data")
class_docstr_tok: ["Class","for","embedding","local","file","links","in","an","IPython","session",",","based","on","path","e.g",".","to","embed","links","to","files","that","were","generated","in","the","IPython","notebook","under","``","my\/data","``",",","you","would","do",":",":","local_files","=","FileLinks","(","``","my\/data","''",")","display","(","local_files",")","or","in","the","HTML","notebook",",","just",":",":","FileLinks","(","``","my\/data","''",")"]
docstr: generate built-in formatter function
  
  this is used to define both the notebook and terminal built-in
   formatters as they only differ by some wrapper text for each entry
  
  dirname_output_format: string to use for formatting directory
   names, dirname will be substituted for a single "%s" which
   must appear in this string
  fname_output_format: string to use for formatting file names,
   if a single "%s" appears in the string, fname will be substituted
   if two "%s" appear in the string, the path to fname will be
    substituted for the first and fname will be substituted for the
    second
  fp_format: string to use for formatting filepaths, must contain
   exactly two "%s" and the dirname will be subsituted for the first
   and fname will be substituted for the second
docstr_tok: ["generate","built-in","formatter","function","this","is","used","to","define","both","the","notebook","and","terminal","built-in","formatters","as","they","only","differ","by","some","wrapper","text","for","each","entry","dirname_output_format",":","string","to","use","for","formatting","directory","names",",","dirname","will","be","substituted","for","a","single","``","%","s","''","which","must","appear","in","this","string","fname_output_format",":","string","to","use","for","formatting","file","names",",","if","a","single","``","%","s","''","appears","in","the","string",",","fname","will","be","substituted","if","two","``","%","s","''","appear","in","the","string",",","the","path","to","fname","will","be","substituted","for","the","first","and","fname","will","be","substituted","for","the","second","fp_format",":","string","to","use","for","formatting","filepaths",",","must","contain","exactly","two","``","%","s","''","and","the","dirname","will","be","subsituted","for","the","first","and","fname","will","be","substituted","for","the","second"]
code: def _get_display_formatter(
      self,
      dirname_output_format,
      fname_output_format,
      fp_format,
      fp_cleaner=None,
  ):
      """generate built-in formatter function
  
      this is used to define both the notebook and terminal built-in
       formatters as they only differ by some wrapper text for each entry
  
      dirname_output_format: string to use for formatting directory
       names, dirname will be substituted for a single "%s" which
       must appear in this string
      fname_output_format: string to use for formatting file names,
       if a single "%s" appears in the string, fname will be substituted
       if two "%s" appear in the string, the path to fname will be
        substituted for the first and fname will be substituted for the
        second
      fp_format: string to use for formatting filepaths, must contain
       exactly two "%s" and the dirname will be subsituted for the first
       and fname will be substituted for the second
      """
  
      def f(dirname, fnames, included_suffixes=None):
          result = []
          # begin by figuring out which filenames, if any,
          # are going to be displayed
          display_fnames = []
          for fname in fnames:
              if isfile(join(dirname, fname)) and (
                  included_suffixes is None
                  or splitext(fname)[1] in included_suffixes
              ):
                  display_fnames.append(fname)
  
          if len(display_fnames) == 0:
              # if there are no filenames to display, don't print anything
              # (not even the directory name)
              pass
          else:
              # otherwise print the formatted directory name followed by
              # the formatted filenames
              dirname_output_line = dirname_output_format % dirname
              result.append(dirname_output_line)
              for fname in display_fnames:
                  fp = fp_format % (dirname, fname)
                  if fp_cleaner is not None:
                      fp = fp_cleaner(fp)
                  try:
                      # output can include both a filepath and a filename...
                      fname_output_line = fname_output_format % (
                          fp,
                          fname,
                      )
                  except TypeError:
                      # ... or just a single filepath
                      fname_output_line = fname_output_format % fname
                  result.append(fname_output_line)
          return result
  
      return f
  
imports: from os.path import exists, isfile, splitext, abspath, join, isdir
  from os import walk, sep
  from IPython.core.display import DisplayObject
label_desc: Use image node_id 2 for calling the FileLinks obj's underlying member method code with example usage: obj._get_display_formatter(dirname_output_format, fname_output_format, fp_format, fp_cleaner) and returns: f, result