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
This commit is contained in:
calvin 2003-01-08 08:47:49 +00:00
parent 291b5a2c9d
commit da86b44f6b
13 changed files with 25 additions and 57 deletions

View file

@ -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

View file

@ -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)))

View file

@ -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:

View file

@ -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)

View file

@ -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

View file

@ -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"\?(.+)$")

View file

@ -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,

View file

@ -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)

View file

@ -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 ():

View file

@ -42,8 +42,7 @@ extensions = {
}
import UrlData
from Config import debug
from debuglevels import *
from debug import *
# main check function
def checkUrls (config):

View file

@ -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

View file

@ -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 = {

View file

@ -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