Skip to content

Commit

Permalink
Merge pull request #605 from Vinfall/master
Browse files Browse the repository at this point in the history
Remove `cgi` DeprecationWarning (Close #604)
  • Loading branch information
jarun authored Nov 10, 2022
2 parents 4384cbd + be82701 commit 80fc71c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions buku
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import argparse
import calendar
import cgi
import codecs
import collections
import contextlib
import email.message
import json
import locale
import logging
Expand Down Expand Up @@ -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 = cgi.parse_header(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 = cgi.parse_header(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)
Expand Down

0 comments on commit 80fc71c

Please sign in to comment.