Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.pyparsing.util Namespace Reference

Data Structures

class  _FifoCache
 
class  _UnboundedCache
 
class  LRUMemo
 
class  UnboundedMemo
 

Functions

int col (int loc, str strg)
 
int lineno (int loc, str strg)
 
str line (int loc, str strg)
 
str _escape_regex_range_chars (str s)
 
str _collapse_string_to_ranges (Union[str, Iterable[str]] s, bool re_escape=True)
 
list _flatten (list ll)
 
C _make_synonym_function (str compat_name, C fn)
 
Callable[[Callable], Creplaced_by_pep8 (C fn)
 

Variables

 _bslash = chr(92)
 
 C = TypeVar("C", bound=Callable)
 

Function Documentation

◆ _collapse_string_to_ranges()

str _collapse_string_to_ranges ( Union[str, Iterable[str]]  s,
bool   re_escape = True 
)
protected

Definition at line 186 of file util.py.

188) -> str:
189 def is_consecutive(c):
190 c_int = ord(c)
192 if c_int - prev > 1:
195
196 is_consecutive.prev = 0 # type: ignore [attr-defined]
197 is_consecutive.counter = itertools.count() # type: ignore [attr-defined]
198 is_consecutive.value = -1 # type: ignore [attr-defined]
199
201 return "\\" + c if c in r"\^-][" else c
202
204 return c
205
206 if not re_escape:
207 escape_re_range_char = no_escape_re_range_char
208
209 ret = []
210 s = "".join(sorted(set(s)))
211 if len(s) > 3:
212 for _, chars in itertools.groupby(s, key=is_consecutive):
213 first = last = next(chars)
214 last = collections.deque(
215 itertools.chain(iter([last]), chars), maxlen=1
216 ).pop()
217 if first == last:
219 else:
220 sep = "" if ord(last) == ord(first) + 1 else "-"
222 f"{escape_re_range_char(first)}{sep}{escape_re_range_char(last)}"
223 )
224 else:
225 ret = [escape_re_range_char(c) for c in s]
226
227 return "".join(ret)
228
229
for i

References i.

◆ _escape_regex_range_chars()

str _escape_regex_range_chars ( str  s)
protected

Definition at line 177 of file util.py.

177def _escape_regex_range_chars(s: str) -> str:
178 # escape these chars: ^-[]
179 for c in r"\^-[]":
180 s = s.replace(c, _bslash + c)
181 s = s.replace("\n", r"\n")
182 s = s.replace("\t", r"\t")
183 return str(s)
184
185

◆ _flatten()

list _flatten ( list  ll)
protected

Definition at line 230 of file util.py.

230def _flatten(ll: list) -> list:
231 ret = []
232 for i in ll:
233 if isinstance(i, list):
234 ret.extend(_flatten(i))
235 else:
236 ret.append(i)
237 return ret
238
239

References i.

◆ _make_synonym_function()

C _make_synonym_function ( str  compat_name,
C  fn 
)
protected

Definition at line 240 of file util.py.

240def _make_synonym_function(compat_name: str, fn: C) -> C:
241 # In a future version, uncomment the code in the internal _inner() functions
242 # to begin emitting DeprecationWarnings.
243
244 # Unwrap staticmethod/classmethod
245 fn = getattr(fn, "__func__", fn)
246
247 # (Presence of 'self' arg in signature is used by explain_exception() methods, so we take
248 # some extra steps to add it if present in decorated function.)
249 if "self" == list(inspect.signature(fn).parameters)[0]:
250
251 @wraps(fn)
252 def _inner(self, *args, **kwargs):
253 # warnings.warn(
254 # f"Deprecated - use {fn.__name__}", DeprecationWarning, stacklevel=3
255 # )
256 return fn(self, *args, **kwargs)
257
258 else:
259
260 @wraps(fn)
261 def _inner(*args, **kwargs):
262 # warnings.warn(
263 # f"Deprecated - use {fn.__name__}", DeprecationWarning, stacklevel=3
264 # )
265 return fn(*args, **kwargs)
266
267 _inner.__doc__ = f"""Deprecated - use :class:`{fn.__name__}`"""
268 _inner.__name__ = compat_name
272 elif isinstance(fn, type) and hasattr(fn, "__init__"):
274 else:
277 return cast(C, _inner)
278
279

References i.

Referenced by pip._vendor.pyparsing.util.replaced_by_pep8().

Here is the caller graph for this function:

◆ col()

int col ( int  loc,
str  strg 
)
Returns current column within a string, counting newlines as line separators.
The first column is number 1.

Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process.  See
:class:`ParserElement.parse_string` for more
information on parsing strings containing ``<TAB>`` s, and suggested
methods to maintain a consistent view of the parsed string, the parse
location, and line and column positions within the parsed string.

Definition at line 40 of file util.py.

40def col(loc: int, strg: str) -> int:
41 """
42 Returns current column within a string, counting newlines as line separators.
43 The first column is number 1.
44
45 Note: the default parsing behavior is to expand tabs in the input string
46 before starting the parsing process. See
47 :class:`ParserElement.parse_string` for more
48 information on parsing strings containing ``<TAB>`` s, and suggested
49 methods to maintain a consistent view of the parsed string, the parse
50 location, and line and column positions within the parsed string.
51 """
52 s = strg
53 return 1 if 0 < loc < len(s) and s[loc - 1] == "\n" else loc - s.rfind("\n", 0, loc)
54
55
56@lru_cache(maxsize=128)

References i.

◆ line()

str line ( int  loc,
str  strg 
)
Returns the line of text containing loc within a string, counting newlines as line separators.

Definition at line 71 of file util.py.

71def line(loc: int, strg: str) -> str:
72 """
73 Returns the line of text containing loc within a string, counting newlines as line separators.
74 """
75 last_cr = strg.rfind("\n", 0, loc)
76 next_cr = strg.find("\n", loc)
77 return strg[last_cr + 1 : next_cr] if next_cr >= 0 else strg[last_cr + 1 :]
78
79

References i.

◆ lineno()

int lineno ( int  loc,
str  strg 
)
Returns current line number within a string, counting newlines as line separators.
The first line is number 1.

Note - the default parsing behavior is to expand tabs in the input string
before starting the parsing process.  See :class:`ParserElement.parse_string`
for more information on parsing strings containing ``<TAB>`` s, and
suggested methods to maintain a consistent view of the parsed string, the
parse location, and line and column positions within the parsed string.

Definition at line 57 of file util.py.

57def lineno(loc: int, strg: str) -> int:
58 """Returns current line number within a string, counting newlines as line separators.
59 The first line is number 1.
60
61 Note - the default parsing behavior is to expand tabs in the input string
62 before starting the parsing process. See :class:`ParserElement.parse_string`
63 for more information on parsing strings containing ``<TAB>`` s, and
64 suggested methods to maintain a consistent view of the parsed string, the
65 parse location, and line and column positions within the parsed string.
66 """
67 return strg.count("\n", 0, loc) + 1
68
69
70@lru_cache(maxsize=128)

References i.

◆ replaced_by_pep8()

Callable[[Callable], C] replaced_by_pep8 ( C  fn)
Decorator for pre-PEP8 compatibility synonyms, to link them to the new function.

Definition at line 280 of file util.py.

280def replaced_by_pep8(fn: C) -> Callable[[Callable], C]:
281 """
282 Decorator for pre-PEP8 compatibility synonyms, to link them to the new function.
283 """
284 return lambda other: _make_synonym_function(other.__name__, fn)

References pip._vendor.pyparsing.util._make_synonym_function(), and i.

Here is the call graph for this function:

Variable Documentation

◆ _bslash

_bslash = chr(92)
protected

Definition at line 10 of file util.py.

◆ C

C = TypeVar("C", bound=Callable)

Definition at line 11 of file util.py.