[Patches] [ python-Patches-943206 ] Convert glob.glob to generator-based DFS

SourceForge.net noreply at sourceforge.net
Sat Jan 8 14:13:50 CET 2005


Patches item #943206, was opened at 2004-04-27 20:25
Message generated for change (Comment added) made by jlgijsbers
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=943206&group_id=5470

Category: Library (Lib)
Group: Python 2.4
>Status: Closed
>Resolution: Accepted
Priority: 6
Submitted By: Cherniavsky Beni (cben)
Assigned to: Nobody/Anonymous (nobody)
Summary: Convert glob.glob to generator-based DFS

Initial Comment:
`glob.glob()` currently calls itself recursively to
build a list of matches of the dirname part of the
pattern and then filters by the basename part.  This is
effectively BFS.  ``glob.glob('*/*/*/*/*/foo')`` will
build a huge list of all directories 5 levels deep even
if only a handful of them contain a ``foo`` entry.  A
generator-based recusion would never have to store
these list at once by implementing DFS.
This patch converts the `glob` function to an `iglob`
recursive generator .  `glob()` now just returns
``list(iglob(pattern))``.
I also cleaned up the code a bit (reduced duplicate
`has_magic()` checks and created a second `glob0`
helper func so that the main loop need not be duplicated).

This patch assumes patch 941486 adding
`os.path.lexists()` was applied; if not the lexists
calls will have to be adjasted.

Tests and docs patches included.


----------------------------------------------------------------------

>Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2005-01-08 14:13

Message:
Logged In: YES 
user_id=469548

Checked in on HEAD. Thanks for the patch!

Log message:

Checking in Doc/lib/libglob.tex;
/cvsroot/python/python/dist/src/Doc/lib/libglob.tex,v  <-- 
libglob.tex
new revision: 1.14; previous revision: 1.13
done
Checking in Lib/glob.py;
/cvsroot/python/python/dist/src/Lib/glob.py,v  <--  glob.py
new revision: 1.12; previous revision: 1.11
cvs diff: [13:13:17] waiting for jlgijsbers's lock in
/cvsroot/python/python/dist/src/Doc/lib
done
Checking in Lib/test/test_glob.py;
/cvsroot/python/python/dist/src/Lib/test/test_glob.py,v  <--
 test_glob.py
new revision: 1.9; previous revision: 1.8
done


----------------------------------------------------------------------

Comment By: Cherniavsky Beni (cben)
Date: 2004-08-20 13:25

Message:
Logged In: YES 
user_id=36166

Refreshed against current trunk (2.4a2+ 2004-08-20).
It's a forward patch -p0, at dist/src.  Again, it assumes
patch 941486  (glob-pathfix.diff version) had been applied;
if not s/lexists/exists/g but then neither version of 941486
will apply cleanly.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=943206&group_id=5470


More information about the Patches mailing list