MCPcopy Index your code
hub / github.com/ipython/ipython / LSString

Class LSString

IPython/utils/text.py:34–84  ·  view source on GitHub ↗

String derivative with a special access attributes. These are normal strings, but with the special attributes: .l (or .list) : value as list (split on newlines). .n (or .nlstr): original value (the string itself). .s (or .spstr): value as whitespace-separated string.

Source from the content-addressed store, hash-verified

32
33
34class LSString(str):
35 """String derivative with a special access attributes.
36
37 These are normal strings, but with the special attributes:
38
39 .l (or .list) : value as list (split on newlines).
40 .n (or .nlstr): original value (the string itself).
41 .s (or .spstr): value as whitespace-separated string.
42 .p (or .paths): list of path objects (requires path.py package)
43
44 Any values which require transformations are computed only once and
45 cached.
46
47 Such strings are very useful to efficiently interact with the shell, which
48 typically only understands whitespace-separated options for commands."""
49
50 __list: List[str]
51 __spstr: str
52 __paths: List[Path]
53
54 def get_list(self) -> List[str]:
55 try:
56 return self.__list
57 except AttributeError:
58 self.__list = self.split('\n')
59 return self.__list
60
61 l = list = property(get_list)
62
63 def get_spstr(self) -> str:
64 try:
65 return self.__spstr
66 except AttributeError:
67 self.__spstr = self.replace('\n',' ')
68 return self.__spstr
69
70 s = spstr = property(get_spstr)
71
72 def get_nlstr(self) -> Self:
73 return self
74
75 n = nlstr = property(get_nlstr)
76
77 def get_paths(self) -> List[Path]:
78 try:
79 return self.__paths
80 except AttributeError:
81 self.__paths = [Path(p) for p in self.split('\n') if os.path.exists(p)]
82 return self.__paths
83
84 p = paths = property(get_paths)
85
86# FIXME: We need to reimplement type specific displayhook and then add this
87# back as a custom printer. This should also be moved outside utils into the

Callers 1

getoutputMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…