@@ -59,6 +59,9 @@ def _is_wildcard_pattern(pat):
59
59
# be looked up directly as a file.
60
60
return "*" in pat or "?" in pat or "[" in pat
61
61
62
+ def _is_case_sensitive (flavour ):
63
+ return flavour .normcase ('Aa' ) == 'Aa'
64
+
62
65
#
63
66
# Globbing helpers
64
67
#
@@ -102,25 +105,24 @@ def select_from(self, parent_path):
102
105
is_dir = path_cls .is_dir
103
106
exists = path_cls .exists
104
107
scandir = path_cls ._scandir
105
- normcase = path_cls ._flavour .normcase
106
108
if not is_dir (parent_path ):
107
109
return iter ([])
108
- return self ._select_from (parent_path , is_dir , exists , scandir , normcase )
110
+ return self ._select_from (parent_path , is_dir , exists , scandir )
109
111
110
112
111
113
class _TerminatingSelector :
112
114
113
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
115
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
114
116
yield parent_path
115
117
116
118
117
119
class _ParentSelector (_Selector ):
118
120
def __init__ (self , name , child_parts , case_sensitive ):
119
121
_Selector .__init__ (self , child_parts , case_sensitive )
120
122
121
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
123
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
122
124
path = parent_path ._make_child_relpath ('..' )
123
- for p in self .successor ._select_from (path , is_dir , exists , scandir , normcase ):
125
+ for p in self .successor ._select_from (path , is_dir , exists , scandir ):
124
126
yield p
125
127
126
128
@@ -130,11 +132,11 @@ def __init__(self, name, child_parts, flavour):
130
132
self .name = name
131
133
_Selector .__init__ (self , child_parts , flavour )
132
134
133
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
135
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
134
136
try :
135
137
path = parent_path ._make_child_relpath (self .name )
136
138
if (is_dir if self .dironly else exists )(path ):
137
- for p in self .successor ._select_from (path , is_dir , exists , scandir , normcase ):
139
+ for p in self .successor ._select_from (path , is_dir , exists , scandir ):
138
140
yield p
139
141
except PermissionError :
140
142
return
@@ -143,10 +145,11 @@ def _select_from(self, parent_path, is_dir, exists, scandir, normcase):
143
145
class _WildcardSelector (_Selector ):
144
146
145
147
def __init__ (self , pat , child_parts , flavour ):
146
- self .match = re .compile (fnmatch .translate (flavour .normcase (pat ))).fullmatch
148
+ flags = re .NOFLAG if _is_case_sensitive (flavour ) else re .IGNORECASE
149
+ self .match = re .compile (fnmatch .translate (pat ), flags = flags ).fullmatch
147
150
_Selector .__init__ (self , child_parts , flavour )
148
151
149
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
152
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
150
153
try :
151
154
# We must close the scandir() object before proceeding to
152
155
# avoid exhausting file descriptors when globbing deep trees.
@@ -165,9 +168,9 @@ def _select_from(self, parent_path, is_dir, exists, scandir, normcase):
165
168
raise
166
169
continue
167
170
name = entry .name
168
- if self .match (normcase ( name ) ):
171
+ if self .match (name ):
169
172
path = parent_path ._make_child_relpath (name )
170
- for p in self .successor ._select_from (path , is_dir , exists , scandir , normcase ):
173
+ for p in self .successor ._select_from (path , is_dir , exists , scandir ):
171
174
yield p
172
175
except PermissionError :
173
176
return
@@ -199,13 +202,13 @@ def _iterate_directories(self, parent_path, is_dir, scandir):
199
202
except PermissionError :
200
203
return
201
204
202
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
205
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
203
206
try :
204
207
yielded = set ()
205
208
try :
206
209
successor_select = self .successor ._select_from
207
210
for starting_point in self ._iterate_directories (parent_path , is_dir , scandir ):
208
- for p in successor_select (starting_point , is_dir , exists , scandir , normcase ):
211
+ for p in successor_select (starting_point , is_dir , exists , scandir ):
209
212
if p not in yielded :
210
213
yield p
211
214
yielded .add (p )
0 commit comments