mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-12 16:43:11 +00:00
Refactor bookmark parsing code into own package.
This commit is contained in:
parent
2dfe62afa2
commit
25b6dc2e57
8 changed files with 62 additions and 20 deletions
3
Makefile
3
Makefile
|
|
@ -120,7 +120,8 @@ check:
|
|||
doccheck:
|
||||
py-check-docstrings --force linkcheck/HtmlParser linkcheck/checker \
|
||||
linkcheck/cache linkcheck/configuration linkcheck/director \
|
||||
linkcheck/htmlutil linkcheck/logger linkcheck/network *.py
|
||||
linkcheck/htmlutil linkcheck/logger linkcheck/network \
|
||||
linkcheck/bookmarks *.py
|
||||
|
||||
filescheck:
|
||||
-./linkchecker $(LCOPTS) http://$(HOST)/
|
||||
|
|
|
|||
16
linkcheck/bookmarks/__init__.py
Normal file
16
linkcheck/bookmarks/__init__.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2011 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.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
35
linkcheck/bookmarks/opera.py
Normal file
35
linkcheck/bookmarks/opera.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2011 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.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
def parse_bookmarks (data):
|
||||
"""Return iterator for bookmarks of the form (url, name, line number).
|
||||
Bookmarks are not sorted.
|
||||
"""
|
||||
name = None
|
||||
lineno = 0
|
||||
for line in data.splitlines():
|
||||
lineno += 1
|
||||
line = line.strip()
|
||||
if line.startswith("NAME="):
|
||||
name = line[5:]
|
||||
elif line.startswith("URL="):
|
||||
url = line[4:]
|
||||
if url and name is not None:
|
||||
yield (url, name, lineno)
|
||||
else:
|
||||
name = None
|
||||
|
|
@ -25,7 +25,8 @@ import urllib
|
|||
import urllib2
|
||||
|
||||
from . import urlbase, get_index_html, get_url_from
|
||||
from .. import log, LOG_CHECK, fileutil, firefox
|
||||
from .. import log, LOG_CHECK, fileutil
|
||||
from ..bookmarks import firefox
|
||||
from .const import WARN_FILE_MISSING_SLASH, WARN_FILE_SYSTEM_PATH
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -924,22 +924,11 @@ class UrlBase (object):
|
|||
def parse_opera (self):
|
||||
"""Parse an opera bookmark file."""
|
||||
log.debug(LOG_CHECK, "Parsing Opera bookmarks %s", self)
|
||||
name = None
|
||||
lineno = 0
|
||||
for line in self.get_content().splitlines():
|
||||
lineno += 1
|
||||
line = line.strip()
|
||||
if line.startswith("NAME="):
|
||||
name = line[5:]
|
||||
elif line.startswith("URL="):
|
||||
url = line[4:]
|
||||
if url and name is not None:
|
||||
url_data = get_url_from(url, self.recursion_level+1,
|
||||
self.aggregate, parent_url=self.url,
|
||||
line=lineno, name=name)
|
||||
self.aggregate.urlqueue.put(url_data)
|
||||
else:
|
||||
name = None
|
||||
from ..bookmarks.opera import parse_bookmarks
|
||||
for url, name, lineno in parse_bookmarks(self.get_content()):
|
||||
url_data = get_url_from(url, self.recursion_level+1,
|
||||
self.aggregate, parent_url=self.url, line=lineno, name=name)
|
||||
self.aggregate.urlqueue.put(url_data)
|
||||
|
||||
def parse_text (self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -63,8 +63,7 @@ class LineEdit (QtGui.QLineEdit):
|
|||
|
||||
def add_firefox (self):
|
||||
"""Copy Firefox bookmark file URL."""
|
||||
from ..firefox import find_bookmark_file
|
||||
from ..bookmarks.firefox import find_bookmark_file
|
||||
fname = find_bookmark_file()
|
||||
if fname:
|
||||
self.setText(fname)
|
||||
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -562,6 +562,7 @@ o a (Fast)CGI web interface (requires HTTP server)
|
|||
'linkcheck.htmlutil', 'linkcheck.dns', 'linkcheck.dns.rdtypes',
|
||||
'linkcheck.dns.rdtypes.ANY', 'linkcheck.dns.rdtypes.IN',
|
||||
'linkcheck.HtmlParser', 'linkcheck.network', 'linkcheck.gui',
|
||||
'linkcheck.bookmarks',
|
||||
],
|
||||
ext_modules = [
|
||||
Extension('linkcheck.HtmlParser.htmlsax',
|
||||
|
|
|
|||
Loading…
Reference in a new issue