MCPcopy Index your code
hub / github.com/microsoft/SandDance / _translate_glob_part

Function _translate_glob_part

python/jupyter-widget/setupbase.py:685–720  ·  view source on GitHub ↗

Translate a glob PATTERN PART to a regular expression.

(pat)

Source from the content-addressed store, hash-verified

683
684
685def _translate_glob_part(pat):
686 """Translate a glob PATTERN PART to a regular expression."""
687 # Code modified from Python 3 standard lib fnmatch:
688 if pat == '**':
689 return '.*'
690 i, n = 0, len(pat)
691 res = []
692 while i < n:
693 c = pat[i]
694 i = i + 1
695 if c == '*':
696 # Match anything but path separators:
697 res.append('[^%s]*' % SEPARATORS)
698 elif c == '?':
699 res.append('[^%s]?' % SEPARATORS)
700 elif c == '[':
701 j = i
702 if j < n and pat[j] == '!':
703 j = j + 1
704 if j < n and pat[j] == ']':
705 j = j + 1
706 while j < n and pat[j] != ']':
707 j = j + 1
708 if j >= n:
709 res.append('\\[')
710 else:
711 stuff = pat[i:j].replace('\\', '\\\\')
712 i = j + 1
713 if stuff[0] == '!':
714 stuff = '^' + stuff[1:]
715 elif stuff[0] == '^':
716 stuff = '\\' + stuff
717 res.append('[%s]' % stuff)
718 else:
719 res.append(re.escape(c))
720 return ''.join(res)

Callers 1

_translate_globFunction · 0.85

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected