@@ -54,11 +54,6 @@ def _ignore_error(exception):
54
54
getattr (exception , 'winerror' , None ) in _IGNORED_WINERRORS )
55
55
56
56
57
- def _is_wildcard_pattern (pat ):
58
- # Whether this pattern needs actual matching using fnmatch, or can
59
- # be looked up directly as a file.
60
- return "*" in pat or "?" in pat or "[" in pat
61
-
62
57
def _is_case_sensitive (flavour ):
63
58
return flavour .normcase ('Aa' ) == 'Aa'
64
59
@@ -78,10 +73,8 @@ def _make_selector(pattern_parts, flavour):
78
73
cls = _ParentSelector
79
74
elif '**' in pat :
80
75
raise ValueError ("Invalid pattern: '**' can only be an entire path component" )
81
- elif _is_wildcard_pattern (pat ):
82
- cls = _WildcardSelector
83
76
else :
84
- cls = _PreciseSelector
77
+ cls = _WildcardSelector
85
78
return cls (pat , child_parts , flavour )
86
79
87
80
@@ -102,55 +95,36 @@ def select_from(self, parent_path):
102
95
"""Iterate over all child paths of `parent_path` matched by this
103
96
selector. This can contain parent_path itself."""
104
97
path_cls = type (parent_path )
105
- is_dir = path_cls .is_dir
106
- exists = path_cls .exists
107
98
scandir = path_cls ._scandir
108
- if not is_dir (parent_path ):
99
+ if not parent_path . is_dir ():
109
100
return iter ([])
110
- return self ._select_from (parent_path , is_dir , exists , scandir )
101
+ return self ._select_from (parent_path , scandir )
111
102
112
103
113
104
class _TerminatingSelector :
114
105
115
- def _select_from (self , parent_path , is_dir , exists , scandir ):
106
+ def _select_from (self , parent_path , scandir ):
116
107
yield parent_path
117
108
118
109
119
110
class _ParentSelector (_Selector ):
120
111
def __init__ (self , name , child_parts , flavour ):
121
112
_Selector .__init__ (self , child_parts , flavour )
122
113
123
- def _select_from (self , parent_path , is_dir , exists , scandir ):
114
+ def _select_from (self , parent_path , scandir ):
124
115
path = parent_path ._make_child_relpath ('..' )
125
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
116
+ for p in self .successor ._select_from (path , scandir ):
126
117
yield p
127
118
128
119
129
- class _PreciseSelector (_Selector ):
130
-
131
- def __init__ (self , name , child_parts , flavour ):
132
- self .name = name
133
- _Selector .__init__ (self , child_parts , flavour )
134
-
135
- def _select_from (self , parent_path , is_dir , exists , scandir ):
136
- try :
137
- path = parent_path ._make_child_relpath (self .name )
138
- follow = is_dir (path ) if self .dironly else exists (path , follow_symlinks = False )
139
- if follow :
140
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
141
- yield p
142
- except PermissionError :
143
- return
144
-
145
-
146
120
class _WildcardSelector (_Selector ):
147
121
148
122
def __init__ (self , pat , child_parts , flavour ):
149
123
flags = re .NOFLAG if _is_case_sensitive (flavour ) else re .IGNORECASE
150
124
self .match = re .compile (fnmatch .translate (pat ), flags = flags ).fullmatch
151
125
_Selector .__init__ (self , child_parts , flavour )
152
126
153
- def _select_from (self , parent_path , is_dir , exists , scandir ):
127
+ def _select_from (self , parent_path , scandir ):
154
128
try :
155
129
# We must close the scandir() object before proceeding to
156
130
# avoid exhausting file descriptors when globbing deep trees.
@@ -171,7 +145,7 @@ def _select_from(self, parent_path, is_dir, exists, scandir):
171
145
name = entry .name
172
146
if self .match (name ):
173
147
path = parent_path ._make_child_relpath (name )
174
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
148
+ for p in self .successor ._select_from (path , scandir ):
175
149
yield p
176
150
except PermissionError :
177
151
return
@@ -182,7 +156,7 @@ class _RecursiveWildcardSelector(_Selector):
182
156
def __init__ (self , pat , child_parts , flavour ):
183
157
_Selector .__init__ (self , child_parts , flavour )
184
158
185
- def _iterate_directories (self , parent_path , is_dir , scandir ):
159
+ def _iterate_directories (self , parent_path , scandir ):
186
160
yield parent_path
187
161
try :
188
162
# We must close the scandir() object before proceeding to
@@ -198,18 +172,18 @@ def _iterate_directories(self, parent_path, is_dir, scandir):
198
172
raise
199
173
if entry_is_dir and not entry .is_symlink ():
200
174
path = parent_path ._make_child_relpath (entry .name )
201
- for p in self ._iterate_directories (path , is_dir , scandir ):
175
+ for p in self ._iterate_directories (path , scandir ):
202
176
yield p
203
177
except PermissionError :
204
178
return
205
179
206
- def _select_from (self , parent_path , is_dir , exists , scandir ):
180
+ def _select_from (self , parent_path , scandir ):
207
181
try :
208
182
yielded = set ()
209
183
try :
210
184
successor_select = self .successor ._select_from
211
- for starting_point in self ._iterate_directories (parent_path , is_dir , scandir ):
212
- for p in successor_select (starting_point , is_dir , exists , scandir ):
185
+ for starting_point in self ._iterate_directories (parent_path , scandir ):
186
+ for p in successor_select (starting_point , scandir ):
213
187
if p not in yielded :
214
188
yield p
215
189
yielded .add (p )
0 commit comments