From 1d1fc45c6eac61832f036bb1ed6e8f61f97b450e Mon Sep 17 00:00:00 2001 From: Alex Koval Date: Sat, 2 Dec 2017 16:46:05 +0200 Subject: [PATCH] Fixes for new Sphinx formatting (for example latest Django docs) Also removed python3 initial support idea - this HTMLParser instance will never by supported by Python3 (see https://www.python.org/dev/peps/pep-3108/) - if someone needs compatible module lets use html.parser --- pylookup.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/pylookup.py b/pylookup.py index dc122c1..babb19b 100755 --- a/pylookup.py +++ b/pylookup.py @@ -25,12 +25,7 @@ from os.path import join, dirname, exists, abspath, expanduser from contextlib import closing -if sys.version_info[0] == 3: - import html.parser as htmllib - import urllib.parse as urlparse - import urllib.request as urllib -else: - import htmllib, urllib, urlparse +import htmllib, urllib, urlparse VERBOSE = False FORMATS = { @@ -141,16 +136,29 @@ def __init__( self, writer, dirn): def start_dd( self, att ): self.list_entry = True + def start_ul( self, att ): + self.list_entry = True + def end_dd( self ): self.list_entry = False + def end_ul( self ): + self.list_entry = False + def start_dt( self, att ): self.one_entry = True self.num_of_a = 0 + def start_li( self, att ): + self.one_entry = True + self.num_of_a = 0 + def end_dt( self ): self.do_entry = False + def end_li( self ): + self.do_entry = False + def start_a( self, att ): if self.one_entry: self.url = join( self.dirn, dict( att )[ 'href' ] ) @@ -224,8 +232,8 @@ def update(db, urls, append=False): success = False for index_url in potential_urls: try: - print "Wait for a few seconds..." - print "Fetching index from '%s'" % index_url + print("Wait for a few seconds...") + print("Fetching index from '%s'" % index_url) index = urllib.urlopen(index_url).read() if not issubclass(type(index), str): @@ -236,14 +244,14 @@ def update(db, urls, append=False): parser.feed(index) # success, we don't need to try other potential urls - print "Loaded index from '%s'" % index_url + print("Loaded index from '%s'" % index_url) success = True break except IOError: - print "Error: fetching file from '%s'" % index_url + print("Error: fetching file from '%s'" % index_url) if not success: - print "Failed to load index for input '%s'" % url + print("Failed to load index for input '%s'" % url) def lookup(db, key, format_spec, out=sys.stdout, insensitive=True, desc=True):