code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
_plen = self._read_binary(3)
_type = self._read_unpack(1)
_flag = self._read_binary(1)
_stid = self._read_binary(4) | def read_http(self, length) | Read Hypertext Transfer Protocol version 2.
Structure of HTTP/2 packet [RFC 7230]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) ... | 6.102954 | 6.492376 | 0.940019 |
seekset = file.tell()
if not _termination:
# FTP analysis
flag, ftp = _analyse_ftp(file, length, seekset=seekset)
if flag:
return ftp
# HTTP/1.* analysis
flag, http = _analyse_httpv1(file, length, seekset=seekset)
if flag:
return http... | def analyse(file, length=None, *, _termination=False) | Analyse application layer packets. | 6.005754 | 5.559219 | 1.080323 |
if isinstance(key, int):
return Routing(key)
if key not in Routing._member_map_:
extend_enum(Routing, key, default)
return Routing[key] | def get(key, default=-1) | Backport support for original codes. | 6.567573 | 5.704148 | 1.151368 |
_byte = self._read_unpack(size)
_prot = ETHERTYPE.get(_byte)
return _prot | def _read_protos(self, size) | Read next layer protocol type.
Positional arguments:
* size -- int, buffer size
Returns:
* str -- next layer's protocol name | 16.705141 | 16.197721 | 1.031327 |
if length == 0:
from pcapkit.protocols.null import NoPayload as Protocol
elif self._sigterm:
from pcapkit.protocols.raw import Raw as Protocol
elif proto == 0x0806:
from pcapkit.protocols.link.arp import ARP as Protocol
elif proto == 0x8035:
... | def _import_next_layer(self, proto, length) | Import next layer extractor.
Positional arguments:
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Returns:
* bool -- flag if extraction of next layer succeeded
* Info -- info of next layer
* ProtoChain --... | 2.6645 | 2.42579 | 1.098405 |
if isinstance(key, int):
return HIT_Suite(key)
if key not in HIT_Suite._member_map_:
extend_enum(HIT_Suite, key, default)
return HIT_Suite[key] | def get(key, default=-1) | Backport support for original codes. | 6.282995 | 5.787757 | 1.085567 |
if isinstance(key, int):
return Authentication(key)
if key not in Authentication._member_map_:
extend_enum(Authentication, key, default)
return Authentication[key] | def get(key, default=-1) | Backport support for original codes. | 6.637487 | 5.797378 | 1.144912 |
if fmt == 'pcap': # output PCAP file
from pcapkit.dumpkit import PCAP as output
elif fmt == 'plist': # output PLIST file
from dictdumper import PLIST as output
elif fmt == 'json': # output JSON file
from dictdumper import JSON as output
... | def make_fout(fout='./tmp', fmt='pcap') | Make root path for output.
Positional arguments:
* fout -- str, root path for output
* fmt -- str, output format
Returns:
* output -- dumper of specified format | 3.371609 | 3.45625 | 0.975511 |
# fetch flow label
output = self.trace(packet, _check=False, _output=True)
# dump files
output(packet['frame'], name=f"Frame {packet['index']}",
byteorder=self._endian, nanosecond=self._nnsecd) | def dump(self, packet) | Dump frame to output files.
Positional arguments:
* packet -- dict, a flow packet
|-- (str) protocol -- data link type from global header
|-- (int) index -- frame number
|-- (Info) frame -- extracted frame info
|-- (bool) syn -- TCP sy... | 22.671152 | 18.282583 | 1.240041 |
self._newflg = True
if _check:
pkt_check(packet)
info = Info(packet)
# Buffer Identifier
BUFID = tuple(sorted([str(info.src), str(info.srcport), # pylint: disable=E1101
str(info.dst), str(info.dstport)])) # pylint: disable=E... | def trace(self, packet, *, _check=True, _output=False) | Trace packets.
Positional arguments:
* packet -- dict, a flow packet
Keyword arguments:
* _check -- bool, flag if run validations
* _output -- bool, flag if has formatted dumper | 4.058087 | 4.023474 | 1.008603 |
self._newflg = False
ret = list()
for buf in self._buffer.values():
buf = copy.deepcopy(buf)
if self._fdpext:
buf['fpout'] = f"{self._fproot}/{buf['label']}.{self._fdpext}"
else:
del buf['fpout']
buf['index'... | def submit(self) | Submit traced TCP flows. | 8.362703 | 8.381309 | 0.99778 |
if length is None:
length = len(self)
_next = self._read_protos(1)
_plen = self._read_unpack(1)
_resv = self._read_fileng(2)
_scpi = self._read_unpack(4)
_dsnf = self._read_unpack(4)
# ICV length & value
_tlen = _plen * 4 - 2
... | def read_ah(self, length, version, extension) | Read Authentication Header.
Structure of AH header [RFC 4302]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next... | 5.513487 | 4.401154 | 1.252737 |
if length is None:
length = len(self)
_dstm = self._read_mac_addr()
_srcm = self._read_mac_addr()
_type = self._read_protos(2)
ethernet = dict(
dst=_dstm,
src=_srcm,
type=_type,
)
length -= 14
eth... | def read_ethernet(self, length) | Read Ethernet Protocol.
Structure of Ethernet Protocol header [RFC 7042]:
Octets Bits Name Description
0 0 eth.dst Destination MAC Address
1 8 eth.src Source MAC Address
... | 4.328092 | 4.402922 | 0.983004 |
_byte = self._read_fileng(6)
_addr = '-'.join(textwrap.wrap(_byte.hex(), 2))
return _addr | def _read_mac_addr(self) | Read MAC address. | 8.298658 | 7.75772 | 1.069729 |
if isinstance(key, int):
return Suite(key)
if key not in Suite._member_map_:
extend_enum(Suite, key, default)
return Suite[key] | def get(key, default=-1) | Backport support for original codes. | 7.438162 | 6.450607 | 1.153095 |
if isinstance(key, int):
return ECDSA_Curve(key)
if key not in ECDSA_Curve._member_map_:
extend_enum(ECDSA_Curve, key, default)
return ECDSA_Curve[key] | def get(key, default=-1) | Backport support for original codes. | 4.662845 | 4.305557 | 1.082983 |
dict_ = dict()
frame = packet.frame_info
for field in frame.field_names:
dict_[field] = getattr(frame, field)
tempdict = dict_
for layer in packet.layers:
tempdict[layer.layer_name.upper()] = dict()
tempdict = tempdict[layer.layer_name.upper()]
for field in laye... | def packet2dict(packet) | Convert PyShark packet into dict. | 2.868022 | 2.710774 | 1.058009 |
if 'TCP' in packet:
ip = packet.ip if 'IP' in packet else packet.ipv6
tcp = packet.tcp
data = dict(
protocol=LINKTYPE.get(packet.layers[0].layer_name.upper()), # data link type from global header
index=int(packet.number), ... | def tcp_traceflow(packet) | Trace packet flow for TCP. | 3.819216 | 3.838045 | 0.995094 |
BUFID = info.bufid # Buffer Identifier
DSN = info.dsn # Data Sequence Number
ACK = info.ack # Acknowledgement Number
FIN = info.fin # Finish Flag (Termination)
RST = info.rst # Reset Connection Flag (Termination)
SYN = info.syn # Synchro... | def reassembly(self, info) | Reassembly procedure.
Positional arguments:
* info -- Info, info dict of packets to be reassembled | 2.979674 | 3.008483 | 0.990424 |
datagram = [] # reassembled datagram
HDL = buf.pop('hdl') # hole descriptor list (remove from dict)
# check through every buffer with ACK
for (ack, buffer) in buf.items():
# if this buffer is not implemented
# go through every hole and extra... | def submit(self, buf, *, bufid) | Submit reassembled payload.
Positional arguments:
* buf -- dict, buffer dict of reassembled packets
Keyword arguments:
* bufid -- tuple, buffer identifier
Returns:
* list -- reassembled packets | 4.930519 | 4.705096 | 1.04791 |
if scapy_all is None:
raise ModuleNotFound("No module named 'scapy'", name='scapy')
chain = [packet.name]
payload = packet.payload
while not isinstance(payload, scapy_all.packet.NoPayload):
chain.append(payload.name)
payload = payload.payload
return ':'.join(chain) | def packet2chain(packet) | Fetch Scapy packet protocol chain. | 4.226532 | 3.793932 | 1.114024 |
if scapy_all is None:
raise ModuleNotFound("No module named 'scapy'", name='scapy')
def wrapper(packet):
dict_ = packet.fields
payload = packet.payload
if not isinstance(payload, scapy_all.packet.NoPayload):
dict_[payload.name] = wrapper(payload)
return ... | def packet2dict(packet, *, count=NotImplemented) | Convert Scapy packet into dict. | 5.599694 | 5.185444 | 1.079887 |
if 'IP' in packet:
ipv4 = packet['IP']
if ipv4.flags.DF: # dismiss not fragmented packet
return False, None
data = dict(
bufid=(
ipaddress.ip_address(ipv4.src), # source IP address
ipaddress.ip_address(ipv4.dst), ... | def ipv4_reassembly(packet, *, count=NotImplemented) | Make data for IPv4 reassembly. | 5.227325 | 5.021204 | 1.04105 |
if scapy_all is None:
raise ModuleNotFound("No module named 'scapy'", name='scapy')
if 'IPv6' in packet:
ipv6 = packet['IPv6']
if scapy_all.IPv6ExtHdrFragment not in ipv6: # pylint: disable=E1101
return False, None # dismiss not fragmented packet
... | def ipv6_reassembly(packet, *, count=NotImplemented) | Make data for IPv6 reassembly. | 4.958046 | 4.838366 | 1.024736 |
if 'TCP' in packet:
ip = packet['IP'] if 'IP' in packet else packet['IPv6']
tcp = packet['TCP']
data = dict(
bufid=(
ipaddress.ip_address(ip.src), # source IP address
ipaddress.ip_address(ip.dst), # destination IP address
... | def tcp_reassembly(packet, *, count=NotImplemented) | Store data for TCP reassembly. | 3.769803 | 3.658113 | 1.030532 |
if 'TCP' in packet:
ip = packet['IP'] if 'IP' in packet else packet['IPv6']
tcp = packet['TCP']
data = dict(
protocol=LINKTYPE.get(packet.name.upper()), # data link type from global header
index=count, # frame number
... | def tcp_traceflow(packet, *, count=NotImplemented) | Trace packet flow for TCP. | 3.758719 | 3.718952 | 1.010693 |
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
# _opts = self._read_fileng(_hlen*8+6)
hopopt = dict(
next=_next,
length=(_hlen + 1) * 8,
)
options = self._read_hopopt_... | def read_hopopt(self, length, extension) | Read IPv6 Hop-by-Hop Options.
Structure of HOPOPT header [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
... | 5.829741 | 5.080232 | 1.147534 |
counter = 0 # length of read options
optkind = list() # option type list
options = dict() # dict of option data
while counter < length:
# break when eol triggered
code = self._read_unpack(1)
if not code:
break
... | def _read_hopopt_options(self, length) | Read HOPOPT options.
Positional arguments:
* length -- int, length of options
Returns:
* dict -- extracted HOPOPT options | 6.344238 | 6.336813 | 1.001172 |
_type = self._read_opt_type(code)
if code == 0:
opt = dict(
desc=desc,
type=_type,
length=1,
)
elif code == 1:
_size = self._read_unpack(1)
_padn = self._read_fileng(_size)
opt ... | def _read_opt_pad(self, code, *, desc) | Read HOPOPT padding options.
Structure of HOPOPT padding options [RFC 8200]:
* Pad1 Option:
+-+-+-+-+-+-+-+-+
| 0 |
+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 ... | 4.120522 | 4.192349 | 0.982867 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 1:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_limt = self._read_unpack(1)
opt = dict(
desc=desc,
type=_type,
length=_size... | def _read_opt_tun(self, code, *, desc) | Read HOPOPT Tunnel Encapsulation Limit option.
Structure of HOPOPT Tunnel Encapsulation Limit option [RFC 2473]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header |Hdr Ext Len = 0| Opt Type = 4 |Opt Data Len=1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 5.304727 | 4.812078 | 1.102378 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 2:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_rval = self._read_unpack(2)
if 4 <= _rval <= 35:
_dscp = f'Aggregated Reservation Nesting Level {_r... | def _read_opt_ra(self, code, *, desc) | Read HOPOPT Router Alert option.
Structure of HOPOPT Router Alert option [RFC 2711]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0 0|0 0 1 0 1|0 0 0 0 0 0 1 0| Value (2 octets) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 5.216532 | 5.053229 | 1.032317 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size < 8 and _size % 8 != 0:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_cmpt = self._read_unpack(4)
_clen = self._read_unpack(1)
if _clen % 2 != 0:
... | def _read_opt_calipso(self, code, *, desc) | Read HOPOPT CALIPSO option.
Structure of HOPOPT CALIPSO option [RFC 5570]:
------------------------------------------------------------
| Next Header | Hdr Ext Len | Option Type | Option Length|
+-------------+---------------+-------------+--------------+
| ... | 3.819402 | 3.137656 | 1.217279 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 10:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_stlr = self._read_unpack(1)
_stls = self._read_unpack(1)
_psnt = self._read_unpack(2)
_psnl = s... | def _read_opt_pdm(self, code, *, desc) | Read HOPOPT PDM option.
Structure of HOPOPT PDM option [RFC 8250]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | 3.364111 | 2.413496 | 1.393875 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 6:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_fcrr = self._read_binary(1)
_func = int(_fcrr[:4], base=2)
_rate = int(_fcrr[4:], base=2)
_ttlv... | def _read_opt_qs(self, code, *, desc) | Read HOPOPT Quick Start option.
Structure of HOPOPT Quick-Start option [RFC 4782]:
* A Quick-Start Request.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+... | 4.750989 | 3.774642 | 1.25866 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size < 4:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_flag = self._read_binary(1)
_rpld = self._read_unpack(1)
_rank = self._read_unpack(2)
opt = dict... | def _read_opt_rpl(self, code, *, desc) | Read HOPOPT RPL option.
Structure of HOPOPT RPL option [RFC 6553]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 3.925911 | 2.985913 | 1.314811 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
_nval = self._read_fileng(_size)
opt = dict(
desc=desc,
type=_type,
length=_size + 2,
value=_nval,
)
return opt | def _read_opt_ilnp(self, code, *, desc) | Read HOPOPT ILNP Nonce option.
Structure of HOPOPT ILNP Nonce option [RFC 6744]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 4.927574 | 4.588296 | 1.073944 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
_llen = self._read_unpack(1)
_line = self._read_fileng(_llen)
opt = dict(
desc=desc,
type=_type,
length=_size + 2,
lid_len=_llen,
lid=_line,
... | def _read_opt_lio(self, code, *, desc) | Read HOPOPT Line-Identification option.
Structure of HOPOPT Line-Identification option [RFC 6788]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-... | 4.246282 | 3.595422 | 1.181025 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 4:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_jlen = self._read_unpack(4)
opt = dict(
desc=desc,
type=_type,
length=_size... | def _read_opt_jumbo(self, code, *, desc) | Read HOPOPT Jumbo Payload option.
Structure of HOPOPT Jumbo Payload option [RFC 2675]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Option Type | Opt Data Len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 5.57259 | 5.102577 | 1.092113 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 16:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_addr = self._read_fileng(16)
opt = dict(
desc=desc,
type=_type,
length=_si... | def _read_opt_home(self, code, *, desc) | Read HOPOPT Home Address option.
Structure of HOPOPT Home Address option [RFC 6275]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 5.594055 | 4.892287 | 1.143444 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size != 2:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_verf = self._read_binary(1)
_seqn = self._read_unpack(2)
opt = dict(
desc=desc,
... | def _read_opt_ip_dff(self, code, *, desc) | Read HOPOPT IP_DFF option.
Structure of HOPOPT IP_DFF option [RFC 6971]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 4.054116 | 3.514278 | 1.153613 |
if isinstance(key, int):
return Socket(key)
if key not in Socket._member_map_:
extend_enum(Socket, key, default)
return Socket[key] | def get(key, default=-1) | Backport support for original codes. | 7.23515 | 6.355645 | 1.138382 |
if not (isinstance(value, int) and 0x0000 <= value <= 0xFFFF):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0x0001 <= value <= 0x0BB8:
extend_enum(cls, 'Registered by Xerox [0x%s]' % hex(value)[2:].upper().zfill(4), value)
return cls(va... | def _missing_(cls, value) | Lookup function used when value is not found. | 2.101117 | 2.129403 | 0.986716 |
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
# _opts = self._read_fileng(_hlen*8+6)
ipv6_opts = dict(
next=_next,
length=(_hlen + 1) * 8,
)
options = self._read_ipv6... | def read_ipv6_opts(self, length, extension) | Read Destination Options for IPv6.
Structure of IPv6-Opts header [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
... | 4.874895 | 4.643316 | 1.049874 |
bin_ = bin(kind)[2:].zfill(8)
type_ = dict(
value=kind,
action=_IPv6_Opts_ACT.get(bin_[:2]),
change=True if int(bin_[2], base=2) else False,
)
return type_ | def _read_opt_type(self, kind) | Read option type field.
Positional arguments:
* kind -- int, option kind value
Returns:
* dict -- extracted IPv6_Opts option
Structure of option type field [RFC 791]:
Octets Bits Name Descriptions
0 ... | 9.013609 | 4.986885 | 1.807463 |
counter = 0 # length of read options
optkind = list() # option type list
options = dict() # dict of option data
while counter < length:
# break when eol triggered
code = self._read_unpack(1)
if not code:
break
... | def _read_ipv6_opts_options(self, length) | Read IPv6_Opts options.
Positional arguments:
* length -- int, length of options
Returns:
* dict -- extracted IPv6_Opts options | 6.335976 | 6.269453 | 1.010611 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
_data = self._read_fileng(_size)
opt = dict(
desc=_IPv6_Opts_NULL.get(code, desc),
type=_type,
length=_size + 2,
data=_data,
)
return opt | def _read_opt_none(self, code, *, desc) | Read IPv6_Opts unassigned options.
Structure of IPv6_Opts unassigned options [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
| Option Type | Opt Data Len | Option Data
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
Octets Bits ... | 6.104019 | 5.212582 | 1.171016 |
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
if _size < 2:
raise ProtocolError(f'{self.alias}: [Optno {code}] invalid format')
_type = self._read_opt_type(code)
_size = self._read_unpack(1)
_smvr = self._read_binary(1)
_seqn... | def _read_opt_mpl(self, code, *, desc) | Read IPv6_Opts MPL option.
Structure of IPv6_Opts MPL option [RFC 7731]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 2.694194 | 2.370979 | 1.136321 |
if isinstance(key, int):
return ReturnCode(key)
if key not in ReturnCode._member_map_:
extend_enum(ReturnCode, key, default)
return ReturnCode[key] | def get(key, default=-1) | Backport support for original codes. | 5.292536 | 4.058308 | 1.304124 |
if not (isinstance(value, int) and 100 <= value <= 659):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
code = str(value)
kind = KIND.get(code[0], 'Reserved')
info = INFO.get(code[1], 'Reserved')
extend_enum(cls, '%s - %s [%s]' % (kind, info... | def _missing_(cls, value) | Lookup function used when value is not found. | 4.663933 | 4.734315 | 0.985134 |
if isinstance(key, int):
return Cipher(key)
if key not in Cipher._member_map_:
extend_enum(Cipher, key, default)
return Cipher[key] | def get(key, default=-1) | Backport support for original codes. | 7.613652 | 6.666433 | 1.142088 |
if isinstance(key, int):
return Packet(key)
if key not in Packet._member_map_:
extend_enum(Packet, key, default)
return Packet[key] | def get(key, default=-1) | Backport support for original codes. | 6.580026 | 5.906434 | 1.114044 |
if isinstance(key, int):
return Option(key)
if key not in Option._member_map_:
extend_enum(Option, key, default)
return Option[key] | def get(key, default=-1) | Backport support for original codes. | 6.4982 | 5.738735 | 1.13234 |
if isinstance(key, int):
return ExtensionHeader(key)
if key not in ExtensionHeader._member_map_:
extend_enum(ExtensionHeader, key, default)
return ExtensionHeader[key] | def get(key, default=-1) | Backport support for original codes. | 6.73315 | 5.950639 | 1.1315 |
if isinstance(key, int):
return OptionClass(key)
if key not in OptionClass._member_map_:
extend_enum(OptionClass, key, default)
return OptionClass[key] | def get(key, default=-1) | Backport support for original codes. | 6.125593 | 5.209102 | 1.17594 |
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
_type = self._read_unpack(1)
_left = self._read_unpack(1)
ipv6_route = dict(
next=_next,
length=(_hlen + 1) * 8,
type... | def read_ipv6_route(self, length, extension) | Read Routing Header for IPv6.
Structure of IPv6-Route header [RFC 8200][RFC 5095]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | Routing Type | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 4.232745 | 3.734671 | 1.133365 |
_data = self._read_fileng(length)
data = dict(
data=_data,
)
return data | def _read_data_type_none(self, length) | Read IPv6-Route unknown type data.
Structure of IPv6-Route unknown type data [RFC 8200][RFC 5095]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | Routing Type | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 9.383138 | 11.107842 | 0.844731 |
_resv = self._read_fileng(4)
_addr = list()
for _ in range((length - 4) // 16):
_addr.append(ipaddress.ip_address(self._read_fileng(16)))
data = dict(
ip=tuple(_addr),
)
return data | def _read_data_type_src(self, length) | Read IPv6-Route Source Route data.
Structure of IPv6-Route Source Route data [RFC 5095]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | Routing Type=0| Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 6.214224 | 4.89537 | 1.269409 |
if length != 20:
raise ProtocolError(f'{self.alias}: [Typeno 2] invalid format')
_resv = self._read_fileng(4)
_home = self._read_fileng(16)
data = dict(
ip=ipaddress.ip_address(_home),
)
return data | def _read_data_type_2(self, length) | Read IPv6-Route Type 2 data.
Structure of IPv6-Route Type 2 data [RFC 6275]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len=2 | Routing Type=2|Segments Left=1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 9.579268 | 7.896957 | 1.213033 |
_cmpr = self._read_binary(1)
_padr = self._read_binary(1)
_resv = self._read_fileng(2)
_inti = int(_cmpr[:4], base=2)
_inte = int(_cmpr[4:], base=2)
_plen = int(_padr[:4], base=2)
_ilen = 16 - _inti
_elen = 16 - _inte
_addr = list()
... | def _read_data_type_rpl(self, length) | Read IPv6-Route RPL Source data.
Structure of IPv6-Route RPL Source data [RFC 6554]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | 3.998801 | 3.493134 | 1.144761 |
if length is None:
length = len(self)
packet = self._file.read(length)
try:
header, body = packet.split(b'\r\n\r\n', 1)
except ValueError:
raise ProtocolError('HTTP: invalid format', quiet=True)
header_unpacked, http_receipt = self._... | def read_http(self, length) | Read Hypertext Transfer Protocol (HTTP/1.*).
Structure of HTTP/1.* packet [RFC 7230]:
HTTP-message :==: start-line
*( header-field CRLF )
CRLF
[ message-body ] | 3.469598 | 3.608575 | 0.961487 |
try:
startline, headerfield = header.split(b'\r\n', 1)
para1, para2, para3 = re.split(rb'\s+', startline, 2)
fields = headerfield.split(b'\r\n')
lists = (re.split(rb'\s*:\s*', field, 1) for field in fields)
except ValueError:
raise Pro... | def _read_http_header(self, header) | Read HTTP/1.* header.
Structure of HTTP/1.* header [RFC 7230]:
start-line :==: request-line / status-line
request-line :==: method SP request-target SP HTTP-version CRLF
status-line :==: HTTP-version SP status-code SP reason-phrase CRLF
heade... | 2.534997 | 2.454443 | 1.032819 |
lat_centroid, lng_centroid, lat_offset, lng_offset = geohash.decode_exactly(geo)
corner_1 = (lat_centroid - lat_offset, lng_centroid - lng_offset)[::-1]
corner_2 = (lat_centroid - lat_offset, lng_centroid + lng_offset)[::-1]
corner_3 = (lat_centroid + lat_offset, lng_centroid + lng_offset)[::-1]
... | def geohash_to_polygon(geo) | :param geo: String that represents the geohash.
:return: Returns a Shapely's Polygon instance that represents the geohash. | 1.782357 | 1.845361 | 0.965858 |
inner_geohashes = set()
outer_geohashes = set()
envelope = polygon.envelope
centroid = polygon.centroid
testing_geohashes = queue.Queue()
testing_geohashes.put(geohash.encode(centroid.y, centroid.x, precision))
while not testing_geohashes.empty():
current_geohash = testing_ge... | def polygon_to_geohashes(polygon, precision, inner=True) | :param polygon: shapely polygon.
:param precision: int. Geohashes' precision that form resulting polygon.
:param inner: bool, default 'True'. If false, geohashes that are completely outside from the polygon are ignored.
:return: set. Set of geohashes that form the polygon. | 1.802727 | 1.804345 | 0.999104 |
#
# Ogg header
#
# check fields of Ogg page header
chunk = file.read(OGG_FIRST_PAGE_HEADER.size)
first_ogg_page = bytearray()
first_ogg_page.extend(chunk)
if len(chunk) < OGG_FIRST_PAGE_HEADER.size:
logger().error("Not enough bytes in Ogg page header: %u, expected at least %u" % (len(chunk),
... | def parse_oggopus_output_gain(file) | Parse an OggOpus file headers, read and return its output gain, and set file seek position to start of Opus header. | 2.218217 | 2.173548 | 1.020551 |
opus_header_pos = file.tell()
# write Opus header with new gain
file.seek(opus_header_pos + OGG_OPUS_ID_HEADER_GAIN_OFFSET)
file.write(OGG_OPUS_ID_HEADER_GAIN.pack(new_output_gain))
# compute page crc
file.seek(0)
page = file.read(opus_header_pos + OGG_OPUS_ID_HEADER.size)
computed_crc = _compute_o... | def write_oggopus_output_gain(file, new_output_gain) | Write output gain Opus header for a file.
file must be an object successfully used by parse_oggopus_output_gain. | 3.137673 | 3.009193 | 1.042696 |
page_zero_crc = page[:OGG_FIRST_PAGE_HEADER_CRC_OFFSET] + \
b"\00" * OGG_FIRST_PAGE_HEADER_CRC.size + \
page[OGG_FIRST_PAGE_HEADER_CRC_OFFSET + OGG_FIRST_PAGE_HEADER_CRC.size:]
return ogg_page_crc(page_zero_crc) | def _compute_ogg_page_crc(page) | Compute CRC of an Ogg page. | 3.721324 | 3.681761 | 1.010746 |
r = collections.OrderedDict()
cmd = (ffmpeg_path or "ffmpeg", "-version")
output = subprocess.run(cmd,
check=True,
stdout=subprocess.PIPE,
universal_newlines=True).stdout
output = output.splitlines()
lib_version_regex = re.compil... | def get_ffmpeg_lib_versions(ffmpeg_path=None) | Get FFmpeg library versions as 32 bit integers, with same format as sys.hexversion.
Example: 0x3040100 for FFmpeg 3.4.1 | 2.589715 | 2.545826 | 1.01724 |
return "%s=%s" % (name,
":".join("%s=%s" % (k, v) for k, v in params.items())) | def format_ffmpeg_filter(name, params) | Build a string to call a FFMpeg filter. | 3.776892 | 3.49734 | 1.079933 |
r128_data = {}
with contextlib.ExitStack() as cm:
if executor is None:
if thread_count is None:
try:
thread_count = len(os.sched_getaffinity(0))
except AttributeError:
thread_count = os.cpu_count()
enable_ffmpeg_threading = thread_count > (len(audio_filepaths)... | def scan(audio_filepaths, *, album_gain=False, skip_tagged=False, thread_count=None, ffmpeg_path=None, executor=None) | Analyze files, and return a dictionary of filepath to loudness metadata or filepath to future if executor is not None. | 2.526629 | 2.464951 | 1.025022 |
track, album = False, False
try:
mf = mutagen.File(filepath)
except mutagen.MutagenError as e:
logger().warning("File '%s' %s: %s" % (filepath,
e.__class__.__qualname__,
e))
return
if (isinstance(mf.tags, muta... | def has_loudness_tag(filepath) | Return a pair of booleans indicating if filepath has a RG or R128 track/album tag, or None if file is invalid. | 2.1884 | 2.065346 | 1.05958 |
# track loudness/peak
for audio_filepath in audio_filepaths:
try:
loudness, peak = r128_data[audio_filepath]
except KeyError:
loudness, peak = "SKIPPED", "SKIPPED"
else:
loudness = "%.1f LUFS" % (loudness)
if peak is None:
peak = "-"
else:
peak = "%.1f dB... | def show_scan_report(audio_filepaths, album_dir, r128_data) | Display loudness scan results. | 2.08046 | 2.065644 | 1.007173 |
install_reqs = parse_requirements(filename=source, session=PipSession())
return [str(ir.req) for ir in install_reqs] | def get_requirements(source) | Get the requirements from the given ``source``
Parameters
----------
source: str
The filename containing the requirements | 2.870065 | 5.430376 | 0.52852 |
return (
response.status == 503
and response.headers.get('Server', '').startswith(b'cloudflare')
and 'jschl_vc' in response.text
and 'jschl_answer' in response.text
) | def is_cloudflare_challenge(response) | Test if the given response contains the cloudflare's anti-bot protection | 4.167895 | 3.860279 | 1.079688 |
if not self.is_cloudflare_challenge(response):
return response
logger = logging.getLogger('cloudflaremiddleware')
logger.debug(
'Cloudflare protection detected on %s, trying to bypass...',
response.url
)
cloudflare_tokens, __ = get... | def process_response(self, request, response, spider) | Handle the a Scrapy response | 4.790618 | 4.866724 | 0.984362 |
raise VkCaptchaNeeded(url, sid) | async def enter_captcha(self, url: str, sid: str) -> str | Override this method for processing captcha.
:param url: link to captcha image
:param sid: captcha id. I do not know why pass here but may be useful
:return captcha value | 132.651047 | 49.374298 | 2.686642 |
html = await self._get_auth_page()
url = URL('/authorize?email')
for step in range(self.num_of_attempts):
if url.path == '/authorize' and 'email' in url.query:
# Invalid login or password and 'email' in q.query
url, html = await self._process... | async def authorize(self) -> None | Getting a new token from server | 5.038617 | 4.912114 | 1.025753 |
# Prepare request
params = {
'client_id': self.app_id,
'redirect_uri': 'https://oauth.vk.com/blank.html',
'display': 'mobile',
'response_type': 'token',
'v': self.API_VERSION
}
if self.scope:
params['scope']... | async def _get_auth_page(self) -> str | Get authorization mobile page without js
:return: html page | 2.617224 | 2.649374 | 0.987865 |
# Parse page
p = AuthPageParser()
p.feed(html)
p.close()
# Get data from hidden inputs
form_data = dict(p.inputs)
form_url = p.url
form_data['email'] = self.login
form_data['pass'] = self.password
if p.message:
# Show ... | async def _process_auth_form(self, html: str) -> (str, str) | Parsing data from authorization page and filling the form and submitting the form
:param html: html page
:return: url and html from redirected page | 3.594407 | 3.592304 | 1.000585 |
# Parse page
p = TwoFactorCodePageParser()
p.feed(html)
p.close()
# Prepare request data
form_url = p.url
form_data = dict(p.inputs)
form_data['remember'] = 0
if p.message:
raise VkAuthError('invalid_data', p.message, form_url... | async def _process_2auth_form(self, html: str) -> (str, str) | Parsing two-factor authorization page and filling the code
:param html: html page
:return: url and html from redirected page | 4.960008 | 4.620118 | 1.073567 |
# Parse page
p = AccessPageParser()
p.feed(html)
p.close()
form_url = p.url
form_data = dict(p.inputs)
# Send request
url, html = await self.driver.post_text(form_url, form_data)
return url, html | async def _process_access_form(self, html: str) -> (str, str) | Parsing page with access rights
:param html: html page
:return: url and html from redirected page | 4.772056 | 4.760264 | 1.002477 |
code = await self.get_code(code)
params = {
'client_id': self.app_id,
'client_secret': self.app_secret,
'redirect_uri': self.redirect_uri,
'code': code
}
response = await self.driver.json(self.CODE_URL, params, self.timeout)
... | async def authorize(self, code: str=None) -> None | Getting a new token from server | 2.740054 | 2.653972 | 1.032435 |
if not self.base_url:
await self._get_long_poll_server(need_pts)
params = {
'ts': self.ts,
'key': self.key,
}
params.update(self.base_params)
# invalid mimetype from server
code, response = await self.api._session.driver.get_t... | async def wait(self, need_pts=False) -> dict | Send long poll request
:param need_pts: need return the pts field | 4.270388 | 4.253515 | 1.003967 |
'''Returns a Dirichlet PDF function'''
alphap = alphas - 1
c = np.exp(gammaln(alphas.sum()) - gammaln(alphas).sum())
def dirichlet(xs):
'''N x K array'''
return c * (xs**alphap).prod(axis=1)
return dirichlet | def pdf(alphas) | Returns a Dirichlet PDF function | 5.020486 | 4.729168 | 1.0616 |
'''Mean and precision of Dirichlet distribution.
Parameters
----------
a : array
Parameters of Dirichlet distribution.
Returns
-------
mean : array
Numbers [0,1] of the means of the Dirichlet distribution.
precision : float
Precision or concentration parameter o... | def meanprecision(a) | Mean and precision of Dirichlet distribution.
Parameters
----------
a : array
Parameters of Dirichlet distribution.
Returns
-------
mean : array
Numbers [0,1] of the means of the Dirichlet distribution.
precision : float
Precision or concentration parameter of the D... | 4.502657 | 1.944182 | 2.315964 |
'''Compute log likelihood of Dirichlet distribution, i.e. log p(D|a).
Parameters
----------
D : 2D array
where ``N`` is the number of observations, ``K`` is the number of
parameters for the Dirichlet distribution.
a : array
Parameters for the Dirichlet distribution.
Ret... | def loglikelihood(D, a) | Compute log likelihood of Dirichlet distribution, i.e. log p(D|a).
Parameters
----------
D : 2D array
where ``N`` is the number of observations, ``K`` is the number of
parameters for the Dirichlet distribution.
a : array
Parameters for the Dirichlet distribution.
Returns
... | 3.496387 | 1.959348 | 1.784464 |
'''Iteratively computes maximum likelihood Dirichlet distribution
for an observed data set, i.e. a for which log p(D|a) is maximum.
Parameters
----------
D : 2D array
``N x K`` array of numbers from [0,1] where ``N`` is the number of
observations, ``K`` is the number of parameters f... | def mle(D, tol=1e-7, method='meanprecision', maxiter=None) | Iteratively computes maximum likelihood Dirichlet distribution
for an observed data set, i.e. a for which log p(D|a) is maximum.
Parameters
----------
D : 2D array
``N x K`` array of numbers from [0,1] where ``N`` is the number of
observations, ``K`` is the number of parameters for the ... | 4.382687 | 1.249536 | 3.507452 |
'''Simple fixed point iteration method for MLE of Dirichlet distribution'''
N, K = D.shape
logp = log(D).mean(axis=0)
a0 = _init_a(D)
# Start updating
if maxiter is None:
maxiter = MAXINT
for i in xrange(maxiter):
a1 = _ipsi(psi(a0.sum()) + logp)
# if norm(a1-a0) < t... | def _fixedpoint(D, tol=1e-7, maxiter=None) | Simple fixed point iteration method for MLE of Dirichlet distribution | 5.433703 | 4.670619 | 1.16338 |
'''Mean and precision alternating method for MLE of Dirichlet
distribution'''
N, K = D.shape
logp = log(D).mean(axis=0)
a0 = _init_a(D)
s0 = a0.sum()
if s0 < 0:
a0 = a0/s0
s0 = 1
elif s0 == 0:
a0 = ones(a.shape) / len(a)
s0 = 1
m0 = a0/s0
# Start ... | def _meanprecision(D, tol=1e-7, maxiter=None) | Mean and precision alternating method for MLE of Dirichlet
distribution | 3.864865 | 3.360663 | 1.150031 |
'''Assuming a fixed mean for Dirichlet distribution, maximize likelihood
for preicision a.k.a. s'''
N, K = D.shape
s1 = a0.sum()
m = a0 / s1
mlogp = (m*logp).sum()
for i in xrange(maxiter):
s0 = s1
g = psi(s1) - (m*psi(s1*m)).sum() + mlogp
h = _trigamma(s1) - ((m**2)*... | def _fit_s(D, a0, logp, tol=1e-7, maxiter=1000) | Assuming a fixed mean for Dirichlet distribution, maximize likelihood
for preicision a.k.a. s | 4.419541 | 3.54824 | 1.245559 |
'''With fixed precision s, maximize mean m'''
N,K = D.shape
s = a0.sum()
for i in xrange(maxiter):
m = a0 / s
a1 = _ipsi(logp + (m*(psi(a0) - logp)).sum())
a1 = a1/a1.sum() * s
if norm(a1 - a0) < tol:
return a1
a0 = a1
raise Exception('Failed to... | def _fit_m(D, a0, logp, tol=1e-7, maxiter=1000) | With fixed precision s, maximize mean m | 6.047511 | 4.645189 | 1.301887 |
'''Fixed version of numpy.piecewise for 0-d arrays'''
x = asanyarray(x)
n2 = len(funclist)
if isscalar(condlist) or \
(isinstance(condlist, np.ndarray) and condlist.ndim == 0) or \
(x.ndim > 0 and condlist[0].ndim == 0):
condlist = [condlist]
condlist = [asarray(c, dt... | def _piecewise(x, condlist, funclist, *args, **kw) | Fixed version of numpy.piecewise for 0-d arrays | 2.800144 | 2.688403 | 1.041564 |
'''Initial guess for Dirichlet alpha parameters given data D'''
E = D.mean(axis=0)
E2 = (D**2).mean(axis=0)
return ((E[0] - E2[0])/(E2[0]-E[0]**2)) * E | def _init_a(D) | Initial guess for Dirichlet alpha parameters given data D | 4.993094 | 3.58271 | 1.393664 |
'''Inverse of psi (digamma) using Newton's method. For the purposes
of Dirichlet MLE, since the parameters a[i] must always
satisfy a > 0, we define ipsi :: R -> (0,inf).'''
y = asanyarray(y, dtype='float')
x0 = _piecewise(y, [y >= -2.22, y < -2.22],
[(lambda x: exp(x) + 0.5), (lambda x:... | def _ipsi(y, tol=1.48e-9, maxiter=10) | Inverse of psi (digamma) using Newton's method. For the purposes
of Dirichlet MLE, since the parameters a[i] must always
satisfy a > 0, we define ipsi :: R -> (0,inf). | 6.657102 | 3.130122 | 2.126787 |
'''Converts array of barycentric coordinates on a 2-simplex to an array of
Cartesian coordinates on a 2D triangle in the first quadrant, i.e.::
>>> cartesian((1,0,0))
array([0, 0])
>>> cartesian((0,1,0))
array([0, 1])
>>> cartesian((0,0,1))
array([0.5, 0.86602540... | def cartesian(points) | Converts array of barycentric coordinates on a 2-simplex to an array of
Cartesian coordinates on a 2D triangle in the first quadrant, i.e.::
>>> cartesian((1,0,0))
array([0, 0])
>>> cartesian((0,1,0))
array([0, 1])
>>> cartesian((0,0,1))
array([0.5, 0.866025403784438... | 3.500184 | 1.997713 | 1.752095 |
'''Inverse of :func:`cartesian`.'''
points = np.asanyarray(points)
ndim = points.ndim
if ndim == 1:
points = points.reshape((1,points.size))
c = (2/np.sqrt(3.0))*points[:,1]
b = (2*points[:,0] - c)/2.0
a = 1.0 - c - b
out = np.vstack([a,b,c]).T
if ndim == 1:
return ou... | def barycentric(points) | Inverse of :func:`cartesian`. | 2.979038 | 2.833521 | 1.051356 |
'''Scatter plot of barycentric 2-simplex points on a 2D triangle.
:param points: Points on a 2-simplex.
:type points: N x 3 list or ndarray.
:param vertexlabels: Labels for corners of plot in the order
``(a, b, c)`` where ``a == (1,0,0)``, ``b == (0,1,0)``,
``c == (0,0,1)``.
:type v... | def scatter(points, vertexlabels=None, **kwargs) | Scatter plot of barycentric 2-simplex points on a 2D triangle.
:param points: Points on a 2-simplex.
:type points: N x 3 list or ndarray.
:param vertexlabels: Labels for corners of plot in the order
``(a, b, c)`` where ``a == (1,0,0)``, ``b == (0,1,0)``,
``c == (0,0,1)``.
:type vertexla... | 3.916975 | 1.739305 | 2.252035 |
'''Contour line plot on a 2D triangle of a function evaluated at
barycentric 2-simplex points.
:param f: Function to evaluate on N x 3 ndarray of coordinates
:type f: ``ufunc``
:param vertexlabels: Labels for corners of plot in the order
``(a, b, c)`` where ``a == (1,0,0)``, ``b == (0,1,0)`... | def contour(f, vertexlabels=None, **kwargs) | Contour line plot on a 2D triangle of a function evaluated at
barycentric 2-simplex points.
:param f: Function to evaluate on N x 3 ndarray of coordinates
:type f: ``ufunc``
:param vertexlabels: Labels for corners of plot in the order
``(a, b, c)`` where ``a == (1,0,0)``, ``b == (0,1,0)``,
... | 5.038706 | 1.460537 | 3.449901 |
'''Filled contour plot on a 2D triangle of a function evaluated at
barycentric 2-simplex points.
Function signature is identical to :func:`contour` with the caveat that
``**kwargs`` are passed on to :func:`plt.tricontourf`.'''
return _contour(f, vertexlabels, contourfunc=plt.tricontourf, **kwargs) | def contourf(f, vertexlabels=None, **kwargs) | Filled contour plot on a 2D triangle of a function evaluated at
barycentric 2-simplex points.
Function signature is identical to :func:`contour` with the caveat that
``**kwargs`` are passed on to :func:`plt.tricontourf`. | 6.584534 | 1.964676 | 3.351461 |
'''Workhorse function for the above, where ``contourfunc`` is the contour
plotting function to use for actual plotting.'''
if contourfunc is None:
contourfunc = plt.tricontour
if vertexlabels is None:
vertexlabels = ('1','2','3')
x = np.linspace(0, 1, 100)
y = np.linspace(0, np.... | def _contour(f, vertexlabels=None, contourfunc=None, **kwargs) | Workhorse function for the above, where ``contourfunc`` is the contour
plotting function to use for actual plotting. | 2.959052 | 2.42058 | 1.222456 |
@wraps(func)
def func_wrapper(*args, **kwargs):
# pylint: disable=C0111, C0103
function_name = func.__name__
VALIDATORS_DISABLED = os.getenv('VALIDATORS_DISABLED', '')
disabled_functions = [x.strip() for x in VALIDATORS_DISABLED.split(',')]
force_run = kwargs.get('f... | def disable_on_env(func) | Disable the ``func`` called if its name is present in ``VALIDATORS_DISABLED``.
:param func: The function/validator to be disabled.
:type func: callable
:returns: If disabled, the ``value`` (first positional argument) passed to
``func``. If enabled, the result of ``func``. | 3.13691 | 2.873688 | 1.091597 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.