Skip to content

Commit b661dc1

Browse files
committed
New distribution [0.14.5]
* revised deps * added vendor CLI * delayed vendor import
1 parent bb261d4 commit b661dc1

File tree

9 files changed

+105
-16
lines changed

9 files changed

+105
-16
lines changed

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Module",
9+
"type": "python",
10+
"request": "launch",
11+
"module": "pcapkit"
12+
}
13+
]
14+
}

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"emojize",
2929
"eool",
3030
"exeng",
31+
"exlayer",
3132
"exlyr",
3233
"expkg",
3334
"exptl",
@@ -43,6 +44,8 @@
4344
"gaocegege",
4445
"gbhdr",
4546
"hdrs",
47+
"hexbuf",
48+
"hexlst",
4649
"httpv",
4750
"ifile",
4851
"ifnm",
@@ -80,13 +83,16 @@
8083
"sched",
8184
"splt",
8285
"srcport",
86+
"strbuf",
8387
"strflg",
88+
"strlst",
8489
"subd",
8590
"subn",
8691
"sufs",
8792
"sysconf",
8893
"tbitem",
8994
"tbody",
9095
"vinfo"
91-
]
96+
],
97+
"restructuredtext.confPath": "${workspaceFolder}/docs/conf.py"
9298
}

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ clean-pipenv:
5151
clean-pypi:
5252
cd $(DIR)
5353
mkdir -p sdist eggs wheels
54-
find dist -iname '*.egg' -exec mv {} eggs \;
55-
find dist -iname '*.whl' -exec mv {} wheels \;
56-
find dist -iname '*.tar.gz' -exec mv {} sdist \;
54+
[ -d dist ] && find dist -iname '*.egg' -exec mv {} eggs \; || true
55+
[ -d dist ] && find dist -iname '*.whl' -exec mv {} wheels \; || true
56+
[ -d dist ] && find dist -iname '*.tar.gz' -exec mv {} sdist \; || true
5757
rm -rf build dist *.egg-info
5858

5959
# update pipenv
@@ -85,7 +85,7 @@ dist-pypi: clean-pypi dist-pypi-new dist-pypi-old
8585
dist-pypi-new:
8686
set -ex
8787
cd $(DIR)
88-
~/.pyenv/versions/3.8-dev/bin/python3.8 setup.py bdist_egg bdist_wheel --python-tag='cp38'
88+
~/.pyenv/versions/3.8.0/bin/python3.8 setup.py bdist_egg bdist_wheel --python-tag='cp38'
8989
~/.pyenv/versions/3.7.4/bin/python3.7 setup.py bdist_egg bdist_wheel --python-tag='cp37'
9090
~/.pyenv/versions/3.6.9/bin/python3.6 setup.py bdist_egg bdist_wheel --python-tag='cp36'
9191
~/.pyenv/versions/pypy3.6-7.1.1/bin/pypy3 setup.py bdist_egg bdist_wheel --python-tag='pp36'

doc/pcap/Frame.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Reference: [Libpcap File Format](https://wiki.wireshark.org/Development/LibpcapF
88

99
# PCAP Frame Header
1010

11-
## Description
11+
## Description
1212

1313
 
1414

@@ -41,7 +41,7 @@ class Frame(file, *, num, proto, nanosecond, **kwrags)
4141
2. `pcapkit.protocols.protocol.Protocol`
4242
3. `pcapkit.protocols.pcap.frame.Frame`
4343

44-
### Data Format
44+
### Data Format
4545

4646
```
4747
(Info) Frame

doc/pcap/Header.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Reference: [Libpcap File Format](https://wiki.wireshark.org/Development/LibpcapF
1010

1111
# PCAP Global Header
1212

13-
## Description
13+
## Description
1414

1515
  This header starts the `libpcap` file and will be followed by the first packet header:
1616

setup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from distutils.core import setup
77

88
# version string
9-
__version__ = '0.14.4'
9+
__version__ = '0.14.5'
1010

1111
# README
1212
with open('README.md', encoding='utf-8') as file:
@@ -38,7 +38,7 @@
3838
'all': [
3939
'emoji',
4040
'dpkt', 'scapy', 'pyshark',
41-
'requests[socks]', 'bs4', 'html5lib',
41+
'requests[socks]', 'bs4[html5lib]',
4242
],
4343
# for CLI display
4444
'cli': ['emoji'],
@@ -47,14 +47,15 @@
4747
'Scapy': ['scapy'],
4848
'PyShark': ['pyshark'],
4949
# for developers
50-
'vendor': ['requests[socks]', 'bs4', 'html5lib'],
50+
'vendor': ['requests[socks]', 'bs4[html5lib]'],
5151
# version compatibility
5252
':python_version == "3.4"': ['pathlib2>=2.3.2'],
5353
},
5454
# py_modules = ['pcapkit'],
5555
entry_points={
5656
'console_scripts': [
5757
'pcapkit-cli = pcapkit.__main__:main',
58+
'pcapkit-vendor = pcapkit.vendor.__main__:main',
5859
]
5960
},
6061
# packages=setuptools.find_namespace_packages(
@@ -109,6 +110,9 @@
109110
'pcapkit.vendor.tcp',
110111
'pcapkit.vendor.vlan',
111112
],
113+
package_dir={
114+
'pcapkit': 'src',
115+
},
112116
package_data={
113117
'': [
114118
'LICENSE',

src/all.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
"""
1111
import pcapkit.const as const
12-
import pcapkit.vendor as vendor
12+
# import pcapkit.vendor as vendor
1313
from pcapkit.corekit import *
1414
from pcapkit.dumpkit import *
1515
from pcapkit.foundation import *
@@ -24,8 +24,8 @@
2424
# pcapkit.const
2525
'const',
2626

27-
# pcapkit.vendor
28-
'vendor',
27+
# # pcapkit.vendor
28+
# 'vendor',
2929

3030
# pcapkit.corekit
3131
'Info', # Info Class

src/utilities/warnings.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# UserWarning
88
'BaseWarning',
99
# ImportWarning
10-
'FormatWarning', 'EngineWarning',
10+
'FormatWarning', 'EngineWarning', 'InvalidVendorWarning',
1111
# RuntimeWarning
1212
'FileWarning', 'LayerWarning', 'ProtocolWarning', 'AttributeWarning',
13-
'DevModeWarning', 'VendorRequestWarning',
13+
'DevModeWarning', 'VendorRequestWarning', 'VendorRuntimeWarning',
1414
# ResourceWarning
1515
'DPKTWarning', 'ScapyWarning', 'PySharkWarning'
1616
]
@@ -41,6 +41,10 @@ class EngineWarning(BaseWarning, ImportWarning):
4141
"""Unsupported extraction engine."""
4242

4343

44+
class InvalidVendorWarning(BaseWarning, ImportWarning):
45+
"""Vendor CLI invalid updater."""
46+
47+
4448
##############################################################################
4549
# RuntimeWarning session.
4650
##############################################################################
@@ -70,6 +74,10 @@ class VendorRequestWarning(BaseWarning, RuntimeWarning):
7074
"""Vendor request connection failed."""
7175

7276

77+
class VendorRuntimeWarning(BaseWarning, RuntimeWarning):
78+
"""Vendor failed during runtime."""
79+
80+
7381
##############################################################################
7482
# ResourceWarning session.
7583
##############################################################################

src/vendor/__main__.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
"""CLI for web crawlers."""
3+
4+
import argparse
5+
import importlib
6+
import multiprocessing
7+
import sys
8+
import warnings
9+
10+
import pcapkit.vendor as vendor_module
11+
from pcapkit.utilities.warnings import InvalidVendorWarning, VendorRuntimeWarning
12+
from pcapkit.vendor import __all__ as vendor_all
13+
14+
# version string
15+
__version__ = '0.14.5'
16+
17+
18+
def get_parser():
19+
parser = argparse.ArgumentParser(prog='pcapkit-vendor',
20+
description='update constant enumerations')
21+
parser.add_argument('-V', '--version', action='version', version=__version__)
22+
parser.add_argument('target', action='store', nargs=argparse.REMAINDER,
23+
help='update targets, supply none to update all')
24+
return parser
25+
26+
27+
def run(vendor):
28+
print(vendor.__doc__)
29+
try:
30+
vendor()
31+
except Exception as error:
32+
warnings.warn(error, VendorRuntimeWarning)
33+
34+
35+
def main():
36+
parser = get_parser()
37+
args = parser.parse_args()
38+
39+
target_list = list()
40+
for target in args.target:
41+
try:
42+
module = importlib.import_module(f'pcapkit.vendor.{target}')
43+
target_list.extend(getattr(module, name) for name in module.__all__)
44+
except ImportError:
45+
warn = warnings.formatwarning(f'invalid vendor updater: {target}', InvalidVendorWarning,
46+
__file__, 0, ' '.join(sys.argv))
47+
print(warn, file=sys.stderr)
48+
49+
if not target_list:
50+
target_list.extend(getattr(vendor_module, name) for name in vendor_all)
51+
52+
with multiprocessing.Pool() as pool:
53+
pool.map(run, target_list)
54+
55+
56+
if __name__ == "__main__":
57+
sys.exit(main())

0 commit comments

Comments
 (0)