Staging
v0.8.1
Revision 5d0fdbc690744dd48a9476d1b362b2bbcf773e88 authored by Anthony Baxter on 01 November 2001, 13:58:16 UTC, committed by Anthony Baxter on 01 November 2001, 13:58:16 UTC
  Use PySocket_Err() instead of PyErr_SetFromErrno().
  The former does the right thing on Windows, the latter does not.

The 'partial' is because the code's changed quite a lot and it's not clear
that the two that are still there of the form
                return PyErr_SetFromErrno(SSLErrorObject);
can be replaced with PySocket_Err() - it looks like they need the new
PySSL_SetError, which is a tad large to be comfortable with just checking
in without reading it further.
1 parent 22a2ce8
Raw File
dircache.py
"""Read and cache directory listings.

The listdir() routine returns a sorted list of the files in a directory,
using a cache to avoid reading the directory more often than necessary.
The annotate() routine appends slashes to directories."""

import os

__all__ = ["listdir", "opendir", "annotate", "reset"]

cache = {}

def reset():
    """Reset the cache completely."""
    global cache
    cache = {}

def listdir(path):
    """List directory contents, using cache."""
    try:
        cached_mtime, list = cache[path]
        del cache[path]
    except KeyError:
        cached_mtime, list = -1, []
    try:
        mtime = os.stat(path)[8]
    except os.error:
        return []
    if mtime != cached_mtime:
        try:
            list = os.listdir(path)
        except os.error:
            return []
        list.sort()
    cache[path] = mtime, list
    return list

opendir = listdir # XXX backward compatibility

def annotate(head, list):
    """Add '/' suffixes to directories."""
    for i in range(len(list)):
        if os.path.isdir(os.path.join(head, list[i])):
            list[i] = list[i] + '/'
back to top