mirror of https://github.com/scrapy/scrapy.git
FixedSGMLParser is useless.
This commit is contained in:
parent
00cd4f0fa5
commit
7316a37635
|
|
@ -3,18 +3,19 @@ SGMLParser-based Link extractors
|
|||
"""
|
||||
from urlparse import urljoin
|
||||
import warnings
|
||||
from sgmllib import SGMLParser
|
||||
|
||||
from w3lib.url import safe_url_string
|
||||
from scrapy.selector import Selector
|
||||
from scrapy.link import Link
|
||||
from scrapy.linkextractor import FilteringLinkExtractor
|
||||
from scrapy.utils.misc import arg_to_iter
|
||||
from scrapy.utils.python import FixedSGMLParser, unique as unique_list, str_to_unicode
|
||||
from scrapy.utils.python import unique as unique_list, str_to_unicode
|
||||
from scrapy.utils.response import get_base_url
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
|
||||
|
||||
class BaseSgmlLinkExtractor(FixedSGMLParser):
|
||||
class BaseSgmlLinkExtractor(SGMLParser):
|
||||
|
||||
def __init__(self, tag="a", attr="href", unique=False, process_value=None):
|
||||
warnings.warn(
|
||||
|
|
@ -22,8 +23,7 @@ class BaseSgmlLinkExtractor(FixedSGMLParser):
|
|||
"Please use scrapy.contrib.linkextractors.LinkExtractor",
|
||||
ScrapyDeprecationWarning
|
||||
)
|
||||
with warnings.catch_warnings(record=True):
|
||||
FixedSGMLParser.__init__(self)
|
||||
SGMLParser.__init__(self)
|
||||
self.scan_tag = tag if callable(tag) else lambda t: t == tag
|
||||
self.scan_attr = attr if callable(attr) else lambda a: a == attr
|
||||
self.process_value = (lambda v: v) if process_value is None else process_value
|
||||
|
|
@ -64,7 +64,7 @@ class BaseSgmlLinkExtractor(FixedSGMLParser):
|
|||
return links
|
||||
|
||||
def reset(self):
|
||||
FixedSGMLParser.reset(self)
|
||||
SGMLParser.reset(self)
|
||||
self.links = []
|
||||
self.base_url = None
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@ if six.PY2:
|
|||
from sgmllib import SGMLParser
|
||||
|
||||
class FixedSGMLParser(SGMLParser):
|
||||
"""The SGMLParser that comes with Python has a bug in the convert_charref()
|
||||
method. This is the same class with the bug fixed.
|
||||
|
||||
Warning: this class is deprecated and will be removed in future releases.
|
||||
"""
|
||||
|
||||
Warning: this class is deprecated and will be removed in future
|
||||
releases. Please use standard `sgmllib.SGMLParser`.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn(
|
||||
"FixedSGMLParser is deprecated and will be removed in future releases.",
|
||||
|
|
@ -35,16 +33,6 @@ if six.PY2:
|
|||
)
|
||||
SGMLParser.__init__(self, *args, **kwargs)
|
||||
|
||||
def convert_charref(self, name):
|
||||
"""This method fixes a bug in Python's SGMLParser."""
|
||||
try:
|
||||
n = int(name)
|
||||
except ValueError:
|
||||
return
|
||||
if not 0 <= n <= 127 : # ASCII ends at 127, not 255
|
||||
return
|
||||
return self.convert_codepoint(n)
|
||||
|
||||
|
||||
def flatten(x):
|
||||
"""flatten(sequence) -> list
|
||||
|
|
|
|||
Loading…
Reference in New Issue