-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
glob doesn't return unicode with no dir in unicode filename #40668
Comments
#Here is the script
#Python 2.3 on W2K
import glob
name = glob.glob(u"./*.mp3")[0]
print type(name)
name = glob.glob(u"*.mp3")[0]
print type(name)
##OUTPUT##
#<type 'unicode'>
#<type 'str'>
#The second line should be <type 'unicode'> too. |
Logged In: YES The attached patch fixes the problem and all tests pass on Changing to a patch. |
Logged In: YES I wrote a slightly different patch that converts the >>> glob.glob("*")
['a.bat', 'abc', 'ascii', 'b.bat', 'fileobject.c',
'fileobject.c.diff', 'Gr\xfc\xdf-Gott', 'pep-0277.txt',
'posixmodule.c', 'posixmodule.c.diff', 'uni.py',
'winunichanges.zip', 'Ge??-sa?', '????????????', '??????',
'???', '????G\xdf', '???']
>>> glob.glob(u"*")
[u'a.bat', u'abc', u'ascii', u'b.bat', u'fileobject.c',
u'fileobject.c.diff', u'Gr\xfc\xdf-Gott', u'pep-0277.txt',
u'posixmodule.c', u'posixmodule.c.diff', u'uni.py',
u'winunichanges.zip',
u'\u0393\u03b5\u03b9\u03ac-\u03c3\u03b1\u03c2',
u'\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435',
u'\u05d4\u05e9\u05e7\u05e6\u05e5\u05e1',
u'\u306b\u307d\u3093',
u'\u66e8\u05e9\u3093\u0434\u0393\xdf', u'\u66e8\u66e9\u66eb'] Here is my patch if you are interested: --- glob.py Wed Jun 06 06:24:38 2001
+++ g:\Python23\Lib\glob.py Sun Aug 01 23:50:43 2004
@@ -19,7 +19,10 @@
return []
dirname, basename = os.path.split(pathname)
if not dirname:
- return glob1(os.curdir, basename)
+ # Use the current directory but match the argument
+ # string form, either unicode or string.
+ dirname = type(dirname)(os.curdir)
+ return glob1(dirname, basename)
elif has_magic(dirname):
list = glob(dirname)
else:
@@ -40,7 +43,7 @@
return result
def glob1(dirname, pattern):
- if not dirname: dirname = os.curdir
+ assert dirname
try:
names = os.listdir(dirname)
except os.error: |
Logged In: YES The patch in itself is fine - it is policy that file name The test is flawed, though: there is no guarantee that the Also, there is currently no guarantee that a) drop the test checking for equality |
Shouldn't the conversion to Unicode use the filesystem encoding? |
gbrandl: you are right, it should. |
Committed corrected patch as rev. 54197, 54198 (2.5). |
2.5.1 (r251:54863, Jul 10 2008, 17:24:48) Fails for me with 2.5.1 on Linux, OS X, and Windows. >>> glob.glob("*")
['t.txt', 't\xd0\xb4.txt', 't\xe2\xbd\x94.txt']
>>> glob.glob(u"*")
['t.txt', 't\xd0\xb4.txt', 't\xe2\xbd\x94.txt']
>>> glob.glob(u"./*")
[u'./t.txt', u'./t\u0434.txt', u'./t\u2f54.txt'] |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: