From: Seth Forshee <seth.forshee@canonical.com>
To: Matthias Schiffer <mschiffer@universe-factory.net>
Cc: wireless-regdb@lists.infradead.org, linux-wireless@vger.kernel.org
Subject: Re: [PATCH v2 2/2] wireless-regdb: make scripts compatible with Python 3
Date: Fri, 30 Mar 2018 08:14:33 -0500 [thread overview]
Message-ID: <20180330131433.GQ18469@ubuntu-xps13> (raw)
In-Reply-To: <3a370649-9417-47d0-49c0-544f99a22306@universe-factory.net>
On Thu, Mar 22, 2018 at 03:44:00PM +0100, Matthias Schiffer wrote:
> On 03/22/2018 03:05 PM, Seth Forshee wrote:
> > On Sun, Feb 04, 2018 at 12:36:54AM +0100, Matthias Schiffer wrote:
> >> When playing with the generation scripts for OpenWrt development, I noticed
> >> that these scripts still required Python 2. Future-proof them by replacing
> >> deprecated functions with new Python 3 compatible variants. The result
> >> works with both Python 2.7 and Python 3.x; older Python 2.x releases are
> >> not supported anymore.
> >>
> >> regulatory.db and regulatory.bin are unchanged and reproducible across
> >> Python versions. Note that there is no stable release of m2crypto for
> >> Python 3 yet; I used the current development branch for testing.
> >
> > I can't say I'm all that knowledgable about Python 2 to Python 3
> > conversion, but as far as I can tell this looks okay. It does seem to
> > work for me running with both Python 2 and Python 3.
> >
> > One question below though, mostly just to satisfy my curiousity.
> >
> >> Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
> >> ---
> >>
> >> v2: explicitly open input file with UTF-8 encoding; otherwise the scripts
> >> will fail without a UTF-8 locale set in the environment
> >>
> >>
> >> db2bin.py | 22 ++++++++---------
> >> db2fw.py | 28 +++++++++++-----------
> >> dbparse.py | 81 +++++++++++++++++++++++++++++++++++++-------------------------
> >> 3 files changed, 74 insertions(+), 57 deletions(-)
> >>
> >> diff --git a/db2bin.py b/db2bin.py
> >> index ae5f064..28cd7d2 100755
> >> --- a/db2bin.py
> >> +++ b/db2bin.py
> >> @@ -1,6 +1,6 @@
> >> #!/usr/bin/env python
> >>
> >> -from cStringIO import StringIO
> >> +from io import BytesIO, open
> >> import struct
> >> import hashlib
> >> from dbparse import DBParser
> >> @@ -10,21 +10,21 @@ MAGIC = 0x52474442
> >> VERSION = 19
> >>
> >> if len(sys.argv) < 3:
> >> - print 'Usage: %s output-file input-file [key-file]' % sys.argv[0]
> >> + print('Usage: %s output-file input-file [key-file]' % sys.argv[0])
> >> sys.exit(2)
> >>
> >> def create_rules(countries):
> >> result = {}
> >> - for c in countries.itervalues():
> >> + for c in countries.values():
> >> for rule in c.permissions:
> >> result[rule] = 1
> >> - return result.keys()
> >> + return list(result)
> >
> > Here and elsewhere, to get a list of the keys from a dictionary, we use
> > list(dict). Experimentally I find this works, but I haven't been able to
> > find anything which actually tells me that this is the defined behavior,
> > and examples seem to prefer list(dict.keys()). I'm curious why this is
> > guaranteed to provide a lsit of dictionary keys, and why you've done
> > that rather than list(dict.keys()) (I'll grant that the scripts
> > elsewhere use list(dict), so maybe you were just being consistent with
> > that).
>
> list(dict) is the recommended syntax in
> http://python-future.org/compatible_idioms.html#dict-keys-values-items-as-a-list
Thanks for the explanation. I've applied both patches.
Seth
prev parent reply other threads:[~2018-03-30 13:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-03 23:36 [PATCH v2 1/2] wireless-regdb: do not rely on sorting of dict keys in conversion scripts Matthias Schiffer
2018-02-03 23:36 ` [PATCH v2 2/2] wireless-regdb: make scripts compatible with Python 3 Matthias Schiffer
2018-03-22 14:05 ` Seth Forshee
2018-03-22 14:44 ` Matthias Schiffer
2018-03-30 13:14 ` Seth Forshee [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180330131433.GQ18469@ubuntu-xps13 \
--to=seth.forshee@canonical.com \
--cc=linux-wireless@vger.kernel.org \
--cc=mschiffer@universe-factory.net \
--cc=wireless-regdb@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox