From a9335fb3e80e7579370ef3ef545d410d33ff6f5a Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Mon, 2 Mar 2009 08:02:27 +0100 Subject: [PATCH] Make file list an iterator, and add missing slash if needed to manually given file URLs. --- linkcheck/checker/__init__.py | 5 ++--- linkcheck/checker/fileurl.py | 18 +++++++++--------- tests/checker/data/dir.result | 3 +-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/linkcheck/checker/__init__.py b/linkcheck/checker/__init__.py index d52f0256..256a6067 100644 --- a/linkcheck/checker/__init__.py +++ b/linkcheck/checker/__init__.py @@ -115,8 +115,8 @@ def get_index_html (urls): """ Construct artificial index.html from given URLs. - @param urls: list with url strings - @type urls: list of string + @param urls: URL strings + @type urls: iterator of string """ lines = ["", ""] for entry in urls: @@ -127,7 +127,6 @@ def get_index_html (urls): return os.linesep.join(lines) - class StoringHandler (logging.Handler): """Store all emitted log messages in a size-limited list. Used by the CSS syntax checker.""" diff --git a/linkcheck/checker/fileurl.py b/linkcheck/checker/fileurl.py index 5cb3d09f..fa7b6f03 100644 --- a/linkcheck/checker/fileurl.py +++ b/linkcheck/checker/fileurl.py @@ -36,18 +36,16 @@ except ImportError: has_sqlite = False def get_files (dirname): - """ - Get lists of files in directory. Does only allow regular files - and directories, no symlinks. - """ - files = [] + """Get iterator of entries in directory. Only allows regular files + and directories, no symlinks.""" for entry in os.listdir(dirname): fullentry = os.path.join(dirname, entry) - if os.path.islink(fullentry) or \ - not (os.path.isfile(fullentry) or os.path.isdir(fullentry)): + if os.path.islink(fullentry): continue - files.append(entry) - return files + if os.path.isfile(fullentry): + yield entry + elif os.path.isdir(fullentry): + yield entry+"/" def prepare_urlpath_for_nt (path): @@ -107,6 +105,8 @@ class FileUrl (urlbase.UrlBase): base_url = os.path.expanduser(base_url) if not is_absolute_path(base_url): base_url = os.getcwd()+"/"+base_url + if os.path.isdir(base_url): + base_url += "/" base_url = "file://"+base_url if os.name == "nt": base_url = base_url.replace("\\", "/") diff --git a/tests/checker/data/dir.result b/tests/checker/data/dir.result index 6d686611..f7331643 100644 --- a/tests/checker/data/dir.result +++ b/tests/checker/data/dir.result @@ -1,8 +1,7 @@ -url file://%(curdir)s/%(datadir)s/dir +url file://%(curdir)s/%(datadir)s/dir/ cache key file://%(curdir)s/%(datadir)s/dir/ real url file://%(curdir)s/%(datadir)s/dir/ name %(datadir)s/dir -warning Added trailing slash to directory. valid url %%ED%%BB%%AD%%AF%%BF.dat