repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
hazelcast/hazelcast-python-client | hazelcast/config.py | ClientConfig.add_membership_listener | def add_membership_listener(self, member_added=None, member_removed=None, fire_for_existing=False):
"""
Helper method for adding membership listeners
:param member_added: (Function), Function to be called when a member is added, in the form of f(member)
(optional).
:param member_removed: (Function), Function to be called when a member is removed, in the form of f(member)
(optional).
:param fire_for_existing: if True, already existing members will fire member_added event (optional).
:return: `self` for cascading configuration
"""
self.membership_listeners.append((member_added, member_removed, fire_for_existing))
return self | python | def add_membership_listener(self, member_added=None, member_removed=None, fire_for_existing=False):
"""
Helper method for adding membership listeners
:param member_added: (Function), Function to be called when a member is added, in the form of f(member)
(optional).
:param member_removed: (Function), Function to be called when a member is removed, in the form of f(member)
(optional).
:param fire_for_existing: if True, already existing members will fire member_added event (optional).
:return: `self` for cascading configuration
"""
self.membership_listeners.append((member_added, member_removed, fire_for_existing))
return self | [
"def",
"add_membership_listener",
"(",
"self",
",",
"member_added",
"=",
"None",
",",
"member_removed",
"=",
"None",
",",
"fire_for_existing",
"=",
"False",
")",
":",
"self",
".",
"membership_listeners",
".",
"append",
"(",
"(",
"member_added",
",",
"member_remo... | Helper method for adding membership listeners
:param member_added: (Function), Function to be called when a member is added, in the form of f(member)
(optional).
:param member_removed: (Function), Function to be called when a member is removed, in the form of f(member)
(optional).
:param fire_for_existing: if True, already existing members will fire member_added event (optional).
:return: `self` for cascading configuration | [
"Helper",
"method",
"for",
"adding",
"membership",
"listeners"
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/config.py#L119-L131 | train | 230,800 |
hazelcast/hazelcast-python-client | hazelcast/config.py | SerializationConfig.set_custom_serializer | def set_custom_serializer(self, _type, serializer):
"""
Assign a serializer for the type.
:param _type: (Type), the target type of the serializer
:param serializer: (Serializer), Custom Serializer constructor function
"""
validate_type(_type)
validate_serializer(serializer, StreamSerializer)
self._custom_serializers[_type] = serializer | python | def set_custom_serializer(self, _type, serializer):
"""
Assign a serializer for the type.
:param _type: (Type), the target type of the serializer
:param serializer: (Serializer), Custom Serializer constructor function
"""
validate_type(_type)
validate_serializer(serializer, StreamSerializer)
self._custom_serializers[_type] = serializer | [
"def",
"set_custom_serializer",
"(",
"self",
",",
"_type",
",",
"serializer",
")",
":",
"validate_type",
"(",
"_type",
")",
"validate_serializer",
"(",
"serializer",
",",
"StreamSerializer",
")",
"self",
".",
"_custom_serializers",
"[",
"_type",
"]",
"=",
"seria... | Assign a serializer for the type.
:param _type: (Type), the target type of the serializer
:param serializer: (Serializer), Custom Serializer constructor function | [
"Assign",
"a",
"serializer",
"for",
"the",
"type",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/config.py#L354-L363 | train | 230,801 |
hazelcast/hazelcast-python-client | hazelcast/config.py | ClientProperties.get | def get(self, property):
"""
Gets the value of the given property. First checks client config properties, then environment variables
and lastly fall backs to the default value of the property.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from
:return: Value of the given property
"""
return self._properties.get(property.name) or os.getenv(property.name) or property.default_value | python | def get(self, property):
"""
Gets the value of the given property. First checks client config properties, then environment variables
and lastly fall backs to the default value of the property.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from
:return: Value of the given property
"""
return self._properties.get(property.name) or os.getenv(property.name) or property.default_value | [
"def",
"get",
"(",
"self",
",",
"property",
")",
":",
"return",
"self",
".",
"_properties",
".",
"get",
"(",
"property",
".",
"name",
")",
"or",
"os",
".",
"getenv",
"(",
"property",
".",
"name",
")",
"or",
"property",
".",
"default_value"
] | Gets the value of the given property. First checks client config properties, then environment variables
and lastly fall backs to the default value of the property.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from
:return: Value of the given property | [
"Gets",
"the",
"value",
"of",
"the",
"given",
"property",
".",
"First",
"checks",
"client",
"config",
"properties",
"then",
"environment",
"variables",
"and",
"lastly",
"fall",
"backs",
"to",
"the",
"default",
"value",
"of",
"the",
"property",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/config.py#L712-L720 | train | 230,802 |
hazelcast/hazelcast-python-client | hazelcast/config.py | ClientProperties.get_bool | def get_bool(self, property):
"""
Gets the value of the given property as boolean.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from
:return: (bool), Value of the given property
"""
value = self.get(property)
if isinstance(value, bool):
return value
return value.lower() == "true" | python | def get_bool(self, property):
"""
Gets the value of the given property as boolean.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from
:return: (bool), Value of the given property
"""
value = self.get(property)
if isinstance(value, bool):
return value
return value.lower() == "true" | [
"def",
"get_bool",
"(",
"self",
",",
"property",
")",
":",
"value",
"=",
"self",
".",
"get",
"(",
"property",
")",
"if",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"return",
"value",
"return",
"value",
".",
"lower",
"(",
")",
"==",
"\"true\""... | Gets the value of the given property as boolean.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from
:return: (bool), Value of the given property | [
"Gets",
"the",
"value",
"of",
"the",
"given",
"property",
"as",
"boolean",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/config.py#L722-L732 | train | 230,803 |
hazelcast/hazelcast-python-client | hazelcast/config.py | ClientProperties.get_seconds | def get_seconds(self, property):
"""
Gets the value of the given property in seconds. If the value of the given property is not a number,
throws TypeError.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
:return: (float), Value of the given property in seconds
"""
return TimeUnit.to_seconds(self.get(property), property.time_unit) | python | def get_seconds(self, property):
"""
Gets the value of the given property in seconds. If the value of the given property is not a number,
throws TypeError.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
:return: (float), Value of the given property in seconds
"""
return TimeUnit.to_seconds(self.get(property), property.time_unit) | [
"def",
"get_seconds",
"(",
"self",
",",
"property",
")",
":",
"return",
"TimeUnit",
".",
"to_seconds",
"(",
"self",
".",
"get",
"(",
"property",
")",
",",
"property",
".",
"time_unit",
")"
] | Gets the value of the given property in seconds. If the value of the given property is not a number,
throws TypeError.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
:return: (float), Value of the given property in seconds | [
"Gets",
"the",
"value",
"of",
"the",
"given",
"property",
"in",
"seconds",
".",
"If",
"the",
"value",
"of",
"the",
"given",
"property",
"is",
"not",
"a",
"number",
"throws",
"TypeError",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/config.py#L734-L742 | train | 230,804 |
hazelcast/hazelcast-python-client | hazelcast/config.py | ClientProperties.get_seconds_positive_or_default | def get_seconds_positive_or_default(self, property):
"""
Gets the value of the given property in seconds. If the value of the given property is not a number,
throws TypeError. If the value of the given property in seconds is not positive, tries to
return the default value in seconds.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
:return: (float), Value of the given property in seconds if it is positive.
Else, value of the default value of given property in seconds.
"""
seconds = self.get_seconds(property)
return seconds if seconds > 0 else TimeUnit.to_seconds(property.default_value, property.time_unit) | python | def get_seconds_positive_or_default(self, property):
"""
Gets the value of the given property in seconds. If the value of the given property is not a number,
throws TypeError. If the value of the given property in seconds is not positive, tries to
return the default value in seconds.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
:return: (float), Value of the given property in seconds if it is positive.
Else, value of the default value of given property in seconds.
"""
seconds = self.get_seconds(property)
return seconds if seconds > 0 else TimeUnit.to_seconds(property.default_value, property.time_unit) | [
"def",
"get_seconds_positive_or_default",
"(",
"self",
",",
"property",
")",
":",
"seconds",
"=",
"self",
".",
"get_seconds",
"(",
"property",
")",
"return",
"seconds",
"if",
"seconds",
">",
"0",
"else",
"TimeUnit",
".",
"to_seconds",
"(",
"property",
".",
"... | Gets the value of the given property in seconds. If the value of the given property is not a number,
throws TypeError. If the value of the given property in seconds is not positive, tries to
return the default value in seconds.
:param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
:return: (float), Value of the given property in seconds if it is positive.
Else, value of the default value of given property in seconds. | [
"Gets",
"the",
"value",
"of",
"the",
"given",
"property",
"in",
"seconds",
".",
"If",
"the",
"value",
"of",
"the",
"given",
"property",
"is",
"not",
"a",
"number",
"throws",
"TypeError",
".",
"If",
"the",
"value",
"of",
"the",
"given",
"property",
"in",
... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/config.py#L744-L755 | train | 230,805 |
hazelcast/hazelcast-python-client | hazelcast/partition.py | PartitionService.start | def start(self):
"""
Starts the partition service.
"""
self.logger.debug("Starting partition service", extra=self._logger_extras)
def partition_updater():
self._do_refresh()
self.timer = self._client.reactor.add_timer(PARTITION_UPDATE_INTERVAL, partition_updater)
self.timer = self._client.reactor.add_timer(PARTITION_UPDATE_INTERVAL, partition_updater) | python | def start(self):
"""
Starts the partition service.
"""
self.logger.debug("Starting partition service", extra=self._logger_extras)
def partition_updater():
self._do_refresh()
self.timer = self._client.reactor.add_timer(PARTITION_UPDATE_INTERVAL, partition_updater)
self.timer = self._client.reactor.add_timer(PARTITION_UPDATE_INTERVAL, partition_updater) | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"Starting partition service\"",
",",
"extra",
"=",
"self",
".",
"_logger_extras",
")",
"def",
"partition_updater",
"(",
")",
":",
"self",
".",
"_do_refresh",
"(",
")",
"self... | Starts the partition service. | [
"Starts",
"the",
"partition",
"service",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/partition.py#L23-L33 | train | 230,806 |
hazelcast/hazelcast-python-client | hazelcast/partition.py | PartitionService.get_partition_owner | def get_partition_owner(self, partition_id):
"""
Gets the owner of the partition if it's set. Otherwise it will trigger partition assignment.
:param partition_id: (int), the partition id.
:return: (:class:`~hazelcast.core.Address`), owner of partition or ``None`` if it's not set yet.
"""
if partition_id not in self.partitions:
self._do_refresh()
return self.partitions.get(partition_id, None) | python | def get_partition_owner(self, partition_id):
"""
Gets the owner of the partition if it's set. Otherwise it will trigger partition assignment.
:param partition_id: (int), the partition id.
:return: (:class:`~hazelcast.core.Address`), owner of partition or ``None`` if it's not set yet.
"""
if partition_id not in self.partitions:
self._do_refresh()
return self.partitions.get(partition_id, None) | [
"def",
"get_partition_owner",
"(",
"self",
",",
"partition_id",
")",
":",
"if",
"partition_id",
"not",
"in",
"self",
".",
"partitions",
":",
"self",
".",
"_do_refresh",
"(",
")",
"return",
"self",
".",
"partitions",
".",
"get",
"(",
"partition_id",
",",
"N... | Gets the owner of the partition if it's set. Otherwise it will trigger partition assignment.
:param partition_id: (int), the partition id.
:return: (:class:`~hazelcast.core.Address`), owner of partition or ``None`` if it's not set yet. | [
"Gets",
"the",
"owner",
"of",
"the",
"partition",
"if",
"it",
"s",
"set",
".",
"Otherwise",
"it",
"will",
"trigger",
"partition",
"assignment",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/partition.py#L48-L57 | train | 230,807 |
hazelcast/hazelcast-python-client | hazelcast/partition.py | PartitionService.get_partition_id | def get_partition_id(self, key):
"""
Returns the partition id for a Data key.
:param key: (object), the data key.
:return: (int), the partition id.
"""
data = self._client.serialization_service.to_data(key)
count = self.get_partition_count()
if count <= 0:
return 0
return hash_to_index(data.get_partition_hash(), count) | python | def get_partition_id(self, key):
"""
Returns the partition id for a Data key.
:param key: (object), the data key.
:return: (int), the partition id.
"""
data = self._client.serialization_service.to_data(key)
count = self.get_partition_count()
if count <= 0:
return 0
return hash_to_index(data.get_partition_hash(), count) | [
"def",
"get_partition_id",
"(",
"self",
",",
"key",
")",
":",
"data",
"=",
"self",
".",
"_client",
".",
"serialization_service",
".",
"to_data",
"(",
"key",
")",
"count",
"=",
"self",
".",
"get_partition_count",
"(",
")",
"if",
"count",
"<=",
"0",
":",
... | Returns the partition id for a Data key.
:param key: (object), the data key.
:return: (int), the partition id. | [
"Returns",
"the",
"partition",
"id",
"for",
"a",
"Data",
"key",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/partition.py#L59-L70 | train | 230,808 |
hazelcast/hazelcast-python-client | hazelcast/hash.py | murmur_hash3_x86_32 | def murmur_hash3_x86_32(data, offset, size, seed=0x01000193):
"""
murmur3 hash function to determine partition
:param data: (byte array), input byte array
:param offset: (long), offset.
:param size: (long), byte length.
:param seed: murmur hash seed hazelcast uses 0x01000193
:return: (int32), calculated hash value.
"""
key = bytearray(data[offset: offset + size])
length = len(key)
nblocks = int(length / 4)
h1 = seed
c1 = 0xcc9e2d51
c2 = 0x1b873593
# body
for block_start in range(0, nblocks * 4, 4):
# ??? big endian?
k1 = key[block_start + 3] << 24 | \
key[block_start + 2] << 16 | \
key[block_start + 1] << 8 | \
key[block_start + 0]
k1 = c1 * k1 & 0xFFFFFFFF
k1 = (k1 << 15 | k1 >> 17) & 0xFFFFFFFF # inlined ROTL32
k1 = (c2 * k1) & 0xFFFFFFFF
h1 ^= k1
h1 = (h1 << 13 | h1 >> 19) & 0xFFFFFFFF # inlined _ROTL32
h1 = (h1 * 5 + 0xe6546b64) & 0xFFFFFFFF
# tail
tail_index = nblocks * 4
k1 = 0
tail_size = length & 3
if tail_size >= 3:
k1 ^= key[tail_index + 2] << 16
if tail_size >= 2:
k1 ^= key[tail_index + 1] << 8
if tail_size >= 1:
k1 ^= key[tail_index + 0]
if tail_size != 0:
k1 = (k1 * c1) & 0xFFFFFFFF
k1 = (k1 << 15 | k1 >> 17) & 0xFFFFFFFF # _ROTL32
k1 = (k1 * c2) & 0xFFFFFFFF
h1 ^= k1
result = _fmix(h1 ^ length)
return -(result & 0x80000000) | (result & 0x7FFFFFFF) | python | def murmur_hash3_x86_32(data, offset, size, seed=0x01000193):
"""
murmur3 hash function to determine partition
:param data: (byte array), input byte array
:param offset: (long), offset.
:param size: (long), byte length.
:param seed: murmur hash seed hazelcast uses 0x01000193
:return: (int32), calculated hash value.
"""
key = bytearray(data[offset: offset + size])
length = len(key)
nblocks = int(length / 4)
h1 = seed
c1 = 0xcc9e2d51
c2 = 0x1b873593
# body
for block_start in range(0, nblocks * 4, 4):
# ??? big endian?
k1 = key[block_start + 3] << 24 | \
key[block_start + 2] << 16 | \
key[block_start + 1] << 8 | \
key[block_start + 0]
k1 = c1 * k1 & 0xFFFFFFFF
k1 = (k1 << 15 | k1 >> 17) & 0xFFFFFFFF # inlined ROTL32
k1 = (c2 * k1) & 0xFFFFFFFF
h1 ^= k1
h1 = (h1 << 13 | h1 >> 19) & 0xFFFFFFFF # inlined _ROTL32
h1 = (h1 * 5 + 0xe6546b64) & 0xFFFFFFFF
# tail
tail_index = nblocks * 4
k1 = 0
tail_size = length & 3
if tail_size >= 3:
k1 ^= key[tail_index + 2] << 16
if tail_size >= 2:
k1 ^= key[tail_index + 1] << 8
if tail_size >= 1:
k1 ^= key[tail_index + 0]
if tail_size != 0:
k1 = (k1 * c1) & 0xFFFFFFFF
k1 = (k1 << 15 | k1 >> 17) & 0xFFFFFFFF # _ROTL32
k1 = (k1 * c2) & 0xFFFFFFFF
h1 ^= k1
result = _fmix(h1 ^ length)
return -(result & 0x80000000) | (result & 0x7FFFFFFF) | [
"def",
"murmur_hash3_x86_32",
"(",
"data",
",",
"offset",
",",
"size",
",",
"seed",
"=",
"0x01000193",
")",
":",
"key",
"=",
"bytearray",
"(",
"data",
"[",
"offset",
":",
"offset",
"+",
"size",
"]",
")",
"length",
"=",
"len",
"(",
"key",
")",
"nblock... | murmur3 hash function to determine partition
:param data: (byte array), input byte array
:param offset: (long), offset.
:param size: (long), byte length.
:param seed: murmur hash seed hazelcast uses 0x01000193
:return: (int32), calculated hash value. | [
"murmur3",
"hash",
"function",
"to",
"determine",
"partition"
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/hash.py#L13-L67 | train | 230,809 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.add | def add(self, item):
"""
Adds the specified item to the end of this list.
:param item: (object), the specified item to be appended to this list.
:return: (bool), ``true`` if item is added, ``false`` otherwise.
"""
check_not_none(item, "Value can't be None")
element_data = self._to_data(item)
return self._encode_invoke(list_add_codec, value=element_data) | python | def add(self, item):
"""
Adds the specified item to the end of this list.
:param item: (object), the specified item to be appended to this list.
:return: (bool), ``true`` if item is added, ``false`` otherwise.
"""
check_not_none(item, "Value can't be None")
element_data = self._to_data(item)
return self._encode_invoke(list_add_codec, value=element_data) | [
"def",
"add",
"(",
"self",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"element_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"list_add_codec",
",",
"value"... | Adds the specified item to the end of this list.
:param item: (object), the specified item to be appended to this list.
:return: (bool), ``true`` if item is added, ``false`` otherwise. | [
"Adds",
"the",
"specified",
"item",
"to",
"the",
"end",
"of",
"this",
"list",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L35-L44 | train | 230,810 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.add_at | def add_at(self, index, item):
"""
Adds the specified item at the specific position in this list. Element in this position and following elements
are shifted to the right, if any.
:param index: (int), the specified index to insert the item.
:param item: (object), the specified item to be inserted.
"""
check_not_none(item, "Value can't be None")
element_data = self._to_data(item)
return self._encode_invoke(list_add_with_index_codec, index=index, value=element_data) | python | def add_at(self, index, item):
"""
Adds the specified item at the specific position in this list. Element in this position and following elements
are shifted to the right, if any.
:param index: (int), the specified index to insert the item.
:param item: (object), the specified item to be inserted.
"""
check_not_none(item, "Value can't be None")
element_data = self._to_data(item)
return self._encode_invoke(list_add_with_index_codec, index=index, value=element_data) | [
"def",
"add_at",
"(",
"self",
",",
"index",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"element_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"list_add_wit... | Adds the specified item at the specific position in this list. Element in this position and following elements
are shifted to the right, if any.
:param index: (int), the specified index to insert the item.
:param item: (object), the specified item to be inserted. | [
"Adds",
"the",
"specified",
"item",
"at",
"the",
"specific",
"position",
"in",
"this",
"list",
".",
"Element",
"in",
"this",
"position",
"and",
"following",
"elements",
"are",
"shifted",
"to",
"the",
"right",
"if",
"any",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L46-L56 | train | 230,811 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.add_all | def add_all(self, items):
"""
Adds all of the items in the specified collection to the end of this list. The order of new elements is
determined by the specified collection's iterator.
:param items: (Collection), the specified collection which includes the elements to be added to list.
:return: (bool), ``true`` if this call changed the list, ``false`` otherwise.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_add_all_codec, value_list=data_items) | python | def add_all(self, items):
"""
Adds all of the items in the specified collection to the end of this list. The order of new elements is
determined by the specified collection's iterator.
:param items: (Collection), the specified collection which includes the elements to be added to list.
:return: (bool), ``true`` if this call changed the list, ``false`` otherwise.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_add_all_codec, value_list=data_items) | [
"def",
"add_all",
"(",
"self",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Value can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"d... | Adds all of the items in the specified collection to the end of this list. The order of new elements is
determined by the specified collection's iterator.
:param items: (Collection), the specified collection which includes the elements to be added to list.
:return: (bool), ``true`` if this call changed the list, ``false`` otherwise. | [
"Adds",
"all",
"of",
"the",
"items",
"in",
"the",
"specified",
"collection",
"to",
"the",
"end",
"of",
"this",
"list",
".",
"The",
"order",
"of",
"new",
"elements",
"is",
"determined",
"by",
"the",
"specified",
"collection",
"s",
"iterator",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L58-L71 | train | 230,812 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.add_all_at | def add_all_at(self, index, items):
"""
Adds all of the elements in the specified collection into this list at the specified position. Elements in this
positions and following elements are shifted to the right, if any. The order of new elements is determined by the
specified collection's iterator.
:param index: (int), the specified index at which the first element of specified collection is added.
:param items: (Collection), the specified collection which includes the elements to be added to list.
:return: (bool), ``true`` if this call changed the list, ``false`` otherwise.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_add_all_with_index_codec, index=index, value_list=data_items) | python | def add_all_at(self, index, items):
"""
Adds all of the elements in the specified collection into this list at the specified position. Elements in this
positions and following elements are shifted to the right, if any. The order of new elements is determined by the
specified collection's iterator.
:param index: (int), the specified index at which the first element of specified collection is added.
:param items: (Collection), the specified collection which includes the elements to be added to list.
:return: (bool), ``true`` if this call changed the list, ``false`` otherwise.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_add_all_with_index_codec, index=index, value_list=data_items) | [
"def",
"add_all_at",
"(",
"self",
",",
"index",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Value can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be... | Adds all of the elements in the specified collection into this list at the specified position. Elements in this
positions and following elements are shifted to the right, if any. The order of new elements is determined by the
specified collection's iterator.
:param index: (int), the specified index at which the first element of specified collection is added.
:param items: (Collection), the specified collection which includes the elements to be added to list.
:return: (bool), ``true`` if this call changed the list, ``false`` otherwise. | [
"Adds",
"all",
"of",
"the",
"elements",
"in",
"the",
"specified",
"collection",
"into",
"this",
"list",
"at",
"the",
"specified",
"position",
".",
"Elements",
"in",
"this",
"positions",
"and",
"following",
"elements",
"are",
"shifted",
"to",
"the",
"right",
... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L73-L88 | train | 230,813 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.contains_all | def contains_all(self, items):
"""
Determines whether this list contains all of the items in specified collection or not.
:param items: (Collection), the specified collection which includes the items to be searched.
:return: (bool), ``true`` if all of the items in specified collection exist in this list, ``false`` otherwise.
"""
check_not_none(items, "Items can't be None")
data_items = []
for item in items:
check_not_none(item, "item can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_contains_all_codec, values=data_items) | python | def contains_all(self, items):
"""
Determines whether this list contains all of the items in specified collection or not.
:param items: (Collection), the specified collection which includes the items to be searched.
:return: (bool), ``true`` if all of the items in specified collection exist in this list, ``false`` otherwise.
"""
check_not_none(items, "Items can't be None")
data_items = []
for item in items:
check_not_none(item, "item can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_contains_all_codec, values=data_items) | [
"def",
"contains_all",
"(",
"self",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Items can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"item can't be None\"",
")",
... | Determines whether this list contains all of the items in specified collection or not.
:param items: (Collection), the specified collection which includes the items to be searched.
:return: (bool), ``true`` if all of the items in specified collection exist in this list, ``false`` otherwise. | [
"Determines",
"whether",
"this",
"list",
"contains",
"all",
"of",
"the",
"items",
"in",
"specified",
"collection",
"or",
"not",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L135-L147 | train | 230,814 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.index_of | def index_of(self, item):
"""
Returns the first index of specified items's occurrences in this list. If specified item is not present in this
list, returns -1.
:param item: (object), the specified item to be searched for.
:return: (int), the first index of specified items's occurrences, -1 if item is not present in this list.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(list_index_of_codec, value=item_data) | python | def index_of(self, item):
"""
Returns the first index of specified items's occurrences in this list. If specified item is not present in this
list, returns -1.
:param item: (object), the specified item to be searched for.
:return: (int), the first index of specified items's occurrences, -1 if item is not present in this list.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(list_index_of_codec, value=item_data) | [
"def",
"index_of",
"(",
"self",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"item_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"list_index_of_codec",
",",
... | Returns the first index of specified items's occurrences in this list. If specified item is not present in this
list, returns -1.
:param item: (object), the specified item to be searched for.
:return: (int), the first index of specified items's occurrences, -1 if item is not present in this list. | [
"Returns",
"the",
"first",
"index",
"of",
"specified",
"items",
"s",
"occurrences",
"in",
"this",
"list",
".",
"If",
"specified",
"item",
"is",
"not",
"present",
"in",
"this",
"list",
"returns",
"-",
"1",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L174-L184 | train | 230,815 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.last_index_of | def last_index_of(self, item):
"""
Returns the last index of specified items's occurrences in this list. If specified item is not present in this
list, returns -1.
:param item: (object), the specified item to be searched for.
:return: (int), the last index of specified items's occurrences, -1 if item is not present in this list.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(list_last_index_of_codec, value=item_data) | python | def last_index_of(self, item):
"""
Returns the last index of specified items's occurrences in this list. If specified item is not present in this
list, returns -1.
:param item: (object), the specified item to be searched for.
:return: (int), the last index of specified items's occurrences, -1 if item is not present in this list.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(list_last_index_of_codec, value=item_data) | [
"def",
"last_index_of",
"(",
"self",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"item_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"list_last_index_of_codec",... | Returns the last index of specified items's occurrences in this list. If specified item is not present in this
list, returns -1.
:param item: (object), the specified item to be searched for.
:return: (int), the last index of specified items's occurrences, -1 if item is not present in this list. | [
"Returns",
"the",
"last",
"index",
"of",
"specified",
"items",
"s",
"occurrences",
"in",
"this",
"list",
".",
"If",
"specified",
"item",
"is",
"not",
"present",
"in",
"this",
"list",
"returns",
"-",
"1",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L194-L204 | train | 230,816 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.remove | def remove(self, item):
"""
Removes the specified element's first occurrence from the list if it exists in this list.
:param item: (object), the specified element.
:return: (bool), ``true`` if the specified element is present in this list.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(list_remove_codec, value=item_data) | python | def remove(self, item):
"""
Removes the specified element's first occurrence from the list if it exists in this list.
:param item: (object), the specified element.
:return: (bool), ``true`` if the specified element is present in this list.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(list_remove_codec, value=item_data) | [
"def",
"remove",
"(",
"self",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"item_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"list_remove_codec",
",",
"val... | Removes the specified element's first occurrence from the list if it exists in this list.
:param item: (object), the specified element.
:return: (bool), ``true`` if the specified element is present in this list. | [
"Removes",
"the",
"specified",
"element",
"s",
"first",
"occurrence",
"from",
"the",
"list",
"if",
"it",
"exists",
"in",
"this",
"list",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L215-L224 | train | 230,817 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.remove_all | def remove_all(self, items):
"""
Removes all of the elements that is present in the specified collection from this list.
:param items: (Collection), the specified collection.
:return: (bool), ``true`` if this list changed as a result of the call.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_compare_and_remove_all_codec, values=data_items) | python | def remove_all(self, items):
"""
Removes all of the elements that is present in the specified collection from this list.
:param items: (Collection), the specified collection.
:return: (bool), ``true`` if this list changed as a result of the call.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_compare_and_remove_all_codec, values=data_items) | [
"def",
"remove_all",
"(",
"self",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Value can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
... | Removes all of the elements that is present in the specified collection from this list.
:param items: (Collection), the specified collection.
:return: (bool), ``true`` if this list changed as a result of the call. | [
"Removes",
"all",
"of",
"the",
"elements",
"that",
"is",
"present",
"in",
"the",
"specified",
"collection",
"from",
"this",
"list",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L236-L248 | train | 230,818 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.retain_all | def retain_all(self, items):
"""
Retains only the items that are contained in the specified collection. It means, items which are not present in
the specified collection are removed from this list.
:param items: (Collection), collections which includes the elements to be retained in this list.
:return: (bool), ``true`` if this list changed as a result of the call.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_compare_and_retain_all_codec, values=data_items) | python | def retain_all(self, items):
"""
Retains only the items that are contained in the specified collection. It means, items which are not present in
the specified collection are removed from this list.
:param items: (Collection), collections which includes the elements to be retained in this list.
:return: (bool), ``true`` if this list changed as a result of the call.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(list_compare_and_retain_all_codec, values=data_items) | [
"def",
"retain_all",
"(",
"self",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Value can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
... | Retains only the items that are contained in the specified collection. It means, items which are not present in
the specified collection are removed from this list.
:param items: (Collection), collections which includes the elements to be retained in this list.
:return: (bool), ``true`` if this list changed as a result of the call. | [
"Retains",
"only",
"the",
"items",
"that",
"are",
"contained",
"in",
"the",
"specified",
"collection",
".",
"It",
"means",
"items",
"which",
"are",
"not",
"present",
"in",
"the",
"specified",
"collection",
"are",
"removed",
"from",
"this",
"list",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L259-L272 | train | 230,819 |
hazelcast/hazelcast-python-client | hazelcast/proxy/list.py | List.set_at | def set_at(self, index, item):
"""
Replaces the specified element with the element at the specified position in this list.
:param index: (int), index of the item to be replaced.
:param item: (object), item to be stored.
:return: (object), the previous item in the specified index.
"""
check_not_none(item, "Value can't be None")
element_data = self._to_data(item)
return self._encode_invoke(list_set_codec, index=index, value=element_data) | python | def set_at(self, index, item):
"""
Replaces the specified element with the element at the specified position in this list.
:param index: (int), index of the item to be replaced.
:param item: (object), item to be stored.
:return: (object), the previous item in the specified index.
"""
check_not_none(item, "Value can't be None")
element_data = self._to_data(item)
return self._encode_invoke(list_set_codec, index=index, value=element_data) | [
"def",
"set_at",
"(",
"self",
",",
"index",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"element_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"list_set_cod... | Replaces the specified element with the element at the specified position in this list.
:param index: (int), index of the item to be replaced.
:param item: (object), item to be stored.
:return: (object), the previous item in the specified index. | [
"Replaces",
"the",
"specified",
"element",
"with",
"the",
"element",
"at",
"the",
"specified",
"position",
"in",
"this",
"list",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/list.py#L282-L292 | train | 230,820 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.add_index | def add_index(self, attribute, ordered=False):
"""
Adds an index to this map for the specified entries so that queries can run faster.
Example:
Let's say your map values are Employee objects.
>>> class Employee(IdentifiedDataSerializable):
>>> active = false
>>> age = None
>>> name = None
>>> #other fields
>>>
>>> #methods
If you query your values mostly based on age and active fields, you should consider indexing these.
>>> map = self.client.get_map("employees")
>>> map.add_index("age" , true) #ordered, since we have ranged queries for this field
>>> map.add_index("active", false) #not ordered, because boolean field cannot have range
:param attribute: (str), index attribute of the value.
:param ordered: (bool), for ordering the index or not (optional).
"""
return self._encode_invoke(map_add_index_codec, attribute=attribute, ordered=ordered) | python | def add_index(self, attribute, ordered=False):
"""
Adds an index to this map for the specified entries so that queries can run faster.
Example:
Let's say your map values are Employee objects.
>>> class Employee(IdentifiedDataSerializable):
>>> active = false
>>> age = None
>>> name = None
>>> #other fields
>>>
>>> #methods
If you query your values mostly based on age and active fields, you should consider indexing these.
>>> map = self.client.get_map("employees")
>>> map.add_index("age" , true) #ordered, since we have ranged queries for this field
>>> map.add_index("active", false) #not ordered, because boolean field cannot have range
:param attribute: (str), index attribute of the value.
:param ordered: (bool), for ordering the index or not (optional).
"""
return self._encode_invoke(map_add_index_codec, attribute=attribute, ordered=ordered) | [
"def",
"add_index",
"(",
"self",
",",
"attribute",
",",
"ordered",
"=",
"False",
")",
":",
"return",
"self",
".",
"_encode_invoke",
"(",
"map_add_index_codec",
",",
"attribute",
"=",
"attribute",
",",
"ordered",
"=",
"ordered",
")"
] | Adds an index to this map for the specified entries so that queries can run faster.
Example:
Let's say your map values are Employee objects.
>>> class Employee(IdentifiedDataSerializable):
>>> active = false
>>> age = None
>>> name = None
>>> #other fields
>>>
>>> #methods
If you query your values mostly based on age and active fields, you should consider indexing these.
>>> map = self.client.get_map("employees")
>>> map.add_index("age" , true) #ordered, since we have ranged queries for this field
>>> map.add_index("active", false) #not ordered, because boolean field cannot have range
:param attribute: (str), index attribute of the value.
:param ordered: (bool), for ordering the index or not (optional). | [
"Adds",
"an",
"index",
"to",
"this",
"map",
"for",
"the",
"specified",
"entries",
"so",
"that",
"queries",
"can",
"run",
"faster",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L124-L147 | train | 230,821 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.add_interceptor | def add_interceptor(self, interceptor):
"""
Adds an interceptor for this map. Added interceptor will intercept operations and execute user defined methods.
:param interceptor: (object), interceptor for the map which includes user defined methods.
:return: (str),id of registered interceptor.
"""
return self._encode_invoke(map_add_interceptor_codec, interceptor=self._to_data(interceptor)) | python | def add_interceptor(self, interceptor):
"""
Adds an interceptor for this map. Added interceptor will intercept operations and execute user defined methods.
:param interceptor: (object), interceptor for the map which includes user defined methods.
:return: (str),id of registered interceptor.
"""
return self._encode_invoke(map_add_interceptor_codec, interceptor=self._to_data(interceptor)) | [
"def",
"add_interceptor",
"(",
"self",
",",
"interceptor",
")",
":",
"return",
"self",
".",
"_encode_invoke",
"(",
"map_add_interceptor_codec",
",",
"interceptor",
"=",
"self",
".",
"_to_data",
"(",
"interceptor",
")",
")"
] | Adds an interceptor for this map. Added interceptor will intercept operations and execute user defined methods.
:param interceptor: (object), interceptor for the map which includes user defined methods.
:return: (str),id of registered interceptor. | [
"Adds",
"an",
"interceptor",
"for",
"this",
"map",
".",
"Added",
"interceptor",
"will",
"intercept",
"operations",
"and",
"execute",
"user",
"defined",
"methods",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L149-L156 | train | 230,822 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.entry_set | def entry_set(self, predicate=None):
"""
Returns a list clone of the mappings contained in this map.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.**
:param predicate: (Predicate), predicate for the map to filter entries (optional).
:return: (Sequence), the list of key-value tuples in the map.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
predicate_data = self._to_data(predicate)
return self._encode_invoke(map_entries_with_predicate_codec, predicate=predicate_data)
else:
return self._encode_invoke(map_entry_set_codec) | python | def entry_set(self, predicate=None):
"""
Returns a list clone of the mappings contained in this map.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.**
:param predicate: (Predicate), predicate for the map to filter entries (optional).
:return: (Sequence), the list of key-value tuples in the map.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
predicate_data = self._to_data(predicate)
return self._encode_invoke(map_entries_with_predicate_codec, predicate=predicate_data)
else:
return self._encode_invoke(map_entry_set_codec) | [
"def",
"entry_set",
"(",
"self",
",",
"predicate",
"=",
"None",
")",
":",
"if",
"predicate",
":",
"predicate_data",
"=",
"self",
".",
"_to_data",
"(",
"predicate",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"map_entries_with_predicate_codec",
",",
"pre... | Returns a list clone of the mappings contained in this map.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.**
:param predicate: (Predicate), predicate for the map to filter entries (optional).
:return: (Sequence), the list of key-value tuples in the map.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. | [
"Returns",
"a",
"list",
"clone",
"of",
"the",
"mappings",
"contained",
"in",
"this",
"map",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L212-L228 | train | 230,823 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.evict | def evict(self, key):
"""
Evicts the specified key from this map.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key to evict.
:return: (bool), ``true`` if the key is evicted, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._evict_internal(key_data) | python | def evict(self, key):
"""
Evicts the specified key from this map.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key to evict.
:return: (bool), ``true`` if the key is evicted, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._evict_internal(key_data) | [
"def",
"evict",
"(",
"self",
",",
"key",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_evict_internal",
"(",
"key_data",
")"
] | Evicts the specified key from this map.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key to evict.
:return: (bool), ``true`` if the key is evicted, ``false`` otherwise. | [
"Evicts",
"the",
"specified",
"key",
"from",
"this",
"map",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L230-L242 | train | 230,824 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.execute_on_entries | def execute_on_entries(self, entry_processor, predicate=None):
"""
Applies the user defined EntryProcessor to all the entries in the map or entries in the map which satisfies
the predicate if provided. Returns the results mapped by each key in the map.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:param predicate: (Predicate), predicate for filtering the entries (optional).
:return: (Sequence), list of map entries which includes the keys and the results of the entry process.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
return self._encode_invoke(map_execute_with_predicate_codec, entry_processor=self._to_data(entry_processor),
predicate=self._to_data(predicate))
return self._encode_invoke(map_execute_on_all_keys_codec, entry_processor=self._to_data(entry_processor)) | python | def execute_on_entries(self, entry_processor, predicate=None):
"""
Applies the user defined EntryProcessor to all the entries in the map or entries in the map which satisfies
the predicate if provided. Returns the results mapped by each key in the map.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:param predicate: (Predicate), predicate for filtering the entries (optional).
:return: (Sequence), list of map entries which includes the keys and the results of the entry process.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
return self._encode_invoke(map_execute_with_predicate_codec, entry_processor=self._to_data(entry_processor),
predicate=self._to_data(predicate))
return self._encode_invoke(map_execute_on_all_keys_codec, entry_processor=self._to_data(entry_processor)) | [
"def",
"execute_on_entries",
"(",
"self",
",",
"entry_processor",
",",
"predicate",
"=",
"None",
")",
":",
"if",
"predicate",
":",
"return",
"self",
".",
"_encode_invoke",
"(",
"map_execute_with_predicate_codec",
",",
"entry_processor",
"=",
"self",
".",
"_to_data... | Applies the user defined EntryProcessor to all the entries in the map or entries in the map which satisfies
the predicate if provided. Returns the results mapped by each key in the map.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:param predicate: (Predicate), predicate for filtering the entries (optional).
:return: (Sequence), list of map entries which includes the keys and the results of the entry process.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. | [
"Applies",
"the",
"user",
"defined",
"EntryProcessor",
"to",
"all",
"the",
"entries",
"in",
"the",
"map",
"or",
"entries",
"in",
"the",
"map",
"which",
"satisfies",
"the",
"predicate",
"if",
"provided",
".",
"Returns",
"the",
"results",
"mapped",
"by",
"each... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L252-L269 | train | 230,825 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.execute_on_key | def execute_on_key(self, key, entry_processor):
"""
Applies the user defined EntryProcessor to the entry mapped by the key. Returns the object which is the result
of EntryProcessor's process method.
:param key: (object), specified key for the entry to be processed.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:return: (object), result of entry process.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._execute_on_key_internal(key_data, entry_processor) | python | def execute_on_key(self, key, entry_processor):
"""
Applies the user defined EntryProcessor to the entry mapped by the key. Returns the object which is the result
of EntryProcessor's process method.
:param key: (object), specified key for the entry to be processed.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:return: (object), result of entry process.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._execute_on_key_internal(key_data, entry_processor) | [
"def",
"execute_on_key",
"(",
"self",
",",
"key",
",",
"entry_processor",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_execute_on_key_internal",
"... | Applies the user defined EntryProcessor to the entry mapped by the key. Returns the object which is the result
of EntryProcessor's process method.
:param key: (object), specified key for the entry to be processed.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:return: (object), result of entry process. | [
"Applies",
"the",
"user",
"defined",
"EntryProcessor",
"to",
"the",
"entry",
"mapped",
"by",
"the",
"key",
".",
"Returns",
"the",
"object",
"which",
"is",
"the",
"result",
"of",
"EntryProcessor",
"s",
"process",
"method",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L271-L285 | train | 230,826 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.execute_on_keys | def execute_on_keys(self, keys, entry_processor):
"""
Applies the user defined EntryProcessor to the entries mapped by the collection of keys. Returns the results
mapped by each key in the collection.
:param keys: (Collection), collection of the keys for the entries to be processed.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:return: (Sequence), list of map entries which includes the keys and the results of the entry process.
"""
key_list = []
for key in keys:
check_not_none(key, "key can't be None")
key_list.append(self._to_data(key))
if len(keys) == 0:
return ImmediateFuture([])
return self._encode_invoke(map_execute_on_keys_codec, entry_processor=self._to_data(entry_processor),
keys=key_list) | python | def execute_on_keys(self, keys, entry_processor):
"""
Applies the user defined EntryProcessor to the entries mapped by the collection of keys. Returns the results
mapped by each key in the collection.
:param keys: (Collection), collection of the keys for the entries to be processed.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:return: (Sequence), list of map entries which includes the keys and the results of the entry process.
"""
key_list = []
for key in keys:
check_not_none(key, "key can't be None")
key_list.append(self._to_data(key))
if len(keys) == 0:
return ImmediateFuture([])
return self._encode_invoke(map_execute_on_keys_codec, entry_processor=self._to_data(entry_processor),
keys=key_list) | [
"def",
"execute_on_keys",
"(",
"self",
",",
"keys",
",",
"entry_processor",
")",
":",
"key_list",
"=",
"[",
"]",
"for",
"key",
"in",
"keys",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_list",
".",
"append",
"(",
"self",
".",
... | Applies the user defined EntryProcessor to the entries mapped by the collection of keys. Returns the results
mapped by each key in the collection.
:param keys: (Collection), collection of the keys for the entries to be processed.
:param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on
server side.
This object must have a serializable EntryProcessor counter part registered on server side with the actual
``org.hazelcast.map.EntryProcessor`` implementation.
:return: (Sequence), list of map entries which includes the keys and the results of the entry process. | [
"Applies",
"the",
"user",
"defined",
"EntryProcessor",
"to",
"the",
"entries",
"mapped",
"by",
"the",
"collection",
"of",
"keys",
".",
"Returns",
"the",
"results",
"mapped",
"by",
"each",
"key",
"in",
"the",
"collection",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L287-L308 | train | 230,827 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.force_unlock | def force_unlock(self, key):
"""
Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key,
never blocks, and returns immediately.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key to lock.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_force_unlock_codec, key_data, key=key_data,
reference_id=self.reference_id_generator.get_and_increment()) | python | def force_unlock(self, key):
"""
Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key,
never blocks, and returns immediately.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key to lock.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_force_unlock_codec, key_data, key=key_data,
reference_id=self.reference_id_generator.get_and_increment()) | [
"def",
"force_unlock",
"(",
"self",
",",
"key",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_encode_invoke_on_key",
"(",
"map_force_unlock_codec",
... | Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key,
never blocks, and returns immediately.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key to lock. | [
"Releases",
"the",
"lock",
"for",
"the",
"specified",
"key",
"regardless",
"of",
"the",
"lock",
"owner",
".",
"It",
"always",
"successfully",
"unlocks",
"the",
"key",
"never",
"blocks",
"and",
"returns",
"immediately",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L316-L329 | train | 230,828 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.get_all | def get_all(self, keys):
"""
Returns the entries for the given keys.
**Warning:
The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the
returned map, and vice-versa.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param keys: (Collection), keys to get.
:return: (dict), dictionary of map entries.
"""
check_not_none(keys, "keys can't be None")
if not keys:
return ImmediateFuture({})
partition_service = self._client.partition_service
partition_to_keys = {}
for key in keys:
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
partition_id = partition_service.get_partition_id(key_data)
try:
partition_to_keys[partition_id][key] = key_data
except KeyError:
partition_to_keys[partition_id] = {key: key_data}
return self._get_all_internal(partition_to_keys) | python | def get_all(self, keys):
"""
Returns the entries for the given keys.
**Warning:
The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the
returned map, and vice-versa.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param keys: (Collection), keys to get.
:return: (dict), dictionary of map entries.
"""
check_not_none(keys, "keys can't be None")
if not keys:
return ImmediateFuture({})
partition_service = self._client.partition_service
partition_to_keys = {}
for key in keys:
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
partition_id = partition_service.get_partition_id(key_data)
try:
partition_to_keys[partition_id][key] = key_data
except KeyError:
partition_to_keys[partition_id] = {key: key_data}
return self._get_all_internal(partition_to_keys) | [
"def",
"get_all",
"(",
"self",
",",
"keys",
")",
":",
"check_not_none",
"(",
"keys",
",",
"\"keys can't be None\"",
")",
"if",
"not",
"keys",
":",
"return",
"ImmediateFuture",
"(",
"{",
"}",
")",
"partition_service",
"=",
"self",
".",
"_client",
".",
"part... | Returns the entries for the given keys.
**Warning:
The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the
returned map, and vice-versa.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param keys: (Collection), keys to get.
:return: (dict), dictionary of map entries. | [
"Returns",
"the",
"entries",
"for",
"the",
"given",
"keys",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L352-L382 | train | 230,829 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.get_entry_view | def get_entry_view(self, key):
"""
Returns the EntryView for the specified key.
**Warning:
This method returns a clone of original mapping, modifying the returned value does not change the actual value
in the map. One should put modified value back to make changes visible to all nodes.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key of the entry.
:return: (EntryView), EntryView of the specified key.
.. seealso:: :class:`~hazelcast.core.EntryView` for more info about EntryView.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_get_entry_view_codec, key_data, key=key_data, thread_id=thread_id()) | python | def get_entry_view(self, key):
"""
Returns the EntryView for the specified key.
**Warning:
This method returns a clone of original mapping, modifying the returned value does not change the actual value
in the map. One should put modified value back to make changes visible to all nodes.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key of the entry.
:return: (EntryView), EntryView of the specified key.
.. seealso:: :class:`~hazelcast.core.EntryView` for more info about EntryView.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_get_entry_view_codec, key_data, key=key_data, thread_id=thread_id()) | [
"def",
"get_entry_view",
"(",
"self",
",",
"key",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_encode_invoke_on_key",
"(",
"map_get_entry_view_codec... | Returns the EntryView for the specified key.
**Warning:
This method returns a clone of original mapping, modifying the returned value does not change the actual value
in the map. One should put modified value back to make changes visible to all nodes.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key of the entry.
:return: (EntryView), EntryView of the specified key.
.. seealso:: :class:`~hazelcast.core.EntryView` for more info about EntryView. | [
"Returns",
"the",
"EntryView",
"for",
"the",
"specified",
"key",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L384-L402 | train | 230,830 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.is_locked | def is_locked(self, key):
"""
Checks the lock for the specified key. If the lock is acquired, it returns ``true``. Otherwise, it returns ``false``.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key that is checked for lock
:return: (bool), ``true`` if lock is acquired, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_is_locked_codec, key_data, key=key_data) | python | def is_locked(self, key):
"""
Checks the lock for the specified key. If the lock is acquired, it returns ``true``. Otherwise, it returns ``false``.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key that is checked for lock
:return: (bool), ``true`` if lock is acquired, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_is_locked_codec, key_data, key=key_data) | [
"def",
"is_locked",
"(",
"self",
",",
"key",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_encode_invoke_on_key",
"(",
"map_is_locked_codec",
",",
... | Checks the lock for the specified key. If the lock is acquired, it returns ``true``. Otherwise, it returns ``false``.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the key that is checked for lock
:return: (bool), ``true`` if lock is acquired, ``false`` otherwise. | [
"Checks",
"the",
"lock",
"for",
"the",
"specified",
"key",
".",
"If",
"the",
"lock",
"is",
"acquired",
"it",
"returns",
"true",
".",
"Otherwise",
"it",
"returns",
"false",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L412-L424 | train | 230,831 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.key_set | def key_set(self, predicate=None):
"""
Returns a List clone of the keys contained in this map or the keys of the entries filtered with the predicate if
provided.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.**
:param predicate: (Predicate), predicate to filter the entries (optional).
:return: (Sequence), a list of the clone of the keys.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
predicate_data = self._to_data(predicate)
return self._encode_invoke(map_key_set_with_predicate_codec, predicate=predicate_data)
else:
return self._encode_invoke(map_key_set_codec) | python | def key_set(self, predicate=None):
"""
Returns a List clone of the keys contained in this map or the keys of the entries filtered with the predicate if
provided.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.**
:param predicate: (Predicate), predicate to filter the entries (optional).
:return: (Sequence), a list of the clone of the keys.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
predicate_data = self._to_data(predicate)
return self._encode_invoke(map_key_set_with_predicate_codec, predicate=predicate_data)
else:
return self._encode_invoke(map_key_set_codec) | [
"def",
"key_set",
"(",
"self",
",",
"predicate",
"=",
"None",
")",
":",
"if",
"predicate",
":",
"predicate_data",
"=",
"self",
".",
"_to_data",
"(",
"predicate",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"map_key_set_with_predicate_codec",
",",
"predi... | Returns a List clone of the keys contained in this map or the keys of the entries filtered with the predicate if
provided.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.**
:param predicate: (Predicate), predicate to filter the entries (optional).
:return: (Sequence), a list of the clone of the keys.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. | [
"Returns",
"a",
"List",
"clone",
"of",
"the",
"keys",
"contained",
"in",
"this",
"map",
"or",
"the",
"keys",
"of",
"the",
"entries",
"filtered",
"with",
"the",
"predicate",
"if",
"provided",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L426-L443 | train | 230,832 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.load_all | def load_all(self, keys=None, replace_existing_values=True):
"""
Loads all keys from the store at server side or loads the given keys if provided.
:param keys: (Collection), keys of the entry values to load (optional).
:param replace_existing_values: (bool), whether the existing values will be replaced or not with those loaded
from the server side MapLoader (optional).
"""
if keys:
key_data_list = list(map(self._to_data, keys))
return self._load_all_internal(key_data_list, replace_existing_values)
else:
return self._encode_invoke(map_load_all_codec, replace_existing_values=replace_existing_values) | python | def load_all(self, keys=None, replace_existing_values=True):
"""
Loads all keys from the store at server side or loads the given keys if provided.
:param keys: (Collection), keys of the entry values to load (optional).
:param replace_existing_values: (bool), whether the existing values will be replaced or not with those loaded
from the server side MapLoader (optional).
"""
if keys:
key_data_list = list(map(self._to_data, keys))
return self._load_all_internal(key_data_list, replace_existing_values)
else:
return self._encode_invoke(map_load_all_codec, replace_existing_values=replace_existing_values) | [
"def",
"load_all",
"(",
"self",
",",
"keys",
"=",
"None",
",",
"replace_existing_values",
"=",
"True",
")",
":",
"if",
"keys",
":",
"key_data_list",
"=",
"list",
"(",
"map",
"(",
"self",
".",
"_to_data",
",",
"keys",
")",
")",
"return",
"self",
".",
... | Loads all keys from the store at server side or loads the given keys if provided.
:param keys: (Collection), keys of the entry values to load (optional).
:param replace_existing_values: (bool), whether the existing values will be replaced or not with those loaded
from the server side MapLoader (optional). | [
"Loads",
"all",
"keys",
"from",
"the",
"store",
"at",
"server",
"side",
"or",
"loads",
"the",
"given",
"keys",
"if",
"provided",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L445-L457 | train | 230,833 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.put_if_absent | def put_if_absent(self, key, value, ttl=-1):
"""
Associates the specified key with the given value if it is not already associated. If ttl is provided, entry
will expire and get evicted after the ttl.
This is equivalent to:
>>> if not map.contains_key(key):
>>> return map.put(key,value)
>>> else:
>>> return map.get(key)
except that the action is performed atomically.
**Warning:
This method returns a clone of the previous value, not the original (identically equal) value previously put
into the map.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value
configured on server side configuration will be used (optional).
:return: (object), old value of the entry.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._put_if_absent_internal(key_data, value_data, ttl) | python | def put_if_absent(self, key, value, ttl=-1):
"""
Associates the specified key with the given value if it is not already associated. If ttl is provided, entry
will expire and get evicted after the ttl.
This is equivalent to:
>>> if not map.contains_key(key):
>>> return map.put(key,value)
>>> else:
>>> return map.get(key)
except that the action is performed atomically.
**Warning:
This method returns a clone of the previous value, not the original (identically equal) value previously put
into the map.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value
configured on server side configuration will be used (optional).
:return: (object), old value of the entry.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._put_if_absent_internal(key_data, value_data, ttl) | [
"def",
"put_if_absent",
"(",
"self",
",",
"key",
",",
"value",
",",
"ttl",
"=",
"-",
"1",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"check_not_none",
"(",
"value",
",",
"\"value can't be None\"",
")",
"key_data",
"=",
"self",... | Associates the specified key with the given value if it is not already associated. If ttl is provided, entry
will expire and get evicted after the ttl.
This is equivalent to:
>>> if not map.contains_key(key):
>>> return map.put(key,value)
>>> else:
>>> return map.get(key)
except that the action is performed atomically.
**Warning:
This method returns a clone of the previous value, not the original (identically equal) value previously put
into the map.**
**Warning 2: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value
configured on server side configuration will be used (optional).
:return: (object), old value of the entry. | [
"Associates",
"the",
"specified",
"key",
"with",
"the",
"given",
"value",
"if",
"it",
"is",
"not",
"already",
"associated",
".",
"If",
"ttl",
"is",
"provided",
"entry",
"will",
"expire",
"and",
"get",
"evicted",
"after",
"the",
"ttl",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L544-L574 | train | 230,834 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.remove_if_same | def remove_if_same(self, key, value):
"""
Removes the entry for a key only if it is currently mapped to a given value.
This is equivalent to:
>>> if map.contains_key(key) and map.get(key).equals(value):
>>> map.remove(key)
>>> return true
>>> else:
>>> return false
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the specified key.
:param value: (object), remove the key if it has this value.
:return: (bool), ``true`` if the value was removed.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._remove_if_same_internal_(key_data, value_data) | python | def remove_if_same(self, key, value):
"""
Removes the entry for a key only if it is currently mapped to a given value.
This is equivalent to:
>>> if map.contains_key(key) and map.get(key).equals(value):
>>> map.remove(key)
>>> return true
>>> else:
>>> return false
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the specified key.
:param value: (object), remove the key if it has this value.
:return: (bool), ``true`` if the value was removed.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._remove_if_same_internal_(key_data, value_data) | [
"def",
"remove_if_same",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"check_not_none",
"(",
"value",
",",
"\"value can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key"... | Removes the entry for a key only if it is currently mapped to a given value.
This is equivalent to:
>>> if map.contains_key(key) and map.get(key).equals(value):
>>> map.remove(key)
>>> return true
>>> else:
>>> return false
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the specified key.
:param value: (object), remove the key if it has this value.
:return: (bool), ``true`` if the value was removed. | [
"Removes",
"the",
"entry",
"for",
"a",
"key",
"only",
"if",
"it",
"is",
"currently",
"mapped",
"to",
"a",
"given",
"value",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L610-L634 | train | 230,835 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.replace | def replace(self, key, value):
"""
Replaces the entry for a key only if it is currently mapped to some value.
This is equivalent to:
>>> if map.contains_key(key):
>>> return map.put(key,value)
>>> else:
>>> return None
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
**Warning 2:
This method returns a clone of the previous value, not the original (identically equal) value previously put
into the map.**
:param key: (object), the specified key.
:param value: (object), the value to replace the previous value.
:return: (object), previous value associated with key, or ``None`` if there was no mapping for key.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._replace_internal(key_data, value_data) | python | def replace(self, key, value):
"""
Replaces the entry for a key only if it is currently mapped to some value.
This is equivalent to:
>>> if map.contains_key(key):
>>> return map.put(key,value)
>>> else:
>>> return None
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
**Warning 2:
This method returns a clone of the previous value, not the original (identically equal) value previously put
into the map.**
:param key: (object), the specified key.
:param value: (object), the value to replace the previous value.
:return: (object), previous value associated with key, or ``None`` if there was no mapping for key.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._replace_internal(key_data, value_data) | [
"def",
"replace",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"check_not_none",
"(",
"value",
",",
"\"value can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")"... | Replaces the entry for a key only if it is currently mapped to some value.
This is equivalent to:
>>> if map.contains_key(key):
>>> return map.put(key,value)
>>> else:
>>> return None
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
**Warning 2:
This method returns a clone of the previous value, not the original (identically equal) value previously put
into the map.**
:param key: (object), the specified key.
:param value: (object), the value to replace the previous value.
:return: (object), previous value associated with key, or ``None`` if there was no mapping for key. | [
"Replaces",
"the",
"entry",
"for",
"a",
"key",
"only",
"if",
"it",
"is",
"currently",
"mapped",
"to",
"some",
"value",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L646-L674 | train | 230,836 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.replace_if_same | def replace_if_same(self, key, old_value, new_value):
"""
Replaces the entry for a key only if it is currently mapped to a given value.
This is equivalent to:
>>> if map.contains_key(key) and map.get(key).equals(old_value):
>>> map.put(key, new_value)
>>> return true
>>> else:
>>> return false
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the specified key.
:param old_value: (object), replace the key value if it is the old value.
:param new_value: (object), the new value to replace the old value.
:return: (bool), ``true`` if the value was replaced.
"""
check_not_none(key, "key can't be None")
check_not_none(old_value, "old_value can't be None")
check_not_none(new_value, "new_value can't be None")
key_data = self._to_data(key)
old_value_data = self._to_data(old_value)
new_value_data = self._to_data(new_value)
return self._replace_if_same_internal(key_data, old_value_data, new_value_data) | python | def replace_if_same(self, key, old_value, new_value):
"""
Replaces the entry for a key only if it is currently mapped to a given value.
This is equivalent to:
>>> if map.contains_key(key) and map.get(key).equals(old_value):
>>> map.put(key, new_value)
>>> return true
>>> else:
>>> return false
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the specified key.
:param old_value: (object), replace the key value if it is the old value.
:param new_value: (object), the new value to replace the old value.
:return: (bool), ``true`` if the value was replaced.
"""
check_not_none(key, "key can't be None")
check_not_none(old_value, "old_value can't be None")
check_not_none(new_value, "new_value can't be None")
key_data = self._to_data(key)
old_value_data = self._to_data(old_value)
new_value_data = self._to_data(new_value)
return self._replace_if_same_internal(key_data, old_value_data, new_value_data) | [
"def",
"replace_if_same",
"(",
"self",
",",
"key",
",",
"old_value",
",",
"new_value",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"check_not_none",
"(",
"old_value",
",",
"\"old_value can't be None\"",
")",
"check_not_none",
"(",
"n... | Replaces the entry for a key only if it is currently mapped to a given value.
This is equivalent to:
>>> if map.contains_key(key) and map.get(key).equals(old_value):
>>> map.put(key, new_value)
>>> return true
>>> else:
>>> return false
except that the action is performed atomically.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), the specified key.
:param old_value: (object), replace the key value if it is the old value.
:param new_value: (object), the new value to replace the old value.
:return: (bool), ``true`` if the value was replaced. | [
"Replaces",
"the",
"entry",
"for",
"a",
"key",
"only",
"if",
"it",
"is",
"currently",
"mapped",
"to",
"a",
"given",
"value",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L676-L704 | train | 230,837 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.set | def set(self, key, value, ttl=-1):
"""
Puts an entry into this map. Similar to the put operation except that set doesn't return the old value, which is
more efficient. If ttl is provided, entry will expire and get evicted after the ttl.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param ttl: (int), maximum time in seconds for this entry to stay in the map, 0 means infinite. If ttl is not
provided, the value configured on server side configuration will be used (optional).
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._set_internal(key_data, value_data, ttl) | python | def set(self, key, value, ttl=-1):
"""
Puts an entry into this map. Similar to the put operation except that set doesn't return the old value, which is
more efficient. If ttl is provided, entry will expire and get evicted after the ttl.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param ttl: (int), maximum time in seconds for this entry to stay in the map, 0 means infinite. If ttl is not
provided, the value configured on server side configuration will be used (optional).
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._set_internal(key_data, value_data, ttl) | [
"def",
"set",
"(",
"self",
",",
"key",
",",
"value",
",",
"ttl",
"=",
"-",
"1",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"check_not_none",
"(",
"value",
",",
"\"value can't be None\"",
")",
"key_data",
"=",
"self",
".",
... | Puts an entry into this map. Similar to the put operation except that set doesn't return the old value, which is
more efficient. If ttl is provided, entry will expire and get evicted after the ttl.
**Warning: This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations
of __hash__ and __eq__ defined in key's class.**
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param ttl: (int), maximum time in seconds for this entry to stay in the map, 0 means infinite. If ttl is not
provided, the value configured on server side configuration will be used (optional). | [
"Puts",
"an",
"entry",
"into",
"this",
"map",
".",
"Similar",
"to",
"the",
"put",
"operation",
"except",
"that",
"set",
"doesn",
"t",
"return",
"the",
"old",
"value",
"which",
"is",
"more",
"efficient",
".",
"If",
"ttl",
"is",
"provided",
"entry",
"will"... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L706-L723 | train | 230,838 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.try_put | def try_put(self, key, value, timeout=0):
"""
Tries to put the given key and value into this map and returns immediately if timeout is not provided. If
timeout is provided, operation waits until it is completed or timeout is reached.
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param timeout: (int), operation timeout in seconds (optional).
:return: (bool), ``true`` if the put is successful, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._try_put_internal(key_data, value_data, timeout) | python | def try_put(self, key, value, timeout=0):
"""
Tries to put the given key and value into this map and returns immediately if timeout is not provided. If
timeout is provided, operation waits until it is completed or timeout is reached.
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param timeout: (int), operation timeout in seconds (optional).
:return: (bool), ``true`` if the put is successful, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
check_not_none(value, "value can't be None")
key_data = self._to_data(key)
value_data = self._to_data(value)
return self._try_put_internal(key_data, value_data, timeout) | [
"def",
"try_put",
"(",
"self",
",",
"key",
",",
"value",
",",
"timeout",
"=",
"0",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"check_not_none",
"(",
"value",
",",
"\"value can't be None\"",
")",
"key_data",
"=",
"self",
".",
... | Tries to put the given key and value into this map and returns immediately if timeout is not provided. If
timeout is provided, operation waits until it is completed or timeout is reached.
:param key: (object), key of the entry.
:param value: (object), value of the entry.
:param timeout: (int), operation timeout in seconds (optional).
:return: (bool), ``true`` if the put is successful, ``false`` otherwise. | [
"Tries",
"to",
"put",
"the",
"given",
"key",
"and",
"value",
"into",
"this",
"map",
"and",
"returns",
"immediately",
"if",
"timeout",
"is",
"not",
"provided",
".",
"If",
"timeout",
"is",
"provided",
"operation",
"waits",
"until",
"it",
"is",
"completed",
"... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L758-L774 | train | 230,839 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.try_remove | def try_remove(self, key, timeout=0):
"""
Tries to remove the given key from this map and returns immediately if timeout is not provided. If
timeout is provided, operation waits until it is completed or timeout is reached.
:param key: (object), key of the entry to be deleted.
:param timeout: (int), operation timeout in seconds (optional).
:return: (bool), ``true`` if the remove is successful, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._try_remove_internal(key_data, timeout) | python | def try_remove(self, key, timeout=0):
"""
Tries to remove the given key from this map and returns immediately if timeout is not provided. If
timeout is provided, operation waits until it is completed or timeout is reached.
:param key: (object), key of the entry to be deleted.
:param timeout: (int), operation timeout in seconds (optional).
:return: (bool), ``true`` if the remove is successful, ``false`` otherwise.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._try_remove_internal(key_data, timeout) | [
"def",
"try_remove",
"(",
"self",
",",
"key",
",",
"timeout",
"=",
"0",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_try_remove_internal",
"("... | Tries to remove the given key from this map and returns immediately if timeout is not provided. If
timeout is provided, operation waits until it is completed or timeout is reached.
:param key: (object), key of the entry to be deleted.
:param timeout: (int), operation timeout in seconds (optional).
:return: (bool), ``true`` if the remove is successful, ``false`` otherwise. | [
"Tries",
"to",
"remove",
"the",
"given",
"key",
"from",
"this",
"map",
"and",
"returns",
"immediately",
"if",
"timeout",
"is",
"not",
"provided",
".",
"If",
"timeout",
"is",
"provided",
"operation",
"waits",
"until",
"it",
"is",
"completed",
"or",
"timeout",... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L776-L788 | train | 230,840 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.unlock | def unlock(self, key):
"""
Releases the lock for the specified key. It never blocks and returns immediately. If the current thread is the
holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released.
:param key: (object), the key to lock.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_unlock_codec, key_data, key=key_data, thread_id=thread_id(),
reference_id=self.reference_id_generator.get_and_increment()) | python | def unlock(self, key):
"""
Releases the lock for the specified key. It never blocks and returns immediately. If the current thread is the
holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released.
:param key: (object), the key to lock.
"""
check_not_none(key, "key can't be None")
key_data = self._to_data(key)
return self._encode_invoke_on_key(map_unlock_codec, key_data, key=key_data, thread_id=thread_id(),
reference_id=self.reference_id_generator.get_and_increment()) | [
"def",
"unlock",
"(",
"self",
",",
"key",
")",
":",
"check_not_none",
"(",
"key",
",",
"\"key can't be None\"",
")",
"key_data",
"=",
"self",
".",
"_to_data",
"(",
"key",
")",
"return",
"self",
".",
"_encode_invoke_on_key",
"(",
"map_unlock_codec",
",",
"key... | Releases the lock for the specified key. It never blocks and returns immediately. If the current thread is the
holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released.
:param key: (object), the key to lock. | [
"Releases",
"the",
"lock",
"for",
"the",
"specified",
"key",
".",
"It",
"never",
"blocks",
"and",
"returns",
"immediately",
".",
"If",
"the",
"current",
"thread",
"is",
"the",
"holder",
"of",
"this",
"lock",
"then",
"the",
"hold",
"count",
"is",
"decrement... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L790-L802 | train | 230,841 |
hazelcast/hazelcast-python-client | hazelcast/proxy/map.py | Map.values | def values(self, predicate=None):
"""
Returns a list clone of the values contained in this map or values of the entries which are filtered with
the predicate if provided.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and
vice-versa.**
:param predicate: (Predicate), predicate to filter the entries (optional).
:return: (Sequence), a list of clone of the values contained in this map.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
predicate_data = self._to_data(predicate)
return self._encode_invoke(map_values_with_predicate_codec, predicate=predicate_data)
else:
return self._encode_invoke(map_values_codec) | python | def values(self, predicate=None):
"""
Returns a list clone of the values contained in this map or values of the entries which are filtered with
the predicate if provided.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and
vice-versa.**
:param predicate: (Predicate), predicate to filter the entries (optional).
:return: (Sequence), a list of clone of the values contained in this map.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
"""
if predicate:
predicate_data = self._to_data(predicate)
return self._encode_invoke(map_values_with_predicate_codec, predicate=predicate_data)
else:
return self._encode_invoke(map_values_codec) | [
"def",
"values",
"(",
"self",
",",
"predicate",
"=",
"None",
")",
":",
"if",
"predicate",
":",
"predicate_data",
"=",
"self",
".",
"_to_data",
"(",
"predicate",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"map_values_with_predicate_codec",
",",
"predica... | Returns a list clone of the values contained in this map or values of the entries which are filtered with
the predicate if provided.
**Warning:
The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and
vice-versa.**
:param predicate: (Predicate), predicate to filter the entries (optional).
:return: (Sequence), a list of clone of the values contained in this map.
.. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. | [
"Returns",
"a",
"list",
"clone",
"of",
"the",
"values",
"contained",
"in",
"this",
"map",
"or",
"values",
"of",
"the",
"entries",
"which",
"are",
"filtered",
"with",
"the",
"predicate",
"if",
"provided",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/map.py#L804-L822 | train | 230,842 |
hazelcast/hazelcast-python-client | hazelcast/transaction.py | TransactionManager.new_transaction | def new_transaction(self, timeout, durability, transaction_type):
"""
Creates a Transaction object with given timeout, durability and transaction type.
:param timeout: (long), the timeout in seconds determines the maximum lifespan of a transaction.
:param durability: (int), the durability is the number of machines that can take over if a member fails during a
transaction commit or rollback
:param transaction_type: (Transaction Type), the transaction type which can be :const:`~hazelcast.transaction.TWO_PHASE` or :const:`~hazelcast.transaction.ONE_PHASE`
:return: (:class:`~hazelcast.transaction.Transaction`), new created Transaction.
"""
connection = self._connect()
return Transaction(self._client, connection, timeout, durability, transaction_type) | python | def new_transaction(self, timeout, durability, transaction_type):
"""
Creates a Transaction object with given timeout, durability and transaction type.
:param timeout: (long), the timeout in seconds determines the maximum lifespan of a transaction.
:param durability: (int), the durability is the number of machines that can take over if a member fails during a
transaction commit or rollback
:param transaction_type: (Transaction Type), the transaction type which can be :const:`~hazelcast.transaction.TWO_PHASE` or :const:`~hazelcast.transaction.ONE_PHASE`
:return: (:class:`~hazelcast.transaction.Transaction`), new created Transaction.
"""
connection = self._connect()
return Transaction(self._client, connection, timeout, durability, transaction_type) | [
"def",
"new_transaction",
"(",
"self",
",",
"timeout",
",",
"durability",
",",
"transaction_type",
")",
":",
"connection",
"=",
"self",
".",
"_connect",
"(",
")",
"return",
"Transaction",
"(",
"self",
".",
"_client",
",",
"connection",
",",
"timeout",
",",
... | Creates a Transaction object with given timeout, durability and transaction type.
:param timeout: (long), the timeout in seconds determines the maximum lifespan of a transaction.
:param durability: (int), the durability is the number of machines that can take over if a member fails during a
transaction commit or rollback
:param transaction_type: (Transaction Type), the transaction type which can be :const:`~hazelcast.transaction.TWO_PHASE` or :const:`~hazelcast.transaction.ONE_PHASE`
:return: (:class:`~hazelcast.transaction.Transaction`), new created Transaction. | [
"Creates",
"a",
"Transaction",
"object",
"with",
"given",
"timeout",
"durability",
"and",
"transaction",
"type",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/transaction.py#L63-L74 | train | 230,843 |
hazelcast/hazelcast-python-client | hazelcast/transaction.py | Transaction.begin | def begin(self):
"""
Begins this transaction.
"""
if hasattr(self._locals, 'transaction_exists') and self._locals.transaction_exists:
raise TransactionError("Nested transactions are not allowed.")
if self.state != _STATE_NOT_STARTED:
raise TransactionError("Transaction has already been started.")
self._locals.transaction_exists = True
self.start_time = time.time()
self.thread_id = thread_id()
try:
request = transaction_create_codec.encode_request(timeout=int(self.timeout * 1000), durability=self.durability,
transaction_type=self.transaction_type,
thread_id=self.thread_id)
response = self.client.invoker.invoke_on_connection(request, self.connection).result()
self.id = transaction_create_codec.decode_response(response)["response"]
self.state = _STATE_ACTIVE
except:
self._locals.transaction_exists = False
raise | python | def begin(self):
"""
Begins this transaction.
"""
if hasattr(self._locals, 'transaction_exists') and self._locals.transaction_exists:
raise TransactionError("Nested transactions are not allowed.")
if self.state != _STATE_NOT_STARTED:
raise TransactionError("Transaction has already been started.")
self._locals.transaction_exists = True
self.start_time = time.time()
self.thread_id = thread_id()
try:
request = transaction_create_codec.encode_request(timeout=int(self.timeout * 1000), durability=self.durability,
transaction_type=self.transaction_type,
thread_id=self.thread_id)
response = self.client.invoker.invoke_on_connection(request, self.connection).result()
self.id = transaction_create_codec.decode_response(response)["response"]
self.state = _STATE_ACTIVE
except:
self._locals.transaction_exists = False
raise | [
"def",
"begin",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"_locals",
",",
"'transaction_exists'",
")",
"and",
"self",
".",
"_locals",
".",
"transaction_exists",
":",
"raise",
"TransactionError",
"(",
"\"Nested transactions are not allowed.\"",
")",... | Begins this transaction. | [
"Begins",
"this",
"transaction",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/transaction.py#L97-L117 | train | 230,844 |
hazelcast/hazelcast-python-client | hazelcast/transaction.py | Transaction.commit | def commit(self):
"""
Commits this transaction.
"""
self._check_thread()
if self.state != _STATE_ACTIVE:
raise TransactionError("Transaction is not active.")
try:
self._check_timeout()
request = transaction_commit_codec.encode_request(self.id, self.thread_id)
self.client.invoker.invoke_on_connection(request, self.connection).result()
self.state = _STATE_COMMITTED
except:
self.state = _STATE_PARTIAL_COMMIT
raise
finally:
self._locals.transaction_exists = False | python | def commit(self):
"""
Commits this transaction.
"""
self._check_thread()
if self.state != _STATE_ACTIVE:
raise TransactionError("Transaction is not active.")
try:
self._check_timeout()
request = transaction_commit_codec.encode_request(self.id, self.thread_id)
self.client.invoker.invoke_on_connection(request, self.connection).result()
self.state = _STATE_COMMITTED
except:
self.state = _STATE_PARTIAL_COMMIT
raise
finally:
self._locals.transaction_exists = False | [
"def",
"commit",
"(",
"self",
")",
":",
"self",
".",
"_check_thread",
"(",
")",
"if",
"self",
".",
"state",
"!=",
"_STATE_ACTIVE",
":",
"raise",
"TransactionError",
"(",
"\"Transaction is not active.\"",
")",
"try",
":",
"self",
".",
"_check_timeout",
"(",
"... | Commits this transaction. | [
"Commits",
"this",
"transaction",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/transaction.py#L119-L135 | train | 230,845 |
hazelcast/hazelcast-python-client | hazelcast/transaction.py | Transaction.rollback | def rollback(self):
"""
Rollback of this current transaction.
"""
self._check_thread()
if self.state not in (_STATE_ACTIVE, _STATE_PARTIAL_COMMIT):
raise TransactionError("Transaction is not active.")
try:
if self.state != _STATE_PARTIAL_COMMIT:
request = transaction_rollback_codec.encode_request(self.id, self.thread_id)
self.client.invoker.invoke_on_connection(request, self.connection).result()
self.state = _STATE_ROLLED_BACK
finally:
self._locals.transaction_exists = False | python | def rollback(self):
"""
Rollback of this current transaction.
"""
self._check_thread()
if self.state not in (_STATE_ACTIVE, _STATE_PARTIAL_COMMIT):
raise TransactionError("Transaction is not active.")
try:
if self.state != _STATE_PARTIAL_COMMIT:
request = transaction_rollback_codec.encode_request(self.id, self.thread_id)
self.client.invoker.invoke_on_connection(request, self.connection).result()
self.state = _STATE_ROLLED_BACK
finally:
self._locals.transaction_exists = False | [
"def",
"rollback",
"(",
"self",
")",
":",
"self",
".",
"_check_thread",
"(",
")",
"if",
"self",
".",
"state",
"not",
"in",
"(",
"_STATE_ACTIVE",
",",
"_STATE_PARTIAL_COMMIT",
")",
":",
"raise",
"TransactionError",
"(",
"\"Transaction is not active.\"",
")",
"t... | Rollback of this current transaction. | [
"Rollback",
"of",
"this",
"current",
"transaction",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/transaction.py#L137-L150 | train | 230,846 |
hazelcast/hazelcast-python-client | hazelcast/discovery.py | HazelcastCloudAddressProvider.load_addresses | def load_addresses(self):
"""
Loads member addresses from Hazelcast.cloud endpoint.
:return: (Sequence), The possible member addresses to connect to.
"""
try:
return list(self.cloud_discovery.discover_nodes().keys())
except Exception as ex:
self.logger.warning("Failed to load addresses from Hazelcast.cloud: {}".format(ex.args[0]),
extra=self._logger_extras)
return [] | python | def load_addresses(self):
"""
Loads member addresses from Hazelcast.cloud endpoint.
:return: (Sequence), The possible member addresses to connect to.
"""
try:
return list(self.cloud_discovery.discover_nodes().keys())
except Exception as ex:
self.logger.warning("Failed to load addresses from Hazelcast.cloud: {}".format(ex.args[0]),
extra=self._logger_extras)
return [] | [
"def",
"load_addresses",
"(",
"self",
")",
":",
"try",
":",
"return",
"list",
"(",
"self",
".",
"cloud_discovery",
".",
"discover_nodes",
"(",
")",
".",
"keys",
"(",
")",
")",
"except",
"Exception",
"as",
"ex",
":",
"self",
".",
"logger",
".",
"warning... | Loads member addresses from Hazelcast.cloud endpoint.
:return: (Sequence), The possible member addresses to connect to. | [
"Loads",
"member",
"addresses",
"from",
"Hazelcast",
".",
"cloud",
"endpoint",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/discovery.py#L27-L38 | train | 230,847 |
hazelcast/hazelcast-python-client | hazelcast/discovery.py | HazelcastCloudAddressTranslator.translate | def translate(self, address):
"""
Translates the given address to another address specific to network or service.
:param address: (:class:`~hazelcast.core.Address`), private address to be translated
:return: (:class:`~hazelcast.core.Address`), new address if given address is known, otherwise returns null
"""
if address is None:
return None
public_address = self._private_to_public.get(address)
if public_address:
return public_address
self.refresh()
return self._private_to_public.get(address) | python | def translate(self, address):
"""
Translates the given address to another address specific to network or service.
:param address: (:class:`~hazelcast.core.Address`), private address to be translated
:return: (:class:`~hazelcast.core.Address`), new address if given address is known, otherwise returns null
"""
if address is None:
return None
public_address = self._private_to_public.get(address)
if public_address:
return public_address
self.refresh()
return self._private_to_public.get(address) | [
"def",
"translate",
"(",
"self",
",",
"address",
")",
":",
"if",
"address",
"is",
"None",
":",
"return",
"None",
"public_address",
"=",
"self",
".",
"_private_to_public",
".",
"get",
"(",
"address",
")",
"if",
"public_address",
":",
"return",
"public_address... | Translates the given address to another address specific to network or service.
:param address: (:class:`~hazelcast.core.Address`), private address to be translated
:return: (:class:`~hazelcast.core.Address`), new address if given address is known, otherwise returns null | [
"Translates",
"the",
"given",
"address",
"to",
"another",
"address",
"specific",
"to",
"network",
"or",
"service",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/discovery.py#L53-L69 | train | 230,848 |
hazelcast/hazelcast-python-client | hazelcast/discovery.py | HazelcastCloudAddressTranslator.refresh | def refresh(self):
"""
Refreshes the internal lookup table if necessary.
"""
try:
self._private_to_public = self.cloud_discovery.discover_nodes()
except Exception as ex:
self.logger.warning("Failed to load addresses from Hazelcast.cloud: {}".format(ex.args[0]),
extra=self._logger_extras) | python | def refresh(self):
"""
Refreshes the internal lookup table if necessary.
"""
try:
self._private_to_public = self.cloud_discovery.discover_nodes()
except Exception as ex:
self.logger.warning("Failed to load addresses from Hazelcast.cloud: {}".format(ex.args[0]),
extra=self._logger_extras) | [
"def",
"refresh",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_private_to_public",
"=",
"self",
".",
"cloud_discovery",
".",
"discover_nodes",
"(",
")",
"except",
"Exception",
"as",
"ex",
":",
"self",
".",
"logger",
".",
"warning",
"(",
"\"Failed to l... | Refreshes the internal lookup table if necessary. | [
"Refreshes",
"the",
"internal",
"lookup",
"table",
"if",
"necessary",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/discovery.py#L71-L79 | train | 230,849 |
hazelcast/hazelcast-python-client | hazelcast/discovery.py | HazelcastCloudDiscovery.get_host_and_url | def get_host_and_url(properties, cloud_token):
"""
Helper method to get host and url that can be used in HTTPSConnection.
:param properties: Client config properties.
:param cloud_token: Cloud discovery token.
:return: Host and URL pair
"""
host = properties.get(HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.name,
HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.default_value)
host = host.replace("https://", "")
host = host.replace("http://", "")
return host, HazelcastCloudDiscovery._CLOUD_URL_PATH + cloud_token | python | def get_host_and_url(properties, cloud_token):
"""
Helper method to get host and url that can be used in HTTPSConnection.
:param properties: Client config properties.
:param cloud_token: Cloud discovery token.
:return: Host and URL pair
"""
host = properties.get(HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.name,
HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.default_value)
host = host.replace("https://", "")
host = host.replace("http://", "")
return host, HazelcastCloudDiscovery._CLOUD_URL_PATH + cloud_token | [
"def",
"get_host_and_url",
"(",
"properties",
",",
"cloud_token",
")",
":",
"host",
"=",
"properties",
".",
"get",
"(",
"HazelcastCloudDiscovery",
".",
"CLOUD_URL_BASE_PROPERTY",
".",
"name",
",",
"HazelcastCloudDiscovery",
".",
"CLOUD_URL_BASE_PROPERTY",
".",
"defaul... | Helper method to get host and url that can be used in HTTPSConnection.
:param properties: Client config properties.
:param cloud_token: Cloud discovery token.
:return: Host and URL pair | [
"Helper",
"method",
"to",
"get",
"host",
"and",
"url",
"that",
"can",
"be",
"used",
"in",
"HTTPSConnection",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/discovery.py#L146-L158 | train | 230,850 |
hazelcast/hazelcast-python-client | hazelcast/proxy/count_down_latch.py | CountDownLatch.try_set_count | def try_set_count(self, count):
"""
Sets the count to the given value if the current count is zero. If count is not zero, this method does nothing
and returns ``false``.
:param count: (int), the number of times count_down() must be invoked before threads can pass through await().
:return: (bool), ``true`` if the new count was set, ``false`` if the current count is not zero.
"""
check_not_negative(count, "count can't be negative")
return self._encode_invoke(count_down_latch_try_set_count_codec, count=count) | python | def try_set_count(self, count):
"""
Sets the count to the given value if the current count is zero. If count is not zero, this method does nothing
and returns ``false``.
:param count: (int), the number of times count_down() must be invoked before threads can pass through await().
:return: (bool), ``true`` if the new count was set, ``false`` if the current count is not zero.
"""
check_not_negative(count, "count can't be negative")
return self._encode_invoke(count_down_latch_try_set_count_codec, count=count) | [
"def",
"try_set_count",
"(",
"self",
",",
"count",
")",
":",
"check_not_negative",
"(",
"count",
",",
"\"count can't be negative\"",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"count_down_latch_try_set_count_codec",
",",
"count",
"=",
"count",
")"
] | Sets the count to the given value if the current count is zero. If count is not zero, this method does nothing
and returns ``false``.
:param count: (int), the number of times count_down() must be invoked before threads can pass through await().
:return: (bool), ``true`` if the new count was set, ``false`` if the current count is not zero. | [
"Sets",
"the",
"count",
"to",
"the",
"given",
"value",
"if",
"the",
"current",
"count",
"is",
"zero",
".",
"If",
"count",
"is",
"not",
"zero",
"this",
"method",
"does",
"nothing",
"and",
"returns",
"false",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/count_down_latch.py#L65-L74 | train | 230,851 |
hazelcast/hazelcast-python-client | hazelcast/proxy/base.py | Proxy.destroy | def destroy(self):
"""
Destroys this proxy.
:return: (bool), ``true`` if this proxy is deleted successfully, ``false`` otherwise.
"""
self._on_destroy()
return self._client.proxy.destroy_proxy(self.service_name, self.name) | python | def destroy(self):
"""
Destroys this proxy.
:return: (bool), ``true`` if this proxy is deleted successfully, ``false`` otherwise.
"""
self._on_destroy()
return self._client.proxy.destroy_proxy(self.service_name, self.name) | [
"def",
"destroy",
"(",
"self",
")",
":",
"self",
".",
"_on_destroy",
"(",
")",
"return",
"self",
".",
"_client",
".",
"proxy",
".",
"destroy_proxy",
"(",
"self",
".",
"service_name",
",",
"self",
".",
"name",
")"
] | Destroys this proxy.
:return: (bool), ``true`` if this proxy is deleted successfully, ``false`` otherwise. | [
"Destroys",
"this",
"proxy",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/base.py#L40-L47 | train | 230,852 |
hazelcast/hazelcast-python-client | hazelcast/cluster.py | ClusterService.add_listener | def add_listener(self, member_added=None, member_removed=None, fire_for_existing=False):
"""
Adds a membership listener to listen for membership updates, it will be notified when a member is added to
cluster or removed from cluster. There is no check for duplicate registrations, so if you register the listener
twice, it will get events twice.
:param member_added: (Function), function to be called when a member is added to the cluster (optional).
:param member_removed: (Function), function to be called when a member is removed to the cluster (optional).
:param fire_for_existing: (bool), (optional).
:return: (str), registration id of the listener which will be used for removing this listener.
"""
registration_id = str(uuid.uuid4())
self.listeners[registration_id] = (member_added, member_removed)
if fire_for_existing:
for member in self.get_member_list():
member_added(member)
return registration_id | python | def add_listener(self, member_added=None, member_removed=None, fire_for_existing=False):
"""
Adds a membership listener to listen for membership updates, it will be notified when a member is added to
cluster or removed from cluster. There is no check for duplicate registrations, so if you register the listener
twice, it will get events twice.
:param member_added: (Function), function to be called when a member is added to the cluster (optional).
:param member_removed: (Function), function to be called when a member is removed to the cluster (optional).
:param fire_for_existing: (bool), (optional).
:return: (str), registration id of the listener which will be used for removing this listener.
"""
registration_id = str(uuid.uuid4())
self.listeners[registration_id] = (member_added, member_removed)
if fire_for_existing:
for member in self.get_member_list():
member_added(member)
return registration_id | [
"def",
"add_listener",
"(",
"self",
",",
"member_added",
"=",
"None",
",",
"member_removed",
"=",
"None",
",",
"fire_for_existing",
"=",
"False",
")",
":",
"registration_id",
"=",
"str",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
"self",
".",
"listeners",
... | Adds a membership listener to listen for membership updates, it will be notified when a member is added to
cluster or removed from cluster. There is no check for duplicate registrations, so if you register the listener
twice, it will get events twice.
:param member_added: (Function), function to be called when a member is added to the cluster (optional).
:param member_removed: (Function), function to be called when a member is removed to the cluster (optional).
:param fire_for_existing: (bool), (optional).
:return: (str), registration id of the listener which will be used for removing this listener. | [
"Adds",
"a",
"membership",
"listener",
"to",
"listen",
"for",
"membership",
"updates",
"it",
"will",
"be",
"notified",
"when",
"a",
"member",
"is",
"added",
"to",
"cluster",
"or",
"removed",
"from",
"cluster",
".",
"There",
"is",
"no",
"check",
"for",
"dup... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L63-L82 | train | 230,853 |
hazelcast/hazelcast-python-client | hazelcast/cluster.py | ClusterService.remove_listener | def remove_listener(self, registration_id):
"""
Removes the specified membership listener.
:param registration_id: (str), registration id of the listener to be deleted.
:return: (bool), if the registration is removed, ``false`` otherwise.
"""
try:
self.listeners.pop(registration_id)
return True
except KeyError:
return False | python | def remove_listener(self, registration_id):
"""
Removes the specified membership listener.
:param registration_id: (str), registration id of the listener to be deleted.
:return: (bool), if the registration is removed, ``false`` otherwise.
"""
try:
self.listeners.pop(registration_id)
return True
except KeyError:
return False | [
"def",
"remove_listener",
"(",
"self",
",",
"registration_id",
")",
":",
"try",
":",
"self",
".",
"listeners",
".",
"pop",
"(",
"registration_id",
")",
"return",
"True",
"except",
"KeyError",
":",
"return",
"False"
] | Removes the specified membership listener.
:param registration_id: (str), registration id of the listener to be deleted.
:return: (bool), if the registration is removed, ``false`` otherwise. | [
"Removes",
"the",
"specified",
"membership",
"listener",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L84-L95 | train | 230,854 |
hazelcast/hazelcast-python-client | hazelcast/cluster.py | ClusterService.get_member_by_uuid | def get_member_by_uuid(self, member_uuid):
"""
Returns the member with specified member uuid.
:param member_uuid: (int), uuid of the desired member.
:return: (:class:`~hazelcast.core.Member`), the corresponding member.
"""
for member in self.get_member_list():
if member.uuid == member_uuid:
return member | python | def get_member_by_uuid(self, member_uuid):
"""
Returns the member with specified member uuid.
:param member_uuid: (int), uuid of the desired member.
:return: (:class:`~hazelcast.core.Member`), the corresponding member.
"""
for member in self.get_member_list():
if member.uuid == member_uuid:
return member | [
"def",
"get_member_by_uuid",
"(",
"self",
",",
"member_uuid",
")",
":",
"for",
"member",
"in",
"self",
".",
"get_member_list",
"(",
")",
":",
"if",
"member",
".",
"uuid",
"==",
"member_uuid",
":",
"return",
"member"
] | Returns the member with specified member uuid.
:param member_uuid: (int), uuid of the desired member.
:return: (:class:`~hazelcast.core.Member`), the corresponding member. | [
"Returns",
"the",
"member",
"with",
"specified",
"member",
"uuid",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L256-L265 | train | 230,855 |
hazelcast/hazelcast-python-client | hazelcast/cluster.py | ClusterService.get_members | def get_members(self, selector):
"""
Returns the members that satisfy the given selector.
:param selector: (:class:`~hazelcast.core.MemberSelector`), Selector to be applied to the members.
:return: (List), List of members.
"""
members = []
for member in self.get_member_list():
if selector.select(member):
members.append(member)
return members | python | def get_members(self, selector):
"""
Returns the members that satisfy the given selector.
:param selector: (:class:`~hazelcast.core.MemberSelector`), Selector to be applied to the members.
:return: (List), List of members.
"""
members = []
for member in self.get_member_list():
if selector.select(member):
members.append(member)
return members | [
"def",
"get_members",
"(",
"self",
",",
"selector",
")",
":",
"members",
"=",
"[",
"]",
"for",
"member",
"in",
"self",
".",
"get_member_list",
"(",
")",
":",
"if",
"selector",
".",
"select",
"(",
"member",
")",
":",
"members",
".",
"append",
"(",
"me... | Returns the members that satisfy the given selector.
:param selector: (:class:`~hazelcast.core.MemberSelector`), Selector to be applied to the members.
:return: (List), List of members. | [
"Returns",
"the",
"members",
"that",
"satisfy",
"the",
"given",
"selector",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L277-L289 | train | 230,856 |
hazelcast/hazelcast-python-client | hazelcast/cluster.py | VectorClock.is_after | def is_after(self, other):
"""
Returns true if this vector clock is causally strictly after the
provided vector clock. This means that it the provided clock is neither
equal to, greater than or concurrent to this vector clock.
:param other: (:class:`~hazelcast.cluster.VectorClock`), Vector clock to be compared
:return: (bool), True if this vector clock is strictly after the other vector clock, False otherwise
"""
any_timestamp_greater = False
for replica_id, other_timestamp in other.entry_set():
local_timestamp = self._replica_timestamps.get(replica_id)
if local_timestamp is None or local_timestamp < other_timestamp:
return False
elif local_timestamp > other_timestamp:
any_timestamp_greater = True
# there is at least one local timestamp greater or local vector clock has additional timestamps
return any_timestamp_greater or other.size() < self.size() | python | def is_after(self, other):
"""
Returns true if this vector clock is causally strictly after the
provided vector clock. This means that it the provided clock is neither
equal to, greater than or concurrent to this vector clock.
:param other: (:class:`~hazelcast.cluster.VectorClock`), Vector clock to be compared
:return: (bool), True if this vector clock is strictly after the other vector clock, False otherwise
"""
any_timestamp_greater = False
for replica_id, other_timestamp in other.entry_set():
local_timestamp = self._replica_timestamps.get(replica_id)
if local_timestamp is None or local_timestamp < other_timestamp:
return False
elif local_timestamp > other_timestamp:
any_timestamp_greater = True
# there is at least one local timestamp greater or local vector clock has additional timestamps
return any_timestamp_greater or other.size() < self.size() | [
"def",
"is_after",
"(",
"self",
",",
"other",
")",
":",
"any_timestamp_greater",
"=",
"False",
"for",
"replica_id",
",",
"other_timestamp",
"in",
"other",
".",
"entry_set",
"(",
")",
":",
"local_timestamp",
"=",
"self",
".",
"_replica_timestamps",
".",
"get",
... | Returns true if this vector clock is causally strictly after the
provided vector clock. This means that it the provided clock is neither
equal to, greater than or concurrent to this vector clock.
:param other: (:class:`~hazelcast.cluster.VectorClock`), Vector clock to be compared
:return: (bool), True if this vector clock is strictly after the other vector clock, False otherwise | [
"Returns",
"true",
"if",
"this",
"vector",
"clock",
"is",
"causally",
"strictly",
"after",
"the",
"provided",
"vector",
"clock",
".",
"This",
"means",
"that",
"it",
"the",
"provided",
"clock",
"is",
"neither",
"equal",
"to",
"greater",
"than",
"or",
"concurr... | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/cluster.py#L329-L348 | train | 230,857 |
hazelcast/hazelcast-python-client | hazelcast/proxy/set.py | Set.contains | def contains(self, item):
"""
Determines whether this set contains the specified item or not.
:param item: (object), the specified item to be searched.
:return: (bool), ``true`` if the specified item exists in this set, ``false`` otherwise.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(set_contains_codec, value=item_data) | python | def contains(self, item):
"""
Determines whether this set contains the specified item or not.
:param item: (object), the specified item to be searched.
:return: (bool), ``true`` if the specified item exists in this set, ``false`` otherwise.
"""
check_not_none(item, "Value can't be None")
item_data = self._to_data(item)
return self._encode_invoke(set_contains_codec, value=item_data) | [
"def",
"contains",
"(",
"self",
",",
"item",
")",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",
"item_data",
"=",
"self",
".",
"_to_data",
"(",
"item",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"set_contains_codec",
",",
"... | Determines whether this set contains the specified item or not.
:param item: (object), the specified item to be searched.
:return: (bool), ``true`` if the specified item exists in this set, ``false`` otherwise. | [
"Determines",
"whether",
"this",
"set",
"contains",
"the",
"specified",
"item",
"or",
"not",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/set.py#L83-L92 | train | 230,858 |
hazelcast/hazelcast-python-client | hazelcast/proxy/set.py | Set.contains_all | def contains_all(self, items):
"""
Determines whether this set contains all of the items in the specified collection or not.
:param items: (Collection), the specified collection which includes the items to be searched.
:return: (bool), ``true`` if all of the items in the specified collection exist in this set, ``false`` otherwise.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(set_contains_all_codec, items=data_items) | python | def contains_all(self, items):
"""
Determines whether this set contains all of the items in the specified collection or not.
:param items: (Collection), the specified collection which includes the items to be searched.
:return: (bool), ``true`` if all of the items in the specified collection exist in this set, ``false`` otherwise.
"""
check_not_none(items, "Value can't be None")
data_items = []
for item in items:
check_not_none(item, "Value can't be None")
data_items.append(self._to_data(item))
return self._encode_invoke(set_contains_all_codec, items=data_items) | [
"def",
"contains_all",
"(",
"self",
",",
"items",
")",
":",
"check_not_none",
"(",
"items",
",",
"\"Value can't be None\"",
")",
"data_items",
"=",
"[",
"]",
"for",
"item",
"in",
"items",
":",
"check_not_none",
"(",
"item",
",",
"\"Value can't be None\"",
")",... | Determines whether this set contains all of the items in the specified collection or not.
:param items: (Collection), the specified collection which includes the items to be searched.
:return: (bool), ``true`` if all of the items in the specified collection exist in this set, ``false`` otherwise. | [
"Determines",
"whether",
"this",
"set",
"contains",
"all",
"of",
"the",
"items",
"in",
"the",
"specified",
"collection",
"or",
"not",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/set.py#L94-L106 | train | 230,859 |
hazelcast/hazelcast-python-client | hazelcast/proxy/atomic_long.py | AtomicLong.alter | def alter(self, function):
"""
Alters the currently stored value by applying a function on it.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
"""
check_not_none(function, "function can't be None")
return self._encode_invoke(atomic_long_alter_codec, function=self._to_data(function)) | python | def alter(self, function):
"""
Alters the currently stored value by applying a function on it.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
"""
check_not_none(function, "function can't be None")
return self._encode_invoke(atomic_long_alter_codec, function=self._to_data(function)) | [
"def",
"alter",
"(",
"self",
",",
"function",
")",
":",
"check_not_none",
"(",
"function",
",",
"\"function can't be None\"",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"atomic_long_alter_codec",
",",
"function",
"=",
"self",
".",
"_to_data",
"(",
"funct... | Alters the currently stored value by applying a function on it.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation. | [
"Alters",
"the",
"currently",
"stored",
"value",
"by",
"applying",
"a",
"function",
"on",
"it",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/atomic_long.py#L22-L32 | train | 230,860 |
hazelcast/hazelcast-python-client | hazelcast/proxy/atomic_long.py | AtomicLong.alter_and_get | def alter_and_get(self, function):
"""
Alters the currently stored value by applying a function on it and gets the result.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
:return: (long), the new value.
"""
check_not_none(function, "function can't be None")
return self._encode_invoke(atomic_long_alter_and_get_codec, function=self._to_data(function)) | python | def alter_and_get(self, function):
"""
Alters the currently stored value by applying a function on it and gets the result.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
:return: (long), the new value.
"""
check_not_none(function, "function can't be None")
return self._encode_invoke(atomic_long_alter_and_get_codec, function=self._to_data(function)) | [
"def",
"alter_and_get",
"(",
"self",
",",
"function",
")",
":",
"check_not_none",
"(",
"function",
",",
"\"function can't be None\"",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"atomic_long_alter_and_get_codec",
",",
"function",
"=",
"self",
".",
"_to_data",... | Alters the currently stored value by applying a function on it and gets the result.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
:return: (long), the new value. | [
"Alters",
"the",
"currently",
"stored",
"value",
"by",
"applying",
"a",
"function",
"on",
"it",
"and",
"gets",
"the",
"result",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/atomic_long.py#L34-L45 | train | 230,861 |
hazelcast/hazelcast-python-client | hazelcast/proxy/atomic_long.py | AtomicLong.get_and_alter | def get_and_alter(self, function):
"""
Alters the currently stored value by applying a function on it on and gets the old value.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
:return: (long), the old value.
"""
check_not_none(function, "function can't be None")
return self._encode_invoke(atomic_long_get_and_alter_codec, function=self._to_data(function)) | python | def get_and_alter(self, function):
"""
Alters the currently stored value by applying a function on it on and gets the old value.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
:return: (long), the old value.
"""
check_not_none(function, "function can't be None")
return self._encode_invoke(atomic_long_get_and_alter_codec, function=self._to_data(function)) | [
"def",
"get_and_alter",
"(",
"self",
",",
"function",
")",
":",
"check_not_none",
"(",
"function",
",",
"\"function can't be None\"",
")",
"return",
"self",
".",
"_encode_invoke",
"(",
"atomic_long_get_and_alter_codec",
",",
"function",
"=",
"self",
".",
"_to_data",... | Alters the currently stored value by applying a function on it on and gets the old value.
:param function: (Function), A stateful serializable object which represents the Function defined on
server side.
This object must have a serializable Function counter part registered on server side with the actual
``org.hazelcast.core.IFunction`` implementation.
:return: (long), the old value. | [
"Alters",
"the",
"currently",
"stored",
"value",
"by",
"applying",
"a",
"function",
"on",
"it",
"on",
"and",
"gets",
"the",
"old",
"value",
"."
] | 3f6639443c23d6d036aa343f8e094f052250d2c1 | https://github.com/hazelcast/hazelcast-python-client/blob/3f6639443c23d6d036aa343f8e094f052250d2c1/hazelcast/proxy/atomic_long.py#L96-L107 | train | 230,862 |
square/pylink | examples/core.py | main | def main(jlink_serial, device):
"""Prints the core's information.
Args:
jlink_serial (str): the J-Link serial number
device (str): the target CPU
Returns:
Always returns ``0``.
Raises:
JLinkException: on error
"""
buf = StringIO.StringIO()
jlink = pylink.JLink(log=buf.write, detailed_log=buf.write)
jlink.open(serial_no=jlink_serial)
# Use Serial Wire Debug as the target interface.
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
jlink.connect(device, verbose=True)
sys.stdout.write('ARM Id: %d\n' % jlink.core_id())
sys.stdout.write('CPU Id: %d\n' % jlink.core_cpu())
sys.stdout.write('Core Name: %s\n' % jlink.core_name())
sys.stdout.write('Device Family: %d\n' % jlink.device_family()) | python | def main(jlink_serial, device):
"""Prints the core's information.
Args:
jlink_serial (str): the J-Link serial number
device (str): the target CPU
Returns:
Always returns ``0``.
Raises:
JLinkException: on error
"""
buf = StringIO.StringIO()
jlink = pylink.JLink(log=buf.write, detailed_log=buf.write)
jlink.open(serial_no=jlink_serial)
# Use Serial Wire Debug as the target interface.
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
jlink.connect(device, verbose=True)
sys.stdout.write('ARM Id: %d\n' % jlink.core_id())
sys.stdout.write('CPU Id: %d\n' % jlink.core_cpu())
sys.stdout.write('Core Name: %s\n' % jlink.core_name())
sys.stdout.write('Device Family: %d\n' % jlink.device_family()) | [
"def",
"main",
"(",
"jlink_serial",
",",
"device",
")",
":",
"buf",
"=",
"StringIO",
".",
"StringIO",
"(",
")",
"jlink",
"=",
"pylink",
".",
"JLink",
"(",
"log",
"=",
"buf",
".",
"write",
",",
"detailed_log",
"=",
"buf",
".",
"write",
")",
"jlink",
... | Prints the core's information.
Args:
jlink_serial (str): the J-Link serial number
device (str): the target CPU
Returns:
Always returns ``0``.
Raises:
JLinkException: on error | [
"Prints",
"the",
"core",
"s",
"information",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/examples/core.py#L35-L59 | train | 230,863 |
square/pylink | pylink/jlock.py | JLock.acquire | def acquire(self):
"""Attempts to acquire a lock for the J-Link lockfile.
If the lockfile exists but does not correspond to an active process,
the lockfile is first removed, before an attempt is made to acquire it.
Args:
self (Jlock): the ``JLock`` instance
Returns:
``True`` if the lock was acquired, otherwise ``False``.
Raises:
OSError: on file errors.
"""
if os.path.exists(self.path):
try:
pid = None
with open(self.path, 'r') as f:
line = f.readline().strip()
pid = int(line)
# In the case that the lockfile exists, but the pid does not
# correspond to a valid process, remove the file.
if not psutil.pid_exists(pid):
os.remove(self.path)
except ValueError as e:
# Pidfile is invalid, so just delete it.
os.remove(self.path)
except IOError as e:
# Something happened while trying to read/remove the file, so
# skip trying to read/remove it.
pass
try:
self.fd = os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
# PID is written to the file, so that if a process exits wtihout
# cleaning up the lockfile, we can still acquire the lock.
to_write = '%s%s' % (os.getpid(), os.linesep)
os.write(self.fd, to_write.encode())
except OSError as e:
if not os.path.exists(self.path):
raise
return False
self.acquired = True
return True | python | def acquire(self):
"""Attempts to acquire a lock for the J-Link lockfile.
If the lockfile exists but does not correspond to an active process,
the lockfile is first removed, before an attempt is made to acquire it.
Args:
self (Jlock): the ``JLock`` instance
Returns:
``True`` if the lock was acquired, otherwise ``False``.
Raises:
OSError: on file errors.
"""
if os.path.exists(self.path):
try:
pid = None
with open(self.path, 'r') as f:
line = f.readline().strip()
pid = int(line)
# In the case that the lockfile exists, but the pid does not
# correspond to a valid process, remove the file.
if not psutil.pid_exists(pid):
os.remove(self.path)
except ValueError as e:
# Pidfile is invalid, so just delete it.
os.remove(self.path)
except IOError as e:
# Something happened while trying to read/remove the file, so
# skip trying to read/remove it.
pass
try:
self.fd = os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
# PID is written to the file, so that if a process exits wtihout
# cleaning up the lockfile, we can still acquire the lock.
to_write = '%s%s' % (os.getpid(), os.linesep)
os.write(self.fd, to_write.encode())
except OSError as e:
if not os.path.exists(self.path):
raise
return False
self.acquired = True
return True | [
"def",
"acquire",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"path",
")",
":",
"try",
":",
"pid",
"=",
"None",
"with",
"open",
"(",
"self",
".",
"path",
",",
"'r'",
")",
"as",
"f",
":",
"line",
"=",
"f",
... | Attempts to acquire a lock for the J-Link lockfile.
If the lockfile exists but does not correspond to an active process,
the lockfile is first removed, before an attempt is made to acquire it.
Args:
self (Jlock): the ``JLock`` instance
Returns:
``True`` if the lock was acquired, otherwise ``False``.
Raises:
OSError: on file errors. | [
"Attempts",
"to",
"acquire",
"a",
"lock",
"for",
"the",
"J",
"-",
"Link",
"lockfile",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlock.py#L81-L132 | train | 230,864 |
square/pylink | pylink/jlock.py | JLock.release | def release(self):
"""Cleans up the lockfile if it was acquired.
Args:
self (JLock): the ``JLock`` instance
Returns:
``False`` if the lock was not released or the lock is not acquired,
otherwise ``True``.
"""
if not self.acquired:
return False
os.close(self.fd)
if os.path.exists(self.path):
os.remove(self.path)
self.acquired = False
return True | python | def release(self):
"""Cleans up the lockfile if it was acquired.
Args:
self (JLock): the ``JLock`` instance
Returns:
``False`` if the lock was not released or the lock is not acquired,
otherwise ``True``.
"""
if not self.acquired:
return False
os.close(self.fd)
if os.path.exists(self.path):
os.remove(self.path)
self.acquired = False
return True | [
"def",
"release",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"acquired",
":",
"return",
"False",
"os",
".",
"close",
"(",
"self",
".",
"fd",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"path",
")",
":",
"os",
".",
"remo... | Cleans up the lockfile if it was acquired.
Args:
self (JLock): the ``JLock`` instance
Returns:
``False`` if the lock was not released or the lock is not acquired,
otherwise ``True``. | [
"Cleans",
"up",
"the",
"lockfile",
"if",
"it",
"was",
"acquired",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlock.py#L134-L153 | train | 230,865 |
square/pylink | pylink/util.py | calculate_parity | def calculate_parity(n):
"""Calculates and returns the parity of a number.
The parity of a number is ``1`` if the number has an odd number of ones
in its binary representation, otherwise ``0``.
Args:
n (int): the number whose parity to calculate
Returns:
``1`` if the number has an odd number of ones, otherwise ``0``.
Raises:
ValueError: if ``n`` is less than ``0``.
"""
if not is_natural(n):
raise ValueError('Expected n to be a positive integer.')
y = 0
n = abs(n)
while n:
y += n & 1
n = n >> 1
return y & 1 | python | def calculate_parity(n):
"""Calculates and returns the parity of a number.
The parity of a number is ``1`` if the number has an odd number of ones
in its binary representation, otherwise ``0``.
Args:
n (int): the number whose parity to calculate
Returns:
``1`` if the number has an odd number of ones, otherwise ``0``.
Raises:
ValueError: if ``n`` is less than ``0``.
"""
if not is_natural(n):
raise ValueError('Expected n to be a positive integer.')
y = 0
n = abs(n)
while n:
y += n & 1
n = n >> 1
return y & 1 | [
"def",
"calculate_parity",
"(",
"n",
")",
":",
"if",
"not",
"is_natural",
"(",
"n",
")",
":",
"raise",
"ValueError",
"(",
"'Expected n to be a positive integer.'",
")",
"y",
"=",
"0",
"n",
"=",
"abs",
"(",
"n",
")",
"while",
"n",
":",
"y",
"+=",
"n",
... | Calculates and returns the parity of a number.
The parity of a number is ``1`` if the number has an odd number of ones
in its binary representation, otherwise ``0``.
Args:
n (int): the number whose parity to calculate
Returns:
``1`` if the number has an odd number of ones, otherwise ``0``.
Raises:
ValueError: if ``n`` is less than ``0``. | [
"Calculates",
"and",
"returns",
"the",
"parity",
"of",
"a",
"number",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/util.py#L159-L182 | train | 230,866 |
square/pylink | pylink/binpacker.py | pack | def pack(value, nbits=None):
"""Packs a given value into an array of 8-bit unsigned integers.
If ``nbits`` is not present, calculates the minimal number of bits required
to represent the given ``value``. The result is little endian.
Args:
value (int): the integer value to pack
nbits (int): optional number of bits to use to represent the value
Returns:
An array of ``ctypes.c_uint8`` representing the packed ``value``.
Raises:
ValueError: if ``value < 0`` and ``nbits`` is ``None`` or ``nbits <= 0``.
TypeError: if ``nbits`` or ``value`` are not numbers.
"""
if nbits is None:
nbits = pack_size(value) * BITS_PER_BYTE
elif nbits <= 0:
raise ValueError('Given number of bits must be greater than 0.')
buf_size = int(math.ceil(nbits / float(BITS_PER_BYTE)))
buf = (ctypes.c_uint8 * buf_size)()
for (idx, _) in enumerate(buf):
buf[idx] = (value >> (idx * BITS_PER_BYTE)) & 0xFF
return buf | python | def pack(value, nbits=None):
"""Packs a given value into an array of 8-bit unsigned integers.
If ``nbits`` is not present, calculates the minimal number of bits required
to represent the given ``value``. The result is little endian.
Args:
value (int): the integer value to pack
nbits (int): optional number of bits to use to represent the value
Returns:
An array of ``ctypes.c_uint8`` representing the packed ``value``.
Raises:
ValueError: if ``value < 0`` and ``nbits`` is ``None`` or ``nbits <= 0``.
TypeError: if ``nbits`` or ``value`` are not numbers.
"""
if nbits is None:
nbits = pack_size(value) * BITS_PER_BYTE
elif nbits <= 0:
raise ValueError('Given number of bits must be greater than 0.')
buf_size = int(math.ceil(nbits / float(BITS_PER_BYTE)))
buf = (ctypes.c_uint8 * buf_size)()
for (idx, _) in enumerate(buf):
buf[idx] = (value >> (idx * BITS_PER_BYTE)) & 0xFF
return buf | [
"def",
"pack",
"(",
"value",
",",
"nbits",
"=",
"None",
")",
":",
"if",
"nbits",
"is",
"None",
":",
"nbits",
"=",
"pack_size",
"(",
"value",
")",
"*",
"BITS_PER_BYTE",
"elif",
"nbits",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"'Given number of bits mu... | Packs a given value into an array of 8-bit unsigned integers.
If ``nbits`` is not present, calculates the minimal number of bits required
to represent the given ``value``. The result is little endian.
Args:
value (int): the integer value to pack
nbits (int): optional number of bits to use to represent the value
Returns:
An array of ``ctypes.c_uint8`` representing the packed ``value``.
Raises:
ValueError: if ``value < 0`` and ``nbits`` is ``None`` or ``nbits <= 0``.
TypeError: if ``nbits`` or ``value`` are not numbers. | [
"Packs",
"a",
"given",
"value",
"into",
"an",
"array",
"of",
"8",
"-",
"bit",
"unsigned",
"integers",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/binpacker.py#L42-L70 | train | 230,867 |
square/pylink | setup.py | long_description | def long_description():
"""Reads and returns the contents of the README.
On failure, returns the project long description.
Returns:
The project's long description.
"""
cwd = os.path.abspath(os.path.dirname(__file__))
readme_path = os.path.join(cwd, 'README.md')
if not os.path.exists(readme_path):
return pylink.__long_description__
try:
import pypandoc
return pypandoc.convert(readme_path, 'rst')
except (IOError, ImportError):
pass
return open(readme_path, 'r').read() | python | def long_description():
"""Reads and returns the contents of the README.
On failure, returns the project long description.
Returns:
The project's long description.
"""
cwd = os.path.abspath(os.path.dirname(__file__))
readme_path = os.path.join(cwd, 'README.md')
if not os.path.exists(readme_path):
return pylink.__long_description__
try:
import pypandoc
return pypandoc.convert(readme_path, 'rst')
except (IOError, ImportError):
pass
return open(readme_path, 'r').read() | [
"def",
"long_description",
"(",
")",
":",
"cwd",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"readme_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"cwd",
",",
"'README.md'",
")",
"if... | Reads and returns the contents of the README.
On failure, returns the project long description.
Returns:
The project's long description. | [
"Reads",
"and",
"returns",
"the",
"contents",
"of",
"the",
"README",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/setup.py#L209-L228 | train | 230,868 |
square/pylink | setup.py | CleanCommand.finalize_options | def finalize_options(self):
"""Populate the attributes.
Args:
self (CleanCommand): the ``CleanCommand`` instance
Returns:
``None``
"""
self.cwd = os.path.abspath(os.path.dirname(__file__))
self.build_dirs = [
os.path.join(self.cwd, 'build'),
os.path.join(self.cwd, 'htmlcov'),
os.path.join(self.cwd, 'dist'),
os.path.join(self.cwd, 'pylink_square.egg-info')
]
self.build_artifacts = ['.pyc', '.o', '.elf', '.bin'] | python | def finalize_options(self):
"""Populate the attributes.
Args:
self (CleanCommand): the ``CleanCommand`` instance
Returns:
``None``
"""
self.cwd = os.path.abspath(os.path.dirname(__file__))
self.build_dirs = [
os.path.join(self.cwd, 'build'),
os.path.join(self.cwd, 'htmlcov'),
os.path.join(self.cwd, 'dist'),
os.path.join(self.cwd, 'pylink_square.egg-info')
]
self.build_artifacts = ['.pyc', '.o', '.elf', '.bin'] | [
"def",
"finalize_options",
"(",
"self",
")",
":",
"self",
".",
"cwd",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"self",
".",
"build_dirs",
"=",
"[",
"os",
".",
"path",
".",
"join",
... | Populate the attributes.
Args:
self (CleanCommand): the ``CleanCommand`` instance
Returns:
``None`` | [
"Populate",
"the",
"attributes",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/setup.py#L52-L68 | train | 230,869 |
square/pylink | setup.py | CoverageCommand.finalize_options | def finalize_options(self):
"""Finalizes the command's options.
Args:
self (CoverageCommand): the ``CoverageCommand`` instance
Returns:
``None``
"""
self.cwd = os.path.abspath(os.path.dirname(__file__))
self.test_dir = os.path.join(self.cwd, 'tests') | python | def finalize_options(self):
"""Finalizes the command's options.
Args:
self (CoverageCommand): the ``CoverageCommand`` instance
Returns:
``None``
"""
self.cwd = os.path.abspath(os.path.dirname(__file__))
self.test_dir = os.path.join(self.cwd, 'tests') | [
"def",
"finalize_options",
"(",
"self",
")",
":",
"self",
".",
"cwd",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"self",
".",
"test_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"s... | Finalizes the command's options.
Args:
self (CoverageCommand): the ``CoverageCommand`` instance
Returns:
``None`` | [
"Finalizes",
"the",
"command",
"s",
"options",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/setup.py#L111-L121 | train | 230,870 |
square/pylink | pylink/unlockers/unlock_kinetis.py | unlock_kinetis_identified | def unlock_kinetis_identified(identity, flags):
"""Checks whether the given flags are a valid identity.
Args:
identity (Identity): the identity to validate against
flags (register.IDCodeRegisterFlags): the set idcode flags
Returns:
``True`` if the given ``flags`` correctly identify the the debug
interface, otherwise ``False``.
"""
if flags.version_code != identity.version_code:
return False
if flags.part_no != identity.part_no:
return False
return flags.valid | python | def unlock_kinetis_identified(identity, flags):
"""Checks whether the given flags are a valid identity.
Args:
identity (Identity): the identity to validate against
flags (register.IDCodeRegisterFlags): the set idcode flags
Returns:
``True`` if the given ``flags`` correctly identify the the debug
interface, otherwise ``False``.
"""
if flags.version_code != identity.version_code:
return False
if flags.part_no != identity.part_no:
return False
return flags.valid | [
"def",
"unlock_kinetis_identified",
"(",
"identity",
",",
"flags",
")",
":",
"if",
"flags",
".",
"version_code",
"!=",
"identity",
".",
"version_code",
":",
"return",
"False",
"if",
"flags",
".",
"part_no",
"!=",
"identity",
".",
"part_no",
":",
"return",
"F... | Checks whether the given flags are a valid identity.
Args:
identity (Identity): the identity to validate against
flags (register.IDCodeRegisterFlags): the set idcode flags
Returns:
``True`` if the given ``flags`` correctly identify the the debug
interface, otherwise ``False``. | [
"Checks",
"whether",
"the",
"given",
"flags",
"are",
"a",
"valid",
"identity",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L34-L51 | train | 230,871 |
square/pylink | pylink/unlockers/unlock_kinetis.py | unlock_kinetis_abort_clear | def unlock_kinetis_abort_clear():
"""Returns the abort register clear code.
Returns:
The abort register clear code.
"""
flags = registers.AbortRegisterFlags()
flags.STKCMPCLR = 1
flags.STKERRCLR = 1
flags.WDERRCLR = 1
flags.ORUNERRCLR = 1
return flags.value | python | def unlock_kinetis_abort_clear():
"""Returns the abort register clear code.
Returns:
The abort register clear code.
"""
flags = registers.AbortRegisterFlags()
flags.STKCMPCLR = 1
flags.STKERRCLR = 1
flags.WDERRCLR = 1
flags.ORUNERRCLR = 1
return flags.value | [
"def",
"unlock_kinetis_abort_clear",
"(",
")",
":",
"flags",
"=",
"registers",
".",
"AbortRegisterFlags",
"(",
")",
"flags",
".",
"STKCMPCLR",
"=",
"1",
"flags",
".",
"STKERRCLR",
"=",
"1",
"flags",
".",
"WDERRCLR",
"=",
"1",
"flags",
".",
"ORUNERRCLR",
"=... | Returns the abort register clear code.
Returns:
The abort register clear code. | [
"Returns",
"the",
"abort",
"register",
"clear",
"code",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L54-L65 | train | 230,872 |
square/pylink | pylink/unlockers/unlock_kinetis.py | unlock_kinetis_read_until_ack | def unlock_kinetis_read_until_ack(jlink, address):
"""Polls the device until the request is acknowledged.
Sends a read request to the connected device to read the register at the
given 'address'. Polls indefinitely until either the request is ACK'd or
the request ends in a fault.
Args:
jlink (JLink): the connected J-Link
address (int) the address of the register to poll
Returns:
``SWDResponse`` object on success.
Raises:
KinetisException: when read exits with non-ack or non-wait status.
Note:
This function is required in order to avoid reading corrupt or otherwise
invalid data from registers when communicating over SWD.
"""
request = swd.ReadRequest(address, ap=True)
response = None
while True:
response = request.send(jlink)
if response.ack():
break
elif response.wait():
continue
raise KinetisException('Read exited with status: %s', response.status)
return response | python | def unlock_kinetis_read_until_ack(jlink, address):
"""Polls the device until the request is acknowledged.
Sends a read request to the connected device to read the register at the
given 'address'. Polls indefinitely until either the request is ACK'd or
the request ends in a fault.
Args:
jlink (JLink): the connected J-Link
address (int) the address of the register to poll
Returns:
``SWDResponse`` object on success.
Raises:
KinetisException: when read exits with non-ack or non-wait status.
Note:
This function is required in order to avoid reading corrupt or otherwise
invalid data from registers when communicating over SWD.
"""
request = swd.ReadRequest(address, ap=True)
response = None
while True:
response = request.send(jlink)
if response.ack():
break
elif response.wait():
continue
raise KinetisException('Read exited with status: %s', response.status)
return response | [
"def",
"unlock_kinetis_read_until_ack",
"(",
"jlink",
",",
"address",
")",
":",
"request",
"=",
"swd",
".",
"ReadRequest",
"(",
"address",
",",
"ap",
"=",
"True",
")",
"response",
"=",
"None",
"while",
"True",
":",
"response",
"=",
"request",
".",
"send",
... | Polls the device until the request is acknowledged.
Sends a read request to the connected device to read the register at the
given 'address'. Polls indefinitely until either the request is ACK'd or
the request ends in a fault.
Args:
jlink (JLink): the connected J-Link
address (int) the address of the register to poll
Returns:
``SWDResponse`` object on success.
Raises:
KinetisException: when read exits with non-ack or non-wait status.
Note:
This function is required in order to avoid reading corrupt or otherwise
invalid data from registers when communicating over SWD. | [
"Polls",
"the",
"device",
"until",
"the",
"request",
"is",
"acknowledged",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L68-L99 | train | 230,873 |
square/pylink | pylink/unlockers/unlock_kinetis.py | unlock_kinetis_swd | def unlock_kinetis_swd(jlink):
"""Unlocks a Kinetis device over SWD.
Steps Involved in Unlocking:
1. Verify that the device is configured to read/write from the CoreSight
registers; this is done by reading the Identification Code Register
and checking its validity. This register is always at 0x0 on reads.
2. Check for errors in the status register. If there are any errors,
they must be cleared by writing to the Abort Register (this is always
0x0 on writes).
3. Turn on the device power and debug power so that the target is
powered by the J-Link as more power is required during an unlock.
4. Assert the ``RESET`` pin to force the target to hold in a reset-state
as to avoid interrupts and other potentially breaking behaviour.
5. At this point, SWD is configured, so send a request to clear the
errors, if any, that may currently be set.
6. Our next SWD request selects the MDM-AP register so that we can start
sending unlock instructions. ``SELECT[31:24] = 0x01`` selects it.
7. Poll the MDM-AP Status Register (AP[1] bank 0, register 0) until the
flash ready bit is set to indicate we can flash.
8. Write to the MDM-AP Control Register (AP[1] bank 0, register 1) to
request a flash mass erase.
9. Poll the system until the flash mass erase bit is acknowledged in the
MDM-AP Status Register.
10. Poll the control register until it clears it's mass erase bit to
indicate that it finished mass erasing, and therefore the system is
now unsecure.
Args:
jlink (JLink): the connected J-Link
Returns:
``True`` if the device was unlocked successfully, otherwise ``False``.
Raises:
KinetisException: when the device cannot be unlocked or fails to unlock.
See Also:
`NXP Forum <https://community.nxp.com/thread/317167>`_.
See Also:
`Kinetis Docs <nxp.com/files/32bit/doc/ref_manual/K12P48M50SF4RM.pdf>`
"""
SWDIdentity = Identity(0x2, 0xBA01)
jlink.power_on()
jlink.coresight_configure()
# 1. Verify that the device is configured properly.
flags = registers.IDCodeRegisterFlags()
flags.value = jlink.coresight_read(0x0, False)
if not unlock_kinetis_identified(SWDIdentity, flags):
return False
# 2. Check for errors.
flags = registers.ControlStatusRegisterFlags()
flags.value = jlink.coresight_read(0x01, False)
if flags.STICKYORUN or flags.STICKYCMP or flags.STICKYERR or flags.WDATAERR:
jlink.coresight_write(0x0, unlock_kinetis_abort_clear(), False)
# 3. Turn on device power and debug.
flags = registers.ControlStatusRegisterFlags()
flags.value = 0
flags.CSYSPWRUPREQ = 1 # System power-up request
flags.CDBGPWRUPREQ = 1 # Debug power-up request
jlink.coresight_write(0x01, flags.value, False)
# 4. Assert the reset pin.
jlink.set_reset_pin_low()
time.sleep(1)
# 5. Send a SWD Request to clear any errors.
request = swd.WriteRequest(0x0, False, unlock_kinetis_abort_clear())
request.send(jlink)
# 6. Send a SWD Request to select the MDM-AP register, SELECT[31:24] = 0x01
request = swd.WriteRequest(0x2, False, (1 << 24))
request.send(jlink)
try:
# 7. Poll until the Flash-ready bit is set in the status register flags.
# Have to read first to ensure the data is valid.
unlock_kinetis_read_until_ack(jlink, 0x0)
flags = registers.MDMAPStatusRegisterFlags()
flags.flash_ready = 0
while not flags.flash_ready:
flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data
# 8. System may still be secure at this point, so request a mass erase.
# AP[1] bank 0, register 1 is the MDM-AP Control Register.
flags = registers.MDMAPControlRegisterFlags()
flags.flash_mass_erase = 1
request = swd.WriteRequest(0x1, True, flags.value)
request.send(jlink)
# 9. Poll the status register until the mass erase command has been
# accepted.
unlock_kinetis_read_until_ack(jlink, 0x0)
flags = registers.MDMAPStatusRegisterFlags()
flags.flash_mass_erase_ack = 0
while not flags.flash_mass_erase_ack:
flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data
# 10. Poll the control register until the ``flash_mass_erase`` bit is
# cleared, which is done automatically when the mass erase
# finishes.
unlock_kinetis_read_until_ack(jlink, 0x1)
flags = registers.MDMAPControlRegisterFlags()
flags.flash_mass_erase = 1
while flags.flash_mass_erase:
flags.value = unlock_kinetis_read_until_ack(jlink, 0x1).data
except KinetisException as e:
jlink.set_reset_pin_high()
return False
jlink.set_reset_pin_high()
time.sleep(1)
jlink.reset()
return True | python | def unlock_kinetis_swd(jlink):
"""Unlocks a Kinetis device over SWD.
Steps Involved in Unlocking:
1. Verify that the device is configured to read/write from the CoreSight
registers; this is done by reading the Identification Code Register
and checking its validity. This register is always at 0x0 on reads.
2. Check for errors in the status register. If there are any errors,
they must be cleared by writing to the Abort Register (this is always
0x0 on writes).
3. Turn on the device power and debug power so that the target is
powered by the J-Link as more power is required during an unlock.
4. Assert the ``RESET`` pin to force the target to hold in a reset-state
as to avoid interrupts and other potentially breaking behaviour.
5. At this point, SWD is configured, so send a request to clear the
errors, if any, that may currently be set.
6. Our next SWD request selects the MDM-AP register so that we can start
sending unlock instructions. ``SELECT[31:24] = 0x01`` selects it.
7. Poll the MDM-AP Status Register (AP[1] bank 0, register 0) until the
flash ready bit is set to indicate we can flash.
8. Write to the MDM-AP Control Register (AP[1] bank 0, register 1) to
request a flash mass erase.
9. Poll the system until the flash mass erase bit is acknowledged in the
MDM-AP Status Register.
10. Poll the control register until it clears it's mass erase bit to
indicate that it finished mass erasing, and therefore the system is
now unsecure.
Args:
jlink (JLink): the connected J-Link
Returns:
``True`` if the device was unlocked successfully, otherwise ``False``.
Raises:
KinetisException: when the device cannot be unlocked or fails to unlock.
See Also:
`NXP Forum <https://community.nxp.com/thread/317167>`_.
See Also:
`Kinetis Docs <nxp.com/files/32bit/doc/ref_manual/K12P48M50SF4RM.pdf>`
"""
SWDIdentity = Identity(0x2, 0xBA01)
jlink.power_on()
jlink.coresight_configure()
# 1. Verify that the device is configured properly.
flags = registers.IDCodeRegisterFlags()
flags.value = jlink.coresight_read(0x0, False)
if not unlock_kinetis_identified(SWDIdentity, flags):
return False
# 2. Check for errors.
flags = registers.ControlStatusRegisterFlags()
flags.value = jlink.coresight_read(0x01, False)
if flags.STICKYORUN or flags.STICKYCMP or flags.STICKYERR or flags.WDATAERR:
jlink.coresight_write(0x0, unlock_kinetis_abort_clear(), False)
# 3. Turn on device power and debug.
flags = registers.ControlStatusRegisterFlags()
flags.value = 0
flags.CSYSPWRUPREQ = 1 # System power-up request
flags.CDBGPWRUPREQ = 1 # Debug power-up request
jlink.coresight_write(0x01, flags.value, False)
# 4. Assert the reset pin.
jlink.set_reset_pin_low()
time.sleep(1)
# 5. Send a SWD Request to clear any errors.
request = swd.WriteRequest(0x0, False, unlock_kinetis_abort_clear())
request.send(jlink)
# 6. Send a SWD Request to select the MDM-AP register, SELECT[31:24] = 0x01
request = swd.WriteRequest(0x2, False, (1 << 24))
request.send(jlink)
try:
# 7. Poll until the Flash-ready bit is set in the status register flags.
# Have to read first to ensure the data is valid.
unlock_kinetis_read_until_ack(jlink, 0x0)
flags = registers.MDMAPStatusRegisterFlags()
flags.flash_ready = 0
while not flags.flash_ready:
flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data
# 8. System may still be secure at this point, so request a mass erase.
# AP[1] bank 0, register 1 is the MDM-AP Control Register.
flags = registers.MDMAPControlRegisterFlags()
flags.flash_mass_erase = 1
request = swd.WriteRequest(0x1, True, flags.value)
request.send(jlink)
# 9. Poll the status register until the mass erase command has been
# accepted.
unlock_kinetis_read_until_ack(jlink, 0x0)
flags = registers.MDMAPStatusRegisterFlags()
flags.flash_mass_erase_ack = 0
while not flags.flash_mass_erase_ack:
flags.value = unlock_kinetis_read_until_ack(jlink, 0x0).data
# 10. Poll the control register until the ``flash_mass_erase`` bit is
# cleared, which is done automatically when the mass erase
# finishes.
unlock_kinetis_read_until_ack(jlink, 0x1)
flags = registers.MDMAPControlRegisterFlags()
flags.flash_mass_erase = 1
while flags.flash_mass_erase:
flags.value = unlock_kinetis_read_until_ack(jlink, 0x1).data
except KinetisException as e:
jlink.set_reset_pin_high()
return False
jlink.set_reset_pin_high()
time.sleep(1)
jlink.reset()
return True | [
"def",
"unlock_kinetis_swd",
"(",
"jlink",
")",
":",
"SWDIdentity",
"=",
"Identity",
"(",
"0x2",
",",
"0xBA01",
")",
"jlink",
".",
"power_on",
"(",
")",
"jlink",
".",
"coresight_configure",
"(",
")",
"# 1. Verify that the device is configured properly.",
"flags",
... | Unlocks a Kinetis device over SWD.
Steps Involved in Unlocking:
1. Verify that the device is configured to read/write from the CoreSight
registers; this is done by reading the Identification Code Register
and checking its validity. This register is always at 0x0 on reads.
2. Check for errors in the status register. If there are any errors,
they must be cleared by writing to the Abort Register (this is always
0x0 on writes).
3. Turn on the device power and debug power so that the target is
powered by the J-Link as more power is required during an unlock.
4. Assert the ``RESET`` pin to force the target to hold in a reset-state
as to avoid interrupts and other potentially breaking behaviour.
5. At this point, SWD is configured, so send a request to clear the
errors, if any, that may currently be set.
6. Our next SWD request selects the MDM-AP register so that we can start
sending unlock instructions. ``SELECT[31:24] = 0x01`` selects it.
7. Poll the MDM-AP Status Register (AP[1] bank 0, register 0) until the
flash ready bit is set to indicate we can flash.
8. Write to the MDM-AP Control Register (AP[1] bank 0, register 1) to
request a flash mass erase.
9. Poll the system until the flash mass erase bit is acknowledged in the
MDM-AP Status Register.
10. Poll the control register until it clears it's mass erase bit to
indicate that it finished mass erasing, and therefore the system is
now unsecure.
Args:
jlink (JLink): the connected J-Link
Returns:
``True`` if the device was unlocked successfully, otherwise ``False``.
Raises:
KinetisException: when the device cannot be unlocked or fails to unlock.
See Also:
`NXP Forum <https://community.nxp.com/thread/317167>`_.
See Also:
`Kinetis Docs <nxp.com/files/32bit/doc/ref_manual/K12P48M50SF4RM.pdf>` | [
"Unlocks",
"a",
"Kinetis",
"device",
"over",
"SWD",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L102-L222 | train | 230,874 |
square/pylink | pylink/unlockers/unlock_kinetis.py | unlock_kinetis | def unlock_kinetis(jlink):
"""Unlock for Freescale Kinetis K40 or K60 device.
Args:
jlink (JLink): an instance of a J-Link that is connected to a target.
Returns:
``True`` if the device was successfully unlocked, otherwise ``False``.
Raises:
ValueError: if the J-Link is not connected to a target.
"""
if not jlink.connected():
raise ValueError('No target to unlock.')
method = UNLOCK_METHODS.get(jlink.tif, None)
if method is None:
raise NotImplementedError('Unsupported target interface for unlock.')
return method(jlink) | python | def unlock_kinetis(jlink):
"""Unlock for Freescale Kinetis K40 or K60 device.
Args:
jlink (JLink): an instance of a J-Link that is connected to a target.
Returns:
``True`` if the device was successfully unlocked, otherwise ``False``.
Raises:
ValueError: if the J-Link is not connected to a target.
"""
if not jlink.connected():
raise ValueError('No target to unlock.')
method = UNLOCK_METHODS.get(jlink.tif, None)
if method is None:
raise NotImplementedError('Unsupported target interface for unlock.')
return method(jlink) | [
"def",
"unlock_kinetis",
"(",
"jlink",
")",
":",
"if",
"not",
"jlink",
".",
"connected",
"(",
")",
":",
"raise",
"ValueError",
"(",
"'No target to unlock.'",
")",
"method",
"=",
"UNLOCK_METHODS",
".",
"get",
"(",
"jlink",
".",
"tif",
",",
"None",
")",
"i... | Unlock for Freescale Kinetis K40 or K60 device.
Args:
jlink (JLink): an instance of a J-Link that is connected to a target.
Returns:
``True`` if the device was successfully unlocked, otherwise ``False``.
Raises:
ValueError: if the J-Link is not connected to a target. | [
"Unlock",
"for",
"Freescale",
"Kinetis",
"K40",
"or",
"K60",
"device",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/unlockers/unlock_kinetis.py#L251-L270 | train | 230,875 |
square/pylink | pylink/jlink.py | JLink.minimum_required | def minimum_required(version):
"""Decorator to specify the minimum SDK version required.
Args:
version (str): valid version string
Returns:
A decorator function.
"""
def _minimum_required(func):
"""Internal decorator that wraps around the given function.
Args:
func (function): function being decorated
Returns:
The wrapper unction.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to compare the DLL's SDK version.
Args:
self (JLink): the ``JLink`` instance
args (list): list of arguments to pass to ``func``
kwargs (dict): key-word arguments dict to pass to ``func``
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the DLL's version is less than ``version``.
"""
if list(self.version) < list(version):
raise errors.JLinkException('Version %s required.' % version)
return func(self, *args, **kwargs)
return wrapper
return _minimum_required | python | def minimum_required(version):
"""Decorator to specify the minimum SDK version required.
Args:
version (str): valid version string
Returns:
A decorator function.
"""
def _minimum_required(func):
"""Internal decorator that wraps around the given function.
Args:
func (function): function being decorated
Returns:
The wrapper unction.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to compare the DLL's SDK version.
Args:
self (JLink): the ``JLink`` instance
args (list): list of arguments to pass to ``func``
kwargs (dict): key-word arguments dict to pass to ``func``
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the DLL's version is less than ``version``.
"""
if list(self.version) < list(version):
raise errors.JLinkException('Version %s required.' % version)
return func(self, *args, **kwargs)
return wrapper
return _minimum_required | [
"def",
"minimum_required",
"(",
"version",
")",
":",
"def",
"_minimum_required",
"(",
"func",
")",
":",
"\"\"\"Internal decorator that wraps around the given function.\n\n Args:\n func (function): function being decorated\n\n Returns:\n The wra... | Decorator to specify the minimum SDK version required.
Args:
version (str): valid version string
Returns:
A decorator function. | [
"Decorator",
"to",
"specify",
"the",
"minimum",
"SDK",
"version",
"required",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L71-L108 | train | 230,876 |
square/pylink | pylink/jlink.py | JLink.open_required | def open_required(func):
"""Decorator to specify that the J-Link DLL must be opened, and a
J-Link connection must be established.
Args:
func (function): function being decorated
Returns:
The wrapper function.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to check that the given ``JLink`` has been
opened.
Args:
self (JLink): the ``JLink`` instance
args: list of arguments to pass to the wrapped function
kwargs: key-word arguments dict to pass to the wrapped function
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the J-Link DLL is not open or the J-Link is
disconnected.
"""
if not self.opened():
raise errors.JLinkException('J-Link DLL is not open.')
elif not self.connected():
raise errors.JLinkException('J-Link connection has been lost.')
return func(self, *args, **kwargs)
return wrapper | python | def open_required(func):
"""Decorator to specify that the J-Link DLL must be opened, and a
J-Link connection must be established.
Args:
func (function): function being decorated
Returns:
The wrapper function.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to check that the given ``JLink`` has been
opened.
Args:
self (JLink): the ``JLink`` instance
args: list of arguments to pass to the wrapped function
kwargs: key-word arguments dict to pass to the wrapped function
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the J-Link DLL is not open or the J-Link is
disconnected.
"""
if not self.opened():
raise errors.JLinkException('J-Link DLL is not open.')
elif not self.connected():
raise errors.JLinkException('J-Link connection has been lost.')
return func(self, *args, **kwargs)
return wrapper | [
"def",
"open_required",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Wrapper function to check that the given ``JLink`` has been\n ope... | Decorator to specify that the J-Link DLL must be opened, and a
J-Link connection must be established.
Args:
func (function): function being decorated
Returns:
The wrapper function. | [
"Decorator",
"to",
"specify",
"that",
"the",
"J",
"-",
"Link",
"DLL",
"must",
"be",
"opened",
"and",
"a",
"J",
"-",
"Link",
"connection",
"must",
"be",
"established",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L110-L142 | train | 230,877 |
square/pylink | pylink/jlink.py | JLink.connection_required | def connection_required(func):
"""Decorator to specify that a target connection is required in order
for the given method to be used.
Args:
func (function): function being decorated
Returns:
The wrapper function.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to check that the given ``JLink`` has been
connected to a target.
Args:
self (JLink): the ``JLink`` instance
args: list of arguments to pass to the wrapped function
kwargs: key-word arguments dict to pass to the wrapped function
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the JLink's target is not connected.
"""
if not self.target_connected():
raise errors.JLinkException('Target is not connected.')
return func(self, *args, **kwargs)
return wrapper | python | def connection_required(func):
"""Decorator to specify that a target connection is required in order
for the given method to be used.
Args:
func (function): function being decorated
Returns:
The wrapper function.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to check that the given ``JLink`` has been
connected to a target.
Args:
self (JLink): the ``JLink`` instance
args: list of arguments to pass to the wrapped function
kwargs: key-word arguments dict to pass to the wrapped function
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the JLink's target is not connected.
"""
if not self.target_connected():
raise errors.JLinkException('Target is not connected.')
return func(self, *args, **kwargs)
return wrapper | [
"def",
"connection_required",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Wrapper function to check that the given ``JLink`` has been\n ... | Decorator to specify that a target connection is required in order
for the given method to be used.
Args:
func (function): function being decorated
Returns:
The wrapper function. | [
"Decorator",
"to",
"specify",
"that",
"a",
"target",
"connection",
"is",
"required",
"in",
"order",
"for",
"the",
"given",
"method",
"to",
"be",
"used",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L144-L173 | train | 230,878 |
square/pylink | pylink/jlink.py | JLink.interface_required | def interface_required(interface):
"""Decorator to specify that a particular interface type is required
for the given method to be used.
Args:
interface (int): attribute of ``JLinkInterfaces``
Returns:
A decorator function.
"""
def _interface_required(func):
"""Internal decorator that wraps around the decorated function.
Args:
func (function): function being decorated
Returns:
The wrapper function.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to check that the given ``JLink`` has the
same interface as the one specified by the decorator.
Args:
self (JLink): the ``JLink`` instance
args: list of arguments to pass to ``func``
kwargs: key-word arguments dict to pass to ``func``
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the current interface is not supported by
the wrapped method.
"""
if self.tif != interface:
raise errors.JLinkException('Unsupported for current interface.')
return func(self, *args, **kwargs)
return wrapper
return _interface_required | python | def interface_required(interface):
"""Decorator to specify that a particular interface type is required
for the given method to be used.
Args:
interface (int): attribute of ``JLinkInterfaces``
Returns:
A decorator function.
"""
def _interface_required(func):
"""Internal decorator that wraps around the decorated function.
Args:
func (function): function being decorated
Returns:
The wrapper function.
"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper function to check that the given ``JLink`` has the
same interface as the one specified by the decorator.
Args:
self (JLink): the ``JLink`` instance
args: list of arguments to pass to ``func``
kwargs: key-word arguments dict to pass to ``func``
Returns:
The return value of the wrapped function.
Raises:
JLinkException: if the current interface is not supported by
the wrapped method.
"""
if self.tif != interface:
raise errors.JLinkException('Unsupported for current interface.')
return func(self, *args, **kwargs)
return wrapper
return _interface_required | [
"def",
"interface_required",
"(",
"interface",
")",
":",
"def",
"_interface_required",
"(",
"func",
")",
":",
"\"\"\"Internal decorator that wraps around the decorated function.\n\n Args:\n func (function): function being decorated\n\n Returns:\n ... | Decorator to specify that a particular interface type is required
for the given method to be used.
Args:
interface (int): attribute of ``JLinkInterfaces``
Returns:
A decorator function. | [
"Decorator",
"to",
"specify",
"that",
"a",
"particular",
"interface",
"type",
"is",
"required",
"for",
"the",
"given",
"method",
"to",
"be",
"used",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L175-L215 | train | 230,879 |
square/pylink | pylink/jlink.py | JLink.log_handler | def log_handler(self, handler):
"""Setter for the log handler function.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_EnableLog(self._log_handler) | python | def log_handler(self, handler):
"""Setter for the log handler function.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_EnableLog(self._log_handler) | [
"def",
"log_handler",
"(",
"self",
",",
"handler",
")",
":",
"if",
"not",
"self",
".",
"opened",
"(",
")",
":",
"handler",
"=",
"handler",
"or",
"util",
".",
"noop",
"self",
".",
"_log_handler",
"=",
"enums",
".",
"JLinkFunctions",
".",
"LOG_PROTOTYPE",
... | Setter for the log handler function.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None`` | [
"Setter",
"for",
"the",
"log",
"handler",
"function",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L343-L355 | train | 230,880 |
square/pylink | pylink/jlink.py | JLink.detailed_log_handler | def detailed_log_handler(self, handler):
"""Setter for the detailed log handler function.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._detailed_log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_EnableLogCom(self._detailed_log_handler) | python | def detailed_log_handler(self, handler):
"""Setter for the detailed log handler function.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._detailed_log_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_EnableLogCom(self._detailed_log_handler) | [
"def",
"detailed_log_handler",
"(",
"self",
",",
"handler",
")",
":",
"if",
"not",
"self",
".",
"opened",
"(",
")",
":",
"handler",
"=",
"handler",
"or",
"util",
".",
"noop",
"self",
".",
"_detailed_log_handler",
"=",
"enums",
".",
"JLinkFunctions",
".",
... | Setter for the detailed log handler function.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None`` | [
"Setter",
"for",
"the",
"detailed",
"log",
"handler",
"function",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L371-L383 | train | 230,881 |
square/pylink | pylink/jlink.py | JLink.error_handler | def error_handler(self, handler):
"""Setter for the error handler function.
If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.
Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on error messages
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._error_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_SetErrorOutHandler(self._error_handler) | python | def error_handler(self, handler):
"""Setter for the error handler function.
If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.
Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on error messages
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._error_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_SetErrorOutHandler(self._error_handler) | [
"def",
"error_handler",
"(",
"self",
",",
"handler",
")",
":",
"if",
"not",
"self",
".",
"opened",
"(",
")",
":",
"handler",
"=",
"handler",
"or",
"util",
".",
"noop",
"self",
".",
"_error_handler",
"=",
"enums",
".",
"JLinkFunctions",
".",
"LOG_PROTOTYP... | Setter for the error handler function.
If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.
Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on error messages
Returns:
``None`` | [
"Setter",
"for",
"the",
"error",
"handler",
"function",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L399-L415 | train | 230,882 |
square/pylink | pylink/jlink.py | JLink.warning_handler | def warning_handler(self, handler):
"""Setter for the warning handler function.
If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.
Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on warning messages
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._warning_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_SetWarnOutHandler(self._warning_handler) | python | def warning_handler(self, handler):
"""Setter for the warning handler function.
If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.
Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on warning messages
Returns:
``None``
"""
if not self.opened():
handler = handler or util.noop
self._warning_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
self._dll.JLINKARM_SetWarnOutHandler(self._warning_handler) | [
"def",
"warning_handler",
"(",
"self",
",",
"handler",
")",
":",
"if",
"not",
"self",
".",
"opened",
"(",
")",
":",
"handler",
"=",
"handler",
"or",
"util",
".",
"noop",
"self",
".",
"_warning_handler",
"=",
"enums",
".",
"JLinkFunctions",
".",
"LOG_PROT... | Setter for the warning handler function.
If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.
Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on warning messages
Returns:
``None`` | [
"Setter",
"for",
"the",
"warning",
"handler",
"function",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L431-L447 | train | 230,883 |
square/pylink | pylink/jlink.py | JLink.connected_emulators | def connected_emulators(self, host=enums.JLinkHost.USB):
"""Returns a list of all the connected emulators.
Args:
self (JLink): the ``JLink`` instance
host (int): host type to search (default: ``JLinkHost.USB``)
Returns:
List of ``JLinkConnectInfo`` specifying the connected emulators.
Raises:
JLinkException: if fails to enumerate devices.
"""
res = self._dll.JLINKARM_EMU_GetList(host, 0, 0)
if res < 0:
raise errors.JLinkException(res)
num_devices = res
info = (structs.JLinkConnectInfo * num_devices)()
num_found = self._dll.JLINKARM_EMU_GetList(host, info, num_devices)
if num_found < 0:
raise errors.JLinkException(num_found)
return list(info)[:num_found] | python | def connected_emulators(self, host=enums.JLinkHost.USB):
"""Returns a list of all the connected emulators.
Args:
self (JLink): the ``JLink`` instance
host (int): host type to search (default: ``JLinkHost.USB``)
Returns:
List of ``JLinkConnectInfo`` specifying the connected emulators.
Raises:
JLinkException: if fails to enumerate devices.
"""
res = self._dll.JLINKARM_EMU_GetList(host, 0, 0)
if res < 0:
raise errors.JLinkException(res)
num_devices = res
info = (structs.JLinkConnectInfo * num_devices)()
num_found = self._dll.JLINKARM_EMU_GetList(host, info, num_devices)
if num_found < 0:
raise errors.JLinkException(num_found)
return list(info)[:num_found] | [
"def",
"connected_emulators",
"(",
"self",
",",
"host",
"=",
"enums",
".",
"JLinkHost",
".",
"USB",
")",
":",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_EMU_GetList",
"(",
"host",
",",
"0",
",",
"0",
")",
"if",
"res",
"<",
"0",
":",
"raise",
"... | Returns a list of all the connected emulators.
Args:
self (JLink): the ``JLink`` instance
host (int): host type to search (default: ``JLinkHost.USB``)
Returns:
List of ``JLinkConnectInfo`` specifying the connected emulators.
Raises:
JLinkException: if fails to enumerate devices. | [
"Returns",
"a",
"list",
"of",
"all",
"the",
"connected",
"emulators",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L461-L484 | train | 230,884 |
square/pylink | pylink/jlink.py | JLink.supported_device | def supported_device(self, index=0):
"""Gets the device at the given ``index``.
Args:
self (JLink): the ``JLink`` instance
index (int): the index of the device whose information to get
Returns:
A ``JLinkDeviceInfo`` describing the requested device.
Raises:
ValueError: if index is less than 0 or >= supported device count.
"""
if not util.is_natural(index) or index >= self.num_supported_devices():
raise ValueError('Invalid index.')
info = structs.JLinkDeviceInfo()
result = self._dll.JLINKARM_DEVICE_GetInfo(index, ctypes.byref(info))
return info | python | def supported_device(self, index=0):
"""Gets the device at the given ``index``.
Args:
self (JLink): the ``JLink`` instance
index (int): the index of the device whose information to get
Returns:
A ``JLinkDeviceInfo`` describing the requested device.
Raises:
ValueError: if index is less than 0 or >= supported device count.
"""
if not util.is_natural(index) or index >= self.num_supported_devices():
raise ValueError('Invalid index.')
info = structs.JLinkDeviceInfo()
result = self._dll.JLINKARM_DEVICE_GetInfo(index, ctypes.byref(info))
return info | [
"def",
"supported_device",
"(",
"self",
",",
"index",
"=",
"0",
")",
":",
"if",
"not",
"util",
".",
"is_natural",
"(",
"index",
")",
"or",
"index",
">=",
"self",
".",
"num_supported_devices",
"(",
")",
":",
"raise",
"ValueError",
"(",
"'Invalid index.'",
... | Gets the device at the given ``index``.
Args:
self (JLink): the ``JLink`` instance
index (int): the index of the device whose information to get
Returns:
A ``JLinkDeviceInfo`` describing the requested device.
Raises:
ValueError: if index is less than 0 or >= supported device count. | [
"Gets",
"the",
"device",
"at",
"the",
"given",
"index",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L498-L517 | train | 230,885 |
square/pylink | pylink/jlink.py | JLink.close | def close(self):
"""Closes the open J-Link.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
Raises:
JLinkException: if there is no connected JLink.
"""
self._dll.JLINKARM_Close()
if self._lock is not None:
del self._lock
self._lock = None
return None | python | def close(self):
"""Closes the open J-Link.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
Raises:
JLinkException: if there is no connected JLink.
"""
self._dll.JLINKARM_Close()
if self._lock is not None:
del self._lock
self._lock = None
return None | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"_dll",
".",
"JLINKARM_Close",
"(",
")",
"if",
"self",
".",
"_lock",
"is",
"not",
"None",
":",
"del",
"self",
".",
"_lock",
"self",
".",
"_lock",
"=",
"None",
"return",
"None"
] | Closes the open J-Link.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
Raises:
JLinkException: if there is no connected JLink. | [
"Closes",
"the",
"open",
"J",
"-",
"Link",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L606-L624 | train | 230,886 |
square/pylink | pylink/jlink.py | JLink.sync_firmware | def sync_firmware(self):
"""Syncs the emulator's firmware version and the DLL's firmware.
This method is useful for ensuring that the firmware running on the
J-Link matches the firmware supported by the DLL.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
"""
serial_no = self.serial_number
if self.firmware_newer():
# The J-Link's firmware is newer than the one compatible with the
# DLL (though there are promises of backwards compatibility), so
# perform a downgrade.
try:
# This may throw an exception on older versions of the J-Link
# software due to the software timing out after a firmware
# upgrade.
self.invalidate_firmware()
self.update_firmware()
except errors.JLinkException as e:
pass
res = self.open(serial_no=serial_no)
if self.firmware_newer():
raise errors.JLinkException('Failed to sync firmware version.')
return res
elif self.firmware_outdated():
# The J-Link's firmware is older than the one compatible with the
# DLL, so perform a firmware upgrade.
try:
# This may throw an exception on older versions of the J-Link
# software due to the software timing out after a firmware
# upgrade.
self.update_firmware()
except errors.JLinkException as e:
pass
if self.firmware_outdated():
raise errors.JLinkException('Failed to sync firmware version.')
return self.open(serial_no=serial_no)
return None | python | def sync_firmware(self):
"""Syncs the emulator's firmware version and the DLL's firmware.
This method is useful for ensuring that the firmware running on the
J-Link matches the firmware supported by the DLL.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None``
"""
serial_no = self.serial_number
if self.firmware_newer():
# The J-Link's firmware is newer than the one compatible with the
# DLL (though there are promises of backwards compatibility), so
# perform a downgrade.
try:
# This may throw an exception on older versions of the J-Link
# software due to the software timing out after a firmware
# upgrade.
self.invalidate_firmware()
self.update_firmware()
except errors.JLinkException as e:
pass
res = self.open(serial_no=serial_no)
if self.firmware_newer():
raise errors.JLinkException('Failed to sync firmware version.')
return res
elif self.firmware_outdated():
# The J-Link's firmware is older than the one compatible with the
# DLL, so perform a firmware upgrade.
try:
# This may throw an exception on older versions of the J-Link
# software due to the software timing out after a firmware
# upgrade.
self.update_firmware()
except errors.JLinkException as e:
pass
if self.firmware_outdated():
raise errors.JLinkException('Failed to sync firmware version.')
return self.open(serial_no=serial_no)
return None | [
"def",
"sync_firmware",
"(",
"self",
")",
":",
"serial_no",
"=",
"self",
".",
"serial_number",
"if",
"self",
".",
"firmware_newer",
"(",
")",
":",
"# The J-Link's firmware is newer than the one compatible with the",
"# DLL (though there are promises of backwards compatibility),... | Syncs the emulator's firmware version and the DLL's firmware.
This method is useful for ensuring that the firmware running on the
J-Link matches the firmware supported by the DLL.
Args:
self (JLink): the ``JLink`` instance
Returns:
``None`` | [
"Syncs",
"the",
"emulator",
"s",
"firmware",
"version",
"and",
"the",
"DLL",
"s",
"firmware",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L676-L726 | train | 230,887 |
square/pylink | pylink/jlink.py | JLink.exec_command | def exec_command(self, cmd):
"""Executes the given command.
This method executes a command by calling the DLL's exec method.
Direct API methods should be prioritized over calling this method.
Args:
self (JLink): the ``JLink`` instance
cmd (str): the command to run
Returns:
The return code of running the command.
Raises:
JLinkException: if the command is invalid or fails.
See Also:
For a full list of the supported commands, please see the SEGGER
J-Link documentation,
`UM08001 <https://www.segger.com/downloads/jlink>`__.
"""
err_buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
res = self._dll.JLINKARM_ExecCommand(cmd.encode(), err_buf, self.MAX_BUF_SIZE)
err_buf = ctypes.string_at(err_buf).decode()
if len(err_buf) > 0:
# This is how they check for error in the documentation, so check
# this way as well.
raise errors.JLinkException(err_buf.strip())
return res | python | def exec_command(self, cmd):
"""Executes the given command.
This method executes a command by calling the DLL's exec method.
Direct API methods should be prioritized over calling this method.
Args:
self (JLink): the ``JLink`` instance
cmd (str): the command to run
Returns:
The return code of running the command.
Raises:
JLinkException: if the command is invalid or fails.
See Also:
For a full list of the supported commands, please see the SEGGER
J-Link documentation,
`UM08001 <https://www.segger.com/downloads/jlink>`__.
"""
err_buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
res = self._dll.JLINKARM_ExecCommand(cmd.encode(), err_buf, self.MAX_BUF_SIZE)
err_buf = ctypes.string_at(err_buf).decode()
if len(err_buf) > 0:
# This is how they check for error in the documentation, so check
# this way as well.
raise errors.JLinkException(err_buf.strip())
return res | [
"def",
"exec_command",
"(",
"self",
",",
"cmd",
")",
":",
"err_buf",
"=",
"(",
"ctypes",
".",
"c_char",
"*",
"self",
".",
"MAX_BUF_SIZE",
")",
"(",
")",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_ExecCommand",
"(",
"cmd",
".",
"encode",
"(",
")"... | Executes the given command.
This method executes a command by calling the DLL's exec method.
Direct API methods should be prioritized over calling this method.
Args:
self (JLink): the ``JLink`` instance
cmd (str): the command to run
Returns:
The return code of running the command.
Raises:
JLinkException: if the command is invalid or fails.
See Also:
For a full list of the supported commands, please see the SEGGER
J-Link documentation,
`UM08001 <https://www.segger.com/downloads/jlink>`__. | [
"Executes",
"the",
"given",
"command",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L728-L758 | train | 230,888 |
square/pylink | pylink/jlink.py | JLink.jtag_configure | def jtag_configure(self, instr_regs=0, data_bits=0):
"""Configures the JTAG scan chain to determine which CPU to address.
Must be called if the J-Link is connected to a JTAG scan chain with
multiple devices.
Args:
self (JLink): the ``JLink`` instance
instr_regs (int): length of instruction registers of all devices
closer to TD1 then the addressed CPU
data_bits (int): total number of data bits closer to TD1 than the
addressed CPU
Returns:
``None``
Raises:
ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers
"""
if not util.is_natural(instr_regs):
raise ValueError('IR value is not a natural number.')
if not util.is_natural(data_bits):
raise ValueError('Data bits is not a natural number.')
self._dll.JLINKARM_ConfigJTAG(instr_regs, data_bits)
return None | python | def jtag_configure(self, instr_regs=0, data_bits=0):
"""Configures the JTAG scan chain to determine which CPU to address.
Must be called if the J-Link is connected to a JTAG scan chain with
multiple devices.
Args:
self (JLink): the ``JLink`` instance
instr_regs (int): length of instruction registers of all devices
closer to TD1 then the addressed CPU
data_bits (int): total number of data bits closer to TD1 than the
addressed CPU
Returns:
``None``
Raises:
ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers
"""
if not util.is_natural(instr_regs):
raise ValueError('IR value is not a natural number.')
if not util.is_natural(data_bits):
raise ValueError('Data bits is not a natural number.')
self._dll.JLINKARM_ConfigJTAG(instr_regs, data_bits)
return None | [
"def",
"jtag_configure",
"(",
"self",
",",
"instr_regs",
"=",
"0",
",",
"data_bits",
"=",
"0",
")",
":",
"if",
"not",
"util",
".",
"is_natural",
"(",
"instr_regs",
")",
":",
"raise",
"ValueError",
"(",
"'IR value is not a natural number.'",
")",
"if",
"not",... | Configures the JTAG scan chain to determine which CPU to address.
Must be called if the J-Link is connected to a JTAG scan chain with
multiple devices.
Args:
self (JLink): the ``JLink`` instance
instr_regs (int): length of instruction registers of all devices
closer to TD1 then the addressed CPU
data_bits (int): total number of data bits closer to TD1 than the
addressed CPU
Returns:
``None``
Raises:
ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers | [
"Configures",
"the",
"JTAG",
"scan",
"chain",
"to",
"determine",
"which",
"CPU",
"to",
"address",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L804-L830 | train | 230,889 |
square/pylink | pylink/jlink.py | JLink.coresight_configure | def coresight_configure(self,
ir_pre=0,
dr_pre=0,
ir_post=0,
dr_post=0,
ir_len=0,
perform_tif_init=True):
"""Prepares target and J-Link for CoreSight function usage.
Args:
self (JLink): the ``JLink`` instance
ir_pre (int): sum of instruction register length of all JTAG devices
in the JTAG chain, close to TDO than the actual one, that J-Link
shall communicate with
dr_pre (int): number of JTAG devices in the JTAG chain, closer to TDO
than the actual one, that J-Link shall communicate with
ir_post (int): sum of instruction register length of all JTAG devices
in the JTAG chain, following the actual one, that J-Link shall
communicate with
dr_post (int): Number of JTAG devices in the JTAG chain, following
the actual one, J-Link shall communicate with
ir_len (int): instruction register length of the actual device that
J-Link shall communicate with
perform_tif_init (bool): if ``False``, then do not output switching
sequence on completion
Returns:
``None``
Note:
This must be called before calling ``coresight_read()`` or
``coresight_write()``.
"""
if self.tif == enums.JLinkInterfaces.SWD:
# No special setup is needed for SWD, just need to output the
# switching sequence.
res = self._dll.JLINKARM_CORESIGHT_Configure('')
if res < 0:
raise errors.JLinkException(res)
return None
# JTAG requires more setup than SWD.
config_string = 'IRPre=%s;DRPre=%s;IRPost=%s;DRPost=%s;IRLenDevice=%s;'
config_string = config_string % (ir_pre, dr_pre, ir_post, dr_post, ir_len)
if not perform_tif_init:
config_string = config_string + ('PerformTIFInit=0;')
res = self._dll.JLINKARM_CORESIGHT_Configure(config_string.encode())
if res < 0:
raise errors.JLinkException(res)
return None | python | def coresight_configure(self,
ir_pre=0,
dr_pre=0,
ir_post=0,
dr_post=0,
ir_len=0,
perform_tif_init=True):
"""Prepares target and J-Link for CoreSight function usage.
Args:
self (JLink): the ``JLink`` instance
ir_pre (int): sum of instruction register length of all JTAG devices
in the JTAG chain, close to TDO than the actual one, that J-Link
shall communicate with
dr_pre (int): number of JTAG devices in the JTAG chain, closer to TDO
than the actual one, that J-Link shall communicate with
ir_post (int): sum of instruction register length of all JTAG devices
in the JTAG chain, following the actual one, that J-Link shall
communicate with
dr_post (int): Number of JTAG devices in the JTAG chain, following
the actual one, J-Link shall communicate with
ir_len (int): instruction register length of the actual device that
J-Link shall communicate with
perform_tif_init (bool): if ``False``, then do not output switching
sequence on completion
Returns:
``None``
Note:
This must be called before calling ``coresight_read()`` or
``coresight_write()``.
"""
if self.tif == enums.JLinkInterfaces.SWD:
# No special setup is needed for SWD, just need to output the
# switching sequence.
res = self._dll.JLINKARM_CORESIGHT_Configure('')
if res < 0:
raise errors.JLinkException(res)
return None
# JTAG requires more setup than SWD.
config_string = 'IRPre=%s;DRPre=%s;IRPost=%s;DRPost=%s;IRLenDevice=%s;'
config_string = config_string % (ir_pre, dr_pre, ir_post, dr_post, ir_len)
if not perform_tif_init:
config_string = config_string + ('PerformTIFInit=0;')
res = self._dll.JLINKARM_CORESIGHT_Configure(config_string.encode())
if res < 0:
raise errors.JLinkException(res)
return None | [
"def",
"coresight_configure",
"(",
"self",
",",
"ir_pre",
"=",
"0",
",",
"dr_pre",
"=",
"0",
",",
"ir_post",
"=",
"0",
",",
"dr_post",
"=",
"0",
",",
"ir_len",
"=",
"0",
",",
"perform_tif_init",
"=",
"True",
")",
":",
"if",
"self",
".",
"tif",
"=="... | Prepares target and J-Link for CoreSight function usage.
Args:
self (JLink): the ``JLink`` instance
ir_pre (int): sum of instruction register length of all JTAG devices
in the JTAG chain, close to TDO than the actual one, that J-Link
shall communicate with
dr_pre (int): number of JTAG devices in the JTAG chain, closer to TDO
than the actual one, that J-Link shall communicate with
ir_post (int): sum of instruction register length of all JTAG devices
in the JTAG chain, following the actual one, that J-Link shall
communicate with
dr_post (int): Number of JTAG devices in the JTAG chain, following
the actual one, J-Link shall communicate with
ir_len (int): instruction register length of the actual device that
J-Link shall communicate with
perform_tif_init (bool): if ``False``, then do not output switching
sequence on completion
Returns:
``None``
Note:
This must be called before calling ``coresight_read()`` or
``coresight_write()``. | [
"Prepares",
"target",
"and",
"J",
"-",
"Link",
"for",
"CoreSight",
"function",
"usage",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L834-L887 | train | 230,890 |
square/pylink | pylink/jlink.py | JLink.connect | def connect(self, chip_name, speed='auto', verbose=False):
"""Connects the J-Link to its target.
Args:
self (JLink): the ``JLink`` instance
chip_name (str): target chip name
speed (int): connection speed, one of ``{5-12000, 'auto', 'adaptive'}``
verbose (bool): boolean indicating if connection should be verbose in logging
Returns:
``None``
Raises:
JLinkException: if connection fails to establish.
TypeError: if given speed is invalid
"""
if verbose:
self.exec_command('EnableRemarks = 1')
# This is weird but is currently the only way to specify what the
# target is to the J-Link.
self.exec_command('Device = %s' % chip_name)
# Need to select target interface speed here, so the J-Link knows what
# speed to use to establish target communication.
if speed == 'auto':
self.set_speed(auto=True)
elif speed == 'adaptive':
self.set_speed(adaptive=True)
else:
self.set_speed(speed)
result = self._dll.JLINKARM_Connect()
if result < 0:
raise errors.JLinkException(result)
try:
# Issue a no-op command after connect. This has to be in a try-catch.
self.halted()
except errors.JLinkException:
pass
# Determine which device we are. This is essential for using methods
# like 'unlock' or 'lock'.
for index in range(self.num_supported_devices()):
device = self.supported_device(index)
if device.name.lower() == chip_name.lower():
self._device = device
break
else:
raise errors.JLinkException('Unsupported device was connected to.')
return None | python | def connect(self, chip_name, speed='auto', verbose=False):
"""Connects the J-Link to its target.
Args:
self (JLink): the ``JLink`` instance
chip_name (str): target chip name
speed (int): connection speed, one of ``{5-12000, 'auto', 'adaptive'}``
verbose (bool): boolean indicating if connection should be verbose in logging
Returns:
``None``
Raises:
JLinkException: if connection fails to establish.
TypeError: if given speed is invalid
"""
if verbose:
self.exec_command('EnableRemarks = 1')
# This is weird but is currently the only way to specify what the
# target is to the J-Link.
self.exec_command('Device = %s' % chip_name)
# Need to select target interface speed here, so the J-Link knows what
# speed to use to establish target communication.
if speed == 'auto':
self.set_speed(auto=True)
elif speed == 'adaptive':
self.set_speed(adaptive=True)
else:
self.set_speed(speed)
result = self._dll.JLINKARM_Connect()
if result < 0:
raise errors.JLinkException(result)
try:
# Issue a no-op command after connect. This has to be in a try-catch.
self.halted()
except errors.JLinkException:
pass
# Determine which device we are. This is essential for using methods
# like 'unlock' or 'lock'.
for index in range(self.num_supported_devices()):
device = self.supported_device(index)
if device.name.lower() == chip_name.lower():
self._device = device
break
else:
raise errors.JLinkException('Unsupported device was connected to.')
return None | [
"def",
"connect",
"(",
"self",
",",
"chip_name",
",",
"speed",
"=",
"'auto'",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"verbose",
":",
"self",
".",
"exec_command",
"(",
"'EnableRemarks = 1'",
")",
"# This is weird but is currently the only way to specify what t... | Connects the J-Link to its target.
Args:
self (JLink): the ``JLink`` instance
chip_name (str): target chip name
speed (int): connection speed, one of ``{5-12000, 'auto', 'adaptive'}``
verbose (bool): boolean indicating if connection should be verbose in logging
Returns:
``None``
Raises:
JLinkException: if connection fails to establish.
TypeError: if given speed is invalid | [
"Connects",
"the",
"J",
"-",
"Link",
"to",
"its",
"target",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L890-L943 | train | 230,891 |
square/pylink | pylink/jlink.py | JLink.compile_date | def compile_date(self):
"""Returns a string specifying the date and time at which the DLL was
translated.
Args:
self (JLink): the ``JLink`` instance
Returns:
Datetime string.
"""
result = self._dll.JLINKARM_GetCompileDateTime()
return ctypes.cast(result, ctypes.c_char_p).value.decode() | python | def compile_date(self):
"""Returns a string specifying the date and time at which the DLL was
translated.
Args:
self (JLink): the ``JLink`` instance
Returns:
Datetime string.
"""
result = self._dll.JLINKARM_GetCompileDateTime()
return ctypes.cast(result, ctypes.c_char_p).value.decode() | [
"def",
"compile_date",
"(",
"self",
")",
":",
"result",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_GetCompileDateTime",
"(",
")",
"return",
"ctypes",
".",
"cast",
"(",
"result",
",",
"ctypes",
".",
"c_char_p",
")",
".",
"value",
".",
"decode",
"(",
")"
] | Returns a string specifying the date and time at which the DLL was
translated.
Args:
self (JLink): the ``JLink`` instance
Returns:
Datetime string. | [
"Returns",
"a",
"string",
"specifying",
"the",
"date",
"and",
"time",
"at",
"which",
"the",
"DLL",
"was",
"translated",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L975-L986 | train | 230,892 |
square/pylink | pylink/jlink.py | JLink.version | def version(self):
"""Returns the device's version.
The device's version is returned as a string of the format: M.mr where
``M`` is major number, ``m`` is minor number, and ``r`` is revision
character.
Args:
self (JLink): the ``JLink`` instance
Returns:
Device version string.
"""
version = int(self._dll.JLINKARM_GetDLLVersion())
major = version / 10000
minor = (version / 100) % 100
rev = version % 100
rev = '' if rev == 0 else chr(rev + ord('a') - 1)
return '%d.%02d%s' % (major, minor, rev) | python | def version(self):
"""Returns the device's version.
The device's version is returned as a string of the format: M.mr where
``M`` is major number, ``m`` is minor number, and ``r`` is revision
character.
Args:
self (JLink): the ``JLink`` instance
Returns:
Device version string.
"""
version = int(self._dll.JLINKARM_GetDLLVersion())
major = version / 10000
minor = (version / 100) % 100
rev = version % 100
rev = '' if rev == 0 else chr(rev + ord('a') - 1)
return '%d.%02d%s' % (major, minor, rev) | [
"def",
"version",
"(",
"self",
")",
":",
"version",
"=",
"int",
"(",
"self",
".",
"_dll",
".",
"JLINKARM_GetDLLVersion",
"(",
")",
")",
"major",
"=",
"version",
"/",
"10000",
"minor",
"=",
"(",
"version",
"/",
"100",
")",
"%",
"100",
"rev",
"=",
"v... | Returns the device's version.
The device's version is returned as a string of the format: M.mr where
``M`` is major number, ``m`` is minor number, and ``r`` is revision
character.
Args:
self (JLink): the ``JLink`` instance
Returns:
Device version string. | [
"Returns",
"the",
"device",
"s",
"version",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L989-L1007 | train | 230,893 |
square/pylink | pylink/jlink.py | JLink.compatible_firmware_version | def compatible_firmware_version(self):
"""Returns the DLL's compatible J-Link firmware version.
Args:
self (JLink): the ``JLink`` instance
Returns:
The firmware version of the J-Link that the DLL is compatible
with.
Raises:
JLinkException: on error.
"""
identifier = self.firmware_version.split('compiled')[0]
buf_size = self.MAX_BUF_SIZE
buf = (ctypes.c_char * buf_size)()
res = self._dll.JLINKARM_GetEmbeddedFWString(identifier.encode(), buf, buf_size)
if res < 0:
raise errors.JLinkException(res)
return ctypes.string_at(buf).decode() | python | def compatible_firmware_version(self):
"""Returns the DLL's compatible J-Link firmware version.
Args:
self (JLink): the ``JLink`` instance
Returns:
The firmware version of the J-Link that the DLL is compatible
with.
Raises:
JLinkException: on error.
"""
identifier = self.firmware_version.split('compiled')[0]
buf_size = self.MAX_BUF_SIZE
buf = (ctypes.c_char * buf_size)()
res = self._dll.JLINKARM_GetEmbeddedFWString(identifier.encode(), buf, buf_size)
if res < 0:
raise errors.JLinkException(res)
return ctypes.string_at(buf).decode() | [
"def",
"compatible_firmware_version",
"(",
"self",
")",
":",
"identifier",
"=",
"self",
".",
"firmware_version",
".",
"split",
"(",
"'compiled'",
")",
"[",
"0",
"]",
"buf_size",
"=",
"self",
".",
"MAX_BUF_SIZE",
"buf",
"=",
"(",
"ctypes",
".",
"c_char",
"*... | Returns the DLL's compatible J-Link firmware version.
Args:
self (JLink): the ``JLink`` instance
Returns:
The firmware version of the J-Link that the DLL is compatible
with.
Raises:
JLinkException: on error. | [
"Returns",
"the",
"DLL",
"s",
"compatible",
"J",
"-",
"Link",
"firmware",
"version",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1011-L1031 | train | 230,894 |
square/pylink | pylink/jlink.py | JLink.firmware_outdated | def firmware_outdated(self):
"""Returns whether the J-Link's firmware version is older than the one
that the DLL is compatible with.
Note:
This is not the same as calling ``not jlink.firmware_newer()``.
Args:
self (JLink): the ``JLink`` instance
Returns:
``True`` if the J-Link's firmware is older than the one supported by
the DLL, otherwise ``False``.
"""
datefmt = ' %b %d %Y %H:%M:%S'
compat_date = self.compatible_firmware_version.split('compiled')[1]
compat_date = datetime.datetime.strptime(compat_date, datefmt)
fw_date = self.firmware_version.split('compiled')[1]
fw_date = datetime.datetime.strptime(fw_date, datefmt)
return (compat_date > fw_date) | python | def firmware_outdated(self):
"""Returns whether the J-Link's firmware version is older than the one
that the DLL is compatible with.
Note:
This is not the same as calling ``not jlink.firmware_newer()``.
Args:
self (JLink): the ``JLink`` instance
Returns:
``True`` if the J-Link's firmware is older than the one supported by
the DLL, otherwise ``False``.
"""
datefmt = ' %b %d %Y %H:%M:%S'
compat_date = self.compatible_firmware_version.split('compiled')[1]
compat_date = datetime.datetime.strptime(compat_date, datefmt)
fw_date = self.firmware_version.split('compiled')[1]
fw_date = datetime.datetime.strptime(fw_date, datefmt)
return (compat_date > fw_date) | [
"def",
"firmware_outdated",
"(",
"self",
")",
":",
"datefmt",
"=",
"' %b %d %Y %H:%M:%S'",
"compat_date",
"=",
"self",
".",
"compatible_firmware_version",
".",
"split",
"(",
"'compiled'",
")",
"[",
"1",
"]",
"compat_date",
"=",
"datetime",
".",
"datetime",
".",
... | Returns whether the J-Link's firmware version is older than the one
that the DLL is compatible with.
Note:
This is not the same as calling ``not jlink.firmware_newer()``.
Args:
self (JLink): the ``JLink`` instance
Returns:
``True`` if the J-Link's firmware is older than the one supported by
the DLL, otherwise ``False``. | [
"Returns",
"whether",
"the",
"J",
"-",
"Link",
"s",
"firmware",
"version",
"is",
"older",
"than",
"the",
"one",
"that",
"the",
"DLL",
"is",
"compatible",
"with",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1034-L1055 | train | 230,895 |
square/pylink | pylink/jlink.py | JLink.hardware_info | def hardware_info(self, mask=0xFFFFFFFF):
"""Returns a list of 32 integer values corresponding to the bitfields
specifying the power consumption of the target.
The values returned by this function only have significance if the
J-Link is powering the target.
The words, indexed, have the following significance:
0. If ``1``, target is powered via J-Link.
1. Overcurrent bitfield:
0: No overcurrent.
1: Overcurrent happened. 2ms @ 3000mA
2: Overcurrent happened. 10ms @ 1000mA
3: Overcurrent happened. 40ms @ 400mA
2. Power consumption of target (mA).
3. Peak of target power consumption (mA).
4. Peak of target power consumption during J-Link operation (mA).
Args:
self (JLink): the ``JLink`` instance
mask (int): bit mask to decide which hardware information words are
returned (defaults to all the words).
Returns:
List of bitfields specifying different states based on their index
within the list and their value.
Raises:
JLinkException: on hardware error.
"""
buf = (ctypes.c_uint32 * 32)()
res = self._dll.JLINKARM_GetHWInfo(mask, ctypes.byref(buf))
if res != 0:
raise errors.JLinkException(res)
return list(buf) | python | def hardware_info(self, mask=0xFFFFFFFF):
"""Returns a list of 32 integer values corresponding to the bitfields
specifying the power consumption of the target.
The values returned by this function only have significance if the
J-Link is powering the target.
The words, indexed, have the following significance:
0. If ``1``, target is powered via J-Link.
1. Overcurrent bitfield:
0: No overcurrent.
1: Overcurrent happened. 2ms @ 3000mA
2: Overcurrent happened. 10ms @ 1000mA
3: Overcurrent happened. 40ms @ 400mA
2. Power consumption of target (mA).
3. Peak of target power consumption (mA).
4. Peak of target power consumption during J-Link operation (mA).
Args:
self (JLink): the ``JLink`` instance
mask (int): bit mask to decide which hardware information words are
returned (defaults to all the words).
Returns:
List of bitfields specifying different states based on their index
within the list and their value.
Raises:
JLinkException: on hardware error.
"""
buf = (ctypes.c_uint32 * 32)()
res = self._dll.JLINKARM_GetHWInfo(mask, ctypes.byref(buf))
if res != 0:
raise errors.JLinkException(res)
return list(buf) | [
"def",
"hardware_info",
"(",
"self",
",",
"mask",
"=",
"0xFFFFFFFF",
")",
":",
"buf",
"=",
"(",
"ctypes",
".",
"c_uint32",
"*",
"32",
")",
"(",
")",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_GetHWInfo",
"(",
"mask",
",",
"ctypes",
".",
"byref",... | Returns a list of 32 integer values corresponding to the bitfields
specifying the power consumption of the target.
The values returned by this function only have significance if the
J-Link is powering the target.
The words, indexed, have the following significance:
0. If ``1``, target is powered via J-Link.
1. Overcurrent bitfield:
0: No overcurrent.
1: Overcurrent happened. 2ms @ 3000mA
2: Overcurrent happened. 10ms @ 1000mA
3: Overcurrent happened. 40ms @ 400mA
2. Power consumption of target (mA).
3. Peak of target power consumption (mA).
4. Peak of target power consumption during J-Link operation (mA).
Args:
self (JLink): the ``JLink`` instance
mask (int): bit mask to decide which hardware information words are
returned (defaults to all the words).
Returns:
List of bitfields specifying different states based on their index
within the list and their value.
Raises:
JLinkException: on hardware error. | [
"Returns",
"a",
"list",
"of",
"32",
"integer",
"values",
"corresponding",
"to",
"the",
"bitfields",
"specifying",
"the",
"power",
"consumption",
"of",
"the",
"target",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1078-L1112 | train | 230,896 |
square/pylink | pylink/jlink.py | JLink.hardware_status | def hardware_status(self):
"""Retrieves and returns the hardware status.
Args:
self (JLink): the ``JLink`` instance
Returns:
A ``JLinkHardwareStatus`` describing the J-Link hardware.
"""
stat = structs.JLinkHardwareStatus()
res = self._dll.JLINKARM_GetHWStatus(ctypes.byref(stat))
if res == 1:
raise errors.JLinkException('Error in reading hardware status.')
return stat | python | def hardware_status(self):
"""Retrieves and returns the hardware status.
Args:
self (JLink): the ``JLink`` instance
Returns:
A ``JLinkHardwareStatus`` describing the J-Link hardware.
"""
stat = structs.JLinkHardwareStatus()
res = self._dll.JLINKARM_GetHWStatus(ctypes.byref(stat))
if res == 1:
raise errors.JLinkException('Error in reading hardware status.')
return stat | [
"def",
"hardware_status",
"(",
"self",
")",
":",
"stat",
"=",
"structs",
".",
"JLinkHardwareStatus",
"(",
")",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_GetHWStatus",
"(",
"ctypes",
".",
"byref",
"(",
"stat",
")",
")",
"if",
"res",
"==",
"1",
":"... | Retrieves and returns the hardware status.
Args:
self (JLink): the ``JLink`` instance
Returns:
A ``JLinkHardwareStatus`` describing the J-Link hardware. | [
"Retrieves",
"and",
"returns",
"the",
"hardware",
"status",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1116-L1129 | train | 230,897 |
square/pylink | pylink/jlink.py | JLink.hardware_version | def hardware_version(self):
"""Returns the hardware version of the connected J-Link as a
major.minor string.
Args:
self (JLink): the ``JLink`` instance
Returns:
Hardware version string.
"""
version = self._dll.JLINKARM_GetHardwareVersion()
major = version / 10000 % 100
minor = version / 100 % 100
return '%d.%02d' % (major, minor) | python | def hardware_version(self):
"""Returns the hardware version of the connected J-Link as a
major.minor string.
Args:
self (JLink): the ``JLink`` instance
Returns:
Hardware version string.
"""
version = self._dll.JLINKARM_GetHardwareVersion()
major = version / 10000 % 100
minor = version / 100 % 100
return '%d.%02d' % (major, minor) | [
"def",
"hardware_version",
"(",
"self",
")",
":",
"version",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_GetHardwareVersion",
"(",
")",
"major",
"=",
"version",
"/",
"10000",
"%",
"100",
"minor",
"=",
"version",
"/",
"100",
"%",
"100",
"return",
"'%d.%02d'",
... | Returns the hardware version of the connected J-Link as a
major.minor string.
Args:
self (JLink): the ``JLink`` instance
Returns:
Hardware version string. | [
"Returns",
"the",
"hardware",
"version",
"of",
"the",
"connected",
"J",
"-",
"Link",
"as",
"a",
"major",
".",
"minor",
"string",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1133-L1146 | train | 230,898 |
square/pylink | pylink/jlink.py | JLink.firmware_version | def firmware_version(self):
"""Returns a firmware identification string of the connected J-Link.
It consists of the following:
- Product Name (e.g. J-Link)
- The string: compiled
- Compile data and time.
- Optional additional information.
Args:
self (JLink): the ``JLink`` instance
Returns:
Firmware identification string.
"""
buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
self._dll.JLINKARM_GetFirmwareString(buf, self.MAX_BUF_SIZE)
return ctypes.string_at(buf).decode() | python | def firmware_version(self):
"""Returns a firmware identification string of the connected J-Link.
It consists of the following:
- Product Name (e.g. J-Link)
- The string: compiled
- Compile data and time.
- Optional additional information.
Args:
self (JLink): the ``JLink`` instance
Returns:
Firmware identification string.
"""
buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
self._dll.JLINKARM_GetFirmwareString(buf, self.MAX_BUF_SIZE)
return ctypes.string_at(buf).decode() | [
"def",
"firmware_version",
"(",
"self",
")",
":",
"buf",
"=",
"(",
"ctypes",
".",
"c_char",
"*",
"self",
".",
"MAX_BUF_SIZE",
")",
"(",
")",
"self",
".",
"_dll",
".",
"JLINKARM_GetFirmwareString",
"(",
"buf",
",",
"self",
".",
"MAX_BUF_SIZE",
")",
"retur... | Returns a firmware identification string of the connected J-Link.
It consists of the following:
- Product Name (e.g. J-Link)
- The string: compiled
- Compile data and time.
- Optional additional information.
Args:
self (JLink): the ``JLink`` instance
Returns:
Firmware identification string. | [
"Returns",
"a",
"firmware",
"identification",
"string",
"of",
"the",
"connected",
"J",
"-",
"Link",
"."
] | 81dda0a191d923a8b2627c52cb778aba24d279d7 | https://github.com/square/pylink/blob/81dda0a191d923a8b2627c52cb778aba24d279d7/pylink/jlink.py#L1150-L1167 | train | 230,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.