repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
aws/aws-xray-sdk-python
aws_xray_sdk/ext/util.py
calculate_segment_name
def calculate_segment_name(host_name, recorder): """ Returns the segment name based on recorder configuration and input host name. This is a helper generally used in web framework middleware where a host name is available from incoming request's headers. """ if recorder.dynamic_naming: r...
python
def calculate_segment_name(host_name, recorder): """ Returns the segment name based on recorder configuration and input host name. This is a helper generally used in web framework middleware where a host name is available from incoming request's headers. """ if recorder.dynamic_naming: r...
[ "def", "calculate_segment_name", "(", "host_name", ",", "recorder", ")", ":", "if", "recorder", ".", "dynamic_naming", ":", "return", "recorder", ".", "dynamic_naming", ".", "get_name", "(", "host_name", ")", "else", ":", "return", "recorder", ".", "service" ]
Returns the segment name based on recorder configuration and input host name. This is a helper generally used in web framework middleware where a host name is available from incoming request's headers.
[ "Returns", "the", "segment", "name", "based", "on", "recorder", "configuration", "and", "input", "host", "name", ".", "This", "is", "a", "helper", "generally", "used", "in", "web", "framework", "middleware", "where", "a", "host", "name", "is", "available", "...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/util.py#L76-L85
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/util.py
prepare_response_header
def prepare_response_header(origin_header, segment): """ Prepare a trace header to be inserted into response based on original header and the request segment. """ if origin_header and origin_header.sampled == '?': new_header = TraceHeader(root=segment.trace_id, ...
python
def prepare_response_header(origin_header, segment): """ Prepare a trace header to be inserted into response based on original header and the request segment. """ if origin_header and origin_header.sampled == '?': new_header = TraceHeader(root=segment.trace_id, ...
[ "def", "prepare_response_header", "(", "origin_header", ",", "segment", ")", ":", "if", "origin_header", "and", "origin_header", ".", "sampled", "==", "'?'", ":", "new_header", "=", "TraceHeader", "(", "root", "=", "segment", ".", "trace_id", ",", "sampled", "...
Prepare a trace header to be inserted into response based on original header and the request segment.
[ "Prepare", "a", "trace", "header", "to", "be", "inserted", "into", "response", "based", "on", "original", "header", "and", "the", "request", "segment", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/util.py#L88-L99
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/util.py
to_snake_case
def to_snake_case(name): """ Convert the input string to snake-cased string. """ s1 = first_cap_re.sub(r'\1_\2', name) # handle acronym words return all_cap_re.sub(r'\1_\2', s1).lower()
python
def to_snake_case(name): """ Convert the input string to snake-cased string. """ s1 = first_cap_re.sub(r'\1_\2', name) # handle acronym words return all_cap_re.sub(r'\1_\2', s1).lower()
[ "def", "to_snake_case", "(", "name", ")", ":", "s1", "=", "first_cap_re", ".", "sub", "(", "r'\\1_\\2'", ",", "name", ")", "return", "all_cap_re", ".", "sub", "(", "r'\\1_\\2'", ",", "s1", ")", ".", "lower", "(", ")" ]
Convert the input string to snake-cased string.
[ "Convert", "the", "input", "string", "to", "snake", "-", "cased", "string", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/util.py#L102-L108
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/botocore/patch.py
patch
def patch(): """ Patch botocore client so it generates subsegments when calling AWS services. """ if hasattr(botocore.client, '_xray_enabled'): return setattr(botocore.client, '_xray_enabled', True) wrapt.wrap_function_wrapper( 'botocore.client', 'BaseClient._make_ap...
python
def patch(): """ Patch botocore client so it generates subsegments when calling AWS services. """ if hasattr(botocore.client, '_xray_enabled'): return setattr(botocore.client, '_xray_enabled', True) wrapt.wrap_function_wrapper( 'botocore.client', 'BaseClient._make_ap...
[ "def", "patch", "(", ")", ":", "if", "hasattr", "(", "botocore", ".", "client", ",", "'_xray_enabled'", ")", ":", "return", "setattr", "(", "botocore", ".", "client", ",", "'_xray_enabled'", ",", "True", ")", "wrapt", ".", "wrap_function_wrapper", "(", "'b...
Patch botocore client so it generates subsegments when calling AWS services.
[ "Patch", "botocore", "client", "so", "it", "generates", "subsegments", "when", "calling", "AWS", "services", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/botocore/patch.py#L8-L27
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.configure
def configure(self, sampling=None, plugins=None, context_missing=None, sampling_rules=None, daemon_address=None, service=None, context=None, emitter=None, streaming=None, dynamic_naming=None, streaming_threshold=None, max_trace_ba...
python
def configure(self, sampling=None, plugins=None, context_missing=None, sampling_rules=None, daemon_address=None, service=None, context=None, emitter=None, streaming=None, dynamic_naming=None, streaming_threshold=None, max_trace_ba...
[ "def", "configure", "(", "self", ",", "sampling", "=", "None", ",", "plugins", "=", "None", ",", "context_missing", "=", "None", ",", "sampling_rules", "=", "None", ",", "daemon_address", "=", "None", ",", "service", "=", "None", ",", "context", "=", "No...
Configure global X-Ray recorder. Configure needs to run before patching thrid party libraries to avoid creating dangling subsegment. :param bool sampling: If sampling is enabled, every time the recorder creates a segment it decides whether to send this segment to the X-R...
[ "Configure", "global", "X", "-", "Ray", "recorder", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L81-L183
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.begin_segment
def begin_segment(self, name=None, traceid=None, parent_id=None, sampling=None): """ Begin a segment on the current thread and return it. The recorder only keeps one segment at a time. Create the second one without closing existing one will overwrite it. :p...
python
def begin_segment(self, name=None, traceid=None, parent_id=None, sampling=None): """ Begin a segment on the current thread and return it. The recorder only keeps one segment at a time. Create the second one without closing existing one will overwrite it. :p...
[ "def", "begin_segment", "(", "self", ",", "name", "=", "None", ",", "traceid", "=", "None", ",", "parent_id", "=", "None", ",", "sampling", "=", "None", ")", ":", "seg_name", "=", "name", "or", "self", ".", "service", "if", "not", "seg_name", ":", "r...
Begin a segment on the current thread and return it. The recorder only keeps one segment at a time. Create the second one without closing existing one will overwrite it. :param str name: the name of the segment :param str traceid: trace id of the segment :param int sampling: 0 m...
[ "Begin", "a", "segment", "on", "the", "current", "thread", "and", "return", "it", ".", "The", "recorder", "only", "keeps", "one", "segment", "at", "a", "time", ".", "Create", "the", "second", "one", "without", "closing", "existing", "one", "will", "overwri...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L203-L246
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.end_segment
def end_segment(self, end_time=None): """ End the current segment and send it to X-Ray daemon if it is ready to send. Ready means segment and all its subsegments are closed. :param float end_time: segment compeletion in unix epoch in seconds. """ self.context.end...
python
def end_segment(self, end_time=None): """ End the current segment and send it to X-Ray daemon if it is ready to send. Ready means segment and all its subsegments are closed. :param float end_time: segment compeletion in unix epoch in seconds. """ self.context.end...
[ "def", "end_segment", "(", "self", ",", "end_time", "=", "None", ")", ":", "self", ".", "context", ".", "end_segment", "(", "end_time", ")", "segment", "=", "self", ".", "current_segment", "(", ")", "if", "segment", "and", "segment", ".", "ready_to_send", ...
End the current segment and send it to X-Ray daemon if it is ready to send. Ready means segment and all its subsegments are closed. :param float end_time: segment compeletion in unix epoch in seconds.
[ "End", "the", "current", "segment", "and", "send", "it", "to", "X", "-", "Ray", "daemon", "if", "it", "is", "ready", "to", "send", ".", "Ready", "means", "segment", "and", "all", "its", "subsegments", "are", "closed", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L248-L259
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.current_segment
def current_segment(self): """ Return the currently active segment. In a multithreading environment, this will make sure the segment returned is the one created by the same thread. """ entity = self.get_trace_entity() if self._is_subsegment(entity): re...
python
def current_segment(self): """ Return the currently active segment. In a multithreading environment, this will make sure the segment returned is the one created by the same thread. """ entity = self.get_trace_entity() if self._is_subsegment(entity): re...
[ "def", "current_segment", "(", "self", ")", ":", "entity", "=", "self", ".", "get_trace_entity", "(", ")", "if", "self", ".", "_is_subsegment", "(", "entity", ")", ":", "return", "entity", ".", "parent_segment", "else", ":", "return", "entity" ]
Return the currently active segment. In a multithreading environment, this will make sure the segment returned is the one created by the same thread.
[ "Return", "the", "currently", "active", "segment", ".", "In", "a", "multithreading", "environment", "this", "will", "make", "sure", "the", "segment", "returned", "is", "the", "one", "created", "by", "the", "same", "thread", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L261-L271
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.begin_subsegment
def begin_subsegment(self, name, namespace='local'): """ Begin a new subsegment. If there is open subsegment, the newly created subsegment will be the child of latest opened subsegment. If not, it will be the child of the current open segment. :param str name: the name o...
python
def begin_subsegment(self, name, namespace='local'): """ Begin a new subsegment. If there is open subsegment, the newly created subsegment will be the child of latest opened subsegment. If not, it will be the child of the current open segment. :param str name: the name o...
[ "def", "begin_subsegment", "(", "self", ",", "name", ",", "namespace", "=", "'local'", ")", ":", "segment", "=", "self", ".", "current_segment", "(", ")", "if", "not", "segment", ":", "log", ".", "warning", "(", "\"No segment found, cannot begin subsegment %s.\"...
Begin a new subsegment. If there is open subsegment, the newly created subsegment will be the child of latest opened subsegment. If not, it will be the child of the current open segment. :param str name: the name of the subsegment. :param str namespace: currently can only be 'lo...
[ "Begin", "a", "new", "subsegment", ".", "If", "there", "is", "open", "subsegment", "the", "newly", "created", "subsegment", "will", "be", "the", "child", "of", "latest", "opened", "subsegment", ".", "If", "not", "it", "will", "be", "the", "child", "of", ...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L273-L296
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.end_subsegment
def end_subsegment(self, end_time=None): """ End the current active subsegment. If this is the last one open under its parent segment, the entire segment will be sent. :param float end_time: subsegment compeletion in unix epoch in seconds. """ if not self.context.end_sub...
python
def end_subsegment(self, end_time=None): """ End the current active subsegment. If this is the last one open under its parent segment, the entire segment will be sent. :param float end_time: subsegment compeletion in unix epoch in seconds. """ if not self.context.end_sub...
[ "def", "end_subsegment", "(", "self", ",", "end_time", "=", "None", ")", ":", "if", "not", "self", ".", "context", ".", "end_subsegment", "(", "end_time", ")", ":", "return", "if", "self", ".", "current_segment", "(", ")", ".", "ready_to_send", "(", ")",...
End the current active subsegment. If this is the last one open under its parent segment, the entire segment will be sent. :param float end_time: subsegment compeletion in unix epoch in seconds.
[ "End", "the", "current", "active", "subsegment", ".", "If", "this", "is", "the", "last", "one", "open", "under", "its", "parent", "segment", "the", "entire", "segment", "will", "be", "sent", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L310-L325
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.put_annotation
def put_annotation(self, key, value): """ Annotate current active trace entity with a key-value pair. Annotations will be indexed for later search query. :param str key: annotation key :param object value: annotation value. Any type other than string/number/bool will...
python
def put_annotation(self, key, value): """ Annotate current active trace entity with a key-value pair. Annotations will be indexed for later search query. :param str key: annotation key :param object value: annotation value. Any type other than string/number/bool will...
[ "def", "put_annotation", "(", "self", ",", "key", ",", "value", ")", ":", "entity", "=", "self", ".", "get_trace_entity", "(", ")", "if", "entity", "and", "entity", ".", "sampled", ":", "entity", ".", "put_annotation", "(", "key", ",", "value", ")" ]
Annotate current active trace entity with a key-value pair. Annotations will be indexed for later search query. :param str key: annotation key :param object value: annotation value. Any type other than string/number/bool will be dropped
[ "Annotate", "current", "active", "trace", "entity", "with", "a", "key", "-", "value", "pair", ".", "Annotations", "will", "be", "indexed", "for", "later", "search", "query", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L327-L338
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.put_metadata
def put_metadata(self, key, value, namespace='default'): """ Add metadata to the current active trace entity. Metadata is not indexed but can be later retrieved by BatchGetTraces API. :param str namespace: optional. Default namespace is `default`. It must be a string...
python
def put_metadata(self, key, value, namespace='default'): """ Add metadata to the current active trace entity. Metadata is not indexed but can be later retrieved by BatchGetTraces API. :param str namespace: optional. Default namespace is `default`. It must be a string...
[ "def", "put_metadata", "(", "self", ",", "key", ",", "value", ",", "namespace", "=", "'default'", ")", ":", "entity", "=", "self", ".", "get_trace_entity", "(", ")", "if", "entity", "and", "entity", ".", "sampled", ":", "entity", ".", "put_metadata", "("...
Add metadata to the current active trace entity. Metadata is not indexed but can be later retrieved by BatchGetTraces API. :param str namespace: optional. Default namespace is `default`. It must be a string and prefix `AWS.` is reserved. :param str key: metadata key under sp...
[ "Add", "metadata", "to", "the", "current", "active", "trace", "entity", ".", "Metadata", "is", "not", "indexed", "but", "can", "be", "later", "retrieved", "by", "BatchGetTraces", "API", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L340-L353
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder.stream_subsegments
def stream_subsegments(self): """ Stream all closed subsegments to the daemon and remove reference to the parent segment. No-op for a not sampled segment. """ segment = self.current_segment() if self.streaming.is_eligible(segment): self.streaming.stre...
python
def stream_subsegments(self): """ Stream all closed subsegments to the daemon and remove reference to the parent segment. No-op for a not sampled segment. """ segment = self.current_segment() if self.streaming.is_eligible(segment): self.streaming.stre...
[ "def", "stream_subsegments", "(", "self", ")", ":", "segment", "=", "self", ".", "current_segment", "(", ")", "if", "self", ".", "streaming", ".", "is_eligible", "(", "segment", ")", ":", "self", ".", "streaming", ".", "stream", "(", "segment", ",", "sel...
Stream all closed subsegments to the daemon and remove reference to the parent segment. No-op for a not sampled segment.
[ "Stream", "all", "closed", "subsegments", "to", "the", "daemon", "and", "remove", "reference", "to", "the", "parent", "segment", ".", "No", "-", "op", "for", "a", "not", "sampled", "segment", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L383-L392
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/recorder.py
AWSXRayRecorder._send_segment
def _send_segment(self): """ Send the current segment to X-Ray daemon if it is present and sampled, then clean up context storage. The emitter will handle failures. """ segment = self.current_segment() if not segment: return if segment.sample...
python
def _send_segment(self): """ Send the current segment to X-Ray daemon if it is present and sampled, then clean up context storage. The emitter will handle failures. """ segment = self.current_segment() if not segment: return if segment.sample...
[ "def", "_send_segment", "(", "self", ")", ":", "segment", "=", "self", ".", "current_segment", "(", ")", "if", "not", "segment", ":", "return", "if", "segment", ".", "sampled", ":", "self", ".", "emitter", ".", "send_entity", "(", "segment", ")", "self",...
Send the current segment to X-Ray daemon if it is present and sampled, then clean up context storage. The emitter will handle failures.
[ "Send", "the", "current", "segment", "to", "X", "-", "Ray", "daemon", "if", "it", "is", "present", "and", "sampled", "then", "clean", "up", "context", "storage", ".", "The", "emitter", "will", "handle", "failures", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/recorder.py#L460-L473
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/local/sampling_rule.py
SamplingRule.applies
def applies(self, host, method, path): """ Determines whether or not this sampling rule applies to the incoming request based on some of the request's parameters. Any None parameters provided will be considered an implicit match. """ return (not host or wildcard_match(sel...
python
def applies(self, host, method, path): """ Determines whether or not this sampling rule applies to the incoming request based on some of the request's parameters. Any None parameters provided will be considered an implicit match. """ return (not host or wildcard_match(sel...
[ "def", "applies", "(", "self", ",", "host", ",", "method", ",", "path", ")", ":", "return", "(", "not", "host", "or", "wildcard_match", "(", "self", ".", "host", ",", "host", ")", ")", "and", "(", "not", "method", "or", "wildcard_match", "(", "self",...
Determines whether or not this sampling rule applies to the incoming request based on some of the request's parameters. Any None parameters provided will be considered an implicit match.
[ "Determines", "whether", "or", "not", "this", "sampling", "rule", "applies", "to", "the", "incoming", "request", "based", "on", "some", "of", "the", "request", "s", "parameters", ".", "Any", "None", "parameters", "provided", "will", "be", "considered", "an", ...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/local/sampling_rule.py#L43-L51
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/django/apps.py
XRayConfig.ready
def ready(self): """ Configure global XRay recorder based on django settings under XRAY_RECORDER namespace. This method could be called twice during server startup because of base command and reload command. So this function must be idempotent """ if not s...
python
def ready(self): """ Configure global XRay recorder based on django settings under XRAY_RECORDER namespace. This method could be called twice during server startup because of base command and reload command. So this function must be idempotent """ if not s...
[ "def", "ready", "(", "self", ")", ":", "if", "not", "settings", ".", "AWS_XRAY_TRACING_NAME", ":", "raise", "SegmentNameMissingException", "(", "'Segment name is required.'", ")", "xray_recorder", ".", "configure", "(", "daemon_address", "=", "settings", ".", "AWS_X...
Configure global XRay recorder based on django settings under XRAY_RECORDER namespace. This method could be called twice during server startup because of base command and reload command. So this function must be idempotent
[ "Configure", "global", "XRay", "recorder", "based", "on", "django", "settings", "under", "XRAY_RECORDER", "namespace", ".", "This", "method", "could", "be", "called", "twice", "during", "server", "startup", "because", "of", "base", "command", "and", "reload", "c...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/django/apps.py#L18-L59
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/sampler.py
DefaultSampler.start
def start(self): """ Start rule poller and target poller once X-Ray daemon address and context manager is in place. """ if not global_sdk_config.sdk_enabled(): return with self._lock: if not self._started: self._rule_poller.start()...
python
def start(self): """ Start rule poller and target poller once X-Ray daemon address and context manager is in place. """ if not global_sdk_config.sdk_enabled(): return with self._lock: if not self._started: self._rule_poller.start()...
[ "def", "start", "(", "self", ")", ":", "if", "not", "global_sdk_config", ".", "sdk_enabled", "(", ")", ":", "return", "with", "self", ".", "_lock", ":", "if", "not", "self", ".", "_started", ":", "self", ".", "_rule_poller", ".", "start", "(", ")", "...
Start rule poller and target poller once X-Ray daemon address and context manager is in place.
[ "Start", "rule", "poller", "and", "target", "poller", "once", "X", "-", "Ray", "daemon", "address", "and", "context", "manager", "is", "in", "place", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/sampler.py#L36-L48
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/sampler.py
DefaultSampler.should_trace
def should_trace(self, sampling_req=None): """ Return the matched sampling rule name if the sampler finds one and decide to sample. If no sampling rule matched, it falls back to the local sampler's ``should_trace`` implementation. All optional arguments are extracted from incomin...
python
def should_trace(self, sampling_req=None): """ Return the matched sampling rule name if the sampler finds one and decide to sample. If no sampling rule matched, it falls back to the local sampler's ``should_trace`` implementation. All optional arguments are extracted from incomin...
[ "def", "should_trace", "(", "self", ",", "sampling_req", "=", "None", ")", ":", "if", "not", "global_sdk_config", ".", "sdk_enabled", "(", ")", ":", "return", "False", "if", "not", "self", ".", "_started", ":", "self", ".", "start", "(", ")", "now", "=...
Return the matched sampling rule name if the sampler finds one and decide to sample. If no sampling rule matched, it falls back to the local sampler's ``should_trace`` implementation. All optional arguments are extracted from incoming requests by X-Ray middleware to perform path based sa...
[ "Return", "the", "matched", "sampling", "rule", "name", "if", "the", "sampler", "finds", "one", "and", "decide", "to", "sample", ".", "If", "no", "sampling", "rule", "matched", "it", "falls", "back", "to", "the", "local", "sampler", "s", "should_trace", "i...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/sampler.py#L50-L75
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/pynamodb/patch.py
patch
def patch(): """Patch PynamoDB so it generates subsegements when calling DynamoDB.""" import pynamodb if hasattr(botocore.vendored.requests.sessions, '_xray_enabled'): return setattr(botocore.vendored.requests.sessions, '_xray_enabled', True) wrapt.wrap_function_wrapper( 'botocore....
python
def patch(): """Patch PynamoDB so it generates subsegements when calling DynamoDB.""" import pynamodb if hasattr(botocore.vendored.requests.sessions, '_xray_enabled'): return setattr(botocore.vendored.requests.sessions, '_xray_enabled', True) wrapt.wrap_function_wrapper( 'botocore....
[ "def", "patch", "(", ")", ":", "import", "pynamodb", "if", "hasattr", "(", "botocore", ".", "vendored", ".", "requests", ".", "sessions", ",", "'_xray_enabled'", ")", ":", "return", "setattr", "(", "botocore", ".", "vendored", ".", "requests", ".", "sessio...
Patch PynamoDB so it generates subsegements when calling DynamoDB.
[ "Patch", "PynamoDB", "so", "it", "generates", "subsegements", "when", "calling", "DynamoDB", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/pynamodb/patch.py#L10-L22
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/context.py
Context.end_segment
def end_segment(self, end_time=None): """ End the current active segment. :param int end_time: epoch in seconds. If not specified the current system time will be used. """ entity = self.get_trace_entity() if not entity: log.warning("No segment to ...
python
def end_segment(self, end_time=None): """ End the current active segment. :param int end_time: epoch in seconds. If not specified the current system time will be used. """ entity = self.get_trace_entity() if not entity: log.warning("No segment to ...
[ "def", "end_segment", "(", "self", ",", "end_time", "=", "None", ")", ":", "entity", "=", "self", ".", "get_trace_entity", "(", ")", "if", "not", "entity", ":", "log", ".", "warning", "(", "\"No segment to end\"", ")", "return", "if", "self", ".", "_is_s...
End the current active segment. :param int end_time: epoch in seconds. If not specified the current system time will be used.
[ "End", "the", "current", "active", "segment", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/context.py#L40-L54
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/context.py
Context.put_subsegment
def put_subsegment(self, subsegment): """ Store the subsegment created by ``xray_recorder`` to the context. If you put a new subsegment while there is already an open subsegment, the new subsegment becomes the child of the existing subsegment. """ entity = self.get_trace_...
python
def put_subsegment(self, subsegment): """ Store the subsegment created by ``xray_recorder`` to the context. If you put a new subsegment while there is already an open subsegment, the new subsegment becomes the child of the existing subsegment. """ entity = self.get_trace_...
[ "def", "put_subsegment", "(", "self", ",", "subsegment", ")", ":", "entity", "=", "self", ".", "get_trace_entity", "(", ")", "if", "not", "entity", ":", "log", ".", "warning", "(", "\"Active segment or subsegment not found. Discarded %s.\"", "%", "subsegment", "."...
Store the subsegment created by ``xray_recorder`` to the context. If you put a new subsegment while there is already an open subsegment, the new subsegment becomes the child of the existing subsegment.
[ "Store", "the", "subsegment", "created", "by", "xray_recorder", "to", "the", "context", ".", "If", "you", "put", "a", "new", "subsegment", "while", "there", "is", "already", "an", "open", "subsegment", "the", "new", "subsegment", "becomes", "the", "child", "...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/context.py#L56-L68
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/context.py
Context.end_subsegment
def end_subsegment(self, end_time=None): """ End the current active segment. Return False if there is no subsegment to end. :param int end_time: epoch in seconds. If not specified the current system time will be used. """ subsegment = self.get_trace_entity() ...
python
def end_subsegment(self, end_time=None): """ End the current active segment. Return False if there is no subsegment to end. :param int end_time: epoch in seconds. If not specified the current system time will be used. """ subsegment = self.get_trace_entity() ...
[ "def", "end_subsegment", "(", "self", ",", "end_time", "=", "None", ")", ":", "subsegment", "=", "self", ".", "get_trace_entity", "(", ")", "if", "self", ".", "_is_subsegment", "(", "subsegment", ")", ":", "subsegment", ".", "close", "(", "end_time", ")", ...
End the current active segment. Return False if there is no subsegment to end. :param int end_time: epoch in seconds. If not specified the current system time will be used.
[ "End", "the", "current", "active", "segment", ".", "Return", "False", "if", "there", "is", "no", "subsegment", "to", "end", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/context.py#L70-L85
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/context.py
Context.handle_context_missing
def handle_context_missing(self): """ Called whenever there is no trace entity to access or mutate. """ if self.context_missing == 'RUNTIME_ERROR': log.error(MISSING_SEGMENT_MSG) raise SegmentNotFoundException(MISSING_SEGMENT_MSG) else: log.err...
python
def handle_context_missing(self): """ Called whenever there is no trace entity to access or mutate. """ if self.context_missing == 'RUNTIME_ERROR': log.error(MISSING_SEGMENT_MSG) raise SegmentNotFoundException(MISSING_SEGMENT_MSG) else: log.err...
[ "def", "handle_context_missing", "(", "self", ")", ":", "if", "self", ".", "context_missing", "==", "'RUNTIME_ERROR'", ":", "log", ".", "error", "(", "MISSING_SEGMENT_MSG", ")", "raise", "SegmentNotFoundException", "(", "MISSING_SEGMENT_MSG", ")", "else", ":", "lo...
Called whenever there is no trace entity to access or mutate.
[ "Called", "whenever", "there", "is", "no", "trace", "entity", "to", "access", "or", "mutate", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/context.py#L112-L120
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/lambda_launcher.py
check_in_lambda
def check_in_lambda(): """ Return None if SDK is not loaded in AWS Lambda worker. Otherwise drop a touch file and return a lambda context. """ if not os.getenv(LAMBDA_TASK_ROOT_KEY): return None try: os.mkdir(TOUCH_FILE_DIR) except OSError: log.debug('directory %s al...
python
def check_in_lambda(): """ Return None if SDK is not loaded in AWS Lambda worker. Otherwise drop a touch file and return a lambda context. """ if not os.getenv(LAMBDA_TASK_ROOT_KEY): return None try: os.mkdir(TOUCH_FILE_DIR) except OSError: log.debug('directory %s al...
[ "def", "check_in_lambda", "(", ")", ":", "if", "not", "os", ".", "getenv", "(", "LAMBDA_TASK_ROOT_KEY", ")", ":", "return", "None", "try", ":", "os", ".", "mkdir", "(", "TOUCH_FILE_DIR", ")", "except", "OSError", ":", "log", ".", "debug", "(", "'director...
Return None if SDK is not loaded in AWS Lambda worker. Otherwise drop a touch file and return a lambda context.
[ "Return", "None", "if", "SDK", "is", "not", "loaded", "in", "AWS", "Lambda", "worker", ".", "Otherwise", "drop", "a", "touch", "file", "and", "return", "a", "lambda", "context", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/lambda_launcher.py#L19-L40
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/lambda_launcher.py
LambdaContext._refresh_context
def _refresh_context(self): """ Get current facade segment. To prevent resource leaking in Lambda worker, every time there is segment present, we compare its trace id to current environment variables. If it is different we create a new facade segment and clean up subsegments stor...
python
def _refresh_context(self): """ Get current facade segment. To prevent resource leaking in Lambda worker, every time there is segment present, we compare its trace id to current environment variables. If it is different we create a new facade segment and clean up subsegments stor...
[ "def", "_refresh_context", "(", "self", ")", ":", "header_str", "=", "os", ".", "getenv", "(", "LAMBDA_TRACE_HEADER_KEY", ")", "trace_header", "=", "TraceHeader", ".", "from_header_str", "(", "header_str", ")", "if", "not", "global_sdk_config", ".", "sdk_enabled",...
Get current facade segment. To prevent resource leaking in Lambda worker, every time there is segment present, we compare its trace id to current environment variables. If it is different we create a new facade segment and clean up subsegments stored.
[ "Get", "current", "facade", "segment", ".", "To", "prevent", "resource", "leaking", "in", "Lambda", "worker", "every", "time", "there", "is", "segment", "present", "we", "compare", "its", "trace", "id", "to", "current", "environment", "variables", ".", "If", ...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/lambda_launcher.py#L88-L109
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/lambda_launcher.py
LambdaContext._initialize_context
def _initialize_context(self, trace_header): """ Create a facade segment based on environment variables set by AWS Lambda and initialize storage for subsegments. """ sampled = None if not global_sdk_config.sdk_enabled(): # Force subsequent subsegments to be di...
python
def _initialize_context(self, trace_header): """ Create a facade segment based on environment variables set by AWS Lambda and initialize storage for subsegments. """ sampled = None if not global_sdk_config.sdk_enabled(): # Force subsequent subsegments to be di...
[ "def", "_initialize_context", "(", "self", ",", "trace_header", ")", ":", "sampled", "=", "None", "if", "not", "global_sdk_config", ".", "sdk_enabled", "(", ")", ":", "sampled", "=", "False", "elif", "trace_header", ".", "sampled", "==", "0", ":", "sampled",...
Create a facade segment based on environment variables set by AWS Lambda and initialize storage for subsegments.
[ "Create", "a", "facade", "segment", "based", "on", "environment", "variables", "set", "by", "AWS", "Lambda", "and", "initialize", "storage", "for", "subsegments", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/lambda_launcher.py#L125-L146
train
aws/aws-xray-sdk-python
aws_xray_sdk/sdk_config.py
SDKConfig.set_sdk_enabled
def set_sdk_enabled(cls, value): """ Modifies the enabled flag if the "AWS_XRAY_SDK_ENABLED" environment variable is not set, otherwise, set the enabled flag to be equal to the environment variable. If the env variable is an invalid string boolean, it will default to true. :para...
python
def set_sdk_enabled(cls, value): """ Modifies the enabled flag if the "AWS_XRAY_SDK_ENABLED" environment variable is not set, otherwise, set the enabled flag to be equal to the environment variable. If the env variable is an invalid string boolean, it will default to true. :para...
[ "def", "set_sdk_enabled", "(", "cls", ",", "value", ")", ":", "if", "cls", ".", "XRAY_ENABLED_KEY", "in", "os", ".", "environ", ":", "cls", ".", "__SDK_ENABLED", "=", "str", "(", "os", ".", "getenv", "(", "cls", ".", "XRAY_ENABLED_KEY", ",", "'true'", ...
Modifies the enabled flag if the "AWS_XRAY_SDK_ENABLED" environment variable is not set, otherwise, set the enabled flag to be equal to the environment variable. If the env variable is an invalid string boolean, it will default to true. :param bool value: Flag to set whether the SDK is enabled ...
[ "Modifies", "the", "enabled", "flag", "if", "the", "AWS_XRAY_SDK_ENABLED", "environment", "variable", "is", "not", "set", "otherwise", "set", "the", "enabled", "flag", "to", "be", "equal", "to", "the", "environment", "variable", ".", "If", "the", "env", "varia...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/sdk_config.py#L40-L58
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/psycopg2/patch.py
_xray_register_type_fix
def _xray_register_type_fix(wrapped, instance, args, kwargs): """Send the actual connection or curser to register type.""" our_args = list(copy.copy(args)) if len(our_args) == 2 and isinstance(our_args[1], (XRayTracedConn, XRayTracedCursor)): our_args[1] = our_args[1].__wrapped__ return wrapped...
python
def _xray_register_type_fix(wrapped, instance, args, kwargs): """Send the actual connection or curser to register type.""" our_args = list(copy.copy(args)) if len(our_args) == 2 and isinstance(our_args[1], (XRayTracedConn, XRayTracedCursor)): our_args[1] = our_args[1].__wrapped__ return wrapped...
[ "def", "_xray_register_type_fix", "(", "wrapped", ",", "instance", ",", "args", ",", "kwargs", ")", ":", "our_args", "=", "list", "(", "copy", ".", "copy", "(", "args", ")", ")", "if", "len", "(", "our_args", ")", "==", "2", "and", "isinstance", "(", ...
Send the actual connection or curser to register type.
[ "Send", "the", "actual", "connection", "or", "curser", "to", "register", "type", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/psycopg2/patch.py#L42-L48
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/models/trace_header.py
TraceHeader.from_header_str
def from_header_str(cls, header): """ Create a TraceHeader object from a tracing header string extracted from a http request headers. """ if not header: return cls() try: params = header.strip().split(HEADER_DELIMITER) header_dict = {}...
python
def from_header_str(cls, header): """ Create a TraceHeader object from a tracing header string extracted from a http request headers. """ if not header: return cls() try: params = header.strip().split(HEADER_DELIMITER) header_dict = {}...
[ "def", "from_header_str", "(", "cls", ",", "header", ")", ":", "if", "not", "header", ":", "return", "cls", "(", ")", "try", ":", "params", "=", "header", ".", "strip", "(", ")", ".", "split", "(", "HEADER_DELIMITER", ")", "header_dict", "=", "{", "}...
Create a TraceHeader object from a tracing header string extracted from a http request headers.
[ "Create", "a", "TraceHeader", "object", "from", "a", "tracing", "header", "string", "extracted", "from", "a", "http", "request", "headers", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/models/trace_header.py#L42-L73
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/models/trace_header.py
TraceHeader.to_header_str
def to_header_str(self): """ Convert to a tracing header string that can be injected to outgoing http request headers. """ h_parts = [] if self.root: h_parts.append(ROOT + '=' + self.root) if self.parent: h_parts.append(PARENT + '=' + self....
python
def to_header_str(self): """ Convert to a tracing header string that can be injected to outgoing http request headers. """ h_parts = [] if self.root: h_parts.append(ROOT + '=' + self.root) if self.parent: h_parts.append(PARENT + '=' + self....
[ "def", "to_header_str", "(", "self", ")", ":", "h_parts", "=", "[", "]", "if", "self", ".", "root", ":", "h_parts", ".", "append", "(", "ROOT", "+", "'='", "+", "self", ".", "root", ")", "if", "self", ".", "parent", ":", "h_parts", ".", "append", ...
Convert to a tracing header string that can be injected to outgoing http request headers.
[ "Convert", "to", "a", "tracing", "header", "string", "that", "can", "be", "injected", "to", "outgoing", "http", "request", "headers", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/models/trace_header.py#L75-L91
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/models/default_dynamic_naming.py
DefaultDynamicNaming.get_name
def get_name(self, host_name): """ Returns the segment name based on the input host name. """ if wildcard_match(self._pattern, host_name): return host_name else: return self._fallback
python
def get_name(self, host_name): """ Returns the segment name based on the input host name. """ if wildcard_match(self._pattern, host_name): return host_name else: return self._fallback
[ "def", "get_name", "(", "self", ",", "host_name", ")", ":", "if", "wildcard_match", "(", "self", ".", "_pattern", ",", "host_name", ")", ":", "return", "host_name", "else", ":", "return", "self", ".", "_fallback" ]
Returns the segment name based on the input host name.
[ "Returns", "the", "segment", "name", "based", "on", "the", "input", "host", "name", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/models/default_dynamic_naming.py#L24-L31
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/emitters/udp_emitter.py
UDPEmitter.set_daemon_address
def set_daemon_address(self, address): """ Set up UDP ip and port from the raw daemon address string using ``DaemonConfig`` class utlities. """ if address: daemon_config = DaemonConfig(address) self._ip, self._port = daemon_config.udp_ip, daemon_config.udp...
python
def set_daemon_address(self, address): """ Set up UDP ip and port from the raw daemon address string using ``DaemonConfig`` class utlities. """ if address: daemon_config = DaemonConfig(address) self._ip, self._port = daemon_config.udp_ip, daemon_config.udp...
[ "def", "set_daemon_address", "(", "self", ",", "address", ")", ":", "if", "address", ":", "daemon_config", "=", "DaemonConfig", "(", "address", ")", "self", ".", "_ip", ",", "self", ".", "_port", "=", "daemon_config", ".", "udp_ip", ",", "daemon_config", "...
Set up UDP ip and port from the raw daemon address string using ``DaemonConfig`` class utlities.
[ "Set", "up", "UDP", "ip", "and", "port", "from", "the", "raw", "daemon", "address", "string", "using", "DaemonConfig", "class", "utlities", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/emitters/udp_emitter.py#L42-L49
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/aiobotocore/patch.py
patch
def patch(): """ Patch aiobotocore client so it generates subsegments when calling AWS services. """ if hasattr(aiobotocore.client, '_xray_enabled'): return setattr(aiobotocore.client, '_xray_enabled', True) wrapt.wrap_function_wrapper( 'aiobotocore.client', 'AioBase...
python
def patch(): """ Patch aiobotocore client so it generates subsegments when calling AWS services. """ if hasattr(aiobotocore.client, '_xray_enabled'): return setattr(aiobotocore.client, '_xray_enabled', True) wrapt.wrap_function_wrapper( 'aiobotocore.client', 'AioBase...
[ "def", "patch", "(", ")", ":", "if", "hasattr", "(", "aiobotocore", ".", "client", ",", "'_xray_enabled'", ")", ":", "return", "setattr", "(", "aiobotocore", ".", "client", ",", "'_xray_enabled'", ",", "True", ")", "wrapt", ".", "wrap_function_wrapper", "(",...
Patch aiobotocore client so it generates subsegments when calling AWS services.
[ "Patch", "aiobotocore", "client", "so", "it", "generates", "subsegments", "when", "calling", "AWS", "services", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/aiobotocore/patch.py#L8-L27
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/streaming/default_streaming.py
DefaultStreaming.is_eligible
def is_eligible(self, segment): """ A segment is eligible to have its children subsegments streamed if it is sampled and it breaches streaming threshold. """ if not segment or not segment.sampled: return False return segment.get_total_subsegments_size() > sel...
python
def is_eligible(self, segment): """ A segment is eligible to have its children subsegments streamed if it is sampled and it breaches streaming threshold. """ if not segment or not segment.sampled: return False return segment.get_total_subsegments_size() > sel...
[ "def", "is_eligible", "(", "self", ",", "segment", ")", ":", "if", "not", "segment", "or", "not", "segment", ".", "sampled", ":", "return", "False", "return", "segment", ".", "get_total_subsegments_size", "(", ")", ">", "self", ".", "streaming_threshold" ]
A segment is eligible to have its children subsegments streamed if it is sampled and it breaches streaming threshold.
[ "A", "segment", "is", "eligible", "to", "have", "its", "children", "subsegments", "streamed", "if", "it", "is", "sampled", "and", "it", "breaches", "streaming", "threshold", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/streaming/default_streaming.py#L14-L22
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/streaming/default_streaming.py
DefaultStreaming.stream
def stream(self, entity, callback): """ Stream out all eligible children of the input entity. :param entity: The target entity to be streamed. :param callback: The function that takes the node and actually send it out. """ with self._lock: self._s...
python
def stream(self, entity, callback): """ Stream out all eligible children of the input entity. :param entity: The target entity to be streamed. :param callback: The function that takes the node and actually send it out. """ with self._lock: self._s...
[ "def", "stream", "(", "self", ",", "entity", ",", "callback", ")", ":", "with", "self", ".", "_lock", ":", "self", ".", "_stream", "(", "entity", ",", "callback", ")" ]
Stream out all eligible children of the input entity. :param entity: The target entity to be streamed. :param callback: The function that takes the node and actually send it out.
[ "Stream", "out", "all", "eligible", "children", "of", "the", "input", "entity", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/streaming/default_streaming.py#L24-L33
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/sqlalchemy/util/decorators.py
parse_bind
def parse_bind(bind): """Parses a connection string and creates SQL trace metadata""" if isinstance(bind, Connection): engine = bind.engine else: engine = bind m = re.match(r"Engine\((.*?)\)", str(engine)) if m is not None: u = urlparse(m.group(1)) # Add Scheme to use...
python
def parse_bind(bind): """Parses a connection string and creates SQL trace metadata""" if isinstance(bind, Connection): engine = bind.engine else: engine = bind m = re.match(r"Engine\((.*?)\)", str(engine)) if m is not None: u = urlparse(m.group(1)) # Add Scheme to use...
[ "def", "parse_bind", "(", "bind", ")", ":", "if", "isinstance", "(", "bind", ",", "Connection", ")", ":", "engine", "=", "bind", ".", "engine", "else", ":", "engine", "=", "bind", "m", "=", "re", ".", "match", "(", "r\"Engine\\((.*?)\\)\"", ",", "str",...
Parses a connection string and creates SQL trace metadata
[ "Parses", "a", "connection", "string", "and", "creates", "SQL", "trace", "metadata" ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/sqlalchemy/util/decorators.py#L89-L113
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/models/subsegment.py
Subsegment.add_subsegment
def add_subsegment(self, subsegment): """ Add input subsegment as a child subsegment and increment reference counter and total subsegments counter of the parent segment. """ super(Subsegment, self).add_subsegment(subsegment) self.parent_segment.increment()
python
def add_subsegment(self, subsegment): """ Add input subsegment as a child subsegment and increment reference counter and total subsegments counter of the parent segment. """ super(Subsegment, self).add_subsegment(subsegment) self.parent_segment.increment()
[ "def", "add_subsegment", "(", "self", ",", "subsegment", ")", ":", "super", "(", "Subsegment", ",", "self", ")", ".", "add_subsegment", "(", "subsegment", ")", "self", ".", "parent_segment", ".", "increment", "(", ")" ]
Add input subsegment as a child subsegment and increment reference counter and total subsegments counter of the parent segment.
[ "Add", "input", "subsegment", "as", "a", "child", "subsegment", "and", "increment", "reference", "counter", "and", "total", "subsegments", "counter", "of", "the", "parent", "segment", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/models/subsegment.py#L111-L118
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/models/subsegment.py
Subsegment.remove_subsegment
def remove_subsegment(self, subsegment): """ Remove input subsegment from child subsegemnts and decrement parent segment total subsegments count. :param Subsegment: subsegment to remove. """ super(Subsegment, self).remove_subsegment(subsegment) self.parent_segmen...
python
def remove_subsegment(self, subsegment): """ Remove input subsegment from child subsegemnts and decrement parent segment total subsegments count. :param Subsegment: subsegment to remove. """ super(Subsegment, self).remove_subsegment(subsegment) self.parent_segmen...
[ "def", "remove_subsegment", "(", "self", ",", "subsegment", ")", ":", "super", "(", "Subsegment", ",", "self", ")", ".", "remove_subsegment", "(", "subsegment", ")", "self", ".", "parent_segment", ".", "decrement_subsegments_size", "(", ")" ]
Remove input subsegment from child subsegemnts and decrement parent segment total subsegments count. :param Subsegment: subsegment to remove.
[ "Remove", "input", "subsegment", "from", "child", "subsegemnts", "and", "decrement", "parent", "segment", "total", "subsegments", "count", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/models/subsegment.py#L120-L128
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/models/subsegment.py
Subsegment.close
def close(self, end_time=None): """ Close the trace entity by setting `end_time` and flip the in progress flag to False. Also decrement parent segment's ref counter by 1. :param int end_time: Epoch in seconds. If not specified current time will be used. """ ...
python
def close(self, end_time=None): """ Close the trace entity by setting `end_time` and flip the in progress flag to False. Also decrement parent segment's ref counter by 1. :param int end_time: Epoch in seconds. If not specified current time will be used. """ ...
[ "def", "close", "(", "self", ",", "end_time", "=", "None", ")", ":", "super", "(", "Subsegment", ",", "self", ")", ".", "close", "(", "end_time", ")", "self", ".", "parent_segment", ".", "decrement_ref_counter", "(", ")" ]
Close the trace entity by setting `end_time` and flip the in progress flag to False. Also decrement parent segment's ref counter by 1. :param int end_time: Epoch in seconds. If not specified current time will be used.
[ "Close", "the", "trace", "entity", "by", "setting", "end_time", "and", "flip", "the", "in", "progress", "flag", "to", "False", ".", "Also", "decrement", "parent", "segment", "s", "ref", "counter", "by", "1", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/models/subsegment.py#L130-L140
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/connector.py
ServiceConnector.fetch_sampling_rules
def fetch_sampling_rules(self): """ Use X-Ray botocore client to get the centralized sampling rules from X-Ray service. The call is proxied and signed by X-Ray Daemon. """ new_rules = [] resp = self._xray_client.get_sampling_rules() records = resp['SamplingRuleRe...
python
def fetch_sampling_rules(self): """ Use X-Ray botocore client to get the centralized sampling rules from X-Ray service. The call is proxied and signed by X-Ray Daemon. """ new_rules = [] resp = self._xray_client.get_sampling_rules() records = resp['SamplingRuleRe...
[ "def", "fetch_sampling_rules", "(", "self", ")", ":", "new_rules", "=", "[", "]", "resp", "=", "self", ".", "_xray_client", ".", "get_sampling_rules", "(", ")", "records", "=", "resp", "[", "'SamplingRuleRecords'", "]", "for", "record", "in", "records", ":",...
Use X-Ray botocore client to get the centralized sampling rules from X-Ray service. The call is proxied and signed by X-Ray Daemon.
[ "Use", "X", "-", "Ray", "botocore", "client", "to", "get", "the", "centralized", "sampling", "rules", "from", "X", "-", "Ray", "service", ".", "The", "call", "is", "proxied", "and", "signed", "by", "X", "-", "Ray", "Daemon", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/connector.py#L49-L73
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/connector.py
ServiceConnector.setup_xray_client
def setup_xray_client(self, ip, port, client): """ Setup the xray client based on ip and port. If a preset client is specified, ip and port will be ignored. """ if not client: client = self._create_xray_client(ip, port) self._xray_client = client
python
def setup_xray_client(self, ip, port, client): """ Setup the xray client based on ip and port. If a preset client is specified, ip and port will be ignored. """ if not client: client = self._create_xray_client(ip, port) self._xray_client = client
[ "def", "setup_xray_client", "(", "self", ",", "ip", ",", "port", ",", "client", ")", ":", "if", "not", "client", ":", "client", "=", "self", ".", "_create_xray_client", "(", "ip", ",", "port", ")", "self", ".", "_xray_client", "=", "client" ]
Setup the xray client based on ip and port. If a preset client is specified, ip and port will be ignored.
[ "Setup", "the", "xray", "client", "based", "on", "ip", "and", "port", ".", "If", "a", "preset", "client", "is", "specified", "ip", "and", "port", "will", "be", "ignored", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/connector.py#L102-L110
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/connector.py
ServiceConnector._dt_to_epoch
def _dt_to_epoch(self, dt): """ Convert a offset-aware datetime to POSIX time. """ if PY2: # The input datetime is from botocore unmarshalling and it is # offset-aware so the timedelta of subtracting this time # to 01/01/1970 using the same tzinfo give...
python
def _dt_to_epoch(self, dt): """ Convert a offset-aware datetime to POSIX time. """ if PY2: # The input datetime is from botocore unmarshalling and it is # offset-aware so the timedelta of subtracting this time # to 01/01/1970 using the same tzinfo give...
[ "def", "_dt_to_epoch", "(", "self", ",", "dt", ")", ":", "if", "PY2", ":", "time_delta", "=", "dt", "-", "datetime", "(", "1970", ",", "1", ",", "1", ")", ".", "replace", "(", "tzinfo", "=", "dt", ".", "tzinfo", ")", "return", "int", "(", "time_d...
Convert a offset-aware datetime to POSIX time.
[ "Convert", "a", "offset", "-", "aware", "datetime", "to", "POSIX", "time", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/connector.py#L136-L149
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/utils/stacktrace.py
get_stacktrace
def get_stacktrace(limit=None): """ Get a full stacktrace for the current state of execution. Include the current state of the stack, minus this function. If there is an active exception, include the stacktrace information from the exception as well. :param int limit: Optionally limit ...
python
def get_stacktrace(limit=None): """ Get a full stacktrace for the current state of execution. Include the current state of the stack, minus this function. If there is an active exception, include the stacktrace information from the exception as well. :param int limit: Optionally limit ...
[ "def", "get_stacktrace", "(", "limit", "=", "None", ")", ":", "if", "limit", "is", "not", "None", "and", "limit", "==", "0", ":", "return", "[", "]", "stack", "=", "traceback", ".", "extract_stack", "(", ")", "stack", "=", "stack", "[", ":", "-", "...
Get a full stacktrace for the current state of execution. Include the current state of the stack, minus this function. If there is an active exception, include the stacktrace information from the exception as well. :param int limit: Optionally limit stack trace size results. This parmaeters ha...
[ "Get", "a", "full", "stacktrace", "for", "the", "current", "state", "of", "execution", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/utils/stacktrace.py#L5-L51
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/local/sampler.py
LocalSampler.should_trace
def should_trace(self, sampling_req=None): """ Return True if the sampler decide to sample based on input information and sampling rules. It will first check if any custom rule should be applied, if not it falls back to the default sampling rule. All optional arugments a...
python
def should_trace(self, sampling_req=None): """ Return True if the sampler decide to sample based on input information and sampling rules. It will first check if any custom rule should be applied, if not it falls back to the default sampling rule. All optional arugments a...
[ "def", "should_trace", "(", "self", ",", "sampling_req", "=", "None", ")", ":", "if", "sampling_req", "is", "None", ":", "return", "self", ".", "_should_trace", "(", "self", ".", "_default_rule", ")", "host", "=", "sampling_req", ".", "get", "(", "'host'",...
Return True if the sampler decide to sample based on input information and sampling rules. It will first check if any custom rule should be applied, if not it falls back to the default sampling rule. All optional arugments are extracted from incoming requests by X-Ray middleware...
[ "Return", "True", "if", "the", "sampler", "decide", "to", "sample", "based", "on", "input", "information", "and", "sampling", "rules", ".", "It", "will", "first", "check", "if", "any", "custom", "rule", "should", "be", "applied", "if", "not", "it", "falls"...
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/local/sampler.py#L53-L74
train
aws/aws-xray-sdk-python
aws_xray_sdk/ext/django/middleware.py
XRayMiddleware.process_exception
def process_exception(self, request, exception): """ Add exception information and fault flag to the current segment. """ if self.in_lambda_ctx: segment = xray_recorder.current_subsegment() else: segment = xray_recorder.current_segment() se...
python
def process_exception(self, request, exception): """ Add exception information and fault flag to the current segment. """ if self.in_lambda_ctx: segment = xray_recorder.current_subsegment() else: segment = xray_recorder.current_segment() se...
[ "def", "process_exception", "(", "self", ",", "request", ",", "exception", ")", ":", "if", "self", ".", "in_lambda_ctx", ":", "segment", "=", "xray_recorder", ".", "current_subsegment", "(", ")", "else", ":", "segment", "=", "xray_recorder", ".", "current_segm...
Add exception information and fault flag to the current segment.
[ "Add", "exception", "information", "and", "fault", "flag", "to", "the", "current", "segment", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/ext/django/middleware.py#L93-L105
train
aws/aws-xray-sdk-python
aws_xray_sdk/core/sampling/local/reservoir.py
Reservoir.take
def take(self): """ Returns True if there are segments left within the current second, otherwise return False. """ with self._lock: now = int(time.time()) if now != self.this_sec: self.used_this_sec = 0 self.this_sec = now ...
python
def take(self): """ Returns True if there are segments left within the current second, otherwise return False. """ with self._lock: now = int(time.time()) if now != self.this_sec: self.used_this_sec = 0 self.this_sec = now ...
[ "def", "take", "(", "self", ")", ":", "with", "self", ".", "_lock", ":", "now", "=", "int", "(", "time", ".", "time", "(", ")", ")", "if", "now", "!=", "self", ".", "this_sec", ":", "self", ".", "used_this_sec", "=", "0", "self", ".", "this_sec",...
Returns True if there are segments left within the current second, otherwise return False.
[ "Returns", "True", "if", "there", "are", "segments", "left", "within", "the", "current", "second", "otherwise", "return", "False", "." ]
707358cd3a516d51f2ebf71cf34f00e8d906a667
https://github.com/aws/aws-xray-sdk-python/blob/707358cd3a516d51f2ebf71cf34f00e8d906a667/aws_xray_sdk/core/sampling/local/reservoir.py#L21-L37
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/__init__.py
get_default_connection
def get_default_connection(): """Returns the default datastore connection. Defaults endpoint to helper.get_project_endpoint_from_env() and credentials to helper.get_credentials_from_env(). Use set_options to override defaults. """ tid = id(threading.current_thread()) conn = _conn_holder.get(tid) if no...
python
def get_default_connection(): """Returns the default datastore connection. Defaults endpoint to helper.get_project_endpoint_from_env() and credentials to helper.get_credentials_from_env(). Use set_options to override defaults. """ tid = id(threading.current_thread()) conn = _conn_holder.get(tid) if no...
[ "def", "get_default_connection", "(", ")", ":", "tid", "=", "id", "(", "threading", ".", "current_thread", "(", ")", ")", "conn", "=", "_conn_holder", ".", "get", "(", "tid", ")", "if", "not", "conn", ":", "with", "(", "_rlock", ")", ":", "if", "'pro...
Returns the default datastore connection. Defaults endpoint to helper.get_project_endpoint_from_env() and credentials to helper.get_credentials_from_env(). Use set_options to override defaults.
[ "Returns", "the", "default", "datastore", "connection", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/__init__.py#L79-L100
train
GoogleCloudPlatform/google-cloud-datastore
python/demos/todos/todos.py
Todo.get_all
def get_all(cls): """Query for all Todo items ordered by creation date. This method is eventually consistent to avoid the need for an extra index. """ req = datastore.RunQueryRequest() q = req.query set_kind(q, kind='Todo') add_property_orders(q, 'created') resp = datastore.run_query(r...
python
def get_all(cls): """Query for all Todo items ordered by creation date. This method is eventually consistent to avoid the need for an extra index. """ req = datastore.RunQueryRequest() q = req.query set_kind(q, kind='Todo') add_property_orders(q, 'created') resp = datastore.run_query(r...
[ "def", "get_all", "(", "cls", ")", ":", "req", "=", "datastore", ".", "RunQueryRequest", "(", ")", "q", "=", "req", ".", "query", "set_kind", "(", "q", ",", "kind", "=", "'Todo'", ")", "add_property_orders", "(", "q", ",", "'created'", ")", "resp", "...
Query for all Todo items ordered by creation date. This method is eventually consistent to avoid the need for an extra index.
[ "Query", "for", "all", "Todo", "items", "ordered", "by", "creation", "date", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/demos/todos/todos.py#L131-L143
train
GoogleCloudPlatform/google-cloud-datastore
python/demos/todos/todos.py
Todo.archive
def archive(cls): """Delete all Todo items that are done.""" req = datastore.BeginTransactionRequest() resp = datastore.begin_transaction(req) tx = resp.transaction req = datastore.RunQueryRequest() req.read_options.transaction = tx q = req.query set_kind(q, kind='Todo') add_projecti...
python
def archive(cls): """Delete all Todo items that are done.""" req = datastore.BeginTransactionRequest() resp = datastore.begin_transaction(req) tx = resp.transaction req = datastore.RunQueryRequest() req.read_options.transaction = tx q = req.query set_kind(q, kind='Todo') add_projecti...
[ "def", "archive", "(", "cls", ")", ":", "req", "=", "datastore", ".", "BeginTransactionRequest", "(", ")", "resp", "=", "datastore", ".", "begin_transaction", "(", "req", ")", "tx", "=", "resp", ".", "transaction", "req", "=", "datastore", ".", "RunQueryRe...
Delete all Todo items that are done.
[ "Delete", "all", "Todo", "items", "that", "are", "done", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/demos/todos/todos.py#L146-L171
train
GoogleCloudPlatform/google-cloud-datastore
python/demos/todos/todos.py
Todo.save
def save(self): """Update or insert a Todo item.""" req = datastore.CommitRequest() req.mode = datastore.CommitRequest.NON_TRANSACTIONAL req.mutations.add().upsert.CopyFrom(self.to_proto()) resp = datastore.commit(req) if not self.id: self.id = resp.mutation_results[0].key.path[-1].id ...
python
def save(self): """Update or insert a Todo item.""" req = datastore.CommitRequest() req.mode = datastore.CommitRequest.NON_TRANSACTIONAL req.mutations.add().upsert.CopyFrom(self.to_proto()) resp = datastore.commit(req) if not self.id: self.id = resp.mutation_results[0].key.path[-1].id ...
[ "def", "save", "(", "self", ")", ":", "req", "=", "datastore", ".", "CommitRequest", "(", ")", "req", ".", "mode", "=", "datastore", ".", "CommitRequest", ".", "NON_TRANSACTIONAL", "req", ".", "mutations", ".", "add", "(", ")", ".", "upsert", ".", "Cop...
Update or insert a Todo item.
[ "Update", "or", "insert", "a", "Todo", "item", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/demos/todos/todos.py#L173-L181
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/datastore_emulator.py
DatastoreEmulatorFactory.Get
def Get(self, project_id): """Returns an existing emulator instance for the provided project_id. If an emulator instance doesn't yet exist, it creates one. Args: project_id: project ID Returns: a DatastoreEmulator """ if project_id in self._emulators: return self._emulators[...
python
def Get(self, project_id): """Returns an existing emulator instance for the provided project_id. If an emulator instance doesn't yet exist, it creates one. Args: project_id: project ID Returns: a DatastoreEmulator """ if project_id in self._emulators: return self._emulators[...
[ "def", "Get", "(", "self", ",", "project_id", ")", ":", "if", "project_id", "in", "self", ".", "_emulators", ":", "return", "self", ".", "_emulators", "[", "project_id", "]", "emulator", "=", "self", ".", "Create", "(", "project_id", ")", "self", ".", ...
Returns an existing emulator instance for the provided project_id. If an emulator instance doesn't yet exist, it creates one. Args: project_id: project ID Returns: a DatastoreEmulator
[ "Returns", "an", "existing", "emulator", "instance", "for", "the", "provided", "project_id", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/datastore_emulator.py#L71-L87
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/datastore_emulator.py
DatastoreEmulatorFactory.Create
def Create(self, project_id, start_options=None, deadline=10): """Creates an emulator instance. This method will wait for up to 'deadline' seconds for the emulator to start. Args: project_id: project ID start_options: a list of additional command-line options to pass to the emula...
python
def Create(self, project_id, start_options=None, deadline=10): """Creates an emulator instance. This method will wait for up to 'deadline' seconds for the emulator to start. Args: project_id: project ID start_options: a list of additional command-line options to pass to the emula...
[ "def", "Create", "(", "self", ",", "project_id", ",", "start_options", "=", "None", ",", "deadline", "=", "10", ")", ":", "return", "DatastoreEmulator", "(", "self", ".", "_emulator_cmd", ",", "self", ".", "_working_directory", ",", "project_id", ",", "deadl...
Creates an emulator instance. This method will wait for up to 'deadline' seconds for the emulator to start. Args: project_id: project ID start_options: a list of additional command-line options to pass to the emulator 'start' command deadline: number of seconds to wait for the ...
[ "Creates", "an", "emulator", "instance", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/datastore_emulator.py#L89-L108
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/datastore_emulator.py
DatastoreEmulator._WaitForStartup
def _WaitForStartup(self, deadline): """Waits for the emulator to start. Args: deadline: deadline in seconds Returns: True if the emulator responds within the deadline, False otherwise. """ start = time.time() sleep = 0.05 def Elapsed(): return time.time() - start w...
python
def _WaitForStartup(self, deadline): """Waits for the emulator to start. Args: deadline: deadline in seconds Returns: True if the emulator responds within the deadline, False otherwise. """ start = time.time() sleep = 0.05 def Elapsed(): return time.time() - start w...
[ "def", "_WaitForStartup", "(", "self", ",", "deadline", ")", ":", "start", "=", "time", ".", "time", "(", ")", "sleep", "=", "0.05", "def", "Elapsed", "(", ")", ":", "return", "time", ".", "time", "(", ")", "-", "start", "while", "True", ":", "try"...
Waits for the emulator to start. Args: deadline: deadline in seconds Returns: True if the emulator responds within the deadline, False otherwise.
[ "Waits", "for", "the", "emulator", "to", "start", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/datastore_emulator.py#L170-L198
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/datastore_emulator.py
DatastoreEmulator.Clear
def Clear(self): """Clears all data from the emulator instance. Returns: True if the data was successfully cleared, False otherwise. """ headers = {'Content-length': '0'} response, _ = self._http.request('%s/reset' % self._host, method='POST', headers=head...
python
def Clear(self): """Clears all data from the emulator instance. Returns: True if the data was successfully cleared, False otherwise. """ headers = {'Content-length': '0'} response, _ = self._http.request('%s/reset' % self._host, method='POST', headers=head...
[ "def", "Clear", "(", "self", ")", ":", "headers", "=", "{", "'Content-length'", ":", "'0'", "}", "response", ",", "_", "=", "self", ".", "_http", ".", "request", "(", "'%s/reset'", "%", "self", ".", "_host", ",", "method", "=", "'POST'", ",", "header...
Clears all data from the emulator instance. Returns: True if the data was successfully cleared, False otherwise.
[ "Clears", "all", "data", "from", "the", "emulator", "instance", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/datastore_emulator.py#L200-L212
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/datastore_emulator.py
DatastoreEmulator.Stop
def Stop(self): """Stops the emulator instance.""" if not self.__running: return logging.info('shutting down the emulator running at %s', self._host) headers = {'Content-length': '0'} response, _ = self._http.request('%s/shutdown' % self._host, method='POST...
python
def Stop(self): """Stops the emulator instance.""" if not self.__running: return logging.info('shutting down the emulator running at %s', self._host) headers = {'Content-length': '0'} response, _ = self._http.request('%s/shutdown' % self._host, method='POST...
[ "def", "Stop", "(", "self", ")", ":", "if", "not", "self", ".", "__running", ":", "return", "logging", ".", "info", "(", "'shutting down the emulator running at %s'", ",", "self", ".", "_host", ")", "headers", "=", "{", "'Content-length'", ":", "'0'", "}", ...
Stops the emulator instance.
[ "Stops", "the", "emulator", "instance", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/datastore_emulator.py#L214-L227
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/connection.py
Datastore._call_method
def _call_method(self, method, req, resp_class): """_call_method call the given RPC method over HTTP. It uses the given protobuf message request as the payload and returns the deserialized protobuf message response. Args: method: RPC method name to be called. req: protobuf message for the ...
python
def _call_method(self, method, req, resp_class): """_call_method call the given RPC method over HTTP. It uses the given protobuf message request as the payload and returns the deserialized protobuf message response. Args: method: RPC method name to be called. req: protobuf message for the ...
[ "def", "_call_method", "(", "self", ",", "method", ",", "req", ",", "resp_class", ")", ":", "payload", "=", "req", ".", "SerializeToString", "(", ")", "headers", "=", "{", "'Content-Type'", ":", "'application/x-protobuf'", ",", "'Content-Length'", ":", "str", ...
_call_method call the given RPC method over HTTP. It uses the given protobuf message request as the payload and returns the deserialized protobuf message response. Args: method: RPC method name to be called. req: protobuf message for the RPC request. resp_class: protobuf message class fo...
[ "_call_method", "call", "the", "given", "RPC", "method", "over", "HTTP", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/connection.py#L174-L204
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
get_credentials_from_env
def get_credentials_from_env(): """Get credentials from environment variables. Preference of credentials is: - No credentials if DATASTORE_EMULATOR_HOST is set. - Google APIs Signed JWT credentials based on DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE environments variables - Google Applicati...
python
def get_credentials_from_env(): """Get credentials from environment variables. Preference of credentials is: - No credentials if DATASTORE_EMULATOR_HOST is set. - Google APIs Signed JWT credentials based on DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE environments variables - Google Applicati...
[ "def", "get_credentials_from_env", "(", ")", ":", "if", "os", ".", "getenv", "(", "_DATASTORE_USE_STUB_CREDENTIAL_FOR_TEST_ENV", ")", ":", "logging", ".", "info", "(", "'connecting without credentials because %s is set.'", ",", "_DATASTORE_USE_STUB_CREDENTIAL_FOR_TEST_ENV", "...
Get credentials from environment variables. Preference of credentials is: - No credentials if DATASTORE_EMULATOR_HOST is set. - Google APIs Signed JWT credentials based on DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE environments variables - Google Application Default https://developers.googl...
[ "Get", "credentials", "from", "environment", "variables", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L71-L111
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
get_project_endpoint_from_env
def get_project_endpoint_from_env(project_id=None, host=None): """Get Datastore project endpoint from environment variables. Args: project_id: The Cloud project, defaults to the environment variable DATASTORE_PROJECT_ID. host: The Cloud Datastore API host to use. Returns: the endpoint to use...
python
def get_project_endpoint_from_env(project_id=None, host=None): """Get Datastore project endpoint from environment variables. Args: project_id: The Cloud project, defaults to the environment variable DATASTORE_PROJECT_ID. host: The Cloud Datastore API host to use. Returns: the endpoint to use...
[ "def", "get_project_endpoint_from_env", "(", "project_id", "=", "None", ",", "host", "=", "None", ")", ":", "project_id", "=", "project_id", "or", "os", ".", "getenv", "(", "_DATASTORE_PROJECT_ID_ENV", ")", "if", "not", "project_id", ":", "raise", "ValueError", ...
Get Datastore project endpoint from environment variables. Args: project_id: The Cloud project, defaults to the environment variable DATASTORE_PROJECT_ID. host: The Cloud Datastore API host to use. Returns: the endpoint to use, for example https://datastore.googleapis.com/v1/projects/my-pr...
[ "Get", "Datastore", "project", "endpoint", "from", "environment", "variables", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L114-L150
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
add_key_path
def add_key_path(key_proto, *path_elements): """Add path elements to the given datastore.Key proto message. Args: key_proto: datastore.Key proto message. *path_elements: list of ancestors to add to the key. (kind1, id1/name1, ..., kindN, idN/nameN), the last 2 elements represent the entity ...
python
def add_key_path(key_proto, *path_elements): """Add path elements to the given datastore.Key proto message. Args: key_proto: datastore.Key proto message. *path_elements: list of ancestors to add to the key. (kind1, id1/name1, ..., kindN, idN/nameN), the last 2 elements represent the entity ...
[ "def", "add_key_path", "(", "key_proto", ",", "*", "path_elements", ")", ":", "for", "i", "in", "range", "(", "0", ",", "len", "(", "path_elements", ")", ",", "2", ")", ":", "pair", "=", "path_elements", "[", "i", ":", "i", "+", "2", "]", "elem", ...
Add path elements to the given datastore.Key proto message. Args: key_proto: datastore.Key proto message. *path_elements: list of ancestors to add to the key. (kind1, id1/name1, ..., kindN, idN/nameN), the last 2 elements represent the entity key, if no terminating id/name: they key w...
[ "Add", "path", "elements", "to", "the", "given", "datastore", ".", "Key", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L153-L194
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
add_properties
def add_properties(entity_proto, property_dict, exclude_from_indexes=None): """Add values to the given datastore.Entity proto message. Args: entity_proto: datastore.Entity proto message. property_dict: a dictionary from property name to either a python object or datastore.Value. exclude_from_in...
python
def add_properties(entity_proto, property_dict, exclude_from_indexes=None): """Add values to the given datastore.Entity proto message. Args: entity_proto: datastore.Entity proto message. property_dict: a dictionary from property name to either a python object or datastore.Value. exclude_from_in...
[ "def", "add_properties", "(", "entity_proto", ",", "property_dict", ",", "exclude_from_indexes", "=", "None", ")", ":", "for", "name", ",", "value", "in", "property_dict", ".", "iteritems", "(", ")", ":", "set_property", "(", "entity_proto", ".", "properties", ...
Add values to the given datastore.Entity proto message. Args: entity_proto: datastore.Entity proto message. property_dict: a dictionary from property name to either a python object or datastore.Value. exclude_from_indexes: if the value should be exclude from indexes. None leaves indexing ...
[ "Add", "values", "to", "the", "given", "datastore", ".", "Entity", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L197-L215
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
set_property
def set_property(property_map, name, value, exclude_from_indexes=None): """Set property value in the given datastore.Property proto message. Args: property_map: a string->datastore.Value protobuf map. name: name of the property. value: python object or datastore.Value. exclude_from_indexes: if the ...
python
def set_property(property_map, name, value, exclude_from_indexes=None): """Set property value in the given datastore.Property proto message. Args: property_map: a string->datastore.Value protobuf map. name: name of the property. value: python object or datastore.Value. exclude_from_indexes: if the ...
[ "def", "set_property", "(", "property_map", ",", "name", ",", "value", ",", "exclude_from_indexes", "=", "None", ")", ":", "set_value", "(", "property_map", "[", "name", "]", ",", "value", ",", "exclude_from_indexes", ")" ]
Set property value in the given datastore.Property proto message. Args: property_map: a string->datastore.Value protobuf map. name: name of the property. value: python object or datastore.Value. exclude_from_indexes: if the value should be exclude from indexes. None leaves indexing as is (def...
[ "Set", "property", "value", "in", "the", "given", "datastore", ".", "Property", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L218-L234
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
set_value
def set_value(value_proto, value, exclude_from_indexes=None): """Set the corresponding datastore.Value _value field for the given arg. Args: value_proto: datastore.Value proto message. value: python object or datastore.Value. (unicode value will set a datastore string value, str value will set a bl...
python
def set_value(value_proto, value, exclude_from_indexes=None): """Set the corresponding datastore.Value _value field for the given arg. Args: value_proto: datastore.Value proto message. value: python object or datastore.Value. (unicode value will set a datastore string value, str value will set a bl...
[ "def", "set_value", "(", "value_proto", ",", "value", ",", "exclude_from_indexes", "=", "None", ")", ":", "value_proto", ".", "Clear", "(", ")", "if", "isinstance", "(", "value", ",", "(", "list", ",", "tuple", ")", ")", ":", "for", "sub_value", "in", ...
Set the corresponding datastore.Value _value field for the given arg. Args: value_proto: datastore.Value proto message. value: python object or datastore.Value. (unicode value will set a datastore string value, str value will set a blob string value). Undefined behavior if value is/contains v...
[ "Set", "the", "corresponding", "datastore", ".", "Value", "_value", "field", "for", "the", "given", "arg", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L237-L282
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
get_value
def get_value(value_proto): """Gets the python object equivalent for the given value proto. Args: value_proto: datastore.Value proto message. Returns: the corresponding python object value. timestamps are converted to datetime, and datastore.Value is returned for blob_key_value. """ field = valu...
python
def get_value(value_proto): """Gets the python object equivalent for the given value proto. Args: value_proto: datastore.Value proto message. Returns: the corresponding python object value. timestamps are converted to datetime, and datastore.Value is returned for blob_key_value. """ field = valu...
[ "def", "get_value", "(", "value_proto", ")", ":", "field", "=", "value_proto", ".", "WhichOneof", "(", "'value_type'", ")", "if", "field", "in", "__native_value_types", ":", "return", "getattr", "(", "value_proto", ",", "field", ")", "if", "field", "==", "'t...
Gets the python object equivalent for the given value proto. Args: value_proto: datastore.Value proto message. Returns: the corresponding python object value. timestamps are converted to datetime, and datastore.Value is returned for blob_key_value.
[ "Gets", "the", "python", "object", "equivalent", "for", "the", "given", "value", "proto", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L285-L303
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
get_property_dict
def get_property_dict(entity_proto): """Convert datastore.Entity to a dict of property name -> datastore.Value. Args: entity_proto: datastore.Entity proto message. Usage: >>> get_property_dict(entity_proto) {'foo': {string_value='a'}, 'bar': {integer_value=2}} Returns: dict of entity properti...
python
def get_property_dict(entity_proto): """Convert datastore.Entity to a dict of property name -> datastore.Value. Args: entity_proto: datastore.Entity proto message. Usage: >>> get_property_dict(entity_proto) {'foo': {string_value='a'}, 'bar': {integer_value=2}} Returns: dict of entity properti...
[ "def", "get_property_dict", "(", "entity_proto", ")", ":", "return", "dict", "(", "(", "p", ".", "key", ",", "p", ".", "value", ")", "for", "p", "in", "entity_proto", ".", "property", ")" ]
Convert datastore.Entity to a dict of property name -> datastore.Value. Args: entity_proto: datastore.Entity proto message. Usage: >>> get_property_dict(entity_proto) {'foo': {string_value='a'}, 'bar': {integer_value=2}} Returns: dict of entity properties.
[ "Convert", "datastore", ".", "Entity", "to", "a", "dict", "of", "property", "name", "-", ">", "datastore", ".", "Value", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L306-L319
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
set_kind
def set_kind(query_proto, kind): """Set the kind constraint for the given datastore.Query proto message.""" del query_proto.kind[:] query_proto.kind.add().name = kind
python
def set_kind(query_proto, kind): """Set the kind constraint for the given datastore.Query proto message.""" del query_proto.kind[:] query_proto.kind.add().name = kind
[ "def", "set_kind", "(", "query_proto", ",", "kind", ")", ":", "del", "query_proto", ".", "kind", "[", ":", "]", "query_proto", ".", "kind", ".", "add", "(", ")", ".", "name", "=", "kind" ]
Set the kind constraint for the given datastore.Query proto message.
[ "Set", "the", "kind", "constraint", "for", "the", "given", "datastore", ".", "Query", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L322-L325
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
add_property_orders
def add_property_orders(query_proto, *orders): """Add ordering constraint for the given datastore.Query proto message. Args: query_proto: datastore.Query proto message. orders: list of propertype name string, default to ascending order and set descending if prefixed by '-'. Usage: >>> add_proper...
python
def add_property_orders(query_proto, *orders): """Add ordering constraint for the given datastore.Query proto message. Args: query_proto: datastore.Query proto message. orders: list of propertype name string, default to ascending order and set descending if prefixed by '-'. Usage: >>> add_proper...
[ "def", "add_property_orders", "(", "query_proto", ",", "*", "orders", ")", ":", "for", "order", "in", "orders", ":", "proto", "=", "query_proto", ".", "order", ".", "add", "(", ")", "if", "order", "[", "0", "]", "==", "'-'", ":", "order", "=", "order...
Add ordering constraint for the given datastore.Query proto message. Args: query_proto: datastore.Query proto message. orders: list of propertype name string, default to ascending order and set descending if prefixed by '-'. Usage: >>> add_property_orders(query_proto, 'foo') # sort by foo asc ...
[ "Add", "ordering", "constraint", "for", "the", "given", "datastore", ".", "Query", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L328-L347
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
add_projection
def add_projection(query_proto, *projection): """Add projection properties to the given datatstore.Query proto message.""" for p in projection: proto = query_proto.projection.add() proto.property.name = p
python
def add_projection(query_proto, *projection): """Add projection properties to the given datatstore.Query proto message.""" for p in projection: proto = query_proto.projection.add() proto.property.name = p
[ "def", "add_projection", "(", "query_proto", ",", "*", "projection", ")", ":", "for", "p", "in", "projection", ":", "proto", "=", "query_proto", ".", "projection", ".", "add", "(", ")", "proto", ".", "property", ".", "name", "=", "p" ]
Add projection properties to the given datatstore.Query proto message.
[ "Add", "projection", "properties", "to", "the", "given", "datatstore", ".", "Query", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L350-L354
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
set_property_filter
def set_property_filter(filter_proto, name, op, value): """Set property filter contraint in the given datastore.Filter proto message. Args: filter_proto: datastore.Filter proto message name: property name op: datastore.PropertyFilter.Operation value: property value Returns: the same datastor...
python
def set_property_filter(filter_proto, name, op, value): """Set property filter contraint in the given datastore.Filter proto message. Args: filter_proto: datastore.Filter proto message name: property name op: datastore.PropertyFilter.Operation value: property value Returns: the same datastor...
[ "def", "set_property_filter", "(", "filter_proto", ",", "name", ",", "op", ",", "value", ")", ":", "filter_proto", ".", "Clear", "(", ")", "pf", "=", "filter_proto", ".", "property_filter", "pf", ".", "property", ".", "name", "=", "name", "pf", ".", "op"...
Set property filter contraint in the given datastore.Filter proto message. Args: filter_proto: datastore.Filter proto message name: property name op: datastore.PropertyFilter.Operation value: property value Returns: the same datastore.Filter. Usage: >>> set_property_filter(filter_proto,...
[ "Set", "property", "filter", "contraint", "in", "the", "given", "datastore", ".", "Filter", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L357-L378
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
set_composite_filter
def set_composite_filter(filter_proto, op, *filters): """Set composite filter contraint in the given datastore.Filter proto message. Args: filter_proto: datastore.Filter proto message op: datastore.CompositeFilter.Operation filters: vararg list of datastore.Filter Returns: the same datastore.Filt...
python
def set_composite_filter(filter_proto, op, *filters): """Set composite filter contraint in the given datastore.Filter proto message. Args: filter_proto: datastore.Filter proto message op: datastore.CompositeFilter.Operation filters: vararg list of datastore.Filter Returns: the same datastore.Filt...
[ "def", "set_composite_filter", "(", "filter_proto", ",", "op", ",", "*", "filters", ")", ":", "filter_proto", ".", "Clear", "(", ")", "cf", "=", "filter_proto", ".", "composite_filter", "cf", ".", "op", "=", "op", "for", "f", "in", "filters", ":", "cf", ...
Set composite filter contraint in the given datastore.Filter proto message. Args: filter_proto: datastore.Filter proto message op: datastore.CompositeFilter.Operation filters: vararg list of datastore.Filter Returns: the same datastore.Filter. Usage: >>> set_composite_filter(filter_proto, da...
[ "Set", "composite", "filter", "contraint", "in", "the", "given", "datastore", ".", "Filter", "proto", "message", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L381-L402
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
micros_to_timestamp
def micros_to_timestamp(micros, timestamp): """Convert microseconds from utc epoch to google.protobuf.timestamp. Args: micros: a long, number of microseconds since utc epoch. timestamp: a google.protobuf.timestamp.Timestamp to populate. """ seconds = long(micros / _MICROS_PER_SECOND) micro_remainder ...
python
def micros_to_timestamp(micros, timestamp): """Convert microseconds from utc epoch to google.protobuf.timestamp. Args: micros: a long, number of microseconds since utc epoch. timestamp: a google.protobuf.timestamp.Timestamp to populate. """ seconds = long(micros / _MICROS_PER_SECOND) micro_remainder ...
[ "def", "micros_to_timestamp", "(", "micros", ",", "timestamp", ")", ":", "seconds", "=", "long", "(", "micros", "/", "_MICROS_PER_SECOND", ")", "micro_remainder", "=", "micros", "%", "_MICROS_PER_SECOND", "timestamp", ".", "seconds", "=", "seconds", "timestamp", ...
Convert microseconds from utc epoch to google.protobuf.timestamp. Args: micros: a long, number of microseconds since utc epoch. timestamp: a google.protobuf.timestamp.Timestamp to populate.
[ "Convert", "microseconds", "from", "utc", "epoch", "to", "google", ".", "protobuf", ".", "timestamp", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L422-L432
train
GoogleCloudPlatform/google-cloud-datastore
python/googledatastore/helper.py
to_timestamp
def to_timestamp(dt, timestamp): """Convert datetime to google.protobuf.Timestamp. Args: dt: a timezone naive datetime. timestamp: a google.protobuf.Timestamp to populate. Raises: TypeError: if a timezone aware datetime was provided. """ if dt.tzinfo: # this is an "aware" datetime with an ex...
python
def to_timestamp(dt, timestamp): """Convert datetime to google.protobuf.Timestamp. Args: dt: a timezone naive datetime. timestamp: a google.protobuf.Timestamp to populate. Raises: TypeError: if a timezone aware datetime was provided. """ if dt.tzinfo: # this is an "aware" datetime with an ex...
[ "def", "to_timestamp", "(", "dt", ",", "timestamp", ")", ":", "if", "dt", ".", "tzinfo", ":", "raise", "TypeError", "(", "'Cannot store a timezone aware datetime. '", "'Convert to UTC and store the naive datetime.'", ")", "timestamp", ".", "seconds", "=", "calendar", ...
Convert datetime to google.protobuf.Timestamp. Args: dt: a timezone naive datetime. timestamp: a google.protobuf.Timestamp to populate. Raises: TypeError: if a timezone aware datetime was provided.
[ "Convert", "datetime", "to", "google", ".", "protobuf", ".", "Timestamp", "." ]
a23940d0634d7f537faf01ad9e60598046bcb40a
https://github.com/GoogleCloudPlatform/google-cloud-datastore/blob/a23940d0634d7f537faf01ad9e60598046bcb40a/python/googledatastore/helper.py#L435-L450
train
HDI-Project/MLBlocks
mlblocks/mlblock.py
MLBlock._extract_params
def _extract_params(self, kwargs, hyperparameters): """Extract init, fit and produce params from kwargs. The `init_params`, `fit_params` and `produce_params` are extracted from the passed `kwargs` taking the metadata hyperparameters as a reference. During this extraction, make ...
python
def _extract_params(self, kwargs, hyperparameters): """Extract init, fit and produce params from kwargs. The `init_params`, `fit_params` and `produce_params` are extracted from the passed `kwargs` taking the metadata hyperparameters as a reference. During this extraction, make ...
[ "def", "_extract_params", "(", "self", ",", "kwargs", ",", "hyperparameters", ")", ":", "init_params", "=", "dict", "(", ")", "fit_params", "=", "dict", "(", ")", "produce_params", "=", "dict", "(", ")", "for", "name", ",", "param", "in", "hyperparameters"...
Extract init, fit and produce params from kwargs. The `init_params`, `fit_params` and `produce_params` are extracted from the passed `kwargs` taking the metadata hyperparameters as a reference. During this extraction, make sure that all the required hyperparameters have been gi...
[ "Extract", "init", "fit", "and", "produce", "params", "from", "kwargs", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlblock.py#L55-L111
train
HDI-Project/MLBlocks
mlblocks/mlblock.py
MLBlock.set_hyperparameters
def set_hyperparameters(self, hyperparameters): """Set new hyperparameters. Only the specified hyperparameters are modified, so any other hyperparameter keeps the value that had been previously given. If necessary, a new instance of the primitive is created. Args: ...
python
def set_hyperparameters(self, hyperparameters): """Set new hyperparameters. Only the specified hyperparameters are modified, so any other hyperparameter keeps the value that had been previously given. If necessary, a new instance of the primitive is created. Args: ...
[ "def", "set_hyperparameters", "(", "self", ",", "hyperparameters", ")", ":", "self", ".", "_hyperparameters", ".", "update", "(", "hyperparameters", ")", "if", "self", ".", "_class", ":", "LOGGER", ".", "debug", "(", "'Creating a new primitive instance for %s'", "...
Set new hyperparameters. Only the specified hyperparameters are modified, so any other hyperparameter keeps the value that had been previously given. If necessary, a new instance of the primitive is created. Args: hyperparameters (dict): Dictionary containing as keys the n...
[ "Set", "new", "hyperparameters", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlblock.py#L204-L221
train
HDI-Project/MLBlocks
mlblocks/mlblock.py
MLBlock.fit
def fit(self, **kwargs): """Call the fit method of the primitive. The given keyword arguments will be passed directly to the `fit` method of the primitive instance specified in the JSON annotation. If any of the arguments expected by the produce method had been given during the...
python
def fit(self, **kwargs): """Call the fit method of the primitive. The given keyword arguments will be passed directly to the `fit` method of the primitive instance specified in the JSON annotation. If any of the arguments expected by the produce method had been given during the...
[ "def", "fit", "(", "self", ",", "**", "kwargs", ")", ":", "if", "self", ".", "fit_method", "is", "not", "None", ":", "fit_args", "=", "self", ".", "_fit_params", ".", "copy", "(", ")", "fit_args", ".", "update", "(", "kwargs", ")", "getattr", "(", ...
Call the fit method of the primitive. The given keyword arguments will be passed directly to the `fit` method of the primitive instance specified in the JSON annotation. If any of the arguments expected by the produce method had been given during the MLBlock initialization, they will b...
[ "Call", "the", "fit", "method", "of", "the", "primitive", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlblock.py#L223-L246
train
HDI-Project/MLBlocks
mlblocks/mlblock.py
MLBlock.produce
def produce(self, **kwargs): """Call the primitive function, or the predict method of the primitive. The given keyword arguments will be passed directly to the primitive, if it is a simple function, or to the `produce` method of the primitive instance specified in the JSON annotation, i...
python
def produce(self, **kwargs): """Call the primitive function, or the predict method of the primitive. The given keyword arguments will be passed directly to the primitive, if it is a simple function, or to the `produce` method of the primitive instance specified in the JSON annotation, i...
[ "def", "produce", "(", "self", ",", "**", "kwargs", ")", ":", "produce_args", "=", "self", ".", "_produce_params", ".", "copy", "(", ")", "produce_args", ".", "update", "(", "kwargs", ")", "if", "self", ".", "_class", ":", "return", "getattr", "(", "se...
Call the primitive function, or the predict method of the primitive. The given keyword arguments will be passed directly to the primitive, if it is a simple function, or to the `produce` method of the primitive instance specified in the JSON annotation, if it is a class. If any of the ...
[ "Call", "the", "primitive", "function", "or", "the", "predict", "method", "of", "the", "primitive", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlblock.py#L248-L268
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.get_hyperparameters
def get_hyperparameters(self): """Get the current hyperparamters of each block. Returns: dict: A dictionary containing the block names as keys and the current block hyperparameters dictionary as values. """ hyperparameters = {} for blo...
python
def get_hyperparameters(self): """Get the current hyperparamters of each block. Returns: dict: A dictionary containing the block names as keys and the current block hyperparameters dictionary as values. """ hyperparameters = {} for blo...
[ "def", "get_hyperparameters", "(", "self", ")", ":", "hyperparameters", "=", "{", "}", "for", "block_name", ",", "block", "in", "self", ".", "blocks", ".", "items", "(", ")", ":", "hyperparameters", "[", "block_name", "]", "=", "block", ".", "get_hyperpara...
Get the current hyperparamters of each block. Returns: dict: A dictionary containing the block names as keys and the current block hyperparameters dictionary as values.
[ "Get", "the", "current", "hyperparamters", "of", "each", "block", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L117-L129
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.set_hyperparameters
def set_hyperparameters(self, hyperparameters): """Set new hyperparameter values for some blocks. Args: hyperparameters (dict): A dictionary containing the block names as keys and the new hyperparameters dictionary as v...
python
def set_hyperparameters(self, hyperparameters): """Set new hyperparameter values for some blocks. Args: hyperparameters (dict): A dictionary containing the block names as keys and the new hyperparameters dictionary as v...
[ "def", "set_hyperparameters", "(", "self", ",", "hyperparameters", ")", ":", "for", "block_name", ",", "block_hyperparams", "in", "hyperparameters", ".", "items", "(", ")", ":", "self", ".", "blocks", "[", "block_name", "]", ".", "set_hyperparameters", "(", "b...
Set new hyperparameter values for some blocks. Args: hyperparameters (dict): A dictionary containing the block names as keys and the new hyperparameters dictionary as values.
[ "Set", "new", "hyperparameter", "values", "for", "some", "blocks", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L131-L140
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.fit
def fit(self, X=None, y=None, **kwargs): """Fit the blocks of this pipeline. Sequentially call the `fit` and the `produce` methods of each block, capturing the outputs each `produce` method before calling the `fit` method of the next one. During the whole process a context dict...
python
def fit(self, X=None, y=None, **kwargs): """Fit the blocks of this pipeline. Sequentially call the `fit` and the `produce` methods of each block, capturing the outputs each `produce` method before calling the `fit` method of the next one. During the whole process a context dict...
[ "def", "fit", "(", "self", ",", "X", "=", "None", ",", "y", "=", "None", ",", "**", "kwargs", ")", ":", "context", "=", "{", "'X'", ":", "X", ",", "'y'", ":", "y", "}", "context", ".", "update", "(", "kwargs", ")", "last_block_name", "=", "list...
Fit the blocks of this pipeline. Sequentially call the `fit` and the `produce` methods of each block, capturing the outputs each `produce` method before calling the `fit` method of the next one. During the whole process a context dictionary is built, where both the passed argum...
[ "Fit", "the", "blocks", "of", "this", "pipeline", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L191-L236
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.predict
def predict(self, X=None, **kwargs): """Produce predictions using the blocks of this pipeline. Sequentially call the `produce` method of each block, capturing the outputs before calling the next one. During the whole process a context dictionary is built, where both the passed ...
python
def predict(self, X=None, **kwargs): """Produce predictions using the blocks of this pipeline. Sequentially call the `produce` method of each block, capturing the outputs before calling the next one. During the whole process a context dictionary is built, where both the passed ...
[ "def", "predict", "(", "self", ",", "X", "=", "None", ",", "**", "kwargs", ")", ":", "context", "=", "{", "'X'", ":", "X", "}", "context", ".", "update", "(", "kwargs", ")", "last_block_name", "=", "list", "(", "self", ".", "blocks", ".", "keys", ...
Produce predictions using the blocks of this pipeline. Sequentially call the `produce` method of each block, capturing the outputs before calling the next one. During the whole process a context dictionary is built, where both the passed arguments and the captured outputs of the `produ...
[ "Produce", "predictions", "using", "the", "blocks", "of", "this", "pipeline", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L238-L274
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.to_dict
def to_dict(self): """Return all the details of this MLPipeline in a dict. The dict structure contains all the `__init__` arguments of the MLPipeline, as well as the current hyperparameter values and the specification of the tunable_hyperparameters:: { "prim...
python
def to_dict(self): """Return all the details of this MLPipeline in a dict. The dict structure contains all the `__init__` arguments of the MLPipeline, as well as the current hyperparameter values and the specification of the tunable_hyperparameters:: { "prim...
[ "def", "to_dict", "(", "self", ")", ":", "return", "{", "'primitives'", ":", "self", ".", "primitives", ",", "'init_params'", ":", "self", ".", "init_params", ",", "'input_names'", ":", "self", ".", "input_names", ",", "'output_names'", ":", "self", ".", "...
Return all the details of this MLPipeline in a dict. The dict structure contains all the `__init__` arguments of the MLPipeline, as well as the current hyperparameter values and the specification of the tunable_hyperparameters:: { "primitives": [ ...
[ "Return", "all", "the", "details", "of", "this", "MLPipeline", "in", "a", "dict", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L276-L323
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.save
def save(self, path): """Save the specification of this MLPipeline in a JSON file. The content of the JSON file is the dict returned by the `to_dict` method. Args: path (str): Path to the JSON file to write. """ with open(path, 'w') as out_file: json.dum...
python
def save(self, path): """Save the specification of this MLPipeline in a JSON file. The content of the JSON file is the dict returned by the `to_dict` method. Args: path (str): Path to the JSON file to write. """ with open(path, 'w') as out_file: json.dum...
[ "def", "save", "(", "self", ",", "path", ")", ":", "with", "open", "(", "path", ",", "'w'", ")", "as", "out_file", ":", "json", ".", "dump", "(", "self", ".", "to_dict", "(", ")", ",", "out_file", ",", "indent", "=", "4", ")" ]
Save the specification of this MLPipeline in a JSON file. The content of the JSON file is the dict returned by the `to_dict` method. Args: path (str): Path to the JSON file to write.
[ "Save", "the", "specification", "of", "this", "MLPipeline", "in", "a", "JSON", "file", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L325-L334
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.from_dict
def from_dict(cls, metadata): """Create a new MLPipeline from a dict specification. The dict structure is the same as the one created by the `to_dict` method. Args: metadata (dict): Dictionary containing the pipeline specification. Returns: MLPipeline: ...
python
def from_dict(cls, metadata): """Create a new MLPipeline from a dict specification. The dict structure is the same as the one created by the `to_dict` method. Args: metadata (dict): Dictionary containing the pipeline specification. Returns: MLPipeline: ...
[ "def", "from_dict", "(", "cls", ",", "metadata", ")", ":", "hyperparameters", "=", "metadata", ".", "get", "(", "'hyperparameters'", ")", "tunable", "=", "metadata", ".", "get", "(", "'tunable_hyperparameters'", ")", "pipeline", "=", "cls", "(", "metadata", ...
Create a new MLPipeline from a dict specification. The dict structure is the same as the one created by the `to_dict` method. Args: metadata (dict): Dictionary containing the pipeline specification. Returns: MLPipeline: A new MLPipeline instance with th...
[ "Create", "a", "new", "MLPipeline", "from", "a", "dict", "specification", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L337-L366
train
HDI-Project/MLBlocks
mlblocks/mlpipeline.py
MLPipeline.load
def load(cls, path): """Create a new MLPipeline from a JSON specification. The JSON file format is the same as the one created by the `to_dict` method. Args: path (str): Path of the JSON file to load. Returns: MLPipeline: A new MLPipeline instan...
python
def load(cls, path): """Create a new MLPipeline from a JSON specification. The JSON file format is the same as the one created by the `to_dict` method. Args: path (str): Path of the JSON file to load. Returns: MLPipeline: A new MLPipeline instan...
[ "def", "load", "(", "cls", ",", "path", ")", ":", "with", "open", "(", "path", ",", "'r'", ")", "as", "in_file", ":", "metadata", "=", "json", ".", "load", "(", "in_file", ")", "return", "cls", ".", "from_dict", "(", "metadata", ")" ]
Create a new MLPipeline from a JSON specification. The JSON file format is the same as the one created by the `to_dict` method. Args: path (str): Path of the JSON file to load. Returns: MLPipeline: A new MLPipeline instance with the specification found ...
[ "Create", "a", "new", "MLPipeline", "from", "a", "JSON", "specification", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/mlpipeline.py#L369-L385
train
HDI-Project/MLBlocks
mlblocks/primitives.py
add_primitives_path
def add_primitives_path(path): """Add a new path to look for primitives. The new path will be inserted in the first place of the list, so any primitive found in this new folder will take precedence over any other primitive with the same name that existed in the system before. Args: pat...
python
def add_primitives_path(path): """Add a new path to look for primitives. The new path will be inserted in the first place of the list, so any primitive found in this new folder will take precedence over any other primitive with the same name that existed in the system before. Args: pat...
[ "def", "add_primitives_path", "(", "path", ")", ":", "if", "path", "not", "in", "_PRIMITIVES_PATHS", ":", "if", "not", "os", ".", "path", ".", "isdir", "(", "path", ")", ":", "raise", "ValueError", "(", "'Invalid path: {}'", ".", "format", "(", "path", "...
Add a new path to look for primitives. The new path will be inserted in the first place of the list, so any primitive found in this new folder will take precedence over any other primitive with the same name that existed in the system before. Args: path (str): path to add Raises: ...
[ "Add", "a", "new", "path", "to", "look", "for", "primitives", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/primitives.py#L27-L46
train
HDI-Project/MLBlocks
mlblocks/primitives.py
get_primitives_paths
def get_primitives_paths(): """Get the list of folders where the primitives will be looked for. This list will include the value of any `entry_point` named `jsons_path` published under the name `mlprimitives`. An example of such an entry point would be:: entry_points = { 'mlprimit...
python
def get_primitives_paths(): """Get the list of folders where the primitives will be looked for. This list will include the value of any `entry_point` named `jsons_path` published under the name `mlprimitives`. An example of such an entry point would be:: entry_points = { 'mlprimit...
[ "def", "get_primitives_paths", "(", ")", ":", "primitives_paths", "=", "list", "(", ")", "entry_points", "=", "pkg_resources", ".", "iter_entry_points", "(", "'mlprimitives'", ")", "for", "entry_point", "in", "entry_points", ":", "if", "entry_point", ".", "name", ...
Get the list of folders where the primitives will be looked for. This list will include the value of any `entry_point` named `jsons_path` published under the name `mlprimitives`. An example of such an entry point would be:: entry_points = { 'mlprimitives': [ 'jsons_pat...
[ "Get", "the", "list", "of", "folders", "where", "the", "primitives", "will", "be", "looked", "for", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/primitives.py#L49-L79
train
HDI-Project/MLBlocks
mlblocks/primitives.py
load_primitive
def load_primitive(name): """Locate and load the JSON annotation of the given primitive. All the paths found in PRIMTIVE_PATHS will be scanned to find a JSON file with the given name, and as soon as a JSON with the given name is found it is returned. Args: name (str): name of the primitive...
python
def load_primitive(name): """Locate and load the JSON annotation of the given primitive. All the paths found in PRIMTIVE_PATHS will be scanned to find a JSON file with the given name, and as soon as a JSON with the given name is found it is returned. Args: name (str): name of the primitive...
[ "def", "load_primitive", "(", "name", ")", ":", "for", "base_path", "in", "get_primitives_paths", "(", ")", ":", "parts", "=", "name", ".", "split", "(", "'.'", ")", "number_of_parts", "=", "len", "(", "parts", ")", "for", "folder_parts", "in", "range", ...
Locate and load the JSON annotation of the given primitive. All the paths found in PRIMTIVE_PATHS will be scanned to find a JSON file with the given name, and as soon as a JSON with the given name is found it is returned. Args: name (str): name of the primitive to look for. The name should ...
[ "Locate", "and", "load", "the", "JSON", "annotation", "of", "the", "given", "primitive", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/primitives.py#L82-L117
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_usps
def load_usps(): """USPs Digits Dataset. The data of this dataset is a 3d numpy array vector with shape (224, 224, 3) containing 9298 224x224 RGB photos of handwritten digits, and the target is a 1d numpy integer array containing the label of the digit represented in the image. """ dataset_...
python
def load_usps(): """USPs Digits Dataset. The data of this dataset is a 3d numpy array vector with shape (224, 224, 3) containing 9298 224x224 RGB photos of handwritten digits, and the target is a 1d numpy integer array containing the label of the digit represented in the image. """ dataset_...
[ "def", "load_usps", "(", ")", ":", "dataset_path", "=", "_load", "(", "'usps'", ")", "df", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "X", "=", "_load_images", "(", "os", ".", "path", ".", "join", "(", "dataset_path", ",", "'images'", "...
USPs Digits Dataset. The data of this dataset is a 3d numpy array vector with shape (224, 224, 3) containing 9298 224x224 RGB photos of handwritten digits, and the target is a 1d numpy integer array containing the label of the digit represented in the image.
[ "USPs", "Digits", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L237-L251
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_handgeometry
def load_handgeometry(): """Hand Geometry Dataset. The data of this dataset is a 3d numpy array vector with shape (224, 224, 3) containing 112 224x224 RGB photos of hands, and the target is a 1d numpy float array containing the width of the wrist in centimeters. """ dataset_path = _load('handge...
python
def load_handgeometry(): """Hand Geometry Dataset. The data of this dataset is a 3d numpy array vector with shape (224, 224, 3) containing 112 224x224 RGB photos of hands, and the target is a 1d numpy float array containing the width of the wrist in centimeters. """ dataset_path = _load('handge...
[ "def", "load_handgeometry", "(", ")", ":", "dataset_path", "=", "_load", "(", "'handgeometry'", ")", "df", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "X", "=", "_load_images", "(", "os", ".", "path", ".", "join", "(", "dataset_path", ",", ...
Hand Geometry Dataset. The data of this dataset is a 3d numpy array vector with shape (224, 224, 3) containing 112 224x224 RGB photos of hands, and the target is a 1d numpy float array containing the width of the wrist in centimeters.
[ "Hand", "Geometry", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L254-L267
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_personae
def load_personae(): """Personae Dataset. The data of this dataset is a 2d numpy array vector containing 145 entries that include texts written by Dutch users in Twitter, with some additional information about the author, and the target is a 1d numpy binary integer array indicating whether the auth...
python
def load_personae(): """Personae Dataset. The data of this dataset is a 2d numpy array vector containing 145 entries that include texts written by Dutch users in Twitter, with some additional information about the author, and the target is a 1d numpy binary integer array indicating whether the auth...
[ "def", "load_personae", "(", ")", ":", "dataset_path", "=", "_load", "(", "'personae'", ")", "X", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "y", "=", "X", ".", "pop", "(", "'label'", ")", ".", "values", "return", "Dataset", "(", "load_...
Personae Dataset. The data of this dataset is a 2d numpy array vector containing 145 entries that include texts written by Dutch users in Twitter, with some additional information about the author, and the target is a 1d numpy binary integer array indicating whether the author was extrovert or not.
[ "Personae", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L270-L283
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_umls
def load_umls(): """UMLs Dataset. The data consists of information about a 135 Graph and the relations between their nodes given as a DataFrame with three columns, source, target and type, indicating which nodes are related and with which type of link. The target is a 1d numpy binary integer array ...
python
def load_umls(): """UMLs Dataset. The data consists of information about a 135 Graph and the relations between their nodes given as a DataFrame with three columns, source, target and type, indicating which nodes are related and with which type of link. The target is a 1d numpy binary integer array ...
[ "def", "load_umls", "(", ")", ":", "dataset_path", "=", "_load", "(", "'umls'", ")", "X", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "y", "=", "X", ".", "pop", "(", "'label'", ")", ".", "values", "graph", "=", "nx", ".", "Graph", "(...
UMLs Dataset. The data consists of information about a 135 Graph and the relations between their nodes given as a DataFrame with three columns, source, target and type, indicating which nodes are related and with which type of link. The target is a 1d numpy binary integer array indicating whether the i...
[ "UMLs", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L286-L302
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_dic28
def load_dic28(): """DIC28 Dataset from Pajek. This network represents connections among English words in a dictionary. It was generated from Knuth's dictionary. Two words are connected by an edge if we can reach one from the other by - changing a single character (e. g., work - word) - adding ...
python
def load_dic28(): """DIC28 Dataset from Pajek. This network represents connections among English words in a dictionary. It was generated from Knuth's dictionary. Two words are connected by an edge if we can reach one from the other by - changing a single character (e. g., work - word) - adding ...
[ "def", "load_dic28", "(", ")", ":", "dataset_path", "=", "_load", "(", "'dic28'", ")", "X", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "y", "=", "X", ".", "pop", "(", "'label'", ")", ".", "values", "graph1", "=", "nx", ".", "Graph", ...
DIC28 Dataset from Pajek. This network represents connections among English words in a dictionary. It was generated from Knuth's dictionary. Two words are connected by an edge if we can reach one from the other by - changing a single character (e. g., work - word) - adding / removing a single chara...
[ "DIC28", "Dataset", "from", "Pajek", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L305-L337
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_amazon
def load_amazon(): """Amazon product co-purchasing network and ground-truth communities. Network was collected by crawling Amazon website. It is based on Customers Who Bought This Item Also Bought feature of the Amazon website. If a product i is frequently co-purchased with product j, the graph contain...
python
def load_amazon(): """Amazon product co-purchasing network and ground-truth communities. Network was collected by crawling Amazon website. It is based on Customers Who Bought This Item Also Bought feature of the Amazon website. If a product i is frequently co-purchased with product j, the graph contain...
[ "def", "load_amazon", "(", ")", ":", "dataset_path", "=", "_load", "(", "'amazon'", ")", "X", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "y", "=", "X", ".", "pop", "(", "'label'", ")", ".", "values", "graph", "=", "nx", ".", "Graph", ...
Amazon product co-purchasing network and ground-truth communities. Network was collected by crawling Amazon website. It is based on Customers Who Bought This Item Also Bought feature of the Amazon website. If a product i is frequently co-purchased with product j, the graph contains an undirected edge from ...
[ "Amazon", "product", "co", "-", "purchasing", "network", "and", "ground", "-", "truth", "communities", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L357-L373
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_jester
def load_jester(): """Ratings from the Jester Online Joke Recommender System. This dataset consists of over 1.7 million instances of (user_id, item_id, rating) triples, which is split 50-50 into train and test data. source: "University of California Berkeley, CA" sourceURI: "http://eigentaste.berk...
python
def load_jester(): """Ratings from the Jester Online Joke Recommender System. This dataset consists of over 1.7 million instances of (user_id, item_id, rating) triples, which is split 50-50 into train and test data. source: "University of California Berkeley, CA" sourceURI: "http://eigentaste.berk...
[ "def", "load_jester", "(", ")", ":", "dataset_path", "=", "_load", "(", "'jester'", ")", "X", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ")", "y", "=", "X", ".", "pop", "(", "'rating'", ")", ".", "values", "return", "Dataset", "(", "load_jes...
Ratings from the Jester Online Joke Recommender System. This dataset consists of over 1.7 million instances of (user_id, item_id, rating) triples, which is split 50-50 into train and test data. source: "University of California Berkeley, CA" sourceURI: "http://eigentaste.berkeley.edu/dataset/"
[ "Ratings", "from", "the", "Jester", "Online", "Joke", "Recommender", "System", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L376-L391
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_wikiqa
def load_wikiqa(): """A Challenge Dataset for Open-Domain Question Answering. WikiQA dataset is a publicly available set of question and sentence (QS) pairs, collected and annotated for research on open-domain question answering. source: "Microsoft" sourceURI: "https://www.microsoft.com/en-us/rese...
python
def load_wikiqa(): """A Challenge Dataset for Open-Domain Question Answering. WikiQA dataset is a publicly available set of question and sentence (QS) pairs, collected and annotated for research on open-domain question answering. source: "Microsoft" sourceURI: "https://www.microsoft.com/en-us/rese...
[ "def", "load_wikiqa", "(", ")", ":", "dataset_path", "=", "_load", "(", "'wikiqa'", ")", "data", "=", "_load_csv", "(", "dataset_path", ",", "'data'", ",", "set_index", "=", "True", ")", "questions", "=", "_load_csv", "(", "dataset_path", ",", "'questions'",...
A Challenge Dataset for Open-Domain Question Answering. WikiQA dataset is a publicly available set of question and sentence (QS) pairs, collected and annotated for research on open-domain question answering. source: "Microsoft" sourceURI: "https://www.microsoft.com/en-us/research/publication/wikiqa-a-...
[ "A", "Challenge", "Dataset", "for", "Open", "-", "Domain", "Question", "Answering", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L394-L425
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_newsgroups
def load_newsgroups(): """20 News Groups Dataset. The data of this dataset is a 1d numpy array vector containing the texts from 11314 newsgroups posts, and the target is a 1d numpy integer array containing the label of one of the 20 topics that they are about. """ dataset = datasets.fetch_20new...
python
def load_newsgroups(): """20 News Groups Dataset. The data of this dataset is a 1d numpy array vector containing the texts from 11314 newsgroups posts, and the target is a 1d numpy integer array containing the label of one of the 20 topics that they are about. """ dataset = datasets.fetch_20new...
[ "def", "load_newsgroups", "(", ")", ":", "dataset", "=", "datasets", ".", "fetch_20newsgroups", "(", ")", "return", "Dataset", "(", "load_newsgroups", ".", "__doc__", ",", "np", ".", "array", "(", "dataset", ".", "data", ")", ",", "dataset", ".", "target",...
20 News Groups Dataset. The data of this dataset is a 1d numpy array vector containing the texts from 11314 newsgroups posts, and the target is a 1d numpy integer array containing the label of one of the 20 topics that they are about.
[ "20", "News", "Groups", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L428-L437
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_iris
def load_iris(): """Iris Dataset.""" dataset = datasets.load_iris() return Dataset(load_iris.__doc__, dataset.data, dataset.target, accuracy_score, stratify=True)
python
def load_iris(): """Iris Dataset.""" dataset = datasets.load_iris() return Dataset(load_iris.__doc__, dataset.data, dataset.target, accuracy_score, stratify=True)
[ "def", "load_iris", "(", ")", ":", "dataset", "=", "datasets", ".", "load_iris", "(", ")", "return", "Dataset", "(", "load_iris", ".", "__doc__", ",", "dataset", ".", "data", ",", "dataset", ".", "target", ",", "accuracy_score", ",", "stratify", "=", "Tr...
Iris Dataset.
[ "Iris", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L440-L444
train
HDI-Project/MLBlocks
mlblocks/datasets.py
load_boston
def load_boston(): """Boston House Prices Dataset.""" dataset = datasets.load_boston() return Dataset(load_boston.__doc__, dataset.data, dataset.target, r2_score)
python
def load_boston(): """Boston House Prices Dataset.""" dataset = datasets.load_boston() return Dataset(load_boston.__doc__, dataset.data, dataset.target, r2_score)
[ "def", "load_boston", "(", ")", ":", "dataset", "=", "datasets", ".", "load_boston", "(", ")", "return", "Dataset", "(", "load_boston", ".", "__doc__", ",", "dataset", ".", "data", ",", "dataset", ".", "target", ",", "r2_score", ")" ]
Boston House Prices Dataset.
[ "Boston", "House", "Prices", "Dataset", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L447-L450
train
HDI-Project/MLBlocks
mlblocks/datasets.py
Dataset.get_splits
def get_splits(self, n_splits=1): """Return splits of this dataset ready for Cross Validation. If n_splits is 1, a tuple containing the X for train and test and the y for train and test is returned. Otherwise, if n_splits is bigger than 1, a list of such tuples is returned, one ...
python
def get_splits(self, n_splits=1): """Return splits of this dataset ready for Cross Validation. If n_splits is 1, a tuple containing the X for train and test and the y for train and test is returned. Otherwise, if n_splits is bigger than 1, a list of such tuples is returned, one ...
[ "def", "get_splits", "(", "self", ",", "n_splits", "=", "1", ")", ":", "if", "n_splits", "==", "1", ":", "stratify", "=", "self", ".", "target", "if", "self", ".", "_stratify", "else", "None", "return", "train_test_split", "(", "self", ".", "data", ","...
Return splits of this dataset ready for Cross Validation. If n_splits is 1, a tuple containing the X for train and test and the y for train and test is returned. Otherwise, if n_splits is bigger than 1, a list of such tuples is returned, one for each split. Args: n_...
[ "Return", "splits", "of", "this", "dataset", "ready", "for", "Cross", "Validation", "." ]
e1ca77bce3c4537c0800a4c1395e1b6bbde5465d
https://github.com/HDI-Project/MLBlocks/blob/e1ca77bce3c4537c0800a4c1395e1b6bbde5465d/mlblocks/datasets.py#L144-L184
train
scoutapp/scout_apm_python
src/scout_apm/api/context.py
Context.add
def add(key, value): """Adds context to the currently executing request. :key: Any String identifying the request context. Example: "user_ip", "plan", "alert_count" :value: Any json-serializable type. Example: "1.1.1.1", "free", 100 :returns: nothing. ...
python
def add(key, value): """Adds context to the currently executing request. :key: Any String identifying the request context. Example: "user_ip", "plan", "alert_count" :value: Any json-serializable type. Example: "1.1.1.1", "free", 100 :returns: nothing. ...
[ "def", "add", "(", "key", ",", "value", ")", ":", "tr", "=", "TrackedRequest", ".", "instance", "(", ")", "tr", ".", "tag", "(", "key", ",", "value", ")" ]
Adds context to the currently executing request. :key: Any String identifying the request context. Example: "user_ip", "plan", "alert_count" :value: Any json-serializable type. Example: "1.1.1.1", "free", 100 :returns: nothing.
[ "Adds", "context", "to", "the", "currently", "executing", "request", "." ]
e5539ee23b8129be9b75d5007c88b6158b51294f
https://github.com/scoutapp/scout_apm_python/blob/e5539ee23b8129be9b75d5007c88b6158b51294f/src/scout_apm/api/context.py#L8-L18
train
scoutapp/scout_apm_python
src/scout_apm/core/platform_detection.py
PlatformDetection.libc
def libc(cls): """ Alpine linux uses a non glibc version of the standard library, it uses the stripped down musl instead. The core agent can be built against it, but which one is running must be detected. Shelling out to `ldd` appears to be the most reliable way to do this. ...
python
def libc(cls): """ Alpine linux uses a non glibc version of the standard library, it uses the stripped down musl instead. The core agent can be built against it, but which one is running must be detected. Shelling out to `ldd` appears to be the most reliable way to do this. ...
[ "def", "libc", "(", "cls", ")", ":", "try", ":", "output", "=", "subprocess", ".", "check_output", "(", "[", "\"ldd\"", ",", "\"--version\"", "]", ",", "stderr", "=", "subprocess", ".", "STDOUT", ")", "except", "(", "OSError", ",", "subprocess", ".", "...
Alpine linux uses a non glibc version of the standard library, it uses the stripped down musl instead. The core agent can be built against it, but which one is running must be detected. Shelling out to `ldd` appears to be the most reliable way to do this.
[ "Alpine", "linux", "uses", "a", "non", "glibc", "version", "of", "the", "standard", "library", "it", "uses", "the", "stripped", "down", "musl", "instead", ".", "The", "core", "agent", "can", "be", "built", "against", "it", "but", "which", "one", "is", "r...
e5539ee23b8129be9b75d5007c88b6158b51294f
https://github.com/scoutapp/scout_apm_python/blob/e5539ee23b8129be9b75d5007c88b6158b51294f/src/scout_apm/core/platform_detection.py#L45-L62
train