@@ -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
#
@@ -100,15 +103,14 @@ def select_from(self, parent_path):
100
103
is_dir = path_cls .is_dir
101
104
exists = path_cls .exists
102
105
scandir = path_cls ._scandir
103
- normcase = path_cls ._flavour .normcase
104
106
if not is_dir (parent_path ):
105
107
return iter ([])
106
- return self ._select_from (parent_path , is_dir , exists , scandir , normcase )
108
+ return self ._select_from (parent_path , is_dir , exists , scandir )
107
109
108
110
109
111
class _TerminatingSelector :
110
112
111
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
113
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
112
114
yield parent_path
113
115
114
116
@@ -118,11 +120,11 @@ def __init__(self, name, child_parts, flavour):
118
120
self .name = name
119
121
_Selector .__init__ (self , child_parts , flavour )
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
try :
123
125
path = parent_path ._make_child_relpath (self .name )
124
126
if (is_dir if self .dironly else exists )(path ):
125
- for p in self .successor ._select_from (path , is_dir , exists , scandir , normcase ):
127
+ for p in self .successor ._select_from (path , is_dir , exists , scandir ):
126
128
yield p
127
129
except PermissionError :
128
130
return
@@ -131,10 +133,11 @@ def _select_from(self, parent_path, is_dir, exists, scandir, normcase):
131
133
class _WildcardSelector (_Selector ):
132
134
133
135
def __init__ (self , pat , child_parts , flavour ):
134
- self .match = re .compile (fnmatch .translate (flavour .normcase (pat ))).fullmatch
136
+ flags = re .NOFLAG if _is_case_sensitive (flavour ) else re .IGNORECASE
137
+ self .match = re .compile (fnmatch .translate (pat ), flags = flags ).fullmatch
135
138
_Selector .__init__ (self , child_parts , flavour )
136
139
137
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
140
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
138
141
try :
139
142
# We must close the scandir() object before proceeding to
140
143
# avoid exhausting file descriptors when globbing deep trees.
@@ -153,9 +156,9 @@ def _select_from(self, parent_path, is_dir, exists, scandir, normcase):
153
156
raise
154
157
continue
155
158
name = entry .name
156
- if self .match (normcase ( name ) ):
159
+ if self .match (name ):
157
160
path = parent_path ._make_child_relpath (name )
158
- for p in self .successor ._select_from (path , is_dir , exists , scandir , normcase ):
161
+ for p in self .successor ._select_from (path , is_dir , exists , scandir ):
159
162
yield p
160
163
except PermissionError :
161
164
return
@@ -187,13 +190,13 @@ def _iterate_directories(self, parent_path, is_dir, scandir):
187
190
except PermissionError :
188
191
return
189
192
190
- def _select_from (self , parent_path , is_dir , exists , scandir , normcase ):
193
+ def _select_from (self , parent_path , is_dir , exists , scandir ):
191
194
try :
192
195
yielded = set ()
193
196
try :
194
197
successor_select = self .successor ._select_from
195
198
for starting_point in self ._iterate_directories (parent_path , is_dir , scandir ):
196
- for p in successor_select (starting_point , is_dir , exists , scandir , normcase ):
199
+ for p in successor_select (starting_point , is_dir , exists , scandir ):
197
200
if p not in yielded :
198
201
yield p
199
202
yielded .add (p )
0 commit comments