From 5de3c11e559c5700f62c8961460ce0497e3275fe Mon Sep 17 00:00:00 2001 From: Vinfall <91039000+Vinfall@users.noreply.github.com> Date: Wed, 9 Nov 2022 11:53:12 +0000 Subject: [PATCH 1/2] Remove `cgi` DeprecationWarning DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13 import cgi --- buku | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buku b/buku index e64e8ed2..1f1bd25d 100755 --- a/buku +++ b/buku @@ -19,10 +19,10 @@ import argparse import calendar -import cgi import codecs import collections import contextlib +import email import json import locale import logging @@ -3809,14 +3809,14 @@ def get_data_from_page(resp): if soup.meta and soup.meta.get('charset') is not None: charset = soup.meta.get('charset') elif 'content-type' in resp.headers: - _, params = cgi.parse_header(resp.headers['content-type']) + _, params = email.message(resp.headers['content-type']) if params.get('charset') is not None: charset = params.get('charset') if not charset and soup: meta_tag = soup.find('meta', attrs={'http-equiv': 'Content-Type'}) if meta_tag: - _, params = cgi.parse_header(meta_tag.attrs['content']) + _, params = email.message(meta_tag.attrs['content']) charset = params.get('charset', charset) if charset: From be8270172b86ee328146857abc3677f5b7e15453 Mon Sep 17 00:00:00 2001 From: Vinfall Date: Thu, 10 Nov 2022 10:38:50 +0800 Subject: [PATCH 2/2] Fix `email.message` not callable warning --- buku | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/buku b/buku index 1f1bd25d..580d4192 100755 --- a/buku +++ b/buku @@ -22,7 +22,7 @@ import calendar import codecs import collections import contextlib -import email +import email.message import json import locale import logging @@ -3809,15 +3809,17 @@ def get_data_from_page(resp): if soup.meta and soup.meta.get('charset') is not None: charset = soup.meta.get('charset') elif 'content-type' in resp.headers: - _, params = email.message(resp.headers['content-type']) - if params.get('charset') is not None: - charset = params.get('charset') + m = email.message.Message() + m['content-type'] = resp.headers['content-type'] + if m.get_param('charset') is not None: + charset = m.get_param('charset') if not charset and soup: meta_tag = soup.find('meta', attrs={'http-equiv': 'Content-Type'}) if meta_tag: - _, params = email.message(meta_tag.attrs['content']) - charset = params.get('charset', charset) + m = email.message.Message() + m['content'] = meta_tag.attrs['content'] + charset = m.get_param('charset', charset) if charset: LOGDBG('charset: %s', charset)