File fix-regex-import-warning.patch of Package python-pyasn
From 9f1cf6d4ad1f404111da4ca575bda52265e7bbab Mon Sep 17 00:00:00 2001
From: caleb <calebdjones@gmail.com>
Date: Thu, 8 May 2025 10:25:06 -0400
Subject: [PATCH 1/2] fix regex import warning and make regex match full
pattern
---
pyasn/__init__.py | 4 ++--
tests/test_simple.py | 8 +++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/pyasn/__init__.py b/pyasn/__init__.py
index dce726f..55808a4 100644
--- a/pyasn/__init__.py
+++ b/pyasn/__init__.py
@@ -240,8 +240,8 @@ def convert_asdot_to_32bit_asn(asdot):
:param asdot: "AS[Number].[Number]" representation of an autonomous system
:return: 32bit AS number
"""
- pattern = re.compile("^[AS]|[as]|[aS]|[As]][0-9]*(\.)?[0-9]+")
- match = pattern.match(asdot)
+ pattern = re.compile(r'^(AS|as|aS|As)[0-9]+(\.[0-9]+)?')
+ match = pattern.fullmatch(asdot)
if not match:
raise ValueError("Invalid asdot format for input. input format must be something like"
" AS<Number> or AS<Number>.<Number> ")
diff --git a/tests/test_simple.py b/tests/test_simple.py
index 08b3290..3d27136 100644
--- a/tests/test_simple.py
+++ b/tests/test_simple.py
@@ -82,7 +82,7 @@ def test_correctness(self):
self.assertEqual(None, prefix)
# todo: check that self.ipdb.lookup_asn('300.3.4.4') raises expcetion
- def test_as_number_convert(self):
+ def test_as_number_convert_success(self):
"""
Tests for correct conversion between 32-bit and ASDOT number formats for ASNs
"""
@@ -98,6 +98,12 @@ def test_as_number_convert(self):
self.assertEqual(0, pyasn.convert_asdot_to_32bit_asn("AS0"))
self.assertEqual(131393, pyasn.convert_asdot_to_32bit_asn("AS2.321"))
+ def test_as_number_convert_fail(self):
+ self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS]2.321")
+ self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS2..321")
+ self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS2.")
+ self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS.098")
+
def test_get_tud_prefixes(self):
"""
Tests if correct prefixes are returned for a predetermined AS
From 7f8fee7a483029bdc8d410f0657e4b39f871be34 Mon Sep 17 00:00:00 2001
From: caleb <calebdjones@gmail.com>
Date: Thu, 8 May 2025 11:06:10 -0400
Subject: [PATCH 2/2] check error message is expected message
---
tests/test_simple.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tests/test_simple.py b/tests/test_simple.py
index 3d27136..6f62df6 100644
--- a/tests/test_simple.py
+++ b/tests/test_simple.py
@@ -99,10 +99,11 @@ def test_as_number_convert_success(self):
self.assertEqual(131393, pyasn.convert_asdot_to_32bit_asn("AS2.321"))
def test_as_number_convert_fail(self):
- self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS]2.321")
- self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS2..321")
- self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS2.")
- self.assertRaises(ValueError, pyasn.convert_asdot_to_32bit_asn, "AS.098")
+ msg = "Invalid asdot format for input. input format must be something like AS<Number> or AS<Number>.<Number> "
+ self.assertRaisesRegex(ValueError, msg, pyasn.convert_asdot_to_32bit_asn, "AS]2.321")
+ self.assertRaisesRegex(ValueError, msg, pyasn.convert_asdot_to_32bit_asn, "AS2..321")
+ self.assertRaisesRegex(ValueError, msg, pyasn.convert_asdot_to_32bit_asn, "AS2.")
+ self.assertRaisesRegex(ValueError, msg, pyasn.convert_asdot_to_32bit_asn, "AS.098")
def test_get_tud_prefixes(self):
"""