Web Crawlers for Constant Enumerations¶
Base Generator¶
-
class
pcapkit.vendor.default.
Vendor
[source]¶ Bases:
object
Default vendor generator.
Inherit this class with
FLAG
&LINK
attributes, etc. to implement a new vendor generator.-
static
__new__
(cls)[source]¶ Subclassing checkpoint.
- Raises
VendorNotImplemented – If
cls
is not a subclass ofVendor
.
-
_request
()[source]¶ Fetch CSV data from
LINK
.This is the low-level call of
request()
.If
LINK
isNone
, it will directly call the upper methodrequest()
with NO arguments.The method will first try to GET the content of
LINK
. Should any exception raised, it will first try with proxy settings fromget_proxies()
.Note
Since some
LINK
links are from Wikipedia, etc., they might not be available in certain areas, e.g. the amazing PRC :)Would proxies failed again, it will prompt for user intervention, i.e. it will use
webbrowser.open()
to open the page in browser for you, and you can manually load that page and save the HTML source at the location it provides.- Returns
CSV data.
- Return type
List[str]
- Warns
VendorRequestWarning – If connection failed with and/or without proxies.
See also
-
count
(data)[source]¶ Count field records.
- Parameters
data (List[str]) – CSV data.
- Returns
Field recordings.
- Return type
Counter
-
rename
(name, code, *, original=None)[source]¶ Rename duplicated fields.
- Parameters
- Keyword Arguments
original (str) – Original field name (extracted from CSV records).
- Returns
Revised field name.
- Return type
Example
If
name
has multiple occurrences in the source registry, the field name will be sanitised as${name}_${code}
.Otherwise, the plain
name
will be returned.
-
static
-
pcapkit.vendor.default.
LINE
(NAME, DOCS, FLAG, ENUM, MISS)¶ Default constant template of enumerate registry from IANA CSV.
Command Line Tool¶
usage: pcapkit-vendor [-h] [-V] ...
update constant enumerations
positional arguments:
target update targets, supply none to update all
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-
pcapkit.vendor.__main__.
get_parser
()[source]¶ CLI argument parser.
- Returns
Argument parser.
- Return type
-
pcapkit.vendor.__main__.
main
()[source]¶ Entrypoint.
- Warns
InvalidVendorWarning – If vendor target not found in
pcapkit.vendor
module.
-
pcapkit.vendor.__main__.
run
(vendor)[source]¶ Script runner.
- Parameters
vendor (Type[Vendor]) – Subclass of
Vendor
frompcapkit.vendor
.- Warns
VendorRuntimeWarning – If failed to initiate the
vendor
class.