mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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:
parent
fd13ef9c9c
commit
84a0b8d4b6
3 changed files with 20 additions and 4 deletions
11
Lib/glob.py
11
Lib/glob.py
|
|
@ -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 == '':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue