partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
Property._retrieve_value
Internal helper to retrieve the value for this Property from an entity. This returns None if no value is set, or the default argument if given. For a repeated Property this returns a list if a value is set, otherwise None. No additional transformations are applied.
ndb/model.py
def _retrieve_value(self, entity, default=None): """Internal helper to retrieve the value for this Property from an entity. This returns None if no value is set, or the default argument if given. For a repeated Property this returns a list if a value is set, otherwise None. No additional transformati...
def _retrieve_value(self, entity, default=None): """Internal helper to retrieve the value for this Property from an entity. This returns None if no value is set, or the default argument if given. For a repeated Property this returns a list if a value is set, otherwise None. No additional transformati...
[ "Internal", "helper", "to", "retrieve", "the", "value", "for", "this", "Property", "from", "an", "entity", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1152-L1159
[ "def", "_retrieve_value", "(", "self", ",", "entity", ",", "default", "=", "None", ")", ":", "return", "entity", ".", "_values", ".", "get", "(", "self", ".", "_name", ",", "default", ")" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._get_base_value_unwrapped_as_list
Like _get_base_value(), but always returns a list. Returns: A new list of unwrapped base values. For an unrepeated property, if the value is missing or None, returns [None]; for a repeated property, if the original value is missing or None or empty, returns [].
ndb/model.py
def _get_base_value_unwrapped_as_list(self, entity): """Like _get_base_value(), but always returns a list. Returns: A new list of unwrapped base values. For an unrepeated property, if the value is missing or None, returns [None]; for a repeated property, if the original value is missing or N...
def _get_base_value_unwrapped_as_list(self, entity): """Like _get_base_value(), but always returns a list. Returns: A new list of unwrapped base values. For an unrepeated property, if the value is missing or None, returns [None]; for a repeated property, if the original value is missing or N...
[ "Like", "_get_base_value", "()", "but", "always", "returns", "a", "list", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1183-L1202
[ "def", "_get_base_value_unwrapped_as_list", "(", "self", ",", "entity", ")", ":", "wrapped", "=", "self", ".", "_get_base_value", "(", "entity", ")", "if", "self", ".", "_repeated", ":", "if", "wrapped", "is", "None", ":", "return", "[", "]", "assert", "is...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._opt_call_from_base_type
Call _from_base_type() if necessary. If the value is a _BaseValue instance, unwrap it and call all _from_base_type() methods. Otherwise, return the value unchanged.
ndb/model.py
def _opt_call_from_base_type(self, value): """Call _from_base_type() if necessary. If the value is a _BaseValue instance, unwrap it and call all _from_base_type() methods. Otherwise, return the value unchanged. """ if isinstance(value, _BaseValue): value = self._call_from_base_type(value...
def _opt_call_from_base_type(self, value): """Call _from_base_type() if necessary. If the value is a _BaseValue instance, unwrap it and call all _from_base_type() methods. Otherwise, return the value unchanged. """ if isinstance(value, _BaseValue): value = self._call_from_base_type(value...
[ "Call", "_from_base_type", "()", "if", "necessary", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1204-L1213
[ "def", "_opt_call_from_base_type", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "_BaseValue", ")", ":", "value", "=", "self", ".", "_call_from_base_type", "(", "value", ".", "b_val", ")", "return", "value" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._opt_call_to_base_type
Call _to_base_type() if necessary. If the value is a _BaseValue instance, return it unchanged. Otherwise, call all _validate() and _to_base_type() methods and wrap it in a _BaseValue instance.
ndb/model.py
def _opt_call_to_base_type(self, value): """Call _to_base_type() if necessary. If the value is a _BaseValue instance, return it unchanged. Otherwise, call all _validate() and _to_base_type() methods and wrap it in a _BaseValue instance. """ if not isinstance(value, _BaseValue): value = _B...
def _opt_call_to_base_type(self, value): """Call _to_base_type() if necessary. If the value is a _BaseValue instance, return it unchanged. Otherwise, call all _validate() and _to_base_type() methods and wrap it in a _BaseValue instance. """ if not isinstance(value, _BaseValue): value = _B...
[ "Call", "_to_base_type", "()", "if", "necessary", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1226-L1235
[ "def", "_opt_call_to_base_type", "(", "self", ",", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "_BaseValue", ")", ":", "value", "=", "_BaseValue", "(", "self", ".", "_call_to_base_type", "(", "value", ")", ")", "return", "value" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._call_from_base_type
Call all _from_base_type() methods on the value. This calls the methods in the reverse method resolution order of the property's class.
ndb/model.py
def _call_from_base_type(self, value): """Call all _from_base_type() methods on the value. This calls the methods in the reverse method resolution order of the property's class. """ methods = self._find_methods('_from_base_type', reverse=True) call = self._apply_list(methods) return call(va...
def _call_from_base_type(self, value): """Call all _from_base_type() methods on the value. This calls the methods in the reverse method resolution order of the property's class. """ methods = self._find_methods('_from_base_type', reverse=True) call = self._apply_list(methods) return call(va...
[ "Call", "all", "_from_base_type", "()", "methods", "on", "the", "value", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1237-L1245
[ "def", "_call_from_base_type", "(", "self", ",", "value", ")", ":", "methods", "=", "self", ".", "_find_methods", "(", "'_from_base_type'", ",", "reverse", "=", "True", ")", "call", "=", "self", ".", "_apply_list", "(", "methods", ")", "return", "call", "(...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._call_to_base_type
Call all _validate() and _to_base_type() methods on the value. This calls the methods in the method resolution order of the property's class.
ndb/model.py
def _call_to_base_type(self, value): """Call all _validate() and _to_base_type() methods on the value. This calls the methods in the method resolution order of the property's class. """ methods = self._find_methods('_validate', '_to_base_type') call = self._apply_list(methods) return call(v...
def _call_to_base_type(self, value): """Call all _validate() and _to_base_type() methods on the value. This calls the methods in the method resolution order of the property's class. """ methods = self._find_methods('_validate', '_to_base_type') call = self._apply_list(methods) return call(v...
[ "Call", "all", "_validate", "()", "and", "_to_base_type", "()", "methods", "on", "the", "value", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1247-L1255
[ "def", "_call_to_base_type", "(", "self", ",", "value", ")", ":", "methods", "=", "self", ".", "_find_methods", "(", "'_validate'", ",", "'_to_base_type'", ")", "call", "=", "self", ".", "_apply_list", "(", "methods", ")", "return", "call", "(", "value", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._call_shallow_validation
Call the initial set of _validate() methods. This is similar to _call_to_base_type() except it only calls those _validate() methods that can be called without needing to call _to_base_type(). An example: suppose the class hierarchy is A -> B -> C -> Property, and suppose A defines _validate() only...
ndb/model.py
def _call_shallow_validation(self, value): """Call the initial set of _validate() methods. This is similar to _call_to_base_type() except it only calls those _validate() methods that can be called without needing to call _to_base_type(). An example: suppose the class hierarchy is A -> B -> C -> ...
def _call_shallow_validation(self, value): """Call the initial set of _validate() methods. This is similar to _call_to_base_type() except it only calls those _validate() methods that can be called without needing to call _to_base_type(). An example: suppose the class hierarchy is A -> B -> C -> ...
[ "Call", "the", "initial", "set", "of", "_validate", "()", "methods", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1257-L1284
[ "def", "_call_shallow_validation", "(", "self", ",", "value", ")", ":", "methods", "=", "[", "]", "for", "method", "in", "self", ".", "_find_methods", "(", "'_validate'", ",", "'_to_base_type'", ")", ":", "if", "method", ".", "__name__", "!=", "'_validate'",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._find_methods
Compute a list of composable methods. Because this is a common operation and the class hierarchy is static, the outcome is cached (assuming that for a particular list of names the reversed flag is either always on, or always off). Args: *names: One or more method names. reverse: Optional f...
ndb/model.py
def _find_methods(cls, *names, **kwds): """Compute a list of composable methods. Because this is a common operation and the class hierarchy is static, the outcome is cached (assuming that for a particular list of names the reversed flag is either always on, or always off). Args: *names: One ...
def _find_methods(cls, *names, **kwds): """Compute a list of composable methods. Because this is a common operation and the class hierarchy is static, the outcome is cached (assuming that for a particular list of names the reversed flag is either always on, or always off). Args: *names: One ...
[ "Compute", "a", "list", "of", "composable", "methods", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1287-L1320
[ "def", "_find_methods", "(", "cls", ",", "*", "names", ",", "*", "*", "kwds", ")", ":", "reverse", "=", "kwds", ".", "pop", "(", "'reverse'", ",", "False", ")", "assert", "not", "kwds", ",", "repr", "(", "kwds", ")", "cache", "=", "cls", ".", "__...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._apply_list
Return a single callable that applies a list of methods to a value. If a method returns None, the last value is kept; if it returns some other value, that replaces the last value. Exceptions are not caught.
ndb/model.py
def _apply_list(self, methods): """Return a single callable that applies a list of methods to a value. If a method returns None, the last value is kept; if it returns some other value, that replaces the last value. Exceptions are not caught. """ def call(value): for method in methods: ...
def _apply_list(self, methods): """Return a single callable that applies a list of methods to a value. If a method returns None, the last value is kept; if it returns some other value, that replaces the last value. Exceptions are not caught. """ def call(value): for method in methods: ...
[ "Return", "a", "single", "callable", "that", "applies", "a", "list", "of", "methods", "to", "a", "value", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1322-L1335
[ "def", "_apply_list", "(", "self", ",", "methods", ")", ":", "def", "call", "(", "value", ")", ":", "for", "method", "in", "methods", ":", "newvalue", "=", "method", "(", "self", ",", "value", ")", "if", "newvalue", "is", "not", "None", ":", "value",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._apply_to_values
Apply a function to the property value/values of a given entity. This retrieves the property value, applies the function, and then stores the value back. For a repeated property, the function is applied separately to each of the values in the list. The resulting value or list of values is both stored...
ndb/model.py
def _apply_to_values(self, entity, function): """Apply a function to the property value/values of a given entity. This retrieves the property value, applies the function, and then stores the value back. For a repeated property, the function is applied separately to each of the values in the list. The...
def _apply_to_values(self, entity, function): """Apply a function to the property value/values of a given entity. This retrieves the property value, applies the function, and then stores the value back. For a repeated property, the function is applied separately to each of the values in the list. The...
[ "Apply", "a", "function", "to", "the", "property", "value", "/", "values", "of", "a", "given", "entity", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1337-L1359
[ "def", "_apply_to_values", "(", "self", ",", "entity", ",", "function", ")", ":", "value", "=", "self", ".", "_retrieve_value", "(", "entity", ",", "self", ".", "_default", ")", "if", "self", ".", "_repeated", ":", "if", "value", "is", "None", ":", "va...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._get_value
Internal helper to get the value for this Property from an entity. For a repeated Property this initializes the value to an empty list if it is not set.
ndb/model.py
def _get_value(self, entity): """Internal helper to get the value for this Property from an entity. For a repeated Property this initializes the value to an empty list if it is not set. """ if entity._projection: if self._name not in entity._projection: raise UnprojectedPropertyError(...
def _get_value(self, entity): """Internal helper to get the value for this Property from an entity. For a repeated Property this initializes the value to an empty list if it is not set. """ if entity._projection: if self._name not in entity._projection: raise UnprojectedPropertyError(...
[ "Internal", "helper", "to", "get", "the", "value", "for", "this", "Property", "from", "an", "entity", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1361-L1371
[ "def", "_get_value", "(", "self", ",", "entity", ")", ":", "if", "entity", ".", "_projection", ":", "if", "self", ".", "_name", "not", "in", "entity", ".", "_projection", ":", "raise", "UnprojectedPropertyError", "(", "'Property %s is not in the projection'", "%...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._delete_value
Internal helper to delete the value for this Property from an entity. Note that if no value exists this is a no-op; deleted values will not be serialized but requesting their value will return None (or an empty list in the case of a repeated Property).
ndb/model.py
def _delete_value(self, entity): """Internal helper to delete the value for this Property from an entity. Note that if no value exists this is a no-op; deleted values will not be serialized but requesting their value will return None (or an empty list in the case of a repeated Property). """ if...
def _delete_value(self, entity): """Internal helper to delete the value for this Property from an entity. Note that if no value exists this is a no-op; deleted values will not be serialized but requesting their value will return None (or an empty list in the case of a repeated Property). """ if...
[ "Internal", "helper", "to", "delete", "the", "value", "for", "this", "Property", "from", "an", "entity", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1373-L1381
[ "def", "_delete_value", "(", "self", ",", "entity", ")", ":", "if", "self", ".", "_name", "in", "entity", ".", "_values", ":", "del", "entity", ".", "_values", "[", "self", ".", "_name", "]" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._is_initialized
Internal helper to ask if the entity has a value for this Property. This returns False if a value is stored but it is None.
ndb/model.py
def _is_initialized(self, entity): """Internal helper to ask if the entity has a value for this Property. This returns False if a value is stored but it is None. """ return (not self._required or ((self._has_value(entity) or self._default is not None) and self._get_value(entity...
def _is_initialized(self, entity): """Internal helper to ask if the entity has a value for this Property. This returns False if a value is stored but it is None. """ return (not self._required or ((self._has_value(entity) or self._default is not None) and self._get_value(entity...
[ "Internal", "helper", "to", "ask", "if", "the", "entity", "has", "a", "value", "for", "this", "Property", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1383-L1390
[ "def", "_is_initialized", "(", "self", ",", "entity", ")", ":", "return", "(", "not", "self", ".", "_required", "or", "(", "(", "self", ".", "_has_value", "(", "entity", ")", "or", "self", ".", "_default", "is", "not", "None", ")", "and", "self", "."...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._serialize
Internal helper to serialize this property to a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. pb: The protocol buffer, an EntityProto instance. prefix: Optional name prefix used for StructuredProperty (if present, must en...
ndb/model.py
def _serialize(self, entity, pb, prefix='', parent_repeated=False, projection=None): """Internal helper to serialize this property to a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. pb: The protocol buffer, an Enti...
def _serialize(self, entity, pb, prefix='', parent_repeated=False, projection=None): """Internal helper to serialize this property to a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. pb: The protocol buffer, an Enti...
[ "Internal", "helper", "to", "serialize", "this", "property", "to", "a", "protocol", "buffer", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1406-L1456
[ "def", "_serialize", "(", "self", ",", "entity", ",", "pb", ",", "prefix", "=", "''", ",", "parent_repeated", "=", "False", ",", "projection", "=", "None", ")", ":", "values", "=", "self", ".", "_get_base_value_unwrapped_as_list", "(", "entity", ")", "name...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._deserialize
Internal helper to deserialize this property from a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. p: A Property Message object (a protocol buffer). depth: Optional nesting depth, default 1 (unused here, but used by some s...
ndb/model.py
def _deserialize(self, entity, p, unused_depth=1): """Internal helper to deserialize this property from a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. p: A Property Message object (a protocol buffer). depth: Optional nesting...
def _deserialize(self, entity, p, unused_depth=1): """Internal helper to deserialize this property from a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. p: A Property Message object (a protocol buffer). depth: Optional nesting...
[ "Internal", "helper", "to", "deserialize", "this", "property", "from", "a", "protocol", "buffer", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1458-L1496
[ "def", "_deserialize", "(", "self", ",", "entity", ",", "p", ",", "unused_depth", "=", "1", ")", ":", "if", "p", ".", "meaning", "(", ")", "==", "entity_pb", ".", "Property", ".", "EMPTY_LIST", ":", "self", ".", "_store_value", "(", "entity", ",", "[...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Property._check_property
Internal helper to check this property for specific requirements. Called by Model._check_properties(). Args: rest: Optional subproperty to check, of the form 'name1.name2...nameN'. Raises: InvalidPropertyError if this property does not meet the given requirements or if a subproperty is ...
ndb/model.py
def _check_property(self, rest=None, require_indexed=True): """Internal helper to check this property for specific requirements. Called by Model._check_properties(). Args: rest: Optional subproperty to check, of the form 'name1.name2...nameN'. Raises: InvalidPropertyError if this property...
def _check_property(self, rest=None, require_indexed=True): """Internal helper to check this property for specific requirements. Called by Model._check_properties(). Args: rest: Optional subproperty to check, of the form 'name1.name2...nameN'. Raises: InvalidPropertyError if this property...
[ "Internal", "helper", "to", "check", "this", "property", "for", "specific", "requirements", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1501-L1519
[ "def", "_check_property", "(", "self", ",", "rest", "=", "None", ",", "require_indexed", "=", "True", ")", ":", "if", "require_indexed", "and", "not", "self", ".", "_indexed", ":", "raise", "InvalidPropertyError", "(", "'Property is unindexed %s'", "%", "self", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
ModelKey._set_value
Setter for key attribute.
ndb/model.py
def _set_value(self, entity, value): """Setter for key attribute.""" if value is not None: value = _validate_key(value, entity=entity) value = entity._validate_key(value) entity._entity_key = value
def _set_value(self, entity, value): """Setter for key attribute.""" if value is not None: value = _validate_key(value, entity=entity) value = entity._validate_key(value) entity._entity_key = value
[ "Setter", "for", "key", "attribute", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1573-L1578
[ "def", "_set_value", "(", "self", ",", "entity", ",", "value", ")", ":", "if", "value", "is", "not", "None", ":", "value", "=", "_validate_key", "(", "value", ",", "entity", "=", "entity", ")", "value", "=", "entity", ".", "_validate_key", "(", "value"...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
StructuredProperty._get_value
Override _get_value() to *not* raise UnprojectedPropertyError.
ndb/model.py
def _get_value(self, entity): """Override _get_value() to *not* raise UnprojectedPropertyError.""" value = self._get_user_value(entity) if value is None and entity._projection: # Invoke super _get_value() to raise the proper exception. return super(StructuredProperty, self)._get_value(entity) ...
def _get_value(self, entity): """Override _get_value() to *not* raise UnprojectedPropertyError.""" value = self._get_user_value(entity) if value is None and entity._projection: # Invoke super _get_value() to raise the proper exception. return super(StructuredProperty, self)._get_value(entity) ...
[ "Override", "_get_value", "()", "to", "*", "not", "*", "raise", "UnprojectedPropertyError", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2262-L2268
[ "def", "_get_value", "(", "self", ",", "entity", ")", ":", "value", "=", "self", ".", "_get_user_value", "(", "entity", ")", "if", "value", "is", "None", "and", "entity", ".", "_projection", ":", "# Invoke super _get_value() to raise the proper exception.", "retur...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
StructuredProperty._check_property
Override for Property._check_property(). Raises: InvalidPropertyError if no subproperty is specified or if something is wrong with the subproperty.
ndb/model.py
def _check_property(self, rest=None, require_indexed=True): """Override for Property._check_property(). Raises: InvalidPropertyError if no subproperty is specified or if something is wrong with the subproperty. """ if not rest: raise InvalidPropertyError( 'Structured propert...
def _check_property(self, rest=None, require_indexed=True): """Override for Property._check_property(). Raises: InvalidPropertyError if no subproperty is specified or if something is wrong with the subproperty. """ if not rest: raise InvalidPropertyError( 'Structured propert...
[ "Override", "for", "Property", ".", "_check_property", "()", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2508-L2518
[ "def", "_check_property", "(", "self", ",", "rest", "=", "None", ",", "require_indexed", "=", "True", ")", ":", "if", "not", "rest", ":", "raise", "InvalidPropertyError", "(", "'Structured property %s requires a subproperty'", "%", "self", ".", "_name", ")", "se...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model.__get_arg
Internal helper method to parse keywords that may be property names.
ndb/model.py
def __get_arg(cls, kwds, kwd): """Internal helper method to parse keywords that may be property names.""" alt_kwd = '_' + kwd if alt_kwd in kwds: return kwds.pop(alt_kwd) if kwd in kwds: obj = getattr(cls, kwd, None) if not isinstance(obj, Property) or isinstance(obj, ModelKey): ...
def __get_arg(cls, kwds, kwd): """Internal helper method to parse keywords that may be property names.""" alt_kwd = '_' + kwd if alt_kwd in kwds: return kwds.pop(alt_kwd) if kwd in kwds: obj = getattr(cls, kwd, None) if not isinstance(obj, Property) or isinstance(obj, ModelKey): ...
[ "Internal", "helper", "method", "to", "parse", "keywords", "that", "may", "be", "property", "names", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2953-L2962
[ "def", "__get_arg", "(", "cls", ",", "kwds", ",", "kwd", ")", ":", "alt_kwd", "=", "'_'", "+", "kwd", "if", "alt_kwd", "in", "kwds", ":", "return", "kwds", ".", "pop", "(", "alt_kwd", ")", "if", "kwd", "in", "kwds", ":", "obj", "=", "getattr", "(...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._set_attributes
Internal helper to set attributes from keyword arguments. Expando overrides this.
ndb/model.py
def _set_attributes(self, kwds): """Internal helper to set attributes from keyword arguments. Expando overrides this. """ cls = self.__class__ for name, value in kwds.iteritems(): prop = getattr(cls, name) # Raises AttributeError for unknown properties. if not isinstance(prop, Property...
def _set_attributes(self, kwds): """Internal helper to set attributes from keyword arguments. Expando overrides this. """ cls = self.__class__ for name, value in kwds.iteritems(): prop = getattr(cls, name) # Raises AttributeError for unknown properties. if not isinstance(prop, Property...
[ "Internal", "helper", "to", "set", "attributes", "from", "keyword", "arguments", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2983-L2993
[ "def", "_set_attributes", "(", "self", ",", "kwds", ")", ":", "cls", "=", "self", ".", "__class__", "for", "name", ",", "value", "in", "kwds", ".", "iteritems", "(", ")", ":", "prop", "=", "getattr", "(", "cls", ",", "name", ")", "# Raises AttributeErr...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._find_uninitialized
Internal helper to find uninitialized properties. Returns: A set of property names.
ndb/model.py
def _find_uninitialized(self): """Internal helper to find uninitialized properties. Returns: A set of property names. """ return set(name for name, prop in self._properties.iteritems() if not prop._is_initialized(self))
def _find_uninitialized(self): """Internal helper to find uninitialized properties. Returns: A set of property names. """ return set(name for name, prop in self._properties.iteritems() if not prop._is_initialized(self))
[ "Internal", "helper", "to", "find", "uninitialized", "properties", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2995-L3003
[ "def", "_find_uninitialized", "(", "self", ")", ":", "return", "set", "(", "name", "for", "name", ",", "prop", "in", "self", ".", "_properties", ".", "iteritems", "(", ")", "if", "not", "prop", ".", "_is_initialized", "(", "self", ")", ")" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._check_initialized
Internal helper to check for uninitialized properties. Raises: BadValueError if it finds any.
ndb/model.py
def _check_initialized(self): """Internal helper to check for uninitialized properties. Raises: BadValueError if it finds any. """ baddies = self._find_uninitialized() if baddies: raise datastore_errors.BadValueError( 'Entity has uninitialized properties: %s' % ', '.join(baddi...
def _check_initialized(self): """Internal helper to check for uninitialized properties. Raises: BadValueError if it finds any. """ baddies = self._find_uninitialized() if baddies: raise datastore_errors.BadValueError( 'Entity has uninitialized properties: %s' % ', '.join(baddi...
[ "Internal", "helper", "to", "check", "for", "uninitialized", "properties", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3005-L3014
[ "def", "_check_initialized", "(", "self", ")", ":", "baddies", "=", "self", ".", "_find_uninitialized", "(", ")", "if", "baddies", ":", "raise", "datastore_errors", ".", "BadValueError", "(", "'Entity has uninitialized properties: %s'", "%", "', '", ".", "join", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._reset_kind_map
Clear the kind map. Useful for testing.
ndb/model.py
def _reset_kind_map(cls): """Clear the kind map. Useful for testing.""" # Preserve "system" kinds, like __namespace__ keep = {} for name, value in cls._kind_map.iteritems(): if name.startswith('__') and name.endswith('__'): keep[name] = value cls._kind_map.clear() cls._kind_map.up...
def _reset_kind_map(cls): """Clear the kind map. Useful for testing.""" # Preserve "system" kinds, like __namespace__ keep = {} for name, value in cls._kind_map.iteritems(): if name.startswith('__') and name.endswith('__'): keep[name] = value cls._kind_map.clear() cls._kind_map.up...
[ "Clear", "the", "kind", "map", ".", "Useful", "for", "testing", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3074-L3082
[ "def", "_reset_kind_map", "(", "cls", ")", ":", "# Preserve \"system\" kinds, like __namespace__", "keep", "=", "{", "}", "for", "name", ",", "value", "in", "cls", ".", "_kind_map", ".", "iteritems", "(", ")", ":", "if", "name", ".", "startswith", "(", "'__'...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._lookup_model
Get the model class for the kind. Args: kind: A string representing the name of the kind to lookup. default_model: The model class to use if the kind can't be found. Returns: The model class for the requested kind. Raises: KindError: The kind was not found and no default_model was ...
ndb/model.py
def _lookup_model(cls, kind, default_model=None): """Get the model class for the kind. Args: kind: A string representing the name of the kind to lookup. default_model: The model class to use if the kind can't be found. Returns: The model class for the requested kind. Raises: Ki...
def _lookup_model(cls, kind, default_model=None): """Get the model class for the kind. Args: kind: A string representing the name of the kind to lookup. default_model: The model class to use if the kind can't be found. Returns: The model class for the requested kind. Raises: Ki...
[ "Get", "the", "model", "class", "for", "the", "kind", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3085-L3102
[ "def", "_lookup_model", "(", "cls", ",", "kind", ",", "default_model", "=", "None", ")", ":", "modelclass", "=", "cls", ".", "_kind_map", ".", "get", "(", "kind", ",", "default_model", ")", "if", "modelclass", "is", "None", ":", "raise", "KindError", "("...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._equivalent
Compare two entities of the same class, excluding keys.
ndb/model.py
def _equivalent(self, other): """Compare two entities of the same class, excluding keys.""" if other.__class__ is not self.__class__: # TODO: What about subclasses? raise NotImplementedError('Cannot compare different model classes. ' '%s is not %s' % (self.__class__.__name...
def _equivalent(self, other): """Compare two entities of the same class, excluding keys.""" if other.__class__ is not self.__class__: # TODO: What about subclasses? raise NotImplementedError('Cannot compare different model classes. ' '%s is not %s' % (self.__class__.__name...
[ "Compare", "two", "entities", "of", "the", "same", "class", "excluding", "keys", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3129-L3153
[ "def", "_equivalent", "(", "self", ",", "other", ")", ":", "if", "other", ".", "__class__", "is", "not", "self", ".", "__class__", ":", "# TODO: What about subclasses?", "raise", "NotImplementedError", "(", "'Cannot compare different model classes. '", "'%s is not %s'",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._to_pb
Internal helper to turn an entity into an EntityProto protobuf.
ndb/model.py
def _to_pb(self, pb=None, allow_partial=False, set_key=True): """Internal helper to turn an entity into an EntityProto protobuf.""" if not allow_partial: self._check_initialized() if pb is None: pb = entity_pb.EntityProto() if set_key: # TODO: Move the key stuff into ModelAdapter.enti...
def _to_pb(self, pb=None, allow_partial=False, set_key=True): """Internal helper to turn an entity into an EntityProto protobuf.""" if not allow_partial: self._check_initialized() if pb is None: pb = entity_pb.EntityProto() if set_key: # TODO: Move the key stuff into ModelAdapter.enti...
[ "Internal", "helper", "to", "turn", "an", "entity", "into", "an", "EntityProto", "protobuf", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3155-L3169
[ "def", "_to_pb", "(", "self", ",", "pb", "=", "None", ",", "allow_partial", "=", "False", ",", "set_key", "=", "True", ")", ":", "if", "not", "allow_partial", ":", "self", ".", "_check_initialized", "(", ")", "if", "pb", "is", "None", ":", "pb", "=",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._key_to_pb
Internal helper to copy the key into a protobuf.
ndb/model.py
def _key_to_pb(self, pb): """Internal helper to copy the key into a protobuf.""" key = self._key if key is None: pairs = [(self._get_kind(), None)] ref = key_module._ReferenceFromPairs(pairs, reference=pb.mutable_key()) else: ref = key.reference() pb.mutable_key().CopyFrom(ref) ...
def _key_to_pb(self, pb): """Internal helper to copy the key into a protobuf.""" key = self._key if key is None: pairs = [(self._get_kind(), None)] ref = key_module._ReferenceFromPairs(pairs, reference=pb.mutable_key()) else: ref = key.reference() pb.mutable_key().CopyFrom(ref) ...
[ "Internal", "helper", "to", "copy", "the", "key", "into", "a", "protobuf", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3171-L3186
[ "def", "_key_to_pb", "(", "self", ",", "pb", ")", ":", "key", "=", "self", ".", "_key", "if", "key", "is", "None", ":", "pairs", "=", "[", "(", "self", ".", "_get_kind", "(", ")", ",", "None", ")", "]", "ref", "=", "key_module", ".", "_ReferenceF...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._from_pb
Internal helper to create an entity from an EntityProto protobuf.
ndb/model.py
def _from_pb(cls, pb, set_key=True, ent=None, key=None): """Internal helper to create an entity from an EntityProto protobuf.""" if not isinstance(pb, entity_pb.EntityProto): raise TypeError('pb must be a EntityProto; received %r' % pb) if ent is None: ent = cls() # A key passed in override...
def _from_pb(cls, pb, set_key=True, ent=None, key=None): """Internal helper to create an entity from an EntityProto protobuf.""" if not isinstance(pb, entity_pb.EntityProto): raise TypeError('pb must be a EntityProto; received %r' % pb) if ent is None: ent = cls() # A key passed in override...
[ "Internal", "helper", "to", "create", "an", "entity", "from", "an", "EntityProto", "protobuf", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3189-L3219
[ "def", "_from_pb", "(", "cls", ",", "pb", ",", "set_key", "=", "True", ",", "ent", "=", "None", ",", "key", "=", "None", ")", ":", "if", "not", "isinstance", "(", "pb", ",", "entity_pb", ".", "EntityProto", ")", ":", "raise", "TypeError", "(", "'pb...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._get_property_for
Internal helper to get the Property for a protobuf-level property.
ndb/model.py
def _get_property_for(self, p, indexed=True, depth=0): """Internal helper to get the Property for a protobuf-level property.""" parts = p.name().split('.') if len(parts) <= depth: # Apparently there's an unstructured value here. # Assume it is a None written for a missing value. # (It coul...
def _get_property_for(self, p, indexed=True, depth=0): """Internal helper to get the Property for a protobuf-level property.""" parts = p.name().split('.') if len(parts) <= depth: # Apparently there's an unstructured value here. # Assume it is a None written for a missing value. # (It coul...
[ "Internal", "helper", "to", "get", "the", "Property", "for", "a", "protobuf", "-", "level", "property", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3238-L3253
[ "def", "_get_property_for", "(", "self", ",", "p", ",", "indexed", "=", "True", ",", "depth", "=", "0", ")", ":", "parts", "=", "p", ".", "name", "(", ")", ".", "split", "(", "'.'", ")", "if", "len", "(", "parts", ")", "<=", "depth", ":", "# Ap...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._clone_properties
Internal helper to clone self._properties if necessary.
ndb/model.py
def _clone_properties(self): """Internal helper to clone self._properties if necessary.""" cls = self.__class__ if self._properties is cls._properties: self._properties = dict(cls._properties)
def _clone_properties(self): """Internal helper to clone self._properties if necessary.""" cls = self.__class__ if self._properties is cls._properties: self._properties = dict(cls._properties)
[ "Internal", "helper", "to", "clone", "self", ".", "_properties", "if", "necessary", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3255-L3259
[ "def", "_clone_properties", "(", "self", ")", ":", "cls", "=", "self", ".", "__class__", "if", "self", ".", "_properties", "is", "cls", ".", "_properties", ":", "self", ".", "_properties", "=", "dict", "(", "cls", ".", "_properties", ")" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._fake_property
Internal helper to create a fake Property.
ndb/model.py
def _fake_property(self, p, next, indexed=True): """Internal helper to create a fake Property.""" self._clone_properties() if p.name() != next and not p.name().endswith('.' + next): prop = StructuredProperty(Expando, next) prop._store_value(self, _BaseValue(Expando())) else: compressed...
def _fake_property(self, p, next, indexed=True): """Internal helper to create a fake Property.""" self._clone_properties() if p.name() != next and not p.name().endswith('.' + next): prop = StructuredProperty(Expando, next) prop._store_value(self, _BaseValue(Expando())) else: compressed...
[ "Internal", "helper", "to", "create", "a", "fake", "Property", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3261-L3275
[ "def", "_fake_property", "(", "self", ",", "p", ",", "next", ",", "indexed", "=", "True", ")", ":", "self", ".", "_clone_properties", "(", ")", "if", "p", ".", "name", "(", ")", "!=", "next", "and", "not", "p", ".", "name", "(", ")", ".", "endswi...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._to_dict
Return a dict containing the entity's property values. Args: include: Optional set of property names to include, default all. exclude: Optional set of property names to skip, default none. A name contained in both include and exclude is excluded.
ndb/model.py
def _to_dict(self, include=None, exclude=None): """Return a dict containing the entity's property values. Args: include: Optional set of property names to include, default all. exclude: Optional set of property names to skip, default none. A name contained in both include and exclude is exc...
def _to_dict(self, include=None, exclude=None): """Return a dict containing the entity's property values. Args: include: Optional set of property names to include, default all. exclude: Optional set of property names to skip, default none. A name contained in both include and exclude is exc...
[ "Return", "a", "dict", "containing", "the", "entity", "s", "property", "values", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3278-L3303
[ "def", "_to_dict", "(", "self", ",", "include", "=", "None", ",", "exclude", "=", "None", ")", ":", "if", "(", "include", "is", "not", "None", "and", "not", "isinstance", "(", "include", ",", "(", "list", ",", "tuple", ",", "set", ",", "frozenset", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._fix_up_properties
Fix up the properties by calling their _fix_up() method. Note: This is called by MetaModel, but may also be called manually after dynamically updating a model class.
ndb/model.py
def _fix_up_properties(cls): """Fix up the properties by calling their _fix_up() method. Note: This is called by MetaModel, but may also be called manually after dynamically updating a model class. """ # Verify that _get_kind() returns an 8-bit string. kind = cls._get_kind() if not isinstan...
def _fix_up_properties(cls): """Fix up the properties by calling their _fix_up() method. Note: This is called by MetaModel, but may also be called manually after dynamically updating a model class. """ # Verify that _get_kind() returns an 8-bit string. kind = cls._get_kind() if not isinstan...
[ "Fix", "up", "the", "properties", "by", "calling", "their", "_fix_up", "()", "method", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3307-L3342
[ "def", "_fix_up_properties", "(", "cls", ")", ":", "# Verify that _get_kind() returns an 8-bit string.", "kind", "=", "cls", ".", "_get_kind", "(", ")", "if", "not", "isinstance", "(", "kind", ",", "basestring", ")", ":", "raise", "KindError", "(", "'Class %s defi...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._check_properties
Internal helper to check the given properties exist and meet specified requirements. Called from query.py. Args: property_names: List or tuple of property names -- each being a string, possibly containing dots (to address subproperties of structured properties). Raises: In...
ndb/model.py
def _check_properties(cls, property_names, require_indexed=True): """Internal helper to check the given properties exist and meet specified requirements. Called from query.py. Args: property_names: List or tuple of property names -- each being a string, possibly containing dots (to addre...
def _check_properties(cls, property_names, require_indexed=True): """Internal helper to check the given properties exist and meet specified requirements. Called from query.py. Args: property_names: List or tuple of property names -- each being a string, possibly containing dots (to addre...
[ "Internal", "helper", "to", "check", "the", "given", "properties", "exist", "and", "meet", "specified", "requirements", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3355-L3381
[ "def", "_check_properties", "(", "cls", ",", "property_names", ",", "require_indexed", "=", "True", ")", ":", "assert", "isinstance", "(", "property_names", ",", "(", "list", ",", "tuple", ")", ")", ",", "repr", "(", "property_names", ")", "for", "name", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._query
Create a Query object for this class. Args: distinct: Optional bool, short hand for group_by = projection. *args: Used to apply an initial filter **kwds: are passed to the Query() constructor. Returns: A Query object.
ndb/model.py
def _query(cls, *args, **kwds): """Create a Query object for this class. Args: distinct: Optional bool, short hand for group_by = projection. *args: Used to apply an initial filter **kwds: are passed to the Query() constructor. Returns: A Query object. """ # Validating dist...
def _query(cls, *args, **kwds): """Create a Query object for this class. Args: distinct: Optional bool, short hand for group_by = projection. *args: Used to apply an initial filter **kwds: are passed to the Query() constructor. Returns: A Query object. """ # Validating dist...
[ "Create", "a", "Query", "object", "for", "this", "class", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3410-L3438
[ "def", "_query", "(", "cls", ",", "*", "args", ",", "*", "*", "kwds", ")", ":", "# Validating distinct.", "if", "'distinct'", "in", "kwds", ":", "if", "'group_by'", "in", "kwds", ":", "raise", "TypeError", "(", "'cannot use distinct= and group_by= at the same ti...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._gql
Run a GQL query.
ndb/model.py
def _gql(cls, query_string, *args, **kwds): """Run a GQL query.""" from .query import gql # Import late to avoid circular imports. return gql('SELECT * FROM %s %s' % (cls._class_name(), query_string), *args, **kwds)
def _gql(cls, query_string, *args, **kwds): """Run a GQL query.""" from .query import gql # Import late to avoid circular imports. return gql('SELECT * FROM %s %s' % (cls._class_name(), query_string), *args, **kwds)
[ "Run", "a", "GQL", "query", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3442-L3446
[ "def", "_gql", "(", "cls", ",", "query_string", ",", "*", "args", ",", "*", "*", "kwds", ")", ":", "from", ".", "query", "import", "gql", "# Import late to avoid circular imports.", "return", "gql", "(", "'SELECT * FROM %s %s'", "%", "(", "cls", ".", "_class...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._put_async
Write this entity to Cloud Datastore. This is the asynchronous version of Model._put().
ndb/model.py
def _put_async(self, **ctx_options): """Write this entity to Cloud Datastore. This is the asynchronous version of Model._put(). """ if self._projection: raise datastore_errors.BadRequestError('Cannot put a partial entity') from . import tasklets ctx = tasklets.get_context() self._prep...
def _put_async(self, **ctx_options): """Write this entity to Cloud Datastore. This is the asynchronous version of Model._put(). """ if self._projection: raise datastore_errors.BadRequestError('Cannot put a partial entity') from . import tasklets ctx = tasklets.get_context() self._prep...
[ "Write", "this", "entity", "to", "Cloud", "Datastore", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3461-L3478
[ "def", "_put_async", "(", "self", ",", "*", "*", "ctx_options", ")", ":", "if", "self", ".", "_projection", ":", "raise", "datastore_errors", ".", "BadRequestError", "(", "'Cannot put a partial entity'", ")", "from", ".", "import", "tasklets", "ctx", "=", "tas...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._get_or_insert
Transactionally retrieves an existing entity or creates a new one. Positional Args: name: Key name to retrieve or create. Keyword Args: namespace: Optional namespace. app: Optional app ID. parent: Parent entity key, if any. context_options: ContextOptions object (not keyword args...
ndb/model.py
def _get_or_insert(*args, **kwds): """Transactionally retrieves an existing entity or creates a new one. Positional Args: name: Key name to retrieve or create. Keyword Args: namespace: Optional namespace. app: Optional app ID. parent: Parent entity key, if any. context_option...
def _get_or_insert(*args, **kwds): """Transactionally retrieves an existing entity or creates a new one. Positional Args: name: Key name to retrieve or create. Keyword Args: namespace: Optional namespace. app: Optional app ID. parent: Parent entity key, if any. context_option...
[ "Transactionally", "retrieves", "an", "existing", "entity", "or", "creates", "a", "new", "one", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3482-L3503
[ "def", "_get_or_insert", "(", "*", "args", ",", "*", "*", "kwds", ")", ":", "cls", ",", "args", "=", "args", "[", "0", "]", ",", "args", "[", "1", ":", "]", "return", "cls", ".", "_get_or_insert_async", "(", "*", "args", ",", "*", "*", "kwds", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._get_or_insert_async
Transactionally retrieves an existing entity or creates a new one. This is the asynchronous version of Model._get_or_insert().
ndb/model.py
def _get_or_insert_async(*args, **kwds): """Transactionally retrieves an existing entity or creates a new one. This is the asynchronous version of Model._get_or_insert(). """ # NOTE: The signature is really weird here because we want to support # models with properties named e.g. 'cls' or 'name'. ...
def _get_or_insert_async(*args, **kwds): """Transactionally retrieves an existing entity or creates a new one. This is the asynchronous version of Model._get_or_insert(). """ # NOTE: The signature is really weird here because we want to support # models with properties named e.g. 'cls' or 'name'. ...
[ "Transactionally", "retrieves", "an", "existing", "entity", "or", "creates", "a", "new", "one", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3507-L3550
[ "def", "_get_or_insert_async", "(", "*", "args", ",", "*", "*", "kwds", ")", ":", "# NOTE: The signature is really weird here because we want to support", "# models with properties named e.g. 'cls' or 'name'.", "from", ".", "import", "tasklets", "cls", ",", "name", "=", "ar...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._allocate_ids
Allocates a range of key IDs for this model class. Args: size: Number of IDs to allocate. Either size or max can be specified, not both. max: Maximum ID to allocate. Either size or max can be specified, not both. parent: Parent key for which the IDs will be allocated. **ctx_...
ndb/model.py
def _allocate_ids(cls, size=None, max=None, parent=None, **ctx_options): """Allocates a range of key IDs for this model class. Args: size: Number of IDs to allocate. Either size or max can be specified, not both. max: Maximum ID to allocate. Either size or max can be specified, not ...
def _allocate_ids(cls, size=None, max=None, parent=None, **ctx_options): """Allocates a range of key IDs for this model class. Args: size: Number of IDs to allocate. Either size or max can be specified, not both. max: Maximum ID to allocate. Either size or max can be specified, not ...
[ "Allocates", "a", "range", "of", "key", "IDs", "for", "this", "model", "class", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3555-L3570
[ "def", "_allocate_ids", "(", "cls", ",", "size", "=", "None", ",", "max", "=", "None", ",", "parent", "=", "None", ",", "*", "*", "ctx_options", ")", ":", "return", "cls", ".", "_allocate_ids_async", "(", "size", "=", "size", ",", "max", "=", "max", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._allocate_ids_async
Allocates a range of key IDs for this model class. This is the asynchronous version of Model._allocate_ids().
ndb/model.py
def _allocate_ids_async(cls, size=None, max=None, parent=None, **ctx_options): """Allocates a range of key IDs for this model class. This is the asynchronous version of Model._allocate_ids(). """ from . import tasklets ctx = tasklets.get_context() cls._pre_allocate_ids...
def _allocate_ids_async(cls, size=None, max=None, parent=None, **ctx_options): """Allocates a range of key IDs for this model class. This is the asynchronous version of Model._allocate_ids(). """ from . import tasklets ctx = tasklets.get_context() cls._pre_allocate_ids...
[ "Allocates", "a", "range", "of", "key", "IDs", "for", "this", "model", "class", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3574-L3589
[ "def", "_allocate_ids_async", "(", "cls", ",", "size", "=", "None", ",", "max", "=", "None", ",", "parent", "=", "None", ",", "*", "*", "ctx_options", ")", ":", "from", ".", "import", "tasklets", "ctx", "=", "tasklets", ".", "get_context", "(", ")", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._get_by_id
Returns an instance of Model class by ID. This is really just a shorthand for Key(cls, id, ...).get(). Args: id: A string or integer key ID. parent: Optional parent key of the model to get. namespace: Optional namespace. app: Optional app ID. **ctx_options: Context options. ...
ndb/model.py
def _get_by_id(cls, id, parent=None, **ctx_options): """Returns an instance of Model class by ID. This is really just a shorthand for Key(cls, id, ...).get(). Args: id: A string or integer key ID. parent: Optional parent key of the model to get. namespace: Optional namespace. app: ...
def _get_by_id(cls, id, parent=None, **ctx_options): """Returns an instance of Model class by ID. This is really just a shorthand for Key(cls, id, ...).get(). Args: id: A string or integer key ID. parent: Optional parent key of the model to get. namespace: Optional namespace. app: ...
[ "Returns", "an", "instance", "of", "Model", "class", "by", "ID", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3594-L3609
[ "def", "_get_by_id", "(", "cls", ",", "id", ",", "parent", "=", "None", ",", "*", "*", "ctx_options", ")", ":", "return", "cls", ".", "_get_by_id_async", "(", "id", ",", "parent", "=", "parent", ",", "*", "*", "ctx_options", ")", ".", "get_result", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._get_by_id_async
Returns an instance of Model class by ID (and app, namespace). This is the asynchronous version of Model._get_by_id().
ndb/model.py
def _get_by_id_async(cls, id, parent=None, app=None, namespace=None, **ctx_options): """Returns an instance of Model class by ID (and app, namespace). This is the asynchronous version of Model._get_by_id(). """ key = Key(cls._get_kind(), id, parent=parent, app=app, namespace=name...
def _get_by_id_async(cls, id, parent=None, app=None, namespace=None, **ctx_options): """Returns an instance of Model class by ID (and app, namespace). This is the asynchronous version of Model._get_by_id(). """ key = Key(cls._get_kind(), id, parent=parent, app=app, namespace=name...
[ "Returns", "an", "instance", "of", "Model", "class", "by", "ID", "(", "and", "app", "namespace", ")", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3614-L3621
[ "def", "_get_by_id_async", "(", "cls", ",", "id", ",", "parent", "=", "None", ",", "app", "=", "None", ",", "namespace", "=", "None", ",", "*", "*", "ctx_options", ")", ":", "key", "=", "Key", "(", "cls", ".", "_get_kind", "(", ")", ",", "id", ",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Model._is_default_hook
Checks whether a specific hook is in its default state. Args: cls: A ndb.model.Model class. default_hook: Callable specified by ndb internally (do not override). hook: The hook defined by a model class using _post_*_hook. Raises: TypeError if either the default hook or the tested hook ...
ndb/model.py
def _is_default_hook(default_hook, hook): """Checks whether a specific hook is in its default state. Args: cls: A ndb.model.Model class. default_hook: Callable specified by ndb internally (do not override). hook: The hook defined by a model class using _post_*_hook. Raises: TypeErr...
def _is_default_hook(default_hook, hook): """Checks whether a specific hook is in its default state. Args: cls: A ndb.model.Model class. default_hook: Callable specified by ndb internally (do not override). hook: The hook defined by a model class using _post_*_hook. Raises: TypeErr...
[ "Checks", "whether", "a", "specific", "hook", "is", "in", "its", "default", "state", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3676-L3691
[ "def", "_is_default_hook", "(", "default_hook", ",", "hook", ")", ":", "if", "not", "hasattr", "(", "default_hook", ",", "'__call__'", ")", ":", "raise", "TypeError", "(", "'Default hooks for ndb.model.Model must be callable'", ")", "if", "not", "hasattr", "(", "h...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_ConstructReference
Construct a Reference; the signature is the same as for Key.
ndb/key.py
def _ConstructReference(cls, pairs=None, flat=None, reference=None, serialized=None, urlsafe=None, app=None, namespace=None, parent=None): """Construct a Reference; the signature is the same as for Key.""" if cls is not Key: raise TypeError('Cannot construct Key r...
def _ConstructReference(cls, pairs=None, flat=None, reference=None, serialized=None, urlsafe=None, app=None, namespace=None, parent=None): """Construct a Reference; the signature is the same as for Key.""" if cls is not Key: raise TypeError('Cannot construct Key r...
[ "Construct", "a", "Reference", ";", "the", "signature", "is", "the", "same", "as", "for", "Key", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L633-L704
[ "def", "_ConstructReference", "(", "cls", ",", "pairs", "=", "None", ",", "flat", "=", "None", ",", "reference", "=", "None", ",", "serialized", "=", "None", ",", "urlsafe", "=", "None", ",", "app", "=", "None", ",", "namespace", "=", "None", ",", "p...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_ReferenceFromPairs
Construct a Reference from a list of pairs. If a Reference is passed in as the second argument, it is modified in place. The app and namespace are set from the corresponding keyword arguments, with the customary defaults.
ndb/key.py
def _ReferenceFromPairs(pairs, reference=None, app=None, namespace=None): """Construct a Reference from a list of pairs. If a Reference is passed in as the second argument, it is modified in place. The app and namespace are set from the corresponding keyword arguments, with the customary defaults. """ if ...
def _ReferenceFromPairs(pairs, reference=None, app=None, namespace=None): """Construct a Reference from a list of pairs. If a Reference is passed in as the second argument, it is modified in place. The app and namespace are set from the corresponding keyword arguments, with the customary defaults. """ if ...
[ "Construct", "a", "Reference", "from", "a", "list", "of", "pairs", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L707-L805
[ "def", "_ReferenceFromPairs", "(", "pairs", ",", "reference", "=", "None", ",", "app", "=", "None", ",", "namespace", "=", "None", ")", ":", "if", "reference", "is", "None", ":", "reference", "=", "entity_pb", ".", "Reference", "(", ")", "path", "=", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_ReferenceFromSerialized
Construct a Reference from a serialized Reference.
ndb/key.py
def _ReferenceFromSerialized(serialized): """Construct a Reference from a serialized Reference.""" if not isinstance(serialized, basestring): raise TypeError('serialized must be a string; received %r' % serialized) elif isinstance(serialized, unicode): serialized = serialized.encode('utf8') return entit...
def _ReferenceFromSerialized(serialized): """Construct a Reference from a serialized Reference.""" if not isinstance(serialized, basestring): raise TypeError('serialized must be a string; received %r' % serialized) elif isinstance(serialized, unicode): serialized = serialized.encode('utf8') return entit...
[ "Construct", "a", "Reference", "from", "a", "serialized", "Reference", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L815-L821
[ "def", "_ReferenceFromSerialized", "(", "serialized", ")", ":", "if", "not", "isinstance", "(", "serialized", ",", "basestring", ")", ":", "raise", "TypeError", "(", "'serialized must be a string; received %r'", "%", "serialized", ")", "elif", "isinstance", "(", "se...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_DecodeUrlSafe
Decode a url-safe base64-encoded string. This returns the decoded string.
ndb/key.py
def _DecodeUrlSafe(urlsafe): """Decode a url-safe base64-encoded string. This returns the decoded string. """ if not isinstance(urlsafe, basestring): raise TypeError('urlsafe must be a string; received %r' % urlsafe) if isinstance(urlsafe, unicode): urlsafe = urlsafe.encode('utf8') mod = len(urlsaf...
def _DecodeUrlSafe(urlsafe): """Decode a url-safe base64-encoded string. This returns the decoded string. """ if not isinstance(urlsafe, basestring): raise TypeError('urlsafe must be a string; received %r' % urlsafe) if isinstance(urlsafe, unicode): urlsafe = urlsafe.encode('utf8') mod = len(urlsaf...
[ "Decode", "a", "url", "-", "safe", "base64", "-", "encoded", "string", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L824-L837
[ "def", "_DecodeUrlSafe", "(", "urlsafe", ")", ":", "if", "not", "isinstance", "(", "urlsafe", ",", "basestring", ")", ":", "raise", "TypeError", "(", "'urlsafe must be a string; received %r'", "%", "urlsafe", ")", "if", "isinstance", "(", "urlsafe", ",", "unicod...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key._parse_from_ref
Construct a Reference; the signature is the same as for Key.
ndb/key.py
def _parse_from_ref(cls, pairs=None, flat=None, reference=None, serialized=None, urlsafe=None, app=None, namespace=None, parent=None): """Construct a Reference; the signature is the same as for Key.""" if cls is not Key: raise TypeError('Cannot construct Key ref...
def _parse_from_ref(cls, pairs=None, flat=None, reference=None, serialized=None, urlsafe=None, app=None, namespace=None, parent=None): """Construct a Reference; the signature is the same as for Key.""" if cls is not Key: raise TypeError('Cannot construct Key ref...
[ "Construct", "a", "Reference", ";", "the", "signature", "is", "the", "same", "as", "for", "Key", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L304-L353
[ "def", "_parse_from_ref", "(", "cls", ",", "pairs", "=", "None", ",", "flat", "=", "None", ",", "reference", "=", "None", ",", "serialized", "=", "None", ",", "urlsafe", "=", "None", ",", "app", "=", "None", ",", "namespace", "=", "None", ",", "paren...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.parent
Return a Key constructed from all but the last (kind, id) pairs. If there is only one (kind, id) pair, return None.
ndb/key.py
def parent(self): """Return a Key constructed from all but the last (kind, id) pairs. If there is only one (kind, id) pair, return None. """ pairs = self.__pairs if len(pairs) <= 1: return None return Key(pairs=pairs[:-1], app=self.__app, namespace=self.__namespace)
def parent(self): """Return a Key constructed from all but the last (kind, id) pairs. If there is only one (kind, id) pair, return None. """ pairs = self.__pairs if len(pairs) <= 1: return None return Key(pairs=pairs[:-1], app=self.__app, namespace=self.__namespace)
[ "Return", "a", "Key", "constructed", "from", "all", "but", "the", "last", "(", "kind", "id", ")", "pairs", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L460-L468
[ "def", "parent", "(", "self", ")", ":", "pairs", "=", "self", ".", "__pairs", "if", "len", "(", "pairs", ")", "<=", "1", ":", "return", "None", "return", "Key", "(", "pairs", "=", "pairs", "[", ":", "-", "1", "]", ",", "app", "=", "self", ".", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.string_id
Return the string id in the last (kind, id) pair, if any. Returns: A string id, or None if the key has an integer id or is incomplete.
ndb/key.py
def string_id(self): """Return the string id in the last (kind, id) pair, if any. Returns: A string id, or None if the key has an integer id or is incomplete. """ id = self.id() if not isinstance(id, basestring): id = None return id
def string_id(self): """Return the string id in the last (kind, id) pair, if any. Returns: A string id, or None if the key has an integer id or is incomplete. """ id = self.id() if not isinstance(id, basestring): id = None return id
[ "Return", "the", "string", "id", "in", "the", "last", "(", "kind", "id", ")", "pair", "if", "any", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L493-L502
[ "def", "string_id", "(", "self", ")", ":", "id", "=", "self", ".", "id", "(", ")", "if", "not", "isinstance", "(", "id", ",", "basestring", ")", ":", "id", "=", "None", "return", "id" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.integer_id
Return the integer id in the last (kind, id) pair, if any. Returns: An integer id, or None if the key has a string id or is incomplete.
ndb/key.py
def integer_id(self): """Return the integer id in the last (kind, id) pair, if any. Returns: An integer id, or None if the key has a string id or is incomplete. """ id = self.id() if not isinstance(id, (int, long)): id = None return id
def integer_id(self): """Return the integer id in the last (kind, id) pair, if any. Returns: An integer id, or None if the key has a string id or is incomplete. """ id = self.id() if not isinstance(id, (int, long)): id = None return id
[ "Return", "the", "integer", "id", "in", "the", "last", "(", "kind", "id", ")", "pair", "if", "any", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L504-L513
[ "def", "integer_id", "(", "self", ")", ":", "id", "=", "self", ".", "id", "(", ")", "if", "not", "isinstance", "(", "id", ",", "(", "int", ",", "long", ")", ")", ":", "id", "=", "None", "return", "id" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.flat
Return a tuple of alternating kind and id values.
ndb/key.py
def flat(self): """Return a tuple of alternating kind and id values.""" flat = [] for kind, id in self.__pairs: flat.append(kind) flat.append(id) return tuple(flat)
def flat(self): """Return a tuple of alternating kind and id values.""" flat = [] for kind, id in self.__pairs: flat.append(kind) flat.append(id) return tuple(flat)
[ "Return", "a", "tuple", "of", "alternating", "kind", "and", "id", "values", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L519-L525
[ "def", "flat", "(", "self", ")", ":", "flat", "=", "[", "]", "for", "kind", ",", "id", "in", "self", ".", "__pairs", ":", "flat", ".", "append", "(", "kind", ")", "flat", ".", "append", "(", "id", ")", "return", "tuple", "(", "flat", ")" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.reference
Return the Reference object for this Key. This is a entity_pb.Reference instance -- a protocol buffer class used by the lower-level API to the datastore. NOTE: The caller should not mutate the return value.
ndb/key.py
def reference(self): """Return the Reference object for this Key. This is a entity_pb.Reference instance -- a protocol buffer class used by the lower-level API to the datastore. NOTE: The caller should not mutate the return value. """ if self.__reference is None: self.__reference = _Cons...
def reference(self): """Return the Reference object for this Key. This is a entity_pb.Reference instance -- a protocol buffer class used by the lower-level API to the datastore. NOTE: The caller should not mutate the return value. """ if self.__reference is None: self.__reference = _Cons...
[ "Return", "the", "Reference", "object", "for", "this", "Key", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L534-L547
[ "def", "reference", "(", "self", ")", ":", "if", "self", ".", "__reference", "is", "None", ":", "self", ".", "__reference", "=", "_ConstructReference", "(", "self", ".", "__class__", ",", "pairs", "=", "self", ".", "__pairs", ",", "app", "=", "self", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.urlsafe
Return a url-safe string encoding this Key's Reference. This string is compatible with other APIs and languages and with the strings used to represent Keys in GQL and in the App Engine Admin Console.
ndb/key.py
def urlsafe(self): """Return a url-safe string encoding this Key's Reference. This string is compatible with other APIs and languages and with the strings used to represent Keys in GQL and in the App Engine Admin Console. """ # This is 3-4x faster than urlsafe_b64decode() urlsafe = base64.b...
def urlsafe(self): """Return a url-safe string encoding this Key's Reference. This string is compatible with other APIs and languages and with the strings used to represent Keys in GQL and in the App Engine Admin Console. """ # This is 3-4x faster than urlsafe_b64decode() urlsafe = base64.b...
[ "Return", "a", "url", "-", "safe", "string", "encoding", "this", "Key", "s", "Reference", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L553-L562
[ "def", "urlsafe", "(", "self", ")", ":", "# This is 3-4x faster than urlsafe_b64decode()", "urlsafe", "=", "base64", ".", "b64encode", "(", "self", ".", "reference", "(", ")", ".", "Encode", "(", ")", ")", "return", "urlsafe", ".", "rstrip", "(", "'='", ")",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.get_async
Return a Future whose result is the entity for this Key. If no such entity exists, a Future is still returned, and the Future's eventual return result be None.
ndb/key.py
def get_async(self, **ctx_options): """Return a Future whose result is the entity for this Key. If no such entity exists, a Future is still returned, and the Future's eventual return result be None. """ from . import model, tasklets ctx = tasklets.get_context() cls = model.Model._kind_map.g...
def get_async(self, **ctx_options): """Return a Future whose result is the entity for this Key. If no such entity exists, a Future is still returned, and the Future's eventual return result be None. """ from . import model, tasklets ctx = tasklets.get_context() cls = model.Model._kind_map.g...
[ "Return", "a", "Future", "whose", "result", "is", "the", "entity", "for", "this", "Key", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L574-L591
[ "def", "get_async", "(", "self", ",", "*", "*", "ctx_options", ")", ":", "from", ".", "import", "model", ",", "tasklets", "ctx", "=", "tasklets", ".", "get_context", "(", ")", "cls", "=", "model", ".", "Model", ".", "_kind_map", ".", "get", "(", "sel...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
Key.delete_async
Schedule deletion of the entity for this Key. This returns a Future, whose result becomes available once the deletion is complete. If no such entity exists, a Future is still returned. In all cases the Future's result is None (i.e. there is no way to tell whether the entity existed or not).
ndb/key.py
def delete_async(self, **ctx_options): """Schedule deletion of the entity for this Key. This returns a Future, whose result becomes available once the deletion is complete. If no such entity exists, a Future is still returned. In all cases the Future's result is None (i.e. there is no way to tell...
def delete_async(self, **ctx_options): """Schedule deletion of the entity for this Key. This returns a Future, whose result becomes available once the deletion is complete. If no such entity exists, a Future is still returned. In all cases the Future's result is None (i.e. there is no way to tell...
[ "Schedule", "deletion", "of", "the", "entity", "for", "this", "Key", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L600-L619
[ "def", "delete_async", "(", "self", ",", "*", "*", "ctx_options", ")", ":", "from", ".", "import", "tasklets", ",", "model", "ctx", "=", "tasklets", ".", "get_context", "(", ")", "cls", "=", "model", ".", "Model", ".", "_kind_map", ".", "get", "(", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
add_flow_exception
Add an exception that should not be logged. The argument must be a subclass of Exception.
ndb/tasklets.py
def add_flow_exception(exc): """Add an exception that should not be logged. The argument must be a subclass of Exception. """ global _flow_exceptions if not isinstance(exc, type) or not issubclass(exc, Exception): raise TypeError('Expected an Exception subclass, got %r' % (exc,)) as_set = set(_flow_exc...
def add_flow_exception(exc): """Add an exception that should not be logged. The argument must be a subclass of Exception. """ global _flow_exceptions if not isinstance(exc, type) or not issubclass(exc, Exception): raise TypeError('Expected an Exception subclass, got %r' % (exc,)) as_set = set(_flow_exc...
[ "Add", "an", "exception", "that", "should", "not", "be", "logged", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L201-L211
[ "def", "add_flow_exception", "(", "exc", ")", ":", "global", "_flow_exceptions", "if", "not", "isinstance", "(", "exc", ",", "type", ")", "or", "not", "issubclass", "(", "exc", ",", "Exception", ")", ":", "raise", "TypeError", "(", "'Expected an Exception subc...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_init_flow_exceptions
Internal helper to initialize _flow_exceptions. This automatically adds webob.exc.HTTPException, if it can be imported.
ndb/tasklets.py
def _init_flow_exceptions(): """Internal helper to initialize _flow_exceptions. This automatically adds webob.exc.HTTPException, if it can be imported. """ global _flow_exceptions _flow_exceptions = () add_flow_exception(datastore_errors.Rollback) try: from webob import exc except ImportError: ...
def _init_flow_exceptions(): """Internal helper to initialize _flow_exceptions. This automatically adds webob.exc.HTTPException, if it can be imported. """ global _flow_exceptions _flow_exceptions = () add_flow_exception(datastore_errors.Rollback) try: from webob import exc except ImportError: ...
[ "Internal", "helper", "to", "initialize", "_flow_exceptions", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L214-L227
[ "def", "_init_flow_exceptions", "(", ")", ":", "global", "_flow_exceptions", "_flow_exceptions", "=", "(", ")", "add_flow_exception", "(", "datastore_errors", ".", "Rollback", ")", "try", ":", "from", "webob", "import", "exc", "except", "ImportError", ":", "pass",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
sleep
Public function to sleep some time. Example: yield tasklets.sleep(0.5) # Sleep for half a sec.
ndb/tasklets.py
def sleep(dt): """Public function to sleep some time. Example: yield tasklets.sleep(0.5) # Sleep for half a sec. """ fut = Future('sleep(%.3f)' % dt) eventloop.queue_call(dt, fut.set_result, None) return fut
def sleep(dt): """Public function to sleep some time. Example: yield tasklets.sleep(0.5) # Sleep for half a sec. """ fut = Future('sleep(%.3f)' % dt) eventloop.queue_call(dt, fut.set_result, None) return fut
[ "Public", "function", "to", "sleep", "some", "time", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L536-L544
[ "def", "sleep", "(", "dt", ")", ":", "fut", "=", "Future", "(", "'sleep(%.3f)'", "%", "dt", ")", "eventloop", ".", "queue_call", "(", "dt", ",", "fut", ".", "set_result", ",", "None", ")", "return", "fut" ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_transfer_result
Helper to transfer result or errors from one Future to another.
ndb/tasklets.py
def _transfer_result(fut1, fut2): """Helper to transfer result or errors from one Future to another.""" exc = fut1.get_exception() if exc is not None: tb = fut1.get_traceback() fut2.set_exception(exc, tb) else: val = fut1.get_result() fut2.set_result(val)
def _transfer_result(fut1, fut2): """Helper to transfer result or errors from one Future to another.""" exc = fut1.get_exception() if exc is not None: tb = fut1.get_traceback() fut2.set_exception(exc, tb) else: val = fut1.get_result() fut2.set_result(val)
[ "Helper", "to", "transfer", "result", "or", "errors", "from", "one", "Future", "to", "another", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L897-L905
[ "def", "_transfer_result", "(", "fut1", ",", "fut2", ")", ":", "exc", "=", "fut1", ".", "get_exception", "(", ")", "if", "exc", "is", "not", "None", ":", "tb", "=", "fut1", ".", "get_traceback", "(", ")", "fut2", ".", "set_exception", "(", "exc", ","...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
synctasklet
Decorator to run a function as a tasklet when called. Use this to wrap a request handler function that will be called by some web application framework (e.g. a Django view function or a webapp.RequestHandler.get method).
ndb/tasklets.py
def synctasklet(func): """Decorator to run a function as a tasklet when called. Use this to wrap a request handler function that will be called by some web application framework (e.g. a Django view function or a webapp.RequestHandler.get method). """ taskletfunc = tasklet(func) # wrap at declaration time....
def synctasklet(func): """Decorator to run a function as a tasklet when called. Use this to wrap a request handler function that will be called by some web application framework (e.g. a Django view function or a webapp.RequestHandler.get method). """ taskletfunc = tasklet(func) # wrap at declaration time....
[ "Decorator", "to", "run", "a", "function", "as", "a", "tasklet", "when", "called", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L1074-L1088
[ "def", "synctasklet", "(", "func", ")", ":", "taskletfunc", "=", "tasklet", "(", "func", ")", "# wrap at declaration time.", "@", "utils", ".", "wrapping", "(", "func", ")", "def", "synctasklet_wrapper", "(", "*", "args", ",", "*", "*", "kwds", ")", ":", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
toplevel
A sync tasklet that sets a fresh default Context. Use this for toplevel view functions such as webapp.RequestHandler.get() or Django view functions.
ndb/tasklets.py
def toplevel(func): """A sync tasklet that sets a fresh default Context. Use this for toplevel view functions such as webapp.RequestHandler.get() or Django view functions. """ synctaskletfunc = synctasklet(func) # wrap at declaration time. @utils.wrapping(func) def add_context_wrapper(*args, **kwds): ...
def toplevel(func): """A sync tasklet that sets a fresh default Context. Use this for toplevel view functions such as webapp.RequestHandler.get() or Django view functions. """ synctaskletfunc = synctasklet(func) # wrap at declaration time. @utils.wrapping(func) def add_context_wrapper(*args, **kwds): ...
[ "A", "sync", "tasklet", "that", "sets", "a", "fresh", "default", "Context", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L1091-L1113
[ "def", "toplevel", "(", "func", ")", ":", "synctaskletfunc", "=", "synctasklet", "(", "func", ")", "# wrap at declaration time.", "@", "utils", ".", "wrapping", "(", "func", ")", "def", "add_context_wrapper", "(", "*", "args", ",", "*", "*", "kwds", ")", "...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_make_cloud_datastore_context
Creates a new context to connect to a remote Cloud Datastore instance. This should only be used outside of Google App Engine. Args: app_id: The application id to connect to. This differs from the project id as it may have an additional prefix, e.g. "s~" or "e~". external_app_ids: A list of apps that...
ndb/tasklets.py
def _make_cloud_datastore_context(app_id, external_app_ids=()): """Creates a new context to connect to a remote Cloud Datastore instance. This should only be used outside of Google App Engine. Args: app_id: The application id to connect to. This differs from the project id as it may have an additional...
def _make_cloud_datastore_context(app_id, external_app_ids=()): """Creates a new context to connect to a remote Cloud Datastore instance. This should only be used outside of Google App Engine. Args: app_id: The application id to connect to. This differs from the project id as it may have an additional...
[ "Creates", "a", "new", "context", "to", "connect", "to", "a", "remote", "Cloud", "Datastore", "instance", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L1183-L1249
[ "def", "_make_cloud_datastore_context", "(", "app_id", ",", "external_app_ids", "=", "(", ")", ")", ":", "from", ".", "import", "model", "# Late import to deal with circular imports.", "# Late import since it might not exist.", "if", "not", "datastore_pbs", ".", "_CLOUD_DAT...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_analyze_indexed_fields
Internal helper to check a list of indexed fields. Args: indexed_fields: A list of names, possibly dotted names. (A dotted name is a string containing names separated by dots, e.g. 'foo.bar.baz'. An undotted name is a string containing no dots, e.g. 'foo'.) Returns: A dict whose keys are undotted ...
ndb/msgprop.py
def _analyze_indexed_fields(indexed_fields): """Internal helper to check a list of indexed fields. Args: indexed_fields: A list of names, possibly dotted names. (A dotted name is a string containing names separated by dots, e.g. 'foo.bar.baz'. An undotted name is a string containing no dots, e.g. 'foo'...
def _analyze_indexed_fields(indexed_fields): """Internal helper to check a list of indexed fields. Args: indexed_fields: A list of names, possibly dotted names. (A dotted name is a string containing names separated by dots, e.g. 'foo.bar.baz'. An undotted name is a string containing no dots, e.g. 'foo'...
[ "Internal", "helper", "to", "check", "a", "list", "of", "indexed", "fields", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L201-L245
[ "def", "_analyze_indexed_fields", "(", "indexed_fields", ")", ":", "result", "=", "{", "}", "for", "field_name", "in", "indexed_fields", ":", "if", "not", "isinstance", "(", "field_name", ",", "basestring", ")", ":", "raise", "TypeError", "(", "'Field names must...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_make_model_class
Construct a Model subclass corresponding to a Message subclass. Args: message_type: A Message subclass. indexed_fields: A list of dotted and undotted field names. **props: Additional properties with which to seed the class. Returns: A Model subclass whose properties correspond to those fields of ...
ndb/msgprop.py
def _make_model_class(message_type, indexed_fields, **props): """Construct a Model subclass corresponding to a Message subclass. Args: message_type: A Message subclass. indexed_fields: A list of dotted and undotted field names. **props: Additional properties with which to seed the class. Returns: ...
def _make_model_class(message_type, indexed_fields, **props): """Construct a Model subclass corresponding to a Message subclass. Args: message_type: A Message subclass. indexed_fields: A list of dotted and undotted field names. **props: Additional properties with which to seed the class. Returns: ...
[ "Construct", "a", "Model", "subclass", "corresponding", "to", "a", "Message", "subclass", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L248-L299
[ "def", "_make_model_class", "(", "message_type", ",", "indexed_fields", ",", "*", "*", "props", ")", ":", "analyzed", "=", "_analyze_indexed_fields", "(", "indexed_fields", ")", "for", "field_name", ",", "sub_fields", "in", "analyzed", ".", "iteritems", "(", ")"...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_message_to_entity
Recursive helper for _to_base_type() to convert a message to an entity. Args: msg: A Message instance. modelclass: A Model subclass. Returns: An instance of modelclass.
ndb/msgprop.py
def _message_to_entity(msg, modelclass): """Recursive helper for _to_base_type() to convert a message to an entity. Args: msg: A Message instance. modelclass: A Model subclass. Returns: An instance of modelclass. """ ent = modelclass() for prop_name, prop in modelclass._properties.iteritems():...
def _message_to_entity(msg, modelclass): """Recursive helper for _to_base_type() to convert a message to an entity. Args: msg: A Message instance. modelclass: A Model subclass. Returns: An instance of modelclass. """ ent = modelclass() for prop_name, prop in modelclass._properties.iteritems():...
[ "Recursive", "helper", "for", "_to_base_type", "()", "to", "convert", "a", "message", "to", "an", "entity", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L396-L417
[ "def", "_message_to_entity", "(", "msg", ",", "modelclass", ")", ":", "ent", "=", "modelclass", "(", ")", "for", "prop_name", ",", "prop", "in", "modelclass", ".", "_properties", ".", "iteritems", "(", ")", ":", "if", "prop", ".", "_code_name", "==", "'b...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_projected_entity_to_message
Recursive helper for _from_base_type() to convert an entity to a message. Args: ent: A Model instance. message_type: A Message subclass. Returns: An instance of message_type.
ndb/msgprop.py
def _projected_entity_to_message(ent, message_type): """Recursive helper for _from_base_type() to convert an entity to a message. Args: ent: A Model instance. message_type: A Message subclass. Returns: An instance of message_type. """ msg = message_type() analyzed = _analyze_indexed_fields(ent...
def _projected_entity_to_message(ent, message_type): """Recursive helper for _from_base_type() to convert an entity to a message. Args: ent: A Model instance. message_type: A Message subclass. Returns: An instance of message_type. """ msg = message_type() analyzed = _analyze_indexed_fields(ent...
[ "Recursive", "helper", "for", "_from_base_type", "()", "to", "convert", "an", "entity", "to", "a", "message", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L420-L447
[ "def", "_projected_entity_to_message", "(", "ent", ",", "message_type", ")", ":", "msg", "=", "message_type", "(", ")", "analyzed", "=", "_analyze_indexed_fields", "(", "ent", ".", "_projection", ")", "for", "name", ",", "sublist", "in", "analyzed", ".", "iter...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
EnumProperty._validate
Validate an Enum value. Raises: TypeError if the value is not an instance of self._enum_type.
ndb/msgprop.py
def _validate(self, value): """Validate an Enum value. Raises: TypeError if the value is not an instance of self._enum_type. """ if not isinstance(value, self._enum_type): raise TypeError('Expected a %s instance, got %r instead' % (self._enum_type.__name__, value))
def _validate(self, value): """Validate an Enum value. Raises: TypeError if the value is not an instance of self._enum_type. """ if not isinstance(value, self._enum_type): raise TypeError('Expected a %s instance, got %r instead' % (self._enum_type.__name__, value))
[ "Validate", "an", "Enum", "value", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L182-L190
[ "def", "_validate", "(", "self", ",", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "self", ".", "_enum_type", ")", ":", "raise", "TypeError", "(", "'Expected a %s instance, got %r instead'", "%", "(", "self", ".", "_enum_type", ".", "__na...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
MessageProperty._validate
Validate an Enum value. Raises: TypeError if the value is not an instance of self._message_type.
ndb/msgprop.py
def _validate(self, msg): """Validate an Enum value. Raises: TypeError if the value is not an instance of self._message_type. """ if not isinstance(msg, self._message_type): raise TypeError('Expected a %s instance for %s property', self._message_type.__name__, ...
def _validate(self, msg): """Validate an Enum value. Raises: TypeError if the value is not an instance of self._message_type. """ if not isinstance(msg, self._message_type): raise TypeError('Expected a %s instance for %s property', self._message_type.__name__, ...
[ "Validate", "an", "Enum", "value", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L353-L362
[ "def", "_validate", "(", "self", ",", "msg", ")", ":", "if", "not", "isinstance", "(", "msg", ",", "self", ".", "_message_type", ")", ":", "raise", "TypeError", "(", "'Expected a %s instance for %s property'", ",", "self", ".", "_message_type", ".", "__name__"...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
MessageProperty._to_base_type
Convert a Message value to a Model instance (entity).
ndb/msgprop.py
def _to_base_type(self, msg): """Convert a Message value to a Model instance (entity).""" ent = _message_to_entity(msg, self._modelclass) ent.blob_ = self._protocol_impl.encode_message(msg) return ent
def _to_base_type(self, msg): """Convert a Message value to a Model instance (entity).""" ent = _message_to_entity(msg, self._modelclass) ent.blob_ = self._protocol_impl.encode_message(msg) return ent
[ "Convert", "a", "Message", "value", "to", "a", "Model", "instance", "(", "entity", ")", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L364-L368
[ "def", "_to_base_type", "(", "self", ",", "msg", ")", ":", "ent", "=", "_message_to_entity", "(", "msg", ",", "self", ".", "_modelclass", ")", "ent", ".", "blob_", "=", "self", ".", "_protocol_impl", ".", "encode_message", "(", "msg", ")", "return", "ent...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
MessageProperty._from_base_type
Convert a Model instance (entity) to a Message value.
ndb/msgprop.py
def _from_base_type(self, ent): """Convert a Model instance (entity) to a Message value.""" if ent._projection: # Projection query result. Reconstitute the message from the fields. return _projected_entity_to_message(ent, self._message_type) blob = ent.blob_ if blob is not None: prot...
def _from_base_type(self, ent): """Convert a Model instance (entity) to a Message value.""" if ent._projection: # Projection query result. Reconstitute the message from the fields. return _projected_entity_to_message(ent, self._message_type) blob = ent.blob_ if blob is not None: prot...
[ "Convert", "a", "Model", "instance", "(", "entity", ")", "to", "a", "Message", "value", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L370-L393
[ "def", "_from_base_type", "(", "self", ",", "ent", ")", ":", "if", "ent", ".", "_projection", ":", "# Projection query result. Reconstitute the message from the fields.", "return", "_projected_entity_to_message", "(", "ent", ",", "self", ".", "_message_type", ")", "blo...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
_ClassKeyProperty._get_value
Compute and store a default value if necessary.
ndb/polymodel.py
def _get_value(self, entity): """Compute and store a default value if necessary.""" value = super(_ClassKeyProperty, self)._get_value(entity) if not value: value = entity._class_key() self._store_value(entity, value) return value
def _get_value(self, entity): """Compute and store a default value if necessary.""" value = super(_ClassKeyProperty, self)._get_value(entity) if not value: value = entity._class_key() self._store_value(entity, value) return value
[ "Compute", "and", "store", "a", "default", "value", "if", "necessary", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L74-L80
[ "def", "_get_value", "(", "self", ",", "entity", ")", ":", "value", "=", "super", "(", "_ClassKeyProperty", ",", "self", ")", ".", "_get_value", "(", "entity", ")", "if", "not", "value", ":", "value", "=", "entity", ".", "_class_key", "(", ")", "self",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
PolyModel._update_kind_map
Override; called by Model._fix_up_properties(). Update the kind map as well as the class map, except for PolyModel itself (its class key is empty). Note that the kind map will contain entries for all classes in a PolyModel hierarchy; they all have the same kind, but different class names. PolyModel c...
ndb/polymodel.py
def _update_kind_map(cls): """Override; called by Model._fix_up_properties(). Update the kind map as well as the class map, except for PolyModel itself (its class key is empty). Note that the kind map will contain entries for all classes in a PolyModel hierarchy; they all have the same kind, but d...
def _update_kind_map(cls): """Override; called by Model._fix_up_properties(). Update the kind map as well as the class map, except for PolyModel itself (its class key is empty). Note that the kind map will contain entries for all classes in a PolyModel hierarchy; they all have the same kind, but d...
[ "Override", ";", "called", "by", "Model", ".", "_fix_up_properties", "()", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L168-L180
[ "def", "_update_kind_map", "(", "cls", ")", ":", "cls", ".", "_kind_map", "[", "cls", ".", "_class_name", "(", ")", "]", "=", "cls", "class_key", "=", "cls", ".", "_class_key", "(", ")", "if", "class_key", ":", "cls", ".", "_class_map", "[", "tuple", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
PolyModel._from_pb
Override. Use the class map to give the entity the correct subclass.
ndb/polymodel.py
def _from_pb(cls, pb, set_key=True, ent=None, key=None): """Override. Use the class map to give the entity the correct subclass. """ prop_name = cls.class_._name class_name = [] for plist in [pb.property_list(), pb.raw_property_list()]: for p in plist: if p.name() == prop_name: ...
def _from_pb(cls, pb, set_key=True, ent=None, key=None): """Override. Use the class map to give the entity the correct subclass. """ prop_name = cls.class_._name class_name = [] for plist in [pb.property_list(), pb.raw_property_list()]: for p in plist: if p.name() == prop_name: ...
[ "Override", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L183-L195
[ "def", "_from_pb", "(", "cls", ",", "pb", ",", "set_key", "=", "True", ",", "ent", "=", "None", ",", "key", "=", "None", ")", ":", "prop_name", "=", "cls", ".", "class_", ".", "_name", "class_name", "=", "[", "]", "for", "plist", "in", "[", "pb",...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
PolyModel._get_kind
Override. Make sure that the kind returned is the root class of the polymorphic hierarchy.
ndb/polymodel.py
def _get_kind(cls): """Override. Make sure that the kind returned is the root class of the polymorphic hierarchy. """ bases = cls._get_hierarchy() if not bases: # We have to jump through some hoops to call the superclass' # _get_kind() method. First, this is called by the metaclass...
def _get_kind(cls): """Override. Make sure that the kind returned is the root class of the polymorphic hierarchy. """ bases = cls._get_hierarchy() if not bases: # We have to jump through some hoops to call the superclass' # _get_kind() method. First, this is called by the metaclass...
[ "Override", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L206-L222
[ "def", "_get_kind", "(", "cls", ")", ":", "bases", "=", "cls", ".", "_get_hierarchy", "(", ")", "if", "not", "bases", ":", "# We have to jump through some hoops to call the superclass'", "# _get_kind() method. First, this is called by the metaclass", "# before the PolyModel na...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
PolyModel._get_hierarchy
Internal helper to return the list of polymorphic base classes. This returns a list of class objects, e.g. [Animal, Feline, Cat].
ndb/polymodel.py
def _get_hierarchy(cls): """Internal helper to return the list of polymorphic base classes. This returns a list of class objects, e.g. [Animal, Feline, Cat]. """ bases = [] for base in cls.mro(): # pragma: no branch if hasattr(base, '_get_hierarchy'): bases.append(base) del bases...
def _get_hierarchy(cls): """Internal helper to return the list of polymorphic base classes. This returns a list of class objects, e.g. [Animal, Feline, Cat]. """ bases = [] for base in cls.mro(): # pragma: no branch if hasattr(base, '_get_hierarchy'): bases.append(base) del bases...
[ "Internal", "helper", "to", "return", "the", "list", "of", "polymorphic", "base", "classes", "." ]
GoogleCloudPlatform/datastore-ndb-python
python
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L242-L253
[ "def", "_get_hierarchy", "(", "cls", ")", ":", "bases", "=", "[", "]", "for", "base", "in", "cls", ".", "mro", "(", ")", ":", "# pragma: no branch", "if", "hasattr", "(", "base", ",", "'_get_hierarchy'", ")", ":", "bases", ".", "append", "(", "base", ...
cf4cab3f1f69cd04e1a9229871be466b53729f3f
train
find_env_paths_in_basedirs
Returns all potential envs in a basedir
environment_kernels/envs_common.py
def find_env_paths_in_basedirs(base_dirs): """Returns all potential envs in a basedir""" # get potential env path in the base_dirs env_path = [] for base_dir in base_dirs: env_path.extend(glob.glob(os.path.join( os.path.expanduser(base_dir), '*', ''))) # self.log.info("Found the ...
def find_env_paths_in_basedirs(base_dirs): """Returns all potential envs in a basedir""" # get potential env path in the base_dirs env_path = [] for base_dir in base_dirs: env_path.extend(glob.glob(os.path.join( os.path.expanduser(base_dir), '*', ''))) # self.log.info("Found the ...
[ "Returns", "all", "potential", "envs", "in", "a", "basedir" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L12-L21
[ "def", "find_env_paths_in_basedirs", "(", "base_dirs", ")", ":", "# get potential env path in the base_dirs", "env_path", "=", "[", "]", "for", "base_dir", "in", "base_dirs", ":", "env_path", ".", "extend", "(", "glob", ".", "glob", "(", "os", ".", "path", ".", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
convert_to_env_data
Converts a list of paths to environments to env_data. env_data is a structure {name -> (ressourcedir, kernel spec)}
environment_kernels/envs_common.py
def convert_to_env_data(mgr, env_paths, validator_func, activate_func, name_template, display_name_template, name_prefix): """Converts a list of paths to environments to env_data. env_data is a structure {name -> (ressourcedir, kernel spec)} """ env_data = {} for venv_dir in...
def convert_to_env_data(mgr, env_paths, validator_func, activate_func, name_template, display_name_template, name_prefix): """Converts a list of paths to environments to env_data. env_data is a structure {name -> (ressourcedir, kernel spec)} """ env_data = {} for venv_dir in...
[ "Converts", "a", "list", "of", "paths", "to", "environments", "to", "env_data", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L24-L60
[ "def", "convert_to_env_data", "(", "mgr", ",", "env_paths", ",", "validator_func", ",", "activate_func", ",", "name_template", ",", "display_name_template", ",", "name_prefix", ")", ":", "env_data", "=", "{", "}", "for", "venv_dir", "in", "env_paths", ":", "venv...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
validate_IPykernel
Validates that this env contains an IPython kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir)
environment_kernels/envs_common.py
def validate_IPykernel(venv_dir): """Validates that this env contains an IPython kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ python_exe_name = find_exe(venv_dir, "python") if python_exe_name is None: python_exe_name = find_exe(venv_dir, "py...
def validate_IPykernel(venv_dir): """Validates that this env contains an IPython kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ python_exe_name = find_exe(venv_dir, "python") if python_exe_name is None: python_exe_name = find_exe(venv_dir, "py...
[ "Validates", "that", "this", "env", "contains", "an", "IPython", "kernel", "and", "returns", "info", "to", "start", "it" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L63-L93
[ "def", "validate_IPykernel", "(", "venv_dir", ")", ":", "python_exe_name", "=", "find_exe", "(", "venv_dir", ",", "\"python\"", ")", "if", "python_exe_name", "is", "None", ":", "python_exe_name", "=", "find_exe", "(", "venv_dir", ",", "\"python2\"", ")", "if", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
validate_IRkernel
Validates that this env contains an IRkernel kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir)
environment_kernels/envs_common.py
def validate_IRkernel(venv_dir): """Validates that this env contains an IRkernel kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ r_exe_name = find_exe(venv_dir, "R") if r_exe_name is None: return [], None, None # check if this is really an...
def validate_IRkernel(venv_dir): """Validates that this env contains an IRkernel kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ r_exe_name = find_exe(venv_dir, "R") if r_exe_name is None: return [], None, None # check if this is really an...
[ "Validates", "that", "this", "env", "contains", "an", "IRkernel", "kernel", "and", "returns", "info", "to", "start", "it" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L96-L121
[ "def", "validate_IRkernel", "(", "venv_dir", ")", ":", "r_exe_name", "=", "find_exe", "(", "venv_dir", ",", "\"R\"", ")", "if", "r_exe_name", "is", "None", ":", "return", "[", "]", ",", "None", ",", "None", "# check if this is really an IRkernel **kernel**", "im...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
find_exe
Finds a exe with that name in the environment path
environment_kernels/envs_common.py
def find_exe(env_dir, name): """Finds a exe with that name in the environment path""" if platform.system() == "Windows": name = name + ".exe" # find the binary exe_name = os.path.join(env_dir, name) if not os.path.exists(exe_name): exe_name = os.path.join(env_dir, "bin", name) ...
def find_exe(env_dir, name): """Finds a exe with that name in the environment path""" if platform.system() == "Windows": name = name + ".exe" # find the binary exe_name = os.path.join(env_dir, name) if not os.path.exists(exe_name): exe_name = os.path.join(env_dir, "bin", name) ...
[ "Finds", "a", "exe", "with", "that", "name", "in", "the", "environment", "path" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L124-L138
[ "def", "find_exe", "(", "env_dir", ",", "name", ")", ":", "if", "platform", ".", "system", "(", ")", "==", "\"Windows\"", ":", "name", "=", "name", "+", "\".exe\"", "# find the binary", "exe_name", "=", "os", ".", "path", ".", "join", "(", "env_dir", "...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
get_virtualenv_env_data
Finds kernel specs from virtualenv environments env_data is a structure {name -> (resourcedir, kernel spec)}
environment_kernels/envs_virtualenv.py
def get_virtualenv_env_data(mgr): """Finds kernel specs from virtualenv environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_virtualenv_envs: return {} mgr.log.debug("Looking for virtualenv environments in %s...", mgr.virtualenv_env_dirs) # fi...
def get_virtualenv_env_data(mgr): """Finds kernel specs from virtualenv environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_virtualenv_envs: return {} mgr.log.debug("Looking for virtualenv environments in %s...", mgr.virtualenv_env_dirs) # fi...
[ "Finds", "kernel", "specs", "from", "virtualenv", "environments" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_virtualenv.py#L12-L35
[ "def", "get_virtualenv_env_data", "(", "mgr", ")", ":", "if", "not", "mgr", ".", "find_virtualenv_envs", ":", "return", "{", "}", "mgr", ".", "log", ".", "debug", "(", "\"Looking for virtualenv environments in %s...\"", ",", "mgr", ".", "virtualenv_env_dirs", ")",...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
source_bash
Simply bash-specific wrapper around source-foreign Returns a dict to be used as a new environment
environment_kernels/activate_helper.py
def source_bash(args, stdin=None): """Simply bash-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['bash', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
def source_bash(args, stdin=None): """Simply bash-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['bash', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
[ "Simply", "bash", "-", "specific", "wrapper", "around", "source", "-", "foreign" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L66-L73
[ "def", "source_bash", "(", "args", ",", "stdin", "=", "None", ")", ":", "args", "=", "list", "(", "args", ")", "new_args", "=", "[", "'bash'", ",", "'--sourcer=source'", "]", "new_args", ".", "extend", "(", "args", ")", "return", "source_foreign", "(", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
source_zsh
Simply zsh-specific wrapper around source-foreign Returns a dict to be used as a new environment
environment_kernels/activate_helper.py
def source_zsh(args, stdin=None): """Simply zsh-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['zsh', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
def source_zsh(args, stdin=None): """Simply zsh-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['zsh', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
[ "Simply", "zsh", "-", "specific", "wrapper", "around", "source", "-", "foreign" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L75-L82
[ "def", "source_zsh", "(", "args", ",", "stdin", "=", "None", ")", ":", "args", "=", "list", "(", "args", ")", "new_args", "=", "[", "'zsh'", ",", "'--sourcer=source'", "]", "new_args", ".", "extend", "(", "args", ")", "return", "source_foreign", "(", "...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
source_cmd
Simple cmd.exe-specific wrapper around source-foreign. returns a dict to be used as a new environment
environment_kernels/activate_helper.py
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign. returns a dict to be used as a new environment """ args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): raise RuntimeError("C...
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign. returns a dict to be used as a new environment """ args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): raise RuntimeError("C...
[ "Simple", "cmd", ".", "exe", "-", "specific", "wrapper", "around", "source", "-", "foreign", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L85-L105
[ "def", "source_cmd", "(", "args", ",", "stdin", "=", "None", ")", ":", "args", "=", "list", "(", "args", ")", "fpath", "=", "locate_binary", "(", "args", "[", "0", "]", ")", "args", "[", "0", "]", "=", "fpath", "if", "fpath", "else", "args", "[",...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
argvquote
Returns an argument quoted in such a way that that CommandLineToArgvW on Windows will return the argument string unchanged. This is the same thing Popen does when supplied with an list of arguments. Arguments in a command line should be separated by spaces; this function does not add these spaces. This ...
environment_kernels/activate_helper.py
def argvquote(arg, force=False): """ Returns an argument quoted in such a way that that CommandLineToArgvW on Windows will return the argument string unchanged. This is the same thing Popen does when supplied with an list of arguments. Arguments in a command line should be separated by spaces; this ...
def argvquote(arg, force=False): """ Returns an argument quoted in such a way that that CommandLineToArgvW on Windows will return the argument string unchanged. This is the same thing Popen does when supplied with an list of arguments. Arguments in a command line should be separated by spaces; this ...
[ "Returns", "an", "argument", "quoted", "in", "such", "a", "way", "that", "that", "CommandLineToArgvW", "on", "Windows", "will", "return", "the", "argument", "string", "unchanged", ".", "This", "is", "the", "same", "thing", "Popen", "does", "when", "supplied", ...
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L124-L155
[ "def", "argvquote", "(", "arg", ",", "force", "=", "False", ")", ":", "if", "not", "force", "and", "len", "(", "arg", ")", "!=", "0", "and", "not", "any", "(", "[", "c", "in", "arg", "for", "c", "in", "' \\t\\n\\v\"'", "]", ")", ":", "return", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
escape_windows_cmd_string
Returns a string that is usable by the Windows cmd.exe. The escaping is based on details here and emperical testing: http://www.robvanderwoude.com/escapechars.php
environment_kernels/activate_helper.py
def escape_windows_cmd_string(s): """Returns a string that is usable by the Windows cmd.exe. The escaping is based on details here and emperical testing: http://www.robvanderwoude.com/escapechars.php """ for c in '()%!^<>&|"': s = s.replace(c, '^' + c) s = s.replace('/?', '/.') retur...
def escape_windows_cmd_string(s): """Returns a string that is usable by the Windows cmd.exe. The escaping is based on details here and emperical testing: http://www.robvanderwoude.com/escapechars.php """ for c in '()%!^<>&|"': s = s.replace(c, '^' + c) s = s.replace('/?', '/.') retur...
[ "Returns", "a", "string", "that", "is", "usable", "by", "the", "Windows", "cmd", ".", "exe", ".", "The", "escaping", "is", "based", "on", "details", "here", "and", "emperical", "testing", ":", "http", ":", "//", "www", ".", "robvanderwoude", ".", "com", ...
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L158-L166
[ "def", "escape_windows_cmd_string", "(", "s", ")", ":", "for", "c", "in", "'()%!^<>&|\"'", ":", "s", "=", "s", ".", "replace", "(", "c", ",", "'^'", "+", "c", ")", "s", "=", "s", ".", "replace", "(", "'/?'", ",", "'/.'", ")", "return", "s" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
train
source_foreign
Sources a file written in a foreign shell language.
environment_kernels/activate_helper.py
def source_foreign(args, stdin=None): """Sources a file written in a foreign shell language.""" parser = _ensure_source_foreign_parser() ns = parser.parse_args(args) if ns.prevcmd is not None: pass # don't change prevcmd if given explicitly elif os.path.isfile(ns.files_or_code[0]): ...
def source_foreign(args, stdin=None): """Sources a file written in a foreign shell language.""" parser = _ensure_source_foreign_parser() ns = parser.parse_args(args) if ns.prevcmd is not None: pass # don't change prevcmd if given explicitly elif os.path.isfile(ns.files_or_code[0]): ...
[ "Sources", "a", "file", "written", "in", "a", "foreign", "shell", "language", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L169-L204
[ "def", "source_foreign", "(", "args", ",", "stdin", "=", "None", ")", ":", "parser", "=", "_ensure_source_foreign_parser", "(", ")", "ns", "=", "parser", ".", "parse_args", "(", "args", ")", "if", "ns", ".", "prevcmd", "is", "not", "None", ":", "pass", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
_is_executable_file
Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. This function was forked from pexpect originally: Copyright (c) 2013-2014, Pexpect development team Copyright (c) 2012, Noah Spurrier <noah@noah.org> PE...
environment_kernels/activate_helper.py
def _is_executable_file(path): """Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. This function was forked from pexpect originally: Copyright (c) 2013-2014, Pexpect development team Copyright (c) 2012,...
def _is_executable_file(path): """Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. This function was forked from pexpect originally: Copyright (c) 2013-2014, Pexpect development team Copyright (c) 2012,...
[ "Checks", "that", "path", "is", "an", "executable", "regular", "file", "or", "a", "symlink", "towards", "one", ".", "This", "is", "roughly", "os", ".", "path", "isfile", "(", "path", ")", "and", "os", ".", "access", "(", "path", "os", ".", "X_OK", ")...
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L244-L271
[ "def", "_is_executable_file", "(", "path", ")", ":", "# follow symlinks,", "fpath", "=", "os", ".", "path", ".", "realpath", "(", "path", ")", "if", "not", "os", ".", "path", ".", "isfile", "(", "fpath", ")", ":", "# non-files (directories, fifo, etc.)", "re...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
foreign_shell_data
Extracts data from a foreign (non-xonsh) shells. Currently this gets the environment, aliases, and functions but may be extended in the future. Parameters ---------- shell : str The name of the shell, such as 'bash' or '/bin/sh'. interactive : bool, optional Whether the shell should...
environment_kernels/activate_helper.py
def foreign_shell_data(shell, interactive=True, login=False, envcmd=None, aliascmd=None, extra_args=(), currenv=None, safe=False, prevcmd='', postcmd='', funcscmd=None, sourcer=None, use_tmpfile=False, tmpfile_ext=None, runcmd=N...
def foreign_shell_data(shell, interactive=True, login=False, envcmd=None, aliascmd=None, extra_args=(), currenv=None, safe=False, prevcmd='', postcmd='', funcscmd=None, sourcer=None, use_tmpfile=False, tmpfile_ext=None, runcmd=N...
[ "Extracts", "data", "from", "a", "foreign", "(", "non", "-", "xonsh", ")", "shells", ".", "Currently", "this", "gets", "the", "environment", "aliases", "and", "functions", "but", "may", "be", "extended", "in", "the", "future", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L328-L443
[ "def", "foreign_shell_data", "(", "shell", ",", "interactive", "=", "True", ",", "login", "=", "False", ",", "envcmd", "=", "None", ",", "aliascmd", "=", "None", ",", "extra_args", "=", "(", ")", ",", "currenv", "=", "None", ",", "safe", "=", "False", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
to_bool
Converts to a boolean in a semantically meaningful way.
environment_kernels/activate_helper.py
def to_bool(x): """"Converts to a boolean in a semantically meaningful way.""" if isinstance(x, bool): return x elif isinstance(x, str): return False if x.lower() in _FALSES else True else: return bool(x)
def to_bool(x): """"Converts to a boolean in a semantically meaningful way.""" if isinstance(x, bool): return x elif isinstance(x, str): return False if x.lower() in _FALSES else True else: return bool(x)
[ "Converts", "to", "a", "boolean", "in", "a", "semantically", "meaningful", "way", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L445-L452
[ "def", "to_bool", "(", "x", ")", ":", "if", "isinstance", "(", "x", ",", "bool", ")", ":", "return", "x", "elif", "isinstance", "(", "x", ",", "str", ")", ":", "return", "False", "if", "x", ".", "lower", "(", ")", "in", "_FALSES", "else", "True",...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
parse_env
Parses the environment portion of string into a dict.
environment_kernels/activate_helper.py
def parse_env(s): """Parses the environment portion of string into a dict.""" m = ENV_RE.search(s) if m is None: return {} g1 = m.group(1) env = dict(ENV_SPLIT_RE.findall(g1)) return env
def parse_env(s): """Parses the environment portion of string into a dict.""" m = ENV_RE.search(s) if m is None: return {} g1 = m.group(1) env = dict(ENV_SPLIT_RE.findall(g1)) return env
[ "Parses", "the", "environment", "portion", "of", "string", "into", "a", "dict", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L511-L518
[ "def", "parse_env", "(", "s", ")", ":", "m", "=", "ENV_RE", ".", "search", "(", "s", ")", "if", "m", "is", "None", ":", "return", "{", "}", "g1", "=", "m", ".", "group", "(", "1", ")", "env", "=", "dict", "(", "ENV_SPLIT_RE", ".", "findall", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
get_conda_env_data
Finds kernel specs from conda environments env_data is a structure {name -> (resourcedir, kernel spec)}
environment_kernels/envs_conda.py
def get_conda_env_data(mgr): """Finds kernel specs from conda environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_conda_envs: return {} mgr.log.debug("Looking for conda environments in %s...", mgr.conda_env_dirs) # find all potential env paths...
def get_conda_env_data(mgr): """Finds kernel specs from conda environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_conda_envs: return {} mgr.log.debug("Looking for conda environments in %s...", mgr.conda_env_dirs) # find all potential env paths...
[ "Finds", "kernel", "specs", "from", "conda", "environments" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_conda.py#L10-L42
[ "def", "get_conda_env_data", "(", "mgr", ")", ":", "if", "not", "mgr", ".", "find_conda_envs", ":", "return", "{", "}", "mgr", ".", "log", ".", "debug", "(", "\"Looking for conda environments in %s...\"", ",", "mgr", ".", "conda_env_dirs", ")", "# find all poten...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
_find_conda_env_paths_from_conda
Returns a list of path as given by `conda env list --json`. Returns empty list, if conda couldn't be called.
environment_kernels/envs_conda.py
def _find_conda_env_paths_from_conda(mgr): """Returns a list of path as given by `conda env list --json`. Returns empty list, if conda couldn't be called. """ # this is expensive, so make it configureable... if not mgr.use_conda_directly: return [] mgr.log.debug("Looking for conda envir...
def _find_conda_env_paths_from_conda(mgr): """Returns a list of path as given by `conda env list --json`. Returns empty list, if conda couldn't be called. """ # this is expensive, so make it configureable... if not mgr.use_conda_directly: return [] mgr.log.debug("Looking for conda envir...
[ "Returns", "a", "list", "of", "path", "as", "given", "by", "conda", "env", "list", "--", "json", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_conda.py#L62-L91
[ "def", "_find_conda_env_paths_from_conda", "(", "mgr", ")", ":", "# this is expensive, so make it configureable...", "if", "not", "mgr", ".", "use_conda_directly", ":", "return", "[", "]", "mgr", ".", "log", ".", "debug", "(", "\"Looking for conda environments by calling ...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
EnvironmentKernelSpecManager.validate_env
Check the name of the environment against the black list and the whitelist. If a whitelist is specified only it is checked.
environment_kernels/core.py
def validate_env(self, envname): """ Check the name of the environment against the black list and the whitelist. If a whitelist is specified only it is checked. """ if self.whitelist_envs and envname in self.whitelist_envs: return True elif self.whitelist_envs...
def validate_env(self, envname): """ Check the name of the environment against the black list and the whitelist. If a whitelist is specified only it is checked. """ if self.whitelist_envs and envname in self.whitelist_envs: return True elif self.whitelist_envs...
[ "Check", "the", "name", "of", "the", "environment", "against", "the", "black", "list", "and", "the", "whitelist", ".", "If", "a", "whitelist", "is", "specified", "only", "it", "is", "checked", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L128-L144
[ "def", "validate_env", "(", "self", ",", "envname", ")", ":", "if", "self", ".", "whitelist_envs", "and", "envname", "in", "self", ".", "whitelist_envs", ":", "return", "True", "elif", "self", ".", "whitelist_envs", ":", "return", "False", "if", "self", "....
3da304550b511bda7d5d39280379b5ca39bb31bc
train
EnvironmentKernelSpecManager._get_env_data
Get the data about the available environments. env_data is a structure {name -> (resourcedir, kernel spec)}
environment_kernels/core.py
def _get_env_data(self, reload=False): """Get the data about the available environments. env_data is a structure {name -> (resourcedir, kernel spec)} """ # This is called much too often and finding-process is really expensive :-( if not reload and getattr(self, "_env_data_cache...
def _get_env_data(self, reload=False): """Get the data about the available environments. env_data is a structure {name -> (resourcedir, kernel spec)} """ # This is called much too often and finding-process is really expensive :-( if not reload and getattr(self, "_env_data_cache...
[ "Get", "the", "data", "about", "the", "available", "environments", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L154-L174
[ "def", "_get_env_data", "(", "self", ",", "reload", "=", "False", ")", ":", "# This is called much too often and finding-process is really expensive :-(", "if", "not", "reload", "and", "getattr", "(", "self", ",", "\"_env_data_cache\"", ",", "{", "}", ")", ":", "ret...
3da304550b511bda7d5d39280379b5ca39bb31bc
train
EnvironmentKernelSpecManager.find_kernel_specs_for_envs
Returns a dict mapping kernel names to resource directories.
environment_kernels/core.py
def find_kernel_specs_for_envs(self): """Returns a dict mapping kernel names to resource directories.""" data = self._get_env_data() return {name: data[name][0] for name in data}
def find_kernel_specs_for_envs(self): """Returns a dict mapping kernel names to resource directories.""" data = self._get_env_data() return {name: data[name][0] for name in data}
[ "Returns", "a", "dict", "mapping", "kernel", "names", "to", "resource", "directories", "." ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L176-L179
[ "def", "find_kernel_specs_for_envs", "(", "self", ")", ":", "data", "=", "self", ".", "_get_env_data", "(", ")", "return", "{", "name", ":", "data", "[", "name", "]", "[", "0", "]", "for", "name", "in", "data", "}" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
train
EnvironmentKernelSpecManager.get_all_kernel_specs_for_envs
Returns the dict of name -> kernel_spec for all environments
environment_kernels/core.py
def get_all_kernel_specs_for_envs(self): """Returns the dict of name -> kernel_spec for all environments""" data = self._get_env_data() return {name: data[name][1] for name in data}
def get_all_kernel_specs_for_envs(self): """Returns the dict of name -> kernel_spec for all environments""" data = self._get_env_data() return {name: data[name][1] for name in data}
[ "Returns", "the", "dict", "of", "name", "-", ">", "kernel_spec", "for", "all", "environments" ]
Cadair/jupyter_environment_kernels
python
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L181-L185
[ "def", "get_all_kernel_specs_for_envs", "(", "self", ")", ":", "data", "=", "self", ".", "_get_env_data", "(", ")", "return", "{", "name", ":", "data", "[", "name", "]", "[", "1", "]", "for", "name", "in", "data", "}" ]
3da304550b511bda7d5d39280379b5ca39bb31bc