diff --git a/scrapy/utils/python.py b/scrapy/utils/python.py index 566b50f17..db88a4e55 100644 --- a/scrapy/utils/python.py +++ b/scrapy/utils/python.py @@ -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):