@@ -1674,7 +1674,7 @@ def match(self, patterns, name, accept_prefix=False):
1674
1674
matcher = wildcard .get_matcher (patterns , case_sensitive )
1675
1675
return matcher (name )
1676
1676
1677
- def match_glob (self , patterns , name , accept_prefix = False ):
1677
+ def match_glob (self , patterns , path , accept_prefix = False ):
1678
1678
# type: (Optional[Iterable[Text]], Text, bool) -> bool
1679
1679
"""Check if a path matches any of a list of glob patterns.
1680
1680
@@ -1687,26 +1687,27 @@ def match_glob(self, patterns, name, accept_prefix=False):
1687
1687
Arguments:
1688
1688
patterns (list, optional): A list of patterns, e.g.
1689
1689
``['*.py']``, or `None` to match everything.
1690
- name (str): A file or directory name (not a path)
1691
- accept_prefix (bool): If ``True``, the name is
1690
+ path (str): A resource path, starting with "/".
1691
+ accept_prefix (bool): If ``True``, the path is
1692
1692
not required to match the wildcards themselves
1693
1693
but only need to be a prefix of a string that does.
1694
1694
1695
1695
Returns:
1696
- bool: `True` if ``name `` matches any of the patterns.
1696
+ bool: `True` if ``path `` matches any of the patterns.
1697
1697
1698
1698
Raises:
1699
1699
TypeError: If ``patterns`` is a single string instead of
1700
1700
a list (or `None`).
1701
+ ValueError: If ``path`` is not a string starting with "/".
1701
1702
1702
1703
Example:
1703
- >>> my_fs.match_glob(['*.py'], '__init__.py')
1704
+ >>> my_fs.match_glob(['*.py'], '/ __init__.py')
1704
1705
True
1705
- >>> my_fs.match_glob(['*.jpg', '*.png'], 'foo.gif')
1706
+ >>> my_fs.match_glob(['*.jpg', '*.png'], '/ foo.gif')
1706
1707
False
1707
- >>> my_fs.match_glob(['dir/file.txt'], 'dir/', accept_prefix=True)
1708
+ >>> my_fs.match_glob(['dir/file.txt'], '/ dir/', accept_prefix=True)
1708
1709
True
1709
- >>> my_fs.match_glob(['dir/file.txt'], 'dir/gile.txt', accept_prefix=True)
1710
+ >>> my_fs.match_glob(['dir/file.txt'], '/ dir/gile.txt', accept_prefix=True)
1710
1711
False
1711
1712
1712
1713
Note:
@@ -1716,6 +1717,8 @@ def match_glob(self, patterns, name, accept_prefix=False):
1716
1717
"""
1717
1718
if patterns is None :
1718
1719
return True
1720
+ if not path or path [0 ] != "/" :
1721
+ raise ValueError ("%s needs to be a string starting with /" % path )
1719
1722
if isinstance (patterns , six .text_type ):
1720
1723
raise TypeError ("patterns must be a list or sequence" )
1721
1724
case_sensitive = not typing .cast (
@@ -1724,7 +1727,7 @@ def match_glob(self, patterns, name, accept_prefix=False):
1724
1727
matcher = glob .get_matcher (
1725
1728
patterns , case_sensitive , accept_prefix = accept_prefix
1726
1729
)
1727
- return matcher (name )
1730
+ return matcher (path )
1728
1731
1729
1732
def tree (self , ** kwargs ):
1730
1733
# type: (**Any) -> None
0 commit comments