Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_integrity(self):
"""Test glob integrity, or better put, test the path structure comes out sane."""
orig = [pathlib.Path(x) for x in glob.iglob('docs/**/*.md', flags=glob.GLOBSTAR)]
results = list(pathlib.Path('docs').glob('**/*.md', flags=glob.GLOBSTAR))
self.assertEqual(orig, results)
orig = [pathlib.Path(x) for x in glob.iglob('**/*.md', flags=glob.GLOBSTAR)]
results = list(pathlib.Path('').glob('**/*.md', flags=glob.GLOBSTAR))
self.assertEqual(orig, results)
if parts:
if len(parts) == 1:
p = parts[0]
else:
p = cls.globjoin(*parts)
if not cls.absolute:
p = cls.globjoin(cls.tempdir, p)
else:
p = cls.tempdir
res = glob.glob(p, **kwargs)
print("RESULTS: ", res)
if res:
cls.assert_equal({type(r) for r in res}, {str})
cls.assert_count_equal(glob.iglob(p, **kwargs), res)
if 'root_dir' in kwargs and kwargs['root_dir'] is not None:
kwargs['root_dir'] = os.fsencode(kwargs['root_dir'])
bres = [os.fsencode(x) for x in res]
cls.assert_count_equal(glob.glob(os.fsencode(p), **kwargs), bres)
cls.assert_count_equal(glob.iglob(os.fsencode(p), **kwargs), bres)
if bres:
cls.assert_equal({type(r) for r in bres}, {bytes})
return res
def hash_files(verbose, debug):
"""Hash the file list."""
found = []
h = hashlib.new('md5')
for pattern in FILES_PATTERNS:
for f in glob.iglob(pattern, flags=FLAGS):
name = f.replace('\\', '/')
found.append(name)
if verbose:
print('FILES:')
for f in sorted(found):
if verbose:
print(f)
h.update(f.encode('ascii'))
with open(f, 'rb') as f:
h.update(f.read().replace(b'\r\n', b'\n'))
result = h.hexdigest()
print('HASH: ', result)
return result
def glob(self, patterns, *, flags=0, limit=_wcparse.PATTERN_LIMIT):
"""
Search the file system.
`GLOBSTAR` is enabled by default in order match the default behavior of `pathlib`.
"""
if self.is_dir():
scandotdir = flags & SCANDOTDIR
flags = self._translate_flags(flags | _NOABSOLUTE) | ((_PATHLIB | SCANDOTDIR) if scandotdir else _PATHLIB)
for filename in glob.iglob(patterns, flags=flags, root_dir=str(self), limit=limit):
yield self.joinpath(filename)
def _walk_src(self, targets, flags, limit, pipeline, expect_match):
"""Walk source and parse files."""
found_something = False
for target in targets:
# Glob using `S` for patterns wit `|` and `O` to exclude directories.
kwargs = {"flags": flags | glob.S | glob.O}
kwargs['limit'] = limit
for f in glob.iglob(target, **kwargs):
found_something = True
self.log('', 2)
self.log('> Processing: %s' % f, 1)
if pipeline:
try:
yield pipeline[0]._run_first(f)
except Exception as e:
err = self.get_error(e)
yield [filters.SourceText('', f, '', '', err)]
else:
try:
if self.default_encoding:
encoding = filters.PYTHON_ENCODING_NAMES.get(
self.default_encoding, self.default_encoding
).lower()
encoding = codecs.lookup(encoding).name