MCPcopy Index your code
hub / github.com/python/cpython / translate_core

Method translate_core

Lib/zipfile/_path/glob.py:51–64  ·  view source on GitHub ↗

r""" Given a glob pattern, produce a regex that matches it. >>> t = Translator() >>> t.translate_core('*.txt').replace('\\\\', '') '[^/]*\\.txt' >>> t.translate_core('a?txt') 'a[^/]txt' >>> t.translate_core('**/*').replace('\\\\', '')

(self, pattern)

Source from the content-addressed store, hash-verified

49 return rf'{pattern}[/]?'
50
51 def translate_core(self, pattern):
52 r"""
53 Given a glob pattern, produce a regex that matches it.
54
55 >>> t = Translator()
56 >>> t.translate_core('*.txt').replace('\\\\', '')
57 '[^/]*\\.txt'
58 >>> t.translate_core('a?txt')
59 'a[^/]txt'
60 >>> t.translate_core('**/*').replace('\\\\', '')
61 '.*/[^/][^/]*'
62 """
63 self.restrict_rglob(pattern)
64 return ''.join(map(self.replace, separate(self.star_not_empty(pattern))))
65
66 def replace(self, match):
67 """

Callers 1

translateMethod · 0.95

Calls 4

restrict_rglobMethod · 0.95
star_not_emptyMethod · 0.95
separateFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected