Skip to content

Commit

Permalink
hardwareprofile: remove external dependency on simplejson
Browse files Browse the repository at this point in the history
This uses the requests module and converts requests responses to json
using requests' own `.json()` method on responses. For incomprehensible
reasons, requests has spent about a decade using either simplejson or
the standard library's json module more or less at will, and returning
either one or the other exception types. They don't know why they use
simplejson, we don't know why they use simplejson. In requests 3 (which
will be released in the Year Of The Linux Desktop or when pigs fly,
whichever one comes later) simplejson is dropped entirely.

There are innumerable issues discussing the problem on the requests
bugtracker, with the general consensus being that it's better to
randomly return either one of two different libraries and two different
library return types in errors -- because it was historically done that
way and people might be depending on it. ??????

Bugs:

psf/requests#710
psf/requests#2516
psf/requests#3052
psf/requests#4169
psf/requests#4842
psf/requests#5794
psf/requests#6084

The awkward workaround is to guarantee that requests' silent behavior of
using simplejson *if it is installed* is forcibly triggered by forcibly
depending on simplejson, and then catching the simplejson exception.

The better solution here is pretty simple: do not rely on the requests
module's automatic json conversion, this is as simple as using the
already-imported json module and calling json.loads() on the retrieved
content.

Fixes: 1df343e
Reimplements: bb154a8
  • Loading branch information
eli-schwartz authored and rcrdnalor committed Jan 8, 2024
1 parent b7092c0 commit af345e2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildmaster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
sudo apt install ccache qt5-qmake qtscript5-dev nasm libsystemd-dev libfreetype6-dev libmp3lame-dev libx264-dev libx265-dev libxrandr-dev libxml2-dev
sudo apt install libavahi-compat-libdnssd-dev libasound2-dev liblzo2-dev libhdhomerun-dev libsamplerate0-dev libva-dev libdrm-dev libvdpau-dev
sudo apt install libass-dev libpulse-dev libcec-dev libssl-dev libtag1-dev libbluray-dev libbluray-bdj libgnutls28-dev libqt5webkit5-dev
sudo apt install libvpx-dev python3-mysqldb python3-lxml python3-simplejson python3-future python3-setuptools libdbi-perl libdbd-mysql-perl libnet-upnp-perl
sudo apt install libvpx-dev python3-mysqldb python3-lxml python3-future python3-setuptools libdbi-perl libdbd-mysql-perl libnet-upnp-perl
sudo apt install libio-socket-inet6-perl libxml-simple-perl libqt5sql5-mysql libwayland-dev qtbase5-private-dev libzip-dev libsoundtouch-dev
if: runner.os == 'Linux'

Expand Down
3 changes: 1 addition & 2 deletions mythtv/configure
Original file line number Diff line number Diff line change
Expand Up @@ -5535,7 +5535,7 @@ if enabled bdjava; then
java_code_version=1.4

javac_version=`"${JAVAC}" -version 2>&1 | head -n 1`

echo "${javac_version}" | grep -E -q '^javac (9|1[0-1])' && java_code_version=1.6
echo "${javac_version}" | grep -E -q '^javac (1[2-9])' && java_code_version=1.7
echo "${javac_version}" | grep -E -q '^javac (2.*)' && java_code_version=1.7
Expand Down Expand Up @@ -6563,7 +6563,6 @@ if enabled bindings_python; then
check_py_lib MySQLdb || disable_bindings_python "MySQLdb"
check_py_lib lxml || disable_bindings_python "lxml"
check_py_lib requests || disable_bindings_python "requests"
check_py_lib simplejson || disable_bindings_python "simplejson"
check_py_lib future || disable_bindings_python "future"
check_python "(3,11,1)" && check_py_lib wheel && check_py_lib_version pip "(23,0,1)" && USE_PYTHON_PIP="yes"
fi
Expand Down
5 changes: 2 additions & 3 deletions mythtv/programs/scripts/hardwareprofile/smolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
from urlparse import urlparse
import json
from json import JSONEncoder
from simplejson import errors as sje
import datetime
import logging

Expand Down Expand Up @@ -790,8 +789,8 @@ def serialize(object, human=False):
sys.exit(1)

try:
admin_obj = admin_token.json()
except sje.JSONDecodeError:
admin_obj = json.loads(admin_token.content)
except json.JSONDecodeError:
self.session.close()
error(_('Incorrect server response. Expected a JSON string'))
return (1, None, None)
Expand Down

0 comments on commit af345e2

Please sign in to comment.