pypcapkit 1.3.5.post6__cp312-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pcapkit/__init__.py +124 -0
- pcapkit/__main__.py +138 -0
- pcapkit/all.py +136 -0
- pcapkit/const/__init__.py +81 -0
- pcapkit/const/arp/__init__.py +25 -0
- pcapkit/const/arp/hardware.py +181 -0
- pcapkit/const/arp/operation.py +131 -0
- pcapkit/const/ftp/__init__.py +25 -0
- pcapkit/const/ftp/command.py +309 -0
- pcapkit/const/ftp/return_code.py +304 -0
- pcapkit/const/hip/__init__.py +94 -0
- pcapkit/const/hip/certificate.py +77 -0
- pcapkit/const/hip/cipher.py +65 -0
- pcapkit/const/hip/di.py +59 -0
- pcapkit/const/hip/ecdsa_curve.py +59 -0
- pcapkit/const/hip/ecdsa_low_curve.py +56 -0
- pcapkit/const/hip/eddsa_curve.py +65 -0
- pcapkit/const/hip/esp_transform_suite.py +98 -0
- pcapkit/const/hip/group.py +86 -0
- pcapkit/const/hip/hi_algorithm.py +86 -0
- pcapkit/const/hip/hit_suite.py +68 -0
- pcapkit/const/hip/nat_traversal.py +62 -0
- pcapkit/const/hip/notify_message.py +200 -0
- pcapkit/const/hip/packet.py +89 -0
- pcapkit/const/hip/parameter.py +377 -0
- pcapkit/const/hip/registration.py +68 -0
- pcapkit/const/hip/registration_failure.py +84 -0
- pcapkit/const/hip/suite.py +71 -0
- pcapkit/const/hip/transport.py +59 -0
- pcapkit/const/http/__init__.py +39 -0
- pcapkit/const/http/error_code.py +95 -0
- pcapkit/const/http/frame.py +95 -0
- pcapkit/const/http/method.py +184 -0
- pcapkit/const/http/setting.py +96 -0
- pcapkit/const/http/status_code.py +298 -0
- pcapkit/const/ipv4/__init__.py +57 -0
- pcapkit/const/ipv4/classification_level.py +64 -0
- pcapkit/const/ipv4/option_class.py +55 -0
- pcapkit/const/ipv4/option_number.py +137 -0
- pcapkit/const/ipv4/protection_authority.py +63 -0
- pcapkit/const/ipv4/qs_function.py +51 -0
- pcapkit/const/ipv4/router_alert.py +251 -0
- pcapkit/const/ipv4/tos_del.py +51 -0
- pcapkit/const/ipv4/tos_ecn.py +55 -0
- pcapkit/const/ipv4/tos_pre.py +63 -0
- pcapkit/const/ipv4/tos_rel.py +51 -0
- pcapkit/const/ipv4/tos_thr.py +51 -0
- pcapkit/const/ipv4/ts_flag.py +53 -0
- pcapkit/const/ipv6/__init__.py +53 -0
- pcapkit/const/ipv6/extension_header.py +69 -0
- pcapkit/const/ipv6/option.py +137 -0
- pcapkit/const/ipv6/option_action.py +55 -0
- pcapkit/const/ipv6/qs_function.py +51 -0
- pcapkit/const/ipv6/router_alert.py +266 -0
- pcapkit/const/ipv6/routing.py +80 -0
- pcapkit/const/ipv6/seed_id.py +55 -0
- pcapkit/const/ipv6/smf_dpd_mode.py +51 -0
- pcapkit/const/ipv6/tagger_id.py +62 -0
- pcapkit/const/ipx/__init__.py +27 -0
- pcapkit/const/ipx/packet.py +72 -0
- pcapkit/const/ipx/socket.py +104 -0
- pcapkit/const/l2tp/__init__.py +21 -0
- pcapkit/const/l2tp/type.py +51 -0
- pcapkit/const/mh/__init__.py +204 -0
- pcapkit/const/mh/access_type.py +92 -0
- pcapkit/const/mh/ack_status_code.py +71 -0
- pcapkit/const/mh/ani_suboption.py +74 -0
- pcapkit/const/mh/auth_subtype.py +53 -0
- pcapkit/const/mh/binding_ack_flag.py +66 -0
- pcapkit/const/mh/binding_error.py +51 -0
- pcapkit/const/mh/binding_revocation.py +59 -0
- pcapkit/const/mh/binding_update_flag.py +81 -0
- pcapkit/const/mh/cga_extension.py +66 -0
- pcapkit/const/mh/cga_sec.py +57 -0
- pcapkit/const/mh/cga_type.py +68 -0
- pcapkit/const/mh/dhcp_support_mode.py +53 -0
- pcapkit/const/mh/dns_status_code.py +65 -0
- pcapkit/const/mh/dsmip6_tls_packet.py +62 -0
- pcapkit/const/mh/dsmipv6_home_address.py +74 -0
- pcapkit/const/mh/enumerating_algorithm.py +56 -0
- pcapkit/const/mh/fb_ack_status.py +62 -0
- pcapkit/const/mh/fb_action.py +71 -0
- pcapkit/const/mh/fb_indication_trigger.py +65 -0
- pcapkit/const/mh/fb_type.py +59 -0
- pcapkit/const/mh/flow_id_status.py +77 -0
- pcapkit/const/mh/flow_id_suboption.py +71 -0
- pcapkit/const/mh/handoff_type.py +71 -0
- pcapkit/const/mh/handover_ack_flag.py +54 -0
- pcapkit/const/mh/handover_ack_status.py +92 -0
- pcapkit/const/mh/handover_initiate_flag.py +57 -0
- pcapkit/const/mh/handover_initiate_status.py +62 -0
- pcapkit/const/mh/home_address_reply.py +71 -0
- pcapkit/const/mh/lla_code.py +63 -0
- pcapkit/const/mh/lma_mag_suboption.py +59 -0
- pcapkit/const/mh/mn_group_id.py +59 -0
- pcapkit/const/mh/mn_id_subtype.py +77 -0
- pcapkit/const/mh/operator_id.py +63 -0
- pcapkit/const/mh/option.py +260 -0
- pcapkit/const/mh/packet.py +119 -0
- pcapkit/const/mh/qos_attribute.py +89 -0
- pcapkit/const/mh/revocation_status_code.py +83 -0
- pcapkit/const/mh/revocation_trigger.py +86 -0
- pcapkit/const/mh/status_code.py +232 -0
- pcapkit/const/mh/traffic_selector.py +62 -0
- pcapkit/const/mh/upa_status.py +71 -0
- pcapkit/const/mh/upn_reason.py +80 -0
- pcapkit/const/ospf/__init__.py +27 -0
- pcapkit/const/ospf/authentication.py +65 -0
- pcapkit/const/ospf/packet.py +71 -0
- pcapkit/const/pcapng/__init__.py +51 -0
- pcapkit/const/pcapng/block_type.py +152 -0
- pcapkit/const/pcapng/filter_type.py +48 -0
- pcapkit/const/pcapng/hash_algorithm.py +59 -0
- pcapkit/const/pcapng/option_type.py +233 -0
- pcapkit/const/pcapng/record_type.py +57 -0
- pcapkit/const/pcapng/secrets_type.py +56 -0
- pcapkit/const/pcapng/verdict_type.py +53 -0
- pcapkit/const/reg/__init__.py +34 -0
- pcapkit/const/reg/apptype.py +32728 -0
- pcapkit/const/reg/ethertype.py +714 -0
- pcapkit/const/reg/linktype.py +890 -0
- pcapkit/const/reg/transtype.py +526 -0
- pcapkit/const/tcp/__init__.py +35 -0
- pcapkit/const/tcp/checksum.py +55 -0
- pcapkit/const/tcp/flags.py +73 -0
- pcapkit/const/tcp/mp_tcp_option.py +80 -0
- pcapkit/const/tcp/option.py +198 -0
- pcapkit/const/vlan/__init__.py +23 -0
- pcapkit/const/vlan/priority_level.py +71 -0
- pcapkit/corekit/__init__.py +59 -0
- pcapkit/corekit/fields/__init__.py +45 -0
- pcapkit/corekit/fields/collections.py +282 -0
- pcapkit/corekit/fields/field.py +269 -0
- pcapkit/corekit/fields/ipaddress.py +274 -0
- pcapkit/corekit/fields/misc.py +722 -0
- pcapkit/corekit/fields/numbers.py +375 -0
- pcapkit/corekit/fields/strings.py +245 -0
- pcapkit/corekit/infoclass.py +394 -0
- pcapkit/corekit/io.py +506 -0
- pcapkit/corekit/module.py +39 -0
- pcapkit/corekit/multidict.py +626 -0
- pcapkit/corekit/protochain.py +263 -0
- pcapkit/corekit/version.py +33 -0
- pcapkit/dumpkit/__init__.py +15 -0
- pcapkit/dumpkit/common.py +199 -0
- pcapkit/dumpkit/null.py +77 -0
- pcapkit/dumpkit/pcap.py +144 -0
- pcapkit/foundation/__init__.py +45 -0
- pcapkit/foundation/engines/__init__.py +36 -0
- pcapkit/foundation/engines/dpkt.py +230 -0
- pcapkit/foundation/engines/engine.py +194 -0
- pcapkit/foundation/engines/pcap.py +188 -0
- pcapkit/foundation/engines/pcapng.py +310 -0
- pcapkit/foundation/engines/pyshark.py +166 -0
- pcapkit/foundation/engines/scapy.py +161 -0
- pcapkit/foundation/extraction.py +915 -0
- pcapkit/foundation/reassembly/__init__.py +49 -0
- pcapkit/foundation/reassembly/data/__init__.py +48 -0
- pcapkit/foundation/reassembly/data/ip.py +117 -0
- pcapkit/foundation/reassembly/data/tcp.py +145 -0
- pcapkit/foundation/reassembly/ip.py +192 -0
- pcapkit/foundation/reassembly/ipv4.py +50 -0
- pcapkit/foundation/reassembly/ipv6.py +50 -0
- pcapkit/foundation/reassembly/reassembly.py +389 -0
- pcapkit/foundation/reassembly/tcp.py +249 -0
- pcapkit/foundation/registry/__init__.py +41 -0
- pcapkit/foundation/registry/foundation.py +327 -0
- pcapkit/foundation/registry/protocols.py +885 -0
- pcapkit/foundation/traceflow/__init__.py +44 -0
- pcapkit/foundation/traceflow/data/__init__.py +30 -0
- pcapkit/foundation/traceflow/data/tcp.py +105 -0
- pcapkit/foundation/traceflow/tcp.py +159 -0
- pcapkit/foundation/traceflow/traceflow.py +390 -0
- pcapkit/interface/__init__.py +22 -0
- pcapkit/interface/core.py +185 -0
- pcapkit/interface/misc.py +120 -0
- pcapkit/protocols/__init__.py +85 -0
- pcapkit/protocols/application/NotImplemented/bgp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcpv6.py +0 -0
- pcapkit/protocols/application/NotImplemented/dns.py +0 -0
- pcapkit/protocols/application/NotImplemented/imap.py +0 -0
- pcapkit/protocols/application/NotImplemented/ldap.py +0 -0
- pcapkit/protocols/application/NotImplemented/mqtt.py +0 -0
- pcapkit/protocols/application/NotImplemented/nntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/onc_rpc.py +0 -0
- pcapkit/protocols/application/NotImplemented/pop.py +0 -0
- pcapkit/protocols/application/NotImplemented/rip.py +0 -0
- pcapkit/protocols/application/NotImplemented/rtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/sip.py +0 -0
- pcapkit/protocols/application/NotImplemented/smtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/snmp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ssh.py +0 -0
- pcapkit/protocols/application/NotImplemented/telnet.py +0 -0
- pcapkit/protocols/application/NotImplemented/tls.py +0 -0
- pcapkit/protocols/application/NotImplemented/xmpp.py +0 -0
- pcapkit/protocols/application/__init__.py +34 -0
- pcapkit/protocols/application/application.py +114 -0
- pcapkit/protocols/application/ftp.py +206 -0
- pcapkit/protocols/application/http.py +176 -0
- pcapkit/protocols/application/httpv1.py +320 -0
- pcapkit/protocols/application/httpv2.py +1255 -0
- pcapkit/protocols/data/__init__.py +192 -0
- pcapkit/protocols/data/application/__init__.py +57 -0
- pcapkit/protocols/data/application/ftp.py +59 -0
- pcapkit/protocols/data/application/httpv1.py +79 -0
- pcapkit/protocols/data/application/httpv2.py +293 -0
- pcapkit/protocols/data/data.py +25 -0
- pcapkit/protocols/data/internet/__init__.py +298 -0
- pcapkit/protocols/data/internet/ah.py +31 -0
- pcapkit/protocols/data/internet/hip.py +804 -0
- pcapkit/protocols/data/internet/hopopt.py +351 -0
- pcapkit/protocols/data/internet/ipv4.py +369 -0
- pcapkit/protocols/data/internet/ipv6.py +67 -0
- pcapkit/protocols/data/internet/ipv6_frag.py +29 -0
- pcapkit/protocols/data/internet/ipv6_opts.py +368 -0
- pcapkit/protocols/data/internet/ipv6_route.py +86 -0
- pcapkit/protocols/data/internet/ipx.py +56 -0
- pcapkit/protocols/data/internet/mh.py +509 -0
- pcapkit/protocols/data/link/__init__.py +33 -0
- pcapkit/protocols/data/link/arp.py +74 -0
- pcapkit/protocols/data/link/ethernet.py +28 -0
- pcapkit/protocols/data/link/l2tp.py +63 -0
- pcapkit/protocols/data/link/ospf.py +58 -0
- pcapkit/protocols/data/link/vlan.py +42 -0
- pcapkit/protocols/data/misc/__init__.py +109 -0
- pcapkit/protocols/data/misc/null.py +18 -0
- pcapkit/protocols/data/misc/pcap/__init__.py +18 -0
- pcapkit/protocols/data/misc/pcap/frame.py +56 -0
- pcapkit/protocols/data/misc/pcap/header.py +53 -0
- pcapkit/protocols/data/misc/pcapng.py +925 -0
- pcapkit/protocols/data/misc/raw.py +25 -0
- pcapkit/protocols/data/protocol.py +32 -0
- pcapkit/protocols/data/transport/__init__.py +71 -0
- pcapkit/protocols/data/transport/tcp.py +555 -0
- pcapkit/protocols/data/transport/udp.py +29 -0
- pcapkit/protocols/internet/NotImplemented/ecn.py +0 -0
- pcapkit/protocols/internet/NotImplemented/esp.py +97 -0
- pcapkit/protocols/internet/NotImplemented/icmp.py +0 -0
- pcapkit/protocols/internet/NotImplemented/icmpv6.py +0 -0
- pcapkit/protocols/internet/NotImplemented/igmp.py +0 -0
- pcapkit/protocols/internet/NotImplemented/shim6.py +0 -0
- pcapkit/protocols/internet/__init__.py +43 -0
- pcapkit/protocols/internet/ah.py +275 -0
- pcapkit/protocols/internet/hip.py +4727 -0
- pcapkit/protocols/internet/hopopt.py +1879 -0
- pcapkit/protocols/internet/internet.py +249 -0
- pcapkit/protocols/internet/ip.py +51 -0
- pcapkit/protocols/internet/ipsec.py +50 -0
- pcapkit/protocols/internet/ipv4.py +1782 -0
- pcapkit/protocols/internet/ipv6.py +412 -0
- pcapkit/protocols/internet/ipv6_frag.py +258 -0
- pcapkit/protocols/internet/ipv6_opts.py +1890 -0
- pcapkit/protocols/internet/ipv6_route.py +708 -0
- pcapkit/protocols/internet/ipx.py +230 -0
- pcapkit/protocols/internet/mh.py +2764 -0
- pcapkit/protocols/link/NotImplemented/dsl.py +0 -0
- pcapkit/protocols/link/NotImplemented/eapol.py +1 -0
- pcapkit/protocols/link/NotImplemented/fddi.py +0 -0
- pcapkit/protocols/link/NotImplemented/isdn.py +0 -0
- pcapkit/protocols/link/NotImplemented/ndp.py +0 -0
- pcapkit/protocols/link/NotImplemented/ppp.py +0 -0
- pcapkit/protocols/link/__init__.py +35 -0
- pcapkit/protocols/link/arp.py +421 -0
- pcapkit/protocols/link/ethernet.py +248 -0
- pcapkit/protocols/link/l2tp.py +267 -0
- pcapkit/protocols/link/link.py +140 -0
- pcapkit/protocols/link/ospf.py +342 -0
- pcapkit/protocols/link/rarp.py +82 -0
- pcapkit/protocols/link/vlan.py +225 -0
- pcapkit/protocols/misc/__init__.py +37 -0
- pcapkit/protocols/misc/null.py +129 -0
- pcapkit/protocols/misc/pcap/__init__.py +17 -0
- pcapkit/protocols/misc/pcap/frame.py +478 -0
- pcapkit/protocols/misc/pcap/header.py +358 -0
- pcapkit/protocols/misc/pcapng.py +5520 -0
- pcapkit/protocols/misc/raw.py +180 -0
- pcapkit/protocols/protocol.py +1216 -0
- pcapkit/protocols/schema/__init__.py +140 -0
- pcapkit/protocols/schema/application/__init__.py +40 -0
- pcapkit/protocols/schema/application/ftp.py +21 -0
- pcapkit/protocols/schema/application/httpv1.py +21 -0
- pcapkit/protocols/schema/application/httpv2.py +384 -0
- pcapkit/protocols/schema/internet/__init__.py +294 -0
- pcapkit/protocols/schema/internet/ah.py +40 -0
- pcapkit/protocols/schema/internet/hip.py +1184 -0
- pcapkit/protocols/schema/internet/hopopt.py +679 -0
- pcapkit/protocols/schema/internet/ipv4.py +576 -0
- pcapkit/protocols/schema/internet/ipv6.py +63 -0
- pcapkit/protocols/schema/internet/ipv6_frag.py +48 -0
- pcapkit/protocols/schema/internet/ipv6_opts.py +680 -0
- pcapkit/protocols/schema/internet/ipv6_route.py +197 -0
- pcapkit/protocols/schema/internet/ipx.py +40 -0
- pcapkit/protocols/schema/internet/mh.py +718 -0
- pcapkit/protocols/schema/link/__init__.py +19 -0
- pcapkit/protocols/schema/link/arp.py +39 -0
- pcapkit/protocols/schema/link/ethernet.py +51 -0
- pcapkit/protocols/schema/link/l2tp.py +88 -0
- pcapkit/protocols/schema/link/ospf.py +90 -0
- pcapkit/protocols/schema/link/vlan.py +69 -0
- pcapkit/protocols/schema/misc/__init__.py +108 -0
- pcapkit/protocols/schema/misc/null.py +18 -0
- pcapkit/protocols/schema/misc/pcap/__init__.py +10 -0
- pcapkit/protocols/schema/misc/pcap/frame.py +51 -0
- pcapkit/protocols/schema/misc/pcap/header.py +63 -0
- pcapkit/protocols/schema/misc/pcapng.py +1689 -0
- pcapkit/protocols/schema/misc/raw.py +24 -0
- pcapkit/protocols/schema/schema.py +809 -0
- pcapkit/protocols/schema/transport/__init__.py +69 -0
- pcapkit/protocols/schema/transport/tcp.py +928 -0
- pcapkit/protocols/schema/transport/udp.py +90 -0
- pcapkit/protocols/transport/NotImplemented/dccp.py +0 -0
- pcapkit/protocols/transport/NotImplemented/rsvp.py +0 -0
- pcapkit/protocols/transport/NotImplemented/sctp.py +0 -0
- pcapkit/protocols/transport/__init__.py +27 -0
- pcapkit/protocols/transport/tcp.py +3025 -0
- pcapkit/protocols/transport/transport.py +158 -0
- pcapkit/protocols/transport/udp.py +214 -0
- pcapkit/py.typed +0 -0
- pcapkit/toolkit/__init__.py +57 -0
- pcapkit/toolkit/dpkt.py +306 -0
- pcapkit/toolkit/pcap.py +212 -0
- pcapkit/toolkit/pcapng.py +251 -0
- pcapkit/toolkit/pyshark.py +99 -0
- pcapkit/toolkit/scapy.py +297 -0
- pcapkit/utilities/__init__.py +20 -0
- pcapkit/utilities/compat.py +196 -0
- pcapkit/utilities/decorators.py +197 -0
- pcapkit/utilities/exceptions.py +365 -0
- pcapkit/utilities/logging.py +55 -0
- pcapkit/utilities/warnings.py +185 -0
- pcapkit/vendor/__init__.py +105 -0
- pcapkit/vendor/__main__.py +92 -0
- pcapkit/vendor/arp/__init__.py +27 -0
- pcapkit/vendor/arp/hardware.py +29 -0
- pcapkit/vendor/arp/operation.py +29 -0
- pcapkit/vendor/default.py +474 -0
- pcapkit/vendor/ftp/__init__.py +27 -0
- pcapkit/vendor/ftp/command.py +244 -0
- pcapkit/vendor/ftp/return_code.py +256 -0
- pcapkit/vendor/hip/__init__.py +94 -0
- pcapkit/vendor/hip/certificate.py +29 -0
- pcapkit/vendor/hip/cipher.py +29 -0
- pcapkit/vendor/hip/di.py +29 -0
- pcapkit/vendor/hip/ecdsa_curve.py +29 -0
- pcapkit/vendor/hip/ecdsa_low_curve.py +29 -0
- pcapkit/vendor/hip/eddsa_curve.py +85 -0
- pcapkit/vendor/hip/esp_transform_suite.py +29 -0
- pcapkit/vendor/hip/group.py +87 -0
- pcapkit/vendor/hip/hi_algorithm.py +29 -0
- pcapkit/vendor/hip/hit_suite.py +29 -0
- pcapkit/vendor/hip/nat_traversal.py +29 -0
- pcapkit/vendor/hip/notify_message.py +29 -0
- pcapkit/vendor/hip/packet.py +88 -0
- pcapkit/vendor/hip/parameter.py +88 -0
- pcapkit/vendor/hip/registration.py +29 -0
- pcapkit/vendor/hip/registration_failure.py +29 -0
- pcapkit/vendor/hip/suite.py +29 -0
- pcapkit/vendor/hip/transport.py +29 -0
- pcapkit/vendor/http/__init__.py +39 -0
- pcapkit/vendor/http/error_code.py +95 -0
- pcapkit/vendor/http/frame.py +91 -0
- pcapkit/vendor/http/method.py +167 -0
- pcapkit/vendor/http/setting.py +93 -0
- pcapkit/vendor/http/status_code.py +185 -0
- pcapkit/vendor/ipv4/__init__.py +57 -0
- pcapkit/vendor/ipv4/classification_level.py +91 -0
- pcapkit/vendor/ipv4/option_class.py +80 -0
- pcapkit/vendor/ipv4/option_number.py +105 -0
- pcapkit/vendor/ipv4/protection_authority.py +84 -0
- pcapkit/vendor/ipv4/qs_function.py +78 -0
- pcapkit/vendor/ipv4/router_alert.py +93 -0
- pcapkit/vendor/ipv4/tos_del.py +78 -0
- pcapkit/vendor/ipv4/tos_ecn.py +95 -0
- pcapkit/vendor/ipv4/tos_pre.py +84 -0
- pcapkit/vendor/ipv4/tos_rel.py +78 -0
- pcapkit/vendor/ipv4/tos_thr.py +77 -0
- pcapkit/vendor/ipv4/ts_flag.py +79 -0
- pcapkit/vendor/ipv6/__init__.py +53 -0
- pcapkit/vendor/ipv6/extension_header.py +171 -0
- pcapkit/vendor/ipv6/option.py +104 -0
- pcapkit/vendor/ipv6/option_action.py +90 -0
- pcapkit/vendor/ipv6/qs_function.py +78 -0
- pcapkit/vendor/ipv6/router_alert.py +93 -0
- pcapkit/vendor/ipv6/routing.py +87 -0
- pcapkit/vendor/ipv6/seed_id.py +81 -0
- pcapkit/vendor/ipv6/smf_dpd_mode.py +78 -0
- pcapkit/vendor/ipv6/tagger_id.py +81 -0
- pcapkit/vendor/ipx/__init__.py +37 -0
- pcapkit/vendor/ipx/packet.py +123 -0
- pcapkit/vendor/ipx/socket.py +125 -0
- pcapkit/vendor/l2tp/__init__.py +21 -0
- pcapkit/vendor/l2tp/type.py +78 -0
- pcapkit/vendor/mh/__init__.py +204 -0
- pcapkit/vendor/mh/access_type.py +87 -0
- pcapkit/vendor/mh/ack_status_code.py +88 -0
- pcapkit/vendor/mh/ani_suboption.py +88 -0
- pcapkit/vendor/mh/auth_subtype.py +83 -0
- pcapkit/vendor/mh/binding_ack_flag.py +148 -0
- pcapkit/vendor/mh/binding_error.py +78 -0
- pcapkit/vendor/mh/binding_revocation.py +87 -0
- pcapkit/vendor/mh/binding_update_flag.py +147 -0
- pcapkit/vendor/mh/cga_extension.py +91 -0
- pcapkit/vendor/mh/cga_sec.py +91 -0
- pcapkit/vendor/mh/cga_type.py +74 -0
- pcapkit/vendor/mh/dhcp_support_mode.py +77 -0
- pcapkit/vendor/mh/dns_status_code.py +87 -0
- pcapkit/vendor/mh/dsmip6_tls_packet.py +87 -0
- pcapkit/vendor/mh/dsmipv6_home_address.py +87 -0
- pcapkit/vendor/mh/enumerating_algorithm.py +82 -0
- pcapkit/vendor/mh/fb_ack_status.py +87 -0
- pcapkit/vendor/mh/fb_action.py +88 -0
- pcapkit/vendor/mh/fb_indication_trigger.py +87 -0
- pcapkit/vendor/mh/fb_type.py +88 -0
- pcapkit/vendor/mh/flow_id_status.py +87 -0
- pcapkit/vendor/mh/flow_id_suboption.py +87 -0
- pcapkit/vendor/mh/handoff_type.py +87 -0
- pcapkit/vendor/mh/handover_ack_flag.py +143 -0
- pcapkit/vendor/mh/handover_ack_status.py +87 -0
- pcapkit/vendor/mh/handover_initiate_flag.py +143 -0
- pcapkit/vendor/mh/handover_initiate_status.py +87 -0
- pcapkit/vendor/mh/home_address_reply.py +87 -0
- pcapkit/vendor/mh/lla_code.py +97 -0
- pcapkit/vendor/mh/lma_mag_suboption.py +88 -0
- pcapkit/vendor/mh/mn_group_id.py +87 -0
- pcapkit/vendor/mh/mn_id_subtype.py +87 -0
- pcapkit/vendor/mh/operator_id.py +87 -0
- pcapkit/vendor/mh/option.py +83 -0
- pcapkit/vendor/mh/packet.py +82 -0
- pcapkit/vendor/mh/qos_attribute.py +87 -0
- pcapkit/vendor/mh/revocation_status_code.py +87 -0
- pcapkit/vendor/mh/revocation_trigger.py +87 -0
- pcapkit/vendor/mh/status_code.py +91 -0
- pcapkit/vendor/mh/traffic_selector.py +87 -0
- pcapkit/vendor/mh/upa_status.py +87 -0
- pcapkit/vendor/mh/upn_reason.py +87 -0
- pcapkit/vendor/ospf/__init__.py +27 -0
- pcapkit/vendor/ospf/authentication.py +29 -0
- pcapkit/vendor/ospf/packet.py +29 -0
- pcapkit/vendor/pcapng/__init__.py +51 -0
- pcapkit/vendor/pcapng/block_type.py +94 -0
- pcapkit/vendor/pcapng/filter_type.py +77 -0
- pcapkit/vendor/pcapng/hash_algorithm.py +82 -0
- pcapkit/vendor/pcapng/option_type.py +287 -0
- pcapkit/vendor/pcapng/record_type.py +81 -0
- pcapkit/vendor/pcapng/secrets_type.py +81 -0
- pcapkit/vendor/pcapng/verdict_type.py +79 -0
- pcapkit/vendor/reg/__init__.py +34 -0
- pcapkit/vendor/reg/apptype.py +338 -0
- pcapkit/vendor/reg/ethertype.py +121 -0
- pcapkit/vendor/reg/linktype.py +110 -0
- pcapkit/vendor/reg/transtype.py +111 -0
- pcapkit/vendor/tcp/__init__.py +35 -0
- pcapkit/vendor/tcp/checksum.py +80 -0
- pcapkit/vendor/tcp/flags.py +149 -0
- pcapkit/vendor/tcp/mp_tcp_option.py +90 -0
- pcapkit/vendor/tcp/option.py +103 -0
- pcapkit/vendor/vlan/__init__.py +23 -0
- pcapkit/vendor/vlan/priority_level.py +97 -0
- pypcapkit-1.3.5.post6.dist-info/LICENSE +29 -0
- pypcapkit-1.3.5.post6.dist-info/METADATA +238 -0
- pypcapkit-1.3.5.post6.dist-info/RECORD +466 -0
- pypcapkit-1.3.5.post6.dist-info/WHEEL +5 -0
- pypcapkit-1.3.5.post6.dist-info/entry_points.txt +3 -0
- pypcapkit-1.3.5.post6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,626 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Multi-Mapping Dictionary
|
3
|
+
==============================
|
4
|
+
|
5
|
+
.. module:: pcapkit.corekit.multidict
|
6
|
+
|
7
|
+
:mod:`pcapkit.corekit.multidict` contains multi-mapping dictionary classes,
|
8
|
+
which are used to store multiple mappings of the same key. The implementation
|
9
|
+
is inspired and based on the `Werkzeug`_ project.
|
10
|
+
|
11
|
+
.. _Werkzeug: https://werkzeug.palletsprojects.com/
|
12
|
+
|
13
|
+
"""
|
14
|
+
|
15
|
+
import copy
|
16
|
+
from typing import TYPE_CHECKING, Generic, TypeVar, cast, overload
|
17
|
+
|
18
|
+
from pcapkit.utilities.exceptions import MissingKeyError, UnsupportedCall
|
19
|
+
|
20
|
+
if TYPE_CHECKING:
|
21
|
+
from typing import Any, Iterable, Iterator, Mapping, NoReturn, Optional, SupportsIndex
|
22
|
+
|
23
|
+
from typing_extensions import Literal
|
24
|
+
|
25
|
+
__all__ = ['MultiDict', 'OrderedMultiDict']
|
26
|
+
|
27
|
+
###############################################################################
|
28
|
+
# Type variables
|
29
|
+
###############################################################################
|
30
|
+
|
31
|
+
_T = TypeVar('_T')
|
32
|
+
_KT = TypeVar('_KT')
|
33
|
+
_VT = TypeVar('_VT')
|
34
|
+
|
35
|
+
###############################################################################
|
36
|
+
# Internals
|
37
|
+
###############################################################################
|
38
|
+
|
39
|
+
|
40
|
+
class _omd_bucket(Generic[_KT, _VT]):
|
41
|
+
"""Wraps values in the :class:`OrderedMultiDict`.
|
42
|
+
|
43
|
+
This makes it possible to keep an order over multiple different keys. It
|
44
|
+
requires a lot of extra memory and slows down access a lit, but makes it
|
45
|
+
possible to access elements in ``O(1)`` and iterate in ``O(n)``
|
46
|
+
|
47
|
+
"""
|
48
|
+
prev: 'Optional[_omd_bucket]'
|
49
|
+
next: 'Optional[_omd_bucket]'
|
50
|
+
key: '_KT'
|
51
|
+
value: '_VT'
|
52
|
+
|
53
|
+
__slots__ = ('prev', 'key', 'value', 'next')
|
54
|
+
|
55
|
+
def __init__(self, omd: 'OrderedMultiDict', key: '_KT', value: '_VT') -> 'None':
|
56
|
+
self.prev = omd._last_bucket
|
57
|
+
self.key = key
|
58
|
+
self.value = value
|
59
|
+
self.next = None
|
60
|
+
|
61
|
+
if omd._first_bucket is None:
|
62
|
+
omd._first_bucket = self
|
63
|
+
if omd._last_bucket is not None:
|
64
|
+
omd._last_bucket.next = self
|
65
|
+
omd._last_bucket = self
|
66
|
+
|
67
|
+
def unlink(self, omd: 'OrderedMultiDict') -> 'None':
|
68
|
+
if self.prev:
|
69
|
+
self.prev.next = self.next
|
70
|
+
if self.next:
|
71
|
+
self.next.prev = self.prev
|
72
|
+
if omd._first_bucket is self: # pylint: disable=protected-access
|
73
|
+
omd._first_bucket = self.next # pylint: disable=protected-access
|
74
|
+
if omd._last_bucket is self: # pylint: disable=protected-access
|
75
|
+
omd._last_bucket = self.prev # pylint: disable=protected-access
|
76
|
+
|
77
|
+
|
78
|
+
class _Missing:
|
79
|
+
def __repr__(self) -> 'str':
|
80
|
+
return "no value"
|
81
|
+
|
82
|
+
def __reduce__(self) -> 'str':
|
83
|
+
return "_missing"
|
84
|
+
|
85
|
+
|
86
|
+
_missing = _Missing()
|
87
|
+
|
88
|
+
###############################################################################
|
89
|
+
# Helpers
|
90
|
+
###############################################################################
|
91
|
+
|
92
|
+
|
93
|
+
def iter_multi_items(mapping: 'Mapping[_KT, _VT | Iterable[_VT]] | Iterable[tuple[_KT, _VT]]') -> 'Iterator[tuple[_KT, _VT]]': # pylint: disable=line-too-long
|
94
|
+
"""Iterates over the items of a mapping yielding keys and values
|
95
|
+
without dropping any from more complex structures.
|
96
|
+
"""
|
97
|
+
if isinstance(mapping, MultiDict):
|
98
|
+
yield from mapping.items(multi=True)
|
99
|
+
elif isinstance(mapping, dict):
|
100
|
+
for key, value in mapping.items():
|
101
|
+
if isinstance(value, (tuple, list)):
|
102
|
+
for v in value:
|
103
|
+
yield key, v
|
104
|
+
else:
|
105
|
+
yield key, value
|
106
|
+
else:
|
107
|
+
yield from mapping # type: ignore[misc]
|
108
|
+
|
109
|
+
|
110
|
+
###############################################################################
|
111
|
+
# Data structures
|
112
|
+
###############################################################################
|
113
|
+
|
114
|
+
|
115
|
+
class MultiDict(dict, Generic[_KT, _VT]):
|
116
|
+
"""A :class:`MultiDict` is a dictionary subclass customized to deal with
|
117
|
+
multiple values for the same key.
|
118
|
+
|
119
|
+
:class:`MultiDict` implements all standard dictionary methods. Internally,
|
120
|
+
it saves all values for a key as a list, but the standard :obj:`dict`
|
121
|
+
access methods will only return the first value for a key. If you want to
|
122
|
+
gain access to the other values, too, you have to use the :meth:`getlist`
|
123
|
+
and similar methods.
|
124
|
+
|
125
|
+
Args:
|
126
|
+
mapping: The initial value for the :class:`MultiDict`. Either a
|
127
|
+
regular :obj:`dict`, an iterable of ``(key, value)`` tuples, or
|
128
|
+
:obj:`None`.
|
129
|
+
|
130
|
+
It behaves like a normal :obj:`dict` thus all :obj:`dict` functions will
|
131
|
+
only return the first value when multiple values for one key are found.
|
132
|
+
|
133
|
+
See Also:
|
134
|
+
The class is inspired from and based on the `Werkzeug`_ project (c.f.
|
135
|
+
``werkzeug.datastructures.MultiDict``).
|
136
|
+
|
137
|
+
"""
|
138
|
+
|
139
|
+
def __init__(self, mapping: 'Optional[dict[_KT, _VT] | Iterable[tuple[_KT, _VT]]]' = None) -> 'None': # pylint: disable=line-too-long
|
140
|
+
if isinstance(mapping, MultiDict):
|
141
|
+
dict.__init__(self, ((k, v[:]) for k, v in mapping.items()))
|
142
|
+
elif isinstance(mapping, dict):
|
143
|
+
tmp = {} # type: dict[_KT, list[_VT]]
|
144
|
+
for key, value in mapping.items():
|
145
|
+
if isinstance(value, (tuple, list)):
|
146
|
+
if len(value) == 0:
|
147
|
+
continue
|
148
|
+
value = list(value)
|
149
|
+
else:
|
150
|
+
value = [value]
|
151
|
+
tmp[key] = value
|
152
|
+
dict.__init__(self, tmp)
|
153
|
+
else:
|
154
|
+
tmp = {}
|
155
|
+
for key, value in mapping or ():
|
156
|
+
tmp.setdefault(key, []).append(value)
|
157
|
+
dict.__init__(self, tmp)
|
158
|
+
|
159
|
+
def __getstate__(self) -> 'dict[_KT, list[_VT]]':
|
160
|
+
return dict(self.lists())
|
161
|
+
|
162
|
+
def __setstate__(self, value: 'Iterable[tuple[_KT, list[_VT]]]') -> 'None':
|
163
|
+
dict.clear(self)
|
164
|
+
dict.update(self, value) # type: ignore[arg-type]
|
165
|
+
|
166
|
+
def __iter__(self) -> 'Iterator[_KT]':
|
167
|
+
return dict.__iter__(self)
|
168
|
+
|
169
|
+
def __getitem__(self, key: '_KT') -> '_VT':
|
170
|
+
"""Return the first data value for this key.
|
171
|
+
|
172
|
+
Args:
|
173
|
+
key: The key to be looked up.
|
174
|
+
|
175
|
+
Raises:
|
176
|
+
KeyError: if the key does not exist.
|
177
|
+
|
178
|
+
"""
|
179
|
+
if key in self:
|
180
|
+
lst = dict.__getitem__(self, key)
|
181
|
+
if len(lst) > 0:
|
182
|
+
return lst[0]
|
183
|
+
raise MissingKeyError(key, quiet=True)
|
184
|
+
|
185
|
+
def __setitem__(self, key: '_KT', value: '_VT') -> 'None':
|
186
|
+
"""Like :meth:`add` but removes an existing key first.
|
187
|
+
|
188
|
+
Args:
|
189
|
+
key: The key for the value.
|
190
|
+
value: The value to set.
|
191
|
+
|
192
|
+
"""
|
193
|
+
dict.__setitem__(self, key, [value])
|
194
|
+
|
195
|
+
def add(self, key: '_KT', value: '_VT') -> 'None':
|
196
|
+
"""Adds a new value for the key.
|
197
|
+
|
198
|
+
Args:
|
199
|
+
key: The key for the value.
|
200
|
+
value: The value to add.
|
201
|
+
|
202
|
+
"""
|
203
|
+
dict.setdefault(self, key, []).append(value) # type: ignore[arg-type,attr-defined]
|
204
|
+
|
205
|
+
@overload
|
206
|
+
def get(self, key: '_KT') -> '_VT | _T': ...
|
207
|
+
@overload
|
208
|
+
def get(self, key: '_KT', default: '_VT | _T' = ...) -> '_VT | _T': ...
|
209
|
+
|
210
|
+
def get(self, key: '_KT', default: '_VT | _T' = None) -> '_VT | _T': # type: ignore[assignment,misc]
|
211
|
+
try:
|
212
|
+
return self[key]
|
213
|
+
except MissingKeyError:
|
214
|
+
return default
|
215
|
+
|
216
|
+
def getlist(self, key: '_KT') -> 'list[_VT]':
|
217
|
+
"""Return the list of items for a given key.
|
218
|
+
|
219
|
+
If that key is not in the :class:`MultiDict`, the return value
|
220
|
+
will be an empty list.
|
221
|
+
|
222
|
+
Args:
|
223
|
+
key: The key to be looked up.
|
224
|
+
|
225
|
+
Returns:
|
226
|
+
A :obj:`list` of all the values for the key.
|
227
|
+
|
228
|
+
"""
|
229
|
+
try:
|
230
|
+
rv = dict.__getitem__(self, key) # type: list[_VT]
|
231
|
+
except KeyError:
|
232
|
+
return []
|
233
|
+
return list(rv)
|
234
|
+
|
235
|
+
def setlist(self, key: '_KT', new_list: 'Iterable[_VT]') -> 'None':
|
236
|
+
"""Remove the old values for a key and add new ones.
|
237
|
+
|
238
|
+
Notes:
|
239
|
+
The list you pass the values in will be shallow-copied before it is
|
240
|
+
inserted in the dictionary.
|
241
|
+
|
242
|
+
Args:
|
243
|
+
key: The key for which the values are set.
|
244
|
+
new_list: An iterable with the new values for the key. Old values
|
245
|
+
are removed first.
|
246
|
+
|
247
|
+
"""
|
248
|
+
dict.__setitem__(self, key, list(new_list))
|
249
|
+
|
250
|
+
def setdefault(self, key: '_KT', default: 'Optional[_VT]' = None) -> '_VT':
|
251
|
+
"""If key is in the dictionary, returns its value.
|
252
|
+
|
253
|
+
If not, set it to default and return default.
|
254
|
+
|
255
|
+
Args:
|
256
|
+
key: The key to be looked up.
|
257
|
+
default: The value to be set.
|
258
|
+
|
259
|
+
Returns:
|
260
|
+
The value of the key.
|
261
|
+
|
262
|
+
"""
|
263
|
+
if key not in self:
|
264
|
+
self[key] = cast('_VT', default)
|
265
|
+
else:
|
266
|
+
default = self[key]
|
267
|
+
return default # type: ignore[return-value]
|
268
|
+
|
269
|
+
def setlistdefault(self, key: '_KT', default_list: 'Optional[Iterable[_VT]]' = None) -> 'list[_VT]':
|
270
|
+
"""Like :meth:`setdefault` but sets multiple values.
|
271
|
+
|
272
|
+
The list returned is not a copy, but the list that is actually used
|
273
|
+
internally. This means that you can put new values into the
|
274
|
+
:class:`dict <MultiDict>` by appending items to the list.
|
275
|
+
|
276
|
+
Args:
|
277
|
+
key: The key to be looked up.
|
278
|
+
default_list: An iterable of default values. It is either copied
|
279
|
+
(in case it was a :obj:`list`) or converted into a :obj:`list`
|
280
|
+
before returned.
|
281
|
+
|
282
|
+
"""
|
283
|
+
if key not in self:
|
284
|
+
default_list = list(default_list or ())
|
285
|
+
dict.__setitem__(self, key, default_list)
|
286
|
+
else:
|
287
|
+
default_list = cast('list[_VT]', dict.__getitem__(self, key))
|
288
|
+
return default_list
|
289
|
+
|
290
|
+
def items(self, multi: 'bool' = False) -> 'Iterable[tuple[_KT, _VT]]': # type: ignore[override]
|
291
|
+
"""Return an interator of ``(key, value)`` paris.
|
292
|
+
|
293
|
+
Args:
|
294
|
+
multi: If set to :obj:`True` the iterator returned will have a pair
|
295
|
+
for each value of each key. Otherwise it will only contain
|
296
|
+
pairs for the first value of each key.
|
297
|
+
|
298
|
+
"""
|
299
|
+
for key, values in dict.items(self):
|
300
|
+
if multi:
|
301
|
+
for value in values:
|
302
|
+
yield key, value
|
303
|
+
else:
|
304
|
+
yield key, values[0]
|
305
|
+
|
306
|
+
def lists(self) -> 'Iterator[tuple[_KT, list[_VT]]]':
|
307
|
+
"""Return an iterator of ``(key, values)`` pairs, where ``values`` is
|
308
|
+
the :obj:`list` of all values associated with the key."""
|
309
|
+
for key, values in dict.items(self):
|
310
|
+
yield key, list(values)
|
311
|
+
|
312
|
+
def values(self) -> 'Iterator[_VT]': # type: ignore[override]
|
313
|
+
"""Returns an iterator of the first value on every key's value list."""
|
314
|
+
for values in dict.values(self):
|
315
|
+
yield values[0]
|
316
|
+
|
317
|
+
def listvalues(self) -> 'Iterator[list[_VT]]':
|
318
|
+
"""Return an iterator of all values associated with a key. Zipping
|
319
|
+
:meth:`keys` and this is the same as calling :meth:`lists`."""
|
320
|
+
return dict.values(self) # type: ignore[return-value]
|
321
|
+
|
322
|
+
def copy(self) -> 'MultiDict[_KT, _VT]':
|
323
|
+
"""Return a shallow copy of this object."""
|
324
|
+
return self.__class__(self)
|
325
|
+
|
326
|
+
def deepcopy(self, memo: 'Optional[dict]' = None) -> 'MultiDict[_KT, _VT]':
|
327
|
+
"""Return a deep copy of this object."""
|
328
|
+
return self.__class__(copy.deepcopy(self.to_dict(flat=False), memo=memo)) # type: ignore[arg-type]
|
329
|
+
|
330
|
+
@overload
|
331
|
+
def to_dict(self, flat: 'Literal[True]' = ...) -> 'dict[_KT, _VT]': ...
|
332
|
+
@overload
|
333
|
+
def to_dict(self, flat: 'Literal[False]') -> 'dict[_KT, list[_VT]]': ...
|
334
|
+
|
335
|
+
def to_dict(self, flat: 'bool' = True) -> 'dict[_KT, _VT] | dict[_KT, list[_VT]]':
|
336
|
+
"""Return the contents as regular :obj:`dict`.
|
337
|
+
|
338
|
+
If ``flat`` is :obj:`True` the returned :obj:`dict` will only have the
|
339
|
+
first item present, if ``flat`` is :obj:`False` all values will be
|
340
|
+
returned as lists.
|
341
|
+
|
342
|
+
Args:
|
343
|
+
flat: If set to :obj:`False` the :obj:`dict` returned will have
|
344
|
+
lists with all the values in it. Otherwise it will only contain
|
345
|
+
the first value for each key.
|
346
|
+
|
347
|
+
"""
|
348
|
+
if flat:
|
349
|
+
return dict(self.items())
|
350
|
+
return dict(self.lists())
|
351
|
+
|
352
|
+
def update(self, mapping: 'Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]]') -> 'None': # type: ignore[override]
|
353
|
+
""":meth:`update` extends rather than replaces existing key lists.
|
354
|
+
|
355
|
+
If the value :obj:`list` for a key in ``other_dict`` is empty, no new
|
356
|
+
values will be added to the :obj:`dict` and the key will not be
|
357
|
+
created.
|
358
|
+
|
359
|
+
Args:
|
360
|
+
mapping: The extending value for the :class:`MultiDict`. Either a
|
361
|
+
regular :obj:`dict`, an iterable of ``(key, value)`` tuples, or
|
362
|
+
:obj:`None`.
|
363
|
+
|
364
|
+
"""
|
365
|
+
for key, value in iter_multi_items(mapping):
|
366
|
+
MultiDict.add(self, key, value)
|
367
|
+
|
368
|
+
@overload
|
369
|
+
def pop(self, key: '_KT') -> '_VT': ...
|
370
|
+
@overload
|
371
|
+
def pop(self, key: '_KT', default: '_VT | _T' = ...) -> '_VT | _T': ...
|
372
|
+
|
373
|
+
def pop(self, key: '_KT', default: '_VT | _T' = _missing) -> '_VT | _T': # type: ignore[assignment,misc]
|
374
|
+
"""Pop the first item for a :obj:`list` on the :obj:`dict`.
|
375
|
+
|
376
|
+
Afterwards the ``key`` is removed from the :obj:`dict`, so additional
|
377
|
+
values are discarded.
|
378
|
+
|
379
|
+
Args:
|
380
|
+
key: The key to pop.
|
381
|
+
default: If provided the value to return if the key was not in the
|
382
|
+
dictionary.
|
383
|
+
|
384
|
+
"""
|
385
|
+
try:
|
386
|
+
lst = dict.pop(self, key)
|
387
|
+
|
388
|
+
if len(lst) == 0:
|
389
|
+
raise MissingKeyError(key)
|
390
|
+
|
391
|
+
return lst[0]
|
392
|
+
except KeyError:
|
393
|
+
if default is not _missing:
|
394
|
+
return default
|
395
|
+
|
396
|
+
raise MissingKeyError(key) from None
|
397
|
+
|
398
|
+
def popitem(self) -> 'tuple[_KT, _VT]':
|
399
|
+
"""Pop an item from the :obj:`dict`."""
|
400
|
+
try:
|
401
|
+
item = dict.popitem(self)
|
402
|
+
|
403
|
+
if len(item[1]) == 0: # type: ignore[arg-type]
|
404
|
+
raise MissingKeyError(item[0])
|
405
|
+
|
406
|
+
return (item[0], item[1][0]) # type: ignore[index,return-value]
|
407
|
+
except KeyError as e:
|
408
|
+
raise MissingKeyError(e.args[0]) from None
|
409
|
+
|
410
|
+
def poplist(self, key: '_KT') -> 'list[_VT]':
|
411
|
+
"""Pop the :obj:`list` for a key from the :obj:`dict`.
|
412
|
+
|
413
|
+
If the key is not in the :obj:`dict` an empty :obj:`list` is returned.
|
414
|
+
|
415
|
+
Notes:
|
416
|
+
If the key does no longer exist a :obj:`list` is returned instead
|
417
|
+
of raising an error.
|
418
|
+
|
419
|
+
Args:
|
420
|
+
key: The key to pop.
|
421
|
+
|
422
|
+
"""
|
423
|
+
return dict.pop(self, key, [])
|
424
|
+
|
425
|
+
def popitemlist(self) -> 'tuple[_KT, list[_VT]]':
|
426
|
+
"""Pop a ``(key, list)`` :obj:`tuple` from the :obj:`dict`."""
|
427
|
+
try:
|
428
|
+
return dict.popitem(self) # type: ignore[return-value]
|
429
|
+
except KeyError as e:
|
430
|
+
raise MissingKeyError(e.args[0]) from None
|
431
|
+
|
432
|
+
def __copy__(self) -> 'MultiDict[_KT, _VT]':
|
433
|
+
return self.copy()
|
434
|
+
|
435
|
+
def __deepcopy__(self, memo: 'Optional[dict]' = None) -> 'MultiDict[_KT, _VT]':
|
436
|
+
return self.deepcopy(memo=memo)
|
437
|
+
|
438
|
+
def __repr__(self) -> 'str':
|
439
|
+
return f'{type(self).__name__}({list(self.items(multi=True))!r})'
|
440
|
+
|
441
|
+
|
442
|
+
class OrderedMultiDict(MultiDict[_KT, _VT]):
|
443
|
+
"""Works like a regular :class:`MultiDict` but preserves the order of the
|
444
|
+
fields.
|
445
|
+
|
446
|
+
Args:
|
447
|
+
mapping: The initial value for the :class:`MultiDict`. Either a
|
448
|
+
regular :obj:`dict`, an iterable of ``(key, value)`` tuples, or
|
449
|
+
:obj:`None`.
|
450
|
+
|
451
|
+
To convert the ordered multi dict into a :obj:`list` you can us the
|
452
|
+
:meth:`items` method and pass it ``multi=True``.
|
453
|
+
|
454
|
+
In general an :class:`OrderedMultiDict` is an order of magnitude slower
|
455
|
+
than a :class:`MultiDict`.
|
456
|
+
|
457
|
+
Notes:
|
458
|
+
Due to a limitation in Python you cannot convert an ordered multi dict
|
459
|
+
into a regular :obj:`dict` by using ``dict(multidict)``. Instead you
|
460
|
+
have to use the :meth:`to_dict` method, otherwise the internal bucket
|
461
|
+
objects are exposed.
|
462
|
+
|
463
|
+
"""
|
464
|
+
_first_bucket: 'Optional[_omd_bucket[_KT, _VT]]'
|
465
|
+
_last_bucket: 'Optional[_omd_bucket[_KT, _VT]]'
|
466
|
+
|
467
|
+
def __init__(self, mapping: 'Optional[dict[_KT, _VT] | Iterable[tuple[_KT, _VT]]]' = None) -> 'None': # pylint: disable=line-too-long
|
468
|
+
dict.__init__(self) # pylint: disable=non-parent-init-called
|
469
|
+
self._first_bucket = self._last_bucket = None
|
470
|
+
if mapping is not None:
|
471
|
+
OrderedMultiDict.update(self, mapping)
|
472
|
+
|
473
|
+
def __eq__(self, other: 'Any') -> 'bool':
|
474
|
+
if not isinstance(other, MultiDict):
|
475
|
+
return NotImplemented
|
476
|
+
if isinstance(other, OrderedMultiDict):
|
477
|
+
iter1 = iter(self.items(multi=True))
|
478
|
+
iter2 = iter(other.items(multi=True))
|
479
|
+
try:
|
480
|
+
for k1, v1 in iter1:
|
481
|
+
k2, v2 = next(iter2)
|
482
|
+
if k1 != k2 or v1 != v2:
|
483
|
+
return False
|
484
|
+
except StopIteration:
|
485
|
+
return False
|
486
|
+
try:
|
487
|
+
next(iter2)
|
488
|
+
except StopIteration:
|
489
|
+
return True
|
490
|
+
return False
|
491
|
+
if len(self) != len(other):
|
492
|
+
return False
|
493
|
+
for key, values in self.lists():
|
494
|
+
if other.getlist(key) != values:
|
495
|
+
return False
|
496
|
+
return True
|
497
|
+
|
498
|
+
__hash__ = None # type: ignore[assignment]
|
499
|
+
|
500
|
+
def __reduce_ex__(self, protocol: 'SupportsIndex') -> 'tuple[type, tuple[list[tuple[_KT, _VT]]]]':
|
501
|
+
return type(self), (list(self.items(multi=True)),)
|
502
|
+
|
503
|
+
def __getstate__(self) -> 'list[tuple[_KT, _VT]]': # type: ignore[override]
|
504
|
+
return list(self.items(multi=True))
|
505
|
+
|
506
|
+
def __setstate__(self, values: 'Iterable[tuple[_KT, _VT]]') -> 'None': # type: ignore[override]
|
507
|
+
dict.clear(self)
|
508
|
+
for key, value in values:
|
509
|
+
self.add(key, value)
|
510
|
+
|
511
|
+
def __getitem__(self, key: '_KT') -> '_VT':
|
512
|
+
if key in self:
|
513
|
+
return dict.__getitem__(self, key)[0].value
|
514
|
+
raise MissingKeyError(key, quiet=True)
|
515
|
+
|
516
|
+
def __setitem__(self, key: '_KT', value: '_VT') -> 'None':
|
517
|
+
self.poplist(key)
|
518
|
+
self.add(key, value)
|
519
|
+
|
520
|
+
def __delitem__(self, key: '_KT') -> 'None':
|
521
|
+
self.pop(key)
|
522
|
+
|
523
|
+
def keys(self) -> 'Iterator[_KT]': # type: ignore[override]
|
524
|
+
return (key for key, _ in self.items())
|
525
|
+
|
526
|
+
def __iter__(self) -> 'Iterator[_KT]':
|
527
|
+
return iter(self.keys())
|
528
|
+
|
529
|
+
def values(self) -> 'Iterator[_VT]': # type: ignore[override]
|
530
|
+
return (value for _, value in self.items())
|
531
|
+
|
532
|
+
def items(self, multi: 'bool' = False) -> 'Iterator[tuple[_KT, _VT]]': # type: ignore[override]
|
533
|
+
ptr = self._first_bucket
|
534
|
+
if multi:
|
535
|
+
while ptr is not None:
|
536
|
+
yield ptr.key, ptr.value
|
537
|
+
ptr = ptr.next
|
538
|
+
else:
|
539
|
+
returned_keys = set() # type: 'set[_KT]'
|
540
|
+
while ptr is not None:
|
541
|
+
if ptr.key not in returned_keys:
|
542
|
+
returned_keys.add(ptr.key)
|
543
|
+
yield ptr.key, ptr.value
|
544
|
+
ptr = ptr.next
|
545
|
+
|
546
|
+
def lists(self) -> 'Iterator[tuple[_KT, list[_VT]]]':
|
547
|
+
returned_keys = set() # type: 'set[_KT]'
|
548
|
+
ptr = self._first_bucket
|
549
|
+
while ptr is not None:
|
550
|
+
if ptr.key not in returned_keys:
|
551
|
+
yield ptr.key, self.getlist(ptr.key)
|
552
|
+
returned_keys.add(ptr.key)
|
553
|
+
ptr = ptr.next
|
554
|
+
|
555
|
+
def listvalues(self) -> 'Iterator[list[_VT]]':
|
556
|
+
for _, values in self.lists():
|
557
|
+
yield values
|
558
|
+
|
559
|
+
def add(self, key: '_KT', value: '_VT') -> 'None':
|
560
|
+
dict.setdefault(self, key, []).append(_omd_bucket(self, key, value)) # type: ignore[arg-type,attr-defined]
|
561
|
+
|
562
|
+
def getlist(self, key: '_KT') -> 'list[_VT]':
|
563
|
+
try:
|
564
|
+
rv = dict.__getitem__(self, key)
|
565
|
+
except KeyError:
|
566
|
+
return []
|
567
|
+
return [x.value for x in rv]
|
568
|
+
|
569
|
+
def setlist(self, key: '_KT', new_list: 'Iterable[_VT]') -> 'None':
|
570
|
+
self.poplist(key)
|
571
|
+
for value in new_list:
|
572
|
+
self.add(key, value)
|
573
|
+
|
574
|
+
def setlistdefault(self, key: '_KT', default_list: 'Optional[Iterable[_VT]]' = None) -> 'NoReturn':
|
575
|
+
raise UnsupportedCall('setlistdefault is unsupported for ordered multi dicts')
|
576
|
+
|
577
|
+
def update(self, mapping: 'Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]]') -> 'None': # type: ignore[override]
|
578
|
+
for key, value in iter_multi_items(mapping):
|
579
|
+
OrderedMultiDict.add(self, key, value)
|
580
|
+
|
581
|
+
def poplist(self, key: '_KT') -> 'list[_VT]':
|
582
|
+
buckets = dict.pop(self, key, []) # type: list[_omd_bucket[_KT, _VT]]
|
583
|
+
for bucket in buckets:
|
584
|
+
bucket.unlink(self)
|
585
|
+
return [x.value for x in buckets]
|
586
|
+
|
587
|
+
@overload
|
588
|
+
def pop(self, key: '_KT') -> '_VT': ...
|
589
|
+
@overload
|
590
|
+
def pop(self, key: '_KT', default: '_VT | _T' = ...) -> '_VT | _T': ...
|
591
|
+
|
592
|
+
def pop(self, key: '_KT', default: '_VT | _T' = _missing) -> '_VT | _T': # type: ignore[assignment,misc]
|
593
|
+
try:
|
594
|
+
buckets = dict.pop(self, key) # type: list[_omd_bucket[_KT, _VT]]
|
595
|
+
except KeyError:
|
596
|
+
if default is not _missing:
|
597
|
+
return default
|
598
|
+
|
599
|
+
raise MissingKeyError(key) from None
|
600
|
+
|
601
|
+
for bucket in buckets:
|
602
|
+
bucket.unlink(self)
|
603
|
+
|
604
|
+
return buckets[0].value
|
605
|
+
|
606
|
+
def popitem(self) -> 'tuple[_KT, _VT]':
|
607
|
+
try:
|
608
|
+
key, buckets = cast('tuple[_KT, list[_omd_bucket[_KT, _VT]]]', dict.popitem(self))
|
609
|
+
except KeyError as e:
|
610
|
+
raise MissingKeyError(str(e)) from None
|
611
|
+
|
612
|
+
for bucket in buckets:
|
613
|
+
bucket.unlink(self)
|
614
|
+
|
615
|
+
return key, buckets[0].value
|
616
|
+
|
617
|
+
def popitemlist(self) -> 'tuple[_KT, list[_VT]]':
|
618
|
+
try:
|
619
|
+
key, buckets = cast('tuple[_KT, list[_omd_bucket[_KT, _VT]]]', dict.popitem(self))
|
620
|
+
except KeyError as e:
|
621
|
+
raise MissingKeyError(str(e)) from None
|
622
|
+
|
623
|
+
for bucket in buckets:
|
624
|
+
bucket.unlink(self)
|
625
|
+
|
626
|
+
return key, [x.value for x in buckets]
|