@@ -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,54 +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
- if (is_dir if self .dironly else exists )(path ):
139
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
140
- yield p
141
- except PermissionError :
142
- return
143
-
144
-
145
120
class _WildcardSelector (_Selector ):
146
121
147
122
def __init__ (self , pat , child_parts , flavour ):
148
123
flags = re .NOFLAG if _is_case_sensitive (flavour ) else re .IGNORECASE
149
124
self .match = re .compile (fnmatch .translate (pat ), flags = flags ).fullmatch
150
125
_Selector .__init__ (self , child_parts , flavour )
151
126
152
- def _select_from (self , parent_path , is_dir , exists , scandir ):
127
+ def _select_from (self , parent_path , scandir ):
153
128
try :
154
129
# We must close the scandir() object before proceeding to
155
130
# avoid exhausting file descriptors when globbing deep trees.
@@ -170,7 +145,7 @@ def _select_from(self, parent_path, is_dir, exists, scandir):
170
145
name = entry .name
171
146
if self .match (name ):
172
147
path = parent_path ._make_child_relpath (name )
173
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
148
+ for p in self .successor ._select_from (path , scandir ):
174
149
yield p
175
150
except PermissionError :
176
151
return
@@ -181,7 +156,7 @@ class _RecursiveWildcardSelector(_Selector):
181
156
def __init__ (self , pat , child_parts , flavour ):
182
157
_Selector .__init__ (self , child_parts , flavour )
183
158
184
- def _iterate_directories (self , parent_path , is_dir , scandir ):
159
+ def _iterate_directories (self , parent_path , scandir ):
185
160
yield parent_path
186
161
try :
187
162
# We must close the scandir() object before proceeding to
@@ -197,18 +172,18 @@ def _iterate_directories(self, parent_path, is_dir, scandir):
197
172
raise
198
173
if entry_is_dir and not entry .is_symlink ():
199
174
path = parent_path ._make_child_relpath (entry .name )
200
- for p in self ._iterate_directories (path , is_dir , scandir ):
175
+ for p in self ._iterate_directories (path , scandir ):
201
176
yield p
202
177
except PermissionError :
203
178
return
204
179
205
- def _select_from (self , parent_path , is_dir , exists , scandir ):
180
+ def _select_from (self , parent_path , scandir ):
206
181
try :
207
182
yielded = set ()
208
183
try :
209
184
successor_select = self .successor ._select_from
210
- for starting_point in self ._iterate_directories (parent_path , is_dir , scandir ):
211
- 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 ):
212
187
if p not in yielded :
213
188
yield p
214
189
yielded .add (p )
0 commit comments