[Python-checkins] r54197 - in python/trunk: Lib/glob.py Lib/test/test_glob.py Misc/NEWS
Guido van Rossum
guido at python.org
Tue Mar 20 22:19:06 CET 2007
This seems to have caused a new failure for me:
ERROR: test_glob_literal (__main__.GlobTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "Lib/test/test_glob.py", line 60, in test_glob_literal
u1 = glob.glob(u'*')
File "/usr/local/google/home/guido/python/trunk/Lib/glob.py", line 16, in glob
return list(iglob(pathname))
File "/usr/local/google/home/guido/python/trunk/Lib/glob.py", line
30, in iglob
for name in glob1(os.curdir, basename):
File "/usr/local/google/home/guido/python/trunk/Lib/glob.py", line
53, in glob1
dirname = unicode(dirname, sys.getfilesystemencoding())
TypeError: unicode() argument 2 must be string, not None
On my system (derived from Ubuntu dapper), sys.getfilesystemencoding()
returns None and the new code in glob.py doesn't seem to be prepared
for that.
--Guido
On 3/7/07, georg.brandl <python-checkins at python.org> wrote:
> Author: georg.brandl
> Date: Wed Mar 7 09:31:51 2007
> New Revision: 54197
>
> Modified:
> python/trunk/Lib/glob.py
> python/trunk/Lib/test/test_glob.py
> python/trunk/Misc/NEWS
> Log:
> Patch #1001604: glob.glob() now returns unicode filenames if it was
> given a unicode argument and os.listdir() returns unicode filenames.
>
>
> Modified: python/trunk/Lib/glob.py
> ==============================================================================
> --- python/trunk/Lib/glob.py (original)
> +++ python/trunk/Lib/glob.py Wed Mar 7 09:31:51 2007
> @@ -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 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 == '':
>
> Modified: python/trunk/Lib/test/test_glob.py
> ==============================================================================
> --- python/trunk/Lib/test/test_glob.py (original)
> +++ python/trunk/Lib/test/test_glob.py Wed Mar 7 09:31:51 2007
> @@ -52,6 +52,16 @@
> eq(self.glob('aab'), [self.norm('aab')])
> eq(self.glob('zymurgy'), [])
>
> + # test return types are unicode, but only if os.listdir
> + # returns unicode filenames
> + uniset = set([unicode])
> + tmp = os.listdir(u'.')
> + if set(type(x) for x in tmp) == uniset:
> + u1 = glob.glob(u'*')
> + u2 = glob.glob(u'./*')
> + self.assertEquals(set(type(r) for r in u1), uniset)
> + self.assertEquals(set(type(r) for r in u2), uniset)
> +
> def test_glob_one_directory(self):
> eq = self.assertSequencesEqual_noorder
> eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa']))
>
> Modified: python/trunk/Misc/NEWS
> ==============================================================================
> --- python/trunk/Misc/NEWS (original)
> +++ python/trunk/Misc/NEWS Wed Mar 7 09:31:51 2007
> @@ -152,6 +152,9 @@
> Library
> -------
>
> +- Patch #1001604: glob.glob() now returns unicode filenames if it was
> + given a unicode argument and os.listdir() returns unicode filenames.
> +
> - Patch #1673619: setup.py identifies extension modules it doesn't know how
> to build and those it knows how to build but that fail to build.
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-checkins
mailing list