Patch #1001604: glob.glob() now returns unicode filenames if it was

given a unicode argument and os.listdir() returns unicode filenames.
 (backport from rev. 54197)
This commit is contained in:
Georg Brandl 2007-03-07 08:32:24 +00:00
parent fd13ef9c9c
commit 84a0b8d4b6
3 changed files with 20 additions and 4 deletions

View file

@ -1,8 +1,9 @@
"""Filename globbing utility."""
import sys
import os
import fnmatch
import re
import fnmatch
__all__ = ["glob", "iglob"]
@ -48,13 +49,15 @@ def iglob(pathname):
def glob1(dirname, pattern):
if not dirname:
dirname = os.curdir
if isinstance(pattern, unicode) and not isinstance(dirname, unicode):
dirname = unicode(dirname, sys.getfilesystemencoding())
try:
names = os.listdir(dirname)
except os.error:
return []
if pattern[0]!='.':
names=filter(lambda x: x[0]!='.',names)
return fnmatch.filter(names,pattern)
if pattern[0] != '.':
names = filter(lambda x: x[0] != '.', names)
return fnmatch.filter(names, pattern)
def glob0(dirname, basename):
if basename == '':