From 9d9a15df4db544958869f112af7dc5ea7403e5be Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 19 Oct 2019 00:40:17 +0100 Subject: [PATCH] make-secnet-sites etc.: Use unicode We are going to want to switch to ipaddress from ipaddr, since ipaddress is available in python3. But ipaddress insists on unicode strings, even in python2. ipaddr doesn't mind them. So make everything be unicode. In particular: all of our literals and all of our io streams. We wrap up io.open(), which is a compatibility thing from python-future. Signed-off-by: Ian Jackson --- ipaddrset-test.py | 1 + make-secnet-sites | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/ipaddrset-test.py b/ipaddrset-test.py index 7dff389..fdc0b6b 100755 --- a/ipaddrset-test.py +++ b/ipaddrset-test.py @@ -30,6 +30,7 @@ # don't believe it is a creative work that attracts copyright. -iwj. from __future__ import print_function +from __future__ import unicode_literals import ipaddr from ipaddr import IPNetwork, IPAddress diff --git a/make-secnet-sites b/make-secnet-sites index 65baa11..76d74f1 100755 --- a/make-secnet-sites +++ b/make-secnet-sites @@ -52,6 +52,7 @@ Cendio Systems AB. """ from __future__ import print_function +from __future__ import unicode_literals from builtins import int import string @@ -71,6 +72,14 @@ import ipaddrset VERSION="0.1.18" +from sys import version_info +if version_info.major == 2: # for python2 + import codecs + sys.stdin = codecs.getreader('utf-8')(sys.stdin) + sys.stdout = codecs.getwriter('utf-8')(sys.stdout) + import io + open=lambda f,m='r': io.open(f,m,encoding='utf-8') + # Are we being invoked from userv? service=0 # If we are, which group does the caller want to modify? -- 2.30.2