summaryrefslogtreecommitdiff
path: root/sci-calculators/units/files/units_cur-urllib.patch
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2021-07-13 08:07:42 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2021-07-13 08:07:59 -0400
commit99506f6bc429482d90111050a1f759a89f6fbc36 (patch)
treeeafeb42fdac35e074fe6332735ea3947752eb1b4 /sci-calculators/units/files/units_cur-urllib.patch
parent5baf6aba1d353151946a870ac162e751c74df76e (diff)
downloadgentoo-overlay-99506f6bc429482d90111050a1f759a89f6fbc36.tar.xz
gentoo-overlay-99506f6bc429482d90111050a1f759a89f6fbc36.zip
sci-calculators/units: add
Diffstat (limited to 'sci-calculators/units/files/units_cur-urllib.patch')
-rw-r--r--sci-calculators/units/files/units_cur-urllib.patch60
1 files changed, 60 insertions, 0 deletions
diff --git a/sci-calculators/units/files/units_cur-urllib.patch b/sci-calculators/units/files/units_cur-urllib.patch
new file mode 100644
index 0000000..e77ff96
--- /dev/null
+++ b/sci-calculators/units/files/units_cur-urllib.patch
@@ -0,0 +1,60 @@
+Only in a: currency.units
+diff -ru a/units_cur b/units_cur
+--- a/units_cur 2018-09-15 16:30:09.000000000 -0400
++++ b/units_cur 2021-07-11 18:01:29.030260473 -0400
+@@ -28,8 +28,12 @@
+ #
+ #
+
+-version = '5.0'
++version = '5.1'
+
++# Version 5.1:
++#
++# Switch to urllib to avoid requests dependency.
++#
+ # Version 5.0:
+ #
+ # Rewrite to support multiple different data sources due to disappearance
+@@ -54,8 +58,11 @@
+ # Python 2 or Python 3. Thanks to Ray Hamel for some help with this update.
+
+ # Normal imports
+-import requests
+ import codecs
++import json
++import urllib.error
++import urllib.parse
++import urllib.request
+ from argparse import ArgumentParser
+ from collections import OrderedDict
+ from datetime import date
+@@ -288,11 +295,12 @@
+ currency[code][rate_index]))
+
+ def getjson(address,args=None):
++ if args:
++ address = address + "?" + urllib.parse.urlencode(args)
+ try:
+- res = requests.get(address,args)
+- res.raise_for_status()
+- return(res.json())
+- except requests.exceptions.RequestException as e:
++ res = urllib.request.urlopen(address)
++ return(json.load(res))
++ except urllib.error.URLError as e:
+ stderr.write('Error connecting to currency server:\n{}.\n'.format(e))
+ exit(1)
+
+@@ -323,9 +331,8 @@
+ stderr.write('European bank uses euro for base currency. Specified base {} ignored.\n'.format(base))
+ import xml.etree.ElementTree as ET
+ try:
+- res=requests.get('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')
+- res.raise_for_status()
+- data = ET.fromstring(res.content)[2][0]
++ res=urllib.request.urlopen('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')
++ data = ET.fromstring(res.read())[2][0]
+ except requests.exceptions.RequestException as e:
+ stderr.write('Error connecting to currency server:\n{}.\n'.
+ format(e))