Suppress spurious warnings from bs4

More MarkupResemblesLocatorWarning warnings have been appearing. This
seems to be caused by parsing HTML content that contains a URL.

This new change suppresses the warning at the root level of the app
before any content has been parsed, so this error shouldn't appear
again.

Fixes #968
pull/994/head
Ben Busby 1 year ago
parent 229c9388cf
commit b39ba0533a
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1

@ -4,14 +4,16 @@ from app.utils.session import generate_key
from app.utils.bangs import gen_bangs_json from app.utils.bangs import gen_bangs_json
from app.utils.misc import gen_file_hash, read_config_bool from app.utils.misc import gen_file_hash, read_config_bool
from base64 import b64encode from base64 import b64encode
from bs4 import MarkupResemblesLocatorWarning
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dotenv import load_dotenv
from flask import Flask from flask import Flask
import json import json
import logging.config import logging.config
import os import os
from stem import Signal from stem import Signal
import threading import threading
from dotenv import load_dotenv import warnings
from werkzeug.middleware.proxy_fix import ProxyFix from werkzeug.middleware.proxy_fix import ProxyFix
@ -174,6 +176,9 @@ app.jinja_env.globals.update(
# Attempt to acquire tor identity, to determine if Tor config is available # Attempt to acquire tor identity, to determine if Tor config is available
send_tor_signal(Signal.HEARTBEAT) send_tor_signal(Signal.HEARTBEAT)
# Suppress spurious warnings from BeautifulSoup
warnings.simplefilter('ignore', MarkupResemblesLocatorWarning)
from app import routes # noqa from app import routes # noqa
# Disable logging from imported modules # Disable logging from imported modules

@ -1,6 +1,6 @@
from app.models.config import Config from app.models.config import Config
from app.models.endpoint import Endpoint from app.models.endpoint import Endpoint
from bs4 import BeautifulSoup, NavigableString, MarkupResemblesLocatorWarning from bs4 import BeautifulSoup, NavigableString
import copy import copy
from flask import current_app from flask import current_app
import html import html
@ -10,9 +10,6 @@ from urllib.parse import parse_qs
import re import re
import warnings import warnings
# Suppress incorrect warnings from bs4 related to parsing HTML content
warnings.filterwarnings('ignore', category=MarkupResemblesLocatorWarning)
SKIP_ARGS = ['ref_src', 'utm'] SKIP_ARGS = ['ref_src', 'utm']
SKIP_PREFIX = ['//www.', '//mobile.', '//m.', 'www.', 'mobile.', 'm.'] SKIP_PREFIX = ['//www.', '//mobile.', '//m.', 'www.', 'mobile.', 'm.']
GOOG_STATIC = 'www.gstatic.com' GOOG_STATIC = 'www.gstatic.com'

Loading…
Cancel
Save