diff --git a/.vscode/settings.json b/.vscode/settings.json index fb033e438..7269e9bbd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,18 +1,28 @@ { "python.pythonPath": ".venv/bin/python", "cSpell.words": [ + "DEVMODE", + "ECDSA", "INET", + "SIOP", "aktau", "bufid", + "cmmd", "cmmt", "distro", "dscp", + "fileng", "gaocegege", "ipsuite", + "lrfc", + "plen", "prio", + "protos", "pval", "pyenv", + "renm", "srcport", + "subd", "sufs", "tbitem", "tbody" diff --git a/MANIFEST.in b/MANIFEST.in index 45b2c1f6c..700f46aaf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,8 +3,16 @@ global-exclude .DS_Store global-include *.md global-include *.py +prune .venv +prune archive +prune devel +prune release +prune src +prune test +prune testbench + include README.md include LICENSE prune pcapkit/protocols/*/NotImplemented -prune pcapkit/vendor +# prune pcapkit/vendor diff --git a/Pipfile b/Pipfile index 4bf0e46af..586a28ac6 100644 --- a/Pipfile +++ b/Pipfile @@ -1,7 +1,17 @@ [[source]] -url = "https://pypi.org/simple" +name = "tuna" +url = "https://pypi.tuna.tsinghua.edu.cn/simple" +verify_ssl = true + +[[source]] +name = "sjtu" +url = "https://mirrors.sjtug.sjtu.edu.cn/pypi/web/simple" verify_ssl = true + +[[source]] name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true [packages] chardet = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 7d1a0988d..a155d45d8 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,13 +1,23 @@ { "_meta": { "hash": { - "sha256": "3fa4db4f0b5ba86e042f24d6e57dc106bb531359a29e89eeb70c5978f9b6bd60" + "sha256": "e4104537ffdf1c94c747153f386d31cbc453f7320fe0a7d3b889501114f0dfb8" }, "pipfile-spec": 6, "requires": { "python_version": "3.7" }, "sources": [ + { + "name": "tuna", + "url": "https://pypi.tuna.tsinghua.edu.cn/simple", + "verify_ssl": true + }, + { + "name": "sjtu", + "url": "https://mirrors.sjtug.sjtu.edu.cn/pypi/web/simple", + "verify_ssl": true + }, { "name": "pypi", "url": "https://pypi.org/simple", @@ -22,7 +32,7 @@ "sha256:b12a7be3d89b270f266f8643aaa126404e5cdc0929bd6f09548b8eaed85e2aa1", "sha256:e4dab068cbe00295bbc3660cd562221b008687d0f7a4c40fc2dd7a80002126a7" ], - "index": "pypi", + "index": "tuna", "version": "==2.2.1" }, "chardet": { @@ -30,35 +40,22 @@ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" ], - "index": "pypi", + "index": "tuna", "version": "==3.0.4" }, "dictdumper": { "hashes": [ - "sha256:1453b3dc017eecf177909d11e084a6c8eeb5bd980d6ddf78d44d4bf9ceb24f46", - "sha256:335e8bd44ce2b3a1e2132ad16745b75e16d86284b17925088129d0f8bf93e976", - "sha256:803eeb6fedf92812b97ff79cb0cae021e2316f1c7374da3cff68691dd2204620", - "sha256:8205854aaeb6c1a90adab51e24542ee5e824613c86594f34cd2fb6c843f62a60", - "sha256:8ce423d37f5204f0709ae025b5edc4a91d974aff6b710ed66605b3acd2a10955", - "sha256:a57e9edc720b6d99a4747aba3a1e01ace95236c43092d184d1355518912aee80", - "sha256:ac48e337fcab1e4934bbbbc09d98d93a037d4f12f0f29074a901a1fa00238c94", - "sha256:bffa44a460fa685fd2ef9433fe6ce02bf8009904ceefac8fdc0b846b378e1443", - "sha256:c0c76d9de181b768a53d3603b6f02e2536b979606bb035e6ef10580bbb11be39", - "sha256:c8c42d3540e75f533031dc29c32e0fd838982f2c024f92af0b400c83b2db66a2", - "sha256:d168a5f34823987b800811402f8b2c6a23074ba8677c393efb61e104b9e6d05a", - "sha256:dcfc9ea2917252f46150483814d6d2babb33412f6667f39b8881e1441156f3f0", - "sha256:dd7575db24e6f1a2b9278389df000a6db8fba4c45a92398c7e6d3e5fa575a3ab", - "sha256:ec79a036569c7867fd121132ffd65bb07c974f1d7cbc0c44105cd45a55f4509c", - "sha256:f028983cb749762c98f2c50a6463dcc74c9b5ad77ae9bbc3fbbc2d04f70e508f" - ], - "index": "pypi", - "version": "==0.7.0.post2" + "sha256:6e087f3b40d04462797d5f3b79d0d511cf12724803d5802b73cc9ea48ae56e3d", + "sha256:861c836e7cd74ac7c5ef3e40839e8279c5cd96edb196daf1400cf3e69c698014" + ], + "index": "tuna", + "version": "==0.7.1" }, "emoji": { "hashes": [ "sha256:b68112d40482a05e5da5d53da33d0aba3cce96891282c9c179cc340003c6c64e" ], - "index": "pypi", + "index": "tuna", "version": "==0.5.3" }, "tbtrim": { @@ -66,7 +63,7 @@ "sha256:860839d7296298a8823b3a0ac49a7f29424819d1481b5521329d339eac062bb9", "sha256:b0810edfb5dcf94c5fe3335a8a8e18ae38a411f6ff6afca188c66ac72444218f" ], - "index": "pypi", + "index": "tuna", "version": "==0.2.1" } }, @@ -77,7 +74,7 @@ "sha256:b12a7be3d89b270f266f8643aaa126404e5cdc0929bd6f09548b8eaed85e2aa1", "sha256:e4dab068cbe00295bbc3660cd562221b008687d0f7a4c40fc2dd7a80002126a7" ], - "index": "pypi", + "index": "tuna", "version": "==2.2.1" }, "appnope": { @@ -99,7 +96,7 @@ "hashes": [ "sha256:4d8eec30cc81bc5617dbf1218201d770dc35629363547f17577c61683ccfb3ee" ], - "index": "pypi", + "index": "tuna", "version": "==1.4.4" }, "backcall": { @@ -121,7 +118,7 @@ "hashes": [ "sha256:36ecea1fd7cc5c0c6e4a1ff075df26d50da647b75376626cc186e2212886dd3a" ], - "index": "pypi", + "index": "tuna", "version": "==0.0.1" }, "certifi": { @@ -136,7 +133,7 @@ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" ], - "index": "pypi", + "index": "tuna", "version": "==3.0.4" }, "decorator": { @@ -148,38 +145,25 @@ }, "dictdumper": { "hashes": [ - "sha256:1453b3dc017eecf177909d11e084a6c8eeb5bd980d6ddf78d44d4bf9ceb24f46", - "sha256:335e8bd44ce2b3a1e2132ad16745b75e16d86284b17925088129d0f8bf93e976", - "sha256:803eeb6fedf92812b97ff79cb0cae021e2316f1c7374da3cff68691dd2204620", - "sha256:8205854aaeb6c1a90adab51e24542ee5e824613c86594f34cd2fb6c843f62a60", - "sha256:8ce423d37f5204f0709ae025b5edc4a91d974aff6b710ed66605b3acd2a10955", - "sha256:a57e9edc720b6d99a4747aba3a1e01ace95236c43092d184d1355518912aee80", - "sha256:ac48e337fcab1e4934bbbbc09d98d93a037d4f12f0f29074a901a1fa00238c94", - "sha256:bffa44a460fa685fd2ef9433fe6ce02bf8009904ceefac8fdc0b846b378e1443", - "sha256:c0c76d9de181b768a53d3603b6f02e2536b979606bb035e6ef10580bbb11be39", - "sha256:c8c42d3540e75f533031dc29c32e0fd838982f2c024f92af0b400c83b2db66a2", - "sha256:d168a5f34823987b800811402f8b2c6a23074ba8677c393efb61e104b9e6d05a", - "sha256:dcfc9ea2917252f46150483814d6d2babb33412f6667f39b8881e1441156f3f0", - "sha256:dd7575db24e6f1a2b9278389df000a6db8fba4c45a92398c7e6d3e5fa575a3ab", - "sha256:ec79a036569c7867fd121132ffd65bb07c974f1d7cbc0c44105cd45a55f4509c", - "sha256:f028983cb749762c98f2c50a6463dcc74c9b5ad77ae9bbc3fbbc2d04f70e508f" - ], - "index": "pypi", - "version": "==0.7.0.post2" + "sha256:6e087f3b40d04462797d5f3b79d0d511cf12724803d5802b73cc9ea48ae56e3d", + "sha256:861c836e7cd74ac7c5ef3e40839e8279c5cd96edb196daf1400cf3e69c698014" + ], + "index": "tuna", + "version": "==0.7.1" }, "dpkt": { "hashes": [ "sha256:472c8fbf992f913cee2760fed8fb4253a600d7fb2210c793e2c0c0c23eb3b629", "sha256:52a92ecd5ca04d5bd852bb11cb2eac4bbe38b42a7c472e0d950eeb9f82a81e54" ], - "index": "pypi", + "index": "tuna", "version": "==1.9.2" }, "emoji": { "hashes": [ "sha256:b68112d40482a05e5da5d53da33d0aba3cce96891282c9c179cc340003c6c64e" ], - "index": "pypi", + "index": "tuna", "version": "==0.5.3" }, "f2format": { @@ -187,7 +171,7 @@ "sha256:d0ae4ca7d68e9863bd3e705f6ef80604b4aab7c12524dd99adbb5994917d1cb1", "sha256:e11951aefb9d9fc178c15f3ddac38bf2bbd1e6e214f03865b2c71cd975fc9fad" ], - "index": "pypi", + "index": "tuna", "version": "==0.8.2" }, "html5lib": { @@ -195,7 +179,7 @@ "sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3", "sha256:66cb0dcfdbbc4f9c3ba1a63fdb511ffdbd4f513b2b6d81b80cd26ce6b3fb3736" ], - "index": "pypi", + "index": "tuna", "version": "==1.0.1" }, "idna": { @@ -210,7 +194,7 @@ "sha256:1d3a1692921e932751bc1a1f7bb96dc38671eeefdc66ed33ee4cbc57e92a410e", "sha256:537cd0176ff6abd06ef3e23f2d0c4c2c8a4d9277b7451544c6cbf56d1c79a83d" ], - "index": "pypi", + "index": "tuna", "version": "==7.7.0" }, "ipython-genutils": { @@ -229,66 +213,60 @@ }, "jedi": { "hashes": [ - "sha256:53c850f1a7d3cfcd306cc513e2450a54bdf5cacd7604b74e42dd1f0758eaaf36", - "sha256:e07457174ef7cb2342ff94fa56484fe41cec7ef69b0059f01d3f812379cb6f7c" + "sha256:786b6c3d80e2f06fd77162a07fed81b8baa22dde5d62896a790a331d6ac21a27", + "sha256:ba859c74fa3c966a22f2aeebe1b74ee27e2a462f56d3f5f7ca4a59af61bfe42e" ], - "version": "==0.14.1" + "version": "==0.15.1" }, "lazy-object-proxy": { "hashes": [ - "sha256:159a745e61422217881c4de71f9eafd9d703b93af95618635849fe469a283661", - "sha256:23f63c0821cc96a23332e45dfaa83266feff8adc72b9bcaef86c202af765244f", - "sha256:3b11be575475db2e8a6e11215f5aa95b9ec14de658628776e10d96fa0b4dac13", - "sha256:3f447aff8bc61ca8b42b73304f6a44fa0d915487de144652816f950a3f1ab821", - "sha256:4ba73f6089cd9b9478bc0a4fa807b47dbdb8fad1d8f31a0f0a5dbf26a4527a71", - "sha256:4f53eadd9932055eac465bd3ca1bd610e4d7141e1278012bd1f28646aebc1d0e", - "sha256:64483bd7154580158ea90de5b8e5e6fc29a16a9b4db24f10193f0c1ae3f9d1ea", - "sha256:6f72d42b0d04bfee2397aa1862262654b56922c20a9bb66bb76b6f0e5e4f9229", - "sha256:7c7f1ec07b227bdc561299fa2328e85000f90179a2f44ea30579d38e037cb3d4", - "sha256:7c8b1ba1e15c10b13cad4171cfa77f5bb5ec2580abc5a353907780805ebe158e", - "sha256:8559b94b823f85342e10d3d9ca4ba5478168e1ac5658a8a2f18c991ba9c52c20", - "sha256:a262c7dfb046f00e12a2bdd1bafaed2408114a89ac414b0af8755c696eb3fc16", - "sha256:acce4e3267610c4fdb6632b3886fe3f2f7dd641158a843cf6b6a68e4ce81477b", - "sha256:be089bb6b83fac7f29d357b2dc4cf2b8eb8d98fe9d9ff89f9ea6012970a853c7", - "sha256:bfab710d859c779f273cc48fb86af38d6e9210f38287df0069a63e40b45a2f5c", - "sha256:c10d29019927301d524a22ced72706380de7cfc50f767217485a912b4c8bd82a", - "sha256:dd6e2b598849b3d7aee2295ac765a578879830fb8966f70be8cd472e6069932e", - "sha256:e408f1eacc0a68fed0c08da45f31d0ebb38079f043328dce69ff133b95c29dc1" - ], - "version": "==1.4.1" - }, - "logbook": { - "hashes": [ - "sha256:a5a96792abd8172c80d61b7530e134524f20e2841981038031e602ed5920fef5" - ], - "version": "==1.4.3" + "sha256:02b260c8deb80db09325b99edf62ae344ce9bc64d68b7a634410b8e9a568edbf", + "sha256:18f9c401083a4ba6e162355873f906315332ea7035803d0fd8166051e3d402e3", + "sha256:1f2c6209a8917c525c1e2b55a716135ca4658a3042b5122d4e3413a4030c26ce", + "sha256:2f06d97f0ca0f414f6b707c974aaf8829c2292c1c497642f63824119d770226f", + "sha256:616c94f8176808f4018b39f9638080ed86f96b55370b5a9463b2ee5c926f6c5f", + "sha256:63b91e30ef47ef68a30f0c3c278fbfe9822319c15f34b7538a829515b84ca2a0", + "sha256:77b454f03860b844f758c5d5c6e5f18d27de899a3db367f4af06bec2e6013a8e", + "sha256:83fe27ba321e4cfac466178606147d3c0aa18e8087507caec78ed5a966a64905", + "sha256:84742532d39f72df959d237912344d8a1764c2d03fe58beba96a87bfa11a76d8", + "sha256:874ebf3caaf55a020aeb08acead813baf5a305927a71ce88c9377970fe7ad3c2", + "sha256:9f5caf2c7436d44f3cec97c2fa7791f8a675170badbfa86e1992ca1b84c37009", + "sha256:a0c8758d01fcdfe7ae8e4b4017b13552efa7f1197dd7358dc9da0576f9d0328a", + "sha256:a4def978d9d28cda2d960c279318d46b327632686d82b4917516c36d4c274512", + "sha256:ad4f4be843dace866af5fc142509e9b9817ca0c59342fdb176ab6ad552c927f5", + "sha256:ae33dd198f772f714420c5ab698ff05ff900150486c648d29951e9c70694338e", + "sha256:b4a2b782b8a8c5522ad35c93e04d60e2ba7f7dcb9271ec8e8c3e08239be6c7b4", + "sha256:c462eb33f6abca3b34cdedbe84d761f31a60b814e173b98ede3c81bb48967c4f", + "sha256:fd135b8d35dfdcdb984828c84d695937e58cc5f49e1c854eb311c4d6aa03f4f1" + ], + "version": "==1.4.2" }, "lxml": { "hashes": [ - "sha256:06e5599b9c54f797a3c0f384c67705a0d621031007aa2400a6c7d17300fdb995", - "sha256:092237cfe4ece074401b75001a2e525fa6e1fb9d40fee8b7b132b1947d3bd2f8", - "sha256:0b6d49d0a26fe8207df8dd27c40b75be4deb2277173903aa76ec3e82df77cbe7", - "sha256:0f77061c20b4f32b1cf39e8f661c74e966344084c996e7b23c3a94e472461df0", - "sha256:0fef86edfa2f146b4b0ae2c6c05c3e4a8f3388b3655eafbc4aab3247f4dabb24", - "sha256:2f163c8844db4ed06a230ef092e2461ad01830972a896b8f3cf8b5bac70ae85d", - "sha256:350333190052bbfbc3222b1805b59b7979d7276e57af2257367e15a2db27082d", - "sha256:3b57dc5ed7b6a7d852c961f2389ca99404c2b59fd2088baec6fbaca02f688be4", - "sha256:3e86e5df4a8edd6f725f3c76f1d45e046d4f3aa40478092e4f5f373ad1f526e2", - "sha256:43dac60d10341d3e56be089cd0798b70e70d45ce32279f4c3190d8cbd71350e4", - "sha256:4665ee84ac8ba11d58f1ed517e29ea8536b4ae4e0c6fb6c7d3dce70abcd279f0", - "sha256:5033cf606a7cb559db967689b1b2e743994000f783607ba4c484e90917395ad7", - "sha256:75d731af05bf40f808d7716e0d26b4b02913402f861c032ce8c36efca350ae72", - "sha256:7720174604c7647e357566ac9e4d135c137caed5e7b01223551a4c81c8dc8b9a", - "sha256:b33ec641309bcea40c76c1b105f988e4e8f9a2f1ee1486aa5c0eeef33956c9bb", - "sha256:d1135dc0ac197242028ede085b693ba1f2bff7f0f9b91080e2540348312bfa53", - "sha256:d5a61e9c2322b45f259909a02b76bc98c4641214e22a37191d00c151aa9cdb9a", - "sha256:da22c4b17bc17dad9c8faf6d94c8fe568ac71c867a56631ab874da418fc7f8f7", - "sha256:da5c48ec9f8d8b5df42d328b6d1fb8d9413cd664a2367ef4f6f7cc48ee5b82c0", - "sha256:db2794bad21b7b30b6849b4e1537171cae8a7087711d958d69c233470dc612e7", - "sha256:f1c2f67df727034f94ccb590142d1d110f3dd38f638a4f1567fdd9f39892ba05", - "sha256:f840dddded8b046edc774c88ed8d2442cdb231a68894c42c74e3a809450fae76" - ], - "version": "==4.4.0" + "sha256:02ca7bf899da57084041bb0f6095333e4d239948ad3169443f454add9f4e9cb4", + "sha256:096b82c5e0ea27ce9138bcbb205313343ee66a6e132f25c5ed67e2c8d960a1bc", + "sha256:0a920ff98cf1aac310470c644bc23b326402d3ef667ddafecb024e1713d485f1", + "sha256:17cae1730a782858a6e2758fd20dd0ef7567916c47757b694a06ffafdec20046", + "sha256:17e3950add54c882e032527795c625929613adbd2ce5162b94667334458b5a36", + "sha256:1f4f214337f6ee5825bf90a65d04d70aab05526c08191ab888cb5149501923c5", + "sha256:2e8f77db25b0a96af679e64ff9bf9dddb27d379c9900c3272f3041c4d1327c9d", + "sha256:4dffd405390a45ecb95ab5ab1c1b847553c18b0ef8ed01e10c1c8b1a76452916", + "sha256:6b899931a5648862c7b88c795eddff7588fb585e81cecce20f8d9da16eff96e0", + "sha256:726c17f3e0d7a7200718c9a890ccfeab391c9133e363a577a44717c85c71db27", + "sha256:760c12276fee05c36f95f8040180abc7fbebb9e5011447a97cdc289b5d6ab6fc", + "sha256:796685d3969815a633827c818863ee199440696b0961e200b011d79b9394bbe7", + "sha256:891fe897b49abb7db470c55664b198b1095e4943b9f82b7dcab317a19116cd38", + "sha256:a471628e20f03dcdfde00770eeaf9c77811f0c331c8805219ca7b87ac17576c5", + "sha256:a63b4fd3e2cabdcc9d918ed280bdde3e8e9641e04f3c59a2a3109644a07b9832", + "sha256:b0b84408d4eabc6de9dd1e1e0bc63e7731e890c0b378a62443e5741cfd0ae90a", + "sha256:be78485e5d5f3684e875dab60f40cddace2f5b2a8f7fede412358ab3214c3a6f", + "sha256:c27eaed872185f047bb7f7da2d21a7d8913457678c9a100a50db6da890bc28b9", + "sha256:c81cb40bff373ab7a7446d6bbca0190bccc5be3448b47b51d729e37799bb5692", + "sha256:d11874b3c33ee441059464711cd365b89fa1a9cf19ae75b0c189b01fbf735b84", + "sha256:e9c028b5897901361d81a4718d1db217b716424a0283afe9d6735fe0caf70f79", + "sha256:fe489d486cd00b739be826e8c1be188ddb74c7a1ca784d93d06fda882a6a1681" + ], + "version": "==4.4.1" }, "mccabe": { "hashes": [ @@ -304,10 +282,6 @@ ], "version": "==0.5.1" }, - "pypcapkit": { - "editable": true, - "path": "." - }, "pexpect": { "hashes": [ "sha256:2094eefdfcf37a1fdbfb9aa090862c1a4878e5c7e0e7e7088bdb511c558e5cd1", @@ -364,30 +338,34 @@ "sha256:5d77031694a5fb97ea95e828c8d10fc770a1df6eb3906067aaed42201a8a6a09", "sha256:723e3db49555abaf9bf79dc474c6b9e2935ad82230b10c1138a71ea41ac0fff1" ], - "index": "pypi", + "index": "tuna", "version": "==2.3.1" }, + "pypcapkit": { + "editable": true, + "path": "." + }, "pyshark": { "hashes": [ - "sha256:46ee30c6f23fb18c7ed6dd26a86e76c223b40e3dcc66d51c34f6df3915bc41cc", - "sha256:e885690b8144c7f7f14bf4ba1527b0c30c640f5e7f7aa15b4cdb408f7f576fa2" + "sha256:a6576fb63ede519dc26145b5535f6ea445ccad03aa018adb1e9a13522720d663", + "sha256:e7bfb1bd0c12a13cb573de103b177ef7efe4143e1ebb5a02c6b185da7dd7edd0" ], - "index": "pypi", - "version": "==0.4.2.8" + "index": "tuna", + "version": "==0.4.2.9" }, "requests": { "hashes": [ "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31" ], - "index": "pypi", + "index": "tuna", "version": "==2.22.0" }, "scapy": { "hashes": [ "sha256:e2f8d11f6a941c14a789ae8b236b27bd634681f1b29b5e893861e284d234f6b0" ], - "index": "pypi", + "index": "tuna", "version": "==2.4.3" }, "six": { @@ -399,17 +377,17 @@ }, "soupsieve": { "hashes": [ - "sha256:72b5f1aea9101cf720a36bb2327ede866fd6f1a07b1e87c92a1cc18113cbc946", - "sha256:e4e9c053d59795e440163733a7fec6c5972210e1790c507e4c7b051d6c5259de" + "sha256:8662843366b8d8779dec4e2f921bebec9afd856a5ff2e82cd419acc5054a1a92", + "sha256:a5a6166b4767725fd52ae55fee8c8b6137d9a51e9f1edea461a062a759160118" ], - "version": "==1.9.2" + "version": "==1.9.3" }, "tbtrim": { "hashes": [ "sha256:860839d7296298a8823b3a0ac49a7f29424819d1481b5521329d339eac062bb9", "sha256:b0810edfb5dcf94c5fe3335a8a8e18ae38a411f6ff6afca188c66ac72444218f" ], - "index": "pypi", + "index": "tuna", "version": "==0.2.1" }, "traitlets": { diff --git a/setup.py b/setup.py index f8da1af89..00a89cc42 100644 --- a/setup.py +++ b/setup.py @@ -86,6 +86,19 @@ 'pcapkit.reassembly', 'pcapkit.toolkit', 'pcapkit.utilities', + 'pcapkit.vendor', + 'pcapkit.vendor.arp', + 'pcapkit.vendor.ftp', + 'pcapkit.vendor.hip', + 'pcapkit.vendor.http', + 'pcapkit.vendor.ipv4', + 'pcapkit.vendor.ipv6', + 'pcapkit.vendor.ipx', + 'pcapkit.vendor.mh', + 'pcapkit.vendor.misc', + 'pcapkit.vendor.ospf', + 'pcapkit.vendor.tcp', + 'pcapkit.vendor.vlan', ], package_data={ '': [ diff --git a/src/const/arp/hardware.py b/src/const/arp/hardware.py index b50c81378..5d973b607 100644 --- a/src/const/arp/hardware.py +++ b/src/const/arp/hardware.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -56,7 +57,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Hardware(key) - if key not in Hardware._member_map_: + if key not in Hardware._member_map_: # pylint: disable=no-member extend_enum(Hardware, key, default) return Hardware[key] @@ -71,4 +72,4 @@ def _missing_(cls, value): if 258 <= value <= 65534: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/arp/operation.py b/src/const/arp/operation.py index 7e74e2a02..3aea64ab7 100644 --- a/src/const/arp/operation.py +++ b/src/const/arp/operation.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -42,7 +43,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Operation(key) - if key not in Operation._member_map_: + if key not in Operation._member_map_: # pylint: disable=no-member extend_enum(Operation, key, default) return Operation[key] @@ -54,4 +55,4 @@ def _missing_(cls, value): if 26 <= value <= 65534: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/ftp/command.py b/src/const/ftp/command.py index 2fd1e9fba..a7a10e275 100644 --- a/src/const/ftp/command.py +++ b/src/const/ftp/command.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from pcapkit.corekit.infoclass import Info diff --git a/src/const/ftp/return_code.py b/src/const/ftp/return_code.py index 64e03cbc1..b2b6d584b 100644 --- a/src/const/ftp/return_code.py +++ b/src/const/ftp/return_code.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -81,7 +82,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ReturnCode(key) - if key not in ReturnCode._member_map_: + if key not in ReturnCode._member_map_: # pylint: disable=no-member extend_enum(ReturnCode, key, default) return ReturnCode[key] diff --git a/src/const/hip/certificate.py b/src/const/hip/certificate.py index 4974a4986..d163414a2 100644 --- a/src/const/hip/certificate.py +++ b/src/const/hip/certificate.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -24,7 +25,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Certificate(key) - if key not in Certificate._member_map_: + if key not in Certificate._member_map_: # pylint: disable=no-member extend_enum(Certificate, key, default) return Certificate[key] @@ -36,4 +37,4 @@ def _missing_(cls, value): if 9 <= value <= 255: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/cipher.py b/src/const/hip/cipher.py index 3bd589317..3527dd6fe 100644 --- a/src/const/hip/cipher.py +++ b/src/const/hip/cipher.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -20,7 +21,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Cipher(key) - if key not in Cipher._member_map_: + if key not in Cipher._member_map_: # pylint: disable=no-member extend_enum(Cipher, key, default) return Cipher[key] @@ -32,4 +33,4 @@ def _missing_(cls, value): if 5 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/di.py b/src/const/hip/di.py index 5c4fc6307..a93a502be 100644 --- a/src/const/hip/di.py +++ b/src/const/hip/di.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -18,7 +19,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return DI(key) - if key not in DI._member_map_: + if key not in DI._member_map_: # pylint: disable=no-member extend_enum(DI, key, default) return DI[key] @@ -30,4 +31,4 @@ def _missing_(cls, value): if 3 <= value <= 15: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/ecdsa_curve.py b/src/const/hip/ecdsa_curve.py index a11ac05c4..ccb52dc7b 100644 --- a/src/const/hip/ecdsa_curve.py +++ b/src/const/hip/ecdsa_curve.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -18,7 +19,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ECDSA_Curve(key) - if key not in ECDSA_Curve._member_map_: + if key not in ECDSA_Curve._member_map_: # pylint: disable=no-member extend_enum(ECDSA_Curve, key, default) return ECDSA_Curve[key] @@ -30,4 +31,4 @@ def _missing_(cls, value): if 3 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/ecdsa_low_curve.py b/src/const/hip/ecdsa_low_curve.py index 8945e2403..32626b815 100644 --- a/src/const/hip/ecdsa_low_curve.py +++ b/src/const/hip/ecdsa_low_curve.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -17,7 +18,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ECDSA_LOW_Curve(key) - if key not in ECDSA_LOW_Curve._member_map_: + if key not in ECDSA_LOW_Curve._member_map_: # pylint: disable=no-member extend_enum(ECDSA_LOW_Curve, key, default) return ECDSA_LOW_Curve[key] @@ -29,4 +30,4 @@ def _missing_(cls, value): if 2 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/esp_transform_suite.py b/src/const/hip/esp_transform_suite.py index 93ae76ec4..cf890862f 100644 --- a/src/const/hip/esp_transform_suite.py +++ b/src/const/hip/esp_transform_suite.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -31,7 +32,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ESP_TransformSuite(key) - if key not in ESP_TransformSuite._member_map_: + if key not in ESP_TransformSuite._member_map_: # pylint: disable=no-member extend_enum(ESP_TransformSuite, key, default) return ESP_TransformSuite[key] @@ -43,4 +44,4 @@ def _missing_(cls, value): if 16 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/group.py b/src/const/hip/group.py index 91da8bd2b..4b8614a7d 100644 --- a/src/const/hip/group.py +++ b/src/const/hip/group.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -27,7 +28,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Group(key) - if key not in Group._member_map_: + if key not in Group._member_map_: # pylint: disable=no-member extend_enum(Group, key, default) return Group[key] @@ -39,4 +40,4 @@ def _missing_(cls, value): if 12 <= value <= 255: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/hi_algorithm.py b/src/const/hip/hi_algorithm.py index 4a1d6f3a2..4871264a3 100644 --- a/src/const/hip/hi_algorithm.py +++ b/src/const/hip/hi_algorithm.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -25,7 +26,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return HI_Algorithm(key) - if key not in HI_Algorithm._member_map_: + if key not in HI_Algorithm._member_map_: # pylint: disable=no-member extend_enum(HI_Algorithm, key, default) return HI_Algorithm[key] @@ -37,4 +38,4 @@ def _missing_(cls, value): if 10 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/hit_suite.py b/src/const/hip/hit_suite.py index ccdba6cfc..4eacc44aa 100644 --- a/src/const/hip/hit_suite.py +++ b/src/const/hip/hit_suite.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -19,7 +20,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return HIT_Suite(key) - if key not in HIT_Suite._member_map_: + if key not in HIT_Suite._member_map_: # pylint: disable=no-member extend_enum(HIT_Suite, key, default) return HIT_Suite[key] @@ -31,4 +32,4 @@ def _missing_(cls, value): if 4 <= value <= 15: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/nat_traversal.py b/src/const/hip/nat_traversal.py index aeb5392a5..180e4da1b 100644 --- a/src/const/hip/nat_traversal.py +++ b/src/const/hip/nat_traversal.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -18,7 +19,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return NAT_Traversal(key) - if key not in NAT_Traversal._member_map_: + if key not in NAT_Traversal._member_map_: # pylint: disable=no-member extend_enum(NAT_Traversal, key, default) return NAT_Traversal[key] @@ -30,4 +31,4 @@ def _missing_(cls, value): if 3 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/notify_message.py b/src/const/hip/notify_message.py index e058f59e2..3d90d6486 100644 --- a/src/const/hip/notify_message.py +++ b/src/const/hip/notify_message.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -50,7 +51,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return NotifyMessage(key) - if key not in NotifyMessage._member_map_: + if key not in NotifyMessage._member_map_: # pylint: disable=no-member extend_enum(NotifyMessage, key, default) return NotifyMessage[key] @@ -100,4 +101,4 @@ def _missing_(cls, value): # [RFC 7401] extend_enum(cls, 'Reserved for Private Use [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/packet.py b/src/const/hip/packet.py index 6833b460a..08bb9f7ad 100644 --- a/src/const/hip/packet.py +++ b/src/const/hip/packet.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -26,7 +27,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Packet(key) - if key not in Packet._member_map_: + if key not in Packet._member_map_: # pylint: disable=no-member extend_enum(Packet, key, default) return Packet[key] @@ -44,4 +45,4 @@ def _missing_(cls, value): if 33 <= value <= 127: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/parameter.py b/src/const/hip/parameter.py index 1755537ec..76fba5141 100644 --- a/src/const/hip/parameter.py +++ b/src/const/hip/parameter.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -72,7 +73,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Parameter(key) - if key not in Parameter._member_map_: + if key not in Parameter._member_map_: # pylint: disable=no-member extend_enum(Parameter, key, default) return Parameter[key] @@ -211,4 +212,4 @@ def _missing_(cls, value): if 65521 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/registration.py b/src/const/hip/registration.py index 59b70e9ae..ac886cf7f 100644 --- a/src/const/hip/registration.py +++ b/src/const/hip/registration.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -18,7 +19,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Registration(key) - if key not in Registration._member_map_: + if key not in Registration._member_map_: # pylint: disable=no-member extend_enum(Registration, key, default) return Registration[key] @@ -34,4 +35,4 @@ def _missing_(cls, value): # [RFC 8003] extend_enum(cls, 'Reserved for Private Use [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/registration_failure.py b/src/const/hip/registration_failure.py index b07faf8d8..695bd04f9 100644 --- a/src/const/hip/registration_failure.py +++ b/src/const/hip/registration_failure.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -24,7 +25,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return RegistrationFailure(key) - if key not in RegistrationFailure._member_map_: + if key not in RegistrationFailure._member_map_: # pylint: disable=no-member extend_enum(RegistrationFailure, key, default) return RegistrationFailure[key] @@ -40,4 +41,4 @@ def _missing_(cls, value): # [RFC 8003] extend_enum(cls, 'Reserved for Private Use [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/suite.py b/src/const/hip/suite.py index e9958ed84..9986d76bc 100644 --- a/src/const/hip/suite.py +++ b/src/const/hip/suite.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -22,7 +23,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Suite(key) - if key not in Suite._member_map_: + if key not in Suite._member_map_: # pylint: disable=no-member extend_enum(Suite, key, default) return Suite[key] @@ -34,4 +35,4 @@ def _missing_(cls, value): if 7 <= value <= 65535: extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/hip/transport.py b/src/const/hip/transport.py index 06f68ae62..f3f69eb16 100644 --- a/src/const/hip/transport.py +++ b/src/const/hip/transport.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -19,7 +20,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Transport(key) - if key not in Transport._member_map_: + if key not in Transport._member_map_: # pylint: disable=no-member extend_enum(Transport, key, default) return Transport[key] @@ -28,5 +29,4 @@ def _missing_(cls, value): """Lookup function used when value is not found.""" if not (isinstance(value, int) and 0 <= value <= 3): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/http/error_code.py b/src/const/http/error_code.py index 14919e0d1..d13c2febb 100644 --- a/src/const/http/error_code.py +++ b/src/const/http/error_code.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -29,7 +30,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ErrorCode(key) - if key not in ErrorCode._member_map_: + if key not in ErrorCode._member_map_: # pylint: disable=no-member extend_enum(ErrorCode, key, default) return ErrorCode[key] @@ -42,4 +43,4 @@ def _missing_(cls, value): temp = hex(value)[2:].upper().zfill(8) extend_enum(cls, 'Unassigned [0x%s]' % (temp[:4]+'_'+temp[4:]), value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/http/frame.py b/src/const/http/frame.py index f4ba4c799..875f39116 100644 --- a/src/const/http/frame.py +++ b/src/const/http/frame.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -28,7 +29,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Frame(key) - if key not in Frame._member_map_: + if key not in Frame._member_map_: # pylint: disable=no-member extend_enum(Frame, key, default) return Frame[key] @@ -44,4 +45,4 @@ def _missing_(cls, value): # [RFC 7540] extend_enum(cls, 'Reserved for Experimental Use [0x%s]' % hex(value)[2:].upper().zfill(2), value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/http/setting.py b/src/const/http/setting.py index 3e9f07d69..dba662476 100644 --- a/src/const/http/setting.py +++ b/src/const/http/setting.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -25,7 +26,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return Setting(key) - if key not in Setting._member_map_: + if key not in Setting._member_map_: # pylint: disable=no-member extend_enum(Setting, key, default) return Setting[key] @@ -44,4 +45,4 @@ def _missing_(cls, value): # [RFC 7540] extend_enum(cls, 'Reserved for Experimental Use [0x%s]' % hex(value)[2:].upper().zfill(4), value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/ipv4/classification_level.py b/src/const/ipv4/classification_level.py index 285f404dd..74c1b7558 100644 --- a/src/const/ipv4/classification_level.py +++ b/src/const/ipv4/classification_level.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -23,7 +24,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ClassificationLevel(key) - if key not in ClassificationLevel._member_map_: + if key not in ClassificationLevel._member_map_: # pylint: disable=no-member extend_enum(ClassificationLevel, key, default) return ClassificationLevel[key] @@ -35,4 +36,3 @@ def _missing_(cls, value): temp = bin(value)[2:].upper().zfill(8) extend_enum(cls, 'Unassigned [0b%s]' % (temp[:4]+'_'+temp[4:]), value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/option_class.py b/src/const/ipv4/option_class.py index 57bef5d4e..950b289ef 100644 --- a/src/const/ipv4/option_class.py +++ b/src/const/ipv4/option_class.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -19,7 +20,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return OptionClass(key) - if key not in OptionClass._member_map_: + if key not in OptionClass._member_map_: # pylint: disable=no-member extend_enum(OptionClass, key, default) return OptionClass[key] @@ -30,4 +31,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/option_number.py b/src/const/ipv4/option_number.py index 6e191385c..a440865e5 100644 --- a/src/const/ipv4/option_number.py +++ b/src/const/ipv4/option_number.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -45,7 +46,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return OptionNumber(key) - if key not in OptionNumber._member_map_: + if key not in OptionNumber._member_map_: # pylint: disable=no-member extend_enum(OptionNumber, key, default) return OptionNumber[key] @@ -56,4 +57,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/protection_authority.py b/src/const/ipv4/protection_authority.py index 708aeaab6..bde24c5e0 100644 --- a/src/const/ipv4/protection_authority.py +++ b/src/const/ipv4/protection_authority.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -23,7 +24,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ProtectionAuthority(key) - if key not in ProtectionAuthority._member_map_: + if key not in ProtectionAuthority._member_map_: # pylint: disable=no-member extend_enum(ProtectionAuthority, key, default) return ProtectionAuthority[key] @@ -34,4 +35,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/qs_function.py b/src/const/ipv4/qs_function.py index 9c271857a..290bca8e7 100644 --- a/src/const/ipv4/qs_function.py +++ b/src/const/ipv4/qs_function.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -17,7 +18,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return QS_Function(key) - if key not in QS_Function._member_map_: + if key not in QS_Function._member_map_: # pylint: disable=no-member extend_enum(QS_Function, key, default) return QS_Function[key] @@ -28,4 +29,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/router_alert.py b/src/const/ipv4/router_alert.py index 2a7b63845..e69cfafc0 100644 --- a/src/const/ipv4/router_alert.py +++ b/src/const/ipv4/router_alert.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -81,7 +82,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return RouterAlert(key) - if key not in RouterAlert._member_map_: + if key not in RouterAlert._member_map_: # pylint: disable=no-member extend_enum(RouterAlert, key, default) return RouterAlert[key] @@ -97,4 +98,4 @@ def _missing_(cls, value): # [RFC 5350] extend_enum(cls, 'Reserved for experimental use [%d]' % value, value) return cls(value) - super()._missing_(value) + return super()._missing_(value) diff --git a/src/const/ipv4/tos_del.py b/src/const/ipv4/tos_del.py index 6b58a3881..9cb7c602c 100644 --- a/src/const/ipv4/tos_del.py +++ b/src/const/ipv4/tos_del.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -17,7 +18,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return TOS_DEL(key) - if key not in TOS_DEL._member_map_: + if key not in TOS_DEL._member_map_: # pylint: disable=no-member extend_enum(TOS_DEL, key, default) return TOS_DEL[key] @@ -28,4 +29,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/tos_ecn.py b/src/const/ipv4/tos_ecn.py index a5a8ffa52..0d85f1943 100644 --- a/src/const/ipv4/tos_ecn.py +++ b/src/const/ipv4/tos_ecn.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -19,7 +20,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return TOS_ECN(key) - if key not in TOS_ECN._member_map_: + if key not in TOS_ECN._member_map_: # pylint: disable=no-member extend_enum(TOS_ECN, key, default) return TOS_ECN[key] @@ -30,4 +31,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [0b%s]' % bin(value)[2:].zfill(2), value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/tos_pre.py b/src/const/ipv4/tos_pre.py index e8327ae89..653078ef9 100644 --- a/src/const/ipv4/tos_pre.py +++ b/src/const/ipv4/tos_pre.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -23,7 +24,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return TOS_PRE(key) - if key not in TOS_PRE._member_map_: + if key not in TOS_PRE._member_map_: # pylint: disable=no-member extend_enum(TOS_PRE, key, default) return TOS_PRE[key] @@ -34,4 +35,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/tos_rel.py b/src/const/ipv4/tos_rel.py index 3952e43e6..0ea1b8914 100644 --- a/src/const/ipv4/tos_rel.py +++ b/src/const/ipv4/tos_rel.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -17,7 +18,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return TOS_REL(key) - if key not in TOS_REL._member_map_: + if key not in TOS_REL._member_map_: # pylint: disable=no-member extend_enum(TOS_REL, key, default) return TOS_REL[key] @@ -28,4 +29,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv4/tos_thr.py b/src/const/ipv4/tos_thr.py index d32fd12de..93e383f2c 100644 --- a/src/const/ipv4/tos_thr.py +++ b/src/const/ipv4/tos_thr.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -17,7 +18,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return TOS_THR(key) - if key not in TOS_THR._member_map_: + if key not in TOS_THR._member_map_: # pylint: disable=no-member extend_enum(TOS_THR, key, default) return TOS_THR[key] @@ -28,4 +29,3 @@ def _missing_(cls, value): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) extend_enum(cls, 'Unassigned [%d]' % value, value) return cls(value) - super()._missing_(value) diff --git a/src/const/ipv6/extension_header.py b/src/const/ipv6/extension_header.py index 7146ffa11..69e35f5f1 100644 --- a/src/const/ipv6/extension_header.py +++ b/src/const/ipv6/extension_header.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -26,6 +27,6 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return ExtensionHeader(key) - if key not in ExtensionHeader._member_map_: + if key not in ExtensionHeader._member_map_: # pylint: disable=no-member extend_enum(ExtensionHeader, key, default) return ExtensionHeader[key] diff --git a/src/protocols/protocol.py b/src/protocols/protocol.py index db630d051..075d6f6d2 100644 --- a/src/protocols/protocol.py +++ b/src/protocols/protocol.py @@ -25,10 +25,8 @@ from pcapkit.corekit.infoclass import Info from pcapkit.corekit.protochain import ProtoChain from pcapkit.utilities.decorators import beholder, seekset -from pcapkit.utilities.exceptions import (BoolError, BytesError, - ProtocolNotFound, ProtocolUnbound, +from pcapkit.utilities.exceptions import (ProtocolNotFound, ProtocolUnbound, StructError) -from pcapkit.utilities.validations import bool_check, int_check ############################################################################### # from pcapkit.protocols.raw import Raw @@ -89,7 +87,6 @@ class Protocol(metaclass=abc.ABCMeta): @abc.abstractmethod def name(self): """Name of current protocol.""" - pass # acronym of current protocol @property @@ -108,7 +105,6 @@ def info(self): @abc.abstractmethod def length(self): """Header length of current protocol.""" - pass # payload of current instance @property diff --git a/src/vendor/arp/hardware.py b/src/vendor/arp/hardware.py index cccc057e1..6cb702b64 100644 --- a/src/vendor/arp/hardware.py +++ b/src/vendor/arp/hardware.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Hardware'] -############### -# Macros -############### -NAME = 'Hardware' -DOCS = 'Hardware Types [RFC 826][RFC 5494]' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/arp-parameters/arp-parameters-2.csv' +class Hardware(Vendor): + """Hardware Types [RFC 826][RFC 5494]""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/arp-parameters/arp-parameters-2.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == '__main__': + Hardware() diff --git a/src/vendor/arp/operation.py b/src/vendor/arp/operation.py index f723c8c6b..214252314 100644 --- a/src/vendor/arp/operation.py +++ b/src/vendor/arp/operation.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Operation'] -############### -# Macros -############### -NAME = 'Operation' -DOCS = 'Operation Codes [RFC 826][RFC 5494]' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/arp-parameters/arp-parameters-1.csv' +class Operation(Vendor): + """Operation Codes [RFC 826][RFC 5494]""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/arp-parameters/arp-parameters-1.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Operation() diff --git a/src/vendor/default.py b/src/vendor/default.py new file mode 100644 index 000000000..f6468cc7e --- /dev/null +++ b/src/vendor/default.py @@ -0,0 +1,226 @@ +# -*- coding: utf-8 -*- +"""Default vendor generation.""" + +import abc +import collections +import csv +import inspect +import os +import re +import tempfile +import webbrowser + +import requests + +__all__ = ['Vendor'] + +# default const file of enumerate registry from IANA CSV +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ +# -*- coding: utf-8 -*- +# pylint: disable=line-too-long + +from aenum import IntEnum, extend_enum + + +class {NAME}(IntEnum): + """Enumeration class for {NAME}.""" + _ignore_ = '{NAME} _' + {NAME} = vars() + + # {DOCS} + {ENUM} + + @staticmethod + def get(key, default=-1): + """Backport support for original codes.""" + if isinstance(key, int): + return {NAME}(key) + if key not in {NAME}._member_map_: # pylint: disable=no-member + extend_enum({NAME}, key, default) + return {NAME}[key] + + @classmethod + def _missing_(cls, value): + """Lookup function used when value is not found.""" + if not ({FLAG}): + raise ValueError('%r is not a valid %s' % (value, cls.__name__)) + {MISS} + return super()._missing_(value) +''' + + +class Vendor(metaclass=abc.ABCMeta): + """Default vendor generator. + + Inherit this class with `FLAG` & `LINK` attributes, + etc. to implement a new vendor generator. + + Macros: + - `FLAG` -- `str`, value limit checker + - `LINK` -- `str`, link to CSV file + + Processors: + - `rename` -- rename duplicated fields + - `process` -- process CSV data + - `count` -- count field records + - `context` -- generate constant context + - `request` -- fetch CSV file + + """ + ############### + # Macros + ############### + + # NAME = None + # DOCS = None + FLAG = None + LINK = None + + ############### + # Processors + ############### + + def rename(self, name, code): # pylint: disable=redefined-outer-name + """Rename duplicated fields. + + Args: + - `name` -- str, field name + - `code` -- str, field code + + Returns: + - `str` -- revised field name + + """ + if self.record[name] > 1: + return f'{name} [{code}]' + return name + + def process(self, data): + """Process CSV data. + + Args: + - `data` -- List[str], CSV data + + Returns: + - `List[str]` -- enumeration fields + - `List[str]` -- missing fields + + """ + reader = csv.reader(data) + next(reader) + + enum = list() + miss = list() + for item in reader: + name = item[1] + rfcs = item[2] + + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f"# {''.join(temp)}" if rfcs else '' + + try: + code, _ = item[0], int(item[0]) + renm = self.rename(name, code) + + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) + + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = item[0].split('-') + more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) + + miss.append(f'if {start} <= value <= {stop}:') + if more: + miss.append(f' {more}') + miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") + miss.append(' return cls(value)') + return enum, miss + + def count(self, data): # pylint: disable=no-self-use + """Count field records. + + Args: + - `data` -- `List[str]`, CSV data + + Returns: + - `Counter` -- field recordings + + """ + reader = csv.reader(data) + next(reader) # header + return collections.Counter(map(lambda item: item[1], # pylint: disable=map-builtin-not-iterating + filter(lambda item: len(item[0].split('-')) != 2, reader))) # pylint: disable=filter-builtin-not-iterating + + def context(self, data): + """Generate constant context. + + Args: + - `data` -- `List[str]`, CSV data + + Returns: + - `str` -- constant context + + """ + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + def request(self): + """Fetch CSV file. + + Returns: + - `List[str]` -- CSV data + + """ + try: + page = requests.get(self.LINK) + data = page.text.strip().split('\r\n') + except requests.RequestException: + with tempfile.TemporaryDirectory(prefix=f'{os.path.realpath(os.curdir)}{os.path.sep}') as tempdir: + temp_file = os.path.join(tempdir, 'index.html') + + webbrowser.open(self.LINK) + print(f'Please save the CSV code at {temp_file}') + input('Press ENTER to continue...') + + with open(temp_file) as file: + text = file.read() + data = text.strip().split('\r\n') + return data + + ############### + # Defaults + ############### + + def __init__(self): + self.NAME = type(self).__name__ + self.DOCS = type(self).__doc__ + + data = self.request() + self.record = self.count(data) + + temp_ctx = list() + orig_ctx = self.context(data) + for line in orig_ctx.splitlines(): + if line: + if line.strip(): + temp_ctx.append(line) + else: + temp_ctx.append(line) + context = '\n'.join(temp_ctx) + + temp, FILE = os.path.split(os.path.abspath(inspect.getfile(type(self)))) + ROOT, STEM = os.path.split(temp) + + os.makedirs(os.path.join(ROOT, '..', 'const', STEM), exist_ok=True) + with open(os.path.join(ROOT, '..', 'const', STEM, FILE), 'w') as file: + print(context, file=file) diff --git a/src/vendor/ftp/command.py b/src/vendor/ftp/command.py index a3de8a4ff..d70f33c0d 100644 --- a/src/vendor/ftp/command.py +++ b/src/vendor/ftp/command.py @@ -1,23 +1,11 @@ # -*- coding: utf-8 -*- -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### - -NAME = 'Command' -DOCS = 'FTP Command' -LINK = 'https://www.iana.org/assignments/ftp-commands-extensions/ftp-commands-extensions-2.csv' - -############### -# Processors -############### +__all__ = ['Command'] KIND = dict( a='access control', @@ -31,8 +19,7 @@ h='historic', ) - -def make(cmmd, feat, desc, kind, conf, rfcs): return f'''\ +make = lambda cmmd, feat, desc, kind, conf, rfcs: f'''\ {cmmd}=Info( name={cmmd!r}, feat={feat!r}, @@ -43,47 +30,9 @@ def make(cmmd, feat, desc, kind, conf, rfcs): return f'''\ )\ ''' - -page = requests.get(LINK) -data = page.text.strip().split('\r\n') - -reader = csv.reader(data) -header = next(reader) - -info = dict() -for item in reader: - cmmd = item[0].strip('+') - feat = item[1] or None - desc = re.sub(r'{.*}', r'', item[2]).strip() or None - kind = tuple(KIND.get(s) for s in item[3].split('/')) or None - conf = CONF.get(item[4].split()[0]) - temp = list() - for rfc in filter(lambda s: 'RFC' in s, re.split(r'\[|\]', item[5])): - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - rfcs = tuple(temp) or None - - if cmmd == '-N/A-': - MISS = '\n'.ljust(25).join((f"Info(name='%s' % key,", - f'feat={feat!r},', - f'desc={desc!r},', - f'type={kind!r},', - f'conf={conf!r},', - f'note={rfcs!r})')) - else: - info[cmmd] = make(cmmd, feat, desc, kind, conf, rfcs) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -INFO = ',\n '.join(map(lambda s: s.strip(), info.values())) - - -def LINE(NAME, DOCS, INFO, MISS): return f'''\ +LINE = lambda NAME, DOCS, INFO, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from pcapkit.corekit.infoclass import Info @@ -104,7 +53,43 @@ def __getitem__(self, key): ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, INFO, MISS)) +class Command(Vendor): + """FTP Command""" + + LINK = 'https://www.iana.org/assignments/ftp-commands-extensions/ftp-commands-extensions-2.csv' + + def process(self, data): + reader = csv.reader(data) + next(reader) # header + + info = dict() + for item in reader: + cmmd = item[0].strip('+') + feat = item[1] or None + desc = re.sub(r'{.*}', r'', item[2]).strip() or None + kind = tuple(KIND.get(s) for s in item[3].split('/')) or None + conf = CONF.get(item[4].split()[0]) + temp = list() + for rfc in filter(lambda s: 'RFC' in s, re.split(r'\[|\]', item[5])): + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + rfcs = tuple(temp) or None + + if cmmd == '-N/A-': + MISS = '\n'.ljust(25).join((f"Info(name='%s' % key,", + f'feat={feat!r},', + f'desc={desc!r},', + f'type={kind!r},', + f'conf={conf!r},', + f'note={rfcs!r})')) + else: + info[cmmd] = make(cmmd, feat, desc, kind, conf, rfcs) + return info, MISS + + def context(self, data): + info, MISS = self.process(data) + INFO = ',\n '.join(map(lambda s: s.strip(), info.values())) # pylint: disable=dict-values-not-iterating + return LINE(self.NAME, self.DOCS, INFO, MISS) + + +if __name__ == "__main__": + Command() diff --git a/src/vendor/ftp/return_code.py b/src/vendor/ftp/return_code.py index 0accb1cbe..7f24a9c0f 100644 --- a/src/vendor/ftp/return_code.py +++ b/src/vendor/ftp/return_code.py @@ -1,88 +1,20 @@ # -*- coding: utf-8 -*- import collections -import contextlib import os import tempfile import webbrowser import bs4 -# import requests +import requests -############### -# Macros -############### - -NAME = 'ReturnCode' -DOCS = 'FTP Server Return Code' -FLAG = 'isinstance(value, int) and 100 <= value <= 659' -LINK = 'https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes' - -############### -# Processors -############### - -# page = requests.get(LINK) -# soup = bs4.BeautifulSoup(page.text, 'html5lib') -with tempfile.TemporaryDirectory(prefix=f'{os.path.realpath(os.curdir)}/') as tempdir: - index_html = os.path.join(tempdir, 'index.html') - - webbrowser.open(LINK) - print(f'Please save the HTML code as {index_html!r}.') - input('Press ENTER to continue...') - - with open(index_html) as file: - text = file.read() -soup = bs4.BeautifulSoup(text, 'html5lib') - -table = soup.find_all('table', class_='wikitable')[2] -content = filter(lambda item: isinstance(item, bs4.element.Tag), table.tbody) # pylint: disable=filter-builtin-not-iterating -header = next(content) - -temp = list() -for item in content: - line = item.find_all('td') - - code = ' '.join(line[0].stripped_strings) - if len(code) != 3: - continue - desc = f"{' '.join(line[1].stripped_strings).split('.')[0].strip()}." - temp.append(desc) -record = collections.Counter(temp) - - -def rename(name, code): # pylint: disable=redefined-outer-name - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -table = soup.find_all('table', class_='wikitable')[2] -content = filter(lambda item: isinstance(item, bs4.element.Tag), table.tbody) # pylint: disable=filter-builtin-not-iterating -header = next(content) - -enum = list() -for item in content: - line = item.find_all('td') - - code = ' '.join(line[0].stripped_strings) - if len(code) != 3: - continue - desc = f"{' '.join(line[1].stripped_strings).split('.')[0].strip()}." - enum.append(f'{NAME}[{rename(desc, code)!r}] = {code}') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) +from pcapkit.vendor.default import Vendor +__all__ = ['ReturnCode'] LINE = lambda NAME, DOCS, FLAG, ENUM: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -118,7 +50,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -135,7 +67,66 @@ def _missing_(cls, value): ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM)) +class ReturnCode(Vendor): + """FTP Server Return Code""" + + FLAG = 'isinstance(value, int) and 100 <= value <= 659' + LINK = 'https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes' + + def request(self): + try: + page = requests.get(self.LINK) + soup = bs4.BeautifulSoup(page.text, 'html5lib') + except requests.RequestException: + with tempfile.TemporaryDirectory(prefix=f'{os.path.realpath(os.curdir)}{os.path.sep}') as tempdir: + index_html = os.path.join(tempdir, 'index.html') + + webbrowser.open(self.LINK) + print(f'Please save the HTML code at {index_html}') + input('Press ENTER to continue...') + + with open(index_html) as file: + text = file.read() + soup = bs4.BeautifulSoup(text, 'html5lib') + return soup + + def context(self, soup): # pylint: disable=arguments-differ + enum = self.process(soup) + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM) + + def process(self, soup): # pylint: disable=arguments-differ + table = soup.find_all('table', class_='wikitable')[2] + content = filter(lambda item: isinstance(item, bs4.element.Tag), table.tbody) # pylint: disable=filter-builtin-not-iterating + next(content) # header + + enum = list() + for item in content: + line = item.find_all('td') + + code = ' '.join(line[0].stripped_strings) + if len(code) != 3: + continue + desc = f"{' '.join(line[1].stripped_strings).split('.')[0].strip()}." + enum.append(f'{self.NAME}[{self.rename(desc, code)!r}] = {code}') + return enum + + def count(self, soup): # pylint: disable=arguments-differ, no-self-use + table = soup.find_all('table', class_='wikitable')[2] + content = filter(lambda item: isinstance(item, bs4.element.Tag), table.tbody) # pylint: disable=filter-builtin-not-iterating + next(content) # header + + temp = list() + for item in content: + line = item.find_all('td') + + code = ' '.join(line[0].stripped_strings) + if len(code) != 3: + continue + desc = f"{' '.join(line[1].stripped_strings).split('.')[0].strip()}." + temp.append(desc) + return collections.Counter(temp) + + +if __name__ == "__main__": + ReturnCode() diff --git a/src/vendor/hip/certificate.py b/src/vendor/hip/certificate.py index a3791123b..2d8fd4447 100644 --- a/src/vendor/hip/certificate.py +++ b/src/vendor/hip/certificate.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Certificate'] -############### -# Macros -############### -NAME = 'Certificate' -DOCS = 'HIP Certificate Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 255' -LINK = 'https://www.iana.org/assignments/hip-parameters/certificate-types.csv' +class Certificate(Vendor): + """HIP Certificate Types""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 255' + LINK = 'https://www.iana.org/assignments/hip-parameters/certificate-types.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Certificate() diff --git a/src/vendor/hip/cipher.py b/src/vendor/hip/cipher.py index 681a95980..f405871f1 100644 --- a/src/vendor/hip/cipher.py +++ b/src/vendor/hip/cipher.py @@ -1,122 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Cipher'] -############### -# Macros -############### -NAME = 'Cipher' -DOCS = 'Cipher IDs' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-cipher-id.csv' +class Cipher(Vendor): + """Cipher IDs""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-cipher-id.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Cipher() diff --git a/src/vendor/hip/di.py b/src/vendor/hip/di.py index 64bace23c..b23807ebb 100644 --- a/src/vendor/hip/di.py +++ b/src/vendor/hip/di.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['DI'] -############### -# Macros -############### -NAME = 'DI' -DOCS = 'DI-Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 15' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-7.csv' +class DI(Vendor): + """DI-Types""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 15' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-7.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + DI() diff --git a/src/vendor/hip/ecdsa_curve.py b/src/vendor/hip/ecdsa_curve.py index a143b0712..f2294c4a2 100644 --- a/src/vendor/hip/ecdsa_curve.py +++ b/src/vendor/hip/ecdsa_curve.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['ECDSA_Curve'] -############### -# Macros -############### -NAME = 'ECDSA_Curve' -DOCS = 'ECDSA Curve Label' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/ecdsa-curve-label.csv' +class ECDSA_Curve(Vendor): + """ECDSA Curve Label""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/ecdsa-curve-label.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + ECDSA_Curve() diff --git a/src/vendor/hip/ecdsa_low_curve.py b/src/vendor/hip/ecdsa_low_curve.py index a9da25acf..34a1ec3d2 100644 --- a/src/vendor/hip/ecdsa_low_curve.py +++ b/src/vendor/hip/ecdsa_low_curve.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['ECDSA_LOW_Curve'] -############### -# Macros -############### -NAME = 'ECDSA_LOW_Curve' -DOCS = 'ECDSA_LOW Curve Label' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/ecdsa-low-curve-label.csv' +class ECDSA_LOW_Curve(Vendor): + """ECDSA_LOW Curve Label""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/ecdsa-low-curve-label.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + ECDSA_LOW_Curve() diff --git a/src/vendor/hip/esp_transform_suite.py b/src/vendor/hip/esp_transform_suite.py index fbbacb912..6c62f774e 100644 --- a/src/vendor/hip/esp_transform_suite.py +++ b/src/vendor/hip/esp_transform_suite.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['ESP_TransformSuite'] -############### -# Macros -############### -NAME = 'ESP_TransformSuite' -DOCS = 'ESP Transform Suite IDs' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/esp-transform-suite-ids.csv' +class ESP_TransformSuite(Vendor): + """ESP Transform Suite IDs""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/esp-transform-suite-ids.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + ESP_TransformSuite() diff --git a/src/vendor/hip/group.py b/src/vendor/hip/group.py index 0237c609a..122b8a45d 100644 --- a/src/vendor/hip/group.py +++ b/src/vendor/hip/group.py @@ -1,127 +1,67 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### +__all__ = ['Group'] -NAME = 'Group' -DOCS = 'Group IDs' -FLAG = 'isinstance(value, int) and 0 <= value <= 255' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-5.csv' -############### -# Processors -############### +class Group(Vendor): + """Group IDs""" -page = requests.get(LINK) -data = page.text.strip().split('\r\n') + FLAG = 'isinstance(value, int) and 0 <= value <= 255' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-5.csv' -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) + def rename(self, name, code, *, original): # pylint: disable=redefined-outer-name, arguments-differ + if self.record[original] > 1: + return f'{name} [{code}]' + return name + def process(self, data): + reader = csv.reader(data) + next(reader) # header -def rename(name, code, *, original): - if record[original] > 1: - return f'{name} [{code}]' - return name + enum = list() + miss = list() + for item in reader: + long = item[1] + rfcs = item[2] + split = long.split(' (') + if len(split) == 2: + name = split[0] + cmmt = f' {split[1][:-1]}' + else: + name, cmmt = long, '' -reader = csv.reader(data) -header = next(reader) + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + lrfc = f" {''.join(temp)}" if rfcs else '' -enum = list() -miss = list() -for item in reader: - long = item[1] - rfcs = item[2] + try: + code, _ = item[0], int(item[0]) + renm = self.rename(name, code, original=long) - split = long.split(' (') - if len(split) == 2: - name = split[0] - cmmt = f' {split[1][:-1]}' - else: - name, cmmt = long, '' + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f"#{lrfc}{cmmt}" if lrfc or cmmt else '' - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - lrfc = f" {''.join(temp)}" if rfcs else '' + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = item[0].split('-') - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code, original=long) + miss.append(f'if {start} <= value <= {stop}:') + if lrfc or cmmt: + miss.append(f' #{lrfc}{cmmt}') + miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") + miss.append(' return cls(value)') + return enum, miss - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f"#{lrfc}{cmmt}" if lrfc or cmmt else '' - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - - miss.append(f'if {start} <= value <= {stop}:') - if lrfc or cmmt: - miss.append(f' #{lrfc}{cmmt}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Group() diff --git a/src/vendor/hip/hi_algorithm.py b/src/vendor/hip/hi_algorithm.py index 3510f74f9..1a525c1d6 100644 --- a/src/vendor/hip/hi_algorithm.py +++ b/src/vendor/hip/hi_algorithm.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['HI_Algorithm'] -############### -# Macros -############### -NAME = 'HI_Algorithm' -DOCS = 'HI Algorithm' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/hi-algorithm.csv' +class HI_Algorithm(Vendor): + """HI Algorithm""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/hi-algorithm.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + HI_Algorithm() diff --git a/src/vendor/hip/hit_suite.py b/src/vendor/hip/hit_suite.py index 992bc50a6..e5c82c4bd 100644 --- a/src/vendor/hip/hit_suite.py +++ b/src/vendor/hip/hit_suite.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['HIT_Suite'] -############### -# Macros -############### -NAME = 'HIT_Suite' -DOCS = 'HIT Suite ID' -FLAG = 'isinstance(value, int) and 0 <= value <= 15' -LINK = 'https://www.iana.org/assignments/hip-parameters/hit-suite-id.csv' +class HIT_Suite(Vendor): + """HIT Suite ID""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 15' + LINK = 'https://www.iana.org/assignments/hip-parameters/hit-suite-id.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + HIT_Suite() diff --git a/src/vendor/hip/nat_traversal.py b/src/vendor/hip/nat_traversal.py index ab0e30ff1..41bf3b9a1 100644 --- a/src/vendor/hip/nat_traversal.py +++ b/src/vendor/hip/nat_traversal.py @@ -1,122 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['NAT_Traversal'] -############### -# Macros -############### -NAME = 'NAT_Traversal' -DOCS = 'HIP NAT Traversal Modes' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/nat-traversal.csv' +class NAT_Traversal(Vendor): + """HIP NAT Traversal Modes""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/nat-traversal.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + NAT_Traversal() diff --git a/src/vendor/hip/notify_message.py b/src/vendor/hip/notify_message.py index 09e41c666..358cb731c 100644 --- a/src/vendor/hip/notify_message.py +++ b/src/vendor/hip/notify_message.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['NotifyMessage'] -############### -# Macros -############### -NAME = 'NotifyMessage' -DOCS = 'Notify Message Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-9.csv' +class NotifyMessage(Vendor): + """Notify Message Types""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-9.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + NotifyMessage() diff --git a/src/vendor/hip/packet.py b/src/vendor/hip/packet.py index 8bdf6a791..75aa1722b 100644 --- a/src/vendor/hip/packet.py +++ b/src/vendor/hip/packet.py @@ -1,127 +1,67 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### +__all__ = ['Packet'] -NAME = 'Packet' -DOCS = 'HIP Packet Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 127' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-1.csv' -############### -# Processors -############### +class Packet(Vendor): + """HIP Packet Types""" -page = requests.get(LINK) -data = page.text.strip().split('\r\n') + FLAG = 'isinstance(value, int) and 0 <= value <= 127' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-1.csv' -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) + def rename(self, name, code, *, original): # pylint: disable=redefined-outer-name, arguments-differ + if self.record[original] > 1: + return f'{name} [{code}]' + return name + def process(self, data): + reader = csv.reader(data) + next(reader) # header -def rename(name, code, *, original): - if record[name] > 1: - return f'{name} [{code}]' - return name + enum = list() + miss = list() + for item in reader: + long = item[1] + rfcs = item[2] + if ' - ' in long: + name, cmmt = long.split(' -') + elif ' (' in long: + cmmt, name = f" {long.strip(')')}".split(' (') + else: + name, cmmt = long, '' -reader = csv.reader(data) -header = next(reader) + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f" {''.join(temp)}" if rfcs else '' -enum = list() -miss = list() -for item in reader: - long = item[1] - rfcs = item[2] + try: + code, _ = item[0], int(item[0]) + renm = self.rename(name, code, original=long) - if ' - ' in long: - name, cmmt = long.split(' -') - elif ' (' in long: - cmmt, name = f" {long.strip(')')}".split(' (') - else: - name, cmmt = long, '' + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f'#{desc}{cmmt}' if desc or cmmt else '' - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f" {''.join(temp)}" if rfcs else '' + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = item[0].split('-') - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code, original=long) + miss.append(f'if {start} <= value <= {stop}:') + if desc or cmmt: + miss.append(f' #{desc}{cmmt}') + miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") + miss.append(' return cls(value)') + return enum, miss - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f'#{desc}{cmmt}' if desc or cmmt else '' - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - - miss.append(f'if {start} <= value <= {stop}:') - if desc or cmmt: - miss.append(f' #{desc}{cmmt}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Packet() diff --git a/src/vendor/hip/parameter.py b/src/vendor/hip/parameter.py index a46206f5f..621e60f86 100644 --- a/src/vendor/hip/parameter.py +++ b/src/vendor/hip/parameter.py @@ -1,127 +1,68 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### +__all__ = ['Parameter'] -NAME = 'Parameter' -DOCS = 'HIP Parameter Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-4.csv' -############### -# Processors -############### +class Parameter(Vendor): + """HIP Parameter Types""" -page = requests.get(LINK) -data = page.text.strip().split('\r\n') + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-4.csv' -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) + def rename(self, name, code, *, original): # pylint: disable=redefined-outer-name, arguments-differ + if self.record[original] > 1: + return f'{name} [{code}]' + return name + def process(self, data): + reader = csv.reader(data) + next(reader) # header -def rename(name, code, *, original): - if record[name] > 1: - return f'{name} [{code}]' - return name + enum = list() + miss = list() + for item in reader: + long = item[1] + plen = item[2] + rfcs = item[3] + match = re.match(r'(\w*) *(\(.*\))*', long) + group = match.groups() -reader = csv.reader(data) -header = next(reader) + name = group[0] + cmmt = f' {group[1]}' if group[1] else '' + plen = f' {plen}' if re.match(r'\d+', plen) else '' -enum = list() -miss = list() -for item in reader: - long = item[1] - plen = item[2] - rfcs = item[3] + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + lrfc = f" {''.join(temp)}" if rfcs else '' - match = re.match(r'(\w*) *(\(.*\))*', long) - group = match.groups() + try: + code, _ = item[0], int(item[0]) + renm = self.rename(name, code, original=long) - name = group[0] - cmmt = f' {group[1]}' if group[1] else '' - plen = f' {plen}' if re.match(r'\d+', plen) else '' + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f"#{lrfc}{plen}{cmmt}" if lrfc or cmmt or plen else '' - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - lrfc = f" {''.join(temp)}" if rfcs else '' + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = item[0].split('-') - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code, original=long) + miss.append(f'if {start} <= value <= {stop}:') + if lrfc or cmmt or plen: + miss.append(f"#{lrfc}{plen}{cmmt}") + miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") + miss.append(' return cls(value)') + return enum, miss - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f"#{lrfc}{plen}{cmmt}" if lrfc or cmmt or plen else '' - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - - miss.append(f'if {start} <= value <= {stop}:') - if lrfc or cmmt or plen: - miss.append(f"#{lrfc}{plen}{cmmt}") - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -### -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Parameter() diff --git a/src/vendor/hip/registration.py b/src/vendor/hip/registration.py index 7139ec760..979527b1c 100644 --- a/src/vendor/hip/registration.py +++ b/src/vendor/hip/registration.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Registration'] -############### -# Macros -############### -NAME = 'Registration' -DOCS = 'Registration Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 255' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-11.csv' +class Registration(Vendor): + """Registration Types""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 255' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-11.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Registration() diff --git a/src/vendor/hip/registration_failure.py b/src/vendor/hip/registration_failure.py index 2568cb3bf..011a95ee8 100644 --- a/src/vendor/hip/registration_failure.py +++ b/src/vendor/hip/registration_failure.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['RegistrationFailure'] -############### -# Macros -############### -NAME = 'RegistrationFailure' -DOCS = 'Registration Failure Types' -FLAG = 'isinstance(value, int) and 0 <= value <= 255' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-13.csv' +class RegistrationFailure(Vendor): + """Registration Failure Types""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 255' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-13.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + RegistrationFailure() diff --git a/src/vendor/hip/suite.py b/src/vendor/hip/suite.py index fa157f110..fc01e9c1c 100644 --- a/src/vendor/hip/suite.py +++ b/src/vendor/hip/suite.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Suite'] -############### -# Macros -############### -NAME = 'Suite' -DOCS = 'Suite IDs' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-6.csv' +class Suite(Vendor): + """Suite IDs""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/hip-parameters/hip-parameters-6.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Suite() diff --git a/src/vendor/hip/transport.py b/src/vendor/hip/transport.py index 066003e9b..d7abb2855 100644 --- a/src/vendor/hip/transport.py +++ b/src/vendor/hip/transport.py @@ -1,121 +1,16 @@ # -*- coding: utf-8 -*- -import collections -import contextlib -import csv -import os -import re +from pcapkit.vendor.default import Vendor -import requests +__all__ = ['Transport'] -############### -# Macros -############### -NAME = 'Transport' -DOCS = 'HIP Transport Modes' -FLAG = 'isinstance(value, int) and 0 <= value <= 3' -LINK = 'https://www.iana.org/assignments/hip-parameters/transport-modes.csv' +class Transport(Vendor): + """HIP Transport Modes""" -############### -# Processors -############### + FLAG = 'isinstance(value, int) and 0 <= value <= 3' + LINK = 'https://www.iana.org/assignments/hip-parameters/transport-modes.csv' -page = requests.get(LINK) -data = page.text.strip().split('\r\n') -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' - - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Transport() diff --git a/src/vendor/http/error_code.py b/src/vendor/http/error_code.py index 496934068..bff59be8b 100644 --- a/src/vendor/http/error_code.py +++ b/src/vendor/http/error_code.py @@ -1,33 +1,11 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### - -NAME = 'ErrorCode' -DOCS = 'HTTP/2 Error Code' -FLAG = 'isinstance(value, int) and 0x00000000 <= value <= 0xFFFFFFFF' -LINK = 'https://www.iana.org/assignments/http2-parameters/error-code.csv' - -############### -# Processors -############### - -page = requests.get(LINK) -data = page.text.strip().split('\r\n') - -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) +__all__ = ['ErrorCode'] def hexlify(code): @@ -36,95 +14,52 @@ def hexlify(code): return f'0x{hex(code)[2:].upper().zfill(8)}' -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - dscp = item[2] - rfcs = item[3] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f" {''.join(temp)}" if rfcs else '' - dscp = f' {dscp}' if dscp else '' +class ErrorCode(Vendor): + """HTTP/2 Error Code""" - try: - temp = int(item[0], base=16) - code = hexlify(temp) - renm = rename(name, code) + FLAG = 'isinstance(value, int) and 0x00000000 <= value <= 0xFFFFFFFF' + LINK = 'https://www.iana.org/assignments/http2-parameters/error-code.csv' - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f'#{desc}{dscp}' if desc or dscp else '' - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = map(lambda s: int(s, base=16), item[0].split('-')) - - miss.append(f'if {hexlify(start)} <= value <= {hexlify(stop)}:') - if desc or dscp: - miss.append(f'#{desc}{dscp}') - miss.append(' temp = hex(value)[2:].upper().zfill(8)') - miss.append(f" extend_enum(cls, '{name} [0x%s]' % (temp[:4]+'_'+temp[4:]), value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- + def process(self, data): + reader = csv.reader(data) + next(reader) # header -from aenum import IntEnum, extend_enum + enum = list() + miss = list() + for item in reader: + name = item[1] + dscp = item[2] + rfcs = item[3] + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f" {''.join(temp)}" if rfcs else '' + dscp = f' {dscp}' if dscp else '' -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() + try: + temp = int(item[0], base=16) + code = hexlify(temp) + renm = self.rename(name, code) - # {DOCS} - {ENUM} + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f'#{desc}{dscp}' if desc or dscp else '' - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = map(lambda s: int(s, base=16), item[0].split('-')) - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' + miss.append(f'if {hexlify(start)} <= value <= {hexlify(stop)}:') + if desc or dscp: + miss.append(f'#{desc}{dscp}') + miss.append(' temp = hex(value)[2:].upper().zfill(8)') + miss.append(f" extend_enum(cls, '{name} [0x%s]' % (temp[:4]+'_'+temp[4:]), value)") + miss.append(' return cls(value)') + return enum, miss -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + ErrorCode() diff --git a/src/vendor/http/frame.py b/src/vendor/http/frame.py index 1050f9832..2507ee261 100644 --- a/src/vendor/http/frame.py +++ b/src/vendor/http/frame.py @@ -1,127 +1,62 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### - -NAME = 'Frame' -DOCS = 'HTTP/2 Frame Type' -FLAG = 'isinstance(value, int) and 0x00 <= value <= 0xFF' -LINK = 'https://www.iana.org/assignments/http2-parameters/frame-type.csv' - -############### -# Processors -############### - -page = requests.get(LINK) -data = page.text.strip().split('\r\n') - -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) +__all__ = ['Frame'] def hexlify(code): return f'0x{hex(code)[2:].upper().zfill(2)}' -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' +class Frame(Vendor): + """HTTP/2 Frame Type""" - try: - temp = int(item[0], base=16) - code = hexlify(temp) - renm = rename(name, code) + FLAG = 'isinstance(value, int) and 0x00 <= value <= 0xFF' + LINK = 'https://www.iana.org/assignments/http2-parameters/frame-type.csv' - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = map(lambda s: int(s, base=16), item[0].split('-')) - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - miss.append(f'if {hexlify(start)} <= value <= {hexlify(stop)}:') - if more: - miss.append(f' {more}') - miss.append( - f" extend_enum(cls, '{name} [0x%s]' % hex(value)[2:].upper().zfill(2), value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- + def process(self, data): + reader = csv.reader(data) + next(reader) # header -from aenum import IntEnum, extend_enum + enum = list() + miss = list() + for item in reader: + name = item[1] + rfcs = item[2] + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f"# {''.join(temp)}" if rfcs else '' -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() + try: + temp = int(item[0], base=16) + code = hexlify(temp) + renm = self.rename(name, code) - # {DOCS} - {ENUM} + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = map(lambda s: int(s, base=16), item[0].split('-')) + more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' + miss.append(f'if {hexlify(start)} <= value <= {hexlify(stop)}:') + if more: + miss.append(f' {more}') + miss.append( + f" extend_enum(cls, '{name} [0x%s]' % hex(value)[2:].upper().zfill(2), value)") + miss.append(' return cls(value)') + return enum, miss -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == "__main__": + Frame() diff --git a/src/vendor/http/setting.py b/src/vendor/http/setting.py index 98482aae1..97a060660 100644 --- a/src/vendor/http/setting.py +++ b/src/vendor/http/setting.py @@ -1,129 +1,64 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### - -NAME = 'Setting' -DOCS = 'HTTP/2 Settings' -FLAG = 'isinstance(value, int) and 0x0000 <= value <= 0xFFFF' -LINK = 'https://www.iana.org/assignments/http2-parameters/settings.csv' - -############### -# Processors -############### - -page = requests.get(LINK) -data = page.text.strip().split('\r\n') - -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) +__all__ = ['Setting'] def hexlify(code): return f'0x{hex(code)[2:].upper().zfill(4)}' -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - name = item[1] - dscp = item[2] - rfcs = item[3] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f" {''.join(temp)}" if rfcs else '' - subs = re.sub(r'\(|\)', '', dscp) - dscp = f' {subs}' if subs else '' - - try: - temp = int(item[0], base=16) - code = hexlify(temp) - renm = rename(name, code) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f'#{desc}{dscp}' if desc or dscp else '' - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = map(lambda s: int(s, base=16), item[0].split('-')) - - miss.append(f'if {hexlify(start)} <= value <= {hexlify(stop)}:') - if desc or dscp: - miss.append(f' #{desc}{dscp}') - miss.append( - f" extend_enum(cls, '{name} [0x%s]' % hex(value)[2:].upper().zfill(4), value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class Setting(Vendor): + """HTTP/2 Settings""" + + FLAG = 'isinstance(value, int) and 0x0000 <= value <= 0xFFFF' + LINK = 'https://www.iana.org/assignments/http2-parameters/settings.csv' + + def process(self, data): + reader = csv.reader(data) + next(reader) # header + + enum = list() + miss = list() + for item in reader: + name = item[1] + dscp = item[2] + rfcs = item[3] + + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f" {''.join(temp)}" if rfcs else '' + subs = re.sub(r'\(|\)', '', dscp) + dscp = f' {subs}' if subs else '' + + try: + temp = int(item[0], base=16) + code = hexlify(temp) + renm = self.rename(name, code) + + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f'#{desc}{dscp}' if desc or dscp else '' + + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = map(lambda s: int(s, base=16), item[0].split('-')) + + miss.append(f'if {hexlify(start)} <= value <= {hexlify(stop)}:') + if desc or dscp: + miss.append(f' #{desc}{dscp}') + miss.append( + f" extend_enum(cls, '{name} [0x%s]' % hex(value)[2:].upper().zfill(4), value)") + miss.append(' return cls(value)') + return enum, miss + + +if __name__ == "__main__": + Setting() diff --git a/src/vendor/ipv4/classification_level.py b/src/vendor/ipv4/classification_level.py index 767670fd7..2fb68e33f 100644 --- a/src/vendor/ipv4/classification_level.py +++ b/src/vendor/ipv4/classification_level.py @@ -1,16 +1,11 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['ClassificationLevel'] -NAME = 'ClassificationLevel' -DOCS = 'Classification Level Encodings' -FLAG = 'isinstance(value, int) and 0b00000000 <= value <= 0b11111111' DATA = { 0b0000_0001: 'Reserved [4]', 0b0011_1101: 'Top Secret', @@ -22,47 +17,9 @@ 0b1111_0001: 'Reserved [1]', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def binary(code): - return f'0b{bin(code)[2:].upper().zfill(8)}' - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - 'temp = bin(value)[2:].upper().zfill(8)', - "extend_enum(cls, 'Unassigned [0b%s]' % (temp[:4]+'_'+temp[4:]), value)", - 'return cls(value)' -] -for code, name in DATA.items(): - code = binary(code) - renm = rename(name, code) - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -80,7 +37,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -90,11 +47,45 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +def binary(code): + return f'0b{bin(code)[2:].upper().zfill(8)}' + + +class ClassificationLevel(Vendor): + """Classification Level Encodings""" + + FLAG = 'isinstance(value, int) and 0b00000000 <= value <= 0b11111111' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) # pylint: disable=dict-values-not-iterating + + def process(self, data): + enum = list() + miss = [ + 'temp = bin(value)[2:].upper().zfill(8)', + "extend_enum(cls, 'Unassigned [0b%s]' % (temp[:4]+'_'+temp[4:]), value)", + 'return cls(value)' + ] + for code, name in data.items(): + code = binary(code) + renm = self.rename(name, code) + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + ClassificationLevel() diff --git a/src/vendor/ipv4/option_class.py b/src/vendor/ipv4/option_class.py index 276de838c..2f706be9a 100644 --- a/src/vendor/ipv4/option_class.py +++ b/src/vendor/ipv4/option_class.py @@ -1,16 +1,11 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['OptionClass'] -NAME = 'OptionClass' -DOCS = 'Option Classes' -FLAG = 'isinstance(value, int) and 0 <= value <= 3' DATA = { 0: 'control', 1: 'reserved for future use', @@ -18,41 +13,9 @@ 3: 'reserved for future use', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code) - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -70,7 +33,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -80,11 +43,43 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +def binary(code): + return f'0b{bin(code)[2:].upper().zfill(8)}' + + +class OptionClass(Vendor): + """Option Classes""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 3' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) # pylint: disable=dict-values-not-iterating + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in data.items(): + renm = self.rename(name, code) + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + OptionClass() diff --git a/src/vendor/ipv4/option_number.py b/src/vendor/ipv4/option_number.py index 1f8ecb371..5e64857b0 100644 --- a/src/vendor/ipv4/option_number.py +++ b/src/vendor/ipv4/option_number.py @@ -1,87 +1,16 @@ # -*- coding: utf-8 -*- import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### +__all__ = ['OptionNumber'] -NAME = 'OptionNumber' -DOCS = 'IP Option Numbers' -FLAG = 'isinstance(value, int) and 0 <= value <= 255' -LINK = 'https://www.iana.org/assignments/ip-parameters/ip-parameters-1.csv' - -############### -# Processors -############### - -page = requests.get(LINK) -data = page.text.strip().split('\r\n') - -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[4], - filter(lambda item: len(item[3].split('-')) != 2, reader))) - - -def rename(name, code, *, original): - if record[original] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for item in reader: - code = item[3] - dscp = item[4] - rfcs = item[5] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if re.match(r'\d+', rfc): - continue - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f" {''.join(temp)}" if rfcs else '' - - abbr, name = re.split(r'\W+-\W+', dscp) - temp = re.sub(r'\[\d+\]', '', name) - name = f' {temp}' if temp else '' - - renm = rename(abbr or f'Unassigned [{code}]', code, original=dscp) - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f'#{desc}{name}' if desc or name else '' - - enum.append(f'{pres}{sufs}') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -99,7 +28,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -109,11 +38,69 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class OptionNumber(Vendor): + """IP Option Numbers""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 255' + LINK = 'https://www.iana.org/assignments/ip-parameters/ip-parameters-1.csv' + + def count(self, data): + reader = csv.reader(data) + next(reader) # header + return collections.Counter(map(lambda item: item[4], # pylint: disable=map-builtin-not-iterating + filter(lambda item: len(item[3].split('-')) != 2, reader))) # pylint: disable=filter-builtin-not-iterating + + def rename(self, name, code, *, original): # pylint: disable=arguments-differ + if self.record[original] > 1: + return f'{name} [{code}]' + return name + + def process(self, data): + reader = csv.reader(data) + next(reader) # header + + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for item in reader: + code = item[3] + dscp = item[4] + rfcs = item[5] + + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if re.match(r'\d+', rfc): + continue + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f" {''.join(temp)}" if rfcs else '' + + abbr, name = re.split(r'\W+-\W+', dscp) + temp = re.sub(r'\[\d+\]', '', name) + name = f' {temp}' if temp else '' + + renm = self.rename(abbr or f'Unassigned [{code}]', code, original=dscp) + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f'#{desc}{name}' if desc or name else '' + + enum.append(f'{pres}{sufs}') + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + OptionNumber() diff --git a/src/vendor/ipv4/protection_authority.py b/src/vendor/ipv4/protection_authority.py index 86e7ac145..41d191fcb 100644 --- a/src/vendor/ipv4/protection_authority.py +++ b/src/vendor/ipv4/protection_authority.py @@ -1,17 +1,11 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor +__all__ = ['ProtectionAuthority'] -NAME = 'ProtectionAuthority' -DOCS = 'Protection Authority Bit Assignments' -FLAG = 'isinstance(value, int) and 0 <= value <= 7' DATA = { 0: 'GENSER', 1: 'SIOP-ESI', @@ -23,44 +17,9 @@ 7: 'Field Termination Indicator', } - -############### -# Processors -############### - - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code) - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -78,7 +37,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -88,11 +47,39 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class ProtectionAuthority(Vendor): + """Protection Authority Bit Assignments""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 7' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in data.items(): + renm = self.rename(name, code) + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + ProtectionAuthority() diff --git a/src/vendor/ipv4/qs_function.py b/src/vendor/ipv4/qs_function.py index 3417a166f..2547e8b80 100644 --- a/src/vendor/ipv4/qs_function.py +++ b/src/vendor/ipv4/qs_function.py @@ -1,56 +1,19 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['QS_Function'] -NAME = 'QS_Function' -DOCS = 'QS Functions' -FLAG = 'isinstance(value, int) and 0 <= value <= 8' DATA = { 0: 'Quick-Start Request', 8: 'Report of Approved Rate', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code) - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -68,7 +31,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -78,11 +41,39 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class QS_Function(Vendor): + """QS Functions""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 8' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in DATA.items(): + renm = self.rename(name, code) + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + QS_Function() diff --git a/src/vendor/ipv4/router_alert.py b/src/vendor/ipv4/router_alert.py index 6b339266f..cf075ac55 100644 --- a/src/vendor/ipv4/router_alert.py +++ b/src/vendor/ipv4/router_alert.py @@ -1,129 +1,64 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### +__all__ = ['RouterAlert'] -NAME = 'RouterAlert' -DOCS = 'IPv4 Router Alert Option Values' -FLAG = 'isinstance(value, int) and 0 <= value <= 65535' -LINK = 'https://www.iana.org/assignments/ip-parameters/ipv4-router-alert-option-values.csv' -############### -# Processors -############### +class RouterAlert(Vendor): + """IPv4 Router Alert Option Values""" -page = requests.get(LINK) -data = page.text.strip().split('\r\n') + FLAG = 'isinstance(value, int) and 0 <= value <= 65535' + LINK = 'https://www.iana.org/assignments/ip-parameters/ipv4-router-alert-option-values.csv' -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) + def process(self, data): + reader = csv.reader(data) + next(reader) # header + enum = list() + miss = list() + for item in reader: + name = item[1] + rfcs = item[2] -def rename(name, code): - if record[name] > 1: - return f'{name} [{code}]' - return name + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + desc = f"# {''.join(temp)}" if rfcs else '' + try: + code, _ = item[0], int(item[0]) + renm = self.rename(name, code) -reader = csv.reader(data) -header = next(reader) + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) -enum = list() -miss = list() -for item in reader: - name = item[1] - rfcs = item[2] + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = map(int, item[0].split('-')) + more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - desc = f"# {''.join(temp)}" if rfcs else '' + if 'Level' in name: + base = name.rstrip('s 0-31') + for code in range(start, stop+1): + renm = f'{base} {code-start}' + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) - try: - code, _ = item[0], int(item[0]) - renm = rename(name, code) + enum.append(f'{pres}{more}') + else: + miss.append(f'if {start} <= value <= {stop}:') + if more: + miss.append(f' {more}') + miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") + miss.append(' return cls(value)') + return enum, miss - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = map(int, item[0].split('-')) - more = re.sub(r'\r*\n', ' ', desc, re.MULTILINE) - - if 'Level' in name: - base = name.rstrip('s 0-31') - for code in range(start, stop+1): - renm = f'{base} {code-start}' - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - - enum.append(f'{pres}{more}') - else: - miss.append(f'if {start} <= value <= {stop}:') - if more: - miss.append(f' {more}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ -# -*- coding: utf-8 -*- - -from aenum import IntEnum, extend_enum - - -class {NAME}(IntEnum): - """Enumeration class for {NAME}.""" - _ignore_ = '{NAME} _' - {NAME} = vars() - - # {DOCS} - {ENUM} - - @staticmethod - def get(key, default=-1): - """Backport support for original codes.""" - if isinstance(key, int): - return {NAME}(key) - if key not in {NAME}._member_map_: - extend_enum({NAME}, key, default) - return {NAME}[key] - - @classmethod - def _missing_(cls, value): - """Lookup function used when value is not found.""" - if not ({FLAG}): - raise ValueError('%r is not a valid %s' % (value, cls.__name__)) - {MISS} - super()._missing_(value) -''' - - -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +if __name__ == '__main__': + RouterAlert() diff --git a/src/vendor/ipv4/tos_del.py b/src/vendor/ipv4/tos_del.py index 35d91a99f..4ecb9d6f7 100644 --- a/src/vendor/ipv4/tos_del.py +++ b/src/vendor/ipv4/tos_del.py @@ -1,56 +1,19 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['TOS_DEL'] -NAME = 'TOS_DEL' -DOCS = 'TOS (DS Field) Delay' -FLAG = 'isinstance(value, int) and 0 <= value <= 1' DATA = { 0: 'Normal', 1: 'Low', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code).upper() - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -68,7 +31,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -78,11 +41,39 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class TOS_DEL(Vendor): + """TOS (DS Field) Delay""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 1' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in DATA.items(): + renm = self.rename(name, code).upper() + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + TOS_DEL() diff --git a/src/vendor/ipv4/tos_ecn.py b/src/vendor/ipv4/tos_ecn.py index 5f5df15b0..e6f5a865e 100644 --- a/src/vendor/ipv4/tos_ecn.py +++ b/src/vendor/ipv4/tos_ecn.py @@ -1,16 +1,11 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['TOS_ECN'] -NAME = 'TOS_ECN' -DOCS = 'TOS ECN FIELD' -FLAG = 'isinstance(value, int) and 0b00 <= value <= 0b11' DATA = { 0b00: 'Not-ECT', 0b01: 'ECT(1)', @@ -18,41 +13,9 @@ 0b11: 'CE', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [0b{bin(code)[2:].zfill(2)}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [0b%s]' % bin(value)[2:].zfill(2), value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code) - enum.append(f"{NAME}[{renm!r}] = 0b{bin(code)[2:].zfill(2)}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -70,7 +33,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -80,11 +43,44 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class TOS_ECN(Vendor): + """TOS ECN FIELD""" + + FLAG = 'isinstance(value, int) and 0b00 <= value <= 0b11' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def rename(self, name, code): + if self.record[name] > 1: + name = f'{name} [0b{bin(code)[2:].zfill(2)}]' + return name + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [0b%s]' % bin(value)[2:].zfill(2), value)", + 'return cls(value)' + ] + for code, name in DATA.items(): + renm = self.rename(name, code) + enum.append(f"{self.NAME}[{renm!r}] = 0b{bin(code)[2:].zfill(2)}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + TOS_ECN() diff --git a/src/vendor/ipv4/tos_pre.py b/src/vendor/ipv4/tos_pre.py index 2c13d4b58..be04da120 100644 --- a/src/vendor/ipv4/tos_pre.py +++ b/src/vendor/ipv4/tos_pre.py @@ -1,16 +1,11 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['TOS_PRE'] -NAME = 'TOS_PRE' -DOCS = 'TOS (DS Field) Precedence' -FLAG = 'isinstance(value, int) and 0b000 <= value <= 0b111' DATA = { 0b111: 'Network Control', 0b110: 'Internetwork Control', @@ -22,41 +17,9 @@ 0b000: 'Routine', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code) - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -74,7 +37,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -84,11 +47,39 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class TOS_PRE(Vendor): + """TOS (DS Field) Precedence""" + + FLAG = 'isinstance(value, int) and 0b000 <= value <= 0b111' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in DATA.items(): + renm = self.rename(name, code) + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + TOS_PRE() diff --git a/src/vendor/ipv4/tos_rel.py b/src/vendor/ipv4/tos_rel.py index dbcf24559..2e1165867 100644 --- a/src/vendor/ipv4/tos_rel.py +++ b/src/vendor/ipv4/tos_rel.py @@ -1,56 +1,19 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['TOS_REL'] -NAME = 'TOS_REL' -DOCS = 'TOS (DS Field) Reliability' -FLAG = 'isinstance(value, int) and 0 <= value <= 1' DATA = { 0: 'Normal', 1: 'High', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code).upper() - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -68,7 +31,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -78,11 +41,39 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class TOS_REL(Vendor): + """TOS (DS Field) Reliability""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 1' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in DATA.items(): + renm = self.rename(name, code).upper() + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + TOS_REL() diff --git a/src/vendor/ipv4/tos_thr.py b/src/vendor/ipv4/tos_thr.py index 19e0055e7..c8c80ea30 100644 --- a/src/vendor/ipv4/tos_thr.py +++ b/src/vendor/ipv4/tos_thr.py @@ -1,56 +1,19 @@ # -*- coding: utf-8 -*- import collections -import contextlib -import os -############### -# Macros -############### +from pcapkit.vendor.default import Vendor + +__all__ = ['TOS_THR'] -NAME = 'TOS_THR' -DOCS = 'TOS (DS Field) Throughput' -FLAG = 'isinstance(value, int) and 0 <= value <= 1' DATA = { 0: 'Normal', 1: 'High', } -############### -# Processors -############### - -record = collections.Counter(DATA.values()) - - -def rename(name, code): - if record[name] > 1: - name = f'{name} [{code}]' - return name - - -enum = list() -miss = [ - "extend_enum(cls, 'Unassigned [%d]' % value, value)", - 'return cls(value)' -] -for code, name in DATA.items(): - renm = rename(name, code).upper() - enum.append(f"{NAME}[{renm!r}] = {code}".ljust(76)) - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) -MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) - - -def LINE(NAME, DOCS, FLAG, ENUM, MISS): return f'''\ +LINE = lambda NAME, DOCS, FLAG, ENUM, MISS: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -68,7 +31,7 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] @@ -78,11 +41,39 @@ def _missing_(cls, value): if not ({FLAG}): raise ValueError('%r is not a valid %s' % (value, cls.__name__)) {MISS} - super()._missing_(value) ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, FLAG, ENUM, MISS)) +class TOS_THR(Vendor): + """TOS (DS Field) Throughput""" + + FLAG = 'isinstance(value, int) and 0 <= value <= 1' + + def request(self): + return DATA + + def count(self, data): + return collections.Counter(data.values()) + + def process(self, data): + enum = list() + miss = [ + "extend_enum(cls, 'Unassigned [%d]' % value, value)", + 'return cls(value)' + ] + for code, name in DATA.items(): + renm = self.rename(name, code).upper() + enum.append(f"{self.NAME}[{renm!r}] = {code}".ljust(76)) + return enum, miss + + def context(self, data): + enum, miss = self.process(data) + + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + MISS = '\n '.join(map(lambda s: s.rstrip(), miss)) + + return LINE(self.NAME, self.DOCS, self.FLAG, ENUM, MISS) + + +if __name__ == "__main__": + TOS_THR() diff --git a/src/vendor/ipv6/extension_header.py b/src/vendor/ipv6/extension_header.py index 821a8ec7b..72ebc5cce 100644 --- a/src/vendor/ipv6/extension_header.py +++ b/src/vendor/ipv6/extension_header.py @@ -1,104 +1,15 @@ # -*- coding: utf-8 -*- -import collections -import contextlib import csv -import os import re -import requests +from pcapkit.vendor.default import Vendor -############### -# Macros -############### +__all__ = ['ExtensionHeader'] -NAME = 'ExtensionHeader' -DOCS = 'IPv6 Extension Header Types' -LINK = 'https://www.iana.org/assignments/protocol-numbers/protocol-numbers-1.csv' - -############### -# Processors -############### - -page = requests.get(LINK) -data = page.text.strip().split('\r\n') - -reader = csv.reader(data) -header = next(reader) -record = collections.Counter(map(lambda item: item[1], - filter(lambda item: len(item[0].split('-')) != 2, reader))) - - -def rename(name, code, *, original): - if record[original] > 1: - return f'{name} [{code}]' - return name - - -reader = csv.reader(data) -header = next(reader) - -enum = list() -miss = list() -for item in reader: - flag = item[3] - if flag != 'Y': - continue - - name = item[1] - rfcs = item[4] - - temp = list() - for rfc in filter(None, re.split(r'\[|\]', rfcs)): - if 'RFC' in rfc: - temp.append(f'[{rfc[:3]} {rfc[3:]}]') - else: - temp.append(f'[{rfc}]') - lrfc = re.sub(r'( )( )*', ' ', - f" {''.join(temp)}".replace('\n', ' ')) if rfcs else '' - - subd = re.sub(r'( )( )*', ' ', item[2].replace('\n', ' ')) - desc = f' {subd}' if item[2] else '' - - split = name.split(' (', 1) - if len(split) == 2: - name, cmmt = split[0], f" ({split[1]}" - else: - name, cmmt = name, '' - - try: - code, _ = item[0], int(item[0]) - if name == '': - name, desc = item[2], '' - renm = rename(name, code, original=item[1]) - - pres = f"{NAME}[{renm!r}] = {code}".ljust(76) - sufs = f"#{lrfc}{desc}{cmmt}" if lrfc or desc or cmmt else '' - - enum.append(f'{pres}{sufs}') - except ValueError: - start, stop = item[0].split('-') - if name == '': - name, desc = item[2], '' - - miss.append(f'if {start} <= value <= {stop}:') - if lrfc or desc or cmmt: - miss.append(f' #{lrfc}{desc}{cmmt}') - miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") - miss.append(' return cls(value)') - -############### -# Defaults -############### - -temp, FILE = os.path.split(os.path.abspath(__file__)) -ROOT, STEM = os.path.split(temp) - -ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) - - -def LINE(NAME, DOCS, ENUM): return f'''\ +LINE = lambda NAME, DOCS, ENUM: f'''\ # -*- coding: utf-8 -*- +# pylint: disable=line-too-long from aenum import IntEnum, extend_enum @@ -116,13 +27,81 @@ def get(key, default=-1): """Backport support for original codes.""" if isinstance(key, int): return {NAME}(key) - if key not in {NAME}._member_map_: + if key not in {NAME}._member_map_: # pylint: disable=no-member extend_enum({NAME}, key, default) return {NAME}[key] ''' -with contextlib.suppress(FileExistsError): - os.mkdir(os.path.join(ROOT, f'../const/{STEM}')) -with open(os.path.join(ROOT, f'../const/{STEM}/{FILE}'), 'w') as file: - file.write(LINE(NAME, DOCS, ENUM)) +class ExtensionHeader(Vendor): + """IPv6 Extension Header Types""" + + LINK = 'https://www.iana.org/assignments/protocol-numbers/protocol-numbers-1.csv' + + def rename(self, name, code, *, original): # pylint: disable=arguments-differ + if self.record[original] > 1: + return f'{name} [{code}]' + return name + + def process(self, data): + reader = csv.reader(data) + next(reader) # header + + enum = list() + miss = list() + for item in reader: + flag = item[3] + if flag != 'Y': + continue + + name = item[1] + rfcs = item[4] + + temp = list() + for rfc in filter(None, re.split(r'\[|\]', rfcs)): + if 'RFC' in rfc: + temp.append(f'[{rfc[:3]} {rfc[3:]}]') + else: + temp.append(f'[{rfc}]') + lrfc = re.sub(r'( )( )*', ' ', + f" {''.join(temp)}".replace('\n', ' ')) if rfcs else '' + + subd = re.sub(r'( )( )*', ' ', item[2].replace('\n', ' ')) + desc = f' {subd}' if item[2] else '' + + split = name.split(' (', 1) + if len(split) == 2: + name, cmmt = split[0], f" ({split[1]}" + else: + name, cmmt = name, '' + + try: + code, _ = item[0], int(item[0]) + if not name: + name, desc = item[2], '' + renm = self.rename(name, code, original=item[1]) + + pres = f"{self.NAME}[{renm!r}] = {code}".ljust(76) + sufs = f"#{lrfc}{desc}{cmmt}" if lrfc or desc or cmmt else '' + + enum.append(f'{pres}{sufs}') + except ValueError: + start, stop = item[0].split('-') + if not name: + name, desc = item[2], '' + + miss.append(f'if {start} <= value <= {stop}:') + if lrfc or desc or cmmt: + miss.append(f' #{lrfc}{desc}{cmmt}') + miss.append(f" extend_enum(cls, '{name} [%d]' % value, value)") + miss.append(' return cls(value)') + return enum + + def context(self, data): + enum = self.process(data) + ENUM = '\n '.join(map(lambda s: s.rstrip(), enum)) + return LINE(self.NAME, self.DOCS, ENUM) + + +if __name__ == '__main__': + ExtensionHeader()