partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
KafkaConsumer.seek_to_end
Seek to the most recent available offset for partitions. Arguments: *partitions: Optionally provide specific TopicPartitions, otherwise default to all assigned partitions. Raises: AssertionError: If any partition is not currently assigned, or if ...
kafka/consumer/group.py
def seek_to_end(self, *partitions): """Seek to the most recent available offset for partitions. Arguments: *partitions: Optionally provide specific TopicPartitions, otherwise default to all assigned partitions. Raises: AssertionError: If any partition is...
def seek_to_end(self, *partitions): """Seek to the most recent available offset for partitions. Arguments: *partitions: Optionally provide specific TopicPartitions, otherwise default to all assigned partitions. Raises: AssertionError: If any partition is...
[ "Seek", "to", "the", "most", "recent", "available", "offset", "for", "partitions", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L801-L823
[ "def", "seek_to_end", "(", "self", ",", "*", "partitions", ")", ":", "if", "not", "all", "(", "[", "isinstance", "(", "p", ",", "TopicPartition", ")", "for", "p", "in", "partitions", "]", ")", ":", "raise", "TypeError", "(", "'partitions must be TopicParti...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer.subscribe
Subscribe to a list of topics, or a topic regex pattern. Partitions will be dynamically assigned via a group coordinator. Topic subscriptions are not incremental: this list will replace the current assignment (if there is one). This method is incompatible with :meth:`~kafka.KafkaConsum...
kafka/consumer/group.py
def subscribe(self, topics=(), pattern=None, listener=None): """Subscribe to a list of topics, or a topic regex pattern. Partitions will be dynamically assigned via a group coordinator. Topic subscriptions are not incremental: this list will replace the current assignment (if there is o...
def subscribe(self, topics=(), pattern=None, listener=None): """Subscribe to a list of topics, or a topic regex pattern. Partitions will be dynamically assigned via a group coordinator. Topic subscriptions are not incremental: this list will replace the current assignment (if there is o...
[ "Subscribe", "to", "a", "list", "of", "topics", "or", "a", "topic", "regex", "pattern", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L825-L880
[ "def", "subscribe", "(", "self", ",", "topics", "=", "(", ")", ",", "pattern", "=", "None", ",", "listener", "=", "None", ")", ":", "# SubscriptionState handles error checking", "self", ".", "_subscription", ".", "subscribe", "(", "topics", "=", "topics", ",...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer.unsubscribe
Unsubscribe from all topics and clear all assigned partitions.
kafka/consumer/group.py
def unsubscribe(self): """Unsubscribe from all topics and clear all assigned partitions.""" self._subscription.unsubscribe() self._coordinator.close() self._client.cluster.need_all_topic_metadata = False self._client.set_topics([]) log.debug("Unsubscribed all topics or pa...
def unsubscribe(self): """Unsubscribe from all topics and clear all assigned partitions.""" self._subscription.unsubscribe() self._coordinator.close() self._client.cluster.need_all_topic_metadata = False self._client.set_topics([]) log.debug("Unsubscribed all topics or pa...
[ "Unsubscribe", "from", "all", "topics", "and", "clear", "all", "assigned", "partitions", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L892-L898
[ "def", "unsubscribe", "(", "self", ")", ":", "self", ".", "_subscription", ".", "unsubscribe", "(", ")", "self", ".", "_coordinator", ".", "close", "(", ")", "self", ".", "_client", ".", "cluster", ".", "need_all_topic_metadata", "=", "False", "self", ".",...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer.offsets_for_times
Look up the offsets for the given partitions by timestamp. The returned offset for each partition is the earliest offset whose timestamp is greater than or equal to the given timestamp in the corresponding partition. This is a blocking call. The consumer does not have to be assigned the...
kafka/consumer/group.py
def offsets_for_times(self, timestamps): """Look up the offsets for the given partitions by timestamp. The returned offset for each partition is the earliest offset whose timestamp is greater than or equal to the given timestamp in the corresponding partition. This is a blocking...
def offsets_for_times(self, timestamps): """Look up the offsets for the given partitions by timestamp. The returned offset for each partition is the earliest offset whose timestamp is greater than or equal to the given timestamp in the corresponding partition. This is a blocking...
[ "Look", "up", "the", "offsets", "for", "the", "given", "partitions", "by", "timestamp", ".", "The", "returned", "offset", "for", "each", "partition", "is", "the", "earliest", "offset", "whose", "timestamp", "is", "greater", "than", "or", "equal", "to", "the"...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L922-L966
[ "def", "offsets_for_times", "(", "self", ",", "timestamps", ")", ":", "if", "self", ".", "config", "[", "'api_version'", "]", "<=", "(", "0", ",", "10", ",", "0", ")", ":", "raise", "UnsupportedVersionError", "(", "\"offsets_for_times API not supported for clust...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer.beginning_offsets
Get the first offset for the given partitions. This method does not change the current consumer position of the partitions. Note: This method may block indefinitely if the partition does not exist. Arguments: partitions (list): List of TopicPartition instances ...
kafka/consumer/group.py
def beginning_offsets(self, partitions): """Get the first offset for the given partitions. This method does not change the current consumer position of the partitions. Note: This method may block indefinitely if the partition does not exist. Arguments: ...
def beginning_offsets(self, partitions): """Get the first offset for the given partitions. This method does not change the current consumer position of the partitions. Note: This method may block indefinitely if the partition does not exist. Arguments: ...
[ "Get", "the", "first", "offset", "for", "the", "given", "partitions", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L968-L992
[ "def", "beginning_offsets", "(", "self", ",", "partitions", ")", ":", "offsets", "=", "self", ".", "_fetcher", ".", "beginning_offsets", "(", "partitions", ",", "self", ".", "config", "[", "'request_timeout_ms'", "]", ")", "return", "offsets" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer.end_offsets
Get the last offset for the given partitions. The last offset of a partition is the offset of the upcoming message, i.e. the offset of the last available message + 1. This method does not change the current consumer position of the partitions. Note: This method may ...
kafka/consumer/group.py
def end_offsets(self, partitions): """Get the last offset for the given partitions. The last offset of a partition is the offset of the upcoming message, i.e. the offset of the last available message + 1. This method does not change the current consumer position of the partition...
def end_offsets(self, partitions): """Get the last offset for the given partitions. The last offset of a partition is the offset of the upcoming message, i.e. the offset of the last available message + 1. This method does not change the current consumer position of the partition...
[ "Get", "the", "last", "offset", "for", "the", "given", "partitions", ".", "The", "last", "offset", "of", "a", "partition", "is", "the", "offset", "of", "the", "upcoming", "message", "i", ".", "e", ".", "the", "offset", "of", "the", "last", "available", ...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L994-L1019
[ "def", "end_offsets", "(", "self", ",", "partitions", ")", ":", "offsets", "=", "self", ".", "_fetcher", ".", "end_offsets", "(", "partitions", ",", "self", ".", "config", "[", "'request_timeout_ms'", "]", ")", "return", "offsets" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer._use_consumer_group
Return True iff this consumer can/should join a broker-coordinated group.
kafka/consumer/group.py
def _use_consumer_group(self): """Return True iff this consumer can/should join a broker-coordinated group.""" if self.config['api_version'] < (0, 9): return False elif self.config['group_id'] is None: return False elif not self._subscription.partitions_auto_assig...
def _use_consumer_group(self): """Return True iff this consumer can/should join a broker-coordinated group.""" if self.config['api_version'] < (0, 9): return False elif self.config['group_id'] is None: return False elif not self._subscription.partitions_auto_assig...
[ "Return", "True", "iff", "this", "consumer", "can", "/", "should", "join", "a", "broker", "-", "coordinated", "group", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L1021-L1029
[ "def", "_use_consumer_group", "(", "self", ")", ":", "if", "self", ".", "config", "[", "'api_version'", "]", "<", "(", "0", ",", "9", ")", ":", "return", "False", "elif", "self", ".", "config", "[", "'group_id'", "]", "is", "None", ":", "return", "Fa...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaConsumer._update_fetch_positions
Set the fetch position to the committed position (if there is one) or reset it using the offset reset policy the user has configured. Arguments: partitions (List[TopicPartition]): The partitions that need updating fetch positions. Raises: NoOffsetForPart...
kafka/consumer/group.py
def _update_fetch_positions(self, partitions): """Set the fetch position to the committed position (if there is one) or reset it using the offset reset policy the user has configured. Arguments: partitions (List[TopicPartition]): The partitions that need updating fet...
def _update_fetch_positions(self, partitions): """Set the fetch position to the committed position (if there is one) or reset it using the offset reset policy the user has configured. Arguments: partitions (List[TopicPartition]): The partitions that need updating fet...
[ "Set", "the", "fetch", "position", "to", "the", "committed", "position", "(", "if", "there", "is", "one", ")", "or", "reset", "it", "using", "the", "offset", "reset", "policy", "the", "user", "has", "configured", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/consumer/group.py#L1031-L1059
[ "def", "_update_fetch_positions", "(", "self", ",", "partitions", ")", ":", "# Lookup any positions for partitions which are awaiting reset (which may be the", "# case if the user called :meth:`seek_to_beginning` or :meth:`seek_to_end`. We do", "# this check first to avoid an unnecessary lookup ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
DictReporter.snapshot
Return a nested dictionary snapshot of all metrics and their values at this time. Example: { 'category': { 'metric1_name': 42.0, 'metric2_name': 'foo' } }
kafka/metrics/dict_reporter.py
def snapshot(self): """ Return a nested dictionary snapshot of all metrics and their values at this time. Example: { 'category': { 'metric1_name': 42.0, 'metric2_name': 'foo' } } """ return dict((category, di...
def snapshot(self): """ Return a nested dictionary snapshot of all metrics and their values at this time. Example: { 'category': { 'metric1_name': 42.0, 'metric2_name': 'foo' } } """ return dict((category, di...
[ "Return", "a", "nested", "dictionary", "snapshot", "of", "all", "metrics", "and", "their", "values", "at", "this", "time", ".", "Example", ":", "{", "category", ":", "{", "metric1_name", ":", "42", ".", "0", "metric2_name", ":", "foo", "}", "}" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/metrics/dict_reporter.py#L21-L35
[ "def", "snapshot", "(", "self", ")", ":", "return", "dict", "(", "(", "category", ",", "dict", "(", "(", "name", ",", "metric", ".", "value", "(", ")", ")", "for", "name", ",", "metric", "in", "list", "(", "metrics", ".", "items", "(", ")", ")", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
DictReporter.get_category
Return a string category for the metric. The category is made up of this reporter's prefix and the metric's group and tags. Examples: prefix = 'foo', group = 'bar', tags = {'a': 1, 'b': 2} returns: 'foo.bar.a=1,b=2' prefix = 'foo', group = 'bar', tags = Non...
kafka/metrics/dict_reporter.py
def get_category(self, metric): """ Return a string category for the metric. The category is made up of this reporter's prefix and the metric's group and tags. Examples: prefix = 'foo', group = 'bar', tags = {'a': 1, 'b': 2} returns: 'foo.bar.a=1,b=2' ...
def get_category(self, metric): """ Return a string category for the metric. The category is made up of this reporter's prefix and the metric's group and tags. Examples: prefix = 'foo', group = 'bar', tags = {'a': 1, 'b': 2} returns: 'foo.bar.a=1,b=2' ...
[ "Return", "a", "string", "category", "for", "the", "metric", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/metrics/dict_reporter.py#L57-L77
[ "def", "get_category", "(", "self", ",", "metric", ")", ":", "tags", "=", "','", ".", "join", "(", "'%s=%s'", "%", "(", "k", ",", "v", ")", "for", "k", ",", "v", "in", "sorted", "(", "metric", ".", "metric_name", ".", "tags", ".", "items", "(", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.maybe_connect
Queues a node for asynchronous connection during the next .poll()
kafka/client_async.py
def maybe_connect(self, node_id, wakeup=True): """Queues a node for asynchronous connection during the next .poll()""" if self._can_connect(node_id): self._connecting.add(node_id) # Wakeup signal is useful in case another thread is # blocked waiting for incoming netwo...
def maybe_connect(self, node_id, wakeup=True): """Queues a node for asynchronous connection during the next .poll()""" if self._can_connect(node_id): self._connecting.add(node_id) # Wakeup signal is useful in case another thread is # blocked waiting for incoming netwo...
[ "Queues", "a", "node", "for", "asynchronous", "connection", "during", "the", "next", ".", "poll", "()" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L329-L339
[ "def", "maybe_connect", "(", "self", ",", "node_id", ",", "wakeup", "=", "True", ")", ":", "if", "self", ".", "_can_connect", "(", "node_id", ")", ":", "self", ".", "_connecting", ".", "add", "(", "node_id", ")", "# Wakeup signal is useful in case another thre...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient._maybe_connect
Idempotent non-blocking connection attempt to the given node id.
kafka/client_async.py
def _maybe_connect(self, node_id): """Idempotent non-blocking connection attempt to the given node id.""" with self._lock: conn = self._conns.get(node_id) if conn is None: broker = self.cluster.broker_metadata(node_id) assert broker, 'Broker id %s...
def _maybe_connect(self, node_id): """Idempotent non-blocking connection attempt to the given node id.""" with self._lock: conn = self._conns.get(node_id) if conn is None: broker = self.cluster.broker_metadata(node_id) assert broker, 'Broker id %s...
[ "Idempotent", "non", "-", "blocking", "connection", "attempt", "to", "the", "given", "node", "id", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L360-L388
[ "def", "_maybe_connect", "(", "self", ",", "node_id", ")", ":", "with", "self", ".", "_lock", ":", "conn", "=", "self", ".", "_conns", ".", "get", "(", "node_id", ")", "if", "conn", "is", "None", ":", "broker", "=", "self", ".", "cluster", ".", "br...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.ready
Check whether a node is connected and ok to send more requests. Arguments: node_id (int): the id of the node to check metadata_priority (bool): Mark node as not-ready if a metadata refresh is required. Default: True Returns: bool: True if we are read...
kafka/client_async.py
def ready(self, node_id, metadata_priority=True): """Check whether a node is connected and ok to send more requests. Arguments: node_id (int): the id of the node to check metadata_priority (bool): Mark node as not-ready if a metadata refresh is required. Default:...
def ready(self, node_id, metadata_priority=True): """Check whether a node is connected and ok to send more requests. Arguments: node_id (int): the id of the node to check metadata_priority (bool): Mark node as not-ready if a metadata refresh is required. Default:...
[ "Check", "whether", "a", "node", "is", "connected", "and", "ok", "to", "send", "more", "requests", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L390-L402
[ "def", "ready", "(", "self", ",", "node_id", ",", "metadata_priority", "=", "True", ")", ":", "self", ".", "maybe_connect", "(", "node_id", ")", "return", "self", ".", "is_ready", "(", "node_id", ",", "metadata_priority", "=", "metadata_priority", ")" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.connected
Return True iff the node_id is connected.
kafka/client_async.py
def connected(self, node_id): """Return True iff the node_id is connected.""" conn = self._conns.get(node_id) if conn is None: return False return conn.connected()
def connected(self, node_id): """Return True iff the node_id is connected.""" conn = self._conns.get(node_id) if conn is None: return False return conn.connected()
[ "Return", "True", "iff", "the", "node_id", "is", "connected", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L404-L409
[ "def", "connected", "(", "self", ",", "node_id", ")", ":", "conn", "=", "self", ".", "_conns", ".", "get", "(", "node_id", ")", "if", "conn", "is", "None", ":", "return", "False", "return", "conn", ".", "connected", "(", ")" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.close
Close one or all broker connections. Arguments: node_id (int, optional): the id of the node to close
kafka/client_async.py
def close(self, node_id=None): """Close one or all broker connections. Arguments: node_id (int, optional): the id of the node to close """ with self._lock: if node_id is None: self._close() conns = list(self._conns.values()) ...
def close(self, node_id=None): """Close one or all broker connections. Arguments: node_id (int, optional): the id of the node to close """ with self._lock: if node_id is None: self._close() conns = list(self._conns.values()) ...
[ "Close", "one", "or", "all", "broker", "connections", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L418-L435
[ "def", "close", "(", "self", ",", "node_id", "=", "None", ")", ":", "with", "self", ".", "_lock", ":", "if", "node_id", "is", "None", ":", "self", ".", "_close", "(", ")", "conns", "=", "list", "(", "self", ".", "_conns", ".", "values", "(", ")",...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.is_disconnected
Check whether the node connection has been disconnected or failed. A disconnected node has either been closed or has failed. Connection failures are usually transient and can be resumed in the next ready() call, but there are cases where transient failures need to be caught and re-acted...
kafka/client_async.py
def is_disconnected(self, node_id): """Check whether the node connection has been disconnected or failed. A disconnected node has either been closed or has failed. Connection failures are usually transient and can be resumed in the next ready() call, but there are cases where transient ...
def is_disconnected(self, node_id): """Check whether the node connection has been disconnected or failed. A disconnected node has either been closed or has failed. Connection failures are usually transient and can be resumed in the next ready() call, but there are cases where transient ...
[ "Check", "whether", "the", "node", "connection", "has", "been", "disconnected", "or", "failed", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L440-L457
[ "def", "is_disconnected", "(", "self", ",", "node_id", ")", ":", "conn", "=", "self", ".", "_conns", ".", "get", "(", "node_id", ")", "if", "conn", "is", "None", ":", "return", "False", "return", "conn", ".", "disconnected", "(", ")" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.connection_delay
Return the number of milliseconds to wait, based on the connection state, before attempting to send data. When disconnected, this respects the reconnect backoff time. When connecting, returns 0 to allow non-blocking connect to finish. When connected, returns a very large number to handle...
kafka/client_async.py
def connection_delay(self, node_id): """ Return the number of milliseconds to wait, based on the connection state, before attempting to send data. When disconnected, this respects the reconnect backoff time. When connecting, returns 0 to allow non-blocking connect to finish. When...
def connection_delay(self, node_id): """ Return the number of milliseconds to wait, based on the connection state, before attempting to send data. When disconnected, this respects the reconnect backoff time. When connecting, returns 0 to allow non-blocking connect to finish. When...
[ "Return", "the", "number", "of", "milliseconds", "to", "wait", "based", "on", "the", "connection", "state", "before", "attempting", "to", "send", "data", ".", "When", "disconnected", "this", "respects", "the", "reconnect", "backoff", "time", ".", "When", "conn...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L459-L476
[ "def", "connection_delay", "(", "self", ",", "node_id", ")", ":", "conn", "=", "self", ".", "_conns", ".", "get", "(", "node_id", ")", "if", "conn", "is", "None", ":", "return", "0", "return", "conn", ".", "connection_delay", "(", ")" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.is_ready
Check whether a node is ready to send more requests. In addition to connection-level checks, this method also is used to block additional requests from being sent during a metadata refresh. Arguments: node_id (int): id of the node to check metadata_priority (bool): Mark...
kafka/client_async.py
def is_ready(self, node_id, metadata_priority=True): """Check whether a node is ready to send more requests. In addition to connection-level checks, this method also is used to block additional requests from being sent during a metadata refresh. Arguments: node_id (int): id...
def is_ready(self, node_id, metadata_priority=True): """Check whether a node is ready to send more requests. In addition to connection-level checks, this method also is used to block additional requests from being sent during a metadata refresh. Arguments: node_id (int): id...
[ "Check", "whether", "a", "node", "is", "ready", "to", "send", "more", "requests", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L478-L502
[ "def", "is_ready", "(", "self", ",", "node_id", ",", "metadata_priority", "=", "True", ")", ":", "if", "not", "self", ".", "_can_send_request", "(", "node_id", ")", ":", "return", "False", "# if we need to update our metadata now declare all requests unready to", "# m...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.send
Send a request to a specific node. Bytes are placed on an internal per-connection send-queue. Actual network I/O will be triggered in a subsequent call to .poll() Arguments: node_id (int): destination node request (Struct): request object (not-encoded) wakeup...
kafka/client_async.py
def send(self, node_id, request, wakeup=True): """Send a request to a specific node. Bytes are placed on an internal per-connection send-queue. Actual network I/O will be triggered in a subsequent call to .poll() Arguments: node_id (int): destination node request...
def send(self, node_id, request, wakeup=True): """Send a request to a specific node. Bytes are placed on an internal per-connection send-queue. Actual network I/O will be triggered in a subsequent call to .poll() Arguments: node_id (int): destination node request...
[ "Send", "a", "request", "to", "a", "specific", "node", ".", "Bytes", "are", "placed", "on", "an", "internal", "per", "-", "connection", "send", "-", "queue", ".", "Actual", "network", "I", "/", "O", "will", "be", "triggered", "in", "a", "subsequent", "...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L510-L542
[ "def", "send", "(", "self", ",", "node_id", ",", "request", ",", "wakeup", "=", "True", ")", ":", "conn", "=", "self", ".", "_conns", ".", "get", "(", "node_id", ")", "if", "not", "conn", "or", "not", "self", ".", "_can_send_request", "(", "node_id",...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.poll
Try to read and write to sockets. This method will also attempt to complete node connections, refresh stale metadata, and run previously-scheduled tasks. Arguments: timeout_ms (int, optional): maximum amount of time to wait (in ms) for at least one response. Must be...
kafka/client_async.py
def poll(self, timeout_ms=None, future=None): """Try to read and write to sockets. This method will also attempt to complete node connections, refresh stale metadata, and run previously-scheduled tasks. Arguments: timeout_ms (int, optional): maximum amount of time to wait (...
def poll(self, timeout_ms=None, future=None): """Try to read and write to sockets. This method will also attempt to complete node connections, refresh stale metadata, and run previously-scheduled tasks. Arguments: timeout_ms (int, optional): maximum amount of time to wait (...
[ "Try", "to", "read", "and", "write", "to", "sockets", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L544-L602
[ "def", "poll", "(", "self", ",", "timeout_ms", "=", "None", ",", "future", "=", "None", ")", ":", "if", "future", "is", "not", "None", ":", "timeout_ms", "=", "100", "elif", "timeout_ms", "is", "None", ":", "timeout_ms", "=", "self", ".", "config", "...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.in_flight_request_count
Get the number of in-flight requests for a node or all nodes. Arguments: node_id (int, optional): a specific node to check. If unspecified, return the total for all nodes Returns: int: pending in-flight requests for the node, or all nodes if None
kafka/client_async.py
def in_flight_request_count(self, node_id=None): """Get the number of in-flight requests for a node or all nodes. Arguments: node_id (int, optional): a specific node to check. If unspecified, return the total for all nodes Returns: int: pending in-flight...
def in_flight_request_count(self, node_id=None): """Get the number of in-flight requests for a node or all nodes. Arguments: node_id (int, optional): a specific node to check. If unspecified, return the total for all nodes Returns: int: pending in-flight...
[ "Get", "the", "number", "of", "in", "-", "flight", "requests", "for", "a", "node", "or", "all", "nodes", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L671-L688
[ "def", "in_flight_request_count", "(", "self", ",", "node_id", "=", "None", ")", ":", "if", "node_id", "is", "not", "None", ":", "conn", "=", "self", ".", "_conns", ".", "get", "(", "node_id", ")", "if", "conn", "is", "None", ":", "return", "0", "ret...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.least_loaded_node
Choose the node with fewest outstanding requests, with fallbacks. This method will prefer a node with an existing connection and no in-flight-requests. If no such node is found, a node will be chosen randomly from disconnected nodes that are not "blacked out" (i.e., are not subject to a...
kafka/client_async.py
def least_loaded_node(self): """Choose the node with fewest outstanding requests, with fallbacks. This method will prefer a node with an existing connection and no in-flight-requests. If no such node is found, a node will be chosen randomly from disconnected nodes that are not "blacked ...
def least_loaded_node(self): """Choose the node with fewest outstanding requests, with fallbacks. This method will prefer a node with an existing connection and no in-flight-requests. If no such node is found, a node will be chosen randomly from disconnected nodes that are not "blacked ...
[ "Choose", "the", "node", "with", "fewest", "outstanding", "requests", "with", "fallbacks", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L704-L738
[ "def", "least_loaded_node", "(", "self", ")", ":", "nodes", "=", "[", "broker", ".", "nodeId", "for", "broker", "in", "self", ".", "cluster", ".", "brokers", "(", ")", "]", "random", ".", "shuffle", "(", "nodes", ")", "inflight", "=", "float", "(", "...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.set_topics
Set specific topics to track for metadata. Arguments: topics (list of str): topics to check for metadata Returns: Future: resolves after metadata request/response
kafka/client_async.py
def set_topics(self, topics): """Set specific topics to track for metadata. Arguments: topics (list of str): topics to check for metadata Returns: Future: resolves after metadata request/response """ if set(topics).difference(self._topics): f...
def set_topics(self, topics): """Set specific topics to track for metadata. Arguments: topics (list of str): topics to check for metadata Returns: Future: resolves after metadata request/response """ if set(topics).difference(self._topics): f...
[ "Set", "specific", "topics", "to", "track", "for", "metadata", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L740-L754
[ "def", "set_topics", "(", "self", ",", "topics", ")", ":", "if", "set", "(", "topics", ")", ".", "difference", "(", "self", ".", "_topics", ")", ":", "future", "=", "self", ".", "cluster", ".", "request_update", "(", ")", "else", ":", "future", "=", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.add_topic
Add a topic to the list of topics tracked via metadata. Arguments: topic (str): topic to track Returns: Future: resolves after metadata request/response
kafka/client_async.py
def add_topic(self, topic): """Add a topic to the list of topics tracked via metadata. Arguments: topic (str): topic to track Returns: Future: resolves after metadata request/response """ if topic in self._topics: return Future().success(set(...
def add_topic(self, topic): """Add a topic to the list of topics tracked via metadata. Arguments: topic (str): topic to track Returns: Future: resolves after metadata request/response """ if topic in self._topics: return Future().success(set(...
[ "Add", "a", "topic", "to", "the", "list", "of", "topics", "tracked", "via", "metadata", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L756-L769
[ "def", "add_topic", "(", "self", ",", "topic", ")", ":", "if", "topic", "in", "self", ".", "_topics", ":", "return", "Future", "(", ")", ".", "success", "(", "set", "(", "self", ".", "_topics", ")", ")", "self", ".", "_topics", ".", "add", "(", "...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient._maybe_refresh_metadata
Send a metadata request if needed. Returns: int: milliseconds until next refresh
kafka/client_async.py
def _maybe_refresh_metadata(self, wakeup=False): """Send a metadata request if needed. Returns: int: milliseconds until next refresh """ ttl = self.cluster.ttl() wait_for_in_progress_ms = self.config['request_timeout_ms'] if self._metadata_refresh_in_progress else 0 ...
def _maybe_refresh_metadata(self, wakeup=False): """Send a metadata request if needed. Returns: int: milliseconds until next refresh """ ttl = self.cluster.ttl() wait_for_in_progress_ms = self.config['request_timeout_ms'] if self._metadata_refresh_in_progress else 0 ...
[ "Send", "a", "metadata", "request", "if", "needed", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L772-L827
[ "def", "_maybe_refresh_metadata", "(", "self", ",", "wakeup", "=", "False", ")", ":", "ttl", "=", "self", ".", "cluster", ".", "ttl", "(", ")", "wait_for_in_progress_ms", "=", "self", ".", "config", "[", "'request_timeout_ms'", "]", "if", "self", ".", "_me...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaClient.check_version
Attempt to guess the version of a Kafka broker. Note: It is possible that this method blocks longer than the specified timeout. This can happen if the entire cluster is down and the client enters a bootstrap backoff sleep. This is only possible if node_id is None. R...
kafka/client_async.py
def check_version(self, node_id=None, timeout=2, strict=False): """Attempt to guess the version of a Kafka broker. Note: It is possible that this method blocks longer than the specified timeout. This can happen if the entire cluster is down and the client enters a bootstrap back...
def check_version(self, node_id=None, timeout=2, strict=False): """Attempt to guess the version of a Kafka broker. Note: It is possible that this method blocks longer than the specified timeout. This can happen if the entire cluster is down and the client enters a bootstrap back...
[ "Attempt", "to", "guess", "the", "version", "of", "a", "Kafka", "broker", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client_async.py#L840-L892
[ "def", "check_version", "(", "self", ",", "node_id", "=", "None", ",", "timeout", "=", "2", ",", "strict", "=", "False", ")", ":", "self", ".", "_lock", ".", "acquire", "(", ")", "end", "=", "time", ".", "time", "(", ")", "+", "timeout", "while", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
Rate.window_size
Here we check the total amount of time elapsed since the oldest non-obsolete window. This give the total window_size of the batch which is the time used for Rate computation. However, there is an issue if we do not have sufficient data for e.g. if only 1 second has elapsed in a 30 second...
kafka/metrics/stats/rate.py
def window_size(self, config, now): # purge old samples before we compute the window size self._stat.purge_obsolete_samples(config, now) """ Here we check the total amount of time elapsed since the oldest non-obsolete window. This give the total window_size of the batch ...
def window_size(self, config, now): # purge old samples before we compute the window size self._stat.purge_obsolete_samples(config, now) """ Here we check the total amount of time elapsed since the oldest non-obsolete window. This give the total window_size of the batch ...
[ "Here", "we", "check", "the", "total", "amount", "of", "time", "elapsed", "since", "the", "oldest", "non", "-", "obsolete", "window", ".", "This", "give", "the", "total", "window_size", "of", "the", "batch", "which", "is", "the", "time", "used", "for", "...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/metrics/stats/rate.py#L54-L86
[ "def", "window_size", "(", "self", ",", "config", ",", "now", ")", ":", "# purge old samples before we compute the window size", "self", ".", "_stat", ".", "purge_obsolete_samples", "(", "config", ",", "now", ")", "total_elapsed_time_ms", "=", "now", "-", "self", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
Producer.send_messages
Helper method to send produce requests. Note that msg type *must* be encoded to bytes by user. Passing unicode message will not work, for example you should encode before calling send_messages via something like `unicode_message.encode('utf-8')` All messages will set the message 'key' t...
kafka/producer/base.py
def send_messages(self, topic, partition, *msg): """Helper method to send produce requests. Note that msg type *must* be encoded to bytes by user. Passing unicode message will not work, for example you should encode before calling send_messages via something like `unicode_message.encode...
def send_messages(self, topic, partition, *msg): """Helper method to send produce requests. Note that msg type *must* be encoded to bytes by user. Passing unicode message will not work, for example you should encode before calling send_messages via something like `unicode_message.encode...
[ "Helper", "method", "to", "send", "produce", "requests", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/producer/base.py#L356-L387
[ "def", "send_messages", "(", "self", ",", "topic", ",", "partition", ",", "*", "msg", ")", ":", "return", "self", ".", "_send_messages", "(", "topic", ",", "partition", ",", "*", "msg", ")" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
Producer.stop
Stop the producer (async mode). Blocks until async thread completes.
kafka/producer/base.py
def stop(self, timeout=None): """ Stop the producer (async mode). Blocks until async thread completes. """ if timeout is not None: log.warning('timeout argument to stop() is deprecated - ' 'it will be removed in future release') if not self.as...
def stop(self, timeout=None): """ Stop the producer (async mode). Blocks until async thread completes. """ if timeout is not None: log.warning('timeout argument to stop() is deprecated - ' 'it will be removed in future release') if not self.as...
[ "Stop", "the", "producer", "(", "async", "mode", ")", ".", "Blocks", "until", "async", "thread", "completes", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/producer/base.py#L437-L478
[ "def", "stop", "(", "self", ",", "timeout", "=", "None", ")", ":", "if", "timeout", "is", "not", "None", ":", "log", ".", "warning", "(", "'timeout argument to stop() is deprecated - '", "'it will be removed in future release'", ")", "if", "not", "self", ".", "a...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
LegacyRecordBatchBuilder.append
Append message to batch.
kafka/record/legacy_records.py
def append(self, offset, timestamp, key, value, headers=None): """ Append message to batch. """ assert not headers, "Headers not supported in v0/v1" # Check types if type(offset) != int: raise TypeError(offset) if self._magic == 0: timestamp = self...
def append(self, offset, timestamp, key, value, headers=None): """ Append message to batch. """ assert not headers, "Headers not supported in v0/v1" # Check types if type(offset) != int: raise TypeError(offset) if self._magic == 0: timestamp = self...
[ "Append", "message", "to", "batch", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/legacy_records.py#L345-L382
[ "def", "append", "(", "self", ",", "offset", ",", "timestamp", ",", "key", ",", "value", ",", "headers", "=", "None", ")", ":", "assert", "not", "headers", ",", "\"Headers not supported in v0/v1\"", "# Check types", "if", "type", "(", "offset", ")", "!=", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
LegacyRecordBatchBuilder._encode_msg
Encode msg data into the `msg_buffer`, which should be allocated to at least the size of this message.
kafka/record/legacy_records.py
def _encode_msg(self, start_pos, offset, timestamp, key, value, attributes=0): """ Encode msg data into the `msg_buffer`, which should be allocated to at least the size of this message. """ magic = self._magic buf = self._buffer pos = start_pos ...
def _encode_msg(self, start_pos, offset, timestamp, key, value, attributes=0): """ Encode msg data into the `msg_buffer`, which should be allocated to at least the size of this message. """ magic = self._magic buf = self._buffer pos = start_pos ...
[ "Encode", "msg", "data", "into", "the", "msg_buffer", "which", "should", "be", "allocated", "to", "at", "least", "the", "size", "of", "this", "message", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/legacy_records.py#L384-L431
[ "def", "_encode_msg", "(", "self", ",", "start_pos", ",", "offset", ",", "timestamp", ",", "key", ",", "value", ",", "attributes", "=", "0", ")", ":", "magic", "=", "self", ".", "_magic", "buf", "=", "self", ".", "_buffer", "pos", "=", "start_pos", "...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
LegacyRecordBatchBuilder.size_in_bytes
Actual size of message to add
kafka/record/legacy_records.py
def size_in_bytes(self, offset, timestamp, key, value, headers=None): """ Actual size of message to add """ assert not headers, "Headers not supported in v0/v1" magic = self._magic return self.LOG_OVERHEAD + self.record_size(magic, key, value)
def size_in_bytes(self, offset, timestamp, key, value, headers=None): """ Actual size of message to add """ assert not headers, "Headers not supported in v0/v1" magic = self._magic return self.LOG_OVERHEAD + self.record_size(magic, key, value)
[ "Actual", "size", "of", "message", "to", "add" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/legacy_records.py#L472-L477
[ "def", "size_in_bytes", "(", "self", ",", "offset", ",", "timestamp", ",", "key", ",", "value", ",", "headers", "=", "None", ")", ":", "assert", "not", "headers", ",", "\"Headers not supported in v0/v1\"", "magic", "=", "self", ".", "_magic", "return", "self...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
LegacyRecordBatchBuilder.estimate_size_in_bytes
Upper bound estimate of record size.
kafka/record/legacy_records.py
def estimate_size_in_bytes(cls, magic, compression_type, key, value): """ Upper bound estimate of record size. """ assert magic in [0, 1], "Not supported magic" # In case of compression we may need another overhead for inner msg if compression_type: return ( ...
def estimate_size_in_bytes(cls, magic, compression_type, key, value): """ Upper bound estimate of record size. """ assert magic in [0, 1], "Not supported magic" # In case of compression we may need another overhead for inner msg if compression_type: return ( ...
[ "Upper", "bound", "estimate", "of", "record", "size", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/legacy_records.py#L497-L507
[ "def", "estimate_size_in_bytes", "(", "cls", ",", "magic", ",", "compression_type", ",", "key", ",", "value", ")", ":", "assert", "magic", "in", "[", "0", ",", "1", "]", ",", "\"Not supported magic\"", "# In case of compression we may need another overhead for inner m...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleBufferPool.allocate
Allocate a buffer of the given size. This method blocks if there is not enough memory and the buffer pool is configured with blocking mode. Arguments: size (int): The buffer size to allocate in bytes [ignored] max_time_to_block_ms (int): The maximum time in milliseconds to ...
kafka/producer/buffer.py
def allocate(self, size, max_time_to_block_ms): """ Allocate a buffer of the given size. This method blocks if there is not enough memory and the buffer pool is configured with blocking mode. Arguments: size (int): The buffer size to allocate in bytes [ignored] m...
def allocate(self, size, max_time_to_block_ms): """ Allocate a buffer of the given size. This method blocks if there is not enough memory and the buffer pool is configured with blocking mode. Arguments: size (int): The buffer size to allocate in bytes [ignored] m...
[ "Allocate", "a", "buffer", "of", "the", "given", "size", ".", "This", "method", "blocks", "if", "there", "is", "not", "enough", "memory", "and", "the", "buffer", "pool", "is", "configured", "with", "blocking", "mode", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/producer/buffer.py#L38-L92
[ "def", "allocate", "(", "self", ",", "size", ",", "max_time_to_block_ms", ")", ":", "with", "self", ".", "_lock", ":", "# check if we have a free buffer of the right size pooled", "if", "self", ".", "_free", ":", "return", "self", ".", "_free", ".", "popleft", "...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleBufferPool.deallocate
Return buffers to the pool. If they are of the poolable size add them to the free list, otherwise just mark the memory as free. Arguments: buffer_ (io.BytesIO): The buffer to return
kafka/producer/buffer.py
def deallocate(self, buf): """ Return buffers to the pool. If they are of the poolable size add them to the free list, otherwise just mark the memory as free. Arguments: buffer_ (io.BytesIO): The buffer to return """ with self._lock: # BytesIO.tru...
def deallocate(self, buf): """ Return buffers to the pool. If they are of the poolable size add them to the free list, otherwise just mark the memory as free. Arguments: buffer_ (io.BytesIO): The buffer to return """ with self._lock: # BytesIO.tru...
[ "Return", "buffers", "to", "the", "pool", ".", "If", "they", "are", "of", "the", "poolable", "size", "add", "them", "to", "the", "free", "list", "otherwise", "just", "mark", "the", "memory", "as", "free", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/producer/buffer.py#L94-L110
[ "def", "deallocate", "(", "self", ",", "buf", ")", ":", "with", "self", ".", "_lock", ":", "# BytesIO.truncate here makes the pool somewhat pointless", "# but we stick with the BufferPool API until migrating to", "# bytesarray / memoryview. The buffer we return must not", "# expose a...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
MessageSet.decode
Compressed messages should pass in bytes_to_read (via message size) otherwise, we decode from data as Int32
kafka/protocol/message.py
def decode(cls, data, bytes_to_read=None): """Compressed messages should pass in bytes_to_read (via message size) otherwise, we decode from data as Int32 """ if isinstance(data, bytes): data = io.BytesIO(data) if bytes_to_read is None: bytes_to_read = Int3...
def decode(cls, data, bytes_to_read=None): """Compressed messages should pass in bytes_to_read (via message size) otherwise, we decode from data as Int32 """ if isinstance(data, bytes): data = io.BytesIO(data) if bytes_to_read is None: bytes_to_read = Int3...
[ "Compressed", "messages", "should", "pass", "in", "bytes_to_read", "(", "via", "message", "size", ")", "otherwise", "we", "decode", "from", "data", "as", "Int32" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/protocol/message.py#L178-L203
[ "def", "decode", "(", "cls", ",", "data", ",", "bytes_to_read", "=", "None", ")", ":", "if", "isinstance", "(", "data", ",", "bytes", ")", ":", "data", "=", "io", ".", "BytesIO", "(", "data", ")", "if", "bytes_to_read", "is", "None", ":", "bytes_to_r...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
encode_varint
Encode an integer to a varint presentation. See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints on how those can be produced. Arguments: value (int): Value to encode write (function): Called per byte that needs to be writen Returns: ...
kafka/record/util.py
def encode_varint(value, write): """ Encode an integer to a varint presentation. See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints on how those can be produced. Arguments: value (int): Value to encode write (function): Called per byte that needs ...
def encode_varint(value, write): """ Encode an integer to a varint presentation. See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints on how those can be produced. Arguments: value (int): Value to encode write (function): Called per byte that needs ...
[ "Encode", "an", "integer", "to", "a", "varint", "presentation", ".", "See", "https", ":", "//", "developers", ".", "google", ".", "com", "/", "protocol", "-", "buffers", "/", "docs", "/", "encoding?csw", "=", "1#varints", "on", "how", "those", "can", "be...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/util.py#L10-L60
[ "def", "encode_varint", "(", "value", ",", "write", ")", ":", "value", "=", "(", "value", "<<", "1", ")", "^", "(", "value", ">>", "63", ")", "if", "value", "<=", "0x7f", ":", "# 1 byte", "write", "(", "value", ")", "return", "1", "if", "value", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
size_of_varint
Number of bytes needed to encode an integer in variable-length format.
kafka/record/util.py
def size_of_varint(value): """ Number of bytes needed to encode an integer in variable-length format. """ value = (value << 1) ^ (value >> 63) if value <= 0x7f: return 1 if value <= 0x3fff: return 2 if value <= 0x1fffff: return 3 if value <= 0xfffffff: return ...
def size_of_varint(value): """ Number of bytes needed to encode an integer in variable-length format. """ value = (value << 1) ^ (value >> 63) if value <= 0x7f: return 1 if value <= 0x3fff: return 2 if value <= 0x1fffff: return 3 if value <= 0xfffffff: return ...
[ "Number", "of", "bytes", "needed", "to", "encode", "an", "integer", "in", "variable", "-", "length", "format", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/util.py#L63-L85
[ "def", "size_of_varint", "(", "value", ")", ":", "value", "=", "(", "value", "<<", "1", ")", "^", "(", "value", ">>", "63", ")", "if", "value", "<=", "0x7f", ":", "return", "1", "if", "value", "<=", "0x3fff", ":", "return", "2", "if", "value", "<...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
decode_varint
Decode an integer from a varint presentation. See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints on how those can be produced. Arguments: buffer (bytearry): buffer to read from. pos (int): optional position to read from Returns: (...
kafka/record/util.py
def decode_varint(buffer, pos=0): """ Decode an integer from a varint presentation. See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints on how those can be produced. Arguments: buffer (bytearry): buffer to read from. pos (int): optional position to...
def decode_varint(buffer, pos=0): """ Decode an integer from a varint presentation. See https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints on how those can be produced. Arguments: buffer (bytearry): buffer to read from. pos (int): optional position to...
[ "Decode", "an", "integer", "from", "a", "varint", "presentation", ".", "See", "https", ":", "//", "developers", ".", "google", ".", "com", "/", "protocol", "-", "buffers", "/", "docs", "/", "encoding?csw", "=", "1#varints", "on", "how", "those", "can", "...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/record/util.py#L88-L117
[ "def", "decode_varint", "(", "buffer", ",", "pos", "=", "0", ")", ":", "result", "=", "buffer", "[", "pos", "]", "if", "not", "(", "result", "&", "0x81", ")", ":", "return", "(", "result", ">>", "1", ")", ",", "pos", "+", "1", "if", "not", "(",...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaProtocol.send_request
Encode and queue a kafka api request for sending. Arguments: request (object): An un-encoded kafka request. correlation_id (int, optional): Optionally specify an ID to correlate requests with responses. If not provided, an ID will be generated automatical...
kafka/protocol/parser.py
def send_request(self, request, correlation_id=None): """Encode and queue a kafka api request for sending. Arguments: request (object): An un-encoded kafka request. correlation_id (int, optional): Optionally specify an ID to correlate requests with responses. If ...
def send_request(self, request, correlation_id=None): """Encode and queue a kafka api request for sending. Arguments: request (object): An un-encoded kafka request. correlation_id (int, optional): Optionally specify an ID to correlate requests with responses. If ...
[ "Encode", "and", "queue", "a", "kafka", "api", "request", "for", "sending", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/protocol/parser.py#L47-L72
[ "def", "send_request", "(", "self", ",", "request", ",", "correlation_id", "=", "None", ")", ":", "log", ".", "debug", "(", "'Sending request %s'", ",", "request", ")", "if", "correlation_id", "is", "None", ":", "correlation_id", "=", "self", ".", "_next_cor...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaProtocol.send_bytes
Retrieve all pending bytes to send on the network
kafka/protocol/parser.py
def send_bytes(self): """Retrieve all pending bytes to send on the network""" data = b''.join(self.bytes_to_send) self.bytes_to_send = [] return data
def send_bytes(self): """Retrieve all pending bytes to send on the network""" data = b''.join(self.bytes_to_send) self.bytes_to_send = [] return data
[ "Retrieve", "all", "pending", "bytes", "to", "send", "on", "the", "network" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/protocol/parser.py#L74-L78
[ "def", "send_bytes", "(", "self", ")", ":", "data", "=", "b''", ".", "join", "(", "self", ".", "bytes_to_send", ")", "self", ".", "bytes_to_send", "=", "[", "]", "return", "data" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
KafkaProtocol.receive_bytes
Process bytes received from the network. Arguments: data (bytes): any length bytes received from a network connection to a kafka broker. Returns: responses (list of (correlation_id, response)): any/all completed responses, decoded from bytes to p...
kafka/protocol/parser.py
def receive_bytes(self, data): """Process bytes received from the network. Arguments: data (bytes): any length bytes received from a network connection to a kafka broker. Returns: responses (list of (correlation_id, response)): any/all completed ...
def receive_bytes(self, data): """Process bytes received from the network. Arguments: data (bytes): any length bytes received from a network connection to a kafka broker. Returns: responses (list of (correlation_id, response)): any/all completed ...
[ "Process", "bytes", "received", "from", "the", "network", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/protocol/parser.py#L80-L135
[ "def", "receive_bytes", "(", "self", ",", "data", ")", ":", "i", "=", "0", "n", "=", "len", "(", "data", ")", "responses", "=", "[", "]", "while", "i", "<", "n", ":", "# Not receiving is the state of reading the payload header", "if", "not", "self", ".", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient._get_conn
Get or create a connection to a broker using host and port
kafka/client.py
def _get_conn(self, host, port, afi): """Get or create a connection to a broker using host and port""" host_key = (host, port) if host_key not in self._conns: self._conns[host_key] = BrokerConnection( host, port, afi, request_timeout_ms=self.timeout * ...
def _get_conn(self, host, port, afi): """Get or create a connection to a broker using host and port""" host_key = (host, port) if host_key not in self._conns: self._conns[host_key] = BrokerConnection( host, port, afi, request_timeout_ms=self.timeout * ...
[ "Get", "or", "create", "a", "connection", "to", "a", "broker", "using", "host", "and", "port" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L63-L77
[ "def", "_get_conn", "(", "self", ",", "host", ",", "port", ",", "afi", ")", ":", "host_key", "=", "(", "host", ",", "port", ")", "if", "host_key", "not", "in", "self", ".", "_conns", ":", "self", ".", "_conns", "[", "host_key", "]", "=", "BrokerCon...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient._get_leader_for_partition
Returns the leader for a partition or None if the partition exists but has no leader. Raises: UnknownTopicOrPartitionError: If the topic or partition is not part of the metadata. LeaderNotAvailableError: If the server has metadata, but there is no current...
kafka/client.py
def _get_leader_for_partition(self, topic, partition): """ Returns the leader for a partition or None if the partition exists but has no leader. Raises: UnknownTopicOrPartitionError: If the topic or partition is not part of the metadata. LeaderNot...
def _get_leader_for_partition(self, topic, partition): """ Returns the leader for a partition or None if the partition exists but has no leader. Raises: UnknownTopicOrPartitionError: If the topic or partition is not part of the metadata. LeaderNot...
[ "Returns", "the", "leader", "for", "a", "partition", "or", "None", "if", "the", "partition", "exists", "but", "has", "no", "leader", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L79-L114
[ "def", "_get_leader_for_partition", "(", "self", ",", "topic", ",", "partition", ")", ":", "key", "=", "TopicPartition", "(", "topic", ",", "partition", ")", "# Use cached metadata if it is there", "if", "self", ".", "topics_to_brokers", ".", "get", "(", "key", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient._get_coordinator_for_group
Returns the coordinator broker for a consumer group. GroupCoordinatorNotAvailableError will be raised if the coordinator does not currently exist for the group. GroupLoadInProgressError is raised if the coordinator is available but is still loading offsets from the internal topic
kafka/client.py
def _get_coordinator_for_group(self, group): """ Returns the coordinator broker for a consumer group. GroupCoordinatorNotAvailableError will be raised if the coordinator does not currently exist for the group. GroupLoadInProgressError is raised if the coordinator is available ...
def _get_coordinator_for_group(self, group): """ Returns the coordinator broker for a consumer group. GroupCoordinatorNotAvailableError will be raised if the coordinator does not currently exist for the group. GroupLoadInProgressError is raised if the coordinator is available ...
[ "Returns", "the", "coordinator", "broker", "for", "a", "consumer", "group", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L116-L134
[ "def", "_get_coordinator_for_group", "(", "self", ",", "group", ")", ":", "resp", "=", "self", ".", "send_consumer_metadata_request", "(", "group", ")", "# If there's a problem with finding the coordinator, raise the", "# provided error", "kafka", ".", "errors", ".", "che...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient._send_broker_unaware_request
Attempt to send a broker-agnostic request to one of the available brokers. Keep trying until you succeed.
kafka/client.py
def _send_broker_unaware_request(self, payloads, encoder_fn, decoder_fn): """ Attempt to send a broker-agnostic request to one of the available brokers. Keep trying until you succeed. """ hosts = set() for broker in self.brokers.values(): host, port, afi = get...
def _send_broker_unaware_request(self, payloads, encoder_fn, decoder_fn): """ Attempt to send a broker-agnostic request to one of the available brokers. Keep trying until you succeed. """ hosts = set() for broker in self.brokers.values(): host, port, afi = get...
[ "Attempt", "to", "send", "a", "broker", "-", "agnostic", "request", "to", "one", "of", "the", "available", "brokers", ".", "Keep", "trying", "until", "you", "succeed", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L142-L177
[ "def", "_send_broker_unaware_request", "(", "self", ",", "payloads", ",", "encoder_fn", ",", "decoder_fn", ")", ":", "hosts", "=", "set", "(", ")", "for", "broker", "in", "self", ".", "brokers", ".", "values", "(", ")", ":", "host", ",", "port", ",", "...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient._send_broker_aware_request
Group a list of request payloads by topic+partition and send them to the leader broker for that partition using the supplied encode/decode functions Arguments: payloads: list of object-like entities with a topic (str) and partition (int) attribute; payloads with duplicate t...
kafka/client.py
def _send_broker_aware_request(self, payloads, encoder_fn, decoder_fn): """ Group a list of request payloads by topic+partition and send them to the leader broker for that partition using the supplied encode/decode functions Arguments: payloads: list of object-like enti...
def _send_broker_aware_request(self, payloads, encoder_fn, decoder_fn): """ Group a list of request payloads by topic+partition and send them to the leader broker for that partition using the supplied encode/decode functions Arguments: payloads: list of object-like enti...
[ "Group", "a", "list", "of", "request", "payloads", "by", "topic", "+", "partition", "and", "send", "them", "to", "the", "leader", "broker", "for", "that", "partition", "using", "the", "supplied", "encode", "/", "decode", "functions" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L190-L301
[ "def", "_send_broker_aware_request", "(", "self", ",", "payloads", ",", "encoder_fn", ",", "decoder_fn", ")", ":", "# encoders / decoders do not maintain ordering currently", "# so we need to keep this so we can rebuild order before returning", "original_ordering", "=", "[", "(", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient._send_consumer_aware_request
Send a list of requests to the consumer coordinator for the group specified using the supplied encode/decode functions. As the payloads that use consumer-aware requests do not contain the group (e.g. OffsetFetchRequest), all payloads must be for a single group. Arguments: group...
kafka/client.py
def _send_consumer_aware_request(self, group, payloads, encoder_fn, decoder_fn): """ Send a list of requests to the consumer coordinator for the group specified using the supplied encode/decode functions. As the payloads that use consumer-aware requests do not contain the group (e.g. ...
def _send_consumer_aware_request(self, group, payloads, encoder_fn, decoder_fn): """ Send a list of requests to the consumer coordinator for the group specified using the supplied encode/decode functions. As the payloads that use consumer-aware requests do not contain the group (e.g. ...
[ "Send", "a", "list", "of", "requests", "to", "the", "consumer", "coordinator", "for", "the", "group", "specified", "using", "the", "supplied", "encode", "/", "decode", "functions", ".", "As", "the", "payloads", "that", "use", "consumer", "-", "aware", "reque...
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L303-L394
[ "def", "_send_consumer_aware_request", "(", "self", ",", "group", ",", "payloads", ",", "encoder_fn", ",", "decoder_fn", ")", ":", "# encoders / decoders do not maintain ordering currently", "# so we need to keep this so we can rebuild order before returning", "original_ordering", ...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient.copy
Create an inactive copy of the client object, suitable for passing to a separate thread. Note that the copied connections are not initialized, so :meth:`.reinit` must be called on the returned copy.
kafka/client.py
def copy(self): """ Create an inactive copy of the client object, suitable for passing to a separate thread. Note that the copied connections are not initialized, so :meth:`.reinit` must be called on the returned copy. """ _conns = self._conns self._conns...
def copy(self): """ Create an inactive copy of the client object, suitable for passing to a separate thread. Note that the copied connections are not initialized, so :meth:`.reinit` must be called on the returned copy. """ _conns = self._conns self._conns...
[ "Create", "an", "inactive", "copy", "of", "the", "client", "object", "suitable", "for", "passing", "to", "a", "separate", "thread", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L422-L434
[ "def", "copy", "(", "self", ")", ":", "_conns", "=", "self", ".", "_conns", "self", ".", "_conns", "=", "{", "}", "c", "=", "copy", ".", "deepcopy", "(", "self", ")", "self", ".", "_conns", "=", "_conns", "return", "c" ]
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient.load_metadata_for_topics
Fetch broker and topic-partition metadata from the server. Updates internal data: broker list, topic/partition list, and topic/partition -> broker map. This method should be called after receiving any error. Note: Exceptions *will not* be raised in a full refresh (i.e. no topic ...
kafka/client.py
def load_metadata_for_topics(self, *topics, **kwargs): """Fetch broker and topic-partition metadata from the server. Updates internal data: broker list, topic/partition list, and topic/partition -> broker map. This method should be called after receiving any error. Note: Except...
def load_metadata_for_topics(self, *topics, **kwargs): """Fetch broker and topic-partition metadata from the server. Updates internal data: broker list, topic/partition list, and topic/partition -> broker map. This method should be called after receiving any error. Note: Except...
[ "Fetch", "broker", "and", "topic", "-", "partition", "metadata", "from", "the", "server", "." ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L488-L583
[ "def", "load_metadata_for_topics", "(", "self", ",", "*", "topics", ",", "*", "*", "kwargs", ")", ":", "if", "'ignore_leadernotavailable'", "in", "kwargs", ":", "ignore_leadernotavailable", "=", "kwargs", "[", "'ignore_leadernotavailable'", "]", "else", ":", "igno...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient.send_produce_request
Encode and send some ProduceRequests ProduceRequests will be grouped by (topic, partition) and then sent to a specific broker. Output is a list of responses in the same order as the list of payloads specified Arguments: payloads (list of ProduceRequest): produce requests to...
kafka/client.py
def send_produce_request(self, payloads=(), acks=1, timeout=1000, fail_on_error=True, callback=None): """ Encode and send some ProduceRequests ProduceRequests will be grouped by (topic, partition) and then sent to a specific broker. Output is a list of respo...
def send_produce_request(self, payloads=(), acks=1, timeout=1000, fail_on_error=True, callback=None): """ Encode and send some ProduceRequests ProduceRequests will be grouped by (topic, partition) and then sent to a specific broker. Output is a list of respo...
[ "Encode", "and", "send", "some", "ProduceRequests" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L599-L647
[ "def", "send_produce_request", "(", "self", ",", "payloads", "=", "(", ")", ",", "acks", "=", "1", ",", "timeout", "=", "1000", ",", "fail_on_error", "=", "True", ",", "callback", "=", "None", ")", ":", "encoder", "=", "functools", ".", "partial", "(",...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
SimpleClient.send_fetch_request
Encode and send a FetchRequest Payloads are grouped by topic and partition so they can be pipelined to the same brokers.
kafka/client.py
def send_fetch_request(self, payloads=(), fail_on_error=True, callback=None, max_wait_time=100, min_bytes=4096): """ Encode and send a FetchRequest Payloads are grouped by topic and partition so they can be pipelined to the same brokers. """ e...
def send_fetch_request(self, payloads=(), fail_on_error=True, callback=None, max_wait_time=100, min_bytes=4096): """ Encode and send a FetchRequest Payloads are grouped by topic and partition so they can be pipelined to the same brokers. """ e...
[ "Encode", "and", "send", "a", "FetchRequest" ]
dpkp/kafka-python
python
https://github.com/dpkp/kafka-python/blob/f6a8a38937688ea2cc5dc13d3d1039493be5c9b5/kafka/client.py#L649-L667
[ "def", "send_fetch_request", "(", "self", ",", "payloads", "=", "(", ")", ",", "fail_on_error", "=", "True", ",", "callback", "=", "None", ",", "max_wait_time", "=", "100", ",", "min_bytes", "=", "4096", ")", ":", "encoder", "=", "functools", ".", "parti...
f6a8a38937688ea2cc5dc13d3d1039493be5c9b5
train
Token.verify
Performs additional validation steps which were not performed when this token was decoded. This method is part of the "public" API to indicate the intention that it may be overridden in subclasses.
rest_framework_simplejwt/tokens.py
def verify(self): """ Performs additional validation steps which were not performed when this token was decoded. This method is part of the "public" API to indicate the intention that it may be overridden in subclasses. """ # According to RFC 7519, the "exp" claim is OPT...
def verify(self): """ Performs additional validation steps which were not performed when this token was decoded. This method is part of the "public" API to indicate the intention that it may be overridden in subclasses. """ # According to RFC 7519, the "exp" claim is OPT...
[ "Performs", "additional", "validation", "steps", "which", "were", "not", "performed", "when", "this", "token", "was", "decoded", ".", "This", "method", "is", "part", "of", "the", "public", "API", "to", "indicate", "the", "intention", "that", "it", "may", "be...
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/tokens.py#L84-L100
[ "def", "verify", "(", "self", ")", ":", "# According to RFC 7519, the \"exp\" claim is OPTIONAL", "# (https://tools.ietf.org/html/rfc7519#section-4.1.4). As a more", "# correct behavior for authorization tokens, we require an \"exp\"", "# claim. We don't want any zombie tokens walking around.", ...
d6084c595aefbf97865d15254b56017e710e8e47
train
Token.verify_token_type
Ensures that the token type claim is present and has the correct value.
rest_framework_simplejwt/tokens.py
def verify_token_type(self): """ Ensures that the token type claim is present and has the correct value. """ try: token_type = self.payload[api_settings.TOKEN_TYPE_CLAIM] except KeyError: raise TokenError(_('Token has no type')) if self.token_type...
def verify_token_type(self): """ Ensures that the token type claim is present and has the correct value. """ try: token_type = self.payload[api_settings.TOKEN_TYPE_CLAIM] except KeyError: raise TokenError(_('Token has no type')) if self.token_type...
[ "Ensures", "that", "the", "token", "type", "claim", "is", "present", "and", "has", "the", "correct", "value", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/tokens.py#L102-L112
[ "def", "verify_token_type", "(", "self", ")", ":", "try", ":", "token_type", "=", "self", ".", "payload", "[", "api_settings", ".", "TOKEN_TYPE_CLAIM", "]", "except", "KeyError", ":", "raise", "TokenError", "(", "_", "(", "'Token has no type'", ")", ")", "if...
d6084c595aefbf97865d15254b56017e710e8e47
train
Token.set_exp
Updates the expiration time of a token.
rest_framework_simplejwt/tokens.py
def set_exp(self, claim='exp', from_time=None, lifetime=None): """ Updates the expiration time of a token. """ if from_time is None: from_time = self.current_time if lifetime is None: lifetime = self.lifetime self.payload[claim] = datetime_to_epo...
def set_exp(self, claim='exp', from_time=None, lifetime=None): """ Updates the expiration time of a token. """ if from_time is None: from_time = self.current_time if lifetime is None: lifetime = self.lifetime self.payload[claim] = datetime_to_epo...
[ "Updates", "the", "expiration", "time", "of", "a", "token", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/tokens.py#L125-L135
[ "def", "set_exp", "(", "self", ",", "claim", "=", "'exp'", ",", "from_time", "=", "None", ",", "lifetime", "=", "None", ")", ":", "if", "from_time", "is", "None", ":", "from_time", "=", "self", ".", "current_time", "if", "lifetime", "is", "None", ":", ...
d6084c595aefbf97865d15254b56017e710e8e47
train
Token.check_exp
Checks whether a timestamp value in the given claim has passed (since the given datetime value in `current_time`). Raises a TokenError with a user-facing error message if so.
rest_framework_simplejwt/tokens.py
def check_exp(self, claim='exp', current_time=None): """ Checks whether a timestamp value in the given claim has passed (since the given datetime value in `current_time`). Raises a TokenError with a user-facing error message if so. """ if current_time is None: ...
def check_exp(self, claim='exp', current_time=None): """ Checks whether a timestamp value in the given claim has passed (since the given datetime value in `current_time`). Raises a TokenError with a user-facing error message if so. """ if current_time is None: ...
[ "Checks", "whether", "a", "timestamp", "value", "in", "the", "given", "claim", "has", "passed", "(", "since", "the", "given", "datetime", "value", "in", "current_time", ")", ".", "Raises", "a", "TokenError", "with", "a", "user", "-", "facing", "error", "me...
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/tokens.py#L137-L153
[ "def", "check_exp", "(", "self", ",", "claim", "=", "'exp'", ",", "current_time", "=", "None", ")", ":", "if", "current_time", "is", "None", ":", "current_time", "=", "self", ".", "current_time", "try", ":", "claim_value", "=", "self", ".", "payload", "[...
d6084c595aefbf97865d15254b56017e710e8e47
train
Token.for_user
Returns an authorization token for the given user that will be provided after authenticating the user's credentials.
rest_framework_simplejwt/tokens.py
def for_user(cls, user): """ Returns an authorization token for the given user that will be provided after authenticating the user's credentials. """ user_id = getattr(user, api_settings.USER_ID_FIELD) if not isinstance(user_id, int): user_id = str(user_id) ...
def for_user(cls, user): """ Returns an authorization token for the given user that will be provided after authenticating the user's credentials. """ user_id = getattr(user, api_settings.USER_ID_FIELD) if not isinstance(user_id, int): user_id = str(user_id) ...
[ "Returns", "an", "authorization", "token", "for", "the", "given", "user", "that", "will", "be", "provided", "after", "authenticating", "the", "user", "s", "credentials", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/tokens.py#L156-L168
[ "def", "for_user", "(", "cls", ",", "user", ")", ":", "user_id", "=", "getattr", "(", "user", ",", "api_settings", ".", "USER_ID_FIELD", ")", "if", "not", "isinstance", "(", "user_id", ",", "int", ")", ":", "user_id", "=", "str", "(", "user_id", ")", ...
d6084c595aefbf97865d15254b56017e710e8e47
train
RefreshToken.access_token
Returns an access token created from this refresh token. Copies all claims present in this refresh token to the new access token except those claims listed in the `no_copy_claims` attribute.
rest_framework_simplejwt/tokens.py
def access_token(self): """ Returns an access token created from this refresh token. Copies all claims present in this refresh token to the new access token except those claims listed in the `no_copy_claims` attribute. """ access = AccessToken() # Use instantiat...
def access_token(self): """ Returns an access token created from this refresh token. Copies all claims present in this refresh token to the new access token except those claims listed in the `no_copy_claims` attribute. """ access = AccessToken() # Use instantiat...
[ "Returns", "an", "access", "token", "created", "from", "this", "refresh", "token", ".", "Copies", "all", "claims", "present", "in", "this", "refresh", "token", "to", "the", "new", "access", "token", "except", "those", "claims", "listed", "in", "the", "no_cop...
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/tokens.py#L266-L286
[ "def", "access_token", "(", "self", ")", ":", "access", "=", "AccessToken", "(", ")", "# Use instantiation time of refresh token as relative timestamp for", "# access token \"exp\" claim. This ensures that both a refresh and", "# access token expire relative to the same time if they are c...
d6084c595aefbf97865d15254b56017e710e8e47
train
TokenBackend.encode
Returns an encoded token for the given payload dictionary.
rest_framework_simplejwt/backends.py
def encode(self, payload): """ Returns an encoded token for the given payload dictionary. """ token = jwt.encode(payload, self.signing_key, algorithm=self.algorithm) return token.decode('utf-8')
def encode(self, payload): """ Returns an encoded token for the given payload dictionary. """ token = jwt.encode(payload, self.signing_key, algorithm=self.algorithm) return token.decode('utf-8')
[ "Returns", "an", "encoded", "token", "for", "the", "given", "payload", "dictionary", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/backends.py#L30-L35
[ "def", "encode", "(", "self", ",", "payload", ")", ":", "token", "=", "jwt", ".", "encode", "(", "payload", ",", "self", ".", "signing_key", ",", "algorithm", "=", "self", ".", "algorithm", ")", "return", "token", ".", "decode", "(", "'utf-8'", ")" ]
d6084c595aefbf97865d15254b56017e710e8e47
train
TokenBackend.decode
Performs a validation of the given token and returns its payload dictionary. Raises a `TokenBackendError` if the token is malformed, if its signature check fails, or if its 'exp' claim indicates it has expired.
rest_framework_simplejwt/backends.py
def decode(self, token, verify=True): """ Performs a validation of the given token and returns its payload dictionary. Raises a `TokenBackendError` if the token is malformed, if its signature check fails, or if its 'exp' claim indicates it has expired. """ try: ...
def decode(self, token, verify=True): """ Performs a validation of the given token and returns its payload dictionary. Raises a `TokenBackendError` if the token is malformed, if its signature check fails, or if its 'exp' claim indicates it has expired. """ try: ...
[ "Performs", "a", "validation", "of", "the", "given", "token", "and", "returns", "its", "payload", "dictionary", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/backends.py#L37-L48
[ "def", "decode", "(", "self", ",", "token", ",", "verify", "=", "True", ")", ":", "try", ":", "return", "jwt", ".", "decode", "(", "token", ",", "self", ".", "verifying_key", ",", "algorithms", "=", "[", "self", ".", "algorithm", "]", ",", "verify", ...
d6084c595aefbf97865d15254b56017e710e8e47
train
JWTAuthentication.get_header
Extracts the header containing the JSON web token from the given request.
rest_framework_simplejwt/authentication.py
def get_header(self, request): """ Extracts the header containing the JSON web token from the given request. """ header = request.META.get('HTTP_AUTHORIZATION') if isinstance(header, str): # Work around django test client oddness header = header.e...
def get_header(self, request): """ Extracts the header containing the JSON web token from the given request. """ header = request.META.get('HTTP_AUTHORIZATION') if isinstance(header, str): # Work around django test client oddness header = header.e...
[ "Extracts", "the", "header", "containing", "the", "JSON", "web", "token", "from", "the", "given", "request", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/authentication.py#L46-L57
[ "def", "get_header", "(", "self", ",", "request", ")", ":", "header", "=", "request", ".", "META", ".", "get", "(", "'HTTP_AUTHORIZATION'", ")", "if", "isinstance", "(", "header", ",", "str", ")", ":", "# Work around django test client oddness", "header", "=",...
d6084c595aefbf97865d15254b56017e710e8e47
train
JWTAuthentication.get_raw_token
Extracts an unvalidated JSON web token from the given "Authorization" header value.
rest_framework_simplejwt/authentication.py
def get_raw_token(self, header): """ Extracts an unvalidated JSON web token from the given "Authorization" header value. """ parts = header.split() if len(parts) == 0: # Empty AUTHORIZATION header sent return None if parts[0] not in AUTH_...
def get_raw_token(self, header): """ Extracts an unvalidated JSON web token from the given "Authorization" header value. """ parts = header.split() if len(parts) == 0: # Empty AUTHORIZATION header sent return None if parts[0] not in AUTH_...
[ "Extracts", "an", "unvalidated", "JSON", "web", "token", "from", "the", "given", "Authorization", "header", "value", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/authentication.py#L59-L80
[ "def", "get_raw_token", "(", "self", ",", "header", ")", ":", "parts", "=", "header", ".", "split", "(", ")", "if", "len", "(", "parts", ")", "==", "0", ":", "# Empty AUTHORIZATION header sent", "return", "None", "if", "parts", "[", "0", "]", "not", "i...
d6084c595aefbf97865d15254b56017e710e8e47
train
JWTAuthentication.get_validated_token
Validates an encoded JSON web token and returns a validated token wrapper object.
rest_framework_simplejwt/authentication.py
def get_validated_token(self, raw_token): """ Validates an encoded JSON web token and returns a validated token wrapper object. """ messages = [] for AuthToken in api_settings.AUTH_TOKEN_CLASSES: try: return AuthToken(raw_token) exc...
def get_validated_token(self, raw_token): """ Validates an encoded JSON web token and returns a validated token wrapper object. """ messages = [] for AuthToken in api_settings.AUTH_TOKEN_CLASSES: try: return AuthToken(raw_token) exc...
[ "Validates", "an", "encoded", "JSON", "web", "token", "and", "returns", "a", "validated", "token", "wrapper", "object", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/authentication.py#L82-L99
[ "def", "get_validated_token", "(", "self", ",", "raw_token", ")", ":", "messages", "=", "[", "]", "for", "AuthToken", "in", "api_settings", ".", "AUTH_TOKEN_CLASSES", ":", "try", ":", "return", "AuthToken", "(", "raw_token", ")", "except", "TokenError", "as", ...
d6084c595aefbf97865d15254b56017e710e8e47
train
JWTAuthentication.get_user
Attempts to find and return a user using the given validated token.
rest_framework_simplejwt/authentication.py
def get_user(self, validated_token): """ Attempts to find and return a user using the given validated token. """ try: user_id = validated_token[api_settings.USER_ID_CLAIM] except KeyError: raise InvalidToken(_('Token contained no recognizable user identifi...
def get_user(self, validated_token): """ Attempts to find and return a user using the given validated token. """ try: user_id = validated_token[api_settings.USER_ID_CLAIM] except KeyError: raise InvalidToken(_('Token contained no recognizable user identifi...
[ "Attempts", "to", "find", "and", "return", "a", "user", "using", "the", "given", "validated", "token", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/authentication.py#L101-L118
[ "def", "get_user", "(", "self", ",", "validated_token", ")", ":", "try", ":", "user_id", "=", "validated_token", "[", "api_settings", ".", "USER_ID_CLAIM", "]", "except", "KeyError", ":", "raise", "InvalidToken", "(", "_", "(", "'Token contained no recognizable us...
d6084c595aefbf97865d15254b56017e710e8e47
train
JWTTokenUserAuthentication.get_user
Returns a stateless user object which is backed by the given validated token.
rest_framework_simplejwt/authentication.py
def get_user(self, validated_token): """ Returns a stateless user object which is backed by the given validated token. """ if api_settings.USER_ID_CLAIM not in validated_token: # The TokenUser class assumes tokens will have a recognizable user # identifier...
def get_user(self, validated_token): """ Returns a stateless user object which is backed by the given validated token. """ if api_settings.USER_ID_CLAIM not in validated_token: # The TokenUser class assumes tokens will have a recognizable user # identifier...
[ "Returns", "a", "stateless", "user", "object", "which", "is", "backed", "by", "the", "given", "validated", "token", "." ]
davesque/django-rest-framework-simplejwt
python
https://github.com/davesque/django-rest-framework-simplejwt/blob/d6084c595aefbf97865d15254b56017e710e8e47/rest_framework_simplejwt/authentication.py#L122-L132
[ "def", "get_user", "(", "self", ",", "validated_token", ")", ":", "if", "api_settings", ".", "USER_ID_CLAIM", "not", "in", "validated_token", ":", "# The TokenUser class assumes tokens will have a recognizable user", "# identifier claim.", "raise", "InvalidToken", "(", "_",...
d6084c595aefbf97865d15254b56017e710e8e47
train
ImagePart.default_cx
Native width of this image, calculated from its width in pixels and horizontal dots per inch (dpi).
docx/parts/image.py
def default_cx(self): """ Native width of this image, calculated from its width in pixels and horizontal dots per inch (dpi). """ px_width = self.image.px_width horz_dpi = self.image.horz_dpi width_in_inches = px_width / horz_dpi return Inches(width_in_inc...
def default_cx(self): """ Native width of this image, calculated from its width in pixels and horizontal dots per inch (dpi). """ px_width = self.image.px_width horz_dpi = self.image.horz_dpi width_in_inches = px_width / horz_dpi return Inches(width_in_inc...
[ "Native", "width", "of", "this", "image", "calculated", "from", "its", "width", "in", "pixels", "and", "horizontal", "dots", "per", "inch", "(", "dpi", ")", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/image.py#L28-L36
[ "def", "default_cx", "(", "self", ")", ":", "px_width", "=", "self", ".", "image", ".", "px_width", "horz_dpi", "=", "self", ".", "image", ".", "horz_dpi", "width_in_inches", "=", "px_width", "/", "horz_dpi", "return", "Inches", "(", "width_in_inches", ")" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
ImagePart.default_cy
Native height of this image, calculated from its height in pixels and vertical dots per inch (dpi).
docx/parts/image.py
def default_cy(self): """ Native height of this image, calculated from its height in pixels and vertical dots per inch (dpi). """ px_height = self.image.px_height horz_dpi = self.image.horz_dpi height_in_emu = 914400 * px_height / horz_dpi return Emu(heigh...
def default_cy(self): """ Native height of this image, calculated from its height in pixels and vertical dots per inch (dpi). """ px_height = self.image.px_height horz_dpi = self.image.horz_dpi height_in_emu = 914400 * px_height / horz_dpi return Emu(heigh...
[ "Native", "height", "of", "this", "image", "calculated", "from", "its", "height", "in", "pixels", "and", "vertical", "dots", "per", "inch", "(", "dpi", ")", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/image.py#L39-L47
[ "def", "default_cy", "(", "self", ")", ":", "px_height", "=", "self", ".", "image", ".", "px_height", "horz_dpi", "=", "self", ".", "image", ".", "horz_dpi", "height_in_emu", "=", "914400", "*", "px_height", "/", "horz_dpi", "return", "Emu", "(", "height_i...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
ImagePart.filename
Filename from which this image part was originally created. A generic name, e.g. 'image.png', is substituted if no name is available, for example when the image was loaded from an unnamed stream. In that case a default extension is applied based on the detected MIME type of the image.
docx/parts/image.py
def filename(self): """ Filename from which this image part was originally created. A generic name, e.g. 'image.png', is substituted if no name is available, for example when the image was loaded from an unnamed stream. In that case a default extension is applied based on the det...
def filename(self): """ Filename from which this image part was originally created. A generic name, e.g. 'image.png', is substituted if no name is available, for example when the image was loaded from an unnamed stream. In that case a default extension is applied based on the det...
[ "Filename", "from", "which", "this", "image", "part", "was", "originally", "created", ".", "A", "generic", "name", "e", ".", "g", ".", "image", ".", "png", "is", "substituted", "if", "no", "name", "is", "available", "for", "example", "when", "the", "imag...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/image.py#L50-L60
[ "def", "filename", "(", "self", ")", ":", "if", "self", ".", "_image", "is", "not", "None", ":", "return", "self", ".", "_image", ".", "filename", "return", "'image.%s'", "%", "self", ".", "partname", ".", "ext" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
ImagePart.from_image
Return an |ImagePart| instance newly created from *image* and assigned *partname*.
docx/parts/image.py
def from_image(cls, image, partname): """ Return an |ImagePart| instance newly created from *image* and assigned *partname*. """ return ImagePart(partname, image.content_type, image.blob, image)
def from_image(cls, image, partname): """ Return an |ImagePart| instance newly created from *image* and assigned *partname*. """ return ImagePart(partname, image.content_type, image.blob, image)
[ "Return", "an", "|ImagePart|", "instance", "newly", "created", "from", "*", "image", "*", "and", "assigned", "*", "partname", "*", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/image.py#L63-L68
[ "def", "from_image", "(", "cls", ",", "image", ",", "partname", ")", ":", "return", "ImagePart", "(", "partname", ",", "image", ".", "content_type", ",", "image", ".", "blob", ",", "image", ")" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
ImagePart.load
Called by ``docx.opc.package.PartFactory`` to load an image part from a package being opened by ``Document(...)`` call.
docx/parts/image.py
def load(cls, partname, content_type, blob, package): """ Called by ``docx.opc.package.PartFactory`` to load an image part from a package being opened by ``Document(...)`` call. """ return cls(partname, content_type, blob)
def load(cls, partname, content_type, blob, package): """ Called by ``docx.opc.package.PartFactory`` to load an image part from a package being opened by ``Document(...)`` call. """ return cls(partname, content_type, blob)
[ "Called", "by", "docx", ".", "opc", ".", "package", ".", "PartFactory", "to", "load", "an", "image", "part", "from", "a", "package", "being", "opened", "by", "Document", "(", "...", ")", "call", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/image.py#L77-L82
[ "def", "load", "(", "cls", ",", "partname", ",", "content_type", ",", "blob", ",", "package", ")", ":", "return", "cls", "(", "partname", ",", "content_type", ",", "blob", ")" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
TabStops.add_tab_stop
Add a new tab stop at *position*, a |Length| object specifying the location of the tab stop relative to the paragraph edge. A negative *position* value is valid and appears in hanging indentation. Tab alignment defaults to left, but may be specified by passing a member of the :ref:`WdTab...
docx/text/tabstops.py
def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT, leader=WD_TAB_LEADER.SPACES): """ Add a new tab stop at *position*, a |Length| object specifying the location of the tab stop relative to the paragraph edge. A negative *position* value is valid and ap...
def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT, leader=WD_TAB_LEADER.SPACES): """ Add a new tab stop at *position*, a |Length| object specifying the location of the tab stop relative to the paragraph edge. A negative *position* value is valid and ap...
[ "Add", "a", "new", "tab", "stop", "at", "*", "position", "*", "a", "|Length|", "object", "specifying", "the", "location", "of", "the", "tab", "stop", "relative", "to", "the", "paragraph", "edge", ".", "A", "negative", "*", "position", "*", "value", "is",...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/text/tabstops.py#L69-L82
[ "def", "add_tab_stop", "(", "self", ",", "position", ",", "alignment", "=", "WD_TAB_ALIGNMENT", ".", "LEFT", ",", "leader", "=", "WD_TAB_LEADER", ".", "SPACES", ")", ":", "tabs", "=", "self", ".", "_pPr", ".", "get_or_add_tabs", "(", ")", "tab", "=", "ta...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_RPr.style
Set val attribute of <w:rStyle> child element to *style*, adding a new element if necessary. If *style* is |None|, remove the <w:rStyle> element if present.
docx/oxml/text/font.py
def style(self, style): """ Set val attribute of <w:rStyle> child element to *style*, adding a new element if necessary. If *style* is |None|, remove the <w:rStyle> element if present. """ if style is None: self._remove_rStyle() elif self.rStyle is Non...
def style(self, style): """ Set val attribute of <w:rStyle> child element to *style*, adding a new element if necessary. If *style* is |None|, remove the <w:rStyle> element if present. """ if style is None: self._remove_rStyle() elif self.rStyle is Non...
[ "Set", "val", "attribute", "of", "<w", ":", "rStyle", ">", "child", "element", "to", "*", "style", "*", "adding", "a", "new", "element", "if", "necessary", ".", "If", "*", "style", "*", "is", "|None|", "remove", "the", "<w", ":", "rStyle", ">", "elem...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/font.py#L170-L181
[ "def", "style", "(", "self", ",", "style", ")", ":", "if", "style", "is", "None", ":", "self", ".", "_remove_rStyle", "(", ")", "elif", "self", ".", "rStyle", "is", "None", ":", "self", ".", "_add_rStyle", "(", "val", "=", "style", ")", "else", ":"...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_RPr.subscript
|True| if `w:vertAlign/@w:val` is 'subscript'. |False| if `w:vertAlign/@w:val` contains any other value. |None| if `w:vertAlign` is not present.
docx/oxml/text/font.py
def subscript(self): """ |True| if `w:vertAlign/@w:val` is 'subscript'. |False| if `w:vertAlign/@w:val` contains any other value. |None| if `w:vertAlign` is not present. """ vertAlign = self.vertAlign if vertAlign is None: return None if vertAl...
def subscript(self): """ |True| if `w:vertAlign/@w:val` is 'subscript'. |False| if `w:vertAlign/@w:val` contains any other value. |None| if `w:vertAlign` is not present. """ vertAlign = self.vertAlign if vertAlign is None: return None if vertAl...
[ "|True|", "if", "w", ":", "vertAlign", "/" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/font.py#L184-L195
[ "def", "subscript", "(", "self", ")", ":", "vertAlign", "=", "self", ".", "vertAlign", "if", "vertAlign", "is", "None", ":", "return", "None", "if", "vertAlign", ".", "val", "==", "ST_VerticalAlignRun", ".", "SUBSCRIPT", ":", "return", "True", "return", "F...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_RPr.superscript
|True| if `w:vertAlign/@w:val` is 'superscript'. |False| if `w:vertAlign/@w:val` contains any other value. |None| if `w:vertAlign` is not present.
docx/oxml/text/font.py
def superscript(self): """ |True| if `w:vertAlign/@w:val` is 'superscript'. |False| if `w:vertAlign/@w:val` contains any other value. |None| if `w:vertAlign` is not present. """ vertAlign = self.vertAlign if vertAlign is None: return None if ve...
def superscript(self): """ |True| if `w:vertAlign/@w:val` is 'superscript'. |False| if `w:vertAlign/@w:val` contains any other value. |None| if `w:vertAlign` is not present. """ vertAlign = self.vertAlign if vertAlign is None: return None if ve...
[ "|True|", "if", "w", ":", "vertAlign", "/" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/font.py#L209-L220
[ "def", "superscript", "(", "self", ")", ":", "vertAlign", "=", "self", ".", "vertAlign", "if", "vertAlign", "is", "None", ":", "return", "None", "if", "vertAlign", ".", "val", "==", "ST_VerticalAlignRun", ".", "SUPERSCRIPT", ":", "return", "True", "return", ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_RPr._get_bool_val
Return the value of the boolean child element having *name*, e.g. 'b', 'i', and 'smallCaps'.
docx/oxml/text/font.py
def _get_bool_val(self, name): """ Return the value of the boolean child element having *name*, e.g. 'b', 'i', and 'smallCaps'. """ element = getattr(self, name) if element is None: return None return element.val
def _get_bool_val(self, name): """ Return the value of the boolean child element having *name*, e.g. 'b', 'i', and 'smallCaps'. """ element = getattr(self, name) if element is None: return None return element.val
[ "Return", "the", "value", "of", "the", "boolean", "child", "element", "having", "*", "name", "*", "e", ".", "g", ".", "b", "i", "and", "smallCaps", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/font.py#L267-L275
[ "def", "_get_bool_val", "(", "self", ",", "name", ")", ":", "element", "=", "getattr", "(", "self", ",", "name", ")", "if", "element", "is", "None", ":", "return", "None", "return", "element", ".", "val" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_Underline.val
The underline type corresponding to the ``w:val`` attribute value.
docx/oxml/text/font.py
def val(self): """ The underline type corresponding to the ``w:val`` attribute value. """ val = self.get(qn('w:val')) underline = WD_UNDERLINE.from_xml(val) if underline == WD_UNDERLINE.SINGLE: return True if underline == WD_UNDERLINE.NONE: ...
def val(self): """ The underline type corresponding to the ``w:val`` attribute value. """ val = self.get(qn('w:val')) underline = WD_UNDERLINE.from_xml(val) if underline == WD_UNDERLINE.SINGLE: return True if underline == WD_UNDERLINE.NONE: ...
[ "The", "underline", "type", "corresponding", "to", "the", "w", ":", "val", "attribute", "value", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/font.py#L290-L300
[ "def", "val", "(", "self", ")", ":", "val", "=", "self", ".", "get", "(", "qn", "(", "'w:val'", ")", ")", "underline", "=", "WD_UNDERLINE", ".", "from_xml", "(", "val", ")", "if", "underline", "==", "WD_UNDERLINE", ".", "SINGLE", ":", "return", "True...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
FooterPart.new
Return newly created footer part.
docx/parts/hdrftr.py
def new(cls, package): """Return newly created footer part.""" partname = package.next_partname("/word/footer%d.xml") content_type = CT.WML_FOOTER element = parse_xml(cls._default_footer_xml()) return cls(partname, content_type, element, package)
def new(cls, package): """Return newly created footer part.""" partname = package.next_partname("/word/footer%d.xml") content_type = CT.WML_FOOTER element = parse_xml(cls._default_footer_xml()) return cls(partname, content_type, element, package)
[ "Return", "newly", "created", "footer", "part", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/hdrftr.py#L18-L23
[ "def", "new", "(", "cls", ",", "package", ")", ":", "partname", "=", "package", ".", "next_partname", "(", "\"/word/footer%d.xml\"", ")", "content_type", "=", "CT", ".", "WML_FOOTER", "element", "=", "parse_xml", "(", "cls", ".", "_default_footer_xml", "(", ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
HeaderPart.new
Return newly created header part.
docx/parts/hdrftr.py
def new(cls, package): """Return newly created header part.""" partname = package.next_partname("/word/header%d.xml") content_type = CT.WML_HEADER element = parse_xml(cls._default_header_xml()) return cls(partname, content_type, element, package)
def new(cls, package): """Return newly created header part.""" partname = package.next_partname("/word/header%d.xml") content_type = CT.WML_HEADER element = parse_xml(cls._default_header_xml()) return cls(partname, content_type, element, package)
[ "Return", "newly", "created", "header", "part", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/hdrftr.py#L40-L45
[ "def", "new", "(", "cls", ",", "package", ")", ":", "partname", "=", "package", ".", "next_partname", "(", "\"/word/header%d.xml\"", ")", "content_type", "=", "CT", ".", "WML_HEADER", "element", "=", "parse_xml", "(", "cls", ".", "_default_header_xml", "(", ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
StylesPart.default
Return a newly created styles part, containing a default set of elements.
docx/parts/styles.py
def default(cls, package): """ Return a newly created styles part, containing a default set of elements. """ partname = PackURI('/word/styles.xml') content_type = CT.WML_STYLES element = parse_xml(cls._default_styles_xml()) return cls(partname, content_typ...
def default(cls, package): """ Return a newly created styles part, containing a default set of elements. """ partname = PackURI('/word/styles.xml') content_type = CT.WML_STYLES element = parse_xml(cls._default_styles_xml()) return cls(partname, content_typ...
[ "Return", "a", "newly", "created", "styles", "part", "containing", "a", "default", "set", "of", "elements", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/styles.py#L26-L34
[ "def", "default", "(", "cls", ",", "package", ")", ":", "partname", "=", "PackURI", "(", "'/word/styles.xml'", ")", "content_type", "=", "CT", ".", "WML_STYLES", "element", "=", "parse_xml", "(", "cls", ".", "_default_styles_xml", "(", ")", ")", "return", ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
StylesPart._default_styles_xml
Return a bytestream containing XML for a default styles part.
docx/parts/styles.py
def _default_styles_xml(cls): """ Return a bytestream containing XML for a default styles part. """ path = os.path.join( os.path.split(__file__)[0], '..', 'templates', 'default-styles.xml' ) with open(path, 'rb') as f: xml_bytes = f.rea...
def _default_styles_xml(cls): """ Return a bytestream containing XML for a default styles part. """ path = os.path.join( os.path.split(__file__)[0], '..', 'templates', 'default-styles.xml' ) with open(path, 'rb') as f: xml_bytes = f.rea...
[ "Return", "a", "bytestream", "containing", "XML", "for", "a", "default", "styles", "part", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/parts/styles.py#L45-L55
[ "def", "_default_styles_xml", "(", "cls", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "split", "(", "__file__", ")", "[", "0", "]", ",", "'..'", ",", "'templates'", ",", "'default-styles.xml'", ")", "with", "op...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.add_footerReference
Return newly added CT_HdrFtrRef element of *type_* with *rId*. The element tag is `w:footerReference`.
docx/oxml/section.py
def add_footerReference(self, type_, rId): """Return newly added CT_HdrFtrRef element of *type_* with *rId*. The element tag is `w:footerReference`. """ footerReference = self._add_footerReference() footerReference.type_ = type_ footerReference.rId = rId return f...
def add_footerReference(self, type_, rId): """Return newly added CT_HdrFtrRef element of *type_* with *rId*. The element tag is `w:footerReference`. """ footerReference = self._add_footerReference() footerReference.type_ = type_ footerReference.rId = rId return f...
[ "Return", "newly", "added", "CT_HdrFtrRef", "element", "of", "*", "type_", "*", "with", "*", "rId", "*", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L75-L83
[ "def", "add_footerReference", "(", "self", ",", "type_", ",", "rId", ")", ":", "footerReference", "=", "self", ".", "_add_footerReference", "(", ")", "footerReference", ".", "type_", "=", "type_", "footerReference", ".", "rId", "=", "rId", "return", "footerRef...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.add_headerReference
Return newly added CT_HdrFtrRef element of *type_* with *rId*. The element tag is `w:headerReference`.
docx/oxml/section.py
def add_headerReference(self, type_, rId): """Return newly added CT_HdrFtrRef element of *type_* with *rId*. The element tag is `w:headerReference`. """ headerReference = self._add_headerReference() headerReference.type_ = type_ headerReference.rId = rId return h...
def add_headerReference(self, type_, rId): """Return newly added CT_HdrFtrRef element of *type_* with *rId*. The element tag is `w:headerReference`. """ headerReference = self._add_headerReference() headerReference.type_ = type_ headerReference.rId = rId return h...
[ "Return", "newly", "added", "CT_HdrFtrRef", "element", "of", "*", "type_", "*", "with", "*", "rId", "*", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L85-L93
[ "def", "add_headerReference", "(", "self", ",", "type_", ",", "rId", ")", ":", "headerReference", "=", "self", ".", "_add_headerReference", "(", ")", "headerReference", ".", "type_", "=", "type_", "headerReference", ".", "rId", "=", "rId", "return", "headerRef...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.get_footerReference
Return footerReference element of *type_* or None if not present.
docx/oxml/section.py
def get_footerReference(self, type_): """Return footerReference element of *type_* or None if not present.""" path = "./w:footerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_) footerReferences = self.xpath(path) if not footerReferences: return None return fo...
def get_footerReference(self, type_): """Return footerReference element of *type_* or None if not present.""" path = "./w:footerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_) footerReferences = self.xpath(path) if not footerReferences: return None return fo...
[ "Return", "footerReference", "element", "of", "*", "type_", "*", "or", "None", "if", "not", "present", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L139-L145
[ "def", "get_footerReference", "(", "self", ",", "type_", ")", ":", "path", "=", "\"./w:footerReference[@w:type='%s']\"", "%", "WD_HEADER_FOOTER", ".", "to_xml", "(", "type_", ")", "footerReferences", "=", "self", ".", "xpath", "(", "path", ")", "if", "not", "f...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.get_headerReference
Return headerReference element of *type_* or None if not present.
docx/oxml/section.py
def get_headerReference(self, type_): """Return headerReference element of *type_* or None if not present.""" matching_headerReferences = self.xpath( "./w:headerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_) ) if len(matching_headerReferences) == 0: ret...
def get_headerReference(self, type_): """Return headerReference element of *type_* or None if not present.""" matching_headerReferences = self.xpath( "./w:headerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_) ) if len(matching_headerReferences) == 0: ret...
[ "Return", "headerReference", "element", "of", "*", "type_", "*", "or", "None", "if", "not", "present", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L147-L154
[ "def", "get_headerReference", "(", "self", ",", "type_", ")", ":", "matching_headerReferences", "=", "self", ".", "xpath", "(", "\"./w:headerReference[@w:type='%s']\"", "%", "WD_HEADER_FOOTER", ".", "to_xml", "(", "type_", ")", ")", "if", "len", "(", "matching_hea...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.orientation
The member of the ``WD_ORIENTATION`` enumeration corresponding to the value of the ``orient`` attribute of the ``<w:pgSz>`` child element, or ``WD_ORIENTATION.PORTRAIT`` if not present.
docx/oxml/section.py
def orientation(self): """ The member of the ``WD_ORIENTATION`` enumeration corresponding to the value of the ``orient`` attribute of the ``<w:pgSz>`` child element, or ``WD_ORIENTATION.PORTRAIT`` if not present. """ pgSz = self.pgSz if pgSz is None: r...
def orientation(self): """ The member of the ``WD_ORIENTATION`` enumeration corresponding to the value of the ``orient`` attribute of the ``<w:pgSz>`` child element, or ``WD_ORIENTATION.PORTRAIT`` if not present. """ pgSz = self.pgSz if pgSz is None: r...
[ "The", "member", "of", "the", "WD_ORIENTATION", "enumeration", "corresponding", "to", "the", "value", "of", "the", "orient", "attribute", "of", "the", "<w", ":", "pgSz", ">", "child", "element", "or", "WD_ORIENTATION", ".", "PORTRAIT", "if", "not", "present", ...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L208-L217
[ "def", "orientation", "(", "self", ")", ":", "pgSz", "=", "self", ".", "pgSz", "if", "pgSz", "is", "None", ":", "return", "WD_ORIENTATION", ".", "PORTRAIT", "return", "pgSz", ".", "orient" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.remove_footerReference
Return rId of w:footerReference child of *type_* after removing it.
docx/oxml/section.py
def remove_footerReference(self, type_): """Return rId of w:footerReference child of *type_* after removing it.""" footerReference = self.get_footerReference(type_) rId = footerReference.rId self.remove(footerReference) return rId
def remove_footerReference(self, type_): """Return rId of w:footerReference child of *type_* after removing it.""" footerReference = self.get_footerReference(type_) rId = footerReference.rId self.remove(footerReference) return rId
[ "Return", "rId", "of", "w", ":", "footerReference", "child", "of", "*", "type_", "*", "after", "removing", "it", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L263-L268
[ "def", "remove_footerReference", "(", "self", ",", "type_", ")", ":", "footerReference", "=", "self", ".", "get_footerReference", "(", "type_", ")", "rId", "=", "footerReference", ".", "rId", "self", ".", "remove", "(", "footerReference", ")", "return", "rId" ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.remove_headerReference
Return rId of w:headerReference child of *type_* after removing it.
docx/oxml/section.py
def remove_headerReference(self, type_): """Return rId of w:headerReference child of *type_* after removing it.""" headerReference = self.get_headerReference(type_) rId = headerReference.rId self.remove(headerReference) return rId
def remove_headerReference(self, type_): """Return rId of w:headerReference child of *type_* after removing it.""" headerReference = self.get_headerReference(type_) rId = headerReference.rId self.remove(headerReference) return rId
[ "Return", "rId", "of", "w", ":", "headerReference", "child", "of", "*", "type_", "*", "after", "removing", "it", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L270-L275
[ "def", "remove_headerReference", "(", "self", ",", "type_", ")", ":", "headerReference", "=", "self", ".", "get_headerReference", "(", "type_", ")", "rId", "=", "headerReference", ".", "rId", "self", ".", "remove", "(", "headerReference", ")", "return", "rId" ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_SectPr.start_type
The member of the ``WD_SECTION_START`` enumeration corresponding to the value of the ``val`` attribute of the ``<w:type>`` child element, or ``WD_SECTION_START.NEW_PAGE`` if not present.
docx/oxml/section.py
def start_type(self): """ The member of the ``WD_SECTION_START`` enumeration corresponding to the value of the ``val`` attribute of the ``<w:type>`` child element, or ``WD_SECTION_START.NEW_PAGE`` if not present. """ type = self.type if type is None or type.val is...
def start_type(self): """ The member of the ``WD_SECTION_START`` enumeration corresponding to the value of the ``val`` attribute of the ``<w:type>`` child element, or ``WD_SECTION_START.NEW_PAGE`` if not present. """ type = self.type if type is None or type.val is...
[ "The", "member", "of", "the", "WD_SECTION_START", "enumeration", "corresponding", "to", "the", "value", "of", "the", "val", "attribute", "of", "the", "<w", ":", "type", ">", "child", "element", "or", "WD_SECTION_START", ".", "NEW_PAGE", "if", "not", "present",...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/section.py#L295-L304
[ "def", "start_type", "(", "self", ")", ":", "type", "=", "self", ".", "type", "if", "type", "is", "None", "or", "type", ".", "val", "is", "None", ":", "return", "WD_SECTION_START", ".", "NEW_PAGE", "return", "type", ".", "val" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_LatentStyles.bool_prop
Return the boolean value of the attribute having *attr_name*, or |False| if not present.
docx/oxml/styles.py
def bool_prop(self, attr_name): """ Return the boolean value of the attribute having *attr_name*, or |False| if not present. """ value = getattr(self, attr_name) if value is None: return False return value
def bool_prop(self, attr_name): """ Return the boolean value of the attribute having *attr_name*, or |False| if not present. """ value = getattr(self, attr_name) if value is None: return False return value
[ "Return", "the", "boolean", "value", "of", "the", "attribute", "having", "*", "attr_name", "*", "or", "|False|", "if", "not", "present", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/styles.py#L49-L57
[ "def", "bool_prop", "(", "self", ",", "attr_name", ")", ":", "value", "=", "getattr", "(", "self", ",", "attr_name", ")", "if", "value", "is", "None", ":", "return", "False", "return", "value" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_Style.base_style
Sibling CT_Style element this style is based on or |None| if no base style or base style not found.
docx/oxml/styles.py
def base_style(self): """ Sibling CT_Style element this style is based on or |None| if no base style or base style not found. """ basedOn = self.basedOn if basedOn is None: return None styles = self.getparent() base_style = styles.get_by_id(bas...
def base_style(self): """ Sibling CT_Style element this style is based on or |None| if no base style or base style not found. """ basedOn = self.basedOn if basedOn is None: return None styles = self.getparent() base_style = styles.get_by_id(bas...
[ "Sibling", "CT_Style", "element", "this", "style", "is", "based", "on", "or", "|None|", "if", "no", "base", "style", "or", "base", "style", "not", "found", "." ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/styles.py#L154-L166
[ "def", "base_style", "(", "self", ")", ":", "basedOn", "=", "self", ".", "basedOn", "if", "basedOn", "is", "None", ":", "return", "None", "styles", "=", "self", ".", "getparent", "(", ")", "base_style", "=", "styles", ".", "get_by_id", "(", "basedOn", ...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_Style.next_style
Sibling CT_Style element identified by the value of `w:name/@w:val` or |None| if no value is present or no style with that style id is found.
docx/oxml/styles.py
def next_style(self): """ Sibling CT_Style element identified by the value of `w:name/@w:val` or |None| if no value is present or no style with that style id is found. """ next = self.next if next is None: return None styles = self.getparent() ...
def next_style(self): """ Sibling CT_Style element identified by the value of `w:name/@w:val` or |None| if no value is present or no style with that style id is found. """ next = self.next if next is None: return None styles = self.getparent() ...
[ "Sibling", "CT_Style", "element", "identified", "by", "the", "value", "of", "w", ":", "name", "/" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/styles.py#L209-L219
[ "def", "next_style", "(", "self", ")", ":", "next", "=", "self", ".", "next", "if", "next", "is", "None", ":", "return", "None", "styles", "=", "self", ".", "getparent", "(", ")", "return", "styles", ".", "get_by_id", "(", "next", ".", "val", ")" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_Styles.add_style_of_type
Return a newly added `w:style` element having *name* and *style_type*. `w:style/@customStyle` is set based on the value of *builtin*.
docx/oxml/styles.py
def add_style_of_type(self, name, style_type, builtin): """ Return a newly added `w:style` element having *name* and *style_type*. `w:style/@customStyle` is set based on the value of *builtin*. """ style = self.add_style() style.type = style_type style.cus...
def add_style_of_type(self, name, style_type, builtin): """ Return a newly added `w:style` element having *name* and *style_type*. `w:style/@customStyle` is set based on the value of *builtin*. """ style = self.add_style() style.type = style_type style.cus...
[ "Return", "a", "newly", "added", "w", ":", "style", "element", "having", "*", "name", "*", "and", "*", "style_type", "*", ".", "w", ":", "style", "/" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/styles.py#L299-L310
[ "def", "add_style_of_type", "(", "self", ",", "name", ",", "style_type", ",", "builtin", ")", ":", "style", "=", "self", ".", "add_style", "(", ")", "style", ".", "type", "=", "style_type", "style", ".", "customStyle", "=", "None", "if", "builtin", "else...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_Styles.default_for
Return `w:style[@w:type="*{style_type}*][-1]` or |None| if not found.
docx/oxml/styles.py
def default_for(self, style_type): """ Return `w:style[@w:type="*{style_type}*][-1]` or |None| if not found. """ default_styles_for_type = [ s for s in self._iter_styles() if s.type == style_type and s.default ] if not default_styles_for_type: ...
def default_for(self, style_type): """ Return `w:style[@w:type="*{style_type}*][-1]` or |None| if not found. """ default_styles_for_type = [ s for s in self._iter_styles() if s.type == style_type and s.default ] if not default_styles_for_type: ...
[ "Return", "w", ":", "style", "[" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/styles.py#L312-L323
[ "def", "default_for", "(", "self", ",", "style_type", ")", ":", "default_styles_for_type", "=", "[", "s", "for", "s", "in", "self", ".", "_iter_styles", "(", ")", "if", "s", ".", "type", "==", "style_type", "and", "s", ".", "default", "]", "if", "not",...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
Run.add_break
Add a break element of *break_type* to this run. *break_type* can take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and `WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`. *break_type* defaults to `WD_BREAK.LINE`.
docx/text/run.py
def add_break(self, break_type=WD_BREAK.LINE): """ Add a break element of *break_type* to this run. *break_type* can take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and `WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`. *break_type* defaults to `WD_BREAK.LINE...
def add_break(self, break_type=WD_BREAK.LINE): """ Add a break element of *break_type* to this run. *break_type* can take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and `WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`. *break_type* defaults to `WD_BREAK.LINE...
[ "Add", "a", "break", "element", "of", "*", "break_type", "*", "to", "this", "run", ".", "*", "break_type", "*", "can", "take", "the", "values", "WD_BREAK", ".", "LINE", "WD_BREAK", ".", "PAGE", "and", "WD_BREAK", ".", "COLUMN", "where", "WD_BREAK", "is",...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/text/run.py#L28-L47
[ "def", "add_break", "(", "self", ",", "break_type", "=", "WD_BREAK", ".", "LINE", ")", ":", "type_", ",", "clear", "=", "{", "WD_BREAK", ".", "LINE", ":", "(", "None", ",", "None", ")", ",", "WD_BREAK", ".", "PAGE", ":", "(", "'page'", ",", "None",...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
Run.add_picture
Return an |InlineShape| instance containing the image identified by *image_path_or_stream*, added to the end of this run. *image_path_or_stream* can be a path (a string) or a file-like object containing a binary image. If neither width nor height is specified, the picture appears at its ...
docx/text/run.py
def add_picture(self, image_path_or_stream, width=None, height=None): """ Return an |InlineShape| instance containing the image identified by *image_path_or_stream*, added to the end of this run. *image_path_or_stream* can be a path (a string) or a file-like object containing a b...
def add_picture(self, image_path_or_stream, width=None, height=None): """ Return an |InlineShape| instance containing the image identified by *image_path_or_stream*, added to the end of this run. *image_path_or_stream* can be a path (a string) or a file-like object containing a b...
[ "Return", "an", "|InlineShape|", "instance", "containing", "the", "image", "identified", "by", "*", "image_path_or_stream", "*", "added", "to", "the", "end", "of", "this", "run", ".", "*", "image_path_or_stream", "*", "can", "be", "a", "path", "(", "a", "str...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/text/run.py#L49-L64
[ "def", "add_picture", "(", "self", ",", "image_path_or_stream", ",", "width", "=", "None", ",", "height", "=", "None", ")", ":", "inline", "=", "self", ".", "part", ".", "new_pic_inline", "(", "image_path_or_stream", ",", "width", ",", "height", ")", "self...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
Run.add_text
Returns a newly appended |_Text| object (corresponding to a new ``<w:t>`` child element) to the run, containing *text*. Compare with the possibly more friendly approach of assigning text to the :attr:`Run.text` property.
docx/text/run.py
def add_text(self, text): """ Returns a newly appended |_Text| object (corresponding to a new ``<w:t>`` child element) to the run, containing *text*. Compare with the possibly more friendly approach of assigning text to the :attr:`Run.text` property. """ t = self....
def add_text(self, text): """ Returns a newly appended |_Text| object (corresponding to a new ``<w:t>`` child element) to the run, containing *text*. Compare with the possibly more friendly approach of assigning text to the :attr:`Run.text` property. """ t = self....
[ "Returns", "a", "newly", "appended", "|_Text|", "object", "(", "corresponding", "to", "a", "new", "<w", ":", "t", ">", "child", "element", ")", "to", "the", "run", "containing", "*", "text", "*", ".", "Compare", "with", "the", "possibly", "more", "friend...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/text/run.py#L73-L81
[ "def", "add_text", "(", "self", ",", "text", ")", ":", "t", "=", "self", ".", "_r", ".", "add_t", "(", "text", ")", "return", "_Text", "(", "t", ")" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
Run.style
Read/write. A |_CharacterStyle| object representing the character style applied to this run. The default character style for the document (often `Default Character Font`) is returned if the run has no directly-applied character style. Setting this property to |None| removes any directly-...
docx/text/run.py
def style(self): """ Read/write. A |_CharacterStyle| object representing the character style applied to this run. The default character style for the document (often `Default Character Font`) is returned if the run has no directly-applied character style. Setting this property to...
def style(self): """ Read/write. A |_CharacterStyle| object representing the character style applied to this run. The default character style for the document (often `Default Character Font`) is returned if the run has no directly-applied character style. Setting this property to...
[ "Read", "/", "write", ".", "A", "|_CharacterStyle|", "object", "representing", "the", "character", "style", "applied", "to", "this", "run", ".", "The", "default", "character", "style", "for", "the", "document", "(", "often", "Default", "Character", "Font", ")"...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/text/run.py#L123-L132
[ "def", "style", "(", "self", ")", ":", "style_id", "=", "self", ".", "_r", ".", "style", "return", "self", ".", "part", ".", "get_style", "(", "style_id", ",", "WD_STYLE_TYPE", ".", "CHARACTER", ")" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_PPr.first_line_indent
A |Length| value calculated from the values of `w:ind/@w:firstLine` and `w:ind/@w:hanging`. Returns |None| if the `w:ind` child is not present.
docx/oxml/text/parfmt.py
def first_line_indent(self): """ A |Length| value calculated from the values of `w:ind/@w:firstLine` and `w:ind/@w:hanging`. Returns |None| if the `w:ind` child is not present. """ ind = self.ind if ind is None: return None hanging = ind.hangin...
def first_line_indent(self): """ A |Length| value calculated from the values of `w:ind/@w:firstLine` and `w:ind/@w:hanging`. Returns |None| if the `w:ind` child is not present. """ ind = self.ind if ind is None: return None hanging = ind.hangin...
[ "A", "|Length|", "value", "calculated", "from", "the", "values", "of", "w", ":", "ind", "/" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/parfmt.py#L64-L79
[ "def", "first_line_indent", "(", "self", ")", ":", "ind", "=", "self", ".", "ind", "if", "ind", "is", "None", ":", "return", "None", "hanging", "=", "ind", ".", "hanging", "if", "hanging", "is", "not", "None", ":", "return", "Length", "(", "-", "hang...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_PPr.spacing_lineRule
The value of `w:spacing/@w:lineRule` as a member of the :ref:`WdLineSpacing` enumeration. Only the `MULTIPLE`, `EXACTLY`, and `AT_LEAST` members are used. It is the responsibility of the client to calculate the use of `SINGLE`, `DOUBLE`, and `MULTIPLE` based on the value of `w:spacing/@w...
docx/oxml/text/parfmt.py
def spacing_lineRule(self): """ The value of `w:spacing/@w:lineRule` as a member of the :ref:`WdLineSpacing` enumeration. Only the `MULTIPLE`, `EXACTLY`, and `AT_LEAST` members are used. It is the responsibility of the client to calculate the use of `SINGLE`, `DOUBLE`, and `MULTI...
def spacing_lineRule(self): """ The value of `w:spacing/@w:lineRule` as a member of the :ref:`WdLineSpacing` enumeration. Only the `MULTIPLE`, `EXACTLY`, and `AT_LEAST` members are used. It is the responsibility of the client to calculate the use of `SINGLE`, `DOUBLE`, and `MULTI...
[ "The", "value", "of", "w", ":", "spacing", "/" ]
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/parfmt.py#L245-L259
[ "def", "spacing_lineRule", "(", "self", ")", ":", "spacing", "=", "self", ".", "spacing", "if", "spacing", "is", "None", ":", "return", "None", "lineRule", "=", "spacing", ".", "lineRule", "if", "lineRule", "is", "None", "and", "spacing", ".", "line", "i...
6756f6cd145511d3eb6d1d188beea391b1ddfd53
train
CT_PPr.style
Set val attribute of <w:pStyle> child element to *style*, adding a new element if necessary. If *style* is |None|, remove the <w:pStyle> element if present.
docx/oxml/text/parfmt.py
def style(self, style): """ Set val attribute of <w:pStyle> child element to *style*, adding a new element if necessary. If *style* is |None|, remove the <w:pStyle> element if present. """ if style is None: self._remove_pStyle() return pSty...
def style(self, style): """ Set val attribute of <w:pStyle> child element to *style*, adding a new element if necessary. If *style* is |None|, remove the <w:pStyle> element if present. """ if style is None: self._remove_pStyle() return pSty...
[ "Set", "val", "attribute", "of", "<w", ":", "pStyle", ">", "child", "element", "to", "*", "style", "*", "adding", "a", "new", "element", "if", "necessary", ".", "If", "*", "style", "*", "is", "|None|", "remove", "the", "<w", ":", "pStyle", ">", "elem...
python-openxml/python-docx
python
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/oxml/text/parfmt.py#L279-L289
[ "def", "style", "(", "self", ",", "style", ")", ":", "if", "style", "is", "None", ":", "self", ".", "_remove_pStyle", "(", ")", "return", "pStyle", "=", "self", ".", "get_or_add_pStyle", "(", ")", "pStyle", ".", "val", "=", "style" ]
6756f6cd145511d3eb6d1d188beea391b1ddfd53