From 0dfb04e9e39ca878a41ac63e67531f75127885f9 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Wed, 13 Feb 2019 13:38:37 +0100 Subject: [PATCH] Ignore bs4 warnings These are triggered by false positives and get printed to screen when running `toot curses`. --- toot/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/toot/utils.py b/toot/utils.py index 6575698..2508e5a 100644 --- a/toot/utils.py +++ b/toot/utils.py @@ -4,6 +4,7 @@ import os import re import socket import unicodedata +import warnings from bs4 import BeautifulSoup @@ -17,7 +18,13 @@ def str_bool(b): def get_text(html): """Converts html to text, strips all tags.""" - text = BeautifulSoup(html.replace(''', "'"), "html.parser").get_text() + + # Ignore warnings made by BeautifulSoup, if passed something that looks like + # a file (e.g. a dot which matches current dict), it will warn that the file + # should be opened instead of passing a filename. + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + text = BeautifulSoup(html.replace(''', "'"), "html.parser").get_text() return unicodedata.normalize('NFKC', text)