mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix HTMLParser related deprecation warnings in Py3.4
This commit is contained in:
parent
2432a22400
commit
ce8574aff4
2 changed files with 10 additions and 11 deletions
|
|
@ -21,10 +21,7 @@ try:
|
||||||
from html import escape
|
from html import escape
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from cgi import escape
|
from cgi import escape
|
||||||
try:
|
from six.moves.html_parser import HTMLParser
|
||||||
from html.parser import HTMLParser
|
|
||||||
except ImportError:
|
|
||||||
from HTMLParser import HTMLParser
|
|
||||||
|
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
from pelican.contents import Page, Category, Tag, Author
|
from pelican.contents import Page, Category, Tag, Author
|
||||||
|
|
@ -43,7 +40,6 @@ METADATA_PROCESSORS = {
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseReader(object):
|
class BaseReader(object):
|
||||||
"""Base class to read files.
|
"""Base class to read files.
|
||||||
|
|
||||||
|
|
@ -231,7 +227,11 @@ class HTMLReader(BaseReader):
|
||||||
|
|
||||||
class _HTMLParser(HTMLParser):
|
class _HTMLParser(HTMLParser):
|
||||||
def __init__(self, settings, filename):
|
def __init__(self, settings, filename):
|
||||||
HTMLParser.__init__(self)
|
try:
|
||||||
|
# Python 3.4+
|
||||||
|
HTMLParser.__init__(self, convert_charrefs=False)
|
||||||
|
except TypeError:
|
||||||
|
HTMLParser.__init__(self)
|
||||||
self.body = ''
|
self.body = ''
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,10 @@
|
||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
import argparse
|
import argparse
|
||||||
try:
|
try:
|
||||||
# py3k import
|
from html import unescape # py3.4+
|
||||||
from html.parser import HTMLParser
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# py2 import
|
from six.moves.html_parser import HTMLParser
|
||||||
from HTMLParser import HTMLParser # NOQA
|
unescape = HTMLParser().unescape
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
@ -129,7 +128,7 @@ def wp2fields(xml, wp_custpost=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Use HTMLParser due to issues with BeautifulSoup 3
|
# Use HTMLParser due to issues with BeautifulSoup 3
|
||||||
title = HTMLParser().unescape(item.title.contents[0])
|
title = unescape(item.title.contents[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
title = 'No title [%s]' % item.find('post_name').string
|
title = 'No title [%s]' % item.find('post_name').string
|
||||||
logger.warning('Post "%s" is lacking a proper title' % title)
|
logger.warning('Post "%s" is lacking a proper title' % title)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue