Deprecate scrapy.python.utils.FixedSGMLParser

SGML link extractor that uses it is also going to be deprecated;
sgmllib module is not available in Python 3.
This commit is contained in:
Mikhail Korobov 2014-07-02 22:48:16 +06:00
parent e87dc37741
commit 2b749668ba
1 changed files with 30 additions and 13 deletions

View File

@ -10,23 +10,40 @@ import re
import inspect
import weakref
import errno
import warnings
from functools import partial, wraps
from sgmllib import SGMLParser
import six
from scrapy.exceptions import ScrapyDeprecationWarning
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"""
if six.PY2:
from sgmllib import SGMLParser
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)
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.
"""
def __init__(self, *args, **kwargs):
warnings.warn(
"FixedSGMLParser is deprecated and will be removed in future releases.",
ScrapyDeprecationWarning
)
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):