MCPcopy Create free account
hub / github.com/ipython/ipython / _get_display_formatter

Method _get_display_formatter

IPython/lib/display.py:490–544  ·  view source on GitHub ↗

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

(self,
                               dirname_output_format,
                               fname_output_format,
                               fp_format,
                               fp_cleaner=None)

Source from the content-addressed store, hash-verified

488 self.recursive = recursive
489
490 def _get_display_formatter(self,
491 dirname_output_format,
492 fname_output_format,
493 fp_format,
494 fp_cleaner=None):
495 """ generate built-in formatter function
496
497 this is used to define both the notebook and terminal built-in
498 formatters as they only differ by some wrapper text for each entry
499
500 dirname_output_format: string to use for formatting directory
501 names, dirname will be substituted for a single "%s" which
502 must appear in this string
503 fname_output_format: string to use for formatting file names,
504 if a single "%s" appears in the string, fname will be substituted
505 if two "%s" appear in the string, the path to fname will be
506 substituted for the first and fname will be substituted for the
507 second
508 fp_format: string to use for formatting filepaths, must contain
509 exactly two "%s" and the dirname will be substituted for the first
510 and fname will be substituted for the second
511 """
512 def f(dirname, fnames, included_suffixes=None):
513 result = []
514 # begin by figuring out which filenames, if any,
515 # are going to be displayed
516 display_fnames = []
517 for fname in fnames:
518 if (isfile(join(dirname,fname)) and
519 (included_suffixes is None or
520 splitext(fname)[1] in included_suffixes)):
521 display_fnames.append(fname)
522
523 if len(display_fnames) == 0:
524 # if there are no filenames to display, don't print anything
525 # (not even the directory name)
526 pass
527 else:
528 # otherwise print the formatted directory name followed by
529 # the formatted filenames
530 dirname_output_line = dirname_output_format % dirname
531 result.append(dirname_output_line)
532 for fname in display_fnames:
533 fp = fp_format % (dirname,fname)
534 if fp_cleaner is not None:
535 fp = fp_cleaner(fp)
536 try:
537 # output can include both a filepath and a filename...
538 fname_output_line = fname_output_format % (fp, fname)
539 except TypeError:
540 # ... or just a single filepath
541 fname_output_line = fname_output_format % fname
542 result.append(fname_output_line)
543 return result
544 return f
545
546 def _get_notebook_display_formatter(self,
547 spacer="  "):

Calls

no outgoing calls

Tested by

no test coverage detected