-
Notifications
You must be signed in to change notification settings - Fork 49
Closed
Description
The following program illustrates some possible variations:
#!/usr/bin/python3
import pathspec
import os
print("A. String pattern, string path:\n ", end="")
try:
s = pathspec.PathSpec.from_lines('gitwildmatch', ['*.py'])
for p in os.listdir('pathspec'):
if s.match_file(p):
print(p, end=" ")
print()
except Exception as e:
print("FAILED '%s'" % e)
print("B. String pattern, binary path:\n ", end="")
try:
s = pathspec.PathSpec.from_lines('gitwildmatch', ['*.py'])
for p in os.listdir(b'pathspec'):
if s.match_file(p):
print(p, end=' ')
print()
except Exception as e:
print("FAILED '%s'" % e)
print("C. String pattern, binary path + surrogateescape:\n ", end="")
try:
s = pathspec.PathSpec.from_lines('gitwildmatch', ['*.py'])
for p in os.listdir(b'pathspec'):
if s.match_file(p.decode('utf8','surrogateescape')):
print(p, end=' ')
print()
except Exception as e:
print("FAILED '%s'" % e)
print("D. Binary pattern, binary path:\n ", end="")
s = pathspec.PathSpec.from_lines('gitwildmatch', [b'*.py'])
try:
for p in os.listdir(b'pathspec'):
if s.match_file(p):
print(p, end=' ')
print()
except Exception as e:
print("FAILED '%s'" % e)Gives the following result when run in the source directory:
A. String pattern, string path:
util.py pattern.py pathspec.py __init__.py compat.py
B. String pattern, binary path:
FAILED 'cannot use a string pattern on a bytes-like object'
C. String pattern, binary path + surrogateescape:
b'util.py' b'pattern.py' b'pathspec.py' b'__init__.py' b'compat.py'
D. Binary pattern, binary path:
IMHO examples A-C behaves as expected, while example D does not match any files, neither does it complain on the pattern.
Metadata
Metadata
Assignees
Labels
No labels