From ee8de8471696b0c392bdb874b5a0255846bab700 Mon Sep 17 00:00:00 2001 From: Lari Liuhamo Date: Fri, 16 Aug 2024 15:49:45 +0300 Subject: [PATCH] [MAJOR] Swapped boolean parameters to enums --- poetry.lock | 184 ++++++++++++++++++--------------- pyproject.toml | 141 +++++++++++++------------ src/iplib3/address.py | 75 ++++++++------ src/iplib3/subnet.py | 4 +- src/iplib3/validators.py | 41 +++++--- tests/test_address.py | 18 ++-- tests/test_cases_address.py | 16 +-- tests/test_cases_validators.py | 97 ++++++++--------- tests/test_validators.py | 12 +-- 9 files changed, 324 insertions(+), 264 deletions(-) diff --git a/poetry.lock b/poetry.lock index c6cccf2..3559b57 100644 --- a/poetry.lock +++ b/poetry.lock @@ -35,63 +35,83 @@ files = [ [[package]] name = "coverage" -version = "7.3.2" +version = "7.6.1" description = "Code coverage measurement for Python" optional = false python-versions = ">=3.8" files = [ - {file = "coverage-7.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d872145f3a3231a5f20fd48500274d7df222e291d90baa2026cc5152b7ce86bf"}, - {file = "coverage-7.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:310b3bb9c91ea66d59c53fa4989f57d2436e08f18fb2f421a1b0b6b8cc7fffda"}, - {file = "coverage-7.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f47d39359e2c3779c5331fc740cf4bce6d9d680a7b4b4ead97056a0ae07cb49a"}, - {file = "coverage-7.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aa72dbaf2c2068404b9870d93436e6d23addd8bbe9295f49cbca83f6e278179c"}, - {file = "coverage-7.3.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:beaa5c1b4777f03fc63dfd2a6bd820f73f036bfb10e925fce067b00a340d0f3f"}, - {file = "coverage-7.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:dbc1b46b92186cc8074fee9d9fbb97a9dd06c6cbbef391c2f59d80eabdf0faa6"}, - {file = "coverage-7.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:315a989e861031334d7bee1f9113c8770472db2ac484e5b8c3173428360a9148"}, - {file = "coverage-7.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:d1bc430677773397f64a5c88cb522ea43175ff16f8bfcc89d467d974cb2274f9"}, - {file = "coverage-7.3.2-cp310-cp310-win32.whl", hash = "sha256:a889ae02f43aa45032afe364c8ae84ad3c54828c2faa44f3bfcafecb5c96b02f"}, - {file = "coverage-7.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:c0ba320de3fb8c6ec16e0be17ee1d3d69adcda99406c43c0409cb5c41788a611"}, - {file = "coverage-7.3.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ac8c802fa29843a72d32ec56d0ca792ad15a302b28ca6203389afe21f8fa062c"}, - {file = "coverage-7.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:89a937174104339e3a3ffcf9f446c00e3a806c28b1841c63edb2b369310fd074"}, - {file = "coverage-7.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e267e9e2b574a176ddb983399dec325a80dbe161f1a32715c780b5d14b5f583a"}, - {file = "coverage-7.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2443cbda35df0d35dcfb9bf8f3c02c57c1d6111169e3c85fc1fcc05e0c9f39a3"}, - {file = "coverage-7.3.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4175e10cc8dda0265653e8714b3174430b07c1dca8957f4966cbd6c2b1b8065a"}, - {file = "coverage-7.3.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:0cbf38419fb1a347aaf63481c00f0bdc86889d9fbf3f25109cf96c26b403fda1"}, - {file = "coverage-7.3.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:5c913b556a116b8d5f6ef834038ba983834d887d82187c8f73dec21049abd65c"}, - {file = "coverage-7.3.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:1981f785239e4e39e6444c63a98da3a1db8e971cb9ceb50a945ba6296b43f312"}, - {file = "coverage-7.3.2-cp311-cp311-win32.whl", hash = "sha256:43668cabd5ca8258f5954f27a3aaf78757e6acf13c17604d89648ecc0cc66640"}, - {file = "coverage-7.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:e10c39c0452bf6e694511c901426d6b5ac005acc0f78ff265dbe36bf81f808a2"}, - {file = "coverage-7.3.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:4cbae1051ab791debecc4a5dcc4a1ff45fc27b91b9aee165c8a27514dd160836"}, - {file = "coverage-7.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:12d15ab5833a997716d76f2ac1e4b4d536814fc213c85ca72756c19e5a6b3d63"}, - {file = "coverage-7.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3c7bba973ebee5e56fe9251300c00f1579652587a9f4a5ed8404b15a0471f216"}, - {file = "coverage-7.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fe494faa90ce6381770746077243231e0b83ff3f17069d748f645617cefe19d4"}, - {file = "coverage-7.3.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f6e9589bd04d0461a417562649522575d8752904d35c12907d8c9dfeba588faf"}, - {file = "coverage-7.3.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d51ac2a26f71da1b57f2dc81d0e108b6ab177e7d30e774db90675467c847bbdf"}, - {file = "coverage-7.3.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:99b89d9f76070237975b315b3d5f4d6956ae354a4c92ac2388a5695516e47c84"}, - {file = "coverage-7.3.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:fa28e909776dc69efb6ed975a63691bc8172b64ff357e663a1bb06ff3c9b589a"}, - {file = "coverage-7.3.2-cp312-cp312-win32.whl", hash = "sha256:289fe43bf45a575e3ab10b26d7b6f2ddb9ee2dba447499f5401cfb5ecb8196bb"}, - {file = "coverage-7.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:7dbc3ed60e8659bc59b6b304b43ff9c3ed858da2839c78b804973f613d3e92ed"}, - {file = "coverage-7.3.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f94b734214ea6a36fe16e96a70d941af80ff3bfd716c141300d95ebc85339738"}, - {file = "coverage-7.3.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:af3d828d2c1cbae52d34bdbb22fcd94d1ce715d95f1a012354a75e5913f1bda2"}, - {file = "coverage-7.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:630b13e3036e13c7adc480ca42fa7afc2a5d938081d28e20903cf7fd687872e2"}, - {file = "coverage-7.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c9eacf273e885b02a0273bb3a2170f30e2d53a6d53b72dbe02d6701b5296101c"}, - {file = "coverage-7.3.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d8f17966e861ff97305e0801134e69db33b143bbfb36436efb9cfff6ec7b2fd9"}, - {file = "coverage-7.3.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b4275802d16882cf9c8b3d057a0839acb07ee9379fa2749eca54efbce1535b82"}, - {file = "coverage-7.3.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:72c0cfa5250f483181e677ebc97133ea1ab3eb68645e494775deb6a7f6f83901"}, - {file = "coverage-7.3.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:cb536f0dcd14149425996821a168f6e269d7dcd2c273a8bff8201e79f5104e76"}, - {file = "coverage-7.3.2-cp38-cp38-win32.whl", hash = "sha256:307adb8bd3abe389a471e649038a71b4eb13bfd6b7dd9a129fa856f5c695cf92"}, - {file = "coverage-7.3.2-cp38-cp38-win_amd64.whl", hash = "sha256:88ed2c30a49ea81ea3b7f172e0269c182a44c236eb394718f976239892c0a27a"}, - {file = "coverage-7.3.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:b631c92dfe601adf8f5ebc7fc13ced6bb6e9609b19d9a8cd59fa47c4186ad1ce"}, - {file = "coverage-7.3.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:d3d9df4051c4a7d13036524b66ecf7a7537d14c18a384043f30a303b146164e9"}, - {file = "coverage-7.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5f7363d3b6a1119ef05015959ca24a9afc0ea8a02c687fe7e2d557705375c01f"}, - {file = "coverage-7.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2f11cc3c967a09d3695d2a6f03fb3e6236622b93be7a4b5dc09166a861be6d25"}, - {file = "coverage-7.3.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:149de1d2401ae4655c436a3dced6dd153f4c3309f599c3d4bd97ab172eaf02d9"}, - {file = "coverage-7.3.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:3a4006916aa6fee7cd38db3bfc95aa9c54ebb4ffbfc47c677c8bba949ceba0a6"}, - {file = "coverage-7.3.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9028a3871280110d6e1aa2df1afd5ef003bab5fb1ef421d6dc748ae1c8ef2ebc"}, - {file = "coverage-7.3.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:9f805d62aec8eb92bab5b61c0f07329275b6f41c97d80e847b03eb894f38d083"}, - {file = "coverage-7.3.2-cp39-cp39-win32.whl", hash = "sha256:d1c88ec1a7ff4ebca0219f5b1ef863451d828cccf889c173e1253aa84b1e07ce"}, - {file = "coverage-7.3.2-cp39-cp39-win_amd64.whl", hash = "sha256:b4767da59464bb593c07afceaddea61b154136300881844768037fd5e859353f"}, - {file = "coverage-7.3.2-pp38.pp39.pp310-none-any.whl", hash = "sha256:ae97af89f0fbf373400970c0a21eef5aa941ffeed90aee43650b81f7d7f47637"}, - {file = "coverage-7.3.2.tar.gz", hash = "sha256:be32ad29341b0170e795ca590e1c07e81fc061cb5b10c74ce7203491484404ef"}, + {file = "coverage-7.6.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b06079abebbc0e89e6163b8e8f0e16270124c154dc6e4a47b413dd538859af16"}, + {file = "coverage-7.6.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cf4b19715bccd7ee27b6b120e7e9dd56037b9c0681dcc1adc9ba9db3d417fa36"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e61c0abb4c85b095a784ef23fdd4aede7a2628478e7baba7c5e3deba61070a02"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fd21f6ae3f08b41004dfb433fa895d858f3f5979e7762d052b12aef444e29afc"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f59d57baca39b32db42b83b2a7ba6f47ad9c394ec2076b084c3f029b7afca23"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a1ac0ae2b8bd743b88ed0502544847c3053d7171a3cff9228af618a068ed9c34"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:e6a08c0be454c3b3beb105c0596ebdc2371fab6bb90c0c0297f4e58fd7e1012c"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:f5796e664fe802da4f57a168c85359a8fbf3eab5e55cd4e4569fbacecc903959"}, + {file = "coverage-7.6.1-cp310-cp310-win32.whl", hash = "sha256:7bb65125fcbef8d989fa1dd0e8a060999497629ca5b0efbca209588a73356232"}, + {file = "coverage-7.6.1-cp310-cp310-win_amd64.whl", hash = "sha256:3115a95daa9bdba70aea750db7b96b37259a81a709223c8448fa97727d546fe0"}, + {file = "coverage-7.6.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7dea0889685db8550f839fa202744652e87c60015029ce3f60e006f8c4462c93"}, + {file = "coverage-7.6.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ed37bd3c3b063412f7620464a9ac1314d33100329f39799255fb8d3027da50d3"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d85f5e9a5f8b73e2350097c3756ef7e785f55bd71205defa0bfdaf96c31616ff"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9bc572be474cafb617672c43fe989d6e48d3c83af02ce8de73fff1c6bb3c198d"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0c0420b573964c760df9e9e86d1a9a622d0d27f417e1a949a8a66dd7bcee7bc6"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1f4aa8219db826ce6be7099d559f8ec311549bfc4046f7f9fe9b5cea5c581c56"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:fc5a77d0c516700ebad189b587de289a20a78324bc54baee03dd486f0855d234"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:b48f312cca9621272ae49008c7f613337c53fadca647d6384cc129d2996d1133"}, + {file = "coverage-7.6.1-cp311-cp311-win32.whl", hash = "sha256:1125ca0e5fd475cbbba3bb67ae20bd2c23a98fac4e32412883f9bcbaa81c314c"}, + {file = "coverage-7.6.1-cp311-cp311-win_amd64.whl", hash = "sha256:8ae539519c4c040c5ffd0632784e21b2f03fc1340752af711f33e5be83a9d6c6"}, + {file = "coverage-7.6.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:95cae0efeb032af8458fc27d191f85d1717b1d4e49f7cb226cf526ff28179778"}, + {file = "coverage-7.6.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5621a9175cf9d0b0c84c2ef2b12e9f5f5071357c4d2ea6ca1cf01814f45d2391"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:260933720fdcd75340e7dbe9060655aff3af1f0c5d20f46b57f262ab6c86a5e8"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:07e2ca0ad381b91350c0ed49d52699b625aab2b44b65e1b4e02fa9df0e92ad2d"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c44fee9975f04b33331cb8eb272827111efc8930cfd582e0320613263ca849ca"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:877abb17e6339d96bf08e7a622d05095e72b71f8afd8a9fefc82cf30ed944163"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:3e0cadcf6733c09154b461f1ca72d5416635e5e4ec4e536192180d34ec160f8a"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c3c02d12f837d9683e5ab2f3d9844dc57655b92c74e286c262e0fc54213c216d"}, + {file = "coverage-7.6.1-cp312-cp312-win32.whl", hash = "sha256:e05882b70b87a18d937ca6768ff33cc3f72847cbc4de4491c8e73880766718e5"}, + {file = "coverage-7.6.1-cp312-cp312-win_amd64.whl", hash = "sha256:b5d7b556859dd85f3a541db6a4e0167b86e7273e1cdc973e5b175166bb634fdb"}, + {file = "coverage-7.6.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a4acd025ecc06185ba2b801f2de85546e0b8ac787cf9d3b06e7e2a69f925b106"}, + {file = "coverage-7.6.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a6d3adcf24b624a7b778533480e32434a39ad8fa30c315208f6d3e5542aeb6e9"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0c212c49b6c10e6951362f7c6df3329f04c2b1c28499563d4035d964ab8e08c"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6e81d7a3e58882450ec4186ca59a3f20a5d4440f25b1cff6f0902ad890e6748a"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:78b260de9790fd81e69401c2dc8b17da47c8038176a79092a89cb2b7d945d060"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a78d169acd38300060b28d600344a803628c3fd585c912cacc9ea8790fe96862"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:2c09f4ce52cb99dd7505cd0fc8e0e37c77b87f46bc9c1eb03fe3bc9991085388"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6878ef48d4227aace338d88c48738a4258213cd7b74fd9a3d4d7582bb1d8a155"}, + {file = "coverage-7.6.1-cp313-cp313-win32.whl", hash = "sha256:44df346d5215a8c0e360307d46ffaabe0f5d3502c8a1cefd700b34baf31d411a"}, + {file = "coverage-7.6.1-cp313-cp313-win_amd64.whl", hash = "sha256:8284cf8c0dd272a247bc154eb6c95548722dce90d098c17a883ed36e67cdb129"}, + {file = "coverage-7.6.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:d3296782ca4eab572a1a4eca686d8bfb00226300dcefdf43faa25b5242ab8a3e"}, + {file = "coverage-7.6.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:502753043567491d3ff6d08629270127e0c31d4184c4c8d98f92c26f65019962"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6a89ecca80709d4076b95f89f308544ec8f7b4727e8a547913a35f16717856cb"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a318d68e92e80af8b00fa99609796fdbcdfef3629c77c6283566c6f02c6d6704"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13b0a73a0896988f053e4fbb7de6d93388e6dd292b0d87ee51d106f2c11b465b"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:4421712dbfc5562150f7554f13dde997a2e932a6b5f352edcce948a815efee6f"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:166811d20dfea725e2e4baa71fffd6c968a958577848d2131f39b60043400223"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:225667980479a17db1048cb2bf8bfb39b8e5be8f164b8f6628b64f78a72cf9d3"}, + {file = "coverage-7.6.1-cp313-cp313t-win32.whl", hash = "sha256:170d444ab405852903b7d04ea9ae9b98f98ab6d7e63e1115e82620807519797f"}, + {file = "coverage-7.6.1-cp313-cp313t-win_amd64.whl", hash = "sha256:b9f222de8cded79c49bf184bdbc06630d4c58eec9459b939b4a690c82ed05657"}, + {file = "coverage-7.6.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6db04803b6c7291985a761004e9060b2bca08da6d04f26a7f2294b8623a0c1a0"}, + {file = "coverage-7.6.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f1adfc8ac319e1a348af294106bc6a8458a0f1633cc62a1446aebc30c5fa186a"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a95324a9de9650a729239daea117df21f4b9868ce32e63f8b650ebe6cef5595b"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b43c03669dc4618ec25270b06ecd3ee4fa94c7f9b3c14bae6571ca00ef98b0d3"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8929543a7192c13d177b770008bc4e8119f2e1f881d563fc6b6305d2d0ebe9de"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:a09ece4a69cf399510c8ab25e0950d9cf2b42f7b3cb0374f95d2e2ff594478a6"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:9054a0754de38d9dbd01a46621636689124d666bad1936d76c0341f7d71bf569"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:0dbde0f4aa9a16fa4d754356a8f2e36296ff4d83994b2c9d8398aa32f222f989"}, + {file = "coverage-7.6.1-cp38-cp38-win32.whl", hash = "sha256:da511e6ad4f7323ee5702e6633085fb76c2f893aaf8ce4c51a0ba4fc07580ea7"}, + {file = "coverage-7.6.1-cp38-cp38-win_amd64.whl", hash = "sha256:3f1156e3e8f2872197af3840d8ad307a9dd18e615dc64d9ee41696f287c57ad8"}, + {file = "coverage-7.6.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:abd5fd0db5f4dc9289408aaf34908072f805ff7792632250dcb36dc591d24255"}, + {file = "coverage-7.6.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:547f45fa1a93154bd82050a7f3cddbc1a7a4dd2a9bf5cb7d06f4ae29fe94eaf8"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:645786266c8f18a931b65bfcefdbf6952dd0dea98feee39bd188607a9d307ed2"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9e0b2df163b8ed01d515807af24f63de04bebcecbd6c3bfeff88385789fdf75a"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:609b06f178fe8e9f89ef676532760ec0b4deea15e9969bf754b37f7c40326dbc"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:702855feff378050ae4f741045e19a32d57d19f3e0676d589df0575008ea5004"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:2bdb062ea438f22d99cba0d7829c2ef0af1d768d1e4a4f528087224c90b132cb"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:9c56863d44bd1c4fe2abb8a4d6f5371d197f1ac0ebdee542f07f35895fc07f36"}, + {file = "coverage-7.6.1-cp39-cp39-win32.whl", hash = "sha256:6e2cd258d7d927d09493c8df1ce9174ad01b381d4729a9d8d4e38670ca24774c"}, + {file = "coverage-7.6.1-cp39-cp39-win_amd64.whl", hash = "sha256:06a737c882bd26d0d6ee7269b20b12f14a8704807a01056c80bb881a4b2ce6ca"}, + {file = "coverage-7.6.1-pp38.pp39.pp310-none-any.whl", hash = "sha256:e9a6e0eb86070e8ccaedfbd9d38fec54864f3125ab95419970575b42af7541df"}, + {file = "coverage-7.6.1.tar.gz", hash = "sha256:953510dfb7b12ab69d20135a0662397f077c59b1e6379a768e97c59d852ee51d"}, ] [package.dependencies] @@ -102,24 +122,24 @@ toml = ["tomli"] [[package]] name = "distlib" -version = "0.3.7" +version = "0.3.8" description = "Distribution utilities" optional = false python-versions = "*" files = [ - {file = "distlib-0.3.7-py2.py3-none-any.whl", hash = "sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057"}, - {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, + {file = "distlib-0.3.8-py2.py3-none-any.whl", hash = "sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784"}, + {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, ] [[package]] name = "exceptiongroup" -version = "1.1.3" +version = "1.2.2" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" files = [ - {file = "exceptiongroup-1.1.3-py3-none-any.whl", hash = "sha256:343280667a4585d195ca1cf9cef84a4e178c4b6cf2274caef9859782b567d5e3"}, - {file = "exceptiongroup-1.1.3.tar.gz", hash = "sha256:097acd85d473d75af5bb98e41b61ff7fe35efe6675e4f9370ec6ec5126d160e9"}, + {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"}, + {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"}, ] [package.extras] @@ -313,29 +333,29 @@ testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] [[package]] name = "ruff" -version = "0.5.7" +version = "0.6.0" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.5.7-py3-none-linux_armv6l.whl", hash = "sha256:548992d342fc404ee2e15a242cdbea4f8e39a52f2e7752d0e4cbe88d2d2f416a"}, - {file = "ruff-0.5.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:00cc8872331055ee017c4f1071a8a31ca0809ccc0657da1d154a1d2abac5c0be"}, - {file = "ruff-0.5.7-py3-none-macosx_11_0_arm64.whl", hash = "sha256:eaf3d86a1fdac1aec8a3417a63587d93f906c678bb9ed0b796da7b59c1114a1e"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a01c34400097b06cf8a6e61b35d6d456d5bd1ae6961542de18ec81eaf33b4cb8"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:fcc8054f1a717e2213500edaddcf1dbb0abad40d98e1bd9d0ad364f75c763eea"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7f70284e73f36558ef51602254451e50dd6cc479f8b6f8413a95fcb5db4a55fc"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:a78ad870ae3c460394fc95437d43deb5c04b5c29297815a2a1de028903f19692"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9ccd078c66a8e419475174bfe60a69adb36ce04f8d4e91b006f1329d5cd44bcf"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7e31c9bad4ebf8fdb77b59cae75814440731060a09a0e0077d559a556453acbb"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8d796327eed8e168164346b769dd9a27a70e0298d667b4ecee6877ce8095ec8e"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:4a09ea2c3f7778cc635e7f6edf57d566a8ee8f485f3c4454db7771efb692c499"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a36d8dcf55b3a3bc353270d544fb170d75d2dff41eba5df57b4e0b67a95bb64e"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9369c218f789eefbd1b8d82a8cf25017b523ac47d96b2f531eba73770971c9e5"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:b88ca3db7eb377eb24fb7c82840546fb7acef75af4a74bd36e9ceb37a890257e"}, - {file = "ruff-0.5.7-py3-none-win32.whl", hash = "sha256:33d61fc0e902198a3e55719f4be6b375b28f860b09c281e4bdbf783c0566576a"}, - {file = "ruff-0.5.7-py3-none-win_amd64.whl", hash = "sha256:083bbcbe6fadb93cd86709037acc510f86eed5a314203079df174c40bbbca6b3"}, - {file = "ruff-0.5.7-py3-none-win_arm64.whl", hash = "sha256:2dca26154ff9571995107221d0aeaad0e75a77b5a682d6236cf89a58c70b76f4"}, - {file = "ruff-0.5.7.tar.gz", hash = "sha256:8dfc0a458797f5d9fb622dd0efc52d796f23f0a1493a9527f4e49a550ae9a7e5"}, + {file = "ruff-0.6.0-py3-none-linux_armv6l.whl", hash = "sha256:92dcce923e5df265781e5fc76f9a1edad52201a7aafe56e586b90988d5239013"}, + {file = "ruff-0.6.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:31b90ff9dc79ed476c04e957ba7e2b95c3fceb76148f2079d0d68a908d2cfae7"}, + {file = "ruff-0.6.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:6d834a9ec9f8287dd6c3297058b3a265ed6b59233db22593379ee38ebc4b9768"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f2089267692696aba342179471831a085043f218706e642564812145df8b8d0d"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:aa62b423ee4bbd8765f2c1dbe8f6aac203e0583993a91453dc0a449d465c84da"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7344e1a964b16b1137ea361d6516ce4ee61a0403fa94252a1913ecc1311adcae"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:487f3a35c3f33bf82be212ce15dc6278ea854e35573a3f809442f73bec8b2760"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:75db409984077a793cf344d499165298a6f65449e905747ac65983b12e3e64b1"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:84908bd603533ecf1db456d8fc2665d1f4335d722e84bc871d3bbd2d1116c272"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0f1749a0aef3ec41ed91a0e2127a6ae97d2e2853af16dbd4f3c00d7a3af726c5"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:016fea751e2bcfbbd2f8cb19b97b37b3fd33148e4df45b526e87096f4e17354f"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:6ae80f141b53b2e36e230017e64f5ea2def18fac14334ffceaae1b780d70c4f7"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:eaaaf33ea4b3f63fd264d6a6f4a73fa224bbfda4b438ffea59a5340f4afa2bb5"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:7667ddd1fc688150a7ca4137140867584c63309695a30016880caf20831503a0"}, + {file = "ruff-0.6.0-py3-none-win32.whl", hash = "sha256:ae48365aae60d40865a412356f8c6f2c0be1c928591168111eaf07eaefa6bea3"}, + {file = "ruff-0.6.0-py3-none-win_amd64.whl", hash = "sha256:774032b507c96f0c803c8237ce7d2ef3934df208a09c40fa809c2931f957fe5e"}, + {file = "ruff-0.6.0-py3-none-win_arm64.whl", hash = "sha256:a5366e8c3ae6b2dc32821749b532606c42e609a99b0ae1472cf601da931a048c"}, + {file = "ruff-0.6.0.tar.gz", hash = "sha256:272a81830f68f9bd19d49eaf7fa01a5545c5a2e86f32a9935bb0e4bb9a1db5b8"}, ] [[package]] @@ -395,13 +415,13 @@ testing = ["black", "devpi-process", "flake8 (>=6,<7)", "mypy", "pytest (>=7,<8) [[package]] name = "typing-extensions" -version = "4.8.0" +version = "4.12.2" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" files = [ - {file = "typing_extensions-4.8.0-py3-none-any.whl", hash = "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0"}, - {file = "typing_extensions-4.8.0.tar.gz", hash = "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef"}, + {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, + {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, ] [[package]] @@ -427,4 +447,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.9.0" -content-hash = "337237a79db6181176db8fb106adb2728922c831a39857f8039f03d07835e955" +content-hash = "b22fc6df07b21a51ce7f516eda63067cfeb006e1f55ca7f82841fcb72b307215" diff --git a/pyproject.toml b/pyproject.toml index 89e692c..30e794b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ python = "^3.9.0" [tool.poetry.group.dev.dependencies] -mypy = "^1.6.1" +mypy = "^1.8.0" [tool.poetry.group.linters] @@ -80,7 +80,7 @@ optional = true [tool.poetry.group.linters.dependencies] -ruff = ">=0.5.0,<0.6.0" +ruff = "^0.6.0" [tool.poetry.group.tests] @@ -88,10 +88,10 @@ optional = true [tool.poetry.group.tests.dependencies] -pytest = ">=7.4.3,<9.0.0" -pytest-cov = ">=4.1,<6.0" -tox = "^4.11.3" -tox-gh-actions = "^3.1.3" +pytest = "^8.0.0" +pytest-cov = "^5.0.0" +tox = "^4.12.1" +tox-gh-actions = "^3.2.0" [tool.poetry.urls] @@ -116,67 +116,72 @@ testpaths = [ [tool.ruff] -select = [ - "A", # Builtins - "ANN", # Annotations - "ARG", # Unused arguments - "B", # Bugbear - "BLE", # Blind except - "C4", # Comprehensions - "C90", # mccabe - "COM", # Commas - "D1", # Undocumented public elements - "D2", # Docstring conventions - "D3", # Triple double quotes - "D4", # Docstring text format - "DTZ", # Datetimes - "EM", # Error messages - "ERA", # Commented-out code - "EXE", # Executable - "F", # Pyflakes - "FA", # __future__ annotations - "FLY", # F-strings - # "FURB", # Refurb - "G", # Logging format - "I", # Isort - "ICN", # Import conventions - "INP", # Disallow PEP-420 (Implicit namespace packages) - "INT", # gettext - "ISC", # Implicit str concat - # "LOG", # Logging - "N", # PEP-8 Naming - "NPY", # Numpy - "PERF", # Unnecessary performance costs - "PGH", # Pygrep hooks - "PIE", # Unnecessary code - "PL", # Pylint - "PT", # Pytest - "PTH", # Use Pathlib - "PYI", # Stub files - "Q", # Quotes - "RET", # Return - "RUF", # Ruff - "RSE", # Raise - "S", # Bandit - "SIM", # Code simplification - "SLF", # Private member access - "SLOT", # __slots__ - "T10", # Debugger - "T20", # Print - "TCH", # Type checking - "TID", # Tidy imports - "TRY", # Exception handling - "UP", # Pyupgrade - "W", # Warnings - "YTT", # sys.version +lint.select = [ + "A", # Builtins + "ANN", # Annotations + "ARG", # Unused arguments + "ASYNC", # Asynchronous code + "B", # Bugbear + "BLE", # Blind except + "C4", # Comprehensions + "C90", # mccabe + "COM", # Commas + # "CPY", # Copyright + "D1", # Undocumented public elements + "D2", # Docstring conventions + "D3", # Triple double quotes + "D4", # Docstring text format + "DTZ", # Datetimes + "E", # Errors + "EM", # Error messages + "ERA", # Commented-out code + "EXE", # Executable + "F", # Pyflakes + "FA", # __future__ annotations + "FBT", # "Boolean trap" + "FIX", # "FIXME"-comments + "FLY", # F-strings + # "FURB", # Refurb + "G", # Logging format + "I", # Isort + "ICN", # Import conventions + "INP", # Disallow PEP-420 (Implicit namespace packages) + "INT", # gettext + "ISC", # Implicit str concat + "LOG", # Logging + "N", # PEP-8 Naming + "PERF", # Unnecessary performance costs + "PGH", # Pygrep hooks + "PIE", # Unnecessary code + "PL", # Pylint + "PT", # Pytest + "PTH", # Use Pathlib + "PYI", # Stub files + "Q", # Quotes + "RET", # Return + "RUF", # Ruff + "RSE", # Raise + "S", # Bandit + "SIM", # Code simplification + "SLF", # Private member access + "SLOT", # __slots__ + "T10", # Debugger + "T20", # Print + "TCH", # Type checking + "TD", # "TODO"-comments + "TID", # Tidy imports + "TRY", # Exception handling + "UP", # Pyupgrade + "W", # Warnings + "YTT", # sys.version ] -ignore = [ +lint.ignore = [ + "ANN101", # Type annotation for `self` "D203", # One blank line before class docstring "D212", # Multi-line summary first line "PLR0913", # Too many arguments "Q000", # Single quotes found but double quotes preferred ] -ignore-init-module-imports = true line-length = 120 # preview = true show-fixes = true @@ -184,29 +189,33 @@ src = ["src",] target-version = "py39" -[tool.ruff.flake8-quotes] +[tool.ruff.lint.flake8-copyright] +author = "Lari Liuhamo" + + +[tool.ruff.lint.flake8-quotes] docstring-quotes = "double" multiline-quotes = "double" -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 10 -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # https://beta.ruff.rs/docs/rules/ "__init__.py" = ["F401", "F403", "F405",] "tests/*" = ["ANN", "ARG", "INP001", "S101",] -[tool.ruff.pylint] +[tool.ruff.lint.pylint] max-args = 15 max-branches = 20 max-returns = 10 max-statements = 80 -[tool.ruff.flake8-tidy-imports] +[tool.ruff.lint.flake8-tidy-imports] ban-relative-imports = "all" diff --git a/src/iplib3/address.py b/src/iplib3/address.py index 7d5572a..e672aac 100644 --- a/src/iplib3/address.py +++ b/src/iplib3/address.py @@ -2,6 +2,7 @@ from __future__ import annotations +from enum import IntFlag, auto from itertools import groupby from typing import TYPE_CHECKING @@ -35,33 +36,41 @@ __all__ = ('IPAddress', 'IPv4', 'IPv6') +class AddressFormat(IntFlag): + """Specify the address format.""" + + DEFAULT = auto() + SHORTEN = auto() + REMOVE_ZEROES = auto() + + class PureAddress: """Bare-bones, independent base class for IP addresses.""" __slots__ = ('_num', '_port') - def __init__(self: PureAddress, num: int | None = None, port: int | None = None) -> None: + def __init__(self, num: int | None = None, port: int | None = None) -> None: self._num: int = num if num is not None else 0 self._port: int | None = port if port_validator(port) else None - def __eq__(self: PureAddress, other: object) -> bool: + def __eq__(self, other: object) -> bool: if isinstance(other, PureAddress): return self.num == other.num and self.port == other.port return False - def __ne__(self: PureAddress, other: object) -> bool: + def __ne__(self, other: object) -> bool: return not self == other - def __repr__(self: PureAddress) -> str: + def __repr__(self) -> str: return f"iplib3.{self.__class__.__name__}('{self}')" - def __str__(self: PureAddress) -> str: + def __str__(self) -> str: return str(self.num) @property - def num(self: PureAddress) -> int: + def num(self) -> int: """ Negative numbers aren't valid, they are treated as zero. @@ -70,7 +79,7 @@ def num(self: PureAddress) -> int: return max(0, self._num) @property - def port(self: PureAddress) -> int | None: + def port(self) -> int | None: """ Return the port in the address, or None if no port is specified. @@ -82,7 +91,7 @@ def port(self: PureAddress) -> int | None: return min(max(PORT_NUMBER_MIN_VALUE, self._port), PORT_NUMBER_MAX_VALUE) @port.setter - def port(self: PureAddress, value: int | None) -> None: + def port(self, value: int | None) -> None: """ Set a new port value. Value must be a valid integer and within the range of valid ports. @@ -96,24 +105,22 @@ def port(self: PureAddress, value: int | None) -> None: raise TypeError(msg) elif not PORT_NUMBER_MIN_VALUE <= value <= PORT_NUMBER_MAX_VALUE: msg = f"Port number '{value}' not in valid range ({PORT_NUMBER_MIN_VALUE}-{PORT_NUMBER_MAX_VALUE})" - raise ValueError( - msg, - ) + raise ValueError(msg) self._port = value @property - def as_hex(self: PureAddress) -> str: + def as_hex(self) -> str: """Return a hexadecimal representation of the address.""" return f"0x{self.num:0X}" - def num_to_ipv4(self: PureAddress) -> str: + def num_to_ipv4(self) -> str: """Wrap method for the otherwise equivalent static method.""" return self._num_to_ipv4(self.num) - def num_to_ipv6(self: PureAddress, shorten: bool = True, remove_zeroes: bool = False) -> str: + def num_to_ipv6(self, address_format: AddressFormat = AddressFormat.SHORTEN) -> str: """Wrap method for the otherwise equivalent static method.""" - return self._num_to_ipv6(self.num, shorten, remove_zeroes) + return self._num_to_ipv6(self.num, address_format) @staticmethod def _num_to_ipv4(num: int) -> str: @@ -125,9 +132,12 @@ def _num_to_ipv4(num: int) -> str: return '.'.join(str(segment) for segment in segments[::-1]) @staticmethod - def _num_to_ipv6(num: int, shorten: bool = True, remove_zeroes: bool = False) -> str: + def _num_to_ipv6(num: int, address_format: AddressFormat) -> str: """Generate an IPv6 string from an integer, with optional zero removal and shortening.""" - segment_min_length = (IPV6_SEGMENT_BIT_COUNT // IPV6_NUMBER_BIT_COUNT) * (not shorten) + segment_min_length = ( + (IPV6_SEGMENT_BIT_COUNT // IPV6_NUMBER_BIT_COUNT) + * (AddressFormat.SHORTEN not in address_format) + ) zero_segment = f'{0:0{segment_min_length}}' segments = [] @@ -135,7 +145,7 @@ def _num_to_ipv6(num: int, shorten: bool = True, remove_zeroes: bool = False) -> num, segment = divmod(num, IPV6_MAX_SEGMENT_VALUE+1) segments.append(f'{segment:0{segment_min_length}X}') - if remove_zeroes and zero_segment in segments: + if AddressFormat.REMOVE_ZEROES in address_format and zero_segment in segments: # Goes over the segments to find the # longest strip with nothing but zeroes @@ -158,7 +168,10 @@ class IPAddress(PureAddress): __slots__ = ('_ipv4', '_ipv6', '_submask') - def __new__(cls: type[IPAddress], address: int | str | None = None, port_num: int | None = None, **kwargs) -> IPAddress: # noqa: ANN003,PYI034 + def __new__(cls: type[IPAddress], # noqa: PYI034 + address: int | str | None = None, + port_num: int | None = None, + **kwargs) -> IPAddress: # noqa: ANN003 """Create PureAddress.""" if isinstance(address, str): # Only IPv4-addresses have '.', ':' is used in both IPv4 and IPv6 @@ -169,14 +182,14 @@ def __new__(cls: type[IPAddress], address: int | str | None = None, port_num: in self.__init__(address=address, port_num=port_num, **kwargs) # type: ignore # noqa: PGH003 # mypy: ignore return self - def __init__(self: IPAddress, address: int | None = IPV4_LOCALHOST, port_num: int | None = None) -> None: + def __init__(self, address: int | None = IPV4_LOCALHOST, port_num: int | None = None) -> None: """Init PureAddres.""" super().__init__(num=address, port=port_num) self._ipv4: IPv4 | None = None self._ipv6: IPv6 | None = None self._submask: SubnetMask | None = None - def __eq__(self: IPAddress, other: object) -> bool: + def __eq__(self, other: object) -> bool: """Compare equality.""" # To accommodate strings if str(self) == str(other): @@ -184,7 +197,7 @@ def __eq__(self: IPAddress, other: object) -> bool: return super().__eq__(other) - def __str__(self: IPAddress) -> str: + def __str__(self) -> str: """Str variant.""" if IPV4_MIN_VALUE <= self.num <= IPV4_MAX_VALUE: if self._ipv4 is None: @@ -200,12 +213,12 @@ def __str__(self: IPAddress) -> str: raise ValueError(msg) @property - def as_ipv4(self: IPAddress) -> IPv4: + def as_ipv4(self) -> IPv4: """Creates and returns an IPv4 version of the address, if possible.""" return IPv4(self.num_to_ipv4(), port_num=self.port) # type: ignore # noqa: PGH003 @property - def as_ipv6(self: IPAddress) -> IPv6: + def as_ipv6(self) -> IPv6: """Creates and returns an IPv6-version of the address.""" return IPv6(self.num_to_ipv6(), port_num=self.port) # type: ignore # noqa: PGH003 @@ -215,7 +228,7 @@ class IPv4(IPAddress): __slots__ = ('_address',) - def __init__(self: IPv4, address: str | None = None, port_num: int | None = None) -> None: + def __init__(self, address: str | None = None, port_num: int | None = None) -> None: """Init IPv4.""" new_address = self._num_to_ipv4(IPV4_LOCALHOST) if address is None else address @@ -230,14 +243,14 @@ def __init__(self: IPv4, address: str | None = None, port_num: int | None = None self._address = new_address super().__init__(address=self._ipv4_to_num(), port_num=port_num) - def __str__(self: IPv4) -> str: + def __str__(self) -> str: """Str variant.""" if self.port is not None: return f"{self._address}:{self.port}" return self._address - def _ipv4_to_num(self: IPv4) -> int: + def _ipv4_to_num(self) -> int: """ Take a valid IPv4 address and turns it into an equivalent integer value. @@ -257,9 +270,9 @@ class IPv6(IPAddress): __slots__ = ('_address',) - def __init__(self: IPv6, address: str | None = None, port_num: int | None = None) -> None: + def __init__(self, address: str | None = None, port_num: int | None = None) -> None: """Init IPv6.""" - new_address = self._num_to_ipv6(IPV6_LOCALHOST) if address is None else address + new_address = self._num_to_ipv6(IPV6_LOCALHOST, AddressFormat.SHORTEN) if address is None else address _address, *_port = new_address.split(']:') @@ -274,14 +287,14 @@ def __init__(self: IPv6, address: str | None = None, port_num: int | None = None self._address = new_address super().__init__(address=self._ipv6_to_num(), port_num=port_num) - def __str__(self: IPv6) -> str: + def __str__(self) -> str: """Str variant.""" if self.port is not None: return f"[{self._address}]:{self.port}" return self._address - def _ipv6_to_num(self: IPv6) -> int: + def _ipv6_to_num(self) -> int: """ Take a valid IPv6 address and turns it into an equivalent integer value. diff --git a/src/iplib3/subnet.py b/src/iplib3/subnet.py index 9c29604..1908beb 100644 --- a/src/iplib3/subnet.py +++ b/src/iplib3/subnet.py @@ -67,7 +67,9 @@ class SubnetMask(PureSubnetMask): __slots__ = ('_subnet_type',) - def __init__(self: SubnetMask, subnet_mask: int | str | None = None, subnet_type: SubnetType = SubnetType.IPV6) -> None: + def __init__(self: SubnetMask, + subnet_mask: int | str | None = None, + subnet_type: SubnetType = SubnetType.IPV6) -> None: """Create SubnetMask.""" subnet_type = SubnetType(subnet_type) super().__init__() diff --git a/src/iplib3/validators.py b/src/iplib3/validators.py index ec33329..fb53052 100644 --- a/src/iplib3/validators.py +++ b/src/iplib3/validators.py @@ -2,6 +2,8 @@ from __future__ import annotations +from enum import IntEnum, auto + from iplib3.constants.ipv4 import ( IPV4_MAX_SEGMENT_COUNT, IPV4_MAX_SEGMENT_VALUE, @@ -34,6 +36,13 @@ __all__ = ('port_validator', 'ip_validator', 'ipv4_validator', 'ipv6_validator', 'subnet_validator') +class ValidationMode(IntEnum): + """Detemine the validation strictness.""" + + RELAXED = auto() + STRICT = auto() + + def port_validator(port_num: int | None) -> bool: """ Validate an address port. @@ -54,19 +63,19 @@ def port_validator(port_num: int | None) -> bool: ) -def ip_validator(address: str | int, strict: bool = True) -> bool: +def ip_validator(address: str | int, validation_mode: ValidationMode = ValidationMode.STRICT) -> bool: """ Validate an IP address of any kind, returning a boolean. Under strict mode ensures that the numerical values don't exceed legal bounds, otherwise focuses on form. """ - if ipv4_validator(address, strict): + if ipv4_validator(address, validation_mode): return True - return ipv6_validator(address, strict) + return ipv6_validator(address, validation_mode) -def ipv4_validator(address: str | int, strict: bool = True) -> bool: +def ipv4_validator(address: str | int, validation_mode: ValidationMode = ValidationMode.STRICT) -> bool: """ Validate an IPv4 address, returning a boolean. @@ -77,10 +86,10 @@ def ipv4_validator(address: str | int, strict: bool = True) -> bool: if isinstance(address, str) and '.' in address: - portless_address, _, valid = _port_stripper(address, protocol=SubnetType.IPV4, strict=strict) + portless_address, _, valid = _port_stripper(address, protocol=SubnetType.IPV4, validation_mode=validation_mode) if valid: - valid = _ipv4_address_validator(portless_address, strict=strict) + valid = _ipv4_address_validator(portless_address, validation_mode=validation_mode) if isinstance(address, int): valid = IPV4_MIN_VALUE <= address <= IPV4_MAX_VALUE @@ -88,7 +97,7 @@ def ipv4_validator(address: str | int, strict: bool = True) -> bool: return valid -def ipv6_validator(address: str | int, strict: bool = True) -> bool: +def ipv6_validator(address: str | int, validation_mode: ValidationMode = ValidationMode.STRICT) -> bool: """ Validate an IPv6 address, returning a boolean. @@ -99,12 +108,12 @@ def ipv6_validator(address: str | int, strict: bool = True) -> bool: if isinstance(address, str): - portless_address, _, valid = _port_stripper(address, protocol=SubnetType.IPV6, strict=strict) + portless_address, _, valid = _port_stripper(address, protocol=SubnetType.IPV6, validation_mode=validation_mode) if not valid: return valid - valid = _ipv6_address_validator(portless_address, strict=strict) + valid = _ipv6_address_validator(portless_address, validation_mode=validation_mode) if isinstance(address, int): valid = IPV6_MIN_VALUE <= address <= IPV6_MAX_VALUE @@ -186,7 +195,9 @@ def _ipv6_subnet_validator(subnet: int) -> bool: # IPv6 subnets have no string raise TypeError(msg) -def _port_stripper(address: str, protocol: SubnetType = SubnetType.IPV4, strict: bool = True) -> tuple[str, int | None, bool]: +def _port_stripper(address: str, + protocol: SubnetType = SubnetType.IPV4, + validation_mode: ValidationMode = ValidationMode.STRICT) -> tuple[str, int | None, bool]: """ Extract the port number from IP addresses, if any. @@ -218,13 +229,13 @@ def _port_stripper(address: str, protocol: SubnetType = SubnetType.IPV4, strict: except ValueError: valid = False - if strict and valid: + if validation_mode == ValidationMode.STRICT and valid: valid = port_validator(port_num) return address, port_num, valid -def _ipv4_address_validator(address: str, strict: bool = True) -> bool: +def _ipv4_address_validator(address: str, validation_mode: ValidationMode = ValidationMode.STRICT) -> bool: """Validate the address part of an IPv4 address.""" valid = True @@ -238,7 +249,7 @@ def _ipv4_address_validator(address: str, strict: bool = True) -> bool: # Invalid number of segments valid = False - elif strict: + elif validation_mode == ValidationMode.STRICT: for seg in segments: if not IPV4_MIN_SEGMENT_VALUE <= seg <= IPV4_MAX_SEGMENT_VALUE: # Segment value was too high or too low to be strictly valid @@ -248,7 +259,7 @@ def _ipv4_address_validator(address: str, strict: bool = True) -> bool: return valid -def _ipv6_address_validator(address: str, strict: bool = True) -> bool: +def _ipv6_address_validator(address: str, validation_mode: ValidationMode = ValidationMode.STRICT) -> bool: """Validate the address part of an IPv6 address.""" address = address.strip() valid = True @@ -289,7 +300,7 @@ def _ipv6_address_validator(address: str, strict: bool = True) -> bool: if len(processed_segments) != IPV6_MAX_SEGMENT_COUNT: valid = False - if strict and valid: + if validation_mode == ValidationMode.STRICT and valid: valid = all( IPV6_MIN_SEGMENT_VALUE <= seg <= IPV6_MAX_SEGMENT_VALUE for seg in processed_segments diff --git a/tests/test_address.py b/tests/test_address.py index 7cd4a7e..8b53891 100644 --- a/tests/test_address.py +++ b/tests/test_address.py @@ -3,7 +3,7 @@ import pytest from iplib3 import IPAddress -from iplib3.address import IPv6, PureAddress +from iplib3.address import AddressFormat, IPv6, PureAddress from iplib3.constants import IPV6_MAX_VALUE from tests.test_cases_address import ( TEST_CASES_IPADDRESS, @@ -37,7 +37,7 @@ "pure_address", TEST_CASES_PURE_ADDRESS, ) -def test_pure_address(pure_address): +def test_pure_address(pure_address: PureAddress): """Test the PureAddress base class.""" assert pure_address @@ -135,7 +135,7 @@ def test_pure_address_num_to_ipv6(pure_address, excepted_output): ) def test_pure_address_num_to_ipv6_no_shortening(pure_address, excepted_output): """Test PureAddress num to IPv6 string conversion without shortening.""" - assert pure_address.num_to_ipv6(shorten=False) == excepted_output + assert pure_address.num_to_ipv6(AddressFormat.DEFAULT) == excepted_output @pytest.mark.parametrize( @@ -144,12 +144,16 @@ def test_pure_address_num_to_ipv6_no_shortening(pure_address, excepted_output): ) def test_pure_address_num_to_ipv6_remove_zeroes(pure_address, excepted_output): """Test PureAddress num to IPv6 string conversion with empty segment removal.""" - assert pure_address.num_to_ipv6(remove_zeroes=True) == excepted_output + assert pure_address.num_to_ipv6(AddressFormat.REMOVE_ZEROES | AddressFormat.SHORTEN) == excepted_output def test_pure_address_num_to_ipv6_remove_zeroes_no_shortening(): """Test PureAddress num to IPv6 string conversion without shortening but segment removal applied.""" - assert PureAddress(0xBADC_0FFE_E0DD_F00D).num_to_ipv6(shorten=False, remove_zeroes=True) == '::BADC:0FFE:E0DD:F00D' + assert PureAddress( + 0xBADC_0FFE_E0DD_F00D, + ).num_to_ipv6( + address_format=AddressFormat.REMOVE_ZEROES, + ) == '::BADC:0FFE:E0DD:F00D' @pytest.mark.parametrize( @@ -215,7 +219,7 @@ def test_ipaddress_as_ipv6(ip_address, excepted_instance): @pytest.mark.parametrize( "input_ipv4", TEST_CASES_IPV4, ) -def test_ipv4(input_ipv4): +def test_ipv4(input_ipv4: IPAddress): """Test the IPv4 class.""" assert input_ipv4 @@ -241,7 +245,7 @@ def test_ipv4_ipv4_to_num(input_ipv4, excepted_output): @pytest.mark.parametrize( "input_ipv6", TEST_CASES_IPV6, ) -def test_ipv6(input_ipv6): +def test_ipv6(input_ipv6: IPAddress): """Test the IPv6 class.""" assert input_ipv6 diff --git a/tests/test_cases_address.py b/tests/test_cases_address.py index b9c1f6f..a8250ac 100644 --- a/tests/test_cases_address.py +++ b/tests/test_cases_address.py @@ -119,11 +119,11 @@ TEST_CASES_IPADDRESS = [ (IPAddress(), IPAddress), (IPAddress(IPV4_LOCALHOST), IPAddress), - (IPAddress(IP_ADDRESS_MASK[2]), IPv4), - (IPAddress(IP_ADDRESS_MASK[1]), IPv6), + (IPAddress(IP_ADDRESS_MASK[2]), IPv4), # type: ignore[arg-type] + (IPAddress(IP_ADDRESS_MASK[1]), IPv6), # type: ignore[arg-type] (IPAddress(IPV4_LOCALHOST, 80), IPAddress), - (IPAddress(IP_ADDRESS_MASK[2], 80), IPv4), - (IPAddress(IP_ADDRESS_MASK[1], 80), IPv6), + (IPAddress(IP_ADDRESS_MASK[2], 80), IPv4), # type: ignore[arg-type] + (IPAddress(IP_ADDRESS_MASK[1], 80), IPv6), # type: ignore[arg-type] ] TEST_CASES_IPADDRESS_EQUALITY = [ @@ -146,14 +146,14 @@ TEST_CASES_IPADDRESS_AS_IPV4 = [ (IPAddress(), IPv4), - (IPAddress(IP_ADDRESS_MASK[2]), IPv4), - (IPAddress(IP_ADDRESS_MASK[1]), IPv4), + (IPAddress(IP_ADDRESS_MASK[2]), IPv4), # type: ignore[arg-type] + (IPAddress(IP_ADDRESS_MASK[1]), IPv4), # type: ignore[arg-type] ] TEST_CASES_IPADDRESS_AS_IPV6 = [ (IPAddress(), IPv6), - (IPAddress(IP_ADDRESS_MASK[2]), IPv6), - (IPAddress(IP_ADDRESS_MASK[1]), IPv6), + (IPAddress(IP_ADDRESS_MASK[2]), IPv6), # type: ignore[arg-type] + (IPAddress(IP_ADDRESS_MASK[1]), IPv6), # type: ignore[arg-type] ] TEST_CASES_IPV4 = [ diff --git a/tests/test_cases_validators.py b/tests/test_cases_validators.py index 19a5fdd..0d57b29 100644 --- a/tests/test_cases_validators.py +++ b/tests/test_cases_validators.py @@ -12,6 +12,7 @@ PORT_NUMBER_MAX_VALUE, PORT_NUMBER_MIN_VALUE, ) +from iplib3.validators import ValidationMode VALID_IPV4_ADDRESSES_STRICT = [ '127.0.0.1', @@ -91,53 +92,53 @@ ] TEST_CASES_IPV4_VALIDATOR = [ - (VALID_IPV4_ADDRESSES_STRICT[1], True, True), - (VALID_IPV4_ADDRESSES_STRICT[2], True, True), - (VALID_IPV4_ADDRESSES_STRICT[3], True, True), - (f'{VALID_IPV4_ADDRESSES_STRICT[4]}:{PORT_NUMBERS_VALID[14]}', True, True), - (VALID_IPV4_ADDRESSES_LOOSE[0], True, False), - (INVALID_IPV4_ADDRESSES[0], True, False), - (INVALID_IPV4_ADDRESSES[1], False, False), - (INVALID_IPV4_ADDRESSES[2], True, False), - ([127, 0, 0, 1], True, False), - (VALID_IPV4_ADDRESSES_LOOSE[1], True, False), - (f'{VALID_IPV4_ADDRESSES_STRICT[1]}:{PORT_NUMBERS_INVALID[2]}', True, False), - (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:notaport', True, False), - (VALID_IPV4_ADDRESSES_LOOSE[1], False, True), - (f'{VALID_IPV4_ADDRESSES_LOOSE[1]}:{PORT_NUMBERS_INVALID[2]}', False, True), - (25601440, True, True), - (0xDEADBEEF, True, True), - (25601440, False, True), - (0xDEADBEEF, False, True), - (IPV4_MIN_VALUE, True, True), - (IPV4_MAX_VALUE, True, True), - (IPV4_MIN_VALUE - 1, True, False), - (IPV4_MAX_VALUE + 1, True, False), - (256014.40, True, False), + (VALID_IPV4_ADDRESSES_STRICT[1], ValidationMode.STRICT, True), + (VALID_IPV4_ADDRESSES_STRICT[2], ValidationMode.STRICT, True), + (VALID_IPV4_ADDRESSES_STRICT[3], ValidationMode.STRICT, True), + (f'{VALID_IPV4_ADDRESSES_STRICT[4]}:{PORT_NUMBERS_VALID[14]}', ValidationMode.STRICT, True), + (VALID_IPV4_ADDRESSES_LOOSE[0], ValidationMode.STRICT, False), + (INVALID_IPV4_ADDRESSES[0], ValidationMode.STRICT, False), + (INVALID_IPV4_ADDRESSES[1], ValidationMode.RELAXED, False), + (INVALID_IPV4_ADDRESSES[2], ValidationMode.STRICT, False), + ([127, 0, 0, 1], ValidationMode.STRICT, False), + (VALID_IPV4_ADDRESSES_LOOSE[1], ValidationMode.STRICT, False), + (f'{VALID_IPV4_ADDRESSES_STRICT[1]}:{PORT_NUMBERS_INVALID[2]}', ValidationMode.STRICT, False), + (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:notaport', ValidationMode.STRICT, False), + (VALID_IPV4_ADDRESSES_LOOSE[1], ValidationMode.RELAXED, True), + (f'{VALID_IPV4_ADDRESSES_LOOSE[1]}:{PORT_NUMBERS_INVALID[2]}', ValidationMode.RELAXED, True), + (25601440, ValidationMode.STRICT, True), + (0xDEADBEEF, ValidationMode.STRICT, True), + (25601440, ValidationMode.RELAXED, True), + (0xDEADBEEF, ValidationMode.RELAXED, True), + (IPV4_MIN_VALUE, ValidationMode.STRICT, True), + (IPV4_MAX_VALUE, ValidationMode.STRICT, True), + (IPV4_MIN_VALUE - 1, ValidationMode.STRICT, False), + (IPV4_MAX_VALUE + 1, ValidationMode.STRICT, False), + (256014.40, ValidationMode.STRICT, False), ] TEST_CASES_IPV6_VALIDATOR = [ - ('0:0:0:0:0:0:0:0', True, True), - ('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', True, True), - ('[0:0:0:0:0:0:0:0]:80', True, True), - (f'[FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF]:{PORT_NUMBER_MAX_VALUE}', True, True), - ('::12', True, True), - ('314::', True, True), - ('2606:4700:4700::1111', True, True), - ('2606:4700:4700::10000', False, True), - ('2606:4700:4700::10000', True, False), - ('2606:4700::4700::1111', True, False), - ('2606:4700:4700::HACK', True, False), - ('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0001', True, False), - ('2606:4700:4700:1111', True, False), - ([2606, 4700, 4700, 0, 0, 0, 0, 1111], True, False), - ('[2606:4700:4700::1111]:notaport', True, False), - (f'[2606:4700:4700::1111]:{PORT_NUMBERS_INVALID[3]}', True, False), - (f'[2606:4700:4700::1111]:{PORT_NUMBERS_INVALID[2]}', True, False), - (IPV6_MIN_VALUE, True, True), - (IPV6_MAX_VALUE, True, True), - (IPV6_MIN_VALUE - 1, True, False), - (IPV6_MAX_VALUE + 1, True, False), + ('0:0:0:0:0:0:0:0', ValidationMode.STRICT, True), + ('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', ValidationMode.STRICT, True), + ('[0:0:0:0:0:0:0:0]:80', ValidationMode.STRICT, True), + (f'[FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF]:{PORT_NUMBER_MAX_VALUE}', ValidationMode.STRICT, True), + ('::12', ValidationMode.STRICT, True), + ('314::', ValidationMode.STRICT, True), + ('2606:4700:4700::1111', ValidationMode.STRICT, True), + ('2606:4700:4700::10000', ValidationMode.RELAXED, True), + ('2606:4700:4700::10000', ValidationMode.STRICT, False), + ('2606:4700::4700::1111', ValidationMode.STRICT, False), + ('2606:4700:4700::HACK', ValidationMode.STRICT, False), + ('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0001', ValidationMode.STRICT, False), + ('2606:4700:4700:1111', ValidationMode.STRICT, False), + ([2606, 4700, 4700, 0, 0, 0, 0, 1111], ValidationMode.STRICT, False), + ('[2606:4700:4700::1111]:notaport', ValidationMode.STRICT, False), + (f'[2606:4700:4700::1111]:{PORT_NUMBERS_INVALID[3]}', ValidationMode.STRICT, False), + (f'[2606:4700:4700::1111]:{PORT_NUMBERS_INVALID[2]}', ValidationMode.STRICT, False), + (IPV6_MIN_VALUE, ValidationMode.STRICT, True), + (IPV6_MAX_VALUE, ValidationMode.STRICT, True), + (IPV6_MIN_VALUE - 1, ValidationMode.STRICT, False), + (IPV6_MAX_VALUE + 1, ValidationMode.STRICT, False), ] TEST_CASES_SUBNET_VALIDATOR = [ @@ -200,10 +201,10 @@ ] TEST_CASES_PORT_STRIPPER_IPV4 = [ - (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:{PORT_NUMBERS_VALID[14]}', 'ipv4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[14], True), - (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:{PORT_NUMBERS_VALID[14]}', 'IPv4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[14], True), - (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:{PORT_NUMBERS_VALID[14]}', 'IPV4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[14], True), - (f'{VALID_IPV4_ADDRESSES_STRICT[5]}:{PORT_NUMBERS_VALID[8]}', 'ipv4', VALID_IPV4_ADDRESSES_STRICT[5], PORT_NUMBERS_VALID[8], True), + (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:{PORT_NUMBERS_VALID[14]}', 'ipv4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[14], True), # noqa: E501 + (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:{PORT_NUMBERS_VALID[14]}', 'IPv4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[14], True), # noqa: E501 + (f'{VALID_IPV4_ADDRESSES_STRICT[0]}:{PORT_NUMBERS_VALID[14]}', 'IPV4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[14], True), # noqa: E501 + (f'{VALID_IPV4_ADDRESSES_STRICT[5]}:{PORT_NUMBERS_VALID[8]}', 'ipv4', VALID_IPV4_ADDRESSES_STRICT[5], PORT_NUMBERS_VALID[8], True), # noqa: E501 (VALID_IPV4_ADDRESSES_STRICT[0], 'ipv4', VALID_IPV4_ADDRESSES_STRICT[0], PORT_NUMBERS_VALID[0], True), (VALID_IPV4_ADDRESSES_STRICT[5], 'ipv4', VALID_IPV4_ADDRESSES_STRICT[5], PORT_NUMBERS_VALID[0], True), ] diff --git a/tests/test_validators.py b/tests/test_validators.py index 72d0f02..7b7be78 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -46,21 +46,21 @@ def test_ip_validator(address, excepted_output): @pytest.mark.parametrize( - ("address", "strict", "excepted_output"), + ("address", "validation_mode", "excepted_output"), TEST_CASES_IPV4_VALIDATOR, ) -def test_ipv4_validator(address, strict, excepted_output): +def test_ipv4_validator(address, validation_mode, excepted_output): """Test IPv4 validator.""" - assert ipv4_validator(address=address, strict=strict) is excepted_output + assert ipv4_validator(address=address, validation_mode=validation_mode) is excepted_output @pytest.mark.parametrize( - ("address", "strict", "excepted_output"), + ("address", "validation_mode", "excepted_output"), TEST_CASES_IPV6_VALIDATOR, ) -def test_ipv6_validator(address, strict, excepted_output): +def test_ipv6_validator(address, validation_mode, excepted_output): """Test IPv6 validator.""" - assert ipv6_validator(address=address, strict=strict) is excepted_output + assert ipv6_validator(address=address, validation_mode=validation_mode) is excepted_output @pytest.mark.parametrize(