diff --git a/linkcheck/fileutil.py b/linkcheck/fileutil.py index ec27c454..234385a1 100644 --- a/linkcheck/fileutil.py +++ b/linkcheck/fileutil.py @@ -20,7 +20,6 @@ File and path utilities. import os import locale import stat -import fnmatch import tempfile import importlib from distutils.spawn import find_executable @@ -44,71 +43,6 @@ def has_module(name, without_error=True): return not without_error -class GlobDirectoryWalker: - """A forward iterator that traverses a directory tree.""" - - def __init__(self, directory, pattern="*"): - """Set start directory and pattern matcher.""" - self.stack = [directory] - self.pattern = pattern - self.files = [] - self.index = 0 - - def __getitem__(self, index): - """Search for next filename.""" - while True: - try: - filename = self.files[self.index] - self.index += 1 - except IndexError: - # Pop next directory from stack. This effectively - # stops the iteration if stack is empty. - self.directory = self.stack.pop() - self.files = os.listdir(self.directory) - self.index = 0 - else: - # got a filename - fullname = os.path.join(self.directory, filename) - if os.path.isdir(fullname) and not os.path.islink(fullname): - self.stack.append(fullname) - if fnmatch.fnmatch(filename, self.pattern): - return fullname - -# alias -rglob = GlobDirectoryWalker - - -class Buffer: - """Holds buffered data""" - - def __init__(self, empty=''): - """Initialize buffer.""" - self.empty = self.buf = empty - self.tmpbuf = [] - self.pos = 0 - - def __len__(self): - """Buffer length.""" - return self.pos - - def write(self, data): - """Write data to buffer.""" - self.tmpbuf.append(data) - self.pos += len(data) - - def flush(self, overlap=0): - """Flush buffered data and return it.""" - self.buf += self.empty.join(self.tmpbuf) - self.tmpbuf = [] - if overlap and overlap < self.pos: - data = self.buf[:-overlap] - self.buf = self.buf[-overlap:] - else: - data = self.buf - self.buf = self.empty - return data - - def get_mtime(filename): """Return modification time of filename or zero on errors.""" try: @@ -142,19 +76,6 @@ def path_safe(path): return path -# cache for modified check {absolute filename -> mtime} -_mtime_cache = {} -def has_changed(filename): - """Check if filename has changed since the last check. If this - is the first check, assume the file is changed.""" - key = os.path.abspath(filename) - mtime = get_mtime(key) - if key not in _mtime_cache: - _mtime_cache[key] = mtime - return True - return mtime > _mtime_cache[key] - - def get_temp_file(mode='r', **kwargs): """Return tuple (open file object, filename) pointing to a temporary file.""" @@ -183,16 +104,3 @@ def is_writable_by_others(filename): """Check if file or directory is world writable.""" mode = os.stat(filename)[stat.ST_MODE] return mode & stat.S_IWOTH - - -@lru_cache(128) -def is_writable(filename): - """Check if - - the file is a regular file and is writable, or - - the file does not exist and its parent directory exists and is - writable - """ - if not os.path.exists(filename): - parentdir = os.path.dirname(filename) - return os.path.isdir(parentdir) and os.access(parentdir, os.W_OK) - return os.path.isfile(filename) and os.access(filename, os.W_OK)