Skip to content

Commit

Permalink
TV Grabber ttvdb4.py: remove python2 support
Browse files Browse the repository at this point in the history
Removed imports and additional code for python2.

Refs #422
  • Loading branch information
rcrdnalor committed Dec 20, 2021
1 parent e43361f commit 0654387
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.
43 changes: 13 additions & 30 deletions mythtv/bindings/python/ttvdbv4/utils.py
Expand Up @@ -10,40 +10,23 @@
from datetime import datetime
import sys

from io import StringIO
from html.parser import HTMLParser

if sys.version_info[0] == 2:
from HTMLParser import HTMLParser
from StringIO import StringIO

class MLStripper(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.strict = False
self.convert_charrefs= True
self.text = StringIO()

class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.text = StringIO()
def handle_data(self, d):
self.text.write(d)

def handle_data(self, d):
self.text.write(d)

def get_data(self):
return self.text.getvalue()

else:
from io import StringIO
from html.parser import HTMLParser

class MLStripper(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.strict = False
self.convert_charrefs= True
self.text = StringIO()

def handle_data(self, d):
self.text.write(d)

def get_data(self):
return self.text.getvalue()
def get_data(self):
return self.text.getvalue()


def strip_tags(html):
Expand Down
22 changes: 5 additions & 17 deletions mythtv/programs/scripts/metadata/Television/ttvdb4.py
Expand Up @@ -19,16 +19,13 @@

__title__ = "TheTVDatabaseV4"
__author__ = "Roland Ernst"
__version__ = "0.4.0"
__version__ = "0.4.1"


def print_etree(etostr):
"""lxml.etree.tostring is a bytes object in python3, and a str in python2.
"""
if sys.version_info[0] == 2:
sys.stdout.write(etostr)
else:
sys.stdout.write(etostr.decode("utf-8"))
sys.stdout.write(etostr.decode("utf-8"))


def _parse_config(config):
Expand Down Expand Up @@ -186,10 +183,7 @@ def main():
os.makedirs(cachedir)

if not args.debug and not args.doctest:
if sys.version_info[0] == 2:
cache_name = os.path.join(cachedir, 'py2ttvdb4')
else:
cache_name = os.path.join(cachedir, 'py3ttvdb4')
cache_name = os.path.join(cachedir, 'py3ttvdb4')
import requests_cache
requests_cache.install_cache(cache_name, backend='sqlite', expire_after=3600)

Expand Down Expand Up @@ -234,10 +228,7 @@ def main():
print("0000: Init: Local config file '%s' created." % local_config_file)

# storage for authentication bearer token
if sys.version_info[0] == 2:
config_dict['auth_file'] = os.path.join(cachedir, "py2ttvdb4_bearer.pickle")
else:
config_dict['auth_file'] = os.path.join(cachedir, "py3ttvdb4_bearer.pickle")
config_dict['auth_file'] = os.path.join(cachedir, "py3ttvdb4_bearer.pickle")

cmd_args["config"] = config_dict
if args.debug:
Expand All @@ -248,10 +239,7 @@ def main():
import doctest
try:
with open("ttvdb4_doctests") as f:
if sys.version_info[0] == 2:
dtests = b"".join(f.readlines()).decode('utf-8')
else:
dtests = "".join(f.readlines())
dtests = "".join(f.readlines())
main.__doc__ += dtests
except IOError:
pass
Expand Down

0 comments on commit 0654387

Please sign in to comment.