81f50f5dc02d02202bf64b537cdc4017aba76778
[openwrt/staging/wigyori.git] / package / firmware / wireless-regdb / patches / 010-regdb-fix-compatibility-with-python2.patch
1 From 651e39dee8605995b736b6056c6f7dc5c5a9c948 Mon Sep 17 00:00:00 2001
2 From: Johannes Berg <johannes.berg@intel.com>
3 Date: Thu, 22 Aug 2019 21:46:27 +0200
4 Subject: [PATCH] regdb: fix compatibility with python2
5
6 Various changes in the commit mentioned below broke
7 compatibility with python2. Restore it in a way that
8 makes it worth with both versions.
9
10 Fixes: f3c4969c2485 ("wireless-regdb: make scripts compatible with Python 3")
11 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
12 Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
13 ---
14 db2bin.py | 2 +-
15 db2fw.py | 2 +-
16 dbparse.py | 3 +--
17 3 files changed, 3 insertions(+), 4 deletions(-)
18
19 --- a/db2bin.py
20 +++ b/db2bin.py
21 @@ -118,7 +118,7 @@ reg_country_ptr.set()
22 for alpha2 in countrynames:
23 coll = countries[alpha2]
24 # struct regdb_file_reg_country
25 - output.write(struct.pack('>BBxBI', alpha2[0], alpha2[1], coll.dfs_region, reg_rules_collections[coll.permissions]))
26 + output.write(struct.pack('>2sxBI', alpha2, coll.dfs_region, reg_rules_collections[coll.permissions]))
27
28
29 if len(sys.argv) > 3:
30 --- a/db2fw.py
31 +++ b/db2fw.py
32 @@ -85,7 +85,7 @@ countrynames = list(countries)
33 countrynames.sort()
34 for alpha2 in countrynames:
35 coll = countries[alpha2]
36 - output.write(struct.pack('>BB', alpha2[0], alpha2[1]))
37 + output.write(struct.pack('>2s', alpha2))
38 country_ptrs[alpha2] = PTR(output)
39 output.write(b'\x00' * 4)
40
41 --- a/dbparse.py
42 +++ b/dbparse.py
43 @@ -1,6 +1,5 @@
44 #!/usr/bin/env python
45
46 -from builtins import bytes
47 from functools import total_ordering
48 import sys, math
49 from math import ceil, log
50 @@ -359,7 +358,7 @@ class DBParser(object):
51 for cname in cnames:
52 if len(cname) != 2:
53 self._warn("country '%s' not alpha2" % cname)
54 - cname = bytes(cname, 'ascii')
55 + cname = cname.encode('ascii')
56 if not cname in self._countries:
57 self._countries[cname] = Country(dfs_region, comments=self._comments)
58 self._current_countries[cname] = self._countries[cname]