repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
_make_ctx_options
def _make_ctx_options(ctx_options, config_cls=ContextOptions): """Helper to construct a ContextOptions object from keyword arguments. Args: ctx_options: A dict of keyword arguments. config_cls: Optional Configuration class to use, default ContextOptions. Note that either 'options' or 'config' can be use...
python
def _make_ctx_options(ctx_options, config_cls=ContextOptions): """Helper to construct a ContextOptions object from keyword arguments. Args: ctx_options: A dict of keyword arguments. config_cls: Optional Configuration class to use, default ContextOptions. Note that either 'options' or 'config' can be use...
[ "def", "_make_ctx_options", "(", "ctx_options", ",", "config_cls", "=", "ContextOptions", ")", ":", "if", "not", "ctx_options", ":", "return", "None", "for", "key", "in", "list", "(", "ctx_options", ")", ":", "translation", "=", "_OPTION_TRANSLATIONS", ".", "g...
Helper to construct a ContextOptions object from keyword arguments. Args: ctx_options: A dict of keyword arguments. config_cls: Optional Configuration class to use, default ContextOptions. Note that either 'options' or 'config' can be used to pass another Configuration object, but not both. If another ...
[ "Helper", "to", "construct", "a", "ContextOptions", "object", "from", "keyword", "arguments", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L103-L126
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.set_cache_policy
def set_cache_policy(self, func): """Set the context cache policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None. """ if func is None: func = self.default_cache_policy elif isinstance(fu...
python
def set_cache_policy(self, func): """Set the context cache policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None. """ if func is None: func = self.default_cache_policy elif isinstance(fu...
[ "def", "set_cache_policy", "(", "self", ",", "func", ")", ":", "if", "func", "is", "None", ":", "func", "=", "self", ".", "default_cache_policy", "elif", "isinstance", "(", "func", ",", "bool", ")", ":", "func", "=", "lambda", "unused_key", ",", "flag", ...
Set the context cache policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None.
[ "Set", "the", "context", "cache", "policy", "function", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L281-L292
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context._use_cache
def _use_cache(self, key, options=None): """Return whether to use the context cache for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the key should be cached, False otherwise. """ flag = ContextOptions.use_cache(options) if fl...
python
def _use_cache(self, key, options=None): """Return whether to use the context cache for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the key should be cached, False otherwise. """ flag = ContextOptions.use_cache(options) if fl...
[ "def", "_use_cache", "(", "self", ",", "key", ",", "options", "=", "None", ")", ":", "flag", "=", "ContextOptions", ".", "use_cache", "(", "options", ")", "if", "flag", "is", "None", ":", "flag", "=", "self", ".", "_cache_policy", "(", "key", ")", "i...
Return whether to use the context cache for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the key should be cached, False otherwise.
[ "Return", "whether", "to", "use", "the", "context", "cache", "for", "this", "key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L294-L311
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.set_memcache_policy
def set_memcache_policy(self, func): """Set the memcache policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None. """ if func is None: func = self.default_memcache_policy elif isinstance(f...
python
def set_memcache_policy(self, func): """Set the memcache policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None. """ if func is None: func = self.default_memcache_policy elif isinstance(f...
[ "def", "set_memcache_policy", "(", "self", ",", "func", ")", ":", "if", "func", "is", "None", ":", "func", "=", "self", ".", "default_memcache_policy", "elif", "isinstance", "(", "func", ",", "bool", ")", ":", "func", "=", "lambda", "unused_key", ",", "f...
Set the memcache policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None.
[ "Set", "the", "memcache", "policy", "function", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L348-L359
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context._use_memcache
def _use_memcache(self, key, options=None): """Return whether to use memcache for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the key should be cached in memcache, False otherwise. """ flag = ContextOptions.use_memcache(options) ...
python
def _use_memcache(self, key, options=None): """Return whether to use memcache for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the key should be cached in memcache, False otherwise. """ flag = ContextOptions.use_memcache(options) ...
[ "def", "_use_memcache", "(", "self", ",", "key", ",", "options", "=", "None", ")", ":", "flag", "=", "ContextOptions", ".", "use_memcache", "(", "options", ")", "if", "flag", "is", "None", ":", "flag", "=", "self", ".", "_memcache_policy", "(", "key", ...
Return whether to use memcache for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the key should be cached in memcache, False otherwise.
[ "Return", "whether", "to", "use", "memcache", "for", "this", "key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L361-L378
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.default_datastore_policy
def default_datastore_policy(key): """Default datastore policy. This defers to _use_datastore on the Model class. Args: key: Key instance. Returns: A bool or None. """ flag = None if key is not None: modelclass = model.Model._kind_map.get(key.kind()) if modelclass ...
python
def default_datastore_policy(key): """Default datastore policy. This defers to _use_datastore on the Model class. Args: key: Key instance. Returns: A bool or None. """ flag = None if key is not None: modelclass = model.Model._kind_map.get(key.kind()) if modelclass ...
[ "def", "default_datastore_policy", "(", "key", ")", ":", "flag", "=", "None", "if", "key", "is", "not", "None", ":", "modelclass", "=", "model", ".", "Model", ".", "_kind_map", ".", "get", "(", "key", ".", "kind", "(", ")", ")", "if", "modelclass", "...
Default datastore policy. This defers to _use_datastore on the Model class. Args: key: Key instance. Returns: A bool or None.
[ "Default", "datastore", "policy", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L381-L402
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.set_datastore_policy
def set_datastore_policy(self, func): """Set the context datastore policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should use the datastore. May be None. """ if func is None: func = self.default_datastore_policy ...
python
def set_datastore_policy(self, func): """Set the context datastore policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should use the datastore. May be None. """ if func is None: func = self.default_datastore_policy ...
[ "def", "set_datastore_policy", "(", "self", ",", "func", ")", ":", "if", "func", "is", "None", ":", "func", "=", "self", ".", "default_datastore_policy", "elif", "isinstance", "(", "func", ",", "bool", ")", ":", "func", "=", "lambda", "unused_key", ",", ...
Set the context datastore policy function. Args: func: A function that accepts a Key instance as argument and returns a bool indicating if it should use the datastore. May be None.
[ "Set", "the", "context", "datastore", "policy", "function", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L415-L426
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context._use_datastore
def _use_datastore(self, key, options=None): """Return whether to use the datastore for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the datastore should be used, False otherwise. """ flag = ContextOptions.use_datastore(options) ...
python
def _use_datastore(self, key, options=None): """Return whether to use the datastore for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the datastore should be used, False otherwise. """ flag = ContextOptions.use_datastore(options) ...
[ "def", "_use_datastore", "(", "self", ",", "key", ",", "options", "=", "None", ")", ":", "flag", "=", "ContextOptions", ".", "use_datastore", "(", "options", ")", "if", "flag", "is", "None", ":", "flag", "=", "self", ".", "_datastore_policy", "(", "key",...
Return whether to use the datastore for this key. Args: key: Key instance. options: ContextOptions instance, or None. Returns: True if the datastore should be used, False otherwise.
[ "Return", "whether", "to", "use", "the", "datastore", "for", "this", "key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L428-L445
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.default_memcache_timeout_policy
def default_memcache_timeout_policy(key): """Default memcache timeout policy. This defers to _memcache_timeout on the Model class. Args: key: Key instance. Returns: Memcache timeout to use (integer), or None. """ timeout = None if key is not None and isinstance(key, model.Key)...
python
def default_memcache_timeout_policy(key): """Default memcache timeout policy. This defers to _memcache_timeout on the Model class. Args: key: Key instance. Returns: Memcache timeout to use (integer), or None. """ timeout = None if key is not None and isinstance(key, model.Key)...
[ "def", "default_memcache_timeout_policy", "(", "key", ")", ":", "timeout", "=", "None", "if", "key", "is", "not", "None", "and", "isinstance", "(", "key", ",", "model", ".", "Key", ")", ":", "modelclass", "=", "model", ".", "Model", ".", "_kind_map", "."...
Default memcache timeout policy. This defers to _memcache_timeout on the Model class. Args: key: Key instance. Returns: Memcache timeout to use (integer), or None.
[ "Default", "memcache", "timeout", "policy", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L448-L469
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.set_memcache_timeout_policy
def set_memcache_timeout_policy(self, func): """Set the policy function for memcache timeout (expiration). Args: func: A function that accepts a key instance as argument and returns an integer indicating the desired memcache timeout. May be None. If the function returns 0 it implies the def...
python
def set_memcache_timeout_policy(self, func): """Set the policy function for memcache timeout (expiration). Args: func: A function that accepts a key instance as argument and returns an integer indicating the desired memcache timeout. May be None. If the function returns 0 it implies the def...
[ "def", "set_memcache_timeout_policy", "(", "self", ",", "func", ")", ":", "if", "func", "is", "None", ":", "func", "=", "self", ".", "default_memcache_timeout_policy", "elif", "isinstance", "(", "func", ",", "(", "int", ",", "long", ")", ")", ":", "func", ...
Set the policy function for memcache timeout (expiration). Args: func: A function that accepts a key instance as argument and returns an integer indicating the desired memcache timeout. May be None. If the function returns 0 it implies the default timeout.
[ "Set", "the", "policy", "function", "for", "memcache", "timeout", "(", "expiration", ")", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L473-L486
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context._get_memcache_timeout
def _get_memcache_timeout(self, key, options=None): """Return the memcache timeout (expiration) for this key.""" timeout = ContextOptions.memcache_timeout(options) if timeout is None: timeout = self._memcache_timeout_policy(key) if timeout is None: timeout = ContextOptions.memcache_timeout(s...
python
def _get_memcache_timeout(self, key, options=None): """Return the memcache timeout (expiration) for this key.""" timeout = ContextOptions.memcache_timeout(options) if timeout is None: timeout = self._memcache_timeout_policy(key) if timeout is None: timeout = ContextOptions.memcache_timeout(s...
[ "def", "_get_memcache_timeout", "(", "self", ",", "key", ",", "options", "=", "None", ")", ":", "timeout", "=", "ContextOptions", ".", "memcache_timeout", "(", "options", ")", "if", "timeout", "is", "None", ":", "timeout", "=", "self", ".", "_memcache_timeou...
Return the memcache timeout (expiration) for this key.
[ "Return", "the", "memcache", "timeout", "(", "expiration", ")", "for", "this", "key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L492-L501
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context._load_from_cache_if_available
def _load_from_cache_if_available(self, key): """Returns a cached Model instance given the entity key if available. Args: key: Key instance. Returns: A Model instance if the key exists in the cache. """ if key in self._cache: entity = self._cache[key] # May be None, meaning "doe...
python
def _load_from_cache_if_available(self, key): """Returns a cached Model instance given the entity key if available. Args: key: Key instance. Returns: A Model instance if the key exists in the cache. """ if key in self._cache: entity = self._cache[key] # May be None, meaning "doe...
[ "def", "_load_from_cache_if_available", "(", "self", ",", "key", ")", ":", "if", "key", "in", "self", ".", "_cache", ":", "entity", "=", "self", ".", "_cache", "[", "key", "]", "# May be None, meaning \"doesn't exist\".", "if", "entity", "is", "None", "or", ...
Returns a cached Model instance given the entity key if available. Args: key: Key instance. Returns: A Model instance if the key exists in the cache.
[ "Returns", "a", "cached", "Model", "instance", "given", "the", "entity", "key", "if", "available", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L518-L532
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.get
def get(self, key, **ctx_options): """Return a Model instance given the entity key. It will use the context cache if the cache policy for the given key is enabled. Args: key: Key instance. **ctx_options: Context options. Returns: A Model instance if the key exists in the datasto...
python
def get(self, key, **ctx_options): """Return a Model instance given the entity key. It will use the context cache if the cache policy for the given key is enabled. Args: key: Key instance. **ctx_options: Context options. Returns: A Model instance if the key exists in the datasto...
[ "def", "get", "(", "self", ",", "key", ",", "*", "*", "ctx_options", ")", ":", "options", "=", "_make_ctx_options", "(", "ctx_options", ")", "use_cache", "=", "self", ".", "_use_cache", "(", "key", ",", "options", ")", "if", "use_cache", ":", "self", "...
Return a Model instance given the entity key. It will use the context cache if the cache policy for the given key is enabled. Args: key: Key instance. **ctx_options: Context options. Returns: A Model instance if the key exists in the datastore; None otherwise.
[ "Return", "a", "Model", "instance", "given", "the", "entity", "key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L542-L637
GoogleCloudPlatform/datastore-ndb-python
ndb/context.py
Context.call_on_commit
def call_on_commit(self, callback): """Call a callback upon successful commit of a transaction. If not in a transaction, the callback is called immediately. In a transaction, multiple callbacks may be registered and will be called once the transaction commits, in the order in which they were regis...
python
def call_on_commit(self, callback): """Call a callback upon successful commit of a transaction. If not in a transaction, the callback is called immediately. In a transaction, multiple callbacks may be registered and will be called once the transaction commits, in the order in which they were regis...
[ "def", "call_on_commit", "(", "self", ",", "callback", ")", ":", "if", "not", "self", ".", "in_transaction", "(", ")", ":", "callback", "(", ")", "else", ":", "self", ".", "_on_commit_queue", ".", "append", "(", "callback", ")" ]
Call a callback upon successful commit of a transaction. If not in a transaction, the callback is called immediately. In a transaction, multiple callbacks may be registered and will be called once the transaction commits, in the order in which they were registered. If the transaction fails, the callb...
[ "Call", "a", "callback", "upon", "successful", "commit", "of", "a", "transaction", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/context.py#L908-L928
GoogleCloudPlatform/datastore-ndb-python
demo/app/main.py
get_nickname
def get_nickname(userid): """Return a Future for a nickname from an account.""" account = yield get_account(userid) if not account: nickname = 'Unregistered' else: nickname = account.nickname or account.email raise ndb.Return(nickname)
python
def get_nickname(userid): """Return a Future for a nickname from an account.""" account = yield get_account(userid) if not account: nickname = 'Unregistered' else: nickname = account.nickname or account.email raise ndb.Return(nickname)
[ "def", "get_nickname", "(", "userid", ")", ":", "account", "=", "yield", "get_account", "(", "userid", ")", "if", "not", "account", ":", "nickname", "=", "'Unregistered'", "else", ":", "nickname", "=", "account", ".", "nickname", "or", "account", ".", "ema...
Return a Future for a nickname from an account.
[ "Return", "a", "Future", "for", "a", "nickname", "from", "an", "account", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/demo/app/main.py#L111-L118
GoogleCloudPlatform/datastore-ndb-python
demo/task_list.py
mark_done
def mark_done(task_id): """Marks a task as done. Args: task_id: The integer id of the task to update. Raises: ValueError: if the requested task doesn't exist. """ task = Task.get_by_id(task_id) if task is None: raise ValueError('Task with id %d does not exist' % task_id) task.done = True t...
python
def mark_done(task_id): """Marks a task as done. Args: task_id: The integer id of the task to update. Raises: ValueError: if the requested task doesn't exist. """ task = Task.get_by_id(task_id) if task is None: raise ValueError('Task with id %d does not exist' % task_id) task.done = True t...
[ "def", "mark_done", "(", "task_id", ")", ":", "task", "=", "Task", ".", "get_by_id", "(", "task_id", ")", "if", "task", "is", "None", ":", "raise", "ValueError", "(", "'Task with id %d does not exist'", "%", "task_id", ")", "task", ".", "done", "=", "True"...
Marks a task as done. Args: task_id: The integer id of the task to update. Raises: ValueError: if the requested task doesn't exist.
[ "Marks", "a", "task", "as", "done", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/demo/task_list.py#L61-L74
GoogleCloudPlatform/datastore-ndb-python
demo/task_list.py
format_tasks
def format_tasks(tasks): """Converts a list of tasks to a list of string representations. Args: tasks: A list of the tasks to convert. Returns: A list of string formatted tasks. """ return ['%d : %s (%s)' % (task.key.id(), task.description, ('do...
python
def format_tasks(tasks): """Converts a list of tasks to a list of string representations. Args: tasks: A list of the tasks to convert. Returns: A list of string formatted tasks. """ return ['%d : %s (%s)' % (task.key.id(), task.description, ('do...
[ "def", "format_tasks", "(", "tasks", ")", ":", "return", "[", "'%d : %s (%s)'", "%", "(", "task", ".", "key", ".", "id", "(", ")", ",", "task", ".", "description", ",", "(", "'done'", "if", "task", ".", "done", "else", "'created %s'", "%", "task", "....
Converts a list of tasks to a list of string representations. Args: tasks: A list of the tasks to convert. Returns: A list of string formatted tasks.
[ "Converts", "a", "list", "of", "tasks", "to", "a", "list", "of", "string", "representations", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/demo/task_list.py#L102-L114
GoogleCloudPlatform/datastore-ndb-python
demo/task_list.py
handle_command
def handle_command(command): """Accepts a string command and performs an action. Args: command: the command to run as a string. """ try: cmds = command.split(None, 1) cmd = cmds[0] if cmd == 'new': add_task(get_arg(cmds)) elif cmd == 'done': mark_done(int(get_arg(cmds))) eli...
python
def handle_command(command): """Accepts a string command and performs an action. Args: command: the command to run as a string. """ try: cmds = command.split(None, 1) cmd = cmds[0] if cmd == 'new': add_task(get_arg(cmds)) elif cmd == 'done': mark_done(int(get_arg(cmds))) eli...
[ "def", "handle_command", "(", "command", ")", ":", "try", ":", "cmds", "=", "command", ".", "split", "(", "None", ",", "1", ")", "cmd", "=", "cmds", "[", "0", "]", "if", "cmd", "==", "'new'", ":", "add_task", "(", "get_arg", "(", "cmds", ")", ")"...
Accepts a string command and performs an action. Args: command: the command to run as a string.
[ "Accepts", "a", "string", "command", "and", "performs", "an", "action", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/demo/task_list.py#L135-L157
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
delete_async
def delete_async(blob_key, **options): """Async version of delete().""" if not isinstance(blob_key, (basestring, BlobKey)): raise TypeError('Expected blob key, got %r' % (blob_key,)) rpc = blobstore.create_rpc(**options) yield blobstore.delete_async(blob_key, rpc=rpc)
python
def delete_async(blob_key, **options): """Async version of delete().""" if not isinstance(blob_key, (basestring, BlobKey)): raise TypeError('Expected blob key, got %r' % (blob_key,)) rpc = blobstore.create_rpc(**options) yield blobstore.delete_async(blob_key, rpc=rpc)
[ "def", "delete_async", "(", "blob_key", ",", "*", "*", "options", ")", ":", "if", "not", "isinstance", "(", "blob_key", ",", "(", "basestring", ",", "BlobKey", ")", ")", ":", "raise", "TypeError", "(", "'Expected blob key, got %r'", "%", "(", "blob_key", "...
Async version of delete().
[ "Async", "version", "of", "delete", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L273-L278
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
delete_multi_async
def delete_multi_async(blob_keys, **options): """Async version of delete_multi().""" if isinstance(blob_keys, (basestring, BlobKey)): raise TypeError('Expected a list, got %r' % (blob_key,)) rpc = blobstore.create_rpc(**options) yield blobstore.delete_async(blob_keys, rpc=rpc)
python
def delete_multi_async(blob_keys, **options): """Async version of delete_multi().""" if isinstance(blob_keys, (basestring, BlobKey)): raise TypeError('Expected a list, got %r' % (blob_key,)) rpc = blobstore.create_rpc(**options) yield blobstore.delete_async(blob_keys, rpc=rpc)
[ "def", "delete_multi_async", "(", "blob_keys", ",", "*", "*", "options", ")", ":", "if", "isinstance", "(", "blob_keys", ",", "(", "basestring", ",", "BlobKey", ")", ")", ":", "raise", "TypeError", "(", "'Expected a list, got %r'", "%", "(", "blob_key", ",",...
Async version of delete_multi().
[ "Async", "version", "of", "delete_multi", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L293-L298
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
create_upload_url
def create_upload_url(success_path, max_bytes_per_blob=None, max_bytes_total=None, **options): """Create upload URL for POST form. Args: success_path: Path within application to call when POST is successful and upload is complete. max_...
python
def create_upload_url(success_path, max_bytes_per_blob=None, max_bytes_total=None, **options): """Create upload URL for POST form. Args: success_path: Path within application to call when POST is successful and upload is complete. max_...
[ "def", "create_upload_url", "(", "success_path", ",", "max_bytes_per_blob", "=", "None", ",", "max_bytes_total", "=", "None", ",", "*", "*", "options", ")", ":", "fut", "=", "create_upload_url_async", "(", "success_path", ",", "max_bytes_per_blob", "=", "max_bytes...
Create upload URL for POST form. Args: success_path: Path within application to call when POST is successful and upload is complete. max_bytes_per_blob: The maximum size in bytes that any one blob in the upload can be or None for no maximum size. max_bytes_total: The maximum size in bytes tha...
[ "Create", "upload", "URL", "for", "POST", "form", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L301-L328
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
create_upload_url_async
def create_upload_url_async(success_path, max_bytes_per_blob=None, max_bytes_total=None, **options): """Async version of create_upload_url().""" rpc = blobstore.create_rpc(**options) rpc = blobstore.create_upload_url_async(success...
python
def create_upload_url_async(success_path, max_bytes_per_blob=None, max_bytes_total=None, **options): """Async version of create_upload_url().""" rpc = blobstore.create_rpc(**options) rpc = blobstore.create_upload_url_async(success...
[ "def", "create_upload_url_async", "(", "success_path", ",", "max_bytes_per_blob", "=", "None", ",", "max_bytes_total", "=", "None", ",", "*", "*", "options", ")", ":", "rpc", "=", "blobstore", ".", "create_rpc", "(", "*", "*", "options", ")", "rpc", "=", "...
Async version of create_upload_url().
[ "Async", "version", "of", "create_upload_url", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L332-L343
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
parse_blob_info
def parse_blob_info(field_storage): """Parse a BlobInfo record from file upload field_storage. Args: field_storage: cgi.FieldStorage that represents uploaded blob. Returns: BlobInfo record as parsed from the field-storage instance. None if there was no field_storage. Raises: BlobInfoParseErro...
python
def parse_blob_info(field_storage): """Parse a BlobInfo record from file upload field_storage. Args: field_storage: cgi.FieldStorage that represents uploaded blob. Returns: BlobInfo record as parsed from the field-storage instance. None if there was no field_storage. Raises: BlobInfoParseErro...
[ "def", "parse_blob_info", "(", "field_storage", ")", ":", "if", "field_storage", "is", "None", ":", "return", "None", "field_name", "=", "field_storage", ".", "name", "def", "get_value", "(", "dct", ",", "name", ")", ":", "value", "=", "dct", ".", "get", ...
Parse a BlobInfo record from file upload field_storage. Args: field_storage: cgi.FieldStorage that represents uploaded blob. Returns: BlobInfo record as parsed from the field-storage instance. None if there was no field_storage. Raises: BlobInfoParseError when provided field_storage does not co...
[ "Parse", "a", "BlobInfo", "record", "from", "file", "upload", "field_storage", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L346-L400
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
fetch_data
def fetch_data(blob, start_index, end_index, **options): """Fetch data for blob. Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE in length. Attempting to fetch a fragment that extends beyond the boundaries of the blob will return the amount of data from start_index until the end of the blob, which will...
python
def fetch_data(blob, start_index, end_index, **options): """Fetch data for blob. Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE in length. Attempting to fetch a fragment that extends beyond the boundaries of the blob will return the amount of data from start_index until the end of the blob, which will...
[ "def", "fetch_data", "(", "blob", ",", "start_index", ",", "end_index", ",", "*", "*", "options", ")", ":", "fut", "=", "fetch_data_async", "(", "blob", ",", "start_index", ",", "end_index", ",", "*", "*", "options", ")", "return", "fut", ".", "get_resul...
Fetch data for blob. Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE in length. Attempting to fetch a fragment that extends beyond the boundaries of the blob will return the amount of data from start_index until the end of the blob, which will be a smaller size than requested. Requesting a fragment wh...
[ "Fetch", "data", "for", "blob", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L403-L434
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
fetch_data_async
def fetch_data_async(blob, start_index, end_index, **options): """Async version of fetch_data().""" if isinstance(blob, BlobInfo): blob = blob.key() rpc = blobstore.create_rpc(**options) rpc = blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc) result = yield rpc raise tasklets.Return(resu...
python
def fetch_data_async(blob, start_index, end_index, **options): """Async version of fetch_data().""" if isinstance(blob, BlobInfo): blob = blob.key() rpc = blobstore.create_rpc(**options) rpc = blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc) result = yield rpc raise tasklets.Return(resu...
[ "def", "fetch_data_async", "(", "blob", ",", "start_index", ",", "end_index", ",", "*", "*", "options", ")", ":", "if", "isinstance", "(", "blob", ",", "BlobInfo", ")", ":", "blob", "=", "blob", ".", "key", "(", ")", "rpc", "=", "blobstore", ".", "cr...
Async version of fetch_data().
[ "Async", "version", "of", "fetch_data", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L438-L445
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobInfo.get
def get(cls, blob_key, **ctx_options): """Retrieve a BlobInfo by key. Args: blob_key: A blob key. This may be a str, unicode or BlobKey instance. **ctx_options: Context options for Model().get_by_id(). Returns: A BlobInfo entity associated with the provided key, If there was no s...
python
def get(cls, blob_key, **ctx_options): """Retrieve a BlobInfo by key. Args: blob_key: A blob key. This may be a str, unicode or BlobKey instance. **ctx_options: Context options for Model().get_by_id(). Returns: A BlobInfo entity associated with the provided key, If there was no s...
[ "def", "get", "(", "cls", ",", "blob_key", ",", "*", "*", "ctx_options", ")", ":", "fut", "=", "cls", ".", "get_async", "(", "blob_key", ",", "*", "*", "ctx_options", ")", "return", "fut", ".", "get_result", "(", ")" ]
Retrieve a BlobInfo by key. Args: blob_key: A blob key. This may be a str, unicode or BlobKey instance. **ctx_options: Context options for Model().get_by_id(). Returns: A BlobInfo entity associated with the provided key, If there was no such entity, returns None.
[ "Retrieve", "a", "BlobInfo", "by", "key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L167-L179
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobInfo.get_async
def get_async(cls, blob_key, **ctx_options): """Async version of get().""" if not isinstance(blob_key, (BlobKey, basestring)): raise TypeError('Expected blob key, got %r' % (blob_key,)) if 'parent' in ctx_options: raise TypeError('Parent is not supported') return cls.get_by_id_async(str(blob...
python
def get_async(cls, blob_key, **ctx_options): """Async version of get().""" if not isinstance(blob_key, (BlobKey, basestring)): raise TypeError('Expected blob key, got %r' % (blob_key,)) if 'parent' in ctx_options: raise TypeError('Parent is not supported') return cls.get_by_id_async(str(blob...
[ "def", "get_async", "(", "cls", ",", "blob_key", ",", "*", "*", "ctx_options", ")", ":", "if", "not", "isinstance", "(", "blob_key", ",", "(", "BlobKey", ",", "basestring", ")", ")", ":", "raise", "TypeError", "(", "'Expected blob key, got %r'", "%", "(", ...
Async version of get().
[ "Async", "version", "of", "get", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L182-L188
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobInfo.get_multi
def get_multi(cls, blob_keys, **ctx_options): """Multi-key version of get(). Args: blob_keys: A list of blob keys. **ctx_options: Context options for Model().get_by_id(). Returns: A list whose items are each either a BlobInfo entity or None. """ futs = cls.get_multi_async(blob_ke...
python
def get_multi(cls, blob_keys, **ctx_options): """Multi-key version of get(). Args: blob_keys: A list of blob keys. **ctx_options: Context options for Model().get_by_id(). Returns: A list whose items are each either a BlobInfo entity or None. """ futs = cls.get_multi_async(blob_ke...
[ "def", "get_multi", "(", "cls", ",", "blob_keys", ",", "*", "*", "ctx_options", ")", ":", "futs", "=", "cls", ".", "get_multi_async", "(", "blob_keys", ",", "*", "*", "ctx_options", ")", "return", "[", "fut", ".", "get_result", "(", ")", "for", "fut", ...
Multi-key version of get(). Args: blob_keys: A list of blob keys. **ctx_options: Context options for Model().get_by_id(). Returns: A list whose items are each either a BlobInfo entity or None.
[ "Multi", "-", "key", "version", "of", "get", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L191-L202
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobInfo.get_multi_async
def get_multi_async(cls, blob_keys, **ctx_options): """Async version of get_multi().""" for blob_key in blob_keys: if not isinstance(blob_key, (BlobKey, basestring)): raise TypeError('Expected blob key, got %r' % (blob_key,)) if 'parent' in ctx_options: raise TypeError('Parent is not sup...
python
def get_multi_async(cls, blob_keys, **ctx_options): """Async version of get_multi().""" for blob_key in blob_keys: if not isinstance(blob_key, (BlobKey, basestring)): raise TypeError('Expected blob key, got %r' % (blob_key,)) if 'parent' in ctx_options: raise TypeError('Parent is not sup...
[ "def", "get_multi_async", "(", "cls", ",", "blob_keys", ",", "*", "*", "ctx_options", ")", ":", "for", "blob_key", "in", "blob_keys", ":", "if", "not", "isinstance", "(", "blob_key", ",", "(", "BlobKey", ",", "basestring", ")", ")", ":", "raise", "TypeEr...
Async version of get_multi().
[ "Async", "version", "of", "get_multi", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L205-L214
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobInfo.delete
def delete(self, **options): """Permanently delete this blob from Blobstore. Args: **options: Options for create_rpc(). """ fut = delete_async(self.key(), **options) fut.get_result()
python
def delete(self, **options): """Permanently delete this blob from Blobstore. Args: **options: Options for create_rpc(). """ fut = delete_async(self.key(), **options) fut.get_result()
[ "def", "delete", "(", "self", ",", "*", "*", "options", ")", ":", "fut", "=", "delete_async", "(", "self", ".", "key", "(", ")", ",", "*", "*", "options", ")", "fut", ".", "get_result", "(", ")" ]
Permanently delete this blob from Blobstore. Args: **options: Options for create_rpc().
[ "Permanently", "delete", "this", "blob", "from", "Blobstore", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L230-L237
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobReader.__fill_buffer
def __fill_buffer(self, size=0): """Fills the internal buffer. Args: size: Number of bytes to read. Will be clamped to [self.__buffer_size, MAX_BLOB_FETCH_SIZE]. """ read_size = min(max(size, self.__buffer_size), MAX_BLOB_FETCH_SIZE) self.__buffer = fetch_data(self.__blob_key, self._...
python
def __fill_buffer(self, size=0): """Fills the internal buffer. Args: size: Number of bytes to read. Will be clamped to [self.__buffer_size, MAX_BLOB_FETCH_SIZE]. """ read_size = min(max(size, self.__buffer_size), MAX_BLOB_FETCH_SIZE) self.__buffer = fetch_data(self.__blob_key, self._...
[ "def", "__fill_buffer", "(", "self", ",", "size", "=", "0", ")", ":", "read_size", "=", "min", "(", "max", "(", "size", ",", "self", ".", "__buffer_size", ")", ",", "MAX_BLOB_FETCH_SIZE", ")", "self", ".", "__buffer", "=", "fetch_data", "(", "self", "....
Fills the internal buffer. Args: size: Number of bytes to read. Will be clamped to [self.__buffer_size, MAX_BLOB_FETCH_SIZE].
[ "Fills", "the", "internal", "buffer", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L455-L467
GoogleCloudPlatform/datastore-ndb-python
ndb/blobstore.py
BlobReader.blob_info
def blob_info(self): """Returns the BlobInfo for this file.""" if not self.__blob_info: self.__blob_info = BlobInfo.get(self.__blob_key) return self.__blob_info
python
def blob_info(self): """Returns the BlobInfo for this file.""" if not self.__blob_info: self.__blob_info = BlobInfo.get(self.__blob_key) return self.__blob_info
[ "def", "blob_info", "(", "self", ")", ":", "if", "not", "self", ".", "__blob_info", ":", "self", ".", "__blob_info", "=", "BlobInfo", ".", "get", "(", "self", ".", "__blob_key", ")", "return", "self", ".", "__blob_info" ]
Returns the BlobInfo for this file.
[ "Returns", "the", "BlobInfo", "for", "this", "file", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/blobstore.py#L470-L474
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
make_connection
def make_connection(config=None, default_model=None, _api_version=datastore_rpc._DATASTORE_V3, _id_resolver=None): """Create a new Connection object with the right adapter. Optionally you can pass in a datastore_rpc.Configuration object. """ return datastore_rpc.Connecti...
python
def make_connection(config=None, default_model=None, _api_version=datastore_rpc._DATASTORE_V3, _id_resolver=None): """Create a new Connection object with the right adapter. Optionally you can pass in a datastore_rpc.Configuration object. """ return datastore_rpc.Connecti...
[ "def", "make_connection", "(", "config", "=", "None", ",", "default_model", "=", "None", ",", "_api_version", "=", "datastore_rpc", ".", "_DATASTORE_V3", ",", "_id_resolver", "=", "None", ")", ":", "return", "datastore_rpc", ".", "Connection", "(", "adapter", ...
Create a new Connection object with the right adapter. Optionally you can pass in a datastore_rpc.Configuration object.
[ "Create", "a", "new", "Connection", "object", "with", "the", "right", "adapter", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L716-L726
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
_unpack_user
def _unpack_user(v): """Internal helper to unpack a User value from a protocol buffer.""" uv = v.uservalue() email = unicode(uv.email().decode('utf-8')) auth_domain = unicode(uv.auth_domain().decode('utf-8')) obfuscated_gaiaid = uv.obfuscated_gaiaid().decode('utf-8') obfuscated_gaiaid = unicode(obfuscated_g...
python
def _unpack_user(v): """Internal helper to unpack a User value from a protocol buffer.""" uv = v.uservalue() email = unicode(uv.email().decode('utf-8')) auth_domain = unicode(uv.auth_domain().decode('utf-8')) obfuscated_gaiaid = uv.obfuscated_gaiaid().decode('utf-8') obfuscated_gaiaid = unicode(obfuscated_g...
[ "def", "_unpack_user", "(", "v", ")", ":", "uv", "=", "v", ".", "uservalue", "(", ")", "email", "=", "unicode", "(", "uv", ".", "email", "(", ")", ".", "decode", "(", "'utf-8'", ")", ")", "auth_domain", "=", "unicode", "(", "uv", ".", "auth_domain"...
Internal helper to unpack a User value from a protocol buffer.
[ "Internal", "helper", "to", "unpack", "a", "User", "value", "from", "a", "protocol", "buffer", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1838-L1855
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
_date_to_datetime
def _date_to_datetime(value): """Convert a date to a datetime for Cloud Datastore storage. Args: value: A datetime.date object. Returns: A datetime object with time set to 0:00. """ if not isinstance(value, datetime.date): raise TypeError('Cannot convert to datetime expected date value; ' ...
python
def _date_to_datetime(value): """Convert a date to a datetime for Cloud Datastore storage. Args: value: A datetime.date object. Returns: A datetime object with time set to 0:00. """ if not isinstance(value, datetime.date): raise TypeError('Cannot convert to datetime expected date value; ' ...
[ "def", "_date_to_datetime", "(", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "datetime", ".", "date", ")", ":", "raise", "TypeError", "(", "'Cannot convert to datetime expected date value; '", "'received %s'", "%", "value", ")", "return", "dat...
Convert a date to a datetime for Cloud Datastore storage. Args: value: A datetime.date object. Returns: A datetime object with time set to 0:00.
[ "Convert", "a", "date", "to", "a", "datetime", "for", "Cloud", "Datastore", "storage", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2142-L2154
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
_time_to_datetime
def _time_to_datetime(value): """Convert a time to a datetime for Cloud Datastore storage. Args: value: A datetime.time object. Returns: A datetime object with date set to 1970-01-01. """ if not isinstance(value, datetime.time): raise TypeError('Cannot convert to datetime expected time value; ' ...
python
def _time_to_datetime(value): """Convert a time to a datetime for Cloud Datastore storage. Args: value: A datetime.time object. Returns: A datetime object with date set to 1970-01-01. """ if not isinstance(value, datetime.time): raise TypeError('Cannot convert to datetime expected time value; ' ...
[ "def", "_time_to_datetime", "(", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "datetime", ".", "time", ")", ":", "raise", "TypeError", "(", "'Cannot convert to datetime expected time value; '", "'received %s'", "%", "value", ")", "return", "dat...
Convert a time to a datetime for Cloud Datastore storage. Args: value: A datetime.time object. Returns: A datetime object with date set to 1970-01-01.
[ "Convert", "a", "time", "to", "a", "datetime", "for", "Cloud", "Datastore", "storage", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2157-L2171
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
transactional
def transactional(func, args, kwds, **options): """Decorator to make a function automatically run in a transaction. Args: **ctx_options: Transaction options (see transaction(), but propagation default to TransactionOptions.ALLOWED). This supports two forms: (1) Vanilla: @transactional d...
python
def transactional(func, args, kwds, **options): """Decorator to make a function automatically run in a transaction. Args: **ctx_options: Transaction options (see transaction(), but propagation default to TransactionOptions.ALLOWED). This supports two forms: (1) Vanilla: @transactional d...
[ "def", "transactional", "(", "func", ",", "args", ",", "kwds", ",", "*", "*", "options", ")", ":", "return", "transactional_async", ".", "wrapped_decorator", "(", "func", ",", "args", ",", "kwds", ",", "*", "*", "options", ")", ".", "get_result", "(", ...
Decorator to make a function automatically run in a transaction. Args: **ctx_options: Transaction options (see transaction(), but propagation default to TransactionOptions.ALLOWED). This supports two forms: (1) Vanilla: @transactional def callback(arg): ... (2) With options: ...
[ "Decorator", "to", "make", "a", "function", "automatically", "run", "in", "a", "transaction", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3821-L3841
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
transactional_async
def transactional_async(func, args, kwds, **options): """The async version of @ndb.transaction.""" options.setdefault('propagation', datastore_rpc.TransactionOptions.ALLOWED) if args or kwds: return transaction_async(lambda: func(*args, **kwds), **options) return transaction_async(func, **options)
python
def transactional_async(func, args, kwds, **options): """The async version of @ndb.transaction.""" options.setdefault('propagation', datastore_rpc.TransactionOptions.ALLOWED) if args or kwds: return transaction_async(lambda: func(*args, **kwds), **options) return transaction_async(func, **options)
[ "def", "transactional_async", "(", "func", ",", "args", ",", "kwds", ",", "*", "*", "options", ")", ":", "options", ".", "setdefault", "(", "'propagation'", ",", "datastore_rpc", ".", "TransactionOptions", ".", "ALLOWED", ")", "if", "args", "or", "kwds", "...
The async version of @ndb.transaction.
[ "The", "async", "version", "of" ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3845-L3850
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
transactional_tasklet
def transactional_tasklet(func, args, kwds, **options): """The async version of @ndb.transaction. Will return the result of the wrapped function as a Future. """ from . import tasklets func = tasklets.tasklet(func) return transactional_async.wrapped_decorator(func, args, kwds, **options)
python
def transactional_tasklet(func, args, kwds, **options): """The async version of @ndb.transaction. Will return the result of the wrapped function as a Future. """ from . import tasklets func = tasklets.tasklet(func) return transactional_async.wrapped_decorator(func, args, kwds, **options)
[ "def", "transactional_tasklet", "(", "func", ",", "args", ",", "kwds", ",", "*", "*", "options", ")", ":", "from", ".", "import", "tasklets", "func", "=", "tasklets", ".", "tasklet", "(", "func", ")", "return", "transactional_async", ".", "wrapped_decorator"...
The async version of @ndb.transaction. Will return the result of the wrapped function as a Future.
[ "The", "async", "version", "of", "@ndb", ".", "transaction", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3854-L3861
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
non_transactional
def non_transactional(func, args, kwds, allow_existing=True): """A decorator that ensures a function is run outside a transaction. If there is an existing transaction (and allow_existing=True), the existing transaction is paused while the function is executed. Args: allow_existing: If false, throw an exce...
python
def non_transactional(func, args, kwds, allow_existing=True): """A decorator that ensures a function is run outside a transaction. If there is an existing transaction (and allow_existing=True), the existing transaction is paused while the function is executed. Args: allow_existing: If false, throw an exce...
[ "def", "non_transactional", "(", "func", ",", "args", ",", "kwds", ",", "allow_existing", "=", "True", ")", ":", "from", ".", "import", "tasklets", "ctx", "=", "tasklets", ".", "get_context", "(", ")", "if", "not", "ctx", ".", "in_transaction", "(", ")",...
A decorator that ensures a function is run outside a transaction. If there is an existing transaction (and allow_existing=True), the existing transaction is paused while the function is executed. Args: allow_existing: If false, throw an exception if called from within a transaction. If true, temporar...
[ "A", "decorator", "that", "ensures", "a", "function", "is", "run", "outside", "a", "transaction", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3865-L3903
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
_NestedCounter._set
def _set(self, value): """Updates all descendants to a specified value.""" if self.__is_parent_node(): for child in self.__sub_counters.itervalues(): child._set(value) else: self.__counter = value
python
def _set(self, value): """Updates all descendants to a specified value.""" if self.__is_parent_node(): for child in self.__sub_counters.itervalues(): child._set(value) else: self.__counter = value
[ "def", "_set", "(", "self", ",", "value", ")", ":", "if", "self", ".", "__is_parent_node", "(", ")", ":", "for", "child", "in", "self", ".", "__sub_counters", ".", "itervalues", "(", ")", ":", "child", ".", "_set", "(", "value", ")", "else", ":", "...
Updates all descendants to a specified value.
[ "Updates", "all", "descendants", "to", "a", "specified", "value", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L487-L493
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._comparison
def _comparison(self, op, value): """Internal helper for comparison operators. Args: op: The operator ('=', '<' etc.). Returns: A FilterNode instance representing the requested comparison. """ # NOTE: This is also used by query.gql(). if not self._indexed: raise datastore_err...
python
def _comparison(self, op, value): """Internal helper for comparison operators. Args: op: The operator ('=', '<' etc.). Returns: A FilterNode instance representing the requested comparison. """ # NOTE: This is also used by query.gql(). if not self._indexed: raise datastore_err...
[ "def", "_comparison", "(", "self", ",", "op", ",", "value", ")", ":", "# NOTE: This is also used by query.gql().", "if", "not", "self", ".", "_indexed", ":", "raise", "datastore_errors", ".", "BadFilterError", "(", "'Cannot query for unindexed property %s'", "%", "sel...
Internal helper for comparison operators. Args: op: The operator ('=', '<' etc.). Returns: A FilterNode instance representing the requested comparison.
[ "Internal", "helper", "for", "comparison", "operators", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L972-L990
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._IN
def _IN(self, value): """Comparison operator for the 'in' comparison operator. The Python 'in' operator cannot be overloaded in the way we want to, so we define a method. For example:: Employee.query(Employee.rank.IN([4, 5, 6])) Note that the method is called ._IN() but may normally be invoked...
python
def _IN(self, value): """Comparison operator for the 'in' comparison operator. The Python 'in' operator cannot be overloaded in the way we want to, so we define a method. For example:: Employee.query(Employee.rank.IN([4, 5, 6])) Note that the method is called ._IN() but may normally be invoked...
[ "def", "_IN", "(", "self", ",", "value", ")", ":", "if", "not", "self", ".", "_indexed", ":", "raise", "datastore_errors", ".", "BadFilterError", "(", "'Cannot query for unindexed property %s'", "%", "self", ".", "_name", ")", "from", ".", "query", "import", ...
Comparison operator for the 'in' comparison operator. The Python 'in' operator cannot be overloaded in the way we want to, so we define a method. For example:: Employee.query(Employee.rank.IN([4, 5, 6])) Note that the method is called ._IN() but may normally be invoked as .IN(); ._IN() is prov...
[ "Comparison", "operator", "for", "the", "in", "comparison", "operator", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1022-L1048
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._do_validate
def _do_validate(self, value): """Call all validations on the value. This calls the most derived _validate() method(s), then the custom validator function, and then checks the choices. It returns the value, possibly modified in an idempotent way, or raises an exception. Note that this does no...
python
def _do_validate(self, value): """Call all validations on the value. This calls the most derived _validate() method(s), then the custom validator function, and then checks the choices. It returns the value, possibly modified in an idempotent way, or raises an exception. Note that this does no...
[ "def", "_do_validate", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "_BaseValue", ")", ":", "return", "value", "value", "=", "self", ".", "_call_shallow_validation", "(", "value", ")", "if", "self", ".", "_validator", "is", ...
Call all validations on the value. This calls the most derived _validate() method(s), then the custom validator function, and then checks the choices. It returns the value, possibly modified in an idempotent way, or raises an exception. Note that this does not call all composable _validate() meth...
[ "Call", "all", "validations", "on", "the", "value", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1072-L1102
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._fix_up
def _fix_up(self, cls, code_name): """Internal helper called to tell the property its name. This is called by _fix_up_properties() which is called by MetaModel when finishing the construction of a Model subclass. The name passed in is the name of the class attribute to which the Property is assigne...
python
def _fix_up(self, cls, code_name): """Internal helper called to tell the property its name. This is called by _fix_up_properties() which is called by MetaModel when finishing the construction of a Model subclass. The name passed in is the name of the class attribute to which the Property is assigne...
[ "def", "_fix_up", "(", "self", ",", "cls", ",", "code_name", ")", ":", "self", ".", "_code_name", "=", "code_name", "if", "self", ".", "_name", "is", "None", ":", "self", ".", "_name", "=", "code_name" ]
Internal helper called to tell the property its name. This is called by _fix_up_properties() which is called by MetaModel when finishing the construction of a Model subclass. The name passed in is the name of the class attribute to which the Property is assigned (a.k.a. the code name). Note that this ...
[ "Internal", "helper", "called", "to", "tell", "the", "property", "its", "name", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1104-L1119
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._set_value
def _set_value(self, entity, value): """Internal helper to set a value in an entity for a Property. This performs validation first. For a repeated Property the value should be a list. """ if entity._projection: raise ReadonlyPropertyError( 'You cannot set property values of a proje...
python
def _set_value(self, entity, value): """Internal helper to set a value in an entity for a Property. This performs validation first. For a repeated Property the value should be a list. """ if entity._projection: raise ReadonlyPropertyError( 'You cannot set property values of a proje...
[ "def", "_set_value", "(", "self", ",", "entity", ",", "value", ")", ":", "if", "entity", ".", "_projection", ":", "raise", "ReadonlyPropertyError", "(", "'You cannot set property values of a projection entity'", ")", "if", "self", ".", "_repeated", ":", "if", "not...
Internal helper to set a value in an entity for a Property. This performs validation first. For a repeated Property the value should be a list.
[ "Internal", "helper", "to", "set", "a", "value", "in", "an", "entity", "for", "a", "Property", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1129-L1146
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._retrieve_value
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...
python
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", ")", ":", "return", "entity", ".", "_values", ".", "get", "(", "self", ".", "_name", ",", "default", ")" ]
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.
[ "Internal", "helper", "to", "retrieve", "the", "value", "for", "this", "Property", "from", "an", "entity", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1152-L1159
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._get_base_value_unwrapped_as_list
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...
python
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", ")", ":", "wrapped", "=", "self", ".", "_get_base_value", "(", "entity", ")", "if", "self", ".", "_repeated", ":", "if", "wrapped", "is", "None", ":", "return", "[", "]", "assert", "is...
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 [].
[ "Like", "_get_base_value", "()", "but", "always", "returns", "a", "list", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1183-L1202
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._opt_call_from_base_type
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...
python
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", ")", ":", "if", "isinstance", "(", "value", ",", "_BaseValue", ")", ":", "value", "=", "self", ".", "_call_from_base_type", "(", "value", ".", "b_val", ")", "return", "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.
[ "Call", "_from_base_type", "()", "if", "necessary", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1204-L1213
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._opt_call_to_base_type
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...
python
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", ")", ":", "if", "not", "isinstance", "(", "value", ",", "_BaseValue", ")", ":", "value", "=", "_BaseValue", "(", "self", ".", "_call_to_base_type", "(", "value", ")", ")", "return", "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.
[ "Call", "_to_base_type", "()", "if", "necessary", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1226-L1235
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._call_from_base_type
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...
python
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", ")", ":", "methods", "=", "self", ".", "_find_methods", "(", "'_from_base_type'", ",", "reverse", "=", "True", ")", "call", "=", "self", ".", "_apply_list", "(", "methods", ")", "return", "call", "(...
Call all _from_base_type() methods on the value. This calls the methods in the reverse method resolution order of the property's class.
[ "Call", "all", "_from_base_type", "()", "methods", "on", "the", "value", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1237-L1245
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._call_to_base_type
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...
python
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", ")", ":", "methods", "=", "self", ".", "_find_methods", "(", "'_validate'", ",", "'_to_base_type'", ")", "call", "=", "self", ".", "_apply_list", "(", "methods", ")", "return", "call", "(", "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.
[ "Call", "all", "_validate", "()", "and", "_to_base_type", "()", "methods", "on", "the", "value", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1247-L1255
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._call_shallow_validation
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 -> ...
python
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", ")", ":", "methods", "=", "[", "]", "for", "method", "in", "self", ".", "_find_methods", "(", "'_validate'", ",", "'_to_base_type'", ")", ":", "if", "method", ".", "__name__", "!=", "'_validate'",...
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...
[ "Call", "the", "initial", "set", "of", "_validate", "()", "methods", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1257-L1284
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._find_methods
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 ...
python
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", ")", ":", "reverse", "=", "kwds", ".", "pop", "(", "'reverse'", ",", "False", ")", "assert", "not", "kwds", ",", "repr", "(", "kwds", ")", "cache", "=", "cls", ".", "__...
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...
[ "Compute", "a", "list", "of", "composable", "methods", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1287-L1320
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._apply_list
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: ...
python
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", ")", ":", "def", "call", "(", "value", ")", ":", "for", "method", "in", "methods", ":", "newvalue", "=", "method", "(", "self", ",", "value", ")", "if", "newvalue", "is", "not", "None", ":", "value",...
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.
[ "Return", "a", "single", "callable", "that", "applies", "a", "list", "of", "methods", "to", "a", "value", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1322-L1335
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._apply_to_values
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...
python
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", ")", ":", "value", "=", "self", ".", "_retrieve_value", "(", "entity", ",", "self", ".", "_default", ")", "if", "self", ".", "_repeated", ":", "if", "value", "is", "None", ":", "va...
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...
[ "Apply", "a", "function", "to", "the", "property", "value", "/", "values", "of", "a", "given", "entity", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1337-L1359
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._get_value
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(...
python
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", ")", ":", "if", "entity", ".", "_projection", ":", "if", "self", ".", "_name", "not", "in", "entity", ".", "_projection", ":", "raise", "UnprojectedPropertyError", "(", "'Property %s is not in the projection'", "%...
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.
[ "Internal", "helper", "to", "get", "the", "value", "for", "this", "Property", "from", "an", "entity", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1361-L1371
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._delete_value
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...
python
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", ")", ":", "if", "self", ".", "_name", "in", "entity", ".", "_values", ":", "del", "entity", ".", "_values", "[", "self", ".", "_name", "]" ]
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).
[ "Internal", "helper", "to", "delete", "the", "value", "for", "this", "Property", "from", "an", "entity", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1373-L1381
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._is_initialized
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...
python
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", ")", ":", "return", "(", "not", "self", ".", "_required", "or", "(", "(", "self", ".", "_has_value", "(", "entity", ")", "or", "self", ".", "_default", "is", "not", "None", ")", "and", "self", "."...
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.
[ "Internal", "helper", "to", "ask", "if", "the", "entity", "has", "a", "value", "for", "this", "Property", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1383-L1390
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._serialize
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...
python
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", ")", ":", "values", "=", "self", ".", "_get_base_value_unwrapped_as_list", "(", "entity", ")", "name...
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...
[ "Internal", "helper", "to", "serialize", "this", "property", "to", "a", "protocol", "buffer", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1406-L1456
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._deserialize
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...
python
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", ")", ":", "if", "p", ".", "meaning", "(", ")", "==", "entity_pb", ".", "Property", ".", "EMPTY_LIST", ":", "self", ".", "_store_value", "(", "entity", ",", "[...
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...
[ "Internal", "helper", "to", "deserialize", "this", "property", "from", "a", "protocol", "buffer", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1458-L1496
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Property._check_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...
python
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", ")", ":", "if", "require_indexed", "and", "not", "self", ".", "_indexed", ":", "raise", "InvalidPropertyError", "(", "'Property is unindexed %s'", "%", "self", ...
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 ...
[ "Internal", "helper", "to", "check", "this", "property", "for", "specific", "requirements", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1501-L1519
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
ModelKey._set_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
python
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", ")", ":", "if", "value", "is", "not", "None", ":", "value", "=", "_validate_key", "(", "value", ",", "entity", "=", "entity", ")", "value", "=", "entity", ".", "_validate_key", "(", "value"...
Setter for key attribute.
[ "Setter", "for", "key", "attribute", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L1573-L1578
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
StructuredProperty._get_value
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) ...
python
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", ")", ":", "value", "=", "self", ".", "_get_user_value", "(", "entity", ")", "if", "value", "is", "None", "and", "entity", ".", "_projection", ":", "# Invoke super _get_value() to raise the proper exception.", "retur...
Override _get_value() to *not* raise UnprojectedPropertyError.
[ "Override", "_get_value", "()", "to", "*", "not", "*", "raise", "UnprojectedPropertyError", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2262-L2268
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
StructuredProperty._check_property
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...
python
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", ")", ":", "if", "not", "rest", ":", "raise", "InvalidPropertyError", "(", "'Structured property %s requires a subproperty'", "%", "self", ".", "_name", ")", "se...
Override for Property._check_property(). Raises: InvalidPropertyError if no subproperty is specified or if something is wrong with the subproperty.
[ "Override", "for", "Property", ".", "_check_property", "()", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2508-L2518
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model.__get_arg
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): ...
python
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", ")", ":", "alt_kwd", "=", "'_'", "+", "kwd", "if", "alt_kwd", "in", "kwds", ":", "return", "kwds", ".", "pop", "(", "alt_kwd", ")", "if", "kwd", "in", "kwds", ":", "obj", "=", "getattr", "(...
Internal helper method to parse keywords that may be property names.
[ "Internal", "helper", "method", "to", "parse", "keywords", "that", "may", "be", "property", "names", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2953-L2962
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._set_attributes
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...
python
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", ")", ":", "cls", "=", "self", ".", "__class__", "for", "name", ",", "value", "in", "kwds", ".", "iteritems", "(", ")", ":", "prop", "=", "getattr", "(", "cls", ",", "name", ")", "# Raises AttributeErr...
Internal helper to set attributes from keyword arguments. Expando overrides this.
[ "Internal", "helper", "to", "set", "attributes", "from", "keyword", "arguments", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2983-L2993
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._find_uninitialized
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))
python
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", ")", ":", "return", "set", "(", "name", "for", "name", ",", "prop", "in", "self", ".", "_properties", ".", "iteritems", "(", ")", "if", "not", "prop", ".", "_is_initialized", "(", "self", ")", ")" ]
Internal helper to find uninitialized properties. Returns: A set of property names.
[ "Internal", "helper", "to", "find", "uninitialized", "properties", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L2995-L3003
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._check_initialized
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...
python
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", ")", ":", "baddies", "=", "self", ".", "_find_uninitialized", "(", ")", "if", "baddies", ":", "raise", "datastore_errors", ".", "BadValueError", "(", "'Entity has uninitialized properties: %s'", "%", "', '", ".", "join", "...
Internal helper to check for uninitialized properties. Raises: BadValueError if it finds any.
[ "Internal", "helper", "to", "check", "for", "uninitialized", "properties", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3005-L3014
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._reset_kind_map
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...
python
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", ")", ":", "# Preserve \"system\" kinds, like __namespace__", "keep", "=", "{", "}", "for", "name", ",", "value", "in", "cls", ".", "_kind_map", ".", "iteritems", "(", ")", ":", "if", "name", ".", "startswith", "(", "'__'...
Clear the kind map. Useful for testing.
[ "Clear", "the", "kind", "map", ".", "Useful", "for", "testing", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3074-L3082
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._lookup_model
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...
python
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", ")", ":", "modelclass", "=", "cls", ".", "_kind_map", ".", "get", "(", "kind", ",", "default_model", ")", "if", "modelclass", "is", "None", ":", "raise", "KindError", "("...
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 ...
[ "Get", "the", "model", "class", "for", "the", "kind", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3085-L3102
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._equivalent
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...
python
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", ")", ":", "if", "other", ".", "__class__", "is", "not", "self", ".", "__class__", ":", "# TODO: What about subclasses?", "raise", "NotImplementedError", "(", "'Cannot compare different model classes. '", "'%s is not %s'",...
Compare two entities of the same class, excluding keys.
[ "Compare", "two", "entities", "of", "the", "same", "class", "excluding", "keys", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3129-L3153
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._to_pb
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...
python
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", ")", ":", "if", "not", "allow_partial", ":", "self", ".", "_check_initialized", "(", ")", "if", "pb", "is", "None", ":", "pb", "=",...
Internal helper to turn an entity into an EntityProto protobuf.
[ "Internal", "helper", "to", "turn", "an", "entity", "into", "an", "EntityProto", "protobuf", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3155-L3169
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._key_to_pb
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) ...
python
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", ")", ":", "key", "=", "self", ".", "_key", "if", "key", "is", "None", ":", "pairs", "=", "[", "(", "self", ".", "_get_kind", "(", ")", ",", "None", ")", "]", "ref", "=", "key_module", ".", "_ReferenceF...
Internal helper to copy the key into a protobuf.
[ "Internal", "helper", "to", "copy", "the", "key", "into", "a", "protobuf", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3171-L3186
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._from_pb
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...
python
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", ")", ":", "if", "not", "isinstance", "(", "pb", ",", "entity_pb", ".", "EntityProto", ")", ":", "raise", "TypeError", "(", "'pb...
Internal helper to create an entity from an EntityProto protobuf.
[ "Internal", "helper", "to", "create", "an", "entity", "from", "an", "EntityProto", "protobuf", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3189-L3219
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._get_property_for
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...
python
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", ")", ":", "parts", "=", "p", ".", "name", "(", ")", ".", "split", "(", "'.'", ")", "if", "len", "(", "parts", ")", "<=", "depth", ":", "# Ap...
Internal helper to get the Property for a protobuf-level property.
[ "Internal", "helper", "to", "get", "the", "Property", "for", "a", "protobuf", "-", "level", "property", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3238-L3253
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._clone_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)
python
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", ")", ":", "cls", "=", "self", ".", "__class__", "if", "self", ".", "_properties", "is", "cls", ".", "_properties", ":", "self", ".", "_properties", "=", "dict", "(", "cls", ".", "_properties", ")" ]
Internal helper to clone self._properties if necessary.
[ "Internal", "helper", "to", "clone", "self", ".", "_properties", "if", "necessary", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3255-L3259
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._fake_property
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...
python
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", ")", ":", "self", ".", "_clone_properties", "(", ")", "if", "p", ".", "name", "(", ")", "!=", "next", "and", "not", "p", ".", "name", "(", ")", ".", "endswi...
Internal helper to create a fake Property.
[ "Internal", "helper", "to", "create", "a", "fake", "Property", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3261-L3275
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._to_dict
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...
python
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", ")", ":", "if", "(", "include", "is", "not", "None", "and", "not", "isinstance", "(", "include", ",", "(", "list", ",", "tuple", ",", "set", ",", "frozenset", ...
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.
[ "Return", "a", "dict", "containing", "the", "entity", "s", "property", "values", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3278-L3303
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._fix_up_properties
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...
python
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", ")", ":", "# Verify that _get_kind() returns an 8-bit string.", "kind", "=", "cls", ".", "_get_kind", "(", ")", "if", "not", "isinstance", "(", "kind", ",", "basestring", ")", ":", "raise", "KindError", "(", "'Class %s defi...
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.
[ "Fix", "up", "the", "properties", "by", "calling", "their", "_fix_up", "()", "method", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3307-L3342
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._check_properties
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...
python
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", ")", ":", "assert", "isinstance", "(", "property_names", ",", "(", "list", ",", "tuple", ")", ")", ",", "repr", "(", "property_names", ")", "for", "name", "...
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...
[ "Internal", "helper", "to", "check", "the", "given", "properties", "exist", "and", "meet", "specified", "requirements", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3355-L3381
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._query
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...
python
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", ")", ":", "# Validating distinct.", "if", "'distinct'", "in", "kwds", ":", "if", "'group_by'", "in", "kwds", ":", "raise", "TypeError", "(", "'cannot use distinct= and group_by= at the same ti...
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.
[ "Create", "a", "Query", "object", "for", "this", "class", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3410-L3438
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._gql
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)
python
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", ")", ":", "from", ".", "query", "import", "gql", "# Import late to avoid circular imports.", "return", "gql", "(", "'SELECT * FROM %s %s'", "%", "(", "cls", ".", "_class...
Run a GQL query.
[ "Run", "a", "GQL", "query", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3442-L3446
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._put_async
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...
python
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", ")", ":", "if", "self", ".", "_projection", ":", "raise", "datastore_errors", ".", "BadRequestError", "(", "'Cannot put a partial entity'", ")", "from", ".", "import", "tasklets", "ctx", "=", "tas...
Write this entity to Cloud Datastore. This is the asynchronous version of Model._put().
[ "Write", "this", "entity", "to", "Cloud", "Datastore", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3461-L3478
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._get_or_insert
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...
python
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", ")", ":", "cls", ",", "args", "=", "args", "[", "0", "]", ",", "args", "[", "1", ":", "]", "return", "cls", ".", "_get_or_insert_async", "(", "*", "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_options: ContextOptions object (not keyword args...
[ "Transactionally", "retrieves", "an", "existing", "entity", "or", "creates", "a", "new", "one", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3482-L3503
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._get_or_insert_async
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'. ...
python
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", ")", ":", "# 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...
Transactionally retrieves an existing entity or creates a new one. This is the asynchronous version of Model._get_or_insert().
[ "Transactionally", "retrieves", "an", "existing", "entity", "or", "creates", "a", "new", "one", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3507-L3550
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._allocate_ids
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 ...
python
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", ")", ":", "return", "cls", ".", "_allocate_ids_async", "(", "size", "=", "size", ",", "max", "=", "max", ...
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_...
[ "Allocates", "a", "range", "of", "key", "IDs", "for", "this", "model", "class", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3555-L3570
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._allocate_ids_async
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...
python
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", ")", ":", "from", ".", "import", "tasklets", "ctx", "=", "tasklets", ".", "get_context", "(", ")", ...
Allocates a range of key IDs for this model class. This is the asynchronous version of Model._allocate_ids().
[ "Allocates", "a", "range", "of", "key", "IDs", "for", "this", "model", "class", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3574-L3589
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._get_by_id
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: ...
python
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", ")", ":", "return", "cls", ".", "_get_by_id_async", "(", "id", ",", "parent", "=", "parent", ",", "*", "*", "ctx_options", ")", ".", "get_result", "...
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. ...
[ "Returns", "an", "instance", "of", "Model", "class", "by", "ID", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3594-L3609
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._get_by_id_async
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...
python
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", ")", ":", "key", "=", "Key", "(", "cls", ".", "_get_kind", "(", ")", ",", "id", ",...
Returns an instance of Model class by ID (and app, namespace). This is the asynchronous version of Model._get_by_id().
[ "Returns", "an", "instance", "of", "Model", "class", "by", "ID", "(", "and", "app", "namespace", ")", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3614-L3621
GoogleCloudPlatform/datastore-ndb-python
ndb/model.py
Model._is_default_hook
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...
python
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", ")", ":", "if", "not", "hasattr", "(", "default_hook", ",", "'__call__'", ")", ":", "raise", "TypeError", "(", "'Default hooks for ndb.model.Model must be callable'", ")", "if", "not", "hasattr", "(", "h...
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 ...
[ "Checks", "whether", "a", "specific", "hook", "is", "in", "its", "default", "state", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/model.py#L3676-L3691
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
_ConstructReference
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...
python
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", ",", "p...
Construct a Reference; the signature is the same as for Key.
[ "Construct", "a", "Reference", ";", "the", "signature", "is", "the", "same", "as", "for", "Key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L633-L704
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
_ReferenceFromPairs
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 ...
python
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", ")", ":", "if", "reference", "is", "None", ":", "reference", "=", "entity_pb", ".", "Reference", "(", ")", "path", "=", "...
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.
[ "Construct", "a", "Reference", "from", "a", "list", "of", "pairs", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L707-L805
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
_ReferenceFromSerialized
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...
python
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", ")", ":", "if", "not", "isinstance", "(", "serialized", ",", "basestring", ")", ":", "raise", "TypeError", "(", "'serialized must be a string; received %r'", "%", "serialized", ")", "elif", "isinstance", "(", "se...
Construct a Reference from a serialized Reference.
[ "Construct", "a", "Reference", "from", "a", "serialized", "Reference", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L815-L821
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
_DecodeUrlSafe
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...
python
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", ")", ":", "if", "not", "isinstance", "(", "urlsafe", ",", "basestring", ")", ":", "raise", "TypeError", "(", "'urlsafe must be a string; received %r'", "%", "urlsafe", ")", "if", "isinstance", "(", "urlsafe", ",", "unicod...
Decode a url-safe base64-encoded string. This returns the decoded string.
[ "Decode", "a", "url", "-", "safe", "base64", "-", "encoded", "string", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L824-L837
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
Key._parse_from_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...
python
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", ",", "paren...
Construct a Reference; the signature is the same as for Key.
[ "Construct", "a", "Reference", ";", "the", "signature", "is", "the", "same", "as", "for", "Key", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L304-L353
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
Key.parent
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)
python
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", ")", ":", "pairs", "=", "self", ".", "__pairs", "if", "len", "(", "pairs", ")", "<=", "1", ":", "return", "None", "return", "Key", "(", "pairs", "=", "pairs", "[", ":", "-", "1", "]", ",", "app", "=", "self", ".", ...
Return a Key constructed from all but the last (kind, id) pairs. If there is only one (kind, id) pair, return None.
[ "Return", "a", "Key", "constructed", "from", "all", "but", "the", "last", "(", "kind", "id", ")", "pairs", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L460-L468
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
Key.string_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
python
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", ")", ":", "id", "=", "self", ".", "id", "(", ")", "if", "not", "isinstance", "(", "id", ",", "basestring", ")", ":", "id", "=", "None", "return", "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.
[ "Return", "the", "string", "id", "in", "the", "last", "(", "kind", "id", ")", "pair", "if", "any", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L493-L502
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
Key.integer_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
python
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", ")", ":", "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. Returns: An integer id, or None if the key has a string id or is incomplete.
[ "Return", "the", "integer", "id", "in", "the", "last", "(", "kind", "id", ")", "pair", "if", "any", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L504-L513
GoogleCloudPlatform/datastore-ndb-python
ndb/key.py
Key.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)
python
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", ")", ":", "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.
[ "Return", "a", "tuple", "of", "alternating", "kind", "and", "id", "values", "." ]
train
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L519-L525