Skip to content

Commit 50218b5

Browse files
authored
[deps] Add support for Python >=3.12, 3.14 #345
Closes #345
1 parent 6a23630 commit 50218b5

File tree

12 files changed

+28
-21
lines changed

12 files changed

+28
-21
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
python-version:
21-
- "3.8"
2221
- "3.9"
2322
- "3.10"
23+
- "3.11"
24+
- "3.12"
25+
- "3.13"
2426

2527
steps:
2628
- uses: actions/checkout@v4

netjsonconfig/backends/base/backend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
from copy import deepcopy
88
from io import BytesIO
99

10-
from jsonschema import Draft4Validator, draft4_format_checker
10+
from jsonschema import Draft4Validator
1111
from jsonschema.exceptions import ValidationError as JsonSchemaError
1212

1313
from ...exceptions import ValidationError
1414
from ...schema import DEFAULT_FILE_MODE
1515
from ...utils import evaluate_vars, merge_config
1616

17+
format_checker = Draft4Validator.FORMAT_CHECKER
1718
_host_name_re = re.compile(r"^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$")
1819

1920

@@ -126,15 +127,15 @@ def _deduplicate_files(self):
126127
files_dict[file['path']] = file
127128
self.config['files'] = list(files_dict.values())
128129

129-
@draft4_format_checker.checks('cidr', AssertionError)
130+
@format_checker.checks('cidr', AssertionError)
130131
def _cidr_notation(value):
131132
try:
132133
ipaddress.ip_network(value)
133134
except ValueError as e:
134135
assert False, str(e)
135136
return True
136137

137-
@draft4_format_checker.checks('hostname', JsonSchemaError)
138+
@format_checker.checks('hostname', JsonSchemaError)
138139
def _is_hostname(value):
139140
"""
140141
The hostname validation has been taken from jsonschema~=3.2.0
@@ -154,7 +155,7 @@ def _is_hostname(value):
154155

155156
def validate(self):
156157
try:
157-
Draft4Validator(self.schema, format_checker=draft4_format_checker).validate(
158+
Draft4Validator(self.schema, format_checker=format_checker).validate(
158159
self.config
159160
)
160161
except JsonSchemaError as e:

netjsonconfig/backends/openvpn/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from ...utils import sorted_dict
55
from ..base.parser import BaseParser
66

7-
vpn_pattern = re.compile('^# openvpn config:\s', flags=re.MULTILINE)
8-
config_pattern = re.compile('^([^\s]*) ?(.*)$')
7+
vpn_pattern = re.compile(r'^# openvpn config:\s', flags=re.MULTILINE)
8+
config_pattern = re.compile(r'^([^\s]*) ?(.*)$')
99
config_suffix = '.conf'
1010

1111

netjsonconfig/backends/openwrt/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from ...utils import sorted_dict
66
from ..base.parser import BaseParser
77

8-
packages_pattern = re.compile('^package\s', flags=re.MULTILINE)
9-
block_pattern = re.compile('^config\s', flags=re.MULTILINE)
10-
config_pattern = re.compile('^(option|list)\s*([^\s]*)\s*(.*)')
8+
packages_pattern = re.compile(r'^package\s', flags=re.MULTILINE)
9+
block_pattern = re.compile(r'^config\s', flags=re.MULTILINE)
10+
config_pattern = re.compile(r'^(option|list)\s*([^\s]*)\s*(.*)')
1111
config_path = 'etc/config/'
1212

1313

netjsonconfig/backends/openwrt/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ..wireguard.schema import base_wireguard_schema
88
from .timezones import timezones
99

10-
QOS_MAPPING_PATTERN = "^[0-9]\d*:[0-9]\d*$"
10+
QOS_MAPPING_PATTERN = r"^[0-9]\d*:[0-9]\d*$"
1111

1212
default_radio_driver = "mac80211"
1313

netjsonconfig/backends/wireguard/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from ..base.parser import BaseParser
44

5-
vpn_pattern = re.compile('^# wireguard config:\s', flags=re.MULTILINE)
6-
config_pattern = re.compile('^([^\s]*) ?(.*)$')
5+
vpn_pattern = re.compile(r'^# wireguard config:\s', flags=re.MULTILINE)
6+
config_pattern = re.compile(r'^([^\s]*) ?(.*)$')
77
config_suffix = '.conf'
88

99

netjsonconfig/backends/zerotier/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from ..base.parser import BaseParser
66

7-
vpn_pattern = re.compile('^// zerotier controller config:\s', flags=re.MULTILINE)
8-
config_pattern = re.compile('^([^\s]*) ?(.*)$')
7+
vpn_pattern = re.compile(r'^// zerotier controller config:\s', flags=re.MULTILINE)
8+
config_pattern = re.compile(r'^([^\s]*) ?(.*)$')
99
config_suffix = '.json'
1010

1111

tests/openvpn/test_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ def test_parse_tar_bytesio(self):
316316
def test_parse_tar_file(self):
317317
o = OpenVpn(self._multiple_vpn)
318318
o.write(name='test', path='/tmp')
319-
OpenVpn(native=open('/tmp/test.tar.gz'))
319+
with open('/tmp/test.tar.gz', 'rb') as f:
320+
OpenVpn(native=f)
320321
os.remove('/tmp/test.tar.gz')
321322
self.assertDictEqual(o.config, self._multiple_vpn)
322323

tests/openwrt/test_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_type_error(self):
6969
with self.assertRaises(TypeError):
7070
OpenWrt([])
7171
with self.assertRaises(TypeError):
72-
OpenWrt('NOTJSON[]\{\}')
72+
OpenWrt(r'NOTJSON[]\{\}')
7373

7474
def test_system_invalid_timezone(self):
7575
o = OpenWrt({"general": {"hostname": "test_system", "timezone": "WRONG"}})

tests/openwrt/test_network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ def test_render_rule_wrong(self):
263263
o.validate()
264264
rule['ip_rules'][0]['src'] = '192.168.1.0/24'
265265
o = OpenWrt(rule)
266-
with self.assertRaisesRegexp(ValidationError, "'wrong1' is not a 'cidr'"):
266+
with self.assertRaisesRegex(ValidationError, "'wrong1' is not a 'cidr'"):
267267
o.validate()
268268
# fix 'dest' and expect no ValidationError raised
269269
rule['ip_rules'][0]['dest'] = '192.168.1.0/24'
270270
o = OpenWrt(rule)
271271
o.validate()
272272

273273
def test_parse_rules_zone(self):
274-
with self.assertRaisesRegexp(ValidationError, "'wrong' is not a 'cidr'"):
274+
with self.assertRaisesRegex(ValidationError, "'wrong' is not a 'cidr'"):
275275
OpenWrt(
276276
native="""package network
277277

0 commit comments

Comments
 (0)