Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ModuloPerformanceEventSequenceEncoderDecoder.__init__ | (self, num_velocity_bins=0,
max_shift_steps=performance_lib.DEFAULT_MAX_SHIFT_STEPS) | Initialize a ModuloPerformanceEventSequenceEncoderDecoder object.
Args:
num_velocity_bins: Number of velocity bins.
max_shift_steps: Maximum number of shift steps supported.
| Initialize a ModuloPerformanceEventSequenceEncoderDecoder object. | def __init__(self, num_velocity_bins=0,
max_shift_steps=performance_lib.DEFAULT_MAX_SHIFT_STEPS):
"""Initialize a ModuloPerformanceEventSequenceEncoderDecoder object.
Args:
num_velocity_bins: Number of velocity bins.
max_shift_steps: Maximum number of shift steps supported.
"""
... | [
"def",
"__init__",
"(",
"self",
",",
"num_velocity_bins",
"=",
"0",
",",
"max_shift_steps",
"=",
"performance_lib",
".",
"DEFAULT_MAX_SHIFT_STEPS",
")",
":",
"self",
".",
"_modulo_encoding",
"=",
"PerformanceModuloEncoding",
"(",
"num_velocity_bins",
"=",
"num_velocit... | [
147,
2
] | [
159,
77
] | python | en | ['en', 'en', 'it'] | True |
ModuloPerformanceEventSequenceEncoderDecoder.events_to_input | (self, events, position) | Returns the input vector for the given position in the event sequence.
Returns a modulo/circular encoding for the given position in the performance
event sequence.
Args:
events: A list-like sequence of events.
position: An integer event position in the event sequence.
Returns:
An ... | Returns the input vector for the given position in the event sequence. | def events_to_input(self, events, position):
"""Returns the input vector for the given position in the event sequence.
Returns a modulo/circular encoding for the given position in the performance
event sequence.
Args:
events: A list-like sequence of events.
position: An integer event pos... | [
"def",
"events_to_input",
"(",
"self",
",",
"events",
",",
"position",
")",
":",
"input_",
"=",
"[",
"0.0",
"]",
"*",
"self",
".",
"input_size",
"offset",
",",
"event_type",
",",
"value",
"=",
"(",
"self",
".",
"_modulo_encoding",
".",
"encode_modulo_event... | [
174,
2
] | [
215,
17
] | python | en | ['en', 'en', 'en'] | True |
ModuloPerformanceEventSequenceEncoderDecoder.events_to_label | (self, events, position) | Returns the label for the given position in the event sequence.
Returns the zero-based index value for the given position in the event
sequence, as determined by the one hot encoding.
Args:
events: A list-like sequence of events.
position: An integer event position in the event sequence.
... | Returns the label for the given position in the event sequence. | def events_to_label(self, events, position):
"""Returns the label for the given position in the event sequence.
Returns the zero-based index value for the given position in the event
sequence, as determined by the one hot encoding.
Args:
events: A list-like sequence of events.
position: An... | [
"def",
"events_to_label",
"(",
"self",
",",
"events",
",",
"position",
")",
":",
"return",
"self",
".",
"_one_hot_encoding",
".",
"encode_event",
"(",
"events",
"[",
"position",
"]",
")"
] | [
217,
2
] | [
230,
64
] | python | en | ['en', 'en', 'en'] | True |
ModuloPerformanceEventSequenceEncoderDecoder.class_index_to_event | (self, class_index, events) | Returns the event for the given class index.
This is the reverse process of the self.events_to_label method.
Args:
class_index: An integer in the range [0, self.num_classes).
events: A list-like sequence of events. This object is not used in this
implementation.
Returns:
An ev... | Returns the event for the given class index. | def class_index_to_event(self, class_index, events):
"""Returns the event for the given class index.
This is the reverse process of the self.events_to_label method.
Args:
class_index: An integer in the range [0, self.num_classes).
events: A list-like sequence of events. This object is not used... | [
"def",
"class_index_to_event",
"(",
"self",
",",
"class_index",
",",
"events",
")",
":",
"return",
"self",
".",
"_one_hot_encoding",
".",
"decode_event",
"(",
"class_index",
")"
] | [
232,
2
] | [
245,
59
] | python | en | ['en', 'en', 'en'] | True |
ModuloPerformanceEventSequenceEncoderDecoder.labels_to_num_steps | (self, labels) | Returns the total number of time steps for a sequence of class labels.
Args:
labels: A list-like sequence of integers in the range
[0, self.num_classes).
Returns:
The total number of time steps for the label sequence, as determined by
the one-hot encoding.
| Returns the total number of time steps for a sequence of class labels. | def labels_to_num_steps(self, labels):
"""Returns the total number of time steps for a sequence of class labels.
Args:
labels: A list-like sequence of integers in the range
[0, self.num_classes).
Returns:
The total number of time steps for the label sequence, as determined by
t... | [
"def",
"labels_to_num_steps",
"(",
"self",
",",
"labels",
")",
":",
"events",
"=",
"[",
"]",
"for",
"label",
"in",
"labels",
":",
"events",
".",
"append",
"(",
"self",
".",
"class_index_to_event",
"(",
"label",
",",
"events",
")",
")",
"return",
"sum",
... | [
247,
2
] | [
262,
35
] | python | en | ['en', 'en', 'en'] | True |
ip_address | (address) | Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Address or IPv6Address obje... | Take an IP string/int and return an object of the correct type. | def ip_address(address):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An... | [
"def",
"ip_address",
"(",
"address",
")",
":",
"try",
":",
"return",
"IPv4Address",
"(",
"address",
")",
"except",
"(",
"AddressValueError",
",",
"NetmaskValueError",
")",
":",
"pass",
"try",
":",
"return",
"IPv6Address",
"(",
"address",
")",
"except",
"(",
... | [
134,
0
] | [
167,
29
] | python | en | ['en', 'en', 'en'] | True |
ip_network | (address, strict=True) | Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP network. Either IPv4 or
IPv6 networks may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Network or IPv6Network objec... | Take an IP string/int and return an object of the correct type. | def ip_network(address, strict=True):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP network. Either IPv4 or
IPv6 networks may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns... | [
"def",
"ip_network",
"(",
"address",
",",
"strict",
"=",
"True",
")",
":",
"try",
":",
"return",
"IPv4Network",
"(",
"address",
",",
"strict",
")",
"except",
"(",
"AddressValueError",
",",
"NetmaskValueError",
")",
":",
"pass",
"try",
":",
"return",
"IPv6N... | [
170,
0
] | [
203,
29
] | python | en | ['en', 'en', 'en'] | True |
ip_interface | (address) | Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Interface or IPv6Interface ... | Take an IP string/int and return an object of the correct type. | def ip_interface(address):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
... | [
"def",
"ip_interface",
"(",
"address",
")",
":",
"try",
":",
"return",
"IPv4Interface",
"(",
"address",
")",
"except",
"(",
"AddressValueError",
",",
"NetmaskValueError",
")",
":",
"pass",
"try",
":",
"return",
"IPv6Interface",
"(",
"address",
")",
"except",
... | [
206,
0
] | [
238,
29
] | python | en | ['en', 'en', 'en'] | True |
v4_int_to_packed | (address) | Represent an address as 4 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv4 IP address.
Returns:
The integer address packed as 4 bytes in network (big-endian) order.
Raises:
ValueError: If the integer is negative or too large to be an
... | Represent an address as 4 packed bytes in network (big-endian) order. | def v4_int_to_packed(address):
"""Represent an address as 4 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv4 IP address.
Returns:
The integer address packed as 4 bytes in network (big-endian) order.
Raises:
ValueError: If the inte... | [
"def",
"v4_int_to_packed",
"(",
"address",
")",
":",
"try",
":",
"return",
"_compat_to_bytes",
"(",
"address",
",",
"4",
",",
"'big'",
")",
"except",
"(",
"struct",
".",
"error",
",",
"OverflowError",
")",
":",
"raise",
"ValueError",
"(",
"\"Address negative... | [
241,
0
] | [
258,
66
] | python | en | ['en', 'en', 'en'] | True |
v6_int_to_packed | (address) | Represent an address as 16 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv6 IP address.
Returns:
The integer address packed as 16 bytes in network (big-endian) order.
| Represent an address as 16 packed bytes in network (big-endian) order. | def v6_int_to_packed(address):
"""Represent an address as 16 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv6 IP address.
Returns:
The integer address packed as 16 bytes in network (big-endian) order.
"""
try:
return _compat_t... | [
"def",
"v6_int_to_packed",
"(",
"address",
")",
":",
"try",
":",
"return",
"_compat_to_bytes",
"(",
"address",
",",
"16",
",",
"'big'",
")",
"except",
"(",
"struct",
".",
"error",
",",
"OverflowError",
")",
":",
"raise",
"ValueError",
"(",
"\"Address negativ... | [
261,
0
] | [
274,
66
] | python | en | ['en', 'en', 'en'] | True |
_split_optional_netmask | (address) | Helper to split the netmask and raise AddressValueError if needed | Helper to split the netmask and raise AddressValueError if needed | def _split_optional_netmask(address):
"""Helper to split the netmask and raise AddressValueError if needed"""
addr = _compat_str(address).split('/')
if len(addr) > 2:
raise AddressValueError("Only one '/' permitted in %r" % address)
return addr | [
"def",
"_split_optional_netmask",
"(",
"address",
")",
":",
"addr",
"=",
"_compat_str",
"(",
"address",
")",
".",
"split",
"(",
"'/'",
")",
"if",
"len",
"(",
"addr",
")",
">",
"2",
":",
"raise",
"AddressValueError",
"(",
"\"Only one '/' permitted in %r\"",
"... | [
277,
0
] | [
282,
15
] | python | en | ['en', 'fi', 'en'] | True |
_find_address_range | (addresses) | Find a sequence of sorted deduplicated IPv#Address.
Args:
addresses: a list of IPv#Address objects.
Yields:
A tuple containing the first and last IP addresses in the sequence.
| Find a sequence of sorted deduplicated IPv#Address. | def _find_address_range(addresses):
"""Find a sequence of sorted deduplicated IPv#Address.
Args:
addresses: a list of IPv#Address objects.
Yields:
A tuple containing the first and last IP addresses in the sequence.
"""
it = iter(addresses)
first = last = next(it)
for ip in... | [
"def",
"_find_address_range",
"(",
"addresses",
")",
":",
"it",
"=",
"iter",
"(",
"addresses",
")",
"first",
"=",
"last",
"=",
"next",
"(",
"it",
")",
"for",
"ip",
"in",
"it",
":",
"if",
"ip",
".",
"_ip",
"!=",
"last",
".",
"_ip",
"+",
"1",
":",
... | [
285,
0
] | [
302,
21
] | python | en | ['en', 'en', 'en'] | True |
_count_righthand_zero_bits | (number, bits) | Count the number of zero bits on the right hand side.
Args:
number: an integer.
bits: maximum number of bits to count.
Returns:
The number of zero bits on the right hand side of the number.
| Count the number of zero bits on the right hand side. | def _count_righthand_zero_bits(number, bits):
"""Count the number of zero bits on the right hand side.
Args:
number: an integer.
bits: maximum number of bits to count.
Returns:
The number of zero bits on the right hand side of the number.
"""
if number == 0:
return... | [
"def",
"_count_righthand_zero_bits",
"(",
"number",
",",
"bits",
")",
":",
"if",
"number",
"==",
"0",
":",
"return",
"bits",
"return",
"min",
"(",
"bits",
",",
"_compat_bit_length",
"(",
"~",
"number",
"&",
"(",
"number",
"-",
"1",
")",
")",
")"
] | [
305,
0
] | [
318,
64
] | python | en | ['en', 'en', 'en'] | True |
summarize_address_range | (first, last) | Summarize a network range given the first and last IP addresses.
Example:
>>> list(summarize_address_range(IPv4Address('192.0.2.0'),
... IPv4Address('192.0.2.130')))
... #doctest: +NORMALIZE_WHITESPACE
[IPv4Network('192.0.2... | Summarize a network range given the first and last IP addresses. | def summarize_address_range(first, last):
"""Summarize a network range given the first and last IP addresses.
Example:
>>> list(summarize_address_range(IPv4Address('192.0.2.0'),
... IPv4Address('192.0.2.130')))
... #doctest: +N... | [
"def",
"summarize_address_range",
"(",
"first",
",",
"last",
")",
":",
"if",
"(",
"not",
"(",
"isinstance",
"(",
"first",
",",
"_BaseAddress",
")",
"and",
"isinstance",
"(",
"last",
",",
"_BaseAddress",
")",
")",
")",
":",
"raise",
"TypeError",
"(",
"'fi... | [
321,
0
] | [
373,
17
] | python | en | ['en', 'en', 'en'] | True |
_collapse_addresses_internal | (addresses) | Loops through the addresses, collapsing concurrent netblocks.
Example:
ip1 = IPv4Network('192.0.2.0/26')
ip2 = IPv4Network('192.0.2.64/26')
ip3 = IPv4Network('192.0.2.128/26')
ip4 = IPv4Network('192.0.2.192/26')
_collapse_addresses_internal([ip1, ip2, ip3, ip4]) ->
... | Loops through the addresses, collapsing concurrent netblocks. | def _collapse_addresses_internal(addresses):
"""Loops through the addresses, collapsing concurrent netblocks.
Example:
ip1 = IPv4Network('192.0.2.0/26')
ip2 = IPv4Network('192.0.2.64/26')
ip3 = IPv4Network('192.0.2.128/26')
ip4 = IPv4Network('192.0.2.192/26')
_collapse... | [
"def",
"_collapse_addresses_internal",
"(",
"addresses",
")",
":",
"# First merge",
"to_merge",
"=",
"list",
"(",
"addresses",
")",
"subnets",
"=",
"{",
"}",
"while",
"to_merge",
":",
"net",
"=",
"to_merge",
".",
"pop",
"(",
")",
"supernet",
"=",
"net",
".... | [
376,
0
] | [
422,
18
] | python | en | ['en', 'en', 'en'] | True |
collapse_addresses | (addresses) | Collapse a list of IP objects.
Example:
collapse_addresses([IPv4Network('192.0.2.0/25'),
IPv4Network('192.0.2.128/25')]) ->
[IPv4Network('192.0.2.0/24')]
Args:
addresses: An iterator of IPv4Network or IPv6Network objects.
Returns:
... | Collapse a list of IP objects. | def collapse_addresses(addresses):
"""Collapse a list of IP objects.
Example:
collapse_addresses([IPv4Network('192.0.2.0/25'),
IPv4Network('192.0.2.128/25')]) ->
[IPv4Network('192.0.2.0/24')]
Args:
addresses: An iterator of IPv4Network... | [
"def",
"collapse_addresses",
"(",
"addresses",
")",
":",
"addrs",
"=",
"[",
"]",
"ips",
"=",
"[",
"]",
"nets",
"=",
"[",
"]",
"# split IP addresses and networks",
"for",
"ip",
"in",
"addresses",
":",
"if",
"isinstance",
"(",
"ip",
",",
"_BaseAddress",
")",... | [
425,
0
] | [
476,
53
] | python | en | ['en', 'en', 'en'] | True |
get_mixed_type_key | (obj) | Return a key suitable for sorting between networks and addresses.
Address and Network objects are not sortable by default; they're
fundamentally different so the expression
IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24')
doesn't make any sense. There are some times however, where you may... | Return a key suitable for sorting between networks and addresses. | def get_mixed_type_key(obj):
"""Return a key suitable for sorting between networks and addresses.
Address and Network objects are not sortable by default; they're
fundamentally different so the expression
IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24')
doesn't make any sense. There a... | [
"def",
"get_mixed_type_key",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"_BaseNetwork",
")",
":",
"return",
"obj",
".",
"_get_networks_key",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"_BaseAddress",
")",
":",
"return",
"obj",
".",
... | [
479,
0
] | [
501,
25
] | python | en | ['en', 'en', 'en'] | True |
_IPAddressBase.exploded | (self) | Return the longhand version of the IP address as a string. | Return the longhand version of the IP address as a string. | def exploded(self):
"""Return the longhand version of the IP address as a string."""
return self._explode_shorthand_ip_string() | [
"def",
"exploded",
"(",
"self",
")",
":",
"return",
"self",
".",
"_explode_shorthand_ip_string",
"(",
")"
] | [
511,
4
] | [
513,
50
] | python | en | ['en', 'en', 'en'] | True |
_IPAddressBase.compressed | (self) | Return the shorthand version of the IP address as a string. | Return the shorthand version of the IP address as a string. | def compressed(self):
"""Return the shorthand version of the IP address as a string."""
return _compat_str(self) | [
"def",
"compressed",
"(",
"self",
")",
":",
"return",
"_compat_str",
"(",
"self",
")"
] | [
516,
4
] | [
518,
32
] | python | en | ['en', 'en', 'en'] | True |
_IPAddressBase.reverse_pointer | (self) | The name of the reverse DNS pointer for the IP address, e.g.:
>>> ipaddress.ip_address("127.0.0.1").reverse_pointer
'1.0.0.127.in-addr.arpa'
>>> ipaddress.ip_address("2001:db8::1").reverse_pointer
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
... | The name of the reverse DNS pointer for the IP address, e.g.:
>>> ipaddress.ip_address("127.0.0.1").reverse_pointer
'1.0.0.127.in-addr.arpa'
>>> ipaddress.ip_address("2001:db8::1").reverse_pointer
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa' | def reverse_pointer(self):
"""The name of the reverse DNS pointer for the IP address, e.g.:
>>> ipaddress.ip_address("127.0.0.1").reverse_pointer
'1.0.0.127.in-addr.arpa'
>>> ipaddress.ip_address("2001:db8::1").reverse_pointer
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.... | [
"def",
"reverse_pointer",
"(",
"self",
")",
":",
"return",
"self",
".",
"_reverse_pointer",
"(",
")"
] | [
521,
4
] | [
529,
38
] | python | en | ['en', 'en', 'en'] | True |
_IPAddressBase._ip_int_from_prefix | (cls, prefixlen) | Turn the prefix length into a bitwise netmask
Args:
prefixlen: An integer, the prefix length.
Returns:
An integer.
| Turn the prefix length into a bitwise netmask | def _ip_int_from_prefix(cls, prefixlen):
"""Turn the prefix length into a bitwise netmask
Args:
prefixlen: An integer, the prefix length.
Returns:
An integer.
"""
return cls._ALL_ONES ^ (cls._ALL_ONES >> prefixlen) | [
"def",
"_ip_int_from_prefix",
"(",
"cls",
",",
"prefixlen",
")",
":",
"return",
"cls",
".",
"_ALL_ONES",
"^",
"(",
"cls",
".",
"_ALL_ONES",
">>",
"prefixlen",
")"
] | [
556,
4
] | [
566,
59
] | python | en | ['en', 'haw', 'en'] | True |
_IPAddressBase._prefix_from_ip_int | (cls, ip_int) | Return prefix length from the bitwise netmask.
Args:
ip_int: An integer, the netmask in expanded bitwise format
Returns:
An integer, the prefix length.
Raises:
ValueError: If the input intermingles zeroes & ones
| Return prefix length from the bitwise netmask. | def _prefix_from_ip_int(cls, ip_int):
"""Return prefix length from the bitwise netmask.
Args:
ip_int: An integer, the netmask in expanded bitwise format
Returns:
An integer, the prefix length.
Raises:
ValueError: If the input intermingles zeroes & o... | [
"def",
"_prefix_from_ip_int",
"(",
"cls",
",",
"ip_int",
")",
":",
"trailing_zeroes",
"=",
"_count_righthand_zero_bits",
"(",
"ip_int",
",",
"cls",
".",
"_max_prefixlen",
")",
"prefixlen",
"=",
"cls",
".",
"_max_prefixlen",
"-",
"trailing_zeroes",
"leading_ones",
... | [
569,
4
] | [
591,
24
] | python | en | ['en', 'en', 'en'] | True |
_IPAddressBase._prefix_from_prefix_string | (cls, prefixlen_str) | Return prefix length from a numeric string
Args:
prefixlen_str: The string to be converted
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask
| Return prefix length from a numeric string | def _prefix_from_prefix_string(cls, prefixlen_str):
"""Return prefix length from a numeric string
Args:
prefixlen_str: The string to be converted
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask
... | [
"def",
"_prefix_from_prefix_string",
"(",
"cls",
",",
"prefixlen_str",
")",
":",
"# int allows a leading +/- as well as surrounding whitespace,",
"# so we ensure that isn't the case",
"if",
"not",
"_BaseV4",
".",
"_DECIMAL_DIGITS",
".",
"issuperset",
"(",
"prefixlen_str",
")",
... | [
599,
4
] | [
621,
24
] | python | en | ['en', 'en', 'en'] | True |
_IPAddressBase._prefix_from_ip_string | (cls, ip_str) | Turn a netmask/hostmask string into a prefix length
Args:
ip_str: The netmask/hostmask to be converted
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask/hostmask
| Turn a netmask/hostmask string into a prefix length | def _prefix_from_ip_string(cls, ip_str):
"""Turn a netmask/hostmask string into a prefix length
Args:
ip_str: The netmask/hostmask to be converted
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask... | [
"def",
"_prefix_from_ip_string",
"(",
"cls",
",",
"ip_str",
")",
":",
"# Parse the netmask/hostmask like an IP address.",
"try",
":",
"ip_int",
"=",
"cls",
".",
"_ip_int_from_string",
"(",
"ip_str",
")",
"except",
"AddressValueError",
":",
"cls",
".",
"_report_invalid... | [
624,
4
] | [
655,
47
] | python | en | ['en', 'haw', 'en'] | True |
_BaseNetwork.hosts | (self) | Generate Iterator over usable hosts in a network.
This is like __iter__ except it doesn't return the network
or broadcast addresses.
| Generate Iterator over usable hosts in a network. | def hosts(self):
"""Generate Iterator over usable hosts in a network.
This is like __iter__ except it doesn't return the network
or broadcast addresses.
"""
network = int(self.network_address)
broadcast = int(self.broadcast_address)
for x in _compat_range(networ... | [
"def",
"hosts",
"(",
"self",
")",
":",
"network",
"=",
"int",
"(",
"self",
".",
"network_address",
")",
"broadcast",
"=",
"int",
"(",
"self",
".",
"broadcast_address",
")",
"for",
"x",
"in",
"_compat_range",
"(",
"network",
"+",
"1",
",",
"broadcast",
... | [
739,
4
] | [
749,
40
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.overlaps | (self, other) | Tell if self is partly contained in other. | Tell if self is partly contained in other. | def overlaps(self, other):
"""Tell if self is partly contained in other."""
return self.network_address in other or (
self.broadcast_address in other or (
other.network_address in self or (
other.broadcast_address in self))) | [
"def",
"overlaps",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"network_address",
"in",
"other",
"or",
"(",
"self",
".",
"broadcast_address",
"in",
"other",
"or",
"(",
"other",
".",
"network_address",
"in",
"self",
"or",
"(",
"other",
"."... | [
809,
4
] | [
814,
54
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.num_addresses | (self) | Number of hosts in the current subnet. | Number of hosts in the current subnet. | def num_addresses(self):
"""Number of hosts in the current subnet."""
return int(self.broadcast_address) - int(self.network_address) + 1 | [
"def",
"num_addresses",
"(",
"self",
")",
":",
"return",
"int",
"(",
"self",
".",
"broadcast_address",
")",
"-",
"int",
"(",
"self",
".",
"network_address",
")",
"+",
"1"
] | [
846,
4
] | [
848,
74
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.address_exclude | (self, other) | Remove an address from a larger block.
For example:
addr1 = ip_network('192.0.2.0/28')
addr2 = ip_network('192.0.2.1/32')
list(addr1.address_exclude(addr2)) =
[IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.2/31'),
IPv4Network('192.0.2.4/... | Remove an address from a larger block. | def address_exclude(self, other):
"""Remove an address from a larger block.
For example:
addr1 = ip_network('192.0.2.0/28')
addr2 = ip_network('192.0.2.1/32')
list(addr1.address_exclude(addr2)) =
[IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.2/3... | [
"def",
"address_exclude",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"self",
".",
"_version",
"==",
"other",
".",
"_version",
":",
"raise",
"TypeError",
"(",
"\"%s and %s are not of the same version\"",
"%",
"(",
"self",
",",
"other",
")",
")",
"if",
... | [
862,
4
] | [
935,
49
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.compare_networks | (self, other) | Compare two IP objects.
This is only concerned about the comparison of the integer
representation of the network addresses. This means that the
host bits aren't considered at all in this method. If you want
to compare host bits, you can easily enough do a
'HostA._ip < HostB._i... | Compare two IP objects. | def compare_networks(self, other):
"""Compare two IP objects.
This is only concerned about the comparison of the integer
representation of the network addresses. This means that the
host bits aren't considered at all in this method. If you want
to compare host bits, you can ea... | [
"def",
"compare_networks",
"(",
"self",
",",
"other",
")",
":",
"# does this need to raise a ValueError?",
"if",
"self",
".",
"_version",
"!=",
"other",
".",
"_version",
":",
"raise",
"TypeError",
"(",
"'%s and %s are not of the same type'",
"%",
"(",
"self",
",",
... | [
937,
4
] | [
983,
16
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork._get_networks_key | (self) | Network-only key function.
Returns an object that identifies this address' network and
netmask. This function is a suitable "key" argument for sorted()
and list.sort().
| Network-only key function. | def _get_networks_key(self):
"""Network-only key function.
Returns an object that identifies this address' network and
netmask. This function is a suitable "key" argument for sorted()
and list.sort().
"""
return (self._version, self.network_address, self.netmask) | [
"def",
"_get_networks_key",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"_version",
",",
"self",
".",
"network_address",
",",
"self",
".",
"netmask",
")"
] | [
985,
4
] | [
993,
66
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.subnets | (self, prefixlen_diff=1, new_prefix=None) | The subnets which join to make the current subnet.
In the case that self contains only one IP
(self._prefixlen == 32 for IPv4 or self._prefixlen == 128
for IPv6), yield an iterator with just ourself.
Args:
prefixlen_diff: An integer, the amount the prefix length
... | The subnets which join to make the current subnet. | def subnets(self, prefixlen_diff=1, new_prefix=None):
"""The subnets which join to make the current subnet.
In the case that self contains only one IP
(self._prefixlen == 32 for IPv4 or self._prefixlen == 128
for IPv6), yield an iterator with just ourself.
Args:
pre... | [
"def",
"subnets",
"(",
"self",
",",
"prefixlen_diff",
"=",
"1",
",",
"new_prefix",
"=",
"None",
")",
":",
"if",
"self",
".",
"_prefixlen",
"==",
"self",
".",
"_max_prefixlen",
":",
"yield",
"self",
"return",
"if",
"new_prefix",
"is",
"not",
"None",
":",
... | [
995,
4
] | [
1046,
25
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.supernet | (self, prefixlen_diff=1, new_prefix=None) | The supernet containing the current network.
Args:
prefixlen_diff: An integer, the amount the prefix length of
the network should be decreased by. For example, given a
/24 network and a prefixlen_diff of 3, a supernet with a
/21 netmask is returned.
... | The supernet containing the current network. | def supernet(self, prefixlen_diff=1, new_prefix=None):
"""The supernet containing the current network.
Args:
prefixlen_diff: An integer, the amount the prefix length of
the network should be decreased by. For example, given a
/24 network and a prefixlen_diff of ... | [
"def",
"supernet",
"(",
"self",
",",
"prefixlen_diff",
"=",
"1",
",",
"new_prefix",
"=",
"None",
")",
":",
"if",
"self",
".",
"_prefixlen",
"==",
"0",
":",
"return",
"self",
"if",
"new_prefix",
"is",
"not",
"None",
":",
"if",
"new_prefix",
">",
"self",... | [
1048,
4
] | [
1086,
27
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_multicast | (self) | Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is a multicast address.
See RFC 2373 2.7 for details.
| Test if the address is reserved for multicast use. | def is_multicast(self):
"""Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is a multicast address.
See RFC 2373 2.7 for details.
"""
return (self.network_address.is_multicast and
self.broadcast_address.i... | [
"def",
"is_multicast",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_multicast",
"and",
"self",
".",
"broadcast_address",
".",
"is_multicast",
")"
] | [
1089,
4
] | [
1098,
52
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.subnet_of | (self, other) | Return True if this network is a subnet of other. | Return True if this network is a subnet of other. | def subnet_of(self, other):
"""Return True if this network is a subnet of other."""
return self._is_subnet_of(self, other) | [
"def",
"subnet_of",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"_is_subnet_of",
"(",
"self",
",",
"other",
")"
] | [
1113,
4
] | [
1115,
46
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.supernet_of | (self, other) | Return True if this network is a supernet of other. | Return True if this network is a supernet of other. | def supernet_of(self, other):
"""Return True if this network is a supernet of other."""
return self._is_subnet_of(other, self) | [
"def",
"supernet_of",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"_is_subnet_of",
"(",
"other",
",",
"self",
")"
] | [
1117,
4
] | [
1119,
46
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_reserved | (self) | Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
| Test if the address is otherwise IETF reserved. | def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
"""
return (self.network_address.is_reserved and
self.broadcast_address.is_reserv... | [
"def",
"is_reserved",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_reserved",
"and",
"self",
".",
"broadcast_address",
".",
"is_reserved",
")"
] | [
1122,
4
] | [
1131,
51
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_link_local | (self) | Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is reserved per RFC 4291.
| Test if the address is reserved for link-local. | def is_link_local(self):
"""Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is reserved per RFC 4291.
"""
return (self.network_address.is_link_local and
self.broadcast_address.is_link_local) | [
"def",
"is_link_local",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_link_local",
"and",
"self",
".",
"broadcast_address",
".",
"is_link_local",
")"
] | [
1134,
4
] | [
1142,
53
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_private | (self) | Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv4-special-registry or iana-ipv6-special-registry.
| Test if this address is allocated for private networks. | def is_private(self):
"""Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv4-special-registry or iana-ipv6-special-registry.
"""
return (self.network_address.is_private and
sel... | [
"def",
"is_private",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_private",
"and",
"self",
".",
"broadcast_address",
".",
"is_private",
")"
] | [
1145,
4
] | [
1154,
50
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_global | (self) | Test if this address is allocated for public networks.
Returns:
A boolean, True if the address is not reserved per
iana-ipv4-special-registry or iana-ipv6-special-registry.
| Test if this address is allocated for public networks. | def is_global(self):
"""Test if this address is allocated for public networks.
Returns:
A boolean, True if the address is not reserved per
iana-ipv4-special-registry or iana-ipv6-special-registry.
"""
return not self.is_private | [
"def",
"is_global",
"(",
"self",
")",
":",
"return",
"not",
"self",
".",
"is_private"
] | [
1157,
4
] | [
1165,
34
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_unspecified | (self) | Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 2373 2.5.2.
| Test if the address is unspecified. | def is_unspecified(self):
"""Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 2373 2.5.2.
"""
return (self.network_address.is_unspecified and
self.broadcast_address.is_unspecified) | [
"def",
"is_unspecified",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_unspecified",
"and",
"self",
".",
"broadcast_address",
".",
"is_unspecified",
")"
] | [
1168,
4
] | [
1177,
54
] | python | en | ['en', 'en', 'en'] | True |
_BaseNetwork.is_loopback | (self) | Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback address as defined in
RFC 2373 2.5.3.
| Test if the address is a loopback address. | def is_loopback(self):
"""Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback address as defined in
RFC 2373 2.5.3.
"""
return (self.network_address.is_loopback and
self.broadcast_address.is_loopback) | [
"def",
"is_loopback",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_loopback",
"and",
"self",
".",
"broadcast_address",
".",
"is_loopback",
")"
] | [
1180,
4
] | [
1189,
51
] | python | en | ['en', 'en', 'en'] | True |
_BaseV4._make_netmask | (cls, arg) | Make a (netmask, prefix_len) tuple from the given argument.
Argument can be:
- an integer (the prefix length)
- a string representing the prefix length (e.g. "24")
- a string representing the prefix netmask (e.g. "255.255.255.0")
| Make a (netmask, prefix_len) tuple from the given argument. | def _make_netmask(cls, arg):
"""Make a (netmask, prefix_len) tuple from the given argument.
Argument can be:
- an integer (the prefix length)
- a string representing the prefix length (e.g. "24")
- a string representing the prefix netmask (e.g. "255.255.255.0")
"""
... | [
"def",
"_make_netmask",
"(",
"cls",
",",
"arg",
")",
":",
"if",
"arg",
"not",
"in",
"cls",
".",
"_netmask_cache",
":",
"if",
"isinstance",
"(",
"arg",
",",
"_compat_int_types",
")",
":",
"prefixlen",
"=",
"arg",
"else",
":",
"try",
":",
"# Check for a ne... | [
1219,
4
] | [
1240,
38
] | python | en | ['en', 'en', 'en'] | True |
_BaseV4._ip_int_from_string | (cls, ip_str) | Turn the given IP string into an integer for comparison.
Args:
ip_str: A string, the IP ip_str.
Returns:
The IP ip_str as an integer.
Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address.
| Turn the given IP string into an integer for comparison. | def _ip_int_from_string(cls, ip_str):
"""Turn the given IP string into an integer for comparison.
Args:
ip_str: A string, the IP ip_str.
Returns:
The IP ip_str as an integer.
Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address.
... | [
"def",
"_ip_int_from_string",
"(",
"cls",
",",
"ip_str",
")",
":",
"if",
"not",
"ip_str",
":",
"raise",
"AddressValueError",
"(",
"'Address cannot be empty'",
")",
"octets",
"=",
"ip_str",
".",
"split",
"(",
"'.'",
")",
"if",
"len",
"(",
"octets",
")",
"!=... | [
1243,
4
] | [
1267,
63
] | python | en | ['en', 'en', 'en'] | True |
_BaseV4._parse_octet | (cls, octet_str) | Convert a decimal octet into an integer.
Args:
octet_str: A string, the number to parse.
Returns:
The octet as an integer.
Raises:
ValueError: if the octet isn't strictly a decimal from [0..255].
| Convert a decimal octet into an integer. | def _parse_octet(cls, octet_str):
"""Convert a decimal octet into an integer.
Args:
octet_str: A string, the number to parse.
Returns:
The octet as an integer.
Raises:
ValueError: if the octet isn't strictly a decimal from [0..255].
"""
... | [
"def",
"_parse_octet",
"(",
"cls",
",",
"octet_str",
")",
":",
"if",
"not",
"octet_str",
":",
"raise",
"ValueError",
"(",
"\"Empty octet not permitted\"",
")",
"# Whitelist the characters, since int() allows a lot of bizarre stuff.",
"if",
"not",
"cls",
".",
"_DECIMAL_DIG... | [
1270,
4
] | [
1304,
24
] | python | br | ['br', 'lb', 'it'] | False |
_BaseV4._string_from_ip_int | (cls, ip_int) | Turns a 32-bit integer into dotted decimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
The IP address as a string in dotted decimal notation.
| Turns a 32-bit integer into dotted decimal notation. | def _string_from_ip_int(cls, ip_int):
"""Turns a 32-bit integer into dotted decimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
The IP address as a string in dotted decimal notation.
"""
return '.'.join(_compat_str(struct.unpack(b'!B', ... | [
"def",
"_string_from_ip_int",
"(",
"cls",
",",
"ip_int",
")",
":",
"return",
"'.'",
".",
"join",
"(",
"_compat_str",
"(",
"struct",
".",
"unpack",
"(",
"b'!B'",
",",
"b",
")",
"[",
"0",
"]",
"if",
"isinstance",
"(",
"b",
",",
"bytes",
")",
"else",
... | [
1307,
4
] | [
1320,
68
] | python | en | ['pt', 'en', 'en'] | True |
_BaseV4._is_hostmask | (self, ip_str) | Test if the IP string is a hostmask (rather than a netmask).
Args:
ip_str: A string, the potential hostmask.
Returns:
A boolean, True if the IP string is a hostmask.
| Test if the IP string is a hostmask (rather than a netmask). | def _is_hostmask(self, ip_str):
"""Test if the IP string is a hostmask (rather than a netmask).
Args:
ip_str: A string, the potential hostmask.
Returns:
A boolean, True if the IP string is a hostmask.
"""
bits = ip_str.split('.')
try:
... | [
"def",
"_is_hostmask",
"(",
"self",
",",
"ip_str",
")",
":",
"bits",
"=",
"ip_str",
".",
"split",
"(",
"'.'",
")",
"try",
":",
"parts",
"=",
"[",
"x",
"for",
"x",
"in",
"map",
"(",
"int",
",",
"bits",
")",
"if",
"x",
"in",
"self",
".",
"_valid_... | [
1322,
4
] | [
1341,
20
] | python | en | ['en', 'en', 'en'] | True |
_BaseV4._reverse_pointer | (self) | Return the reverse DNS pointer name for the IPv4 address.
This implements the method described in RFC1035 3.5.
| Return the reverse DNS pointer name for the IPv4 address. | def _reverse_pointer(self):
"""Return the reverse DNS pointer name for the IPv4 address.
This implements the method described in RFC1035 3.5.
"""
reverse_octets = _compat_str(self).split('.')[::-1]
return '.'.join(reverse_octets) + '.in-addr.arpa' | [
"def",
"_reverse_pointer",
"(",
"self",
")",
":",
"reverse_octets",
"=",
"_compat_str",
"(",
"self",
")",
".",
"split",
"(",
"'.'",
")",
"[",
":",
":",
"-",
"1",
"]",
"return",
"'.'",
".",
"join",
"(",
"reverse_octets",
")",
"+",
"'.in-addr.arpa'"
] | [
1343,
4
] | [
1350,
57
] | python | en | ['en', 'no', 'en'] | True |
IPv4Address.__init__ | (self, address) |
Args:
address: A string or integer representing the IP
Additionally, an integer can be passed, so
IPv4Address('192.0.2.1') == IPv4Address(3221225985).
or, more generally
IPv4Address(int(IPv4Address('192.0.2.1'))) ==
IPv4Addres... |
Args:
address: A string or integer representing the IP | def __init__(self, address):
"""
Args:
address: A string or integer representing the IP
Additionally, an integer can be passed, so
IPv4Address('192.0.2.1') == IPv4Address(3221225985).
or, more generally
IPv4Address(int(IPv4Address('19... | [
"def",
"__init__",
"(",
"self",
",",
"address",
")",
":",
"# Efficient constructor from integer.",
"if",
"isinstance",
"(",
"address",
",",
"_compat_int_types",
")",
":",
"self",
".",
"_check_int_address",
"(",
"address",
")",
"self",
".",
"_ip",
"=",
"address",... | [
1367,
4
] | [
1401,
53
] | python | en | ['en', 'error', 'th'] | False |
IPv4Address.packed | (self) | The binary representation of this address. | The binary representation of this address. | def packed(self):
"""The binary representation of this address."""
return v4_int_to_packed(self._ip) | [
"def",
"packed",
"(",
"self",
")",
":",
"return",
"v4_int_to_packed",
"(",
"self",
".",
"_ip",
")"
] | [
1404,
4
] | [
1406,
41
] | python | en | ['en', 'en', 'en'] | True |
IPv4Address.is_reserved | (self) | Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within the
reserved IPv4 Network range.
| Test if the address is otherwise IETF reserved. | def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within the
reserved IPv4 Network range.
"""
return self in self._constants._reserved_network | [
"def",
"is_reserved",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_reserved_network"
] | [
1409,
4
] | [
1417,
56
] | python | en | ['en', 'en', 'en'] | True |
IPv4Address.is_private | (self) | Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv4-special-registry.
| Test if this address is allocated for private networks. | def is_private(self):
"""Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv4-special-registry.
"""
return any(self in net for net in self._constants._private_networks) | [
"def",
"is_private",
"(",
"self",
")",
":",
"return",
"any",
"(",
"self",
"in",
"net",
"for",
"net",
"in",
"self",
".",
"_constants",
".",
"_private_networks",
")"
] | [
1420,
4
] | [
1428,
76
] | python | en | ['en', 'en', 'en'] | True |
IPv4Address.is_multicast | (self) | Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is multicast.
See RFC 3171 for details.
| Test if the address is reserved for multicast use. | def is_multicast(self):
"""Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is multicast.
See RFC 3171 for details.
"""
return self in self._constants._multicast_network | [
"def",
"is_multicast",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_multicast_network"
] | [
1437,
4
] | [
1445,
57
] | python | en | ['en', 'en', 'en'] | True |
IPv4Address.is_unspecified | (self) | Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 5735 3.
| Test if the address is unspecified. | def is_unspecified(self):
"""Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 5735 3.
"""
return self == self._constants._unspecified_address | [
"def",
"is_unspecified",
"(",
"self",
")",
":",
"return",
"self",
"==",
"self",
".",
"_constants",
".",
"_unspecified_address"
] | [
1448,
4
] | [
1456,
59
] | python | en | ['en', 'en', 'en'] | True |
IPv4Address.is_loopback | (self) | Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback per RFC 3330.
| Test if the address is a loopback address. | def is_loopback(self):
"""Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback per RFC 3330.
"""
return self in self._constants._loopback_network | [
"def",
"is_loopback",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_loopback_network"
] | [
1459,
4
] | [
1466,
56
] | python | en | ['en', 'en', 'en'] | True |
IPv4Address.is_link_local | (self) | Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is link-local per RFC 3927.
| Test if the address is reserved for link-local. | def is_link_local(self):
"""Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is link-local per RFC 3927.
"""
return self in self._constants._linklocal_network | [
"def",
"is_link_local",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_linklocal_network"
] | [
1469,
4
] | [
1476,
57
] | python | en | ['en', 'en', 'en'] | True |
IPv4Network.__init__ | (self, address, strict=True) | Instantiate a new IPv4 network object.
Args:
address: A string or integer representing the IP [& network].
'192.0.2.0/24'
'192.0.2.0/255.255.255.0'
'192.0.0.2/0.0.0.255'
are all functionally the same in IPv4. Similarly,
'192.0.2.... | Instantiate a new IPv4 network object. | def __init__(self, address, strict=True):
"""Instantiate a new IPv4 network object.
Args:
address: A string or integer representing the IP [& network].
'192.0.2.0/24'
'192.0.2.0/255.255.255.0'
'192.0.0.2/0.0.0.255'
are all functionall... | [
"def",
"__init__",
"(",
"self",
",",
"address",
",",
"strict",
"=",
"True",
")",
":",
"_BaseNetwork",
".",
"__init__",
"(",
"self",
",",
"address",
")",
"# Constructing from a packed address or integer",
"if",
"isinstance",
"(",
"address",
",",
"(",
"_compat_int... | [
1577,
4
] | [
1660,
38
] | python | en | ['en', 'en', 'en'] | True |
IPv4Network.is_global | (self) | Test if this address is allocated for public networks.
Returns:
A boolean, True if the address is not reserved per
iana-ipv4-special-registry.
| Test if this address is allocated for public networks. | def is_global(self):
"""Test if this address is allocated for public networks.
Returns:
A boolean, True if the address is not reserved per
iana-ipv4-special-registry.
"""
return (not (self.network_address in IPv4Network('100.64.0.0/10') and
self.... | [
"def",
"is_global",
"(",
"self",
")",
":",
"return",
"(",
"not",
"(",
"self",
".",
"network_address",
"in",
"IPv4Network",
"(",
"'100.64.0.0/10'",
")",
"and",
"self",
".",
"broadcast_address",
"in",
"IPv4Network",
"(",
"'100.64.0.0/10'",
")",
")",
"and",
"no... | [
1663,
4
] | [
1673,
36
] | python | en | ['en', 'en', 'en'] | True |
_BaseV6._make_netmask | (cls, arg) | Make a (netmask, prefix_len) tuple from the given argument.
Argument can be:
- an integer (the prefix length)
- a string representing the prefix length (e.g. "24")
- a string representing the prefix netmask (e.g. "255.255.255.0")
| Make a (netmask, prefix_len) tuple from the given argument. | def _make_netmask(cls, arg):
"""Make a (netmask, prefix_len) tuple from the given argument.
Argument can be:
- an integer (the prefix length)
- a string representing the prefix length (e.g. "24")
- a string representing the prefix netmask (e.g. "255.255.255.0")
"""
... | [
"def",
"_make_netmask",
"(",
"cls",
",",
"arg",
")",
":",
"if",
"arg",
"not",
"in",
"cls",
".",
"_netmask_cache",
":",
"if",
"isinstance",
"(",
"arg",
",",
"_compat_int_types",
")",
":",
"prefixlen",
"=",
"arg",
"else",
":",
"prefixlen",
"=",
"cls",
".... | [
1732,
4
] | [
1747,
38
] | python | en | ['en', 'en', 'en'] | True |
_BaseV6._ip_int_from_string | (cls, ip_str) | Turn an IPv6 ip_str into an integer.
Args:
ip_str: A string, the IPv6 ip_str.
Returns:
An int, the IPv6 address
Raises:
AddressValueError: if ip_str isn't a valid IPv6 Address.
| Turn an IPv6 ip_str into an integer. | def _ip_int_from_string(cls, ip_str):
"""Turn an IPv6 ip_str into an integer.
Args:
ip_str: A string, the IPv6 ip_str.
Returns:
An int, the IPv6 address
Raises:
AddressValueError: if ip_str isn't a valid IPv6 Address.
"""
if not ip_... | [
"def",
"_ip_int_from_string",
"(",
"cls",
",",
"ip_str",
")",
":",
"if",
"not",
"ip_str",
":",
"raise",
"AddressValueError",
"(",
"'Address cannot be empty'",
")",
"parts",
"=",
"ip_str",
".",
"split",
"(",
"':'",
")",
"# An IPv6 address needs at least 2 colons (3 p... | [
1750,
4
] | [
1852,
63
] | python | en | ['en', 'lb', 'it'] | False |
_BaseV6._parse_hextet | (cls, hextet_str) | Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from
[0..FFFF].
| Convert an IPv6 hextet string into an integer. | def _parse_hextet(cls, hextet_str):
"""Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from
... | [
"def",
"_parse_hextet",
"(",
"cls",
",",
"hextet_str",
")",
":",
"# Whitelist the characters, since int() allows a lot of bizarre stuff.",
"if",
"not",
"cls",
".",
"_HEX_DIGITS",
".",
"issuperset",
"(",
"hextet_str",
")",
":",
"raise",
"ValueError",
"(",
"\"Only hex dig... | [
1855,
4
] | [
1878,
34
] | python | br | ['br', 'lb', 'en'] | False |
_BaseV6._compress_hextets | (cls, hextets) | Compresses a list of hextets.
Compresses a list of strings, replacing the longest continuous
sequence of "0" in the list with "" and adding empty strings at
the beginning or at the end of the string such that subsequently
calling ":".join(hextets) will produce the compressed version of
... | Compresses a list of hextets. | def _compress_hextets(cls, hextets):
"""Compresses a list of hextets.
Compresses a list of strings, replacing the longest continuous
sequence of "0" in the list with "" and adding empty strings at
the beginning or at the end of the string such that subsequently
calling ":".join(... | [
"def",
"_compress_hextets",
"(",
"cls",
",",
"hextets",
")",
":",
"best_doublecolon_start",
"=",
"-",
"1",
"best_doublecolon_len",
"=",
"0",
"doublecolon_start",
"=",
"-",
"1",
"doublecolon_len",
"=",
"0",
"for",
"index",
",",
"hextet",
"in",
"enumerate",
"(",... | [
1881,
4
] | [
1926,
22
] | python | en | ['en', 'ca', 'en'] | True |
_BaseV6._string_from_ip_int | (cls, ip_int=None) | Turns a 128-bit integer into hexadecimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
A string, the hexadecimal representation of the address.
Raises:
ValueError: The address is bigger than 128 bits of all ones.
| Turns a 128-bit integer into hexadecimal notation. | def _string_from_ip_int(cls, ip_int=None):
"""Turns a 128-bit integer into hexadecimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
A string, the hexadecimal representation of the address.
Raises:
ValueError: The address is bigger th... | [
"def",
"_string_from_ip_int",
"(",
"cls",
",",
"ip_int",
"=",
"None",
")",
":",
"if",
"ip_int",
"is",
"None",
":",
"ip_int",
"=",
"int",
"(",
"cls",
".",
"_ip",
")",
"if",
"ip_int",
">",
"cls",
".",
"_ALL_ONES",
":",
"raise",
"ValueError",
"(",
"'IPv... | [
1929,
4
] | [
1952,
32
] | python | en | ['en', 'lb', 'en'] | True |
_BaseV6._explode_shorthand_ip_string | (self) | Expand a shortened IPv6 address.
Args:
ip_str: A string, the IPv6 address.
Returns:
A string, the expanded IPv6 address.
| Expand a shortened IPv6 address. | def _explode_shorthand_ip_string(self):
"""Expand a shortened IPv6 address.
Args:
ip_str: A string, the IPv6 address.
Returns:
A string, the expanded IPv6 address.
"""
if isinstance(self, IPv6Network):
ip_str = _compat_str(self.network_addre... | [
"def",
"_explode_shorthand_ip_string",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
",",
"IPv6Network",
")",
":",
"ip_str",
"=",
"_compat_str",
"(",
"self",
".",
"network_address",
")",
"elif",
"isinstance",
"(",
"self",
",",
"IPv6Interface",
")",
... | [
1954,
4
] | [
1976,
30
] | python | en | ['en', 'ny', 'en'] | True |
_BaseV6._reverse_pointer | (self) | Return the reverse DNS pointer name for the IPv6 address.
This implements the method described in RFC3596 2.5.
| Return the reverse DNS pointer name for the IPv6 address. | def _reverse_pointer(self):
"""Return the reverse DNS pointer name for the IPv6 address.
This implements the method described in RFC3596 2.5.
"""
reverse_chars = self.exploded[::-1].replace(':', '')
return '.'.join(reverse_chars) + '.ip6.arpa' | [
"def",
"_reverse_pointer",
"(",
"self",
")",
":",
"reverse_chars",
"=",
"self",
".",
"exploded",
"[",
":",
":",
"-",
"1",
"]",
".",
"replace",
"(",
"':'",
",",
"''",
")",
"return",
"'.'",
".",
"join",
"(",
"reverse_chars",
")",
"+",
"'.ip6.arpa'"
] | [
1978,
4
] | [
1985,
52
] | python | en | ['en', 'no', 'en'] | True |
IPv6Address.__init__ | (self, address) | Instantiate a new IPv6 address object.
Args:
address: A string or integer representing the IP
Additionally, an integer can be passed, so
IPv6Address('2001:db8::') ==
IPv6Address(42540766411282592856903984951653826560)
or, more generally
... | Instantiate a new IPv6 address object. | def __init__(self, address):
"""Instantiate a new IPv6 address object.
Args:
address: A string or integer representing the IP
Additionally, an integer can be passed, so
IPv6Address('2001:db8::') ==
IPv6Address(425407664112825928569039849516538265... | [
"def",
"__init__",
"(",
"self",
",",
"address",
")",
":",
"# Efficient constructor from integer.",
"if",
"isinstance",
"(",
"address",
",",
"_compat_int_types",
")",
":",
"self",
".",
"_check_int_address",
"(",
"address",
")",
"self",
".",
"_ip",
"=",
"address",... | [
2002,
4
] | [
2037,
53
] | python | en | ['en', 'fy', 'en'] | True |
IPv6Address.packed | (self) | The binary representation of this address. | The binary representation of this address. | def packed(self):
"""The binary representation of this address."""
return v6_int_to_packed(self._ip) | [
"def",
"packed",
"(",
"self",
")",
":",
"return",
"v6_int_to_packed",
"(",
"self",
".",
"_ip",
")"
] | [
2040,
4
] | [
2042,
41
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_multicast | (self) | Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is a multicast address.
See RFC 2373 2.7 for details.
| Test if the address is reserved for multicast use. | def is_multicast(self):
"""Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is a multicast address.
See RFC 2373 2.7 for details.
"""
return self in self._constants._multicast_network | [
"def",
"is_multicast",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_multicast_network"
] | [
2045,
4
] | [
2053,
57
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_reserved | (self) | Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
| Test if the address is otherwise IETF reserved. | def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
"""
return any(self in x for x in self._constants._reserved_networks) | [
"def",
"is_reserved",
"(",
"self",
")",
":",
"return",
"any",
"(",
"self",
"in",
"x",
"for",
"x",
"in",
"self",
".",
"_constants",
".",
"_reserved_networks",
")"
] | [
2056,
4
] | [
2064,
73
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_link_local | (self) | Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is reserved per RFC 4291.
| Test if the address is reserved for link-local. | def is_link_local(self):
"""Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is reserved per RFC 4291.
"""
return self in self._constants._linklocal_network | [
"def",
"is_link_local",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_linklocal_network"
] | [
2067,
4
] | [
2074,
57
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_site_local | (self) | Test if the address is reserved for site-local.
Note that the site-local address space has been deprecated by RFC 3879.
Use is_private to test if this address is in the space of unique local
addresses as defined by RFC 4193.
Returns:
A boolean, True if the address is reserv... | Test if the address is reserved for site-local. | def is_site_local(self):
"""Test if the address is reserved for site-local.
Note that the site-local address space has been deprecated by RFC 3879.
Use is_private to test if this address is in the space of unique local
addresses as defined by RFC 4193.
Returns:
A bo... | [
"def",
"is_site_local",
"(",
"self",
")",
":",
"return",
"self",
"in",
"self",
".",
"_constants",
".",
"_sitelocal_network"
] | [
2077,
4
] | [
2088,
57
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_private | (self) | Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv6-special-registry.
| Test if this address is allocated for private networks. | def is_private(self):
"""Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv6-special-registry.
"""
return any(self in net for net in self._constants._private_networks) | [
"def",
"is_private",
"(",
"self",
")",
":",
"return",
"any",
"(",
"self",
"in",
"net",
"for",
"net",
"in",
"self",
".",
"_constants",
".",
"_private_networks",
")"
] | [
2091,
4
] | [
2099,
76
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_global | (self) | Test if this address is allocated for public networks.
Returns:
A boolean, true if the address is not reserved per
iana-ipv6-special-registry.
| Test if this address is allocated for public networks. | def is_global(self):
"""Test if this address is allocated for public networks.
Returns:
A boolean, true if the address is not reserved per
iana-ipv6-special-registry.
"""
return not self.is_private | [
"def",
"is_global",
"(",
"self",
")",
":",
"return",
"not",
"self",
".",
"is_private"
] | [
2102,
4
] | [
2110,
34
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_unspecified | (self) | Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 2373 2.5.2.
| Test if the address is unspecified. | def is_unspecified(self):
"""Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 2373 2.5.2.
"""
return self._ip == 0 | [
"def",
"is_unspecified",
"(",
"self",
")",
":",
"return",
"self",
".",
"_ip",
"==",
"0"
] | [
2113,
4
] | [
2121,
28
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.is_loopback | (self) | Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback address as defined in
RFC 2373 2.5.3.
| Test if the address is a loopback address. | def is_loopback(self):
"""Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback address as defined in
RFC 2373 2.5.3.
"""
return self._ip == 1 | [
"def",
"is_loopback",
"(",
"self",
")",
":",
"return",
"self",
".",
"_ip",
"==",
"1"
] | [
2124,
4
] | [
2132,
28
] | python | en | ['en', 'en', 'en'] | True |
IPv6Address.ipv4_mapped | (self) | Return the IPv4 mapped address.
Returns:
If the IPv6 address is a v4 mapped address, return the
IPv4 mapped address. Return None otherwise.
| Return the IPv4 mapped address. | def ipv4_mapped(self):
"""Return the IPv4 mapped address.
Returns:
If the IPv6 address is a v4 mapped address, return the
IPv4 mapped address. Return None otherwise.
"""
if (self._ip >> 32) != 0xFFFF:
return None
return IPv4Address(self._ip &... | [
"def",
"ipv4_mapped",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_ip",
">>",
"32",
")",
"!=",
"0xFFFF",
":",
"return",
"None",
"return",
"IPv4Address",
"(",
"self",
".",
"_ip",
"&",
"0xFFFFFFFF",
")"
] | [
2135,
4
] | [
2145,
49
] | python | en | ['en', 'no', 'en'] | True |
IPv6Address.teredo | (self) | Tuple of embedded teredo IPs.
Returns:
Tuple of the (server, client) IPs or None if the address
doesn't appear to be a teredo address (doesn't start with
2001::/32)
| Tuple of embedded teredo IPs. | def teredo(self):
"""Tuple of embedded teredo IPs.
Returns:
Tuple of the (server, client) IPs or None if the address
doesn't appear to be a teredo address (doesn't start with
2001::/32)
"""
if (self._ip >> 96) != 0x20010000:
return None
... | [
"def",
"teredo",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_ip",
">>",
"96",
")",
"!=",
"0x20010000",
":",
"return",
"None",
"return",
"(",
"IPv4Address",
"(",
"(",
"self",
".",
"_ip",
">>",
"64",
")",
"&",
"0xFFFFFFFF",
")",
",",
"IPv4Addres... | [
2148,
4
] | [
2160,
52
] | python | en | ['en', 'xh', 'en'] | True |
IPv6Address.sixtofour | (self) | Return the IPv4 6to4 embedded address.
Returns:
The IPv4 6to4-embedded address if present or None if the
address doesn't appear to contain a 6to4 embedded address.
| Return the IPv4 6to4 embedded address. | def sixtofour(self):
"""Return the IPv4 6to4 embedded address.
Returns:
The IPv4 6to4-embedded address if present or None if the
address doesn't appear to contain a 6to4 embedded address.
"""
if (self._ip >> 112) != 0x2002:
return None
return... | [
"def",
"sixtofour",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_ip",
">>",
"112",
")",
"!=",
"0x2002",
":",
"return",
"None",
"return",
"IPv4Address",
"(",
"(",
"self",
".",
"_ip",
">>",
"80",
")",
"&",
"0xFFFFFFFF",
")"
] | [
2163,
4
] | [
2173,
57
] | python | en | ['en', 'ru-Latn', 'en'] | True |
IPv6Network.__init__ | (self, address, strict=True) | Instantiate a new IPv6 Network object.
Args:
address: A string or integer representing the IPv6 network or the
IP and prefix/netmask.
'2001:db8::/128'
'2001:db8:0000:0000:0000:0000:0000:0000/128'
'2001:db8::'
are all functionally... | Instantiate a new IPv6 Network object. | def __init__(self, address, strict=True):
"""Instantiate a new IPv6 Network object.
Args:
address: A string or integer representing the IPv6 network or the
IP and prefix/netmask.
'2001:db8::/128'
'2001:db8:0000:0000:0000:0000:0000:0000/128'
... | [
"def",
"__init__",
"(",
"self",
",",
"address",
",",
"strict",
"=",
"True",
")",
":",
"_BaseNetwork",
".",
"__init__",
"(",
"self",
",",
"address",
")",
"# Efficient constructor from integer or packed address",
"if",
"isinstance",
"(",
"address",
",",
"(",
"byte... | [
2279,
4
] | [
2356,
38
] | python | en | ['en', 'en', 'en'] | True |
IPv6Network.hosts | (self) | Generate Iterator over usable hosts in a network.
This is like __iter__ except it doesn't return the
Subnet-Router anycast address.
| Generate Iterator over usable hosts in a network. | def hosts(self):
"""Generate Iterator over usable hosts in a network.
This is like __iter__ except it doesn't return the
Subnet-Router anycast address.
"""
network = int(self.network_address)
broadcast = int(self.broadcast_address)
for x in _compat_range(net... | [
"def",
"hosts",
"(",
"self",
")",
":",
"network",
"=",
"int",
"(",
"self",
".",
"network_address",
")",
"broadcast",
"=",
"int",
"(",
"self",
".",
"broadcast_address",
")",
"for",
"x",
"in",
"_compat_range",
"(",
"network",
"+",
"1",
",",
"broadcast",
... | [
2358,
4
] | [
2368,
40
] | python | en | ['en', 'en', 'en'] | True |
IPv6Network.is_site_local | (self) | Test if the address is reserved for site-local.
Note that the site-local address space has been deprecated by RFC 3879.
Use is_private to test if this address is in the space of unique local
addresses as defined by RFC 4193.
Returns:
A boolean, True if the address is reserv... | Test if the address is reserved for site-local. | def is_site_local(self):
"""Test if the address is reserved for site-local.
Note that the site-local address space has been deprecated by RFC 3879.
Use is_private to test if this address is in the space of unique local
addresses as defined by RFC 4193.
Returns:
A bo... | [
"def",
"is_site_local",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"network_address",
".",
"is_site_local",
"and",
"self",
".",
"broadcast_address",
".",
"is_site_local",
")"
] | [
2371,
4
] | [
2383,
53
] | python | en | ['en', 'en', 'en'] | True |
get_console | (request, console_type, instance) | Get a tuple of console url and console type. | Get a tuple of console url and console type. | def get_console(request, console_type, instance):
"""Get a tuple of console url and console type."""
if console_type == 'AUTO':
check_consoles = CONSOLES
else:
try:
check_consoles = {console_type: CONSOLES[console_type]}
except KeyError:
msg = _('Console type ... | [
"def",
"get_console",
"(",
"request",
",",
"console_type",
",",
"instance",
")",
":",
"if",
"console_type",
"==",
"'AUTO'",
":",
"check_consoles",
"=",
"CONSOLES",
"else",
":",
"try",
":",
"check_consoles",
"=",
"{",
"console_type",
":",
"CONSOLES",
"[",
"co... | [
33,
0
] | [
71,
67
] | python | en | ['en', 'en', 'en'] | True |
_suggest_semantic_version | (s) |
Try to suggest a semantic form for a version for which
_suggest_normalized_version couldn't come up with anything.
|
Try to suggest a semantic form for a version for which
_suggest_normalized_version couldn't come up with anything.
| def _suggest_semantic_version(s):
"""
Try to suggest a semantic form for a version for which
_suggest_normalized_version couldn't come up with anything.
"""
result = s.strip().lower()
for pat, repl in _REPLACEMENTS:
result = pat.sub(repl, result)
if not result:
result = '0.0.... | [
"def",
"_suggest_semantic_version",
"(",
"s",
")",
":",
"result",
"=",
"s",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"for",
"pat",
",",
"repl",
"in",
"_REPLACEMENTS",
":",
"result",
"=",
"pat",
".",
"sub",
"(",
"repl",
",",
"result",
")",
"i... | [
405,
0
] | [
448,
17
] | python | en | ['en', 'error', 'th'] | False |
_suggest_normalized_version | (s) | Suggest a normalized version close to the given version string.
If you have a version string that isn't rational (i.e. NormalizedVersion
doesn't like it) then you might be able to get an equivalent (or close)
rational version from this function.
This does a number of simple normalizations to the given... | Suggest a normalized version close to the given version string. | def _suggest_normalized_version(s):
"""Suggest a normalized version close to the given version string.
If you have a version string that isn't rational (i.e. NormalizedVersion
doesn't like it) then you might be able to get an equivalent (or close)
rational version from this function.
This does a n... | [
"def",
"_suggest_normalized_version",
"(",
"s",
")",
":",
"try",
":",
"_normalized_key",
"(",
"s",
")",
"return",
"s",
"# already rational",
"except",
"UnsupportedVersionError",
":",
"pass",
"rs",
"=",
"s",
".",
"lower",
"(",
")",
"# part of this could use maketra... | [
451,
0
] | [
559,
13
] | python | en | ['en', 'en', 'en'] | True |
Matcher.match | (self, version) |
Check if the provided version matches the constraints.
:param version: The version to match against this instance.
:type version: String or :class:`Version` instance.
|
Check if the provided version matches the constraints. | def match(self, version):
"""
Check if the provided version matches the constraints.
:param version: The version to match against this instance.
:type version: String or :class:`Version` instance.
"""
if isinstance(version, string_types):
version = self.versi... | [
"def",
"match",
"(",
"self",
",",
"version",
")",
":",
"if",
"isinstance",
"(",
"version",
",",
"string_types",
")",
":",
"version",
"=",
"self",
".",
"version_class",
"(",
"version",
")",
"for",
"operator",
",",
"constraint",
",",
"prefix",
"in",
"self"... | [
128,
4
] | [
147,
19
] | python | en | ['en', 'error', 'th'] | False |
VersionScheme.is_valid_constraint_list | (self, s) |
Used for processing some metadata fields
|
Used for processing some metadata fields
| def is_valid_constraint_list(self, s):
"""
Used for processing some metadata fields
"""
return self.is_valid_matcher('dummy_name (%s)' % s) | [
"def",
"is_valid_constraint_list",
"(",
"self",
",",
"s",
")",
":",
"return",
"self",
".",
"is_valid_matcher",
"(",
"'dummy_name (%s)'",
"%",
"s",
")"
] | [
708,
4
] | [
712,
59
] | python | en | ['en', 'error', 'th'] | False |
NoneMetadataError.__init__ | (self, dist, metadata_name) |
:param dist: A Distribution object.
:param metadata_name: The name of the metadata being accessed
(can be "METADATA" or "PKG-INFO").
|
:param dist: A Distribution object.
:param metadata_name: The name of the metadata being accessed
(can be "METADATA" or "PKG-INFO").
| def __init__(self, dist, metadata_name):
# type: (Distribution, str) -> None
"""
:param dist: A Distribution object.
:param metadata_name: The name of the metadata being accessed
(can be "METADATA" or "PKG-INFO").
"""
self.dist = dist
self.metadata_nam... | [
"def",
"__init__",
"(",
"self",
",",
"dist",
",",
"metadata_name",
")",
":",
"# type: (Distribution, str) -> None",
"self",
".",
"dist",
"=",
"dist",
"self",
".",
"metadata_name",
"=",
"metadata_name"
] | [
51,
4
] | [
59,
42
] | python | en | ['en', 'error', 'th'] | False |
NetworkConnectionError.__init__ | (self, error_msg, response=None, request=None) |
Initialize NetworkConnectionError with `request` and `response`
objects.
|
Initialize NetworkConnectionError with `request` and `response`
objects.
| def __init__(self, error_msg, response=None, request=None):
# type: (Text, Response, Request) -> None
"""
Initialize NetworkConnectionError with `request` and `response`
objects.
"""
self.response = response
self.request = request
self.error_msg = error_m... | [
"def",
"__init__",
"(",
"self",
",",
"error_msg",
",",
"response",
"=",
"None",
",",
"request",
"=",
"None",
")",
":",
"# type: (Text, Response, Request) -> None",
"self",
".",
"response",
"=",
"response",
"self",
".",
"request",
"=",
"request",
"self",
".",
... | [
105,
4
] | [
118,
41
] | python | en | ['en', 'error', 'th'] | False |
HashError.body | (self) | Return a summary of me for display under the heading.
This default implementation simply prints a description of the
triggering requirement.
:param req: The InstallRequirement that provoked this error, with
its link already populated by the resolver's _populate_link().
| Return a summary of me for display under the heading. | def body(self):
# type: () -> str
"""Return a summary of me for display under the heading.
This default implementation simply prints a description of the
triggering requirement.
:param req: The InstallRequirement that provoked this error, with
its link already popul... | [
"def",
"body",
"(",
"self",
")",
":",
"# type: () -> str",
"return",
"' {}'",
".",
"format",
"(",
"self",
".",
"_requirement_name",
"(",
")",
")"
] | [
204,
4
] | [
215,
56
] | python | en | ['en', 'en', 'en'] | True |
HashError._requirement_name | (self) | Return a description of the requirement that triggered me.
This default implementation returns long description of the req, with
line numbers
| Return a description of the requirement that triggered me. | def _requirement_name(self):
# type: () -> str
"""Return a description of the requirement that triggered me.
This default implementation returns long description of the req, with
line numbers
"""
return str(self.req) if self.req else 'unknown package' | [
"def",
"_requirement_name",
"(",
"self",
")",
":",
"# type: () -> str",
"return",
"str",
"(",
"self",
".",
"req",
")",
"if",
"self",
".",
"req",
"else",
"'unknown package'"
] | [
221,
4
] | [
229,
63
] | python | en | ['en', 'en', 'en'] | True |
HashMissing.__init__ | (self, gotten_hash) |
:param gotten_hash: The hash of the (possibly malicious) archive we
just downloaded
|
:param gotten_hash: The hash of the (possibly malicious) archive we
just downloaded
| def __init__(self, gotten_hash):
# type: (str) -> None
"""
:param gotten_hash: The hash of the (possibly malicious) archive we
just downloaded
"""
self.gotten_hash = gotten_hash | [
"def",
"__init__",
"(",
"self",
",",
"gotten_hash",
")",
":",
"# type: (str) -> None",
"self",
".",
"gotten_hash",
"=",
"gotten_hash"
] | [
262,
4
] | [
268,
38
] | python | en | ['en', 'error', 'th'] | False |
HashMismatch.__init__ | (self, allowed, gots) |
:param allowed: A dict of algorithm names pointing to lists of allowed
hex digests
:param gots: A dict of algorithm names pointing to hashes we
actually got from the files under suspicion
|
:param allowed: A dict of algorithm names pointing to lists of allowed
hex digests
:param gots: A dict of algorithm names pointing to hashes we
actually got from the files under suspicion
| def __init__(self, allowed, gots):
# type: (Dict[str, List[str]], Dict[str, _Hash]) -> None
"""
:param allowed: A dict of algorithm names pointing to lists of allowed
hex digests
:param gots: A dict of algorithm names pointing to hashes we
actually got from the fi... | [
"def",
"__init__",
"(",
"self",
",",
"allowed",
",",
"gots",
")",
":",
"# type: (Dict[str, List[str]], Dict[str, _Hash]) -> None",
"self",
".",
"allowed",
"=",
"allowed",
"self",
".",
"gots",
"=",
"gots"
] | [
313,
4
] | [
322,
24
] | python | en | ['en', 'error', 'th'] | False |
HashMismatch._hash_comparison | (self) |
Return a comparison of actual and expected hash values.
Example::
Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
or 123451234512345123451234512345123451234512345
Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef
... |
Return a comparison of actual and expected hash values. | def _hash_comparison(self):
# type: () -> str
"""
Return a comparison of actual and expected hash values.
Example::
Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
or 123451234512345123451234512345123451234512345
... | [
"def",
"_hash_comparison",
"(",
"self",
")",
":",
"# type: () -> str",
"def",
"hash_then_or",
"(",
"hash_name",
")",
":",
"# type: (str) -> chain[str]",
"# For now, all the decent hashes have 6-char names, so we can get",
"# away with hard-coding space literals.",
"return",
"chain"... | [
329,
4
] | [
354,
31
] | python | en | ['en', 'error', 'th'] | False |
get_lines_from_file | (filename, lineno, context_lines, loader=None, module_name=None) |
Returns context_lines before and after lineno from file.
Returns (pre_context_lineno, pre_context, context_line, post_context).
|
Returns context_lines before and after lineno from file.
Returns (pre_context_lineno, pre_context, context_line, post_context).
| def get_lines_from_file(filename, lineno, context_lines, loader=None, module_name=None):
"""
Returns context_lines before and after lineno from file.
Returns (pre_context_lineno, pre_context, context_line, post_context).
"""
source = None
if loader is not None and hasattr(loader, "get_source"):
... | [
"def",
"get_lines_from_file",
"(",
"filename",
",",
"lineno",
",",
"context_lines",
",",
"loader",
"=",
"None",
",",
"module_name",
"=",
"None",
")",
":",
"source",
"=",
"None",
"if",
"loader",
"is",
"not",
"None",
"and",
"hasattr",
"(",
"loader",
",",
"... | [
16,
0
] | [
71,
63
] | python | en | ['en', 'error', 'th'] | False |
create_streams_if_needed | (
realm: Realm, stream_dicts: List[StreamDict], acting_user: Optional[UserProfile] = None
) | Note that stream_dict["name"] is assumed to already be stripped of
whitespace | Note that stream_dict["name"] is assumed to already be stripped of
whitespace | def create_streams_if_needed(
realm: Realm, stream_dicts: List[StreamDict], acting_user: Optional[UserProfile] = None
) -> Tuple[List[Stream], List[Stream]]:
"""Note that stream_dict["name"] is assumed to already be stripped of
whitespace"""
added_streams: List[Stream] = []
existing_streams: List[St... | [
"def",
"create_streams_if_needed",
"(",
"realm",
":",
"Realm",
",",
"stream_dicts",
":",
"List",
"[",
"StreamDict",
"]",
",",
"acting_user",
":",
"Optional",
"[",
"UserProfile",
"]",
"=",
"None",
")",
"->",
"Tuple",
"[",
"List",
"[",
"Stream",
"]",
",",
... | [
140,
0
] | [
166,
42
] | python | en | ['en', 'en', 'en'] | True |
access_stream_common | (
user_profile: UserProfile,
stream: Stream,
error: str,
require_active: bool = True,
allow_realm_admin: bool = False,
) | Common function for backend code where the target use attempts to
access the target stream, returning all the data fetched along the
way. If that user does not have permission to access that stream,
we throw an exception. A design goal is that the error message is
the same for streams you can't access... | Common function for backend code where the target use attempts to
access the target stream, returning all the data fetched along the
way. If that user does not have permission to access that stream,
we throw an exception. A design goal is that the error message is
the same for streams you can't access... | def access_stream_common(
user_profile: UserProfile,
stream: Stream,
error: str,
require_active: bool = True,
allow_realm_admin: bool = False,
) -> Optional[Subscription]:
"""Common function for backend code where the target use attempts to
access the target stream, returning all the data fe... | [
"def",
"access_stream_common",
"(",
"user_profile",
":",
"UserProfile",
",",
"stream",
":",
"Stream",
",",
"error",
":",
"str",
",",
"require_active",
":",
"bool",
"=",
"True",
",",
"allow_realm_admin",
":",
"bool",
"=",
"False",
",",
")",
"->",
"Optional",
... | [
321,
0
] | [
367,
30
] | python | en | ['en', 'en', 'en'] | True |
access_stream_for_unmute_topic_by_name | (
user_profile: UserProfile, stream_name: str, error: str
) |
It may seem a little silly to have this helper function for unmuting
topics, but it gets around a linter warning, and it helps to be able
to review all security-related stuff in one place.
Our policy for accessing streams when you unmute a topic is that you
don't necessarily need to have an active... |
It may seem a little silly to have this helper function for unmuting
topics, but it gets around a linter warning, and it helps to be able
to review all security-related stuff in one place. | def access_stream_for_unmute_topic_by_name(
user_profile: UserProfile, stream_name: str, error: str
) -> Stream:
"""
It may seem a little silly to have this helper function for unmuting
topics, but it gets around a linter warning, and it helps to be able
to review all security-related stuff in one p... | [
"def",
"access_stream_for_unmute_topic_by_name",
"(",
"user_profile",
":",
"UserProfile",
",",
"stream_name",
":",
"str",
",",
"error",
":",
"str",
")",
"->",
"Stream",
":",
"try",
":",
"stream",
"=",
"get_stream",
"(",
"stream_name",
",",
"user_profile",
".",
... | [
448,
0
] | [
468,
17
] | python | en | ['en', 'error', 'th'] | False |
can_access_stream_history | (user_profile: UserProfile, stream: Stream) | Determine whether the provided user is allowed to access the
history of the target stream. The stream is specified by name.
This is used by the caller to determine whether this user can get
historical messages before they joined for a narrowing search.
Because of the way our search is currently struc... | Determine whether the provided user is allowed to access the
history of the target stream. The stream is specified by name. | def can_access_stream_history(user_profile: UserProfile, stream: Stream) -> bool:
"""Determine whether the provided user is allowed to access the
history of the target stream. The stream is specified by name.
This is used by the caller to determine whether this user can get
historical messages before ... | [
"def",
"can_access_stream_history",
"(",
"user_profile",
":",
"UserProfile",
",",
"stream",
":",
"Stream",
")",
"->",
"bool",
":",
"if",
"user_profile",
".",
"realm_id",
"!=",
"stream",
".",
"realm_id",
":",
"raise",
"AssertionError",
"(",
"\"user_profile and stre... | [
513,
0
] | [
547,
16
] | python | en | ['en', 'en', 'en'] | True |
list_to_streams | (
streams_raw: Collection[StreamDict],
user_profile: UserProfile,
autocreate: bool = False,
admin_access_required: bool = False,
) | Converts list of dicts to a list of Streams, validating input in the process
For each stream name, we validate it to ensure it meets our
requirements for a proper stream name using check_stream_name.
This function in autocreate mode should be atomic: either an exception will be raised
during a prechec... | Converts list of dicts to a list of Streams, validating input in the process | def list_to_streams(
streams_raw: Collection[StreamDict],
user_profile: UserProfile,
autocreate: bool = False,
admin_access_required: bool = False,
) -> Tuple[List[Stream], List[Stream]]:
"""Converts list of dicts to a list of Streams, validating input in the process
For each stream name, we va... | [
"def",
"list_to_streams",
"(",
"streams_raw",
":",
"Collection",
"[",
"StreamDict",
"]",
",",
"user_profile",
":",
"UserProfile",
",",
"autocreate",
":",
"bool",
"=",
"False",
",",
"admin_access_required",
":",
"bool",
"=",
"False",
",",
")",
"->",
"Tuple",
... | [
600,
0
] | [
685,
44
] | python | en | ['en', 'en', 'en'] | True |
get_stream_by_narrow_operand_access_unchecked | (operand: Union[str, int], realm: Realm) | This is required over access_stream_* in certain cases where
we need the stream data only to prepare a response that user can access
and not send it out to unauthorized recipients.
| This is required over access_stream_* in certain cases where
we need the stream data only to prepare a response that user can access
and not send it out to unauthorized recipients.
| def get_stream_by_narrow_operand_access_unchecked(operand: Union[str, int], realm: Realm) -> Stream:
"""This is required over access_stream_* in certain cases where
we need the stream data only to prepare a response that user can access
and not send it out to unauthorized recipients.
"""
if isinstan... | [
"def",
"get_stream_by_narrow_operand_access_unchecked",
"(",
"operand",
":",
"Union",
"[",
"str",
",",
"int",
"]",
",",
"realm",
":",
"Realm",
")",
"->",
"Stream",
":",
"if",
"isinstance",
"(",
"operand",
",",
"str",
")",
":",
"return",
"get_stream",
"(",
... | [
695,
0
] | [
702,
52
] | python | en | ['en', 'en', 'en'] | True |
build_wheel | (source_dir, wheel_dir, config_settings=None) | Build a wheel from a source directory using PEP 517 hooks.
:param str source_dir: Source directory containing pyproject.toml
:param str wheel_dir: Target directory to create wheel in
:param dict config_settings: Options to pass to build backend
This is a blocking function which will run pip in a subpr... | Build a wheel from a source directory using PEP 517 hooks. | def build_wheel(source_dir, wheel_dir, config_settings=None):
"""Build a wheel from a source directory using PEP 517 hooks.
:param str source_dir: Source directory containing pyproject.toml
:param str wheel_dir: Target directory to create wheel in
:param dict config_settings: Options to pass to build b... | [
"def",
"build_wheel",
"(",
"source_dir",
",",
"wheel_dir",
",",
"config_settings",
"=",
"None",
")",
":",
"if",
"config_settings",
"is",
"None",
":",
"config_settings",
"=",
"{",
"}",
"requires",
",",
"backend",
",",
"backend_path",
"=",
"_load_pyproject",
"("... | [
125,
0
] | [
144,
60
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.