chiark / gitweb /
make-secnet-sites etc.: Use unicode
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 18 Oct 2019 23:40:17 +0000 (00:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:16 +0000 (19:16 +0100)
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 <ijackson@chiark.greenend.org.uk>
ipaddrset-test.py
make-secnet-sites

index 7dff38963419ad25014a606dbf66ba05f27b4993..fdc0b6b28c9f5fed667c6213174b9e516f6c12f8 100755 (executable)
@@ -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
index 65baa11c0b98b3d44d2e5d6f8fb9859cf8f86fda..76d74f1a6907944b1cb5b3b2d5e2be31e1c54fae 100755 (executable)
@@ -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?