@@ -363,25 +363,6 @@ def marquee(txt: str = "", width: int = 78, mark: str = "*") -> str:
363363 return '%s %s %s' % (marks ,txt ,marks )
364364
365365
366- ini_spaces_re = re .compile (r'^(\s+)' )
367-
368-
369- def num_ini_spaces (strng : str ) -> int :
370- """Return the number of initial spaces in a string"""
371- warnings .warn (
372- "`num_ini_spaces` is Pending Deprecation since IPython 8.17."
373- "It is considered for removal in in future version. "
374- "Please open an issue if you believe it should be kept." ,
375- stacklevel = 2 ,
376- category = PendingDeprecationWarning ,
377- )
378- ini_spaces = ini_spaces_re .match (strng )
379- if ini_spaces :
380- return ini_spaces .end ()
381- else :
382- return 0
383-
384-
385366def format_screen (strng : str ) -> str :
386367 """Format a string for screen printing.
387368
@@ -501,26 +482,6 @@ def strip_email_quotes(text: str) -> str:
501482 return text
502483
503484
504- def strip_ansi (source : str ) -> str :
505- """
506- Remove ansi escape codes from text.
507-
508- Parameters
509- ----------
510- source : str
511- Source to remove the ansi from
512- """
513- warnings .warn (
514- "`strip_ansi` is Pending Deprecation since IPython 8.17."
515- "It is considered for removal in in future version. "
516- "Please open an issue if you believe it should be kept." ,
517- stacklevel = 2 ,
518- category = PendingDeprecationWarning ,
519- )
520-
521- return re .sub (r'\033\[(\d|;)+?m' , '' , source )
522-
523-
524485class EvalFormatter (Formatter ):
525486 """A String Formatter that allows evaluation of simple expressions.
526487
@@ -704,153 +665,6 @@ def _get_or_default(mylist: List[T], i: int, default: T) -> T:
704665 return mylist [i ]
705666
706667
707- def compute_item_matrix (
708- items : List [str ],
709- row_first : bool = False ,
710- empty : Optional [str ] = None ,
711- * ,
712- separator_size : int = 2 ,
713- displaywidth : int = 80 ,
714- ) -> Tuple [List [List [int ]], Dict [str , int ]]:
715- """Returns a nested list, and info to columnize items
716-
717- Parameters
718- ----------
719- items
720- list of strings to columize
721- row_first : (default False)
722- Whether to compute columns for a row-first matrix instead of
723- column-first (default).
724- empty : (default None)
725- default value to fill list if needed
726- separator_size : int (default=2)
727- How much characters will be used as a separation between each columns.
728- displaywidth : int (default=80)
729- The width of the area onto which the columns should enter
730-
731- Returns
732- -------
733- strings_matrix
734- nested list of string, the outer most list contains as many list as
735- rows, the innermost lists have each as many element as columns. If the
736- total number of elements in `items` does not equal the product of
737- rows*columns, the last element of some lists are filled with `None`.
738- dict_info
739- some info to make columnize easier:
740-
741- num_columns
742- number of columns
743- max_rows
744- maximum number of rows (final number may be less)
745- column_widths
746- list of with of each columns
747- optimal_separator_width
748- best separator width between columns
749-
750- Examples
751- --------
752- ::
753-
754- In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
755- In [2]: list, info = compute_item_matrix(l, displaywidth=12)
756- In [3]: list
757- Out[3]: [['aaa', 'f', 'k'], ['b', 'g', 'l'], ['cc', 'h', None], ['d', 'i', None], ['eeeee', 'j', None]]
758- In [4]: ideal = {'num_columns': 3, 'column_widths': [5, 1, 1], 'optimal_separator_width': 2, 'max_rows': 5}
759- In [5]: all((info[k] == ideal[k] for k in ideal.keys()))
760- Out[5]: True
761- """
762- warnings .warn (
763- "`compute_item_matrix` is Pending Deprecation since IPython 8.17."
764- "It is considered for removal in in future version. "
765- "Please open an issue if you believe it should be kept." ,
766- stacklevel = 2 ,
767- category = PendingDeprecationWarning ,
768- )
769- info = _find_optimal (
770- list (map (len , items )), # type: ignore[arg-type]
771- row_first ,
772- separator_size = separator_size ,
773- displaywidth = displaywidth ,
774- )
775- nrow , ncol = info ["max_rows" ], info ["num_columns" ]
776- if row_first :
777- return (
778- [
779- [
780- _get_or_default (
781- items , r * ncol + c , default = empty
782- ) # type:ignore[misc]
783- for c in range (ncol )
784- ]
785- for r in range (nrow )
786- ],
787- info ,
788- )
789- else :
790- return (
791- [
792- [
793- _get_or_default (
794- items , c * nrow + r , default = empty
795- ) # type:ignore[misc]
796- for c in range (ncol )
797- ]
798- for r in range (nrow )
799- ],
800- info ,
801- )
802-
803-
804- def columnize (
805- items : List [str ],
806- row_first : bool = False ,
807- separator : str = " " ,
808- displaywidth : int = 80 ,
809- spread : bool = False ,
810- ) -> str :
811- """Transform a list of strings into a single string with columns.
812-
813- Parameters
814- ----------
815- items : sequence of strings
816- The strings to process.
817- row_first : (default False)
818- Whether to compute columns for a row-first matrix instead of
819- column-first (default).
820- separator : str, optional [default is two spaces]
821- The string that separates columns.
822- displaywidth : int, optional [default is 80]
823- Width of the display in number of characters.
824-
825- Returns
826- -------
827- The formatted string.
828- """
829- warnings .warn (
830- "`columnize` is Pending Deprecation since IPython 8.17."
831- "It is considered for removal in future versions. "
832- "Please open an issue if you believe it should be kept." ,
833- stacklevel = 2 ,
834- category = PendingDeprecationWarning ,
835- )
836- if not items :
837- return "\n "
838- matrix : List [List [int ]]
839- matrix , info = compute_item_matrix (
840- items ,
841- row_first = row_first ,
842- separator_size = len (separator ),
843- displaywidth = displaywidth ,
844- )
845- if spread :
846- separator = separator .ljust (int (info ["optimal_separator_width" ]))
847- fmatrix : List [filter [int ]] = [filter (None , x ) for x in matrix ]
848- sjoin = lambda x : separator .join (
849- [y .ljust (w , " " ) for y , w in zip (x , cast (List [int ], info ["column_widths" ]))]
850- )
851- return "\n " .join (map (sjoin , fmatrix )) + "\n "
852-
853-
854668def get_text_list (
855669 list_ : List [str ], last_sep : str = " and " , sep : str = ", " , wrap_item_with : str = ""
856670) -> str :
0 commit comments