mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-16 22:10:26 +00:00
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@5 e7d03fd6-7b0d-0410-9947-9c21f3af8025
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
import re,string,os,urlparse
|
|
from UrlData import UrlData
|
|
from os.path import normpath
|
|
|
|
class FileUrlData(UrlData):
|
|
"Url link with file scheme"
|
|
|
|
def __init__(self,
|
|
urlName,
|
|
recursionLevel,
|
|
parentName = None,
|
|
baseRef = None, line=0, _time=0):
|
|
UrlData.__init__(self,
|
|
urlName,
|
|
recursionLevel,
|
|
parentName,
|
|
baseRef, line, _time)
|
|
if not parentName and not baseRef and \
|
|
not re.compile("^file:").search(self.urlName):
|
|
winre = re.compile("^[a-zA-Z]:")
|
|
if winre.search(self.urlName):
|
|
self.adjustWindozePath()
|
|
else:
|
|
if self.urlName[0:1] != "/":
|
|
self.urlName = os.getcwd()+"/"+self.urlName
|
|
if winre.search(self.urlName):
|
|
self.adjustWindozePath()
|
|
self.urlName = "file://"+normpath(self.urlName)
|
|
|
|
|
|
def buildUrl(self):
|
|
UrlData.buildUrl(self)
|
|
# cut off parameter, query and fragment
|
|
self.url = urlparse.urlunparse(self.urlTuple[:3] + ('','',''))
|
|
|
|
|
|
def adjustWindozePath(self):
|
|
"c:\\windows ==> /c|\\windows"
|
|
self.urlName = "/"+self.urlName[0]+"|"+self.urlName[2:]
|
|
|
|
|
|
def isHtml(self):
|
|
return self.valid and re.compile("\.s?html?$").search(self.url)
|
|
|
|
|
|
def __str__(self):
|
|
return "File link\n"+UrlData.__str__(self)
|
|
|