From 5923dee83938fe0b0a8f7e959f1068a6a6eedf71 Mon Sep 17 00:00:00 2001
From: Kyle Robbertze <kyle@paddatrapper.com>
Date: Wed, 22 Jan 2020 13:54:04 +0200
Subject: [PATCH] Fix running apps

---
 python_apps/airtime-celery/setup.py           |  2 +-
 .../api_clients/api_clients/api_client.py     |  2 +-
 .../api_clients/tests/test_apirequest.py      |  2 +-
 python_apps/pypo/pypo/__main__.py             | 53 -------------------
 python_apps/pypo/pypo/recorder.py             |  6 ---
 python_apps/pypo/setup.py                     |  1 -
 6 files changed, 3 insertions(+), 63 deletions(-)

diff --git a/python_apps/airtime-celery/setup.py b/python_apps/airtime-celery/setup.py
index cd873dec0..79d382da7 100644
--- a/python_apps/airtime-celery/setup.py
+++ b/python_apps/airtime-celery/setup.py
@@ -45,7 +45,7 @@ setup(
     author_email="duncan.sommerville@sourcefabric.org",
     license="MIT",
     packages=["airtime-celery"],
-    install_requires=["soundcloud", "celery < 4", "kombu < 3.1", "configobj"],
+    install_requires=["soundcloud", "celery", "kombu", "configobj"],
     zip_safe=False,
     data_files=data_files,
 )
diff --git a/python_apps/api_clients/api_clients/api_client.py b/python_apps/api_clients/api_clients/api_client.py
index 95ad844e9..911fa6179 100644
--- a/python_apps/api_clients/api_clients/api_client.py
+++ b/python_apps/api_clients/api_clients/api_client.py
@@ -122,7 +122,7 @@ class ApiRequest(object):
         try:
             req = urllib.request.Request(final_url, _post_data)
             f = urllib.request.urlopen(req, timeout=ApiRequest.API_HTTP_REQUEST_TIMEOUT)
-            content_type = f.info().getheader('Content-Type')
+            content_type = f.info().get_content_type()
             response = f.read()
         #Everything that calls an ApiRequest should be catching URLError explicitly
         #(according to the other comments in this file and a cursory grep through the code)
diff --git a/python_apps/api_clients/tests/test_apirequest.py b/python_apps/api_clients/tests/test_apirequest.py
index 0fe13129a..3ca7772e8 100644
--- a/python_apps/api_clients/tests/test_apirequest.py
+++ b/python_apps/api_clients/tests/test_apirequest.py
@@ -4,7 +4,7 @@ from mock import MagicMock, patch
 from api_clients.api_client import ApcUrl, ApiRequest
 
 class ResponseInfo:
-    def getheader(self, name):
+    def get_content_type(self):
         return 'application/json'
 
 class TestApiRequest(unittest.TestCase):
diff --git a/python_apps/pypo/pypo/__main__.py b/python_apps/pypo/pypo/__main__.py
index d9f3160a0..94ec277ef 100644
--- a/python_apps/pypo/pypo/__main__.py
+++ b/python_apps/pypo/pypo/__main__.py
@@ -123,59 +123,6 @@ except Exception as e:
     print("Couldn't configure logging: {}".format(e))
     sys.exit(1)
 
-
-def configure_locale():
-    """
-    Silly hacks to force Python 2.x to run in UTF-8 mode. Not portable at all,
-    however serves our purpose at the moment.
-
-    More information available here:
-    http://stackoverflow.com/questions/3828723/why-we-need-sys-setdefaultencodingutf-8-in-a-py-script
-    """
-    logger.debug("Before %s", locale.nl_langinfo(locale.CODESET))
-    current_locale = locale.getlocale()
-
-    if current_locale[1] is None:
-        logger.debug("No locale currently set. Attempting to get default locale.")
-        default_locale = locale.getdefaultlocale()
-
-        if default_locale[1] is None:
-            logger.debug(
-                "No default locale exists. Let's try loading from \
-                    /etc/default/locale"
-            )
-            if os.path.exists("/etc/default/locale"):
-                locale_config = ConfigObj("/etc/default/locale")
-                lang = locale_config.get("LANG")
-                new_locale = lang
-            else:
-                logger.error(
-                    "/etc/default/locale could not be found! Please \
-                        run 'sudo update-locale' from command-line."
-                )
-                sys.exit(1)
-        else:
-            new_locale = default_locale
-
-        logger.info(
-            "New locale set to: %s", locale.setlocale(locale.LC_ALL, new_locale)
-        )
-
-    importlib.reload(sys)
-    sys.setdefaultencoding("UTF-8")
-    current_locale_encoding = locale.getlocale()[1].lower()
-    logger.debug("sys default encoding %s", sys.getdefaultencoding())
-    logger.debug("After %s", locale.nl_langinfo(locale.CODESET))
-
-    if current_locale_encoding not in ["utf-8", "utf8"]:
-        logger.error(
-            "Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding
-        )
-        sys.exit(1)
-
-
-configure_locale()
-
 # loading config file
 try:
     config = ConfigObj("/etc/airtime/airtime.conf")
diff --git a/python_apps/pypo/pypo/recorder.py b/python_apps/pypo/pypo/recorder.py
index 6ed3f301d..ce2d3a4e0 100644
--- a/python_apps/pypo/pypo/recorder.py
+++ b/python_apps/pypo/pypo/recorder.py
@@ -15,9 +15,6 @@ import re
 
 from configobj import ConfigObj
 
-from poster.encode import multipart_encode
-from poster.streaminghttp import register_openers
-
 from subprocess import Popen
 from subprocess import PIPE
 from threading import Thread
@@ -127,9 +124,6 @@ class ShowRecorder(Thread):
 
         filename = os.path.split(filepath)[1]
 
-        # Register the streaming http handlers with urllib2
-        register_openers()
-
         # files is what requests actually expects
         files = {'file': open(filepath, "rb"), 'name': filename, 'show_instance': self.show_instance}
 
diff --git a/python_apps/pypo/setup.py b/python_apps/pypo/setup.py
index 5eea754ca..649ef331c 100644
--- a/python_apps/pypo/setup.py
+++ b/python_apps/pypo/setup.py
@@ -55,7 +55,6 @@ setup(name='airtime-playout',
           'future',
           'kombu',
           'mutagen',
-          'poster3',
           'PyDispatcher',
           'pyinotify',
           'pytz',