From mboxrd@z Thu Jan  1 00:00:00 1970
From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH 04/10] Run 2to3
Date: Fri, 07 May 2021 11:16:48 +0000
Message-ID: <20210507111654.2397-5-michael.tremer@ipfire.org>
In-Reply-To: <20210507111654.2397-1-michael.tremer@ipfire.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============0625778532962932294=="
List-Id: <development.lists.ipfire.org>

--===============0625778532962932294==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

This is the result of running the automatic conversion tool and I have
not tested this, yet. There might be some bugs being introduced by this.

Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
---
 src/fireinfo/cpu.py        | 20 ++++++++++----------
 src/fireinfo/hypervisor.py |  6 +++---
 src/fireinfo/network.py    |  8 ++++----
 src/fireinfo/system.py     | 38 ++++++++++++++++++--------------------
 src/sendprofile            | 34 +++++++++++++++++-----------------
 5 files changed, 52 insertions(+), 54 deletions(-)

diff --git a/src/fireinfo/cpu.py b/src/fireinfo/cpu.py
index dc76caf..e433a04 100644
--- a/src/fireinfo/cpu.py
+++ b/src/fireinfo/cpu.py
@@ -21,7 +21,7 @@
=20
 import os
=20
-import system
+from . import system
=20
 PROC_CPUINFO =3D "/proc/cpuinfo"
=20
@@ -188,12 +188,12 @@ class CPU(object):
 if __name__ =3D=3D "__main__":
 	c =3D CPU()
=20
-	print "Vendor:", c.vendor
-	print "Model:", c.model
-	print "Stepping:", c.stepping
-	print "Flags:", c.flags
-	print "Bogomips:", c.bogomips
-	print "Speed:", c.speed
-	print "Family:", c.family
-	print "Count:", c.count
-	print "Model string:", c.model_string
+	print("Vendor:", c.vendor)
+	print("Model:", c.model)
+	print("Stepping:", c.stepping)
+	print("Flags:", c.flags)
+	print("Bogomips:", c.bogomips)
+	print("Speed:", c.speed)
+	print("Family:", c.family)
+	print("Count:", c.count)
+	print("Model string:", c.model_string)
diff --git a/src/fireinfo/hypervisor.py b/src/fireinfo/hypervisor.py
index 0c07cfa..e76aad5 100644
--- a/src/fireinfo/hypervisor.py
+++ b/src/fireinfo/hypervisor.py
@@ -20,7 +20,7 @@
 ############################################################################=
###
=20
 import _fireinfo
-import system
+from . import system
=20
 class Hypervisor(object):
 	def __init__(self):
@@ -115,5 +115,5 @@ class Hypervisor(object):
 if __name__ =3D=3D "__main__":
 	h =3D Hypervisor()
=20
-	print "Vendor:", h.vendor
-	print "Virtual:", h.virtual
+	print("Vendor:", h.vendor)
+	print("Virtual:", h.virtual)
diff --git a/src/fireinfo/network.py b/src/fireinfo/network.py
index 063e9ec..de58be3 100644
--- a/src/fireinfo/network.py
+++ b/src/fireinfo/network.py
@@ -47,7 +47,7 @@ class Network(object):
 if __name__ =3D=3D "__main__":
 	n =3D Network()
=20
-	print "has_green", n.has_green()
-	print "has_red", n.has_red()
-	print "has_blue", n.has_blue()
-	print "has_orange", n.has_orange()
+	print("has_green", n.has_green())
+	print("has_red", n.has_red())
+	print("has_blue", n.has_blue())
+	print("has_orange", n.has_orange())
diff --git a/src/fireinfo/system.py b/src/fireinfo/system.py
index 73c3882..cfeb171 100644
--- a/src/fireinfo/system.py
+++ b/src/fireinfo/system.py
@@ -26,11 +26,11 @@ import string
=20
 import _fireinfo
=20
-import bios
-import cpu
-import device
-import hypervisor
-import network
+from . import bios
+from . import cpu
+from . import device
+from . import hypervisor
+from . import network
=20
 PROFILE_VERSION =3D 0
=20
@@ -84,9 +84,7 @@ def read_from_file(filename):
 	except IOError:
 		pass
=20
-class System(object):
-	__metaclass__ =3D Singleton
-
+class System(object, metaclass=3DSingleton):
 	def __init__(self):
 		self.bios =3D bios.BIOS(self)
=20
@@ -338,7 +336,7 @@ class System(object):
 		if s is None:
 			return
=20
-		return filter(lambda x: x in string.printable, s)
+		return [x for x in s if x in string.printable]
=20
 	@property
 	def vendor(self):
@@ -373,7 +371,7 @@ class System(object):
 		ret =3D read_from_file("/proc/device-tree/model")
 		if ret:
 			# replace the NULL byte with which the DT string ends
-			ret =3D ret.replace(u"\u0000", "")
+			ret =3D ret.replace("\u0000", "")
=20
 		# Fall back to read /proc/cpuinfo
 		if not ret:
@@ -485,13 +483,13 @@ class System(object):
=20
 if __name__ =3D=3D "__main__":
 	s=3DSystem()
-	print s.arch
-	print s.language
-	print s.release
-	print s.bios_vendor
-	print s.memory
-	print s.kernel
-	print s.root_disk
-	print s.root_size
-	print "------------\n", s.devices, "\n------------\n"
-	print json.dumps(s.profile(), sort_keys=3DTrue, indent=3D4)
+	print(s.arch)
+	print(s.language)
+	print(s.release)
+	print(s.bios_vendor)
+	print(s.memory)
+	print(s.kernel)
+	print(s.root_disk)
+	print(s.root_size)
+	print("------------\n", s.devices, "\n------------\n")
+	print(json.dumps(s.profile(), sort_keys=3DTrue, indent=3D4))
diff --git a/src/sendprofile b/src/sendprofile
index 3ce68b9..5fc6c86 100755
--- a/src/sendprofile
+++ b/src/sendprofile
@@ -24,8 +24,8 @@ import logging
 import logging.handlers
 import os
 import sys
-import urllib
-import urllib2
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
=20
 import fireinfo
=20
@@ -67,8 +67,8 @@ def send_profile(profile):
 	for line in json.dumps(profile, sort_keys=3DTrue, indent=3D4).splitlines():
 		logging.debug(line)
=20
-	request =3D urllib2.Request(PROFILE_URL % profile,
-		data =3D urllib.urlencode({"profile" : json.dumps(profile)}),
+	request =3D urllib.request.Request(PROFILE_URL % profile,
+		data =3D urllib.parse.urlencode({"profile" : json.dumps(profile)}),
 	)
 	request.add_header("User-Agent", "fireinfo/%s" % fireinfo.__version__)
=20
@@ -80,22 +80,22 @@ def send_profile(profile):
 		if proxy["user"] and proxy["pass"]:
 			prx_auth_string =3D "http://%s:%s@%s/" % (proxy["user"], proxy["pass"], p=
roxy["host"])
=20
-			proxy_handler =3D urllib2.ProxyHandler({'http': prx_auth_string, 'https':=
 prx_auth_string})
-			auth =3D urllib2.HTTPBasicAuthHandler()
-			opener =3D urllib2.build_opener(proxy_handler, auth, urllib2.HTTPHandler)
-			urllib2.install_opener(opener)
+			proxy_handler =3D urllib.request.ProxyHandler({'http': prx_auth_string, '=
https': prx_auth_string})
+			auth =3D urllib.request.HTTPBasicAuthHandler()
+			opener =3D urllib.request.build_opener(proxy_handler, auth, urllib.reques=
t.HTTPHandler)
+			urllib.request.install_opener(opener)
 		else:
 			request.set_proxy(proxy["host"], "http")
 			request.set_proxy(proxy["host"], "https")
=20
 	try:
-		urllib2.urlopen(request, timeout=3D60)
-	except (urllib2.HTTPError, urllib2.URLError), e:
+		urllib.request.urlopen(request, timeout=3D60)
+	except (urllib.error.HTTPError, urllib.error.URLError) as e:
 		reason =3D "Unknown reason"
=20
-		if isinstance(e, urllib2.HTTPError):
+		if isinstance(e, urllib.error.HTTPError):
 			reason =3D "%s" % e
-		elif isinstance(e, urllib2.URLError):
+		elif isinstance(e, urllib.error.URLError):
 			reason =3D e.reason
=20
 		logging.error("Profile was not sent propertly: %s" % reason)
@@ -114,19 +114,19 @@ def main():
 		# it contains no information and may confuse people.
 		del profile["private_id"]
=20
-		print json.dumps(profile, sort_keys=3DTrue, indent=3D4)
+		print(json.dumps(profile, sort_keys=3DTrue, indent=3D4))
 		return 0
=20
 	if "--secret-id" in sys.argv:
-		print system.secret_id
+		print(system.secret_id)
 		return 0
=20
 	if "--hardware-string" in sys.argv:
-		print system._unique_id
+		print(system._unique_id)
 		return 0
=20
 	if "--public-id" in sys.argv:
-		print system.public_id
+		print(system.public_id)
 		return 0
=20
 	if not os.path.exists(ENABLED_FILE):
@@ -134,7 +134,7 @@ def main():
=20
 	try:
 		send_profile(profile)
-	except urllib2.URLError:
+	except urllib.error.URLError:
 		return 1
=20
 	return 0
--=20
2.20.1


--===============0625778532962932294==--