From da86b44f6b18c96449670b5eef805ac56898aab0 Mon Sep 17 00:00:00 2001 From: calvin Date: Wed, 8 Jan 2003 08:47:49 +0000 Subject: [PATCH] added debug.py utils and use it git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@731 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- ChangeLog | 2 ++ linkcheck/Config.py | 15 +-------------- linkcheck/FtpUrlData.py | 4 ++-- linkcheck/HttpUrlData.py | 19 +++++++++---------- linkcheck/HttpsUrlData.py | 3 ++- linkcheck/MailtoUrlData.py | 2 +- linkcheck/NntpUrlData.py | 2 +- linkcheck/TelnetUrlData.py | 3 ++- linkcheck/UrlData.py | 3 +-- linkcheck/__init__.py | 3 +-- linkcheck/debuglevels.py | 19 ------------------- linkcheck/linkparse.py | 3 +-- linkchecker | 4 ++-- 13 files changed, 25 insertions(+), 57 deletions(-) delete mode 100644 linkcheck/debuglevels.py diff --git a/ChangeLog b/ChangeLog index 60561d1d..8accf533 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,8 @@ Changed files: linkcheck/parser/htmllex.l * -a anchor option implies -w because anchor errors are always warnings Changed files: linkchecker + * added AnsiColors.py and debug.py to split out some functions + Changed files: a lot .py files using these things 1.8.2 * - ignore invalid html attribute characters diff --git a/linkcheck/Config.py b/linkcheck/Config.py index 0ff649d7..129298b4 100644 --- a/linkcheck/Config.py +++ b/linkcheck/Config.py @@ -21,7 +21,7 @@ from linkcheck import getLinkPat from os.path import expanduser, normpath, normcase, join, isfile from types import StringType from urllib import getproxies -from debuglevels import * +from debug import * Version = _linkchecker_configdata.version AppName = "LinkChecker" @@ -40,19 +40,6 @@ This is free software, and you are welcome to redistribute it under certain conditions. Look at the file `LICENSE' within this distribution.""" -# debug options -DebugDelim = "==========================================================\n" -DebugLevel = 0 - -# note: debugging with more than 1 thread can be painful -def debug (level, *args): - if DebugLevel >= level: - sys.stderr.write("DEBUG(%d):"%level) - for arg in args: - sys.stderr.write(" %s"%str(arg)) - sys.stderr.write("\n") - sys.stderr.flush() - # path util function def norm (path): return normcase(normpath(expanduser(path))) diff --git a/linkcheck/FtpUrlData.py b/linkcheck/FtpUrlData.py index 43828ece..fef9fe9e 100644 --- a/linkcheck/FtpUrlData.py +++ b/linkcheck/FtpUrlData.py @@ -16,7 +16,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import ftplib, i18n -from linkcheck import Config, error, extensions +from linkcheck import Config, error, extensions, debug from urllib import splitpasswd from ProxyUrlData import ProxyUrlData from HttpUrlData import HttpUrlData @@ -82,7 +82,7 @@ class FtpUrlData (ProxyUrlData): # ready to connect try: self.urlConnection = ftplib.FTP() - self.urlConnection.set_debuglevel(Config.DebugLevel) + self.urlConnection.set_debuglevel(debug.DebugLevel) self.urlConnection.connect(self.urlparts[1]) self.urlConnection.login(_user, _password) except EOFError: diff --git a/linkcheck/HttpUrlData.py b/linkcheck/HttpUrlData.py index 98f65f43..b3cecffc 100644 --- a/linkcheck/HttpUrlData.py +++ b/linkcheck/HttpUrlData.py @@ -17,11 +17,11 @@ import urlparse, urllib, sys, time, re, httplib, robotparser import Config, StringUtil, i18n +from debug import * # XXX not dynamic -if Config.DebugLevel > 0: +if DebugLevel > 0: robotparser.debug = 1 from ProxyUrlData import ProxyUrlData -from debuglevels import * _supported_encodings = ('gzip', 'x-gzip', 'deflate') @@ -95,7 +95,7 @@ class HttpUrlData (ProxyUrlData): # first try response = self._getHttpResponse() self.headers = response.msg - Config.debug(BRING_IT_ON, response.status, response.reason, self.headers) + debug(BRING_IT_ON, response.status, response.reason, self.headers) has301status = 0 while 1: # proxy enforcement (overrides standard proxy) @@ -118,7 +118,7 @@ class HttpUrlData (ProxyUrlData): self.urlparts = urlparse.urlsplit(redirected) response = self._getHttpResponse() self.headers = response.msg - Config.debug(BRING_IT_ON, "Redirected", self.headers) + debug(BRING_IT_ON, "Redirected", self.headers) tries += 1 if tries >= 5: self.setError(i18n._("too much redirections (>= 5)")) @@ -132,8 +132,7 @@ class HttpUrlData (ProxyUrlData): base64.encodestring("%s:%s" % (_user, _password)) response = self._getHttpResponse() self.headers = response.msg - Config.debug(BRING_IT_ON, "Authentication", _user, "/", - _password) + debug(BRING_IT_ON, "Authentication", _user, "/", _password) # some servers get the HEAD request wrong: # - Netscape Enterprise Server (no HEAD implemented, 404 error) # - Hyperwave Information Server (501 error) @@ -208,7 +207,7 @@ class HttpUrlData (ProxyUrlData): host = self.proxy else: host = self.urlparts[1] - Config.debug(HURT_ME_PLENTY, "host", host) + debug(HURT_ME_PLENTY, "host", host) if self.urlConnection: self.closeConnection() self.urlConnection = self._getHTTPObject(host) @@ -242,7 +241,7 @@ class HttpUrlData (ProxyUrlData): def _getHTTPObject (self, host): h = httplib.HTTPConnection(host) - h.set_debuglevel(Config.DebugLevel) + h.set_debuglevel(DebugLevel) h.connect() return h @@ -282,8 +281,8 @@ class HttpUrlData (ProxyUrlData): def robotsTxtAllowsUrl (self): roboturl = self.urlparts[0]+"://"+self.urlparts[1]+"/robots.txt" - Config.debug(HURT_ME_PLENTY, "robots.txt url", roboturl) - Config.debug(HURT_ME_PLENTY, "url", self.url) + debug(HURT_ME_PLENTY, "robots.txt url", roboturl) + debug(HURT_ME_PLENTY, "url", self.url) if not self.config.robotsTxtCache_has_key(roboturl): rp = robotparser.RobotFileParser() rp.set_url(roboturl) diff --git a/linkcheck/HttpsUrlData.py b/linkcheck/HttpsUrlData.py index 2f39494a..d0a50528 100644 --- a/linkcheck/HttpsUrlData.py +++ b/linkcheck/HttpsUrlData.py @@ -18,6 +18,7 @@ import Config, httplib, i18n from UrlData import UrlData from HttpUrlData import HttpUrlData +from linkcheck.debug import * _supportHttps = hasattr(httplib, "HTTPSConnection") @@ -26,7 +27,7 @@ class HttpsUrlData (HttpUrlData): def _getHTTPObject (self, host): h = httplib.HTTPSConnection(host) - h.set_debuglevel(Config.DebugLevel) + h.set_debuglevel(DebugLevel) h.connect() return h diff --git a/linkcheck/MailtoUrlData.py b/linkcheck/MailtoUrlData.py index 7a66d3c0..0d4e13c5 100644 --- a/linkcheck/MailtoUrlData.py +++ b/linkcheck/MailtoUrlData.py @@ -21,7 +21,7 @@ from linkcheck.DNS import mxlookup from rfc822 import AddressList from HostCheckingUrlData import HostCheckingUrlData from smtplib import SMTP -from debuglevels import * +from debug import * # regular expression for RFC2368 compliant mailto: scanning headers_re = re.compile(r"\?(.+)$") diff --git a/linkcheck/NntpUrlData.py b/linkcheck/NntpUrlData.py index d67cae05..1855a7fa 100644 --- a/linkcheck/NntpUrlData.py +++ b/linkcheck/NntpUrlData.py @@ -18,7 +18,7 @@ import re, time, sys, nntplib, urlparse, random, i18n from linkcheck import error, Config from UrlData import ExcList,UrlData -from debuglevels import * +from debug import * random.seed() ExcList.extend([nntplib.error_reply, diff --git a/linkcheck/TelnetUrlData.py b/linkcheck/TelnetUrlData.py index 4a61a425..16b62a2f 100644 --- a/linkcheck/TelnetUrlData.py +++ b/linkcheck/TelnetUrlData.py @@ -17,6 +17,7 @@ import telnetlib, urlparse from linkcheck import Config, error, i18n +from debug import * from urllib import splituser, splithost, splitport, splitpasswd from HostCheckingUrlData import HostCheckingUrlData from UrlData import is_valid_port @@ -45,7 +46,7 @@ class TelnetUrlData (HostCheckingUrlData): def checkConnection (self): HostCheckingUrlData.checkConnection(self) self.urlConnection = telnetlib.Telnet() - self.urlConnection.set_debuglevel(Config.DebugLevel) + self.urlConnection.set_debuglevel(DebugLevel) self.urlConnection.open(self.host, self.port) if self.user: self.urlConnection.read_until("login: ", 10) diff --git a/linkcheck/UrlData.py b/linkcheck/UrlData.py index 03889cfb..df06ea59 100644 --- a/linkcheck/UrlData.py +++ b/linkcheck/UrlData.py @@ -27,8 +27,7 @@ DNS.DiscoverNameServers() import Config, StringUtil, linkname, test_support, timeoutsocket from linkparse import LinkParser -from debuglevels import * -debug = Config.debug +from debug import * # helper function for internal errors def internal_error (): diff --git a/linkcheck/__init__.py b/linkcheck/__init__.py index 79f76e6f..96faa14d 100644 --- a/linkcheck/__init__.py +++ b/linkcheck/__init__.py @@ -42,8 +42,7 @@ extensions = { } import UrlData -from Config import debug -from debuglevels import * +from debug import * # main check function def checkUrls (config): diff --git a/linkcheck/debuglevels.py b/linkcheck/debuglevels.py deleted file mode 100644 index 04145b5b..00000000 --- a/linkcheck/debuglevels.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2001 Bastian Kleineidam -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -ALWAYS = 0 -BRING_IT_ON = 1 -HURT_ME_PLENTY = 2 -NIGHTMARE = 3 diff --git a/linkcheck/linkparse.py b/linkcheck/linkparse.py index 3f0b2228..7889fe26 100644 --- a/linkcheck/linkparse.py +++ b/linkcheck/linkparse.py @@ -15,9 +15,8 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import re, StringUtil, linkname -from debuglevels import * +from debug import * from linkcheck.parser.htmllib import HtmlParser -from linkcheck.Config import debug # ripped mainly from HTML::Tagset.pm LinkTags = { diff --git a/linkchecker b/linkchecker index a04eee93..483551db 100755 --- a/linkchecker +++ b/linkchecker @@ -26,9 +26,9 @@ import linkcheck.timeoutsocket # set default 30 seconds timeout linkcheck.timeoutsocket.setDefaultSocketTimeout(30) # import several helper debugging things -from linkcheck.debuglevels import * +from linkcheck.debug import * from linkcheck.log import LoggerKeys -from linkcheck import StringUtil, Config, i18n, debug +from linkcheck import StringUtil, Config, i18n _profile = "linkchecker.prof" # main usage text