partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | bind_parameter | Binds the parameter value specified by `binding_key` to `value`.
The `binding_key` argument should either be a string of the form
`maybe/scope/optional.module.names.configurable_name.parameter_name`, or a
list or tuple of `(scope, selector, parameter_name)`, where `selector`
corresponds to `optional.module.nam... | gin/config.py | def bind_parameter(binding_key, value):
"""Binds the parameter value specified by `binding_key` to `value`.
The `binding_key` argument should either be a string of the form
`maybe/scope/optional.module.names.configurable_name.parameter_name`, or a
list or tuple of `(scope, selector, parameter_name)`, where `se... | def bind_parameter(binding_key, value):
"""Binds the parameter value specified by `binding_key` to `value`.
The `binding_key` argument should either be a string of the form
`maybe/scope/optional.module.names.configurable_name.parameter_name`, or a
list or tuple of `(scope, selector, parameter_name)`, where `se... | [
"Binds",
"the",
"parameter",
"value",
"specified",
"by",
"binding_key",
"to",
"value",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L565-L602 | [
"def",
"bind_parameter",
"(",
"binding_key",
",",
"value",
")",
":",
"if",
"config_is_locked",
"(",
")",
":",
"raise",
"RuntimeError",
"(",
"'Attempted to modify locked Gin config.'",
")",
"pbk",
"=",
"ParsedBindingKey",
"(",
"binding_key",
")",
"fn_dict",
"=",
"_... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | query_parameter | Returns the currently bound value to the specified `binding_key`.
The `binding_key` argument should look like
'maybe/some/scope/maybe.moduels.configurable_name.parameter_name'. Note that
this will not include default parameters.
Args:
binding_key: The parameter whose value should be set.
Returns:
T... | gin/config.py | def query_parameter(binding_key):
"""Returns the currently bound value to the specified `binding_key`.
The `binding_key` argument should look like
'maybe/some/scope/maybe.moduels.configurable_name.parameter_name'. Note that
this will not include default parameters.
Args:
binding_key: The parameter whose... | def query_parameter(binding_key):
"""Returns the currently bound value to the specified `binding_key`.
The `binding_key` argument should look like
'maybe/some/scope/maybe.moduels.configurable_name.parameter_name'. Note that
this will not include default parameters.
Args:
binding_key: The parameter whose... | [
"Returns",
"the",
"currently",
"bound",
"value",
"to",
"the",
"specified",
"binding_key",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L605-L632 | [
"def",
"query_parameter",
"(",
"binding_key",
")",
":",
"pbk",
"=",
"ParsedBindingKey",
"(",
"binding_key",
")",
"if",
"pbk",
".",
"config_key",
"not",
"in",
"_CONFIG",
":",
"err_str",
"=",
"\"Configurable '{}' has no bound parameters.\"",
"raise",
"ValueError",
"("... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _might_have_parameter | Returns True if `arg_name` might be a valid parameter for `fn_or_cls`.
Specifically, this means that `fn_or_cls` either has a parameter named
`arg_name`, or has a `**kwargs` parameter.
Args:
fn_or_cls: The function or class to check.
arg_name: The name fo the parameter.
Returns:
Whether `arg_name... | gin/config.py | def _might_have_parameter(fn_or_cls, arg_name):
"""Returns True if `arg_name` might be a valid parameter for `fn_or_cls`.
Specifically, this means that `fn_or_cls` either has a parameter named
`arg_name`, or has a `**kwargs` parameter.
Args:
fn_or_cls: The function or class to check.
arg_name: The nam... | def _might_have_parameter(fn_or_cls, arg_name):
"""Returns True if `arg_name` might be a valid parameter for `fn_or_cls`.
Specifically, this means that `fn_or_cls` either has a parameter named
`arg_name`, or has a `**kwargs` parameter.
Args:
fn_or_cls: The function or class to check.
arg_name: The nam... | [
"Returns",
"True",
"if",
"arg_name",
"might",
"be",
"a",
"valid",
"parameter",
"for",
"fn_or_cls",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L635-L663 | [
"def",
"_might_have_parameter",
"(",
"fn_or_cls",
",",
"arg_name",
")",
":",
"if",
"inspect",
".",
"isclass",
"(",
"fn_or_cls",
")",
":",
"fn",
"=",
"_find_class_construction_fn",
"(",
"fn_or_cls",
")",
"else",
":",
"fn",
"=",
"fn_or_cls",
"while",
"hasattr",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _get_cached_arg_spec | Gets cached argspec for `fn`. | gin/config.py | def _get_cached_arg_spec(fn):
"""Gets cached argspec for `fn`."""
arg_spec = _ARG_SPEC_CACHE.get(fn)
if arg_spec is None:
arg_spec_fn = inspect.getfullargspec if six.PY3 else inspect.getargspec
try:
arg_spec = arg_spec_fn(fn)
except TypeError:
# `fn` might be a callable object.
arg_... | def _get_cached_arg_spec(fn):
"""Gets cached argspec for `fn`."""
arg_spec = _ARG_SPEC_CACHE.get(fn)
if arg_spec is None:
arg_spec_fn = inspect.getfullargspec if six.PY3 else inspect.getargspec
try:
arg_spec = arg_spec_fn(fn)
except TypeError:
# `fn` might be a callable object.
arg_... | [
"Gets",
"cached",
"argspec",
"for",
"fn",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L673-L685 | [
"def",
"_get_cached_arg_spec",
"(",
"fn",
")",
":",
"arg_spec",
"=",
"_ARG_SPEC_CACHE",
".",
"get",
"(",
"fn",
")",
"if",
"arg_spec",
"is",
"None",
":",
"arg_spec_fn",
"=",
"inspect",
".",
"getfullargspec",
"if",
"six",
".",
"PY3",
"else",
"inspect",
".",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _get_supplied_positional_parameter_names | Returns the names of the supplied arguments to the given function. | gin/config.py | def _get_supplied_positional_parameter_names(fn, args):
"""Returns the names of the supplied arguments to the given function."""
arg_spec = _get_cached_arg_spec(fn)
# May be shorter than len(args) if args contains vararg (*args) arguments.
return arg_spec.args[:len(args)] | def _get_supplied_positional_parameter_names(fn, args):
"""Returns the names of the supplied arguments to the given function."""
arg_spec = _get_cached_arg_spec(fn)
# May be shorter than len(args) if args contains vararg (*args) arguments.
return arg_spec.args[:len(args)] | [
"Returns",
"the",
"names",
"of",
"the",
"supplied",
"arguments",
"to",
"the",
"given",
"function",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L688-L692 | [
"def",
"_get_supplied_positional_parameter_names",
"(",
"fn",
",",
"args",
")",
":",
"arg_spec",
"=",
"_get_cached_arg_spec",
"(",
"fn",
")",
"# May be shorter than len(args) if args contains vararg (*args) arguments.",
"return",
"arg_spec",
".",
"args",
"[",
":",
"len",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _get_all_positional_parameter_names | Returns the names of all positional arguments to the given function. | gin/config.py | def _get_all_positional_parameter_names(fn):
"""Returns the names of all positional arguments to the given function."""
arg_spec = _get_cached_arg_spec(fn)
args = arg_spec.args
if arg_spec.defaults:
args = args[:-len(arg_spec.defaults)]
return args | def _get_all_positional_parameter_names(fn):
"""Returns the names of all positional arguments to the given function."""
arg_spec = _get_cached_arg_spec(fn)
args = arg_spec.args
if arg_spec.defaults:
args = args[:-len(arg_spec.defaults)]
return args | [
"Returns",
"the",
"names",
"of",
"all",
"positional",
"arguments",
"to",
"the",
"given",
"function",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L695-L701 | [
"def",
"_get_all_positional_parameter_names",
"(",
"fn",
")",
":",
"arg_spec",
"=",
"_get_cached_arg_spec",
"(",
"fn",
")",
"args",
"=",
"arg_spec",
".",
"args",
"if",
"arg_spec",
".",
"defaults",
":",
"args",
"=",
"args",
"[",
":",
"-",
"len",
"(",
"arg_s... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _get_default_configurable_parameter_values | Retrieve all default values for configurable parameters of a function.
Any parameters included in the supplied blacklist, or not included in the
supplied whitelist, are excluded.
Args:
fn: The function whose parameter values should be retrieved.
whitelist: The whitelist (or `None`) associated with the f... | gin/config.py | def _get_default_configurable_parameter_values(fn, whitelist, blacklist):
"""Retrieve all default values for configurable parameters of a function.
Any parameters included in the supplied blacklist, or not included in the
supplied whitelist, are excluded.
Args:
fn: The function whose parameter values shou... | def _get_default_configurable_parameter_values(fn, whitelist, blacklist):
"""Retrieve all default values for configurable parameters of a function.
Any parameters included in the supplied blacklist, or not included in the
supplied whitelist, are excluded.
Args:
fn: The function whose parameter values shou... | [
"Retrieve",
"all",
"default",
"values",
"for",
"configurable",
"parameters",
"of",
"a",
"function",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L704-L743 | [
"def",
"_get_default_configurable_parameter_values",
"(",
"fn",
",",
"whitelist",
",",
"blacklist",
")",
":",
"arg_vals",
"=",
"_ARG_DEFAULTS_CACHE",
".",
"get",
"(",
"fn",
")",
"if",
"arg_vals",
"is",
"not",
"None",
":",
"return",
"arg_vals",
".",
"copy",
"("... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | config_scope | Opens a new configuration scope.
Provides a context manager that opens a new explicit configuration
scope. Explicit configuration scopes restrict parameter bindings to only
certain sections of code that run within the scope. Scopes can be nested to
arbitrary depth; any configurable functions called within a sc... | gin/config.py | def config_scope(name_or_scope):
"""Opens a new configuration scope.
Provides a context manager that opens a new explicit configuration
scope. Explicit configuration scopes restrict parameter bindings to only
certain sections of code that run within the scope. Scopes can be nested to
arbitrary depth; any con... | def config_scope(name_or_scope):
"""Opens a new configuration scope.
Provides a context manager that opens a new explicit configuration
scope. Explicit configuration scopes restrict parameter bindings to only
certain sections of code that run within the scope. Scopes can be nested to
arbitrary depth; any con... | [
"Opens",
"a",
"new",
"configuration",
"scope",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L755-L835 | [
"def",
"config_scope",
"(",
"name_or_scope",
")",
":",
"try",
":",
"valid_value",
"=",
"True",
"if",
"isinstance",
"(",
"name_or_scope",
",",
"list",
")",
":",
"new_scope",
"=",
"name_or_scope",
"elif",
"name_or_scope",
"and",
"isinstance",
"(",
"name_or_scope",... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _make_configurable | Wraps `fn_or_cls` to make it configurable.
Infers the configurable name from `fn_or_cls.__name__` if necessary, and
updates global state to keep track of configurable name <-> function
mappings, as well as whitelisted and blacklisted parameters.
Args:
fn_or_cls: The function or class to decorate.
name... | gin/config.py | def _make_configurable(fn_or_cls,
name=None,
module=None,
whitelist=None,
blacklist=None,
subclass=False):
"""Wraps `fn_or_cls` to make it configurable.
Infers the configurable name from `fn_or_cls.__... | def _make_configurable(fn_or_cls,
name=None,
module=None,
whitelist=None,
blacklist=None,
subclass=False):
"""Wraps `fn_or_cls` to make it configurable.
Infers the configurable name from `fn_or_cls.__... | [
"Wraps",
"fn_or_cls",
"to",
"make",
"it",
"configurable",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L838-L1046 | [
"def",
"_make_configurable",
"(",
"fn_or_cls",
",",
"name",
"=",
"None",
",",
"module",
"=",
"None",
",",
"whitelist",
"=",
"None",
",",
"blacklist",
"=",
"None",
",",
"subclass",
"=",
"False",
")",
":",
"if",
"config_is_locked",
"(",
")",
":",
"err_str"... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | configurable | Decorator to make a function or class configurable.
This decorator registers the decorated function/class as configurable, which
allows its parameters to be supplied from the global configuration (i.e., set
through `bind_parameter` or `parse_config`). The decorated function is
associated with a name in the glo... | gin/config.py | def configurable(name_or_fn=None, module=None, whitelist=None, blacklist=None):
"""Decorator to make a function or class configurable.
This decorator registers the decorated function/class as configurable, which
allows its parameters to be supplied from the global configuration (i.e., set
through `bind_paramet... | def configurable(name_or_fn=None, module=None, whitelist=None, blacklist=None):
"""Decorator to make a function or class configurable.
This decorator registers the decorated function/class as configurable, which
allows its parameters to be supplied from the global configuration (i.e., set
through `bind_paramet... | [
"Decorator",
"to",
"make",
"a",
"function",
"or",
"class",
"configurable",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1049-L1130 | [
"def",
"configurable",
"(",
"name_or_fn",
"=",
"None",
",",
"module",
"=",
"None",
",",
"whitelist",
"=",
"None",
",",
"blacklist",
"=",
"None",
")",
":",
"decoration_target",
"=",
"None",
"if",
"callable",
"(",
"name_or_fn",
")",
":",
"decoration_target",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | external_configurable | Allow referencing/configuring an external class or function.
This alerts Gin to the existence of the class or function `fn_or_cls` in the
event that it can't be easily annotated with `@configurable` (for instance, if
it is from another project). This allows `fn_or_cls` to be configured and
referenced (using th... | gin/config.py | def external_configurable(fn_or_cls,
name=None,
module=None,
whitelist=None,
blacklist=None):
"""Allow referencing/configuring an external class or function.
This alerts Gin to the existence of the class or func... | def external_configurable(fn_or_cls,
name=None,
module=None,
whitelist=None,
blacklist=None):
"""Allow referencing/configuring an external class or function.
This alerts Gin to the existence of the class or func... | [
"Allow",
"referencing",
"/",
"configuring",
"an",
"external",
"class",
"or",
"function",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1133-L1174 | [
"def",
"external_configurable",
"(",
"fn_or_cls",
",",
"name",
"=",
"None",
",",
"module",
"=",
"None",
",",
"whitelist",
"=",
"None",
",",
"blacklist",
"=",
"None",
")",
":",
"return",
"_make_configurable",
"(",
"fn_or_cls",
",",
"name",
"=",
"name",
",",... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | operative_config_str | Retrieve the "operative" configuration as a config string.
The operative configuration consists of all parameter values used by
configurable functions that are actually called during execution of the
current program. Parameters associated with configurable functions that are
not called (and so can have no effe... | gin/config.py | def operative_config_str(max_line_length=80, continuation_indent=4):
"""Retrieve the "operative" configuration as a config string.
The operative configuration consists of all parameter values used by
configurable functions that are actually called during execution of the
current program. Parameters associated ... | def operative_config_str(max_line_length=80, continuation_indent=4):
"""Retrieve the "operative" configuration as a config string.
The operative configuration consists of all parameter values used by
configurable functions that are actually called during execution of the
current program. Parameters associated ... | [
"Retrieve",
"the",
"operative",
"configuration",
"as",
"a",
"config",
"string",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1177-L1268 | [
"def",
"operative_config_str",
"(",
"max_line_length",
"=",
"80",
",",
"continuation_indent",
"=",
"4",
")",
":",
"def",
"format_binding",
"(",
"key",
",",
"value",
")",
":",
"\"\"\"Pretty print the given key/value pair.\"\"\"",
"formatted_val",
"=",
"pprint",
".",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | parse_config | Parse a file, string, or list of strings containing parameter bindings.
Parses parameter binding strings to set up the global configuration. Once
`parse_config` has been called, any calls to configurable functions will have
parameter values set according to the values specified by the parameter
bindings in `b... | gin/config.py | def parse_config(bindings, skip_unknown=False):
"""Parse a file, string, or list of strings containing parameter bindings.
Parses parameter binding strings to set up the global configuration. Once
`parse_config` has been called, any calls to configurable functions will have
parameter values set according to t... | def parse_config(bindings, skip_unknown=False):
"""Parse a file, string, or list of strings containing parameter bindings.
Parses parameter binding strings to set up the global configuration. Once
`parse_config` has been called, any calls to configurable functions will have
parameter values set according to t... | [
"Parse",
"a",
"file",
"string",
"or",
"list",
"of",
"strings",
"containing",
"parameter",
"bindings",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1271-L1379 | [
"def",
"parse_config",
"(",
"bindings",
",",
"skip_unknown",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"bindings",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"bindings",
"=",
"'\\n'",
".",
"join",
"(",
"bindings",
")",
"_validate_skip_unknown",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | register_file_reader | Register a file reader for use in parse_config_file.
Registered file readers will be used to try reading files passed to
`parse_config_file`. All file readers (beginning with the default `open`) will
be tried until one of them succeeds at opening the file.
This function may also be be used used as a decorator... | gin/config.py | def register_file_reader(*args):
"""Register a file reader for use in parse_config_file.
Registered file readers will be used to try reading files passed to
`parse_config_file`. All file readers (beginning with the default `open`) will
be tried until one of them succeeds at opening the file.
This function m... | def register_file_reader(*args):
"""Register a file reader for use in parse_config_file.
Registered file readers will be used to try reading files passed to
`parse_config_file`. All file readers (beginning with the default `open`) will
be tried until one of them succeeds at opening the file.
This function m... | [
"Register",
"a",
"file",
"reader",
"for",
"use",
"in",
"parse_config_file",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1382-L1417 | [
"def",
"register_file_reader",
"(",
"*",
"args",
")",
":",
"def",
"do_registration",
"(",
"file_reader_fn",
",",
"is_readable_fn",
")",
":",
"if",
"file_reader_fn",
"not",
"in",
"list",
"(",
"zip",
"(",
"*",
"_FILE_READERS",
")",
")",
"[",
"0",
"]",
":",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | parse_config_file | Parse a Gin config file.
Args:
config_file: The path to a Gin config file.
skip_unknown: A boolean indicating whether unknown configurables and imports
should be skipped instead of causing errors (alternatively a list of
configurable names to skip if unknown). See `parse_config` for additional
... | gin/config.py | def parse_config_file(config_file, skip_unknown=False):
"""Parse a Gin config file.
Args:
config_file: The path to a Gin config file.
skip_unknown: A boolean indicating whether unknown configurables and imports
should be skipped instead of causing errors (alternatively a list of
configurable na... | def parse_config_file(config_file, skip_unknown=False):
"""Parse a Gin config file.
Args:
config_file: The path to a Gin config file.
skip_unknown: A boolean indicating whether unknown configurables and imports
should be skipped instead of causing errors (alternatively a list of
configurable na... | [
"Parse",
"a",
"Gin",
"config",
"file",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1420-L1438 | [
"def",
"parse_config_file",
"(",
"config_file",
",",
"skip_unknown",
"=",
"False",
")",
":",
"for",
"reader",
",",
"existence_check",
"in",
"_FILE_READERS",
":",
"if",
"existence_check",
"(",
"config_file",
")",
":",
"with",
"reader",
"(",
"config_file",
")",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | parse_config_files_and_bindings | Parse a list of config files followed by extra Gin bindings.
This function is equivalent to:
for config_file in config_files:
gin.parse_config_file(config_file, skip_configurables)
gin.parse_config(bindings, skip_configurables)
if finalize_config:
gin.finalize()
Args:
config... | gin/config.py | def parse_config_files_and_bindings(config_files,
bindings,
finalize_config=True,
skip_unknown=False):
"""Parse a list of config files followed by extra Gin bindings.
This function is equivalent to:
f... | def parse_config_files_and_bindings(config_files,
bindings,
finalize_config=True,
skip_unknown=False):
"""Parse a list of config files followed by extra Gin bindings.
This function is equivalent to:
f... | [
"Parse",
"a",
"list",
"of",
"config",
"files",
"followed",
"by",
"extra",
"Gin",
"bindings",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1441-L1473 | [
"def",
"parse_config_files_and_bindings",
"(",
"config_files",
",",
"bindings",
",",
"finalize_config",
"=",
"True",
",",
"skip_unknown",
"=",
"False",
")",
":",
"if",
"config_files",
"is",
"None",
":",
"config_files",
"=",
"[",
"]",
"if",
"bindings",
"is",
"N... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | parse_value | Parse and return a single Gin value. | gin/config.py | def parse_value(value):
"""Parse and return a single Gin value."""
if not isinstance(value, six.string_types):
raise ValueError('value ({}) should be a string type.'.format(value))
return config_parser.ConfigParser(value, ParserDelegate()).parse_value() | def parse_value(value):
"""Parse and return a single Gin value."""
if not isinstance(value, six.string_types):
raise ValueError('value ({}) should be a string type.'.format(value))
return config_parser.ConfigParser(value, ParserDelegate()).parse_value() | [
"Parse",
"and",
"return",
"a",
"single",
"Gin",
"value",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1476-L1480 | [
"def",
"parse_value",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
":",
"raise",
"ValueError",
"(",
"'value ({}) should be a string type.'",
".",
"format",
"(",
"value",
")",
")",
"return",
"config_pars... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | finalize | A function that should be called after parsing all Gin config files.
Calling this function allows registered "finalize hooks" to inspect (and
potentially modify) the Gin config, to provide additional functionality. Hooks
should not modify the configuration object they receive directly; instead,
they should ret... | gin/config.py | def finalize():
"""A function that should be called after parsing all Gin config files.
Calling this function allows registered "finalize hooks" to inspect (and
potentially modify) the Gin config, to provide additional functionality. Hooks
should not modify the configuration object they receive directly; inste... | def finalize():
"""A function that should be called after parsing all Gin config files.
Calling this function allows registered "finalize hooks" to inspect (and
potentially modify) the Gin config, to provide additional functionality. Hooks
should not modify the configuration object they receive directly; inste... | [
"A",
"function",
"that",
"should",
"be",
"called",
"after",
"parsing",
"all",
"Gin",
"config",
"files",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1534-L1566 | [
"def",
"finalize",
"(",
")",
":",
"if",
"config_is_locked",
"(",
")",
":",
"raise",
"RuntimeError",
"(",
"'Finalize called twice (config already locked).'",
")",
"bindings",
"=",
"{",
"}",
"for",
"hook",
"in",
"_FINALIZE_HOOKS",
":",
"new_bindings",
"=",
"hook",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | _iterate_flattened_values | Provides an iterator over all values in a nested structure. | gin/config.py | def _iterate_flattened_values(value):
"""Provides an iterator over all values in a nested structure."""
if isinstance(value, six.string_types):
yield value
return
if isinstance(value, collections.Mapping):
value = collections.ValuesView(value)
if isinstance(value, collections.Iterable):
for ne... | def _iterate_flattened_values(value):
"""Provides an iterator over all values in a nested structure."""
if isinstance(value, six.string_types):
yield value
return
if isinstance(value, collections.Mapping):
value = collections.ValuesView(value)
if isinstance(value, collections.Iterable):
for ne... | [
"Provides",
"an",
"iterator",
"over",
"all",
"values",
"in",
"a",
"nested",
"structure",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1586-L1600 | [
"def",
"_iterate_flattened_values",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
":",
"yield",
"value",
"return",
"if",
"isinstance",
"(",
"value",
",",
"collections",
".",
"Mapping",
")",
":",
"value",
"=... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | iterate_references | Provides an iterator over references in the given config.
Args:
config: A dictionary mapping scoped configurable names to argument bindings.
to: If supplied, only yield references whose `configurable_fn` matches `to`.
Yields:
`ConfigurableReference` instances within `config`, maybe restricted to those... | gin/config.py | def iterate_references(config, to=None):
"""Provides an iterator over references in the given config.
Args:
config: A dictionary mapping scoped configurable names to argument bindings.
to: If supplied, only yield references whose `configurable_fn` matches `to`.
Yields:
`ConfigurableReference` instan... | def iterate_references(config, to=None):
"""Provides an iterator over references in the given config.
Args:
config: A dictionary mapping scoped configurable names to argument bindings.
to: If supplied, only yield references whose `configurable_fn` matches `to`.
Yields:
`ConfigurableReference` instan... | [
"Provides",
"an",
"iterator",
"over",
"references",
"in",
"the",
"given",
"config",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1603-L1617 | [
"def",
"iterate_references",
"(",
"config",
",",
"to",
"=",
"None",
")",
":",
"for",
"value",
"in",
"_iterate_flattened_values",
"(",
"config",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"ConfigurableReference",
")",
":",
"if",
"to",
"is",
"None",
"o... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | constant | Creates a constant that can be referenced from gin config files.
After calling this function in Python, the constant can be referenced from
within a Gin config file using the macro syntax. For example, in Python:
gin.constant('THE_ANSWER', 42)
Then, in a Gin config file:
meaning.of_life = %THE_ANS... | gin/config.py | def constant(name, value):
"""Creates a constant that can be referenced from gin config files.
After calling this function in Python, the constant can be referenced from
within a Gin config file using the macro syntax. For example, in Python:
gin.constant('THE_ANSWER', 42)
Then, in a Gin config file:
... | def constant(name, value):
"""Creates a constant that can be referenced from gin config files.
After calling this function in Python, the constant can be referenced from
within a Gin config file using the macro syntax. For example, in Python:
gin.constant('THE_ANSWER', 42)
Then, in a Gin config file:
... | [
"Creates",
"a",
"constant",
"that",
"can",
"be",
"referenced",
"from",
"gin",
"config",
"files",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1659-L1700 | [
"def",
"constant",
"(",
"name",
",",
"value",
")",
":",
"if",
"not",
"config_parser",
".",
"MODULE_RE",
".",
"match",
"(",
"name",
")",
":",
"raise",
"ValueError",
"(",
"\"Invalid constant selector '{}'.\"",
".",
"format",
"(",
"name",
")",
")",
"if",
"_CO... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | constants_from_enum | Decorator for an enum class that generates Gin constants from values.
Generated constants have format `module.ClassName.ENUM_VALUE`. The module
name is optional when using the constant.
Args:
cls: Class type.
module: The module to associate with the constants, to help handle naming
collisions. If ... | gin/config.py | def constants_from_enum(cls, module=None):
"""Decorator for an enum class that generates Gin constants from values.
Generated constants have format `module.ClassName.ENUM_VALUE`. The module
name is optional when using the constant.
Args:
cls: Class type.
module: The module to associate with the consta... | def constants_from_enum(cls, module=None):
"""Decorator for an enum class that generates Gin constants from values.
Generated constants have format `module.ClassName.ENUM_VALUE`. The module
name is optional when using the constant.
Args:
cls: Class type.
module: The module to associate with the consta... | [
"Decorator",
"for",
"an",
"enum",
"class",
"that",
"generates",
"Gin",
"constants",
"from",
"values",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1703-L1727 | [
"def",
"constants_from_enum",
"(",
"cls",
",",
"module",
"=",
"None",
")",
":",
"if",
"not",
"issubclass",
"(",
"cls",
",",
"enum",
".",
"Enum",
")",
":",
"raise",
"TypeError",
"(",
"\"Class '{}' is not subclass of enum.\"",
".",
"format",
"(",
"cls",
".",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | find_unknown_references_hook | Hook to find/raise errors for references to unknown configurables. | gin/config.py | def find_unknown_references_hook(config):
"""Hook to find/raise errors for references to unknown configurables."""
additional_msg_fmt = " In binding for '{}'."
for (scope, selector), param_bindings in six.iteritems(config):
for param_name, param_value in six.iteritems(param_bindings):
for maybe_unknown ... | def find_unknown_references_hook(config):
"""Hook to find/raise errors for references to unknown configurables."""
additional_msg_fmt = " In binding for '{}'."
for (scope, selector), param_bindings in six.iteritems(config):
for param_name, param_value in six.iteritems(param_bindings):
for maybe_unknown ... | [
"Hook",
"to",
"find",
"/",
"raise",
"errors",
"for",
"references",
"to",
"unknown",
"configurables",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/config.py#L1737-L1748 | [
"def",
"find_unknown_references_hook",
"(",
"config",
")",
":",
"additional_msg_fmt",
"=",
"\" In binding for '{}'.\"",
"for",
"(",
"scope",
",",
"selector",
")",
",",
"param_bindings",
"in",
"six",
".",
"iteritems",
"(",
"config",
")",
":",
"for",
"param_name",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | SelectorMap.matching_selectors | Retrieves all selectors matching `partial_selector`.
For instance, if "one.a.b" and "two.a.b" are stored in a `SelectorMap`, both
`matching_selectors('b')` and `matching_selectors('a.b')` will return them.
In the event that `partial_selector` exactly matches an existing complete
selector, only that co... | gin/selector_map.py | def matching_selectors(self, partial_selector):
"""Retrieves all selectors matching `partial_selector`.
For instance, if "one.a.b" and "two.a.b" are stored in a `SelectorMap`, both
`matching_selectors('b')` and `matching_selectors('a.b')` will return them.
In the event that `partial_selector` exactly ... | def matching_selectors(self, partial_selector):
"""Retrieves all selectors matching `partial_selector`.
For instance, if "one.a.b" and "two.a.b" are stored in a `SelectorMap`, both
`matching_selectors('b')` and `matching_selectors('a.b')` will return them.
In the event that `partial_selector` exactly ... | [
"Retrieves",
"all",
"selectors",
"matching",
"partial_selector",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/selector_map.py#L117-L154 | [
"def",
"matching_selectors",
"(",
"self",
",",
"partial_selector",
")",
":",
"if",
"partial_selector",
"in",
"self",
".",
"_selector_map",
":",
"return",
"[",
"partial_selector",
"]",
"selector_components",
"=",
"partial_selector",
".",
"split",
"(",
"'.'",
")",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | SelectorMap.get_match | Gets a (single) value matching `partial_selector`.
If the partial_selector exactly matches a complete selector, the value
associated with the complete selector is returned.
Args:
partial_selector: The partial selector to find values for.
default: A default value to return if nothing matches `p... | gin/selector_map.py | def get_match(self, partial_selector, default=None):
"""Gets a (single) value matching `partial_selector`.
If the partial_selector exactly matches a complete selector, the value
associated with the complete selector is returned.
Args:
partial_selector: The partial selector to find values for.
... | def get_match(self, partial_selector, default=None):
"""Gets a (single) value matching `partial_selector`.
If the partial_selector exactly matches a complete selector, the value
associated with the complete selector is returned.
Args:
partial_selector: The partial selector to find values for.
... | [
"Gets",
"a",
"(",
"single",
")",
"value",
"matching",
"partial_selector",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/selector_map.py#L156-L178 | [
"def",
"get_match",
"(",
"self",
",",
"partial_selector",
",",
"default",
"=",
"None",
")",
":",
"matching_selectors",
"=",
"self",
".",
"matching_selectors",
"(",
"partial_selector",
")",
"if",
"not",
"matching_selectors",
":",
"return",
"default",
"if",
"len",... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | SelectorMap.get_all_matches | Returns all values matching `partial_selector` as a list. | gin/selector_map.py | def get_all_matches(self, partial_selector):
"""Returns all values matching `partial_selector` as a list."""
matching_selectors = self.matching_selectors(partial_selector)
return [self._selector_map[selector] for selector in matching_selectors] | def get_all_matches(self, partial_selector):
"""Returns all values matching `partial_selector` as a list."""
matching_selectors = self.matching_selectors(partial_selector)
return [self._selector_map[selector] for selector in matching_selectors] | [
"Returns",
"all",
"values",
"matching",
"partial_selector",
"as",
"a",
"list",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/selector_map.py#L180-L183 | [
"def",
"get_all_matches",
"(",
"self",
",",
"partial_selector",
")",
":",
"matching_selectors",
"=",
"self",
".",
"matching_selectors",
"(",
"partial_selector",
")",
"return",
"[",
"self",
".",
"_selector_map",
"[",
"selector",
"]",
"for",
"selector",
"in",
"mat... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | SelectorMap.minimal_selector | Returns the minimal selector that uniquely matches `complete_selector`.
Args:
complete_selector: A complete selector stored in the map.
Returns:
A partial selector that unambiguously matches `complete_selector`.
Raises:
KeyError: If `complete_selector` is not in the map. | gin/selector_map.py | def minimal_selector(self, complete_selector):
"""Returns the minimal selector that uniquely matches `complete_selector`.
Args:
complete_selector: A complete selector stored in the map.
Returns:
A partial selector that unambiguously matches `complete_selector`.
Raises:
KeyError: If ... | def minimal_selector(self, complete_selector):
"""Returns the minimal selector that uniquely matches `complete_selector`.
Args:
complete_selector: A complete selector stored in the map.
Returns:
A partial selector that unambiguously matches `complete_selector`.
Raises:
KeyError: If ... | [
"Returns",
"the",
"minimal",
"selector",
"that",
"uniquely",
"matches",
"complete_selector",
"."
] | google/gin-config | python | https://github.com/google/gin-config/blob/17a170e0a6711005d1c78e67cf493dc44674d44f/gin/selector_map.py#L185-L214 | [
"def",
"minimal_selector",
"(",
"self",
",",
"complete_selector",
")",
":",
"if",
"complete_selector",
"not",
"in",
"self",
".",
"_selector_map",
":",
"raise",
"KeyError",
"(",
"\"No value with selector '{}'.\"",
".",
"format",
"(",
"complete_selector",
")",
")",
... | 17a170e0a6711005d1c78e67cf493dc44674d44f |
test | sp_search_query | Translate a Mopidy search query to a Spotify search query | mopidy_spotify/translator.py | def sp_search_query(query):
"""Translate a Mopidy search query to a Spotify search query"""
result = []
for (field, values) in query.items():
field = SEARCH_FIELD_MAP.get(field, field)
if field is None:
continue
for value in values:
if field == 'year':
... | def sp_search_query(query):
"""Translate a Mopidy search query to a Spotify search query"""
result = []
for (field, values) in query.items():
field = SEARCH_FIELD_MAP.get(field, field)
if field is None:
continue
for value in values:
if field == 'year':
... | [
"Translate",
"a",
"Mopidy",
"search",
"query",
"to",
"a",
"Spotify",
"search",
"query"
] | mopidy/mopidy-spotify | python | https://github.com/mopidy/mopidy-spotify/blob/77a293088e63a7b4b77bf9409ce57cb14048d18c/mopidy_spotify/translator.py#L205-L225 | [
"def",
"sp_search_query",
"(",
"query",
")",
":",
"result",
"=",
"[",
"]",
"for",
"(",
"field",
",",
"values",
")",
"in",
"query",
".",
"items",
"(",
")",
":",
"field",
"=",
"SEARCH_FIELD_MAP",
".",
"get",
"(",
"field",
",",
"field",
")",
"if",
"fi... | 77a293088e63a7b4b77bf9409ce57cb14048d18c |
test | OAuthClient._parse_retry_after | Parse Retry-After header from response if it is set. | mopidy_spotify/web.py | def _parse_retry_after(self, response):
"""Parse Retry-After header from response if it is set."""
value = response.headers.get('Retry-After')
if not value:
seconds = 0
elif re.match(r'^\s*[0-9]+\s*$', value):
seconds = int(value)
else:
date_t... | def _parse_retry_after(self, response):
"""Parse Retry-After header from response if it is set."""
value = response.headers.get('Retry-After')
if not value:
seconds = 0
elif re.match(r'^\s*[0-9]+\s*$', value):
seconds = int(value)
else:
date_t... | [
"Parse",
"Retry",
"-",
"After",
"header",
"from",
"response",
"if",
"it",
"is",
"set",
"."
] | mopidy/mopidy-spotify | python | https://github.com/mopidy/mopidy-spotify/blob/77a293088e63a7b4b77bf9409ce57cb14048d18c/mopidy_spotify/web.py#L196-L210 | [
"def",
"_parse_retry_after",
"(",
"self",
",",
"response",
")",
":",
"value",
"=",
"response",
".",
"headers",
".",
"get",
"(",
"'Retry-After'",
")",
"if",
"not",
"value",
":",
"seconds",
"=",
"0",
"elif",
"re",
".",
"match",
"(",
"r'^\\s*[0-9]+\\s*$'",
... | 77a293088e63a7b4b77bf9409ce57cb14048d18c |
test | Property.validate_value | Validate new property value before setting it.
value -- New value | webthing/property.py | def validate_value(self, value):
"""
Validate new property value before setting it.
value -- New value
"""
if 'readOnly' in self.metadata and self.metadata['readOnly']:
raise PropertyError('Read-only property')
try:
validate(value, self.metadata)... | def validate_value(self, value):
"""
Validate new property value before setting it.
value -- New value
"""
if 'readOnly' in self.metadata and self.metadata['readOnly']:
raise PropertyError('Read-only property')
try:
validate(value, self.metadata)... | [
"Validate",
"new",
"property",
"value",
"before",
"setting",
"it",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/property.py#L34-L46 | [
"def",
"validate_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"'readOnly'",
"in",
"self",
".",
"metadata",
"and",
"self",
".",
"metadata",
"[",
"'readOnly'",
"]",
":",
"raise",
"PropertyError",
"(",
"'Read-only property'",
")",
"try",
":",
"validate",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Property.as_property_description | Get the property description.
Returns a dictionary describing the property. | webthing/property.py | def as_property_description(self):
"""
Get the property description.
Returns a dictionary describing the property.
"""
description = deepcopy(self.metadata)
if 'links' not in description:
description['links'] = []
description['links'].append(
... | def as_property_description(self):
"""
Get the property description.
Returns a dictionary describing the property.
"""
description = deepcopy(self.metadata)
if 'links' not in description:
description['links'] = []
description['links'].append(
... | [
"Get",
"the",
"property",
"description",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/property.py#L48-L65 | [
"def",
"as_property_description",
"(",
"self",
")",
":",
"description",
"=",
"deepcopy",
"(",
"self",
".",
"metadata",
")",
"if",
"'links'",
"not",
"in",
"description",
":",
"description",
"[",
"'links'",
"]",
"=",
"[",
"]",
"description",
"[",
"'links'",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Property.set_value | Set the current value of the property.
value -- the value to set | webthing/property.py | def set_value(self, value):
"""
Set the current value of the property.
value -- the value to set
"""
self.validate_value(value)
self.value.set(value) | def set_value(self, value):
"""
Set the current value of the property.
value -- the value to set
"""
self.validate_value(value)
self.value.set(value) | [
"Set",
"the",
"current",
"value",
"of",
"the",
"property",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/property.py#L91-L98 | [
"def",
"set_value",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"validate_value",
"(",
"value",
")",
"self",
".",
"value",
".",
"set",
"(",
"value",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | MultipleThings.get_thing | Get the thing at the given index.
idx -- the index | webthing/server.py | def get_thing(self, idx):
"""
Get the thing at the given index.
idx -- the index
"""
try:
idx = int(idx)
except ValueError:
return None
if idx < 0 or idx >= len(self.things):
return None
return self.things[idx] | def get_thing(self, idx):
"""
Get the thing at the given index.
idx -- the index
"""
try:
idx = int(idx)
except ValueError:
return None
if idx < 0 or idx >= len(self.things):
return None
return self.things[idx] | [
"Get",
"the",
"thing",
"at",
"the",
"given",
"index",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L60-L74 | [
"def",
"get_thing",
"(",
"self",
",",
"idx",
")",
":",
"try",
":",
"idx",
"=",
"int",
"(",
"idx",
")",
"except",
"ValueError",
":",
"return",
"None",
"if",
"idx",
"<",
"0",
"or",
"idx",
">=",
"len",
"(",
"self",
".",
"things",
")",
":",
"return",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | BaseHandler.initialize | Initialize the handler.
things -- list of Things managed by this server
hosts -- list of allowed hostnames | webthing/server.py | def initialize(self, things, hosts):
"""
Initialize the handler.
things -- list of Things managed by this server
hosts -- list of allowed hostnames
"""
self.things = things
self.hosts = hosts | def initialize(self, things, hosts):
"""
Initialize the handler.
things -- list of Things managed by this server
hosts -- list of allowed hostnames
"""
self.things = things
self.hosts = hosts | [
"Initialize",
"the",
"handler",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L88-L96 | [
"def",
"initialize",
"(",
"self",
",",
"things",
",",
"hosts",
")",
":",
"self",
".",
"things",
"=",
"things",
"self",
".",
"hosts",
"=",
"hosts"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | BaseHandler.set_default_headers | Set the default headers for all requests. | webthing/server.py | def set_default_headers(self, *args, **kwargs):
"""Set the default headers for all requests."""
self.set_header('Access-Control-Allow-Origin', '*')
self.set_header('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept')
self.set_header('A... | def set_default_headers(self, *args, **kwargs):
"""Set the default headers for all requests."""
self.set_header('Access-Control-Allow-Origin', '*')
self.set_header('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept')
self.set_header('A... | [
"Set",
"the",
"default",
"headers",
"for",
"all",
"requests",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L116-L122 | [
"def",
"set_default_headers",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"set_header",
"(",
"'Access-Control-Allow-Origin'",
",",
"'*'",
")",
"self",
".",
"set_header",
"(",
"'Access-Control-Allow-Headers'",
",",
"'Origin, X-R... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ThingsHandler.get | Handle a GET request.
property_name -- the name of the property from the URL path | webthing/server.py | def get(self):
"""
Handle a GET request.
property_name -- the name of the property from the URL path
"""
self.set_header('Content-Type', 'application/json')
ws_href = '{}://{}'.format(
'wss' if self.request.protocol == 'https' else 'ws',
self.requ... | def get(self):
"""
Handle a GET request.
property_name -- the name of the property from the URL path
"""
self.set_header('Content-Type', 'application/json')
ws_href = '{}://{}'.format(
'wss' if self.request.protocol == 'https' else 'ws',
self.requ... | [
"Handle",
"a",
"GET",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L128-L149 | [
"def",
"get",
"(",
"self",
")",
":",
"self",
".",
"set_header",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
"ws_href",
"=",
"'{}://{}'",
".",
"format",
"(",
"'wss'",
"if",
"self",
".",
"request",
".",
"protocol",
"==",
"'https'",
"else",
"'ws'",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ThingHandler.prepare | Validate Host header. | webthing/server.py | def prepare(self):
"""Validate Host header."""
host = self.request.headers.get('Host', None)
if host is not None and host in self.hosts:
return
raise tornado.web.HTTPError(403) | def prepare(self):
"""Validate Host header."""
host = self.request.headers.get('Host', None)
if host is not None and host in self.hosts:
return
raise tornado.web.HTTPError(403) | [
"Validate",
"Host",
"header",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L165-L171 | [
"def",
"prepare",
"(",
"self",
")",
":",
"host",
"=",
"self",
".",
"request",
".",
"headers",
".",
"get",
"(",
"'Host'",
",",
"None",
")",
"if",
"host",
"is",
"not",
"None",
"and",
"host",
"in",
"self",
".",
"hosts",
":",
"return",
"raise",
"tornad... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ThingHandler.get | Handle a GET request, including websocket requests.
thing_id -- ID of the thing this request is for | webthing/server.py | def get(self, thing_id='0'):
"""
Handle a GET request, including websocket requests.
thing_id -- ID of the thing this request is for
"""
self.thing = self.get_thing(thing_id)
if self.thing is None:
self.set_status(404)
self.finish()
re... | def get(self, thing_id='0'):
"""
Handle a GET request, including websocket requests.
thing_id -- ID of the thing this request is for
"""
self.thing = self.get_thing(thing_id)
if self.thing is None:
self.set_status(404)
self.finish()
re... | [
"Handle",
"a",
"GET",
"request",
"including",
"websocket",
"requests",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L192-L221 | [
"def",
"get",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
")",
":",
"self",
".",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"self",
".",
"thing",
"is",
"None",
":",
"self",
".",
"set_status",
"(",
"404",
")",
"self",
".",
"... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ThingHandler.on_message | Handle an incoming message.
message -- message to handle | webthing/server.py | def on_message(self, message):
"""
Handle an incoming message.
message -- message to handle
"""
try:
message = json.loads(message)
except ValueError:
try:
self.write_message(json.dumps({
'messageType': 'error',
... | def on_message(self, message):
"""
Handle an incoming message.
message -- message to handle
"""
try:
message = json.loads(message)
except ValueError:
try:
self.write_message(json.dumps({
'messageType': 'error',
... | [
"Handle",
"an",
"incoming",
"message",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L227-L311 | [
"def",
"on_message",
"(",
"self",
",",
"message",
")",
":",
"try",
":",
"message",
"=",
"json",
".",
"loads",
"(",
"message",
")",
"except",
"ValueError",
":",
"try",
":",
"self",
".",
"write_message",
"(",
"json",
".",
"dumps",
"(",
"{",
"'messageType... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | PropertyHandler.get | Handle a GET request.
thing_id -- ID of the thing this request is for
property_name -- the name of the property from the URL path | webthing/server.py | def get(self, thing_id='0', property_name=None):
"""
Handle a GET request.
thing_id -- ID of the thing this request is for
property_name -- the name of the property from the URL path
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_stat... | def get(self, thing_id='0', property_name=None):
"""
Handle a GET request.
thing_id -- ID of the thing this request is for
property_name -- the name of the property from the URL path
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_stat... | [
"Handle",
"a",
"GET",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L343-L361 | [
"def",
"get",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
",",
"property_name",
"=",
"None",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_status",
"(",
"404",
")",
"return",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | PropertyHandler.put | Handle a PUT request.
thing_id -- ID of the thing this request is for
property_name -- the name of the property from the URL path | webthing/server.py | def put(self, thing_id='0', property_name=None):
"""
Handle a PUT request.
thing_id -- ID of the thing this request is for
property_name -- the name of the property from the URL path
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_stat... | def put(self, thing_id='0', property_name=None):
"""
Handle a PUT request.
thing_id -- ID of the thing this request is for
property_name -- the name of the property from the URL path
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_stat... | [
"Handle",
"a",
"PUT",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L363-L397 | [
"def",
"put",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
",",
"property_name",
"=",
"None",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_status",
"(",
"404",
")",
"return",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ActionsHandler.post | Handle a POST request.
thing_id -- ID of the thing this request is for | webthing/server.py | def post(self, thing_id='0'):
"""
Handle a POST request.
thing_id -- ID of the thing this request is for
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_status(404)
return
try:
message = json.loads(self.request... | def post(self, thing_id='0'):
"""
Handle a POST request.
thing_id -- ID of the thing this request is for
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_status(404)
return
try:
message = json.loads(self.request... | [
"Handle",
"a",
"POST",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L417-L451 | [
"def",
"post",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_status",
"(",
"404",
")",
"return",
"try",
":",
"message",
"=",
"js... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ActionIDHandler.get | Handle a GET request.
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path | webthing/server.py | def get(self, thing_id='0', action_name=None, action_id=None):
"""
Handle a GET request.
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path
"""
thing = self.get_thing(th... | def get(self, thing_id='0', action_name=None, action_id=None):
"""
Handle a GET request.
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path
"""
thing = self.get_thing(th... | [
"Handle",
"a",
"GET",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L516-L535 | [
"def",
"get",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
",",
"action_name",
"=",
"None",
",",
"action_id",
"=",
"None",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_status... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ActionIDHandler.put | Handle a PUT request.
TODO: this is not yet defined in the spec
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path | webthing/server.py | def put(self, thing_id='0', action_name=None, action_id=None):
"""
Handle a PUT request.
TODO: this is not yet defined in the spec
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL... | def put(self, thing_id='0', action_name=None, action_id=None):
"""
Handle a PUT request.
TODO: this is not yet defined in the spec
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL... | [
"Handle",
"a",
"PUT",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L537-L552 | [
"def",
"put",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
",",
"action_name",
"=",
"None",
",",
"action_id",
"=",
"None",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_status... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | ActionIDHandler.delete | Handle a DELETE request.
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path | webthing/server.py | def delete(self, thing_id='0', action_name=None, action_id=None):
"""
Handle a DELETE request.
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path
"""
thing = self.get_th... | def delete(self, thing_id='0', action_name=None, action_id=None):
"""
Handle a DELETE request.
thing_id -- ID of the thing this request is for
action_name -- name of the action from the URL path
action_id -- the action ID from the URL path
"""
thing = self.get_th... | [
"Handle",
"a",
"DELETE",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L554-L570 | [
"def",
"delete",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
",",
"action_name",
"=",
"None",
",",
"action_id",
"=",
"None",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_sta... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | EventsHandler.get | Handle a GET request.
thing_id -- ID of the thing this request is for | webthing/server.py | def get(self, thing_id='0'):
"""
Handle a GET request.
thing_id -- ID of the thing this request is for
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_status(404)
return
self.set_header('Content-Type', 'application/json')
... | def get(self, thing_id='0'):
"""
Handle a GET request.
thing_id -- ID of the thing this request is for
"""
thing = self.get_thing(thing_id)
if thing is None:
self.set_status(404)
return
self.set_header('Content-Type', 'application/json')
... | [
"Handle",
"a",
"GET",
"request",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L576-L588 | [
"def",
"get",
"(",
"self",
",",
"thing_id",
"=",
"'0'",
")",
":",
"thing",
"=",
"self",
".",
"get_thing",
"(",
"thing_id",
")",
"if",
"thing",
"is",
"None",
":",
"self",
".",
"set_status",
"(",
"404",
")",
"return",
"self",
".",
"set_header",
"(",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | WebThingServer.start | Start listening for incoming connections. | webthing/server.py | def start(self):
"""Start listening for incoming connections."""
self.service_info = ServiceInfo(
'_webthing._tcp.local.',
'{}._webthing._tcp.local.'.format(self.name),
address=socket.inet_aton(get_ip()),
port=self.port,
properties={
... | def start(self):
"""Start listening for incoming connections."""
self.service_info = ServiceInfo(
'_webthing._tcp.local.',
'{}._webthing._tcp.local.'.format(self.name),
address=socket.inet_aton(get_ip()),
port=self.port,
properties={
... | [
"Start",
"listening",
"for",
"incoming",
"connections",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L767-L782 | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"service_info",
"=",
"ServiceInfo",
"(",
"'_webthing._tcp.local.'",
",",
"'{}._webthing._tcp.local.'",
".",
"format",
"(",
"self",
".",
"name",
")",
",",
"address",
"=",
"socket",
".",
"inet_aton",
"(",
"ge... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | WebThingServer.stop | Stop listening. | webthing/server.py | def stop(self):
"""Stop listening."""
self.zeroconf.unregister_service(self.service_info)
self.zeroconf.close()
self.server.stop() | def stop(self):
"""Stop listening."""
self.zeroconf.unregister_service(self.service_info)
self.zeroconf.close()
self.server.stop() | [
"Stop",
"listening",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/server.py#L784-L788 | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"zeroconf",
".",
"unregister_service",
"(",
"self",
".",
"service_info",
")",
"self",
".",
"zeroconf",
".",
"close",
"(",
")",
"self",
".",
"server",
".",
"stop",
"(",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Action.as_action_description | Get the action description.
Returns a dictionary describing the action. | webthing/action.py | def as_action_description(self):
"""
Get the action description.
Returns a dictionary describing the action.
"""
description = {
self.name: {
'href': self.href_prefix + self.href,
'timeRequested': self.time_requested,
'... | def as_action_description(self):
"""
Get the action description.
Returns a dictionary describing the action.
"""
description = {
self.name: {
'href': self.href_prefix + self.href,
'timeRequested': self.time_requested,
'... | [
"Get",
"the",
"action",
"description",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/action.py#L28-L48 | [
"def",
"as_action_description",
"(",
"self",
")",
":",
"description",
"=",
"{",
"self",
".",
"name",
":",
"{",
"'href'",
":",
"self",
".",
"href_prefix",
"+",
"self",
".",
"href",
",",
"'timeRequested'",
":",
"self",
".",
"time_requested",
",",
"'status'",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Action.start | Start performing the action. | webthing/action.py | def start(self):
"""Start performing the action."""
self.status = 'pending'
self.thing.action_notify(self)
self.perform_action()
self.finish() | def start(self):
"""Start performing the action."""
self.status = 'pending'
self.thing.action_notify(self)
self.perform_action()
self.finish() | [
"Start",
"performing",
"the",
"action",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/action.py#L90-L95 | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"status",
"=",
"'pending'",
"self",
".",
"thing",
".",
"action_notify",
"(",
"self",
")",
"self",
".",
"perform_action",
"(",
")",
"self",
".",
"finish",
"(",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Action.finish | Finish performing the action. | webthing/action.py | def finish(self):
"""Finish performing the action."""
self.status = 'completed'
self.time_completed = timestamp()
self.thing.action_notify(self) | def finish(self):
"""Finish performing the action."""
self.status = 'completed'
self.time_completed = timestamp()
self.thing.action_notify(self) | [
"Finish",
"performing",
"the",
"action",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/action.py#L105-L109 | [
"def",
"finish",
"(",
"self",
")",
":",
"self",
".",
"status",
"=",
"'completed'",
"self",
".",
"time_completed",
"=",
"timestamp",
"(",
")",
"self",
".",
"thing",
".",
"action_notify",
"(",
"self",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Event.as_event_description | Get the event description.
Returns a dictionary describing the event. | webthing/event.py | def as_event_description(self):
"""
Get the event description.
Returns a dictionary describing the event.
"""
description = {
self.name: {
'timestamp': self.time,
},
}
if self.data is not None:
description[self... | def as_event_description(self):
"""
Get the event description.
Returns a dictionary describing the event.
"""
description = {
self.name: {
'timestamp': self.time,
},
}
if self.data is not None:
description[self... | [
"Get",
"the",
"event",
"description",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/event.py#L22-L37 | [
"def",
"as_event_description",
"(",
"self",
")",
":",
"description",
"=",
"{",
"self",
".",
"name",
":",
"{",
"'timestamp'",
":",
"self",
".",
"time",
",",
"}",
",",
"}",
"if",
"self",
".",
"data",
"is",
"not",
"None",
":",
"description",
"[",
"self"... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | get_ip | Get the default local IP address.
From: https://stackoverflow.com/a/28950776 | webthing/utils.py | def get_ip():
"""
Get the default local IP address.
From: https://stackoverflow.com/a/28950776
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('10.255.255.255', 1))
ip = s.getsockname()[0]
except (socket.error, IndexError):
ip = '127.0.0.1'
... | def get_ip():
"""
Get the default local IP address.
From: https://stackoverflow.com/a/28950776
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('10.255.255.255', 1))
ip = s.getsockname()[0]
except (socket.error, IndexError):
ip = '127.0.0.1'
... | [
"Get",
"the",
"default",
"local",
"IP",
"address",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/utils.py#L17-L32 | [
"def",
"get_ip",
"(",
")",
":",
"s",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_DGRAM",
")",
"try",
":",
"s",
".",
"connect",
"(",
"(",
"'10.255.255.255'",
",",
"1",
")",
")",
"ip",
"=",
"s",
".",
"gets... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | get_addresses | Get all IP addresses.
Returns list of addresses. | webthing/utils.py | def get_addresses():
"""
Get all IP addresses.
Returns list of addresses.
"""
addresses = set()
for iface in ifaddr.get_adapters():
for addr in iface.ips:
# Filter out link-local addresses.
if addr.is_IPv4:
ip = addr.ip
if not ip... | def get_addresses():
"""
Get all IP addresses.
Returns list of addresses.
"""
addresses = set()
for iface in ifaddr.get_adapters():
for addr in iface.ips:
# Filter out link-local addresses.
if addr.is_IPv4:
ip = addr.ip
if not ip... | [
"Get",
"all",
"IP",
"addresses",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/utils.py#L35-L59 | [
"def",
"get_addresses",
"(",
")",
":",
"addresses",
"=",
"set",
"(",
")",
"for",
"iface",
"in",
"ifaddr",
".",
"get_adapters",
"(",
")",
":",
"for",
"addr",
"in",
"iface",
".",
"ips",
":",
"# Filter out link-local addresses.",
"if",
"addr",
".",
"is_IPv4",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Value.set | Set a new value for this thing.
value -- value to set | webthing/value.py | def set(self, value):
"""
Set a new value for this thing.
value -- value to set
"""
if self.value_forwarder is not None:
self.value_forwarder(value)
self.notify_of_external_update(value) | def set(self, value):
"""
Set a new value for this thing.
value -- value to set
"""
if self.value_forwarder is not None:
self.value_forwarder(value)
self.notify_of_external_update(value) | [
"Set",
"a",
"new",
"value",
"for",
"this",
"thing",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/value.py#L35-L44 | [
"def",
"set",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"value_forwarder",
"is",
"not",
"None",
":",
"self",
".",
"value_forwarder",
"(",
"value",
")",
"self",
".",
"notify_of_external_update",
"(",
"value",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Value.notify_of_external_update | Notify observers of a new value.
value -- new value | webthing/value.py | def notify_of_external_update(self, value):
"""
Notify observers of a new value.
value -- new value
"""
if value is not None and value != self.last_value:
self.last_value = value
self.emit('update', value) | def notify_of_external_update(self, value):
"""
Notify observers of a new value.
value -- new value
"""
if value is not None and value != self.last_value:
self.last_value = value
self.emit('update', value) | [
"Notify",
"observers",
"of",
"a",
"new",
"value",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/value.py#L50-L58 | [
"def",
"notify_of_external_update",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
"and",
"value",
"!=",
"self",
".",
"last_value",
":",
"self",
".",
"last_value",
"=",
"value",
"self",
".",
"emit",
"(",
"'update'",
",",
"value"... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.as_thing_description | Return the thing state as a Thing Description.
Returns the state as a dictionary. | webthing/thing.py | def as_thing_description(self):
"""
Return the thing state as a Thing Description.
Returns the state as a dictionary.
"""
thing = {
'name': self.name,
'href': self.href_prefix if self.href_prefix else '/',
'@context': self.context,
... | def as_thing_description(self):
"""
Return the thing state as a Thing Description.
Returns the state as a dictionary.
"""
thing = {
'name': self.name,
'href': self.href_prefix if self.href_prefix else '/',
'@context': self.context,
... | [
"Return",
"the",
"thing",
"state",
"as",
"a",
"Thing",
"Description",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L36-L94 | [
"def",
"as_thing_description",
"(",
"self",
")",
":",
"thing",
"=",
"{",
"'name'",
":",
"self",
".",
"name",
",",
"'href'",
":",
"self",
".",
"href_prefix",
"if",
"self",
".",
"href_prefix",
"else",
"'/'",
",",
"'@context'",
":",
"self",
".",
"context",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.set_href_prefix | Set the prefix of any hrefs associated with this thing.
prefix -- the prefix | webthing/thing.py | def set_href_prefix(self, prefix):
"""
Set the prefix of any hrefs associated with this thing.
prefix -- the prefix
"""
self.href_prefix = prefix
for property_ in self.properties.values():
property_.set_href_prefix(prefix)
for action_name in self.ac... | def set_href_prefix(self, prefix):
"""
Set the prefix of any hrefs associated with this thing.
prefix -- the prefix
"""
self.href_prefix = prefix
for property_ in self.properties.values():
property_.set_href_prefix(prefix)
for action_name in self.ac... | [
"Set",
"the",
"prefix",
"of",
"any",
"hrefs",
"associated",
"with",
"this",
"thing",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L107-L120 | [
"def",
"set_href_prefix",
"(",
"self",
",",
"prefix",
")",
":",
"self",
".",
"href_prefix",
"=",
"prefix",
"for",
"property_",
"in",
"self",
".",
"properties",
".",
"values",
"(",
")",
":",
"property_",
".",
"set_href_prefix",
"(",
"prefix",
")",
"for",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.get_property_descriptions | Get the thing's properties as a dictionary.
Returns the properties as a dictionary, i.e. name -> description. | webthing/thing.py | def get_property_descriptions(self):
"""
Get the thing's properties as a dictionary.
Returns the properties as a dictionary, i.e. name -> description.
"""
return {k: v.as_property_description()
for k, v in self.properties.items()} | def get_property_descriptions(self):
"""
Get the thing's properties as a dictionary.
Returns the properties as a dictionary, i.e. name -> description.
"""
return {k: v.as_property_description()
for k, v in self.properties.items()} | [
"Get",
"the",
"thing",
"s",
"properties",
"as",
"a",
"dictionary",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L162-L169 | [
"def",
"get_property_descriptions",
"(",
"self",
")",
":",
"return",
"{",
"k",
":",
"v",
".",
"as_property_description",
"(",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"properties",
".",
"items",
"(",
")",
"}"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.get_action_descriptions | Get the thing's actions as an array.
action_name -- Optional action name to get descriptions for
Returns the action descriptions. | webthing/thing.py | def get_action_descriptions(self, action_name=None):
"""
Get the thing's actions as an array.
action_name -- Optional action name to get descriptions for
Returns the action descriptions.
"""
descriptions = []
if action_name is None:
for name in self... | def get_action_descriptions(self, action_name=None):
"""
Get the thing's actions as an array.
action_name -- Optional action name to get descriptions for
Returns the action descriptions.
"""
descriptions = []
if action_name is None:
for name in self... | [
"Get",
"the",
"thing",
"s",
"actions",
"as",
"an",
"array",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L171-L189 | [
"def",
"get_action_descriptions",
"(",
"self",
",",
"action_name",
"=",
"None",
")",
":",
"descriptions",
"=",
"[",
"]",
"if",
"action_name",
"is",
"None",
":",
"for",
"name",
"in",
"self",
".",
"actions",
":",
"for",
"action",
"in",
"self",
".",
"action... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.get_event_descriptions | Get the thing's events as an array.
event_name -- Optional event name to get descriptions for
Returns the event descriptions. | webthing/thing.py | def get_event_descriptions(self, event_name=None):
"""
Get the thing's events as an array.
event_name -- Optional event name to get descriptions for
Returns the event descriptions.
"""
if event_name is None:
return [e.as_event_description() for e in self.eve... | def get_event_descriptions(self, event_name=None):
"""
Get the thing's events as an array.
event_name -- Optional event name to get descriptions for
Returns the event descriptions.
"""
if event_name is None:
return [e.as_event_description() for e in self.eve... | [
"Get",
"the",
"thing",
"s",
"events",
"as",
"an",
"array",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L191-L203 | [
"def",
"get_event_descriptions",
"(",
"self",
",",
"event_name",
"=",
"None",
")",
":",
"if",
"event_name",
"is",
"None",
":",
"return",
"[",
"e",
".",
"as_event_description",
"(",
")",
"for",
"e",
"in",
"self",
".",
"events",
"]",
"else",
":",
"return",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.add_property | Add a property to this thing.
property_ -- property to add | webthing/thing.py | def add_property(self, property_):
"""
Add a property to this thing.
property_ -- property to add
"""
property_.set_href_prefix(self.href_prefix)
self.properties[property_.name] = property_ | def add_property(self, property_):
"""
Add a property to this thing.
property_ -- property to add
"""
property_.set_href_prefix(self.href_prefix)
self.properties[property_.name] = property_ | [
"Add",
"a",
"property",
"to",
"this",
"thing",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L205-L212 | [
"def",
"add_property",
"(",
"self",
",",
"property_",
")",
":",
"property_",
".",
"set_href_prefix",
"(",
"self",
".",
"href_prefix",
")",
"self",
".",
"properties",
"[",
"property_",
".",
"name",
"]",
"=",
"property_"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.remove_property | Remove a property from this thing.
property_ -- property to remove | webthing/thing.py | def remove_property(self, property_):
"""
Remove a property from this thing.
property_ -- property to remove
"""
if property_.name in self.properties:
del self.properties[property_.name] | def remove_property(self, property_):
"""
Remove a property from this thing.
property_ -- property to remove
"""
if property_.name in self.properties:
del self.properties[property_.name] | [
"Remove",
"a",
"property",
"from",
"this",
"thing",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L214-L221 | [
"def",
"remove_property",
"(",
"self",
",",
"property_",
")",
":",
"if",
"property_",
".",
"name",
"in",
"self",
".",
"properties",
":",
"del",
"self",
".",
"properties",
"[",
"property_",
".",
"name",
"]"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.get_property | Get a property's value.
property_name -- the property to get the value of
Returns the properties value, if found, else None. | webthing/thing.py | def get_property(self, property_name):
"""
Get a property's value.
property_name -- the property to get the value of
Returns the properties value, if found, else None.
"""
prop = self.find_property(property_name)
if prop:
return prop.get_value()
... | def get_property(self, property_name):
"""
Get a property's value.
property_name -- the property to get the value of
Returns the properties value, if found, else None.
"""
prop = self.find_property(property_name)
if prop:
return prop.get_value()
... | [
"Get",
"a",
"property",
"s",
"value",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L233-L245 | [
"def",
"get_property",
"(",
"self",
",",
"property_name",
")",
":",
"prop",
"=",
"self",
".",
"find_property",
"(",
"property_name",
")",
"if",
"prop",
":",
"return",
"prop",
".",
"get_value",
"(",
")",
"return",
"None"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.get_properties | Get a mapping of all properties and their values.
Returns a dictionary of property_name -> value. | webthing/thing.py | def get_properties(self):
"""
Get a mapping of all properties and their values.
Returns a dictionary of property_name -> value.
"""
return {prop.get_name(): prop.get_value()
for prop in self.properties.values()} | def get_properties(self):
"""
Get a mapping of all properties and their values.
Returns a dictionary of property_name -> value.
"""
return {prop.get_name(): prop.get_value()
for prop in self.properties.values()} | [
"Get",
"a",
"mapping",
"of",
"all",
"properties",
"and",
"their",
"values",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L247-L254 | [
"def",
"get_properties",
"(",
"self",
")",
":",
"return",
"{",
"prop",
".",
"get_name",
"(",
")",
":",
"prop",
".",
"get_value",
"(",
")",
"for",
"prop",
"in",
"self",
".",
"properties",
".",
"values",
"(",
")",
"}"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.set_property | Set a property value.
property_name -- name of the property to set
value -- value to set | webthing/thing.py | def set_property(self, property_name, value):
"""
Set a property value.
property_name -- name of the property to set
value -- value to set
"""
prop = self.find_property(property_name)
if not prop:
return
prop.set_value(value) | def set_property(self, property_name, value):
"""
Set a property value.
property_name -- name of the property to set
value -- value to set
"""
prop = self.find_property(property_name)
if not prop:
return
prop.set_value(value) | [
"Set",
"a",
"property",
"value",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L267-L278 | [
"def",
"set_property",
"(",
"self",
",",
"property_name",
",",
"value",
")",
":",
"prop",
"=",
"self",
".",
"find_property",
"(",
"property_name",
")",
"if",
"not",
"prop",
":",
"return",
"prop",
".",
"set_value",
"(",
"value",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.get_action | Get an action.
action_name -- name of the action
action_id -- ID of the action
Returns the requested action if found, else None. | webthing/thing.py | def get_action(self, action_name, action_id):
"""
Get an action.
action_name -- name of the action
action_id -- ID of the action
Returns the requested action if found, else None.
"""
if action_name not in self.actions:
return None
for action... | def get_action(self, action_name, action_id):
"""
Get an action.
action_name -- name of the action
action_id -- ID of the action
Returns the requested action if found, else None.
"""
if action_name not in self.actions:
return None
for action... | [
"Get",
"an",
"action",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L280-L296 | [
"def",
"get_action",
"(",
"self",
",",
"action_name",
",",
"action_id",
")",
":",
"if",
"action_name",
"not",
"in",
"self",
".",
"actions",
":",
"return",
"None",
"for",
"action",
"in",
"self",
".",
"actions",
"[",
"action_name",
"]",
":",
"if",
"action"... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.add_event | Add a new event and notify subscribers.
event -- the event that occurred | webthing/thing.py | def add_event(self, event):
"""
Add a new event and notify subscribers.
event -- the event that occurred
"""
self.events.append(event)
self.event_notify(event) | def add_event(self, event):
"""
Add a new event and notify subscribers.
event -- the event that occurred
"""
self.events.append(event)
self.event_notify(event) | [
"Add",
"a",
"new",
"event",
"and",
"notify",
"subscribers",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L298-L305 | [
"def",
"add_event",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"events",
".",
"append",
"(",
"event",
")",
"self",
".",
"event_notify",
"(",
"event",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.add_available_event | Add an available event.
name -- name of the event
metadata -- event metadata, i.e. type, description, etc., as a dict | webthing/thing.py | def add_available_event(self, name, metadata):
"""
Add an available event.
name -- name of the event
metadata -- event metadata, i.e. type, description, etc., as a dict
"""
if metadata is None:
metadata = {}
self.available_events[name] = {
... | def add_available_event(self, name, metadata):
"""
Add an available event.
name -- name of the event
metadata -- event metadata, i.e. type, description, etc., as a dict
"""
if metadata is None:
metadata = {}
self.available_events[name] = {
... | [
"Add",
"an",
"available",
"event",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L307-L320 | [
"def",
"add_available_event",
"(",
"self",
",",
"name",
",",
"metadata",
")",
":",
"if",
"metadata",
"is",
"None",
":",
"metadata",
"=",
"{",
"}",
"self",
".",
"available_events",
"[",
"name",
"]",
"=",
"{",
"'metadata'",
":",
"metadata",
",",
"'subscrib... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.perform_action | Perform an action on the thing.
action_name -- name of the action
input_ -- any action inputs
Returns the action that was created. | webthing/thing.py | def perform_action(self, action_name, input_=None):
"""
Perform an action on the thing.
action_name -- name of the action
input_ -- any action inputs
Returns the action that was created.
"""
if action_name not in self.available_actions:
return None
... | def perform_action(self, action_name, input_=None):
"""
Perform an action on the thing.
action_name -- name of the action
input_ -- any action inputs
Returns the action that was created.
"""
if action_name not in self.available_actions:
return None
... | [
"Perform",
"an",
"action",
"on",
"the",
"thing",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L322-L346 | [
"def",
"perform_action",
"(",
"self",
",",
"action_name",
",",
"input_",
"=",
"None",
")",
":",
"if",
"action_name",
"not",
"in",
"self",
".",
"available_actions",
":",
"return",
"None",
"action_type",
"=",
"self",
".",
"available_actions",
"[",
"action_name",... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.remove_action | Remove an existing action.
action_name -- name of the action
action_id -- ID of the action
Returns a boolean indicating the presence of the action. | webthing/thing.py | def remove_action(self, action_name, action_id):
"""
Remove an existing action.
action_name -- name of the action
action_id -- ID of the action
Returns a boolean indicating the presence of the action.
"""
action = self.get_action(action_name, action_id)
... | def remove_action(self, action_name, action_id):
"""
Remove an existing action.
action_name -- name of the action
action_id -- ID of the action
Returns a boolean indicating the presence of the action.
"""
action = self.get_action(action_name, action_id)
... | [
"Remove",
"an",
"existing",
"action",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L348-L363 | [
"def",
"remove_action",
"(",
"self",
",",
"action_name",
",",
"action_id",
")",
":",
"action",
"=",
"self",
".",
"get_action",
"(",
"action_name",
",",
"action_id",
")",
"if",
"action",
"is",
"None",
":",
"return",
"False",
"action",
".",
"cancel",
"(",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.add_available_action | Add an available action.
name -- name of the action
metadata -- action metadata, i.e. type, description, etc., as a dict
cls -- class to instantiate for this action | webthing/thing.py | def add_available_action(self, name, metadata, cls):
"""
Add an available action.
name -- name of the action
metadata -- action metadata, i.e. type, description, etc., as a dict
cls -- class to instantiate for this action
"""
if metadata is None:
meta... | def add_available_action(self, name, metadata, cls):
"""
Add an available action.
name -- name of the action
metadata -- action metadata, i.e. type, description, etc., as a dict
cls -- class to instantiate for this action
"""
if metadata is None:
meta... | [
"Add",
"an",
"available",
"action",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L365-L380 | [
"def",
"add_available_action",
"(",
"self",
",",
"name",
",",
"metadata",
",",
"cls",
")",
":",
"if",
"metadata",
"is",
"None",
":",
"metadata",
"=",
"{",
"}",
"self",
".",
"available_actions",
"[",
"name",
"]",
"=",
"{",
"'metadata'",
":",
"metadata",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.remove_subscriber | Remove a websocket subscriber.
ws -- the websocket | webthing/thing.py | def remove_subscriber(self, ws):
"""
Remove a websocket subscriber.
ws -- the websocket
"""
if ws in self.subscribers:
self.subscribers.remove(ws)
for name in self.available_events:
self.remove_event_subscriber(name, ws) | def remove_subscriber(self, ws):
"""
Remove a websocket subscriber.
ws -- the websocket
"""
if ws in self.subscribers:
self.subscribers.remove(ws)
for name in self.available_events:
self.remove_event_subscriber(name, ws) | [
"Remove",
"a",
"websocket",
"subscriber",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L390-L400 | [
"def",
"remove_subscriber",
"(",
"self",
",",
"ws",
")",
":",
"if",
"ws",
"in",
"self",
".",
"subscribers",
":",
"self",
".",
"subscribers",
".",
"remove",
"(",
"ws",
")",
"for",
"name",
"in",
"self",
".",
"available_events",
":",
"self",
".",
"remove_... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.add_event_subscriber | Add a new websocket subscriber to an event.
name -- name of the event
ws -- the websocket | webthing/thing.py | def add_event_subscriber(self, name, ws):
"""
Add a new websocket subscriber to an event.
name -- name of the event
ws -- the websocket
"""
if name in self.available_events:
self.available_events[name]['subscribers'].add(ws) | def add_event_subscriber(self, name, ws):
"""
Add a new websocket subscriber to an event.
name -- name of the event
ws -- the websocket
"""
if name in self.available_events:
self.available_events[name]['subscribers'].add(ws) | [
"Add",
"a",
"new",
"websocket",
"subscriber",
"to",
"an",
"event",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L402-L410 | [
"def",
"add_event_subscriber",
"(",
"self",
",",
"name",
",",
"ws",
")",
":",
"if",
"name",
"in",
"self",
".",
"available_events",
":",
"self",
".",
"available_events",
"[",
"name",
"]",
"[",
"'subscribers'",
"]",
".",
"add",
"(",
"ws",
")"
] | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.remove_event_subscriber | Remove a websocket subscriber from an event.
name -- name of the event
ws -- the websocket | webthing/thing.py | def remove_event_subscriber(self, name, ws):
"""
Remove a websocket subscriber from an event.
name -- name of the event
ws -- the websocket
"""
if name in self.available_events and \
ws in self.available_events[name]['subscribers']:
self.avail... | def remove_event_subscriber(self, name, ws):
"""
Remove a websocket subscriber from an event.
name -- name of the event
ws -- the websocket
"""
if name in self.available_events and \
ws in self.available_events[name]['subscribers']:
self.avail... | [
"Remove",
"a",
"websocket",
"subscriber",
"from",
"an",
"event",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L412-L421 | [
"def",
"remove_event_subscriber",
"(",
"self",
",",
"name",
",",
"ws",
")",
":",
"if",
"name",
"in",
"self",
".",
"available_events",
"and",
"ws",
"in",
"self",
".",
"available_events",
"[",
"name",
"]",
"[",
"'subscribers'",
"]",
":",
"self",
".",
"avai... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.property_notify | Notify all subscribers of a property change.
property_ -- the property that changed | webthing/thing.py | def property_notify(self, property_):
"""
Notify all subscribers of a property change.
property_ -- the property that changed
"""
message = json.dumps({
'messageType': 'propertyStatus',
'data': {
property_.name: property_.get_value(),
... | def property_notify(self, property_):
"""
Notify all subscribers of a property change.
property_ -- the property that changed
"""
message = json.dumps({
'messageType': 'propertyStatus',
'data': {
property_.name: property_.get_value(),
... | [
"Notify",
"all",
"subscribers",
"of",
"a",
"property",
"change",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L423-L440 | [
"def",
"property_notify",
"(",
"self",
",",
"property_",
")",
":",
"message",
"=",
"json",
".",
"dumps",
"(",
"{",
"'messageType'",
":",
"'propertyStatus'",
",",
"'data'",
":",
"{",
"property_",
".",
"name",
":",
"property_",
".",
"get_value",
"(",
")",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.action_notify | Notify all subscribers of an action status change.
action -- the action whose status changed | webthing/thing.py | def action_notify(self, action):
"""
Notify all subscribers of an action status change.
action -- the action whose status changed
"""
message = json.dumps({
'messageType': 'actionStatus',
'data': action.as_action_description(),
})
for sub... | def action_notify(self, action):
"""
Notify all subscribers of an action status change.
action -- the action whose status changed
"""
message = json.dumps({
'messageType': 'actionStatus',
'data': action.as_action_description(),
})
for sub... | [
"Notify",
"all",
"subscribers",
"of",
"an",
"action",
"status",
"change",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L442-L457 | [
"def",
"action_notify",
"(",
"self",
",",
"action",
")",
":",
"message",
"=",
"json",
".",
"dumps",
"(",
"{",
"'messageType'",
":",
"'actionStatus'",
",",
"'data'",
":",
"action",
".",
"as_action_description",
"(",
")",
",",
"}",
")",
"for",
"subscriber",
... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | Thing.event_notify | Notify all subscribers of an event.
event -- the event that occurred | webthing/thing.py | def event_notify(self, event):
"""
Notify all subscribers of an event.
event -- the event that occurred
"""
if event.name not in self.available_events:
return
message = json.dumps({
'messageType': 'event',
'data': event.as_event_descr... | def event_notify(self, event):
"""
Notify all subscribers of an event.
event -- the event that occurred
"""
if event.name not in self.available_events:
return
message = json.dumps({
'messageType': 'event',
'data': event.as_event_descr... | [
"Notify",
"all",
"subscribers",
"of",
"an",
"event",
"."
] | mozilla-iot/webthing-python | python | https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L459-L477 | [
"def",
"event_notify",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"name",
"not",
"in",
"self",
".",
"available_events",
":",
"return",
"message",
"=",
"json",
".",
"dumps",
"(",
"{",
"'messageType'",
":",
"'event'",
",",
"'data'",
":",
"e... | 65d467c89ed79d0bbc42b8b3c8f9e5a320edd237 |
test | PostgresQuerySet.annotate | Custom version of the standard annotate function
that allows using field names as annotated fields.
Normally, the annotate function doesn't allow you
to use the name of an existing field on the model
as the alias name. This version of the function does
allow that. | psqlextra/manager/manager.py | def annotate(self, **annotations):
"""Custom version of the standard annotate function
that allows using field names as annotated fields.
Normally, the annotate function doesn't allow you
to use the name of an existing field on the model
as the alias name. This version of the fu... | def annotate(self, **annotations):
"""Custom version of the standard annotate function
that allows using field names as annotated fields.
Normally, the annotate function doesn't allow you
to use the name of an existing field on the model
as the alias name. This version of the fu... | [
"Custom",
"version",
"of",
"the",
"standard",
"annotate",
"function",
"that",
"allows",
"using",
"field",
"names",
"as",
"annotated",
"fields",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L31-L64 | [
"def",
"annotate",
"(",
"self",
",",
"*",
"*",
"annotations",
")",
":",
"fields",
"=",
"{",
"field",
".",
"name",
":",
"field",
"for",
"field",
"in",
"self",
".",
"model",
".",
"_meta",
".",
"get_fields",
"(",
")",
"}",
"# temporarily rename the fields t... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.update | Updates all rows that match the filter. | psqlextra/manager/manager.py | def update(self, **fields):
"""Updates all rows that match the filter."""
# build up the query to execute
self._for_write = True
if django.VERSION >= (2, 0):
query = self.query.chain(UpdateQuery)
else:
query = self.query.clone(UpdateQuery)
query._... | def update(self, **fields):
"""Updates all rows that match the filter."""
# build up the query to execute
self._for_write = True
if django.VERSION >= (2, 0):
query = self.query.chain(UpdateQuery)
else:
query = self.query.clone(UpdateQuery)
query._... | [
"Updates",
"all",
"rows",
"that",
"match",
"the",
"filter",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L91-L118 | [
"def",
"update",
"(",
"self",
",",
"*",
"*",
"fields",
")",
":",
"# build up the query to execute",
"self",
".",
"_for_write",
"=",
"True",
"if",
"django",
".",
"VERSION",
">=",
"(",
"2",
",",
"0",
")",
":",
"query",
"=",
"self",
".",
"query",
".",
"... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.on_conflict | Sets the action to take when conflicts arise when attempting
to insert/create a new row.
Arguments:
fields:
The fields the conflicts can occur in.
action:
The action to take when the conflict occurs.
index_predicate:
... | psqlextra/manager/manager.py | def on_conflict(self, fields: List[Union[str, Tuple[str]]], action, index_predicate: str=None):
"""Sets the action to take when conflicts arise when attempting
to insert/create a new row.
Arguments:
fields:
The fields the conflicts can occur in.
action:
... | def on_conflict(self, fields: List[Union[str, Tuple[str]]], action, index_predicate: str=None):
"""Sets the action to take when conflicts arise when attempting
to insert/create a new row.
Arguments:
fields:
The fields the conflicts can occur in.
action:
... | [
"Sets",
"the",
"action",
"to",
"take",
"when",
"conflicts",
"arise",
"when",
"attempting",
"to",
"insert",
"/",
"create",
"a",
"new",
"row",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L120-L140 | [
"def",
"on_conflict",
"(",
"self",
",",
"fields",
":",
"List",
"[",
"Union",
"[",
"str",
",",
"Tuple",
"[",
"str",
"]",
"]",
"]",
",",
"action",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
":",
"self",
".",
"conflict_target",
"=",
"fields",... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.bulk_insert | Creates multiple new records in the database.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
rows:
An array of dictionaries, where each dictionary
... | psqlextra/manager/manager.py | def bulk_insert(self, rows, return_model=False):
"""Creates multiple new records in the database.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
rows:
... | def bulk_insert(self, rows, return_model=False):
"""Creates multiple new records in the database.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
rows:
... | [
"Creates",
"multiple",
"new",
"records",
"in",
"the",
"database",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L142-L171 | [
"def",
"bulk_insert",
"(",
"self",
",",
"rows",
",",
"return_model",
"=",
"False",
")",
":",
"if",
"self",
".",
"conflict_target",
"or",
"self",
".",
"conflict_action",
":",
"compiler",
"=",
"self",
".",
"_build_insert_compiler",
"(",
"rows",
")",
"objs",
... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.insert | Creates a new record in the database.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
fields:
The fields of the row to create.
Returns:
... | psqlextra/manager/manager.py | def insert(self, **fields):
"""Creates a new record in the database.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
fields:
The fields of the row t... | def insert(self, **fields):
"""Creates a new record in the database.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
fields:
The fields of the row t... | [
"Creates",
"a",
"new",
"record",
"in",
"the",
"database",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L173-L195 | [
"def",
"insert",
"(",
"self",
",",
"*",
"*",
"fields",
")",
":",
"if",
"self",
".",
"conflict_target",
"or",
"self",
".",
"conflict_action",
":",
"compiler",
"=",
"self",
".",
"_build_insert_compiler",
"(",
"[",
"fields",
"]",
")",
"rows",
"=",
"compiler... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.insert_and_get | Creates a new record in the database and then gets
the entire row.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
fields:
The fields of the row to ... | psqlextra/manager/manager.py | def insert_and_get(self, **fields):
"""Creates a new record in the database and then gets
the entire row.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
fi... | def insert_and_get(self, **fields):
"""Creates a new record in the database and then gets
the entire row.
This allows specifying custom conflict behavior using .on_conflict().
If no special behavior was specified, this uses the normal Django create(..)
Arguments:
fi... | [
"Creates",
"a",
"new",
"record",
"in",
"the",
"database",
"and",
"then",
"gets",
"the",
"entire",
"row",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L197-L236 | [
"def",
"insert_and_get",
"(",
"self",
",",
"*",
"*",
"fields",
")",
":",
"if",
"not",
"self",
".",
"conflict_target",
"and",
"not",
"self",
".",
"conflict_action",
":",
"# no special action required, use the standard Django create(..)",
"return",
"super",
"(",
")",
... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.upsert | Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
Fields to insert/update.
index_predicate:
The index predicate t... | psqlextra/manager/manager.py | def upsert(self, conflict_target: List, fields: Dict, index_predicate: str=None) -> int:
"""Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
... | def upsert(self, conflict_target: List, fields: Dict, index_predicate: str=None) -> int:
"""Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
... | [
"Creates",
"a",
"new",
"record",
"or",
"updates",
"the",
"existing",
"one",
"with",
"the",
"specified",
"data",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L238-L258 | [
"def",
"upsert",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"fields",
":",
"Dict",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
"->",
"int",
":",
"self",
".",
"on_conflict",
"(",
"conflict_target",
",",
"ConflictAction",
".",
"UPDATE",... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.upsert_and_get | Creates a new record or updates the existing one
with the specified data and then gets the row.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
Fields to insert/update.
index_predicate:
... | psqlextra/manager/manager.py | def upsert_and_get(self, conflict_target: List, fields: Dict, index_predicate: str=None):
"""Creates a new record or updates the existing one
with the specified data and then gets the row.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
... | def upsert_and_get(self, conflict_target: List, fields: Dict, index_predicate: str=None):
"""Creates a new record or updates the existing one
with the specified data and then gets the row.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
... | [
"Creates",
"a",
"new",
"record",
"or",
"updates",
"the",
"existing",
"one",
"with",
"the",
"specified",
"data",
"and",
"then",
"gets",
"the",
"row",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L260-L281 | [
"def",
"upsert_and_get",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"fields",
":",
"Dict",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
":",
"self",
".",
"on_conflict",
"(",
"conflict_target",
",",
"ConflictAction",
".",
"UPDATE",
",",
... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet.bulk_upsert | Creates a set of new records or updates the existing
ones with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
rows:
Rows to upsert.
index_predicate:
The index predicate to ... | psqlextra/manager/manager.py | def bulk_upsert(self, conflict_target: List, rows: List[Dict], index_predicate: str=None):
"""Creates a set of new records or updates the existing
ones with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
rows:... | def bulk_upsert(self, conflict_target: List, rows: List[Dict], index_predicate: str=None):
"""Creates a set of new records or updates the existing
ones with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
rows:... | [
"Creates",
"a",
"set",
"of",
"new",
"records",
"or",
"updates",
"the",
"existing",
"ones",
"with",
"the",
"specified",
"data",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L283-L303 | [
"def",
"bulk_upsert",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"rows",
":",
"List",
"[",
"Dict",
"]",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
":",
"if",
"not",
"rows",
"or",
"len",
"(",
"rows",
")",
"<=",
"0",
":",
"retu... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet._build_insert_compiler | Builds the SQL compiler for a insert query.
Arguments:
rows:
A list of dictionaries, where each entry
describes a record to insert.
Returns:
The SQL compiler for the insert. | psqlextra/manager/manager.py | def _build_insert_compiler(self, rows: List[Dict]):
"""Builds the SQL compiler for a insert query.
Arguments:
rows:
A list of dictionaries, where each entry
describes a record to insert.
Returns:
The SQL compiler for the insert.
"... | def _build_insert_compiler(self, rows: List[Dict]):
"""Builds the SQL compiler for a insert query.
Arguments:
rows:
A list of dictionaries, where each entry
describes a record to insert.
Returns:
The SQL compiler for the insert.
"... | [
"Builds",
"the",
"SQL",
"compiler",
"for",
"a",
"insert",
"query",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L305-L352 | [
"def",
"_build_insert_compiler",
"(",
"self",
",",
"rows",
":",
"List",
"[",
"Dict",
"]",
")",
":",
"# create model objects, we also have to detect cases",
"# such as:",
"# [dict(first_name='swen'), dict(fist_name='swen', last_name='kooij')]",
"# we need to be certain that each row... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet._is_magical_field | Verifies whether this field is gonna modify something
on its own.
"Magical" means that a field modifies the field value
during the pre_save.
Arguments:
model_instance:
The model instance the field is defined on.
field:
The field ... | psqlextra/manager/manager.py | def _is_magical_field(self, model_instance, field, is_insert: bool):
"""Verifies whether this field is gonna modify something
on its own.
"Magical" means that a field modifies the field value
during the pre_save.
Arguments:
model_instance:
The model ... | def _is_magical_field(self, model_instance, field, is_insert: bool):
"""Verifies whether this field is gonna modify something
on its own.
"Magical" means that a field modifies the field value
during the pre_save.
Arguments:
model_instance:
The model ... | [
"Verifies",
"whether",
"this",
"field",
"is",
"gonna",
"modify",
"something",
"on",
"its",
"own",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L354-L381 | [
"def",
"_is_magical_field",
"(",
"self",
",",
"model_instance",
",",
"field",
",",
"is_insert",
":",
"bool",
")",
":",
"# does this field modify someting upon insert?",
"old_value",
"=",
"getattr",
"(",
"model_instance",
",",
"field",
".",
"name",
",",
"None",
")"... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresQuerySet._get_upsert_fields | Gets the fields to use in an upsert.
This some nice magic. We'll split the fields into
a group of "insert fields" and "update fields":
INSERT INTO bla ("val1", "val2") ON CONFLICT DO UPDATE SET val1 = EXCLUDED.val1
^^^^^^^^^^^^^^ ^^^^^^^^^^^... | psqlextra/manager/manager.py | def _get_upsert_fields(self, kwargs):
"""Gets the fields to use in an upsert.
This some nice magic. We'll split the fields into
a group of "insert fields" and "update fields":
INSERT INTO bla ("val1", "val2") ON CONFLICT DO UPDATE SET val1 = EXCLUDED.val1
^^^^... | def _get_upsert_fields(self, kwargs):
"""Gets the fields to use in an upsert.
This some nice magic. We'll split the fields into
a group of "insert fields" and "update fields":
INSERT INTO bla ("val1", "val2") ON CONFLICT DO UPDATE SET val1 = EXCLUDED.val1
^^^^... | [
"Gets",
"the",
"fields",
"to",
"use",
"in",
"an",
"upsert",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L383-L441 | [
"def",
"_get_upsert_fields",
"(",
"self",
",",
"kwargs",
")",
":",
"model_instance",
"=",
"self",
".",
"model",
"(",
"*",
"*",
"kwargs",
")",
"insert_fields",
"=",
"[",
"]",
"update_fields",
"=",
"[",
"]",
"for",
"field",
"in",
"model_instance",
".",
"_m... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresManager.on_conflict | Sets the action to take when conflicts arise when attempting
to insert/create a new row.
Arguments:
fields:
The fields the conflicts can occur in.
action:
The action to take when the conflict occurs.
index_predicate:
... | psqlextra/manager/manager.py | def on_conflict(self, fields: List[Union[str, Tuple[str]]], action, index_predicate: str=None):
"""Sets the action to take when conflicts arise when attempting
to insert/create a new row.
Arguments:
fields:
The fields the conflicts can occur in.
action:
... | def on_conflict(self, fields: List[Union[str, Tuple[str]]], action, index_predicate: str=None):
"""Sets the action to take when conflicts arise when attempting
to insert/create a new row.
Arguments:
fields:
The fields the conflicts can occur in.
action:
... | [
"Sets",
"the",
"action",
"to",
"take",
"when",
"conflicts",
"arise",
"when",
"attempting",
"to",
"insert",
"/",
"create",
"a",
"new",
"row",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L491-L505 | [
"def",
"on_conflict",
"(",
"self",
",",
"fields",
":",
"List",
"[",
"Union",
"[",
"str",
",",
"Tuple",
"[",
"str",
"]",
"]",
"]",
",",
"action",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
":",
"return",
"self",
".",
"get_queryset",
"(",
... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresManager.upsert | Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
Fields to insert/update.
index_predicate:
The index predicate t... | psqlextra/manager/manager.py | def upsert(self, conflict_target: List, fields: Dict, index_predicate: str=None) -> int:
"""Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
... | def upsert(self, conflict_target: List, fields: Dict, index_predicate: str=None) -> int:
"""Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
... | [
"Creates",
"a",
"new",
"record",
"or",
"updates",
"the",
"existing",
"one",
"with",
"the",
"specified",
"data",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L507-L525 | [
"def",
"upsert",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"fields",
":",
"Dict",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
"->",
"int",
":",
"return",
"self",
".",
"get_queryset",
"(",
")",
".",
"upsert",
"(",
"conflict_target",... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresManager.upsert_and_get | Creates a new record or updates the existing one
with the specified data and then gets the row.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
Fields to insert/update.
index_predicate:
... | psqlextra/manager/manager.py | def upsert_and_get(self, conflict_target: List, fields: Dict, index_predicate: str=None):
"""Creates a new record or updates the existing one
with the specified data and then gets the row.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
... | def upsert_and_get(self, conflict_target: List, fields: Dict, index_predicate: str=None):
"""Creates a new record or updates the existing one
with the specified data and then gets the row.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
... | [
"Creates",
"a",
"new",
"record",
"or",
"updates",
"the",
"existing",
"one",
"with",
"the",
"specified",
"data",
"and",
"then",
"gets",
"the",
"row",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L527-L546 | [
"def",
"upsert_and_get",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"fields",
":",
"Dict",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
":",
"return",
"self",
".",
"get_queryset",
"(",
")",
".",
"upsert_and_get",
"(",
"conflict_target",
... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresManager.bulk_upsert | Creates a set of new records or updates the existing
ones with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
index_predicate:
The index predicate to satisfy an arbiter partial index.
rows... | psqlextra/manager/manager.py | def bulk_upsert(self, conflict_target: List, rows: List[Dict], index_predicate: str=None):
"""Creates a set of new records or updates the existing
ones with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
index... | def bulk_upsert(self, conflict_target: List, rows: List[Dict], index_predicate: str=None):
"""Creates a set of new records or updates the existing
ones with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
index... | [
"Creates",
"a",
"set",
"of",
"new",
"records",
"or",
"updates",
"the",
"existing",
"ones",
"with",
"the",
"specified",
"data",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L548-L563 | [
"def",
"bulk_upsert",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"rows",
":",
"List",
"[",
"Dict",
"]",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
":",
"return",
"self",
".",
"get_queryset",
"(",
")",
".",
"bulk_upsert",
"(",
"co... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresManager._on_model_save | When a model gets created or updated. | psqlextra/manager/manager.py | def _on_model_save(sender, **kwargs):
"""When a model gets created or updated."""
created, instance = kwargs['created'], kwargs['instance']
if created:
signals.create.send(sender, pk=instance.pk)
else:
signals.update.send(sender, pk=instance.pk) | def _on_model_save(sender, **kwargs):
"""When a model gets created or updated."""
created, instance = kwargs['created'], kwargs['instance']
if created:
signals.create.send(sender, pk=instance.pk)
else:
signals.update.send(sender, pk=instance.pk) | [
"When",
"a",
"model",
"gets",
"created",
"or",
"updated",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L566-L574 | [
"def",
"_on_model_save",
"(",
"sender",
",",
"*",
"*",
"kwargs",
")",
":",
"created",
",",
"instance",
"=",
"kwargs",
"[",
"'created'",
"]",
",",
"kwargs",
"[",
"'instance'",
"]",
"if",
"created",
":",
"signals",
".",
"create",
".",
"send",
"(",
"sende... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | PostgresManager._on_model_delete | When a model gets deleted. | psqlextra/manager/manager.py | def _on_model_delete(sender, **kwargs):
"""When a model gets deleted."""
instance = kwargs['instance']
signals.delete.send(sender, pk=instance.pk) | def _on_model_delete(sender, **kwargs):
"""When a model gets deleted."""
instance = kwargs['instance']
signals.delete.send(sender, pk=instance.pk) | [
"When",
"a",
"model",
"gets",
"deleted",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/manager/manager.py#L577-L581 | [
"def",
"_on_model_delete",
"(",
"sender",
",",
"*",
"*",
"kwargs",
")",
":",
"instance",
"=",
"kwargs",
"[",
"'instance'",
"]",
"signals",
".",
"delete",
".",
"send",
"(",
"sender",
",",
"pk",
"=",
"instance",
".",
"pk",
")"
] | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | IsNotNone | Selects whichever field is not None, in the specified order.
Arguments:
fields:
The fields to attempt to get a value from,
in order.
default:
The value to return in case all values are None.
Returns:
A Case-When expression that tries each field and
... | psqlextra/expressions.py | def IsNotNone(*fields, default=None):
"""Selects whichever field is not None, in the specified order.
Arguments:
fields:
The fields to attempt to get a value from,
in order.
default:
The value to return in case all values are None.
Returns:
A Ca... | def IsNotNone(*fields, default=None):
"""Selects whichever field is not None, in the specified order.
Arguments:
fields:
The fields to attempt to get a value from,
in order.
default:
The value to return in case all values are None.
Returns:
A Ca... | [
"Selects",
"whichever",
"field",
"is",
"not",
"None",
"in",
"the",
"specified",
"order",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/expressions.py#L202-L231 | [
"def",
"IsNotNone",
"(",
"*",
"fields",
",",
"default",
"=",
"None",
")",
":",
"when_clauses",
"=",
"[",
"expressions",
".",
"When",
"(",
"~",
"expressions",
".",
"Q",
"(",
"*",
"*",
"{",
"field",
":",
"None",
"}",
")",
",",
"then",
"=",
"expressio... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | HStoreValue.resolve_expression | Resolves expressions inside the dictionary. | psqlextra/expressions.py | def resolve_expression(self, *args, **kwargs):
"""Resolves expressions inside the dictionary."""
result = dict()
for key, value in self.value.items():
if hasattr(value, 'resolve_expression'):
result[key] = value.resolve_expression(
*args, **kwargs... | def resolve_expression(self, *args, **kwargs):
"""Resolves expressions inside the dictionary."""
result = dict()
for key, value in self.value.items():
if hasattr(value, 'resolve_expression'):
result[key] = value.resolve_expression(
*args, **kwargs... | [
"Resolves",
"expressions",
"inside",
"the",
"dictionary",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/expressions.py#L17-L28 | [
"def",
"resolve_expression",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"result",
"=",
"dict",
"(",
")",
"for",
"key",
",",
"value",
"in",
"self",
".",
"value",
".",
"items",
"(",
")",
":",
"if",
"hasattr",
"(",
"value",
",... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | HStoreValue.as_sql | Compiles the HStore value into SQL.
Compiles expressions contained in the values
of HStore entries as well.
Given a dictionary like:
dict(key1='val1', key2='val2')
The resulting SQL will be:
hstore(hstore('key1', 'val1'), hstore('key2', 'val2')) | psqlextra/expressions.py | def as_sql(self, compiler, connection):
"""Compiles the HStore value into SQL.
Compiles expressions contained in the values
of HStore entries as well.
Given a dictionary like:
dict(key1='val1', key2='val2')
The resulting SQL will be:
hstore(hstore('ke... | def as_sql(self, compiler, connection):
"""Compiles the HStore value into SQL.
Compiles expressions contained in the values
of HStore entries as well.
Given a dictionary like:
dict(key1='val1', key2='val2')
The resulting SQL will be:
hstore(hstore('ke... | [
"Compiles",
"the",
"HStore",
"value",
"into",
"SQL",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/expressions.py#L30-L57 | [
"def",
"as_sql",
"(",
"self",
",",
"compiler",
",",
"connection",
")",
":",
"result",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"self",
".",
"value",
".",
"items",
"(",
")",
":",
"if",
"hasattr",
"(",
"value",
",",
"'as_sql'",
")",
":",
"s... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
test | HStoreColumn.as_sql | Compiles this expression into SQL. | psqlextra/expressions.py | def as_sql(self, compiler, connection):
"""Compiles this expression into SQL."""
qn = compiler.quote_name_unless_alias
return "%s.%s->'%s'" % (qn(self.alias), qn(self.target.column), self.hstore_key), [] | def as_sql(self, compiler, connection):
"""Compiles this expression into SQL."""
qn = compiler.quote_name_unless_alias
return "%s.%s->'%s'" % (qn(self.alias), qn(self.target.column), self.hstore_key), [] | [
"Compiles",
"this",
"expression",
"into",
"SQL",
"."
] | SectorLabs/django-postgres-extra | python | https://github.com/SectorLabs/django-postgres-extra/blob/eef2ed5504d225858d4e4f5d77a838082ca6053e/psqlextra/expressions.py#L98-L102 | [
"def",
"as_sql",
"(",
"self",
",",
"compiler",
",",
"connection",
")",
":",
"qn",
"=",
"compiler",
".",
"quote_name_unless_alias",
"return",
"\"%s.%s->'%s'\"",
"%",
"(",
"qn",
"(",
"self",
".",
"alias",
")",
",",
"qn",
"(",
"self",
".",
"target",
".",
... | eef2ed5504d225858d4e4f5d77a838082ca6053e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.