3 # We cannot use a generator because we rely on the finally block to
4 # be sure _finalize_chdir_browsing will be called. Python 2.5 allows
5 # finally block in generator, but it relies on the GC so it's not sure
6 # it will be called at the right time.
8 # The expected use of these browsing functions is:
10 # previous_cwd = chdir_browsing.init(path)
12 # for child in os.listdir('.'):
13 # .. Do something with child ..
15 # chdir_browsing.finalize(previous_cwd)
18 previous_cwd
= os
.open('.', os
.O_RDONLY
)
23 os
.close(previous_cwd
)
26 def finalize(previous_cwd
):
28 os
.fchdir(previous_cwd
)
30 os
.close(previous_cwd
)