MCPcopy Create free account
hub / github.com/microsoft/debugpy / Matching

Class Matching

tests/patterns/_impl.py:355–387  ·  view source on GitHub ↗

Matches any string that matches the specified regular expression.

Source from the content-addressed store, hash-verified

353
354
355class Matching(Also):
356 """Matches any string that matches the specified regular expression."""
357
358 def __init__(self, pattern, regex, flags=0):
359 assert isinstance(regex, bytes) or isinstance(regex, str)
360 super().__init__(pattern)
361 self.regex = regex
362 self.flags = flags
363
364 def __repr__(self):
365 s = repr(self.regex)
366 if s[0] in "bu":
367 return s[0] + "/" + s[2:-1] + "/"
368 else:
369 return "/" + s[1:-1] + "/"
370
371 def _also(self, value):
372 regex = self.regex
373
374 # re.match() always starts matching at the beginning, but does not require
375 # a complete match of the string - append "$" to ensure the latter.
376 if isinstance(regex, bytes):
377 if not isinstance(value, bytes):
378 return NotImplemented
379 regex += b"$"
380 elif isinstance(regex, str):
381 if not isinstance(value, str):
382 return NotImplemented
383 regex += "$"
384 else:
385 raise AssertionError()
386
387 return re.match(regex, value, self.flags) is not None

Callers 1

matchingMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…