repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
DLR-RM/RAFCON | source/rafcon/core/config.py | Config.load | def load(self, config_file=None, path=None):
"""Loads the configuration from a specific file
:param config_file: the name of the config file
:param path: the path to the config file
"""
if config_file is None:
if path is None:
path, config_file = spli... | python | def load(self, config_file=None, path=None):
"""Loads the configuration from a specific file
:param config_file: the name of the config file
:param path: the path to the config file
"""
if config_file is None:
if path is None:
path, config_file = spli... | [
"def",
"load",
"(",
"self",
",",
"config_file",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"if",
"config_file",
"is",
"None",
":",
"if",
"path",
"is",
"None",
":",
"path",
",",
"config_file",
"=",
"split",
"(",
"resource_filename",
"(",
"__name__... | Loads the configuration from a specific file
:param config_file: the name of the config file
:param path: the path to the config file | [
"Loads",
"the",
"configuration",
"from",
"a",
"specific",
"file"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/config.py#L81-L92 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/state_editor.py | StateEditorController.register_view | def register_view(self, view):
"""Called when the View was registered
Can be used e.g. to connect signals. Here, the destroy signal is connected to close the application
"""
super(StateEditorController, self).register_view(view)
view.prepare_the_labels() # the preparation of th... | python | def register_view(self, view):
"""Called when the View was registered
Can be used e.g. to connect signals. Here, the destroy signal is connected to close the application
"""
super(StateEditorController, self).register_view(view)
view.prepare_the_labels() # the preparation of th... | [
"def",
"register_view",
"(",
"self",
",",
"view",
")",
":",
"super",
"(",
"StateEditorController",
",",
"self",
")",
".",
"register_view",
"(",
"view",
")",
"view",
".",
"prepare_the_labels",
"(",
")",
"# the preparation of the labels is done here to take into account... | Called when the View was registered
Can be used e.g. to connect signals. Here, the destroy signal is connected to close the application | [
"Called",
"when",
"the",
"View",
"was",
"registered"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/state_editor.py#L89-L155 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/state_editor.py | StateEditorController.state_type_changed | def state_type_changed(self, model, prop_name, info):
"""Reopen state editor when state type is changed
When the type of the observed state changes, a new model is created. The look of this controller's view
depends on the kind of model. Therefore, we have to destroy this editor and open a new ... | python | def state_type_changed(self, model, prop_name, info):
"""Reopen state editor when state type is changed
When the type of the observed state changes, a new model is created. The look of this controller's view
depends on the kind of model. Therefore, we have to destroy this editor and open a new ... | [
"def",
"state_type_changed",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"msg",
"=",
"info",
"[",
"'arg'",
"]",
"# print(self.__class__.__name__, \"state_type_changed check\", info)",
"if",
"msg",
".",
"action",
"in",
"[",
"'change_state_type... | Reopen state editor when state type is changed
When the type of the observed state changes, a new model is created. The look of this controller's view
depends on the kind of model. Therefore, we have to destroy this editor and open a new one with the new model. | [
"Reopen",
"state",
"editor",
"when",
"state",
"type",
"is",
"changed"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/state_editor.py#L179-L193 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/state_editor.py | StateEditorController.state_destruction | def state_destruction(self, model, prop_name, info):
""" Close state editor when state is being destructed """
import rafcon.gui.singleton as gui_singletons
states_editor_ctrl = gui_singletons.main_window_controller.get_controller('states_editor_ctrl')
state_identifier = states_editor_ct... | python | def state_destruction(self, model, prop_name, info):
""" Close state editor when state is being destructed """
import rafcon.gui.singleton as gui_singletons
states_editor_ctrl = gui_singletons.main_window_controller.get_controller('states_editor_ctrl')
state_identifier = states_editor_ct... | [
"def",
"state_destruction",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"import",
"rafcon",
".",
"gui",
".",
"singleton",
"as",
"gui_singletons",
"states_editor_ctrl",
"=",
"gui_singletons",
".",
"main_window_controller",
".",
"get_controll... | Close state editor when state is being destructed | [
"Close",
"state",
"editor",
"when",
"state",
"is",
"being",
"destructed"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/state_editor.py#L196-L201 |
DLR-RM/RAFCON | source/rafcon/gui/models/state_machine.py | StateMachineModel.prepare_destruction | def prepare_destruction(self):
"""Prepares the model for destruction
Unregister itself as observer from the state machine and the root state
"""
if self.state_machine is None:
logger.verbose("Multiple calls of prepare destruction for {0}".format(self))
self.destructi... | python | def prepare_destruction(self):
"""Prepares the model for destruction
Unregister itself as observer from the state machine and the root state
"""
if self.state_machine is None:
logger.verbose("Multiple calls of prepare destruction for {0}".format(self))
self.destructi... | [
"def",
"prepare_destruction",
"(",
"self",
")",
":",
"if",
"self",
".",
"state_machine",
"is",
"None",
":",
"logger",
".",
"verbose",
"(",
"\"Multiple calls of prepare destruction for {0}\"",
".",
"format",
"(",
"self",
")",
")",
"self",
".",
"destruction_signal",... | Prepares the model for destruction
Unregister itself as observer from the state machine and the root state | [
"Prepares",
"the",
"model",
"for",
"destruction"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state_machine.py#L156-L177 |
DLR-RM/RAFCON | source/rafcon/gui/models/state_machine.py | StateMachineModel.meta_changed | def meta_changed(self, model, prop_name, info):
"""When the meta was changed, we have to set the dirty flag, as the changes are unsaved"""
self.state_machine.marked_dirty = True
msg = info.arg
if model is not self and msg.change.startswith('sm_notification_'): # Signal was caused by the... | python | def meta_changed(self, model, prop_name, info):
"""When the meta was changed, we have to set the dirty flag, as the changes are unsaved"""
self.state_machine.marked_dirty = True
msg = info.arg
if model is not self and msg.change.startswith('sm_notification_'): # Signal was caused by the... | [
"def",
"meta_changed",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"self",
".",
"state_machine",
".",
"marked_dirty",
"=",
"True",
"msg",
"=",
"info",
".",
"arg",
"if",
"model",
"is",
"not",
"self",
"and",
"msg",
".",
"change",
... | When the meta was changed, we have to set the dirty flag, as the changes are unsaved | [
"When",
"the",
"meta",
"was",
"changed",
"we",
"have",
"to",
"set",
"the",
"dirty",
"flag",
"as",
"the",
"changes",
"are",
"unsaved"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state_machine.py#L215-L224 |
DLR-RM/RAFCON | source/rafcon/gui/models/state_machine.py | StateMachineModel.action_signal_triggered | def action_signal_triggered(self, model, prop_name, info):
"""When the action was performed, we have to set the dirty flag, as the changes are unsaved"""
# print("ACTION_signal_triggered state machine: ", model, prop_name, info)
self.state_machine.marked_dirty = True
msg = info.arg
... | python | def action_signal_triggered(self, model, prop_name, info):
"""When the action was performed, we have to set the dirty flag, as the changes are unsaved"""
# print("ACTION_signal_triggered state machine: ", model, prop_name, info)
self.state_machine.marked_dirty = True
msg = info.arg
... | [
"def",
"action_signal_triggered",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"# print(\"ACTION_signal_triggered state machine: \", model, prop_name, info)",
"self",
".",
"state_machine",
".",
"marked_dirty",
"=",
"True",
"msg",
"=",
"info",
".",... | When the action was performed, we have to set the dirty flag, as the changes are unsaved | [
"When",
"the",
"action",
"was",
"performed",
"we",
"have",
"to",
"set",
"the",
"dirty",
"flag",
"as",
"the",
"changes",
"are",
"unsaved"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state_machine.py#L227-L242 |
DLR-RM/RAFCON | source/rafcon/gui/models/state_machine.py | StateMachineModel.get_state_model_by_path | def get_state_model_by_path(self, path):
"""Returns the `StateModel` for the given `path`
Searches a `StateModel` in the state machine, who's path is given by `path`.
:param str path: Path of the searched state
:return: The state with that path
:rtype: StateMo... | python | def get_state_model_by_path(self, path):
"""Returns the `StateModel` for the given `path`
Searches a `StateModel` in the state machine, who's path is given by `path`.
:param str path: Path of the searched state
:return: The state with that path
:rtype: StateMo... | [
"def",
"get_state_model_by_path",
"(",
"self",
",",
"path",
")",
":",
"path_elements",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
"path_elements",
".",
"pop",
"(",
"0",
")",
"current_state_model",
"=",
"self",
".",
"root_state",
"for",
"state_id",
"in",
"... | Returns the `StateModel` for the given `path`
Searches a `StateModel` in the state machine, who's path is given by `path`.
:param str path: Path of the searched state
:return: The state with that path
:rtype: StateModel
:raises: ValueError, if path is invalid/... | [
"Returns",
"the",
"StateModel",
"for",
"the",
"given",
"path",
"Searches",
"a",
"StateModel",
"in",
"the",
"state",
"machine",
"who",
"s",
"path",
"is",
"given",
"by",
"path",
".",
":",
"param",
"str",
"path",
":",
"Path",
"of",
"the",
"searched",
"state... | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state_machine.py#L261-L292 |
DLR-RM/RAFCON | source/rafcon/gui/models/state_machine.py | StateMachineModel.load_meta_data | def load_meta_data(self, path=None, recursively=True):
"""Load meta data of state machine model from the file system
The meta data of the state machine model is loaded from the file system and stored in the meta property of the
model. Existing meta data is removed. Also the meta data of root st... | python | def load_meta_data(self, path=None, recursively=True):
"""Load meta data of state machine model from the file system
The meta data of the state machine model is loaded from the file system and stored in the meta property of the
model. Existing meta data is removed. Also the meta data of root st... | [
"def",
"load_meta_data",
"(",
"self",
",",
"path",
"=",
"None",
",",
"recursively",
"=",
"True",
")",
":",
"meta_data_path",
"=",
"path",
"if",
"path",
"is",
"not",
"None",
"else",
"self",
".",
"state_machine",
".",
"file_system_path",
"if",
"meta_data_path"... | Load meta data of state machine model from the file system
The meta data of the state machine model is loaded from the file system and stored in the meta property of the
model. Existing meta data is removed. Also the meta data of root state and children is loaded.
:param str path: Optional pat... | [
"Load",
"meta",
"data",
"of",
"state",
"machine",
"model",
"from",
"the",
"file",
"system"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state_machine.py#L341-L372 |
DLR-RM/RAFCON | source/rafcon/gui/models/state_machine.py | StateMachineModel.store_meta_data | def store_meta_data(self, copy_path=None):
"""Save meta data of the state machine model to the file system
This method generates a dictionary of the meta data of the state machine and stores it on the filesystem.
:param str copy_path: Optional, if the path is specified, it will be used instead... | python | def store_meta_data(self, copy_path=None):
"""Save meta data of the state machine model to the file system
This method generates a dictionary of the meta data of the state machine and stores it on the filesystem.
:param str copy_path: Optional, if the path is specified, it will be used instead... | [
"def",
"store_meta_data",
"(",
"self",
",",
"copy_path",
"=",
"None",
")",
":",
"if",
"copy_path",
":",
"meta_file_json",
"=",
"os",
".",
"path",
".",
"join",
"(",
"copy_path",
",",
"storage",
".",
"FILE_NAME_META_DATA",
")",
"else",
":",
"meta_file_json",
... | Save meta data of the state machine model to the file system
This method generates a dictionary of the meta data of the state machine and stores it on the filesystem.
:param str copy_path: Optional, if the path is specified, it will be used instead of the file system path | [
"Save",
"meta",
"data",
"of",
"the",
"state",
"machine",
"model",
"to",
"the",
"file",
"system"
] | train | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state_machine.py#L374-L388 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies.convert_trees | def convert_trees(self, ptb_trees, representation='basic', universal=True,
include_punct=True, include_erased=False, **kwargs):
"""Convert a list of Penn Treebank formatted strings (ptb_trees)
into Stanford Dependencies. The dependencies are represented
as a list of sentenc... | python | def convert_trees(self, ptb_trees, representation='basic', universal=True,
include_punct=True, include_erased=False, **kwargs):
"""Convert a list of Penn Treebank formatted strings (ptb_trees)
into Stanford Dependencies. The dependencies are represented
as a list of sentenc... | [
"def",
"convert_trees",
"(",
"self",
",",
"ptb_trees",
",",
"representation",
"=",
"'basic'",
",",
"universal",
"=",
"True",
",",
"include_punct",
"=",
"True",
",",
"include_erased",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",... | Convert a list of Penn Treebank formatted strings (ptb_trees)
into Stanford Dependencies. The dependencies are represented
as a list of sentences (CoNLL.Corpus), where each sentence
(CoNLL.Sentence) is itself a list of CoNLL.Token objects.
Currently supported representations are 'basic'... | [
"Convert",
"a",
"list",
"of",
"Penn",
"Treebank",
"formatted",
"strings",
"(",
"ptb_trees",
")",
"into",
"Stanford",
"Dependencies",
".",
"The",
"dependencies",
"are",
"represented",
"as",
"a",
"list",
"of",
"sentences",
"(",
"CoNLL",
".",
"Corpus",
")",
"wh... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L92-L116 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies.setup_and_get_default_path | def setup_and_get_default_path(self, jar_base_filename):
"""Determine the user-specific install path for the Stanford
Dependencies jar if the jar_url is not specified and ensure that
it is writable (that is, make sure the directory exists). Returns
the full path for where the jar file sh... | python | def setup_and_get_default_path(self, jar_base_filename):
"""Determine the user-specific install path for the Stanford
Dependencies jar if the jar_url is not specified and ensure that
it is writable (that is, make sure the directory exists). Returns
the full path for where the jar file sh... | [
"def",
"setup_and_get_default_path",
"(",
"self",
",",
"jar_base_filename",
")",
":",
"import",
"os",
"import",
"errno",
"install_dir",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"INSTALL_DIR",
")",
"try",
":",
"os",
".",
"makedirs",
"(",
"install_dir",
... | Determine the user-specific install path for the Stanford
Dependencies jar if the jar_url is not specified and ensure that
it is writable (that is, make sure the directory exists). Returns
the full path for where the jar file should be installed. | [
"Determine",
"the",
"user",
"-",
"specific",
"install",
"path",
"for",
"the",
"Stanford",
"Dependencies",
"jar",
"if",
"the",
"jar_url",
"is",
"not",
"specified",
"and",
"ensure",
"that",
"it",
"is",
"writable",
"(",
"that",
"is",
"make",
"sure",
"the",
"d... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L126-L140 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies.download_if_missing | def download_if_missing(self, version=None, verbose=True):
"""Download the jar for version into the jar_filename specified
in the constructor. Will not overwrite jar_filename if it already
exists. version defaults to DEFAULT_CORENLP_VERSION (ideally the
latest but we can't guarantee that... | python | def download_if_missing(self, version=None, verbose=True):
"""Download the jar for version into the jar_filename specified
in the constructor. Will not overwrite jar_filename if it already
exists. version defaults to DEFAULT_CORENLP_VERSION (ideally the
latest but we can't guarantee that... | [
"def",
"download_if_missing",
"(",
"self",
",",
"version",
"=",
"None",
",",
"verbose",
"=",
"True",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"jar_filename",
")",
":",
"return",
"jar_url",
"=",
"self",
".",
"get_jar_url",
"("... | Download the jar for version into the jar_filename specified
in the constructor. Will not overwrite jar_filename if it already
exists. version defaults to DEFAULT_CORENLP_VERSION (ideally the
latest but we can't guarantee that since PyStanfordDependencies
is distributed separately). | [
"Download",
"the",
"jar",
"for",
"version",
"into",
"the",
"jar_filename",
"specified",
"in",
"the",
"constructor",
".",
"Will",
"not",
"overwrite",
"jar_filename",
"if",
"it",
"already",
"exists",
".",
"version",
"defaults",
"to",
"DEFAULT_CORENLP_VERSION",
"(",
... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L141-L154 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies._raise_on_bad_representation | def _raise_on_bad_representation(representation):
"""Ensure that representation is a known Stanford Dependency
representation (raises a ValueError if the representation is
invalid)."""
if representation not in REPRESENTATIONS:
repr_desc = ', '.join(map(repr, REPRESENTATIONS))... | python | def _raise_on_bad_representation(representation):
"""Ensure that representation is a known Stanford Dependency
representation (raises a ValueError if the representation is
invalid)."""
if representation not in REPRESENTATIONS:
repr_desc = ', '.join(map(repr, REPRESENTATIONS))... | [
"def",
"_raise_on_bad_representation",
"(",
"representation",
")",
":",
"if",
"representation",
"not",
"in",
"REPRESENTATIONS",
":",
"repr_desc",
"=",
"', '",
".",
"join",
"(",
"map",
"(",
"repr",
",",
"REPRESENTATIONS",
")",
")",
"raise",
"ValueError",
"(",
"... | Ensure that representation is a known Stanford Dependency
representation (raises a ValueError if the representation is
invalid). | [
"Ensure",
"that",
"representation",
"is",
"a",
"known",
"Stanford",
"Dependency",
"representation",
"(",
"raises",
"a",
"ValueError",
"if",
"the",
"representation",
"is",
"invalid",
")",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L157-L164 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies._raise_on_bad_jar_filename | def _raise_on_bad_jar_filename(jar_filename):
"""Ensure that jar_filename is a valid path to a jar file."""
if jar_filename is None:
return
if not isinstance(jar_filename, string_type):
raise TypeError("jar_filename is not a string: %r" % jar_filename)
if not os... | python | def _raise_on_bad_jar_filename(jar_filename):
"""Ensure that jar_filename is a valid path to a jar file."""
if jar_filename is None:
return
if not isinstance(jar_filename, string_type):
raise TypeError("jar_filename is not a string: %r" % jar_filename)
if not os... | [
"def",
"_raise_on_bad_jar_filename",
"(",
"jar_filename",
")",
":",
"if",
"jar_filename",
"is",
"None",
":",
"return",
"if",
"not",
"isinstance",
"(",
"jar_filename",
",",
"string_type",
")",
":",
"raise",
"TypeError",
"(",
"\"jar_filename is not a string: %r\"",
"%... | Ensure that jar_filename is a valid path to a jar file. | [
"Ensure",
"that",
"jar_filename",
"is",
"a",
"valid",
"path",
"to",
"a",
"jar",
"file",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L175-L184 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies.get_jar_url | def get_jar_url(version=None):
"""Get the URL to a Stanford CoreNLP jar file with a specific
version. These jars come from Maven since the Maven version is
smaller than the full CoreNLP distributions. Defaults to
DEFAULT_CORENLP_VERSION."""
if version is None:
version... | python | def get_jar_url(version=None):
"""Get the URL to a Stanford CoreNLP jar file with a specific
version. These jars come from Maven since the Maven version is
smaller than the full CoreNLP distributions. Defaults to
DEFAULT_CORENLP_VERSION."""
if version is None:
version... | [
"def",
"get_jar_url",
"(",
"version",
"=",
"None",
")",
":",
"if",
"version",
"is",
"None",
":",
"version",
"=",
"DEFAULT_CORENLP_VERSION",
"try",
":",
"string_type",
"=",
"basestring",
"except",
"NameError",
":",
"string_type",
"=",
"str",
"if",
"not",
"isi... | Get the URL to a Stanford CoreNLP jar file with a specific
version. These jars come from Maven since the Maven version is
smaller than the full CoreNLP distributions. Defaults to
DEFAULT_CORENLP_VERSION. | [
"Get",
"the",
"URL",
"to",
"a",
"Stanford",
"CoreNLP",
"jar",
"file",
"with",
"a",
"specific",
"version",
".",
"These",
"jars",
"come",
"from",
"Maven",
"since",
"the",
"Maven",
"version",
"is",
"smaller",
"than",
"the",
"full",
"CoreNLP",
"distributions",
... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L187-L206 |
dmcc/PyStanfordDependencies | StanfordDependencies/StanfordDependencies.py | StanfordDependencies.get_instance | def get_instance(jar_filename=None, version=None,
download_if_missing=True, backend='jpype',
**extra_args):
"""This is the typical mechanism of constructing a
StanfordDependencies instance. The backend parameter determines
which backend to load (currentl... | python | def get_instance(jar_filename=None, version=None,
download_if_missing=True, backend='jpype',
**extra_args):
"""This is the typical mechanism of constructing a
StanfordDependencies instance. The backend parameter determines
which backend to load (currentl... | [
"def",
"get_instance",
"(",
"jar_filename",
"=",
"None",
",",
"version",
"=",
"None",
",",
"download_if_missing",
"=",
"True",
",",
"backend",
"=",
"'jpype'",
",",
"*",
"*",
"extra_args",
")",
":",
"StanfordDependencies",
".",
"_raise_on_bad_jar_filename",
"(",
... | This is the typical mechanism of constructing a
StanfordDependencies instance. The backend parameter determines
which backend to load (currently can be 'subprocess' or 'jpype').
To determine which jar file is used, you must specify
jar_filename, download_if_missing=True, and/or version.... | [
"This",
"is",
"the",
"typical",
"mechanism",
"of",
"constructing",
"a",
"StanfordDependencies",
"instance",
".",
"The",
"backend",
"parameter",
"determines",
"which",
"backend",
"to",
"load",
"(",
"currently",
"can",
"be",
"subprocess",
"or",
"jpype",
")",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/StanfordDependencies.py#L209-L262 |
dmcc/PyStanfordDependencies | StanfordDependencies/JPypeBackend.py | JPypeBackend.convert_tree | def convert_tree(self, ptb_tree, representation='basic',
include_punct=True, include_erased=False,
add_lemmas=False, universal=True):
"""Arguments are as in StanfordDependencies.convert_trees but with
the addition of add_lemmas. If add_lemmas=True, we will run t... | python | def convert_tree(self, ptb_tree, representation='basic',
include_punct=True, include_erased=False,
add_lemmas=False, universal=True):
"""Arguments are as in StanfordDependencies.convert_trees but with
the addition of add_lemmas. If add_lemmas=True, we will run t... | [
"def",
"convert_tree",
"(",
"self",
",",
"ptb_tree",
",",
"representation",
"=",
"'basic'",
",",
"include_punct",
"=",
"True",
",",
"include_erased",
"=",
"False",
",",
"add_lemmas",
"=",
"False",
",",
"universal",
"=",
"True",
")",
":",
"self",
".",
"_rai... | Arguments are as in StanfordDependencies.convert_trees but with
the addition of add_lemmas. If add_lemmas=True, we will run the
Stanford CoreNLP lemmatizer and fill in the lemma field. | [
"Arguments",
"are",
"as",
"in",
"StanfordDependencies",
".",
"convert_trees",
"but",
"with",
"the",
"addition",
"of",
"add_lemmas",
".",
"If",
"add_lemmas",
"=",
"True",
"we",
"will",
"run",
"the",
"Stanford",
"CoreNLP",
"lemmatizer",
"and",
"fill",
"in",
"the... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/JPypeBackend.py#L86-L149 |
dmcc/PyStanfordDependencies | StanfordDependencies/JPypeBackend.py | JPypeBackend.stem | def stem(self, form, tag):
"""Returns the stem of word with specific form and part-of-speech
tag according to the Stanford lemmatizer. Lemmas are cached."""
key = (form, tag)
if key not in self.lemma_cache:
lemma = self.stemmer(*key).word()
self.lemma_cache[key] =... | python | def stem(self, form, tag):
"""Returns the stem of word with specific form and part-of-speech
tag according to the Stanford lemmatizer. Lemmas are cached."""
key = (form, tag)
if key not in self.lemma_cache:
lemma = self.stemmer(*key).word()
self.lemma_cache[key] =... | [
"def",
"stem",
"(",
"self",
",",
"form",
",",
"tag",
")",
":",
"key",
"=",
"(",
"form",
",",
"tag",
")",
"if",
"key",
"not",
"in",
"self",
".",
"lemma_cache",
":",
"lemma",
"=",
"self",
".",
"stemmer",
"(",
"*",
"key",
")",
".",
"word",
"(",
... | Returns the stem of word with specific form and part-of-speech
tag according to the Stanford lemmatizer. Lemmas are cached. | [
"Returns",
"the",
"stem",
"of",
"word",
"with",
"specific",
"form",
"and",
"part",
"-",
"of",
"-",
"speech",
"tag",
"according",
"to",
"the",
"Stanford",
"lemmatizer",
".",
"Lemmas",
"are",
"cached",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/JPypeBackend.py#L150-L157 |
dmcc/PyStanfordDependencies | StanfordDependencies/JPypeBackend.py | JPypeBackend._get_deps | def _get_deps(self, tree, include_punct, representation, universal):
"""Get a list of dependencies from a Stanford Tree for a specific
Stanford Dependencies representation."""
if universal:
converter = self.universal_converter
if self.universal_converter == self.converte... | python | def _get_deps(self, tree, include_punct, representation, universal):
"""Get a list of dependencies from a Stanford Tree for a specific
Stanford Dependencies representation."""
if universal:
converter = self.universal_converter
if self.universal_converter == self.converte... | [
"def",
"_get_deps",
"(",
"self",
",",
"tree",
",",
"include_punct",
",",
"representation",
",",
"universal",
")",
":",
"if",
"universal",
":",
"converter",
"=",
"self",
".",
"universal_converter",
"if",
"self",
".",
"universal_converter",
"==",
"self",
".",
... | Get a list of dependencies from a Stanford Tree for a specific
Stanford Dependencies representation. | [
"Get",
"a",
"list",
"of",
"dependencies",
"from",
"a",
"Stanford",
"Tree",
"for",
"a",
"specific",
"Stanford",
"Dependencies",
"representation",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/JPypeBackend.py#L159-L190 |
dmcc/PyStanfordDependencies | StanfordDependencies/JPypeBackend.py | JPypeBackend._listify | def _listify(collection):
"""This is a workaround where Collections are no longer iterable
when using JPype."""
new_list = []
for index in range(len(collection)):
new_list.append(collection[index])
return new_list | python | def _listify(collection):
"""This is a workaround where Collections are no longer iterable
when using JPype."""
new_list = []
for index in range(len(collection)):
new_list.append(collection[index])
return new_list | [
"def",
"_listify",
"(",
"collection",
")",
":",
"new_list",
"=",
"[",
"]",
"for",
"index",
"in",
"range",
"(",
"len",
"(",
"collection",
")",
")",
":",
"new_list",
".",
"append",
"(",
"collection",
"[",
"index",
"]",
")",
"return",
"new_list"
] | This is a workaround where Collections are no longer iterable
when using JPype. | [
"This",
"is",
"a",
"workaround",
"where",
"Collections",
"are",
"no",
"longer",
"iterable",
"when",
"using",
"JPype",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/JPypeBackend.py#L193-L199 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Token.as_conll | def as_conll(self):
"""Represent this Token as a line as a string in CoNLL-X format."""
def get(field):
value = getattr(self, field)
if value is None:
value = '_'
elif field == 'feats':
value = '|'.join(value)
return str(val... | python | def as_conll(self):
"""Represent this Token as a line as a string in CoNLL-X format."""
def get(field):
value = getattr(self, field)
if value is None:
value = '_'
elif field == 'feats':
value = '|'.join(value)
return str(val... | [
"def",
"as_conll",
"(",
"self",
")",
":",
"def",
"get",
"(",
"field",
")",
":",
"value",
"=",
"getattr",
"(",
"self",
",",
"field",
")",
"if",
"value",
"is",
"None",
":",
"value",
"=",
"'_'",
"elif",
"field",
"==",
"'feats'",
":",
"value",
"=",
"... | Represent this Token as a line as a string in CoNLL-X format. | [
"Represent",
"this",
"Token",
"as",
"a",
"line",
"as",
"a",
"string",
"in",
"CoNLL",
"-",
"X",
"format",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L74-L83 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Token.from_conll | def from_conll(this_class, text):
"""Construct a Token from a line in CoNLL-X format."""
fields = text.split('\t')
fields[0] = int(fields[0]) # index
fields[6] = int(fields[6]) # head index
if fields[5] != '_': # feats
fields[5] = tuple(fields[5].split('|'))
f... | python | def from_conll(this_class, text):
"""Construct a Token from a line in CoNLL-X format."""
fields = text.split('\t')
fields[0] = int(fields[0]) # index
fields[6] = int(fields[6]) # head index
if fields[5] != '_': # feats
fields[5] = tuple(fields[5].split('|'))
f... | [
"def",
"from_conll",
"(",
"this_class",
",",
"text",
")",
":",
"fields",
"=",
"text",
".",
"split",
"(",
"'\\t'",
")",
"fields",
"[",
"0",
"]",
"=",
"int",
"(",
"fields",
"[",
"0",
"]",
")",
"# index",
"fields",
"[",
"6",
"]",
"=",
"int",
"(",
... | Construct a Token from a line in CoNLL-X format. | [
"Construct",
"a",
"Token",
"from",
"a",
"line",
"in",
"CoNLL",
"-",
"X",
"format",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L85-L94 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Sentence.renumber | def renumber(self):
"""Destructively renumber the indices based on the actual tokens
(e.g., if there are gaps between token indices, this will remove
them). Old Token objects will still exist, so you'll need to
update your references."""
mapping = {0: 0} # old index -> real index... | python | def renumber(self):
"""Destructively renumber the indices based on the actual tokens
(e.g., if there are gaps between token indices, this will remove
them). Old Token objects will still exist, so you'll need to
update your references."""
mapping = {0: 0} # old index -> real index... | [
"def",
"renumber",
"(",
"self",
")",
":",
"mapping",
"=",
"{",
"0",
":",
"0",
"}",
"# old index -> real index",
"needs_renumbering",
"=",
"False",
"for",
"real_index",
",",
"token",
"in",
"enumerate",
"(",
"self",
",",
"1",
")",
":",
"mapping",
"[",
"tok... | Destructively renumber the indices based on the actual tokens
(e.g., if there are gaps between token indices, this will remove
them). Old Token objects will still exist, so you'll need to
update your references. | [
"Destructively",
"renumber",
"the",
"indices",
"based",
"on",
"the",
"actual",
"tokens",
"(",
"e",
".",
"g",
".",
"if",
"there",
"are",
"gaps",
"between",
"token",
"indices",
"this",
"will",
"remove",
"them",
")",
".",
"Old",
"Token",
"objects",
"will",
... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L98-L114 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Sentence.as_asciitree | def as_asciitree(self, str_func=None):
"""Represent this Sentence as an ASCII tree string. Requires
the asciitree package. A default token stringifier is provided
but for custom formatting, specify a str_func which should take
a single Token and return a string."""
import asciitr... | python | def as_asciitree(self, str_func=None):
"""Represent this Sentence as an ASCII tree string. Requires
the asciitree package. A default token stringifier is provided
but for custom formatting, specify a str_func which should take
a single Token and return a string."""
import asciitr... | [
"def",
"as_asciitree",
"(",
"self",
",",
"str_func",
"=",
"None",
")",
":",
"import",
"asciitree",
"from",
"collections",
"import",
"defaultdict",
"children",
"=",
"defaultdict",
"(",
"list",
")",
"# since erased nodes may be missing, multiple tokens may have same",
"# ... | Represent this Sentence as an ASCII tree string. Requires
the asciitree package. A default token stringifier is provided
but for custom formatting, specify a str_func which should take
a single Token and return a string. | [
"Represent",
"this",
"Sentence",
"as",
"an",
"ASCII",
"tree",
"string",
".",
"Requires",
"the",
"asciitree",
"package",
".",
"A",
"default",
"token",
"stringifier",
"is",
"provided",
"but",
"for",
"custom",
"formatting",
"specify",
"a",
"str_func",
"which",
"s... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L120-L155 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Sentence.as_dotgraph | def as_dotgraph(self, digraph_kwargs=None, id_prefix=None,
node_formatter=None, edge_formatter=None):
"""Returns this sentence as a graphviz.Digraph. Requires the
graphviz Python package and graphviz itself. There are several
ways to customize. Graph level keyword arguments c... | python | def as_dotgraph(self, digraph_kwargs=None, id_prefix=None,
node_formatter=None, edge_formatter=None):
"""Returns this sentence as a graphviz.Digraph. Requires the
graphviz Python package and graphviz itself. There are several
ways to customize. Graph level keyword arguments c... | [
"def",
"as_dotgraph",
"(",
"self",
",",
"digraph_kwargs",
"=",
"None",
",",
"id_prefix",
"=",
"None",
",",
"node_formatter",
"=",
"None",
",",
"edge_formatter",
"=",
"None",
")",
":",
"digraph_kwargs",
"=",
"digraph_kwargs",
"or",
"{",
"}",
"id_prefix",
"=",... | Returns this sentence as a graphviz.Digraph. Requires the
graphviz Python package and graphviz itself. There are several
ways to customize. Graph level keyword arguments can be passed
as a dictionary to digraph_kwargs. If you're viewing multiple
Sentences in the same graph, you'll need t... | [
"Returns",
"this",
"sentence",
"as",
"a",
"graphviz",
".",
"Digraph",
".",
"Requires",
"the",
"graphviz",
"Python",
"package",
"and",
"graphviz",
"itself",
".",
"There",
"are",
"several",
"ways",
"to",
"customize",
".",
"Graph",
"level",
"keyword",
"arguments"... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L156-L191 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Sentence.from_conll | def from_conll(this_class, stream):
"""Construct a Sentence. stream is an iterable over strings where
each string is a line in CoNLL-X format. If there are multiple
sentences in this stream, we only return the first one."""
stream = iter(stream)
sentence = this_class()
fo... | python | def from_conll(this_class, stream):
"""Construct a Sentence. stream is an iterable over strings where
each string is a line in CoNLL-X format. If there are multiple
sentences in this stream, we only return the first one."""
stream = iter(stream)
sentence = this_class()
fo... | [
"def",
"from_conll",
"(",
"this_class",
",",
"stream",
")",
":",
"stream",
"=",
"iter",
"(",
"stream",
")",
"sentence",
"=",
"this_class",
"(",
")",
"for",
"line",
"in",
"stream",
":",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"line",
":",
... | Construct a Sentence. stream is an iterable over strings where
each string is a line in CoNLL-X format. If there are multiple
sentences in this stream, we only return the first one. | [
"Construct",
"a",
"Sentence",
".",
"stream",
"is",
"an",
"iterable",
"over",
"strings",
"where",
"each",
"string",
"is",
"a",
"line",
"in",
"CoNLL",
"-",
"X",
"format",
".",
"If",
"there",
"are",
"multiple",
"sentences",
"in",
"this",
"stream",
"we",
"on... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L194-L206 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Sentence.from_stanford_dependencies | def from_stanford_dependencies(this_class, stream, tree,
include_erased=False, include_punct=True):
"""Construct a Sentence. stream is an iterable over strings
where each string is a line representing a Stanford Dependency
as in the output of the command line S... | python | def from_stanford_dependencies(this_class, stream, tree,
include_erased=False, include_punct=True):
"""Construct a Sentence. stream is an iterable over strings
where each string is a line representing a Stanford Dependency
as in the output of the command line S... | [
"def",
"from_stanford_dependencies",
"(",
"this_class",
",",
"stream",
",",
"tree",
",",
"include_erased",
"=",
"False",
",",
"include_punct",
"=",
"True",
")",
":",
"stream",
"=",
"iter",
"(",
"stream",
")",
"sentence",
"=",
"this_class",
"(",
")",
"covered... | Construct a Sentence. stream is an iterable over strings
where each string is a line representing a Stanford Dependency
as in the output of the command line Stanford Dependency tool:
deprel(gov-index, dep-depindex)
The corresponding Penn Treebank formatted tree must be provided
... | [
"Construct",
"a",
"Sentence",
".",
"stream",
"is",
"an",
"iterable",
"over",
"strings",
"where",
"each",
"string",
"is",
"a",
"line",
"representing",
"a",
"Stanford",
"Dependency",
"as",
"in",
"the",
"output",
"of",
"the",
"command",
"line",
"Stanford",
"Dep... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L208-L267 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Corpus.from_conll | def from_conll(this_class, stream):
"""Construct a Corpus. stream is an iterable over strings where
each string is a line in CoNLL-X format."""
stream = iter(stream)
corpus = this_class()
while 1:
# read until we get an empty sentence
sentence = Sentence.f... | python | def from_conll(this_class, stream):
"""Construct a Corpus. stream is an iterable over strings where
each string is a line in CoNLL-X format."""
stream = iter(stream)
corpus = this_class()
while 1:
# read until we get an empty sentence
sentence = Sentence.f... | [
"def",
"from_conll",
"(",
"this_class",
",",
"stream",
")",
":",
"stream",
"=",
"iter",
"(",
"stream",
")",
"corpus",
"=",
"this_class",
"(",
")",
"while",
"1",
":",
"# read until we get an empty sentence",
"sentence",
"=",
"Sentence",
".",
"from_conll",
"(",
... | Construct a Corpus. stream is an iterable over strings where
each string is a line in CoNLL-X format. | [
"Construct",
"a",
"Corpus",
".",
"stream",
"is",
"an",
"iterable",
"over",
"strings",
"where",
"each",
"string",
"is",
"a",
"line",
"in",
"CoNLL",
"-",
"X",
"format",
"."
] | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L277-L289 |
dmcc/PyStanfordDependencies | StanfordDependencies/CoNLL.py | Corpus.from_stanford_dependencies | def from_stanford_dependencies(this_class, stream, trees,
include_erased=False, include_punct=True):
"""Construct a Corpus. stream is an iterable over strings where
each string is a line representing a Stanford Dependency as in
the output of the command line St... | python | def from_stanford_dependencies(this_class, stream, trees,
include_erased=False, include_punct=True):
"""Construct a Corpus. stream is an iterable over strings where
each string is a line representing a Stanford Dependency as in
the output of the command line St... | [
"def",
"from_stanford_dependencies",
"(",
"this_class",
",",
"stream",
",",
"trees",
",",
"include_erased",
"=",
"False",
",",
"include_punct",
"=",
"True",
")",
":",
"stream",
"=",
"iter",
"(",
"stream",
")",
"corpus",
"=",
"this_class",
"(",
")",
"for",
... | Construct a Corpus. stream is an iterable over strings where
each string is a line representing a Stanford Dependency as in
the output of the command line Stanford Dependency tool:
deprel(gov-index, dep-depindex)
Sentences are separated by blank lines. A corresponding list of
... | [
"Construct",
"a",
"Corpus",
".",
"stream",
"is",
"an",
"iterable",
"over",
"strings",
"where",
"each",
"string",
"is",
"a",
"line",
"representing",
"a",
"Stanford",
"Dependency",
"as",
"in",
"the",
"output",
"of",
"the",
"command",
"line",
"Stanford",
"Depen... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/CoNLL.py#L291-L309 |
dmcc/PyStanfordDependencies | StanfordDependencies/SubprocessBackend.py | SubprocessBackend.convert_trees | def convert_trees(self, ptb_trees, representation='basic',
include_punct=True, include_erased=False, universal=True,
debug=False):
"""Convert a list of Penn Treebank formatted trees (ptb_trees)
into Stanford Dependencies. The dependencies are represented
... | python | def convert_trees(self, ptb_trees, representation='basic',
include_punct=True, include_erased=False, universal=True,
debug=False):
"""Convert a list of Penn Treebank formatted trees (ptb_trees)
into Stanford Dependencies. The dependencies are represented
... | [
"def",
"convert_trees",
"(",
"self",
",",
"ptb_trees",
",",
"representation",
"=",
"'basic'",
",",
"include_punct",
"=",
"True",
",",
"include_erased",
"=",
"False",
",",
"universal",
"=",
"True",
",",
"debug",
"=",
"False",
")",
":",
"self",
".",
"_raise_... | Convert a list of Penn Treebank formatted trees (ptb_trees)
into Stanford Dependencies. The dependencies are represented
as a list of sentences, where each sentence is itself a list of
Token objects.
Currently supported representations are 'basic', 'collapsed',
'CCprocessed', an... | [
"Convert",
"a",
"list",
"of",
"Penn",
"Treebank",
"formatted",
"trees",
"(",
"ptb_trees",
")",
"into",
"Stanford",
"Dependencies",
".",
"The",
"dependencies",
"are",
"represented",
"as",
"a",
"list",
"of",
"sentences",
"where",
"each",
"sentence",
"is",
"itsel... | train | https://github.com/dmcc/PyStanfordDependencies/blob/43d8f38a19e40087f273330087918c87df6d4d8f/StanfordDependencies/SubprocessBackend.py#L35-L108 |
juju-solutions/charms.reactive | charms/reactive/relations.py | endpoint_from_name | def endpoint_from_name(endpoint_name):
"""The object used for interacting with the named relations, or None.
"""
if endpoint_name is None:
return None
factory = relation_factory(endpoint_name)
if factory:
return factory.from_name(endpoint_name) | python | def endpoint_from_name(endpoint_name):
"""The object used for interacting with the named relations, or None.
"""
if endpoint_name is None:
return None
factory = relation_factory(endpoint_name)
if factory:
return factory.from_name(endpoint_name) | [
"def",
"endpoint_from_name",
"(",
"endpoint_name",
")",
":",
"if",
"endpoint_name",
"is",
"None",
":",
"return",
"None",
"factory",
"=",
"relation_factory",
"(",
"endpoint_name",
")",
"if",
"factory",
":",
"return",
"factory",
".",
"from_name",
"(",
"endpoint_na... | The object used for interacting with the named relations, or None. | [
"The",
"object",
"used",
"for",
"interacting",
"with",
"the",
"named",
"relations",
"or",
"None",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L47-L54 |
juju-solutions/charms.reactive | charms/reactive/relations.py | endpoint_from_flag | def endpoint_from_flag(flag):
"""The object used for interacting with relations tied to a flag, or None.
"""
relation_name = None
value = _get_flag_value(flag)
if isinstance(value, dict) and 'relation' in value:
# old-style RelationBase
relation_name = value['relation']
elif flag... | python | def endpoint_from_flag(flag):
"""The object used for interacting with relations tied to a flag, or None.
"""
relation_name = None
value = _get_flag_value(flag)
if isinstance(value, dict) and 'relation' in value:
# old-style RelationBase
relation_name = value['relation']
elif flag... | [
"def",
"endpoint_from_flag",
"(",
"flag",
")",
":",
"relation_name",
"=",
"None",
"value",
"=",
"_get_flag_value",
"(",
"flag",
")",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
"and",
"'relation'",
"in",
"value",
":",
"# old-style RelationBase",
"relat... | The object used for interacting with relations tied to a flag, or None. | [
"The",
"object",
"used",
"for",
"interacting",
"with",
"relations",
"tied",
"to",
"a",
"flag",
"or",
"None",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L65-L85 |
juju-solutions/charms.reactive | charms/reactive/relations.py | relation_factory | def relation_factory(relation_name):
"""Get the RelationFactory for the given relation name.
Looks for a RelationFactory in the first file matching:
``$CHARM_DIR/hooks/relations/{interface}/{provides,requires,peer}.py``
"""
role, interface = hookenv.relation_to_role_and_interface(relation_name)
... | python | def relation_factory(relation_name):
"""Get the RelationFactory for the given relation name.
Looks for a RelationFactory in the first file matching:
``$CHARM_DIR/hooks/relations/{interface}/{provides,requires,peer}.py``
"""
role, interface = hookenv.relation_to_role_and_interface(relation_name)
... | [
"def",
"relation_factory",
"(",
"relation_name",
")",
":",
"role",
",",
"interface",
"=",
"hookenv",
".",
"relation_to_role_and_interface",
"(",
"relation_name",
")",
"if",
"not",
"(",
"role",
"and",
"interface",
")",
":",
"hookenv",
".",
"log",
"(",
"'Unable ... | Get the RelationFactory for the given relation name.
Looks for a RelationFactory in the first file matching:
``$CHARM_DIR/hooks/relations/{interface}/{provides,requires,peer}.py`` | [
"Get",
"the",
"RelationFactory",
"for",
"the",
"given",
"relation",
"name",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L121-L132 |
juju-solutions/charms.reactive | charms/reactive/relations.py | _relation_module | def _relation_module(role, interface):
"""
Return module for relation based on its role and interface, or None.
Prefers new location (reactive/relations) over old (hooks/relations).
"""
_append_path(hookenv.charm_dir())
_append_path(os.path.join(hookenv.charm_dir(), 'hooks'))
base_module = ... | python | def _relation_module(role, interface):
"""
Return module for relation based on its role and interface, or None.
Prefers new location (reactive/relations) over old (hooks/relations).
"""
_append_path(hookenv.charm_dir())
_append_path(os.path.join(hookenv.charm_dir(), 'hooks'))
base_module = ... | [
"def",
"_relation_module",
"(",
"role",
",",
"interface",
")",
":",
"_append_path",
"(",
"hookenv",
".",
"charm_dir",
"(",
")",
")",
"_append_path",
"(",
"os",
".",
"path",
".",
"join",
"(",
"hookenv",
".",
"charm_dir",
"(",
")",
",",
"'hooks'",
")",
"... | Return module for relation based on its role and interface, or None.
Prefers new location (reactive/relations) over old (hooks/relations). | [
"Return",
"module",
"for",
"relation",
"based",
"on",
"its",
"role",
"and",
"interface",
"or",
"None",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L135-L156 |
juju-solutions/charms.reactive | charms/reactive/relations.py | _find_relation_factory | def _find_relation_factory(module):
"""
Attempt to find a RelationFactory subclass in the module.
Note: RelationFactory and RelationBase are ignored so they may
be imported to be used as base classes without fear.
"""
if not module:
return None
# All the RelationFactory subclasses
... | python | def _find_relation_factory(module):
"""
Attempt to find a RelationFactory subclass in the module.
Note: RelationFactory and RelationBase are ignored so they may
be imported to be used as base classes without fear.
"""
if not module:
return None
# All the RelationFactory subclasses
... | [
"def",
"_find_relation_factory",
"(",
"module",
")",
":",
"if",
"not",
"module",
":",
"return",
"None",
"# All the RelationFactory subclasses",
"candidates",
"=",
"[",
"o",
"for",
"o",
"in",
"(",
"getattr",
"(",
"module",
",",
"attr",
")",
"for",
"attr",
"in... | Attempt to find a RelationFactory subclass in the module.
Note: RelationFactory and RelationBase are ignored so they may
be imported to be used as base classes without fear. | [
"Attempt",
"to",
"find",
"a",
"RelationFactory",
"subclass",
"in",
"the",
"module",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L159-L192 |
juju-solutions/charms.reactive | charms/reactive/relations.py | _migrate_conversations | def _migrate_conversations(): # noqa
"""
Due to issue #28 (https://github.com/juju-solutions/charms.reactive/issues/28),
conversations needed to be updated to be namespaced per relation ID for SERVICE
and UNIT scope. To ensure backwards compatibility, this updates all convs in
the old format to th... | python | def _migrate_conversations(): # noqa
"""
Due to issue #28 (https://github.com/juju-solutions/charms.reactive/issues/28),
conversations needed to be updated to be namespaced per relation ID for SERVICE
and UNIT scope. To ensure backwards compatibility, this updates all convs in
the old format to th... | [
"def",
"_migrate_conversations",
"(",
")",
":",
"# noqa",
"for",
"key",
",",
"data",
"in",
"unitdata",
".",
"kv",
"(",
")",
".",
"getrange",
"(",
"'reactive.conversations.'",
")",
".",
"items",
"(",
")",
":",
"if",
"'local-data'",
"in",
"key",
":",
"cont... | Due to issue #28 (https://github.com/juju-solutions/charms.reactive/issues/28),
conversations needed to be updated to be namespaced per relation ID for SERVICE
and UNIT scope. To ensure backwards compatibility, this updates all convs in
the old format to the new.
TODO: Remove in 2.0.0 | [
"Due",
"to",
"issue",
"#28",
"(",
"https",
":",
"//",
"github",
".",
"com",
"/",
"juju",
"-",
"solutions",
"/",
"charms",
".",
"reactive",
"/",
"issues",
"/",
"28",
")",
"conversations",
"needed",
"to",
"be",
"updated",
"to",
"be",
"namespaced",
"per",... | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L842-L884 |
juju-solutions/charms.reactive | charms/reactive/relations.py | relation_call | def relation_call(method, relation_name=None, flag=None, state=None, *args):
"""Invoke a method on the class implementing a relation via the CLI"""
if relation_name:
relation = relation_from_name(relation_name)
if relation is None:
raise ValueError('Relation not found: %s' % relation... | python | def relation_call(method, relation_name=None, flag=None, state=None, *args):
"""Invoke a method on the class implementing a relation via the CLI"""
if relation_name:
relation = relation_from_name(relation_name)
if relation is None:
raise ValueError('Relation not found: %s' % relation... | [
"def",
"relation_call",
"(",
"method",
",",
"relation_name",
"=",
"None",
",",
"flag",
"=",
"None",
",",
"state",
"=",
"None",
",",
"*",
"args",
")",
":",
"if",
"relation_name",
":",
"relation",
"=",
"relation_from_name",
"(",
"relation_name",
")",
"if",
... | Invoke a method on the class implementing a relation via the CLI | [
"Invoke",
"a",
"method",
"on",
"the",
"class",
"implementing",
"a",
"relation",
"via",
"the",
"CLI"
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L888-L904 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.from_flag | def from_flag(cls, flag):
"""
Find relation implementation in the current charm, based on the
name of an active flag.
You should not use this method directly.
Use :func:`endpoint_from_flag` instead.
"""
value = _get_flag_value(flag)
if value is None:
... | python | def from_flag(cls, flag):
"""
Find relation implementation in the current charm, based on the
name of an active flag.
You should not use this method directly.
Use :func:`endpoint_from_flag` instead.
"""
value = _get_flag_value(flag)
if value is None:
... | [
"def",
"from_flag",
"(",
"cls",
",",
"flag",
")",
":",
"value",
"=",
"_get_flag_value",
"(",
"flag",
")",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"relation_name",
"=",
"value",
"[",
"'relation'",
"]",
"conversations",
"=",
"Conversation",
".",
... | Find relation implementation in the current charm, based on the
name of an active flag.
You should not use this method directly.
Use :func:`endpoint_from_flag` instead. | [
"Find",
"relation",
"implementation",
"in",
"the",
"current",
"charm",
"based",
"on",
"the",
"name",
"of",
"an",
"active",
"flag",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L341-L354 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.from_name | def from_name(cls, relation_name, conversations=None):
"""
Find relation implementation in the current charm, based on the
name of the relation.
:return: A Relation instance, or None
"""
if relation_name is None:
return None
relation_class = cls._cach... | python | def from_name(cls, relation_name, conversations=None):
"""
Find relation implementation in the current charm, based on the
name of the relation.
:return: A Relation instance, or None
"""
if relation_name is None:
return None
relation_class = cls._cach... | [
"def",
"from_name",
"(",
"cls",
",",
"relation_name",
",",
"conversations",
"=",
"None",
")",
":",
"if",
"relation_name",
"is",
"None",
":",
"return",
"None",
"relation_class",
"=",
"cls",
".",
"_cache",
".",
"get",
"(",
"relation_name",
")",
"if",
"relati... | Find relation implementation in the current charm, based on the
name of the relation.
:return: A Relation instance, or None | [
"Find",
"relation",
"implementation",
"in",
"the",
"current",
"charm",
"based",
"on",
"the",
"name",
"of",
"the",
"relation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L357-L375 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase._find_impl | def _find_impl(cls, role, interface):
"""
Find relation implementation based on its role and interface.
"""
module = _relation_module(role, interface)
if not module:
return None
return cls._find_subclass(module) | python | def _find_impl(cls, role, interface):
"""
Find relation implementation based on its role and interface.
"""
module = _relation_module(role, interface)
if not module:
return None
return cls._find_subclass(module) | [
"def",
"_find_impl",
"(",
"cls",
",",
"role",
",",
"interface",
")",
":",
"module",
"=",
"_relation_module",
"(",
"role",
",",
"interface",
")",
"if",
"not",
"module",
":",
"return",
"None",
"return",
"cls",
".",
"_find_subclass",
"(",
"module",
")"
] | Find relation implementation based on its role and interface. | [
"Find",
"relation",
"implementation",
"based",
"on",
"its",
"role",
"and",
"interface",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L378-L385 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase._find_subclass | def _find_subclass(cls, module):
"""
Attempt to find subclass of :class:`RelationBase` in the given module.
Note: This means strictly subclasses and not :class:`RelationBase` itself.
This is to prevent picking up :class:`RelationBase` being imported to be
used as the base class.... | python | def _find_subclass(cls, module):
"""
Attempt to find subclass of :class:`RelationBase` in the given module.
Note: This means strictly subclasses and not :class:`RelationBase` itself.
This is to prevent picking up :class:`RelationBase` being imported to be
used as the base class.... | [
"def",
"_find_subclass",
"(",
"cls",
",",
"module",
")",
":",
"for",
"attr",
"in",
"dir",
"(",
"module",
")",
":",
"candidate",
"=",
"getattr",
"(",
"module",
",",
"attr",
")",
"if",
"(",
"isclass",
"(",
"candidate",
")",
"and",
"issubclass",
"(",
"c... | Attempt to find subclass of :class:`RelationBase` in the given module.
Note: This means strictly subclasses and not :class:`RelationBase` itself.
This is to prevent picking up :class:`RelationBase` being imported to be
used as the base class. | [
"Attempt",
"to",
"find",
"subclass",
"of",
":",
"class",
":",
"RelationBase",
"in",
"the",
"given",
"module",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L388-L401 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.conversation | def conversation(self, scope=None):
"""
Get a single conversation, by scope, that this relation is currently handling.
If the scope is not given, the correct scope is inferred by the current
hook execution context. If there is no current hook execution context, it
is assume tha... | python | def conversation(self, scope=None):
"""
Get a single conversation, by scope, that this relation is currently handling.
If the scope is not given, the correct scope is inferred by the current
hook execution context. If there is no current hook execution context, it
is assume tha... | [
"def",
"conversation",
"(",
"self",
",",
"scope",
"=",
"None",
")",
":",
"if",
"scope",
"is",
"None",
":",
"if",
"self",
".",
"scope",
"is",
"scopes",
".",
"UNIT",
":",
"scope",
"=",
"hookenv",
".",
"remote_unit",
"(",
")",
"elif",
"self",
".",
"sc... | Get a single conversation, by scope, that this relation is currently handling.
If the scope is not given, the correct scope is inferred by the current
hook execution context. If there is no current hook execution context, it
is assume that there is only a single global conversation scope for t... | [
"Get",
"a",
"single",
"conversation",
"by",
"scope",
"that",
"this",
"relation",
"is",
"currently",
"handling",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L413-L436 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.toggle_state | def toggle_state(self, state, active=TOGGLE, scope=None):
"""
Toggle the state for the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).toggle_state(state, active)
See :meth:`conversation` and :meth:`Conversation.t... | python | def toggle_state(self, state, active=TOGGLE, scope=None):
"""
Toggle the state for the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).toggle_state(state, active)
See :meth:`conversation` and :meth:`Conversation.t... | [
"def",
"toggle_state",
"(",
"self",
",",
"state",
",",
"active",
"=",
"TOGGLE",
",",
"scope",
"=",
"None",
")",
":",
"self",
".",
"conversation",
"(",
"scope",
")",
".",
"toggle_state",
"(",
"state",
",",
"active",
")"
] | Toggle the state for the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).toggle_state(state, active)
See :meth:`conversation` and :meth:`Conversation.toggle_state`. | [
"Toggle",
"the",
"state",
"for",
"the",
":",
"class",
":",
"Conversation",
"with",
"the",
"given",
"scope",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L474-L484 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.set_remote | def set_remote(self, key=None, value=None, data=None, scope=None, **kwdata):
"""
Set data for the remote end(s) of the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).set_remote(key, value, data, scope, **kwdata)
... | python | def set_remote(self, key=None, value=None, data=None, scope=None, **kwdata):
"""
Set data for the remote end(s) of the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).set_remote(key, value, data, scope, **kwdata)
... | [
"def",
"set_remote",
"(",
"self",
",",
"key",
"=",
"None",
",",
"value",
"=",
"None",
",",
"data",
"=",
"None",
",",
"scope",
"=",
"None",
",",
"*",
"*",
"kwdata",
")",
":",
"self",
".",
"conversation",
"(",
"scope",
")",
".",
"set_remote",
"(",
... | Set data for the remote end(s) of the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).set_remote(key, value, data, scope, **kwdata)
See :meth:`conversation` and :meth:`Conversation.set_remote`. | [
"Set",
"data",
"for",
"the",
"remote",
"end",
"(",
"s",
")",
"of",
"the",
":",
"class",
":",
"Conversation",
"with",
"the",
"given",
"scope",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L486-L496 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.get_remote | def get_remote(self, key, default=None, scope=None):
"""
Get data from the remote end(s) of the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).get_remote(key, default)
See :meth:`conversation` and :meth:`Conversa... | python | def get_remote(self, key, default=None, scope=None):
"""
Get data from the remote end(s) of the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).get_remote(key, default)
See :meth:`conversation` and :meth:`Conversa... | [
"def",
"get_remote",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
",",
"scope",
"=",
"None",
")",
":",
"return",
"self",
".",
"conversation",
"(",
"scope",
")",
".",
"get_remote",
"(",
"key",
",",
"default",
")"
] | Get data from the remote end(s) of the :class:`Conversation` with the given scope.
In Python, this is equivalent to::
relation.conversation(scope).get_remote(key, default)
See :meth:`conversation` and :meth:`Conversation.get_remote`. | [
"Get",
"data",
"from",
"the",
"remote",
"end",
"(",
"s",
")",
"of",
"the",
":",
"class",
":",
"Conversation",
"with",
"the",
"given",
"scope",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L498-L508 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.set_local | def set_local(self, key=None, value=None, data=None, scope=None, **kwdata):
"""
Locally store some data, namespaced by the current or given :class:`Conversation` scope.
In Python, this is equivalent to::
relation.conversation(scope).set_local(data, scope, **kwdata)
See :me... | python | def set_local(self, key=None, value=None, data=None, scope=None, **kwdata):
"""
Locally store some data, namespaced by the current or given :class:`Conversation` scope.
In Python, this is equivalent to::
relation.conversation(scope).set_local(data, scope, **kwdata)
See :me... | [
"def",
"set_local",
"(",
"self",
",",
"key",
"=",
"None",
",",
"value",
"=",
"None",
",",
"data",
"=",
"None",
",",
"scope",
"=",
"None",
",",
"*",
"*",
"kwdata",
")",
":",
"self",
".",
"conversation",
"(",
"scope",
")",
".",
"set_local",
"(",
"k... | Locally store some data, namespaced by the current or given :class:`Conversation` scope.
In Python, this is equivalent to::
relation.conversation(scope).set_local(data, scope, **kwdata)
See :meth:`conversation` and :meth:`Conversation.set_local`. | [
"Locally",
"store",
"some",
"data",
"namespaced",
"by",
"the",
"current",
"or",
"given",
":",
"class",
":",
"Conversation",
"scope",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L510-L520 |
juju-solutions/charms.reactive | charms/reactive/relations.py | RelationBase.get_local | def get_local(self, key, default=None, scope=None):
"""
Retrieve some data previously set via :meth:`set_local`.
In Python, this is equivalent to::
relation.conversation(scope).get_local(key, default)
See :meth:`conversation` and :meth:`Conversation.get_local`.
"""... | python | def get_local(self, key, default=None, scope=None):
"""
Retrieve some data previously set via :meth:`set_local`.
In Python, this is equivalent to::
relation.conversation(scope).get_local(key, default)
See :meth:`conversation` and :meth:`Conversation.get_local`.
"""... | [
"def",
"get_local",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
",",
"scope",
"=",
"None",
")",
":",
"return",
"self",
".",
"conversation",
"(",
"scope",
")",
".",
"get_local",
"(",
"key",
",",
"default",
")"
] | Retrieve some data previously set via :meth:`set_local`.
In Python, this is equivalent to::
relation.conversation(scope).get_local(key, default)
See :meth:`conversation` and :meth:`Conversation.get_local`. | [
"Retrieve",
"some",
"data",
"previously",
"set",
"via",
":",
"meth",
":",
"set_local",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L522-L532 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.relation_ids | def relation_ids(self):
"""
The set of IDs of the specific relation instances that this conversation
is communicating with.
"""
if self.scope == scopes.GLOBAL:
# the namespace is the relation name and this conv speaks for all
# connected instances of that ... | python | def relation_ids(self):
"""
The set of IDs of the specific relation instances that this conversation
is communicating with.
"""
if self.scope == scopes.GLOBAL:
# the namespace is the relation name and this conv speaks for all
# connected instances of that ... | [
"def",
"relation_ids",
"(",
"self",
")",
":",
"if",
"self",
".",
"scope",
"==",
"scopes",
".",
"GLOBAL",
":",
"# the namespace is the relation name and this conv speaks for all",
"# connected instances of that relation",
"return",
"hookenv",
".",
"relation_ids",
"(",
"sel... | The set of IDs of the specific relation instances that this conversation
is communicating with. | [
"The",
"set",
"of",
"IDs",
"of",
"the",
"specific",
"relation",
"instances",
"that",
"this",
"conversation",
"is",
"communicating",
"with",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L577-L588 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.join | def join(cls, scope):
"""
Get or create a conversation for the given scope and active hook context.
The current remote unit for the active hook context will be added to
the conversation.
Note: This uses :mod:`charmhelpers.core.unitdata` and requires that
:meth:`~charmhe... | python | def join(cls, scope):
"""
Get or create a conversation for the given scope and active hook context.
The current remote unit for the active hook context will be added to
the conversation.
Note: This uses :mod:`charmhelpers.core.unitdata` and requires that
:meth:`~charmhe... | [
"def",
"join",
"(",
"cls",
",",
"scope",
")",
":",
"relation_name",
"=",
"hookenv",
".",
"relation_type",
"(",
")",
"relation_id",
"=",
"hookenv",
".",
"relation_id",
"(",
")",
"unit",
"=",
"hookenv",
".",
"remote_unit",
"(",
")",
"service",
"=",
"hooken... | Get or create a conversation for the given scope and active hook context.
The current remote unit for the active hook context will be added to
the conversation.
Note: This uses :mod:`charmhelpers.core.unitdata` and requires that
:meth:`~charmhelpers.core.unitdata.Storage.flush` be call... | [
"Get",
"or",
"create",
"a",
"conversation",
"for",
"the",
"given",
"scope",
"and",
"active",
"hook",
"context",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L591-L618 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.depart | def depart(self):
"""
Remove the current remote unit, for the active hook context, from
this conversation. This should be called from a `-departed` hook.
"""
unit = hookenv.remote_unit()
self.units.remove(unit)
if self.units:
unitdata.kv().set(self.ke... | python | def depart(self):
"""
Remove the current remote unit, for the active hook context, from
this conversation. This should be called from a `-departed` hook.
"""
unit = hookenv.remote_unit()
self.units.remove(unit)
if self.units:
unitdata.kv().set(self.ke... | [
"def",
"depart",
"(",
"self",
")",
":",
"unit",
"=",
"hookenv",
".",
"remote_unit",
"(",
")",
"self",
".",
"units",
".",
"remove",
"(",
"unit",
")",
"if",
"self",
".",
"units",
":",
"unitdata",
".",
"kv",
"(",
")",
".",
"set",
"(",
"self",
".",
... | Remove the current remote unit, for the active hook context, from
this conversation. This should be called from a `-departed` hook. | [
"Remove",
"the",
"current",
"remote",
"unit",
"for",
"the",
"active",
"hook",
"context",
"from",
"this",
"conversation",
".",
"This",
"should",
"be",
"called",
"from",
"a",
"-",
"departed",
"hook",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L620-L630 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.serialize | def serialize(cls, conversation):
"""
Serialize a conversation instance for storage.
"""
return {
'namespace': conversation.namespace,
'units': sorted(conversation.units),
'scope': conversation.scope,
} | python | def serialize(cls, conversation):
"""
Serialize a conversation instance for storage.
"""
return {
'namespace': conversation.namespace,
'units': sorted(conversation.units),
'scope': conversation.scope,
} | [
"def",
"serialize",
"(",
"cls",
",",
"conversation",
")",
":",
"return",
"{",
"'namespace'",
":",
"conversation",
".",
"namespace",
",",
"'units'",
":",
"sorted",
"(",
"conversation",
".",
"units",
")",
",",
"'scope'",
":",
"conversation",
".",
"scope",
",... | Serialize a conversation instance for storage. | [
"Serialize",
"a",
"conversation",
"instance",
"for",
"storage",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L640-L648 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.load | def load(cls, keys):
"""
Load a set of conversations by their keys.
"""
conversations = []
for key in keys:
conversation = unitdata.kv().get(key)
if conversation:
conversations.append(cls.deserialize(conversation))
return conversati... | python | def load(cls, keys):
"""
Load a set of conversations by their keys.
"""
conversations = []
for key in keys:
conversation = unitdata.kv().get(key)
if conversation:
conversations.append(cls.deserialize(conversation))
return conversati... | [
"def",
"load",
"(",
"cls",
",",
"keys",
")",
":",
"conversations",
"=",
"[",
"]",
"for",
"key",
"in",
"keys",
":",
"conversation",
"=",
"unitdata",
".",
"kv",
"(",
")",
".",
"get",
"(",
"key",
")",
"if",
"conversation",
":",
"conversations",
".",
"... | Load a set of conversations by their keys. | [
"Load",
"a",
"set",
"of",
"conversations",
"by",
"their",
"keys",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L651-L660 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.set_state | def set_state(self, state):
"""
Activate and put this conversation into the given state.
The relation name will be interpolated in the state name, and it is
recommended that it be included to avoid conflicts with states from
other relations. For example::
conversat... | python | def set_state(self, state):
"""
Activate and put this conversation into the given state.
The relation name will be interpolated in the state name, and it is
recommended that it be included to avoid conflicts with states from
other relations. For example::
conversat... | [
"def",
"set_state",
"(",
"self",
",",
"state",
")",
":",
"state",
"=",
"state",
".",
"format",
"(",
"relation_name",
"=",
"self",
".",
"relation_name",
")",
"value",
"=",
"_get_flag_value",
"(",
"state",
",",
"{",
"'relation'",
":",
"self",
".",
"relatio... | Activate and put this conversation into the given state.
The relation name will be interpolated in the state name, and it is
recommended that it be included to avoid conflicts with states from
other relations. For example::
conversation.set_state('{relation_name}.state')
... | [
"Activate",
"and",
"put",
"this",
"conversation",
"into",
"the",
"given",
"state",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L662-L686 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.remove_state | def remove_state(self, state):
"""
Remove this conversation from the given state, and potentially
deactivate the state if no more conversations are in it.
The relation name will be interpolated in the state name, and it is
recommended that it be included to avoid conflicts with ... | python | def remove_state(self, state):
"""
Remove this conversation from the given state, and potentially
deactivate the state if no more conversations are in it.
The relation name will be interpolated in the state name, and it is
recommended that it be included to avoid conflicts with ... | [
"def",
"remove_state",
"(",
"self",
",",
"state",
")",
":",
"state",
"=",
"state",
".",
"format",
"(",
"relation_name",
"=",
"self",
".",
"relation_name",
")",
"value",
"=",
"_get_flag_value",
"(",
"state",
")",
"if",
"not",
"value",
":",
"return",
"if",... | Remove this conversation from the given state, and potentially
deactivate the state if no more conversations are in it.
The relation name will be interpolated in the state name, and it is
recommended that it be included to avoid conflicts with states from
other relations. For example::... | [
"Remove",
"this",
"conversation",
"from",
"the",
"given",
"state",
"and",
"potentially",
"deactivate",
"the",
"state",
"if",
"no",
"more",
"conversations",
"are",
"in",
"it",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L688-L712 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.is_state | def is_state(self, state):
"""
Test if this conversation is in the given state.
"""
state = state.format(relation_name=self.relation_name)
value = _get_flag_value(state)
if not value:
return False
return self.key in value['conversations'] | python | def is_state(self, state):
"""
Test if this conversation is in the given state.
"""
state = state.format(relation_name=self.relation_name)
value = _get_flag_value(state)
if not value:
return False
return self.key in value['conversations'] | [
"def",
"is_state",
"(",
"self",
",",
"state",
")",
":",
"state",
"=",
"state",
".",
"format",
"(",
"relation_name",
"=",
"self",
".",
"relation_name",
")",
"value",
"=",
"_get_flag_value",
"(",
"state",
")",
"if",
"not",
"value",
":",
"return",
"False",
... | Test if this conversation is in the given state. | [
"Test",
"if",
"this",
"conversation",
"is",
"in",
"the",
"given",
"state",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L714-L722 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.toggle_state | def toggle_state(self, state, active=TOGGLE):
"""
Toggle the given state for this conversation.
The state will be set ``active`` is ``True``, otherwise the state will be removed.
If ``active`` is not given, it will default to the inverse of the current state
(i.e., ``False`` if... | python | def toggle_state(self, state, active=TOGGLE):
"""
Toggle the given state for this conversation.
The state will be set ``active`` is ``True``, otherwise the state will be removed.
If ``active`` is not given, it will default to the inverse of the current state
(i.e., ``False`` if... | [
"def",
"toggle_state",
"(",
"self",
",",
"state",
",",
"active",
"=",
"TOGGLE",
")",
":",
"if",
"active",
"is",
"TOGGLE",
":",
"active",
"=",
"not",
"self",
".",
"is_state",
"(",
"state",
")",
"if",
"active",
":",
"self",
".",
"set_state",
"(",
"stat... | Toggle the given state for this conversation.
The state will be set ``active`` is ``True``, otherwise the state will be removed.
If ``active`` is not given, it will default to the inverse of the current state
(i.e., ``False`` if the state is currently set, ``True`` if it is not; essentially
... | [
"Toggle",
"the",
"given",
"state",
"for",
"this",
"conversation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L724-L745 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.set_remote | def set_remote(self, key=None, value=None, data=None, **kwdata):
"""
Set data for the remote end(s) of this conversation.
Data can be passed in either as a single dict, or as key-word args.
Note that, in Juju, setting relation data is inherently service scoped.
That is, if the ... | python | def set_remote(self, key=None, value=None, data=None, **kwdata):
"""
Set data for the remote end(s) of this conversation.
Data can be passed in either as a single dict, or as key-word args.
Note that, in Juju, setting relation data is inherently service scoped.
That is, if the ... | [
"def",
"set_remote",
"(",
"self",
",",
"key",
"=",
"None",
",",
"value",
"=",
"None",
",",
"data",
"=",
"None",
",",
"*",
"*",
"kwdata",
")",
":",
"if",
"data",
"is",
"None",
":",
"data",
"=",
"{",
"}",
"if",
"key",
"is",
"not",
"None",
":",
... | Set data for the remote end(s) of this conversation.
Data can be passed in either as a single dict, or as key-word args.
Note that, in Juju, setting relation data is inherently service scoped.
That is, if the conversation only includes a single unit, the data will
still be set for that... | [
"Set",
"data",
"for",
"the",
"remote",
"end",
"(",
"s",
")",
"of",
"this",
"conversation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L747-L773 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.get_remote | def get_remote(self, key, default=None):
"""
Get a value from the remote end(s) of this conversation.
Note that if a conversation's scope encompasses multiple units, then
those units are expected to agree on their data, whether that is through
relying on a single leader to set t... | python | def get_remote(self, key, default=None):
"""
Get a value from the remote end(s) of this conversation.
Note that if a conversation's scope encompasses multiple units, then
those units are expected to agree on their data, whether that is through
relying on a single leader to set t... | [
"def",
"get_remote",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"cur_rid",
"=",
"hookenv",
".",
"relation_id",
"(",
")",
"departing",
"=",
"hookenv",
".",
"hook_name",
"(",
")",
".",
"endswith",
"(",
"'-relation-departed'",
")",
"for... | Get a value from the remote end(s) of this conversation.
Note that if a conversation's scope encompasses multiple units, then
those units are expected to agree on their data, whether that is through
relying on a single leader to set the data or by all units eventually
converging to iden... | [
"Get",
"a",
"value",
"from",
"the",
"remote",
"end",
"(",
"s",
")",
"of",
"this",
"conversation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L775-L800 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.set_local | def set_local(self, key=None, value=None, data=None, **kwdata):
"""
Locally store some data associated with this conversation.
Data can be passed in either as a single dict, or as key-word args.
For example, if you need to store the previous value of a remote field
to determine... | python | def set_local(self, key=None, value=None, data=None, **kwdata):
"""
Locally store some data associated with this conversation.
Data can be passed in either as a single dict, or as key-word args.
For example, if you need to store the previous value of a remote field
to determine... | [
"def",
"set_local",
"(",
"self",
",",
"key",
"=",
"None",
",",
"value",
"=",
"None",
",",
"data",
"=",
"None",
",",
"*",
"*",
"kwdata",
")",
":",
"if",
"data",
"is",
"None",
":",
"data",
"=",
"{",
"}",
"if",
"key",
"is",
"not",
"None",
":",
"... | Locally store some data associated with this conversation.
Data can be passed in either as a single dict, or as key-word args.
For example, if you need to store the previous value of a remote field
to determine if it has changed, you can use the following::
prev = conversation.get... | [
"Locally",
"store",
"some",
"data",
"associated",
"with",
"this",
"conversation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L802-L832 |
juju-solutions/charms.reactive | charms/reactive/relations.py | Conversation.get_local | def get_local(self, key, default=None):
"""
Retrieve some data previously set via :meth:`set_local` for this conversation.
"""
key = '%s.%s.%s' % (self.key, 'local-data', key)
return unitdata.kv().get(key, default) | python | def get_local(self, key, default=None):
"""
Retrieve some data previously set via :meth:`set_local` for this conversation.
"""
key = '%s.%s.%s' % (self.key, 'local-data', key)
return unitdata.kv().get(key, default) | [
"def",
"get_local",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"key",
"=",
"'%s.%s.%s'",
"%",
"(",
"self",
".",
"key",
",",
"'local-data'",
",",
"key",
")",
"return",
"unitdata",
".",
"kv",
"(",
")",
".",
"get",
"(",
"key",
"... | Retrieve some data previously set via :meth:`set_local` for this conversation. | [
"Retrieve",
"some",
"data",
"previously",
"set",
"via",
":",
"meth",
":",
"set_local",
"for",
"this",
"conversation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/relations.py#L834-L839 |
juju-solutions/charms.reactive | charms/reactive/flags.py | set_flag | def set_flag(flag, value=None):
"""set_flag(flag)
Set the given flag as active.
:param str flag: Name of flag to set.
.. note:: **Changes to flags are reset when a handler crashes.** Changes to
flags happen immediately, but they are only persisted at the end of a
complete and successful ... | python | def set_flag(flag, value=None):
"""set_flag(flag)
Set the given flag as active.
:param str flag: Name of flag to set.
.. note:: **Changes to flags are reset when a handler crashes.** Changes to
flags happen immediately, but they are only persisted at the end of a
complete and successful ... | [
"def",
"set_flag",
"(",
"flag",
",",
"value",
"=",
"None",
")",
":",
"old_flags",
"=",
"get_flags",
"(",
")",
"unitdata",
".",
"kv",
"(",
")",
".",
"update",
"(",
"{",
"flag",
":",
"value",
"}",
",",
"prefix",
"=",
"'reactive.states.'",
")",
"if",
... | set_flag(flag)
Set the given flag as active.
:param str flag: Name of flag to set.
.. note:: **Changes to flags are reset when a handler crashes.** Changes to
flags happen immediately, but they are only persisted at the end of a
complete and successful run of the reactive framework. All unpe... | [
"set_flag",
"(",
"flag",
")",
"Set",
"the",
"given",
"flag",
"as",
"active",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/flags.py#L65-L85 |
juju-solutions/charms.reactive | charms/reactive/flags.py | clear_flag | def clear_flag(flag):
"""
Clear / deactivate a flag.
:param str flag: Name of flag to set.
.. note:: **Changes to flags are reset when a handler crashes.** Changes to
flags happen immediately, but they are only persisted at the end of a
complete and successful run of the reactive framewo... | python | def clear_flag(flag):
"""
Clear / deactivate a flag.
:param str flag: Name of flag to set.
.. note:: **Changes to flags are reset when a handler crashes.** Changes to
flags happen immediately, but they are only persisted at the end of a
complete and successful run of the reactive framewo... | [
"def",
"clear_flag",
"(",
"flag",
")",
":",
"old_flags",
"=",
"get_flags",
"(",
")",
"unitdata",
".",
"kv",
"(",
")",
".",
"unset",
"(",
"'reactive.states.%s'",
"%",
"flag",
")",
"unitdata",
".",
"kv",
"(",
")",
".",
"set",
"(",
"'reactive.dispatch.remov... | Clear / deactivate a flag.
:param str flag: Name of flag to set.
.. note:: **Changes to flags are reset when a handler crashes.** Changes to
flags happen immediately, but they are only persisted at the end of a
complete and successful run of the reactive framework. All unpersisted
changes... | [
"Clear",
"/",
"deactivate",
"a",
"flag",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/flags.py#L90-L111 |
juju-solutions/charms.reactive | charms/reactive/flags.py | register_trigger | def register_trigger(when=None, when_not=None, set_flag=None, clear_flag=None):
"""
Register a trigger to set or clear a flag when a given flag is set.
Note: Flag triggers are handled at the same time that the given flag is set.
:param str when: Flag to trigger on when it is set.
:param str when_n... | python | def register_trigger(when=None, when_not=None, set_flag=None, clear_flag=None):
"""
Register a trigger to set or clear a flag when a given flag is set.
Note: Flag triggers are handled at the same time that the given flag is set.
:param str when: Flag to trigger on when it is set.
:param str when_n... | [
"def",
"register_trigger",
"(",
"when",
"=",
"None",
",",
"when_not",
"=",
"None",
",",
"set_flag",
"=",
"None",
",",
"clear_flag",
"=",
"None",
")",
":",
"if",
"not",
"any",
"(",
"(",
"when",
",",
"when_not",
")",
")",
":",
"raise",
"ValueError",
"(... | Register a trigger to set or clear a flag when a given flag is set.
Note: Flag triggers are handled at the same time that the given flag is set.
:param str when: Flag to trigger on when it is set.
:param str when_not: Flag to trigger on when it is cleared.
:param str set_flag: If given, this flag will... | [
"Register",
"a",
"trigger",
"to",
"set",
"or",
"clear",
"a",
"flag",
"when",
"a",
"given",
"flag",
"is",
"set",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/flags.py#L144-L169 |
juju-solutions/charms.reactive | charms/reactive/flags.py | get_flags | def get_flags():
"""
Return a list of all flags which are set.
"""
flags = unitdata.kv().getrange('reactive.states.', strip=True) or {}
return sorted(flags.keys()) | python | def get_flags():
"""
Return a list of all flags which are set.
"""
flags = unitdata.kv().getrange('reactive.states.', strip=True) or {}
return sorted(flags.keys()) | [
"def",
"get_flags",
"(",
")",
":",
"flags",
"=",
"unitdata",
".",
"kv",
"(",
")",
".",
"getrange",
"(",
"'reactive.states.'",
",",
"strip",
"=",
"True",
")",
"or",
"{",
"}",
"return",
"sorted",
"(",
"flags",
".",
"keys",
"(",
")",
")"
] | Return a list of all flags which are set. | [
"Return",
"a",
"list",
"of",
"all",
"flags",
"which",
"are",
"set",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/flags.py#L215-L220 |
juju-solutions/charms.reactive | charms/reactive/bus.py | dispatch | def dispatch(restricted=False):
"""
Dispatch registered handlers.
When dispatching in restricted mode, only matching hook handlers are executed.
Handlers are dispatched according to the following rules:
* Handlers are repeatedly tested and invoked in iterations, until the system
settles int... | python | def dispatch(restricted=False):
"""
Dispatch registered handlers.
When dispatching in restricted mode, only matching hook handlers are executed.
Handlers are dispatched according to the following rules:
* Handlers are repeatedly tested and invoked in iterations, until the system
settles int... | [
"def",
"dispatch",
"(",
"restricted",
"=",
"False",
")",
":",
"FlagWatch",
".",
"reset",
"(",
")",
"def",
"_test",
"(",
"to_test",
")",
":",
"return",
"list",
"(",
"filter",
"(",
"lambda",
"h",
":",
"h",
".",
"test",
"(",
")",
",",
"to_test",
")",
... | Dispatch registered handlers.
When dispatching in restricted mode, only matching hook handlers are executed.
Handlers are dispatched according to the following rules:
* Handlers are repeatedly tested and invoked in iterations, until the system
settles into quiescence (that is, until no new handlers... | [
"Dispatch",
"registered",
"handlers",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L314-L392 |
juju-solutions/charms.reactive | charms/reactive/bus.py | discover | def discover():
"""
Discover handlers based on convention.
Handlers will be loaded from the following directories and their subdirectories:
* ``$CHARM_DIR/reactive/``
* ``$CHARM_DIR/hooks/reactive/``
* ``$CHARM_DIR/hooks/relations/``
They can be Python files, in which case they will... | python | def discover():
"""
Discover handlers based on convention.
Handlers will be loaded from the following directories and their subdirectories:
* ``$CHARM_DIR/reactive/``
* ``$CHARM_DIR/hooks/reactive/``
* ``$CHARM_DIR/hooks/relations/``
They can be Python files, in which case they will... | [
"def",
"discover",
"(",
")",
":",
"# Add $CHARM_DIR and $CHARM_DIR/hooks to sys.path so",
"# 'import reactive.leadership', 'import relations.pgsql' works",
"# as expected, as well as relative imports like 'import ..leadership'",
"# or 'from . import leadership'. Without this, it becomes difficult",
... | Discover handlers based on convention.
Handlers will be loaded from the following directories and their subdirectories:
* ``$CHARM_DIR/reactive/``
* ``$CHARM_DIR/hooks/reactive/``
* ``$CHARM_DIR/hooks/relations/``
They can be Python files, in which case they will be imported and decorated
... | [
"Discover",
"handlers",
"based",
"on",
"convention",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L395-L424 |
juju-solutions/charms.reactive | charms/reactive/bus.py | Handler.get | def get(cls, action, suffix=None):
"""
Get or register a handler for the given action.
:param func action: Callback that is called when invoking the Handler
:param func suffix: Optional suffix for the handler's ID
"""
action_id = _action_id(action, suffix)
if act... | python | def get(cls, action, suffix=None):
"""
Get or register a handler for the given action.
:param func action: Callback that is called when invoking the Handler
:param func suffix: Optional suffix for the handler's ID
"""
action_id = _action_id(action, suffix)
if act... | [
"def",
"get",
"(",
"cls",
",",
"action",
",",
"suffix",
"=",
"None",
")",
":",
"action_id",
"=",
"_action_id",
"(",
"action",
",",
"suffix",
")",
"if",
"action_id",
"not",
"in",
"cls",
".",
"_HANDLERS",
":",
"if",
"LOG_OPTS",
"[",
"'register'",
"]",
... | Get or register a handler for the given action.
:param func action: Callback that is called when invoking the Handler
:param func suffix: Optional suffix for the handler's ID | [
"Get",
"or",
"register",
"a",
"handler",
"for",
"the",
"given",
"action",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L79-L92 |
juju-solutions/charms.reactive | charms/reactive/bus.py | Handler.add_predicate | def add_predicate(self, predicate):
"""
Add a new predicate callback to this handler.
"""
_predicate = predicate
if isinstance(predicate, partial):
_predicate = 'partial(%s, %s, %s)' % (predicate.func, predicate.args, predicate.keywords)
if LOG_OPTS['register'... | python | def add_predicate(self, predicate):
"""
Add a new predicate callback to this handler.
"""
_predicate = predicate
if isinstance(predicate, partial):
_predicate = 'partial(%s, %s, %s)' % (predicate.func, predicate.args, predicate.keywords)
if LOG_OPTS['register'... | [
"def",
"add_predicate",
"(",
"self",
",",
"predicate",
")",
":",
"_predicate",
"=",
"predicate",
"if",
"isinstance",
"(",
"predicate",
",",
"partial",
")",
":",
"_predicate",
"=",
"'partial(%s, %s, %s)'",
"%",
"(",
"predicate",
".",
"func",
",",
"predicate",
... | Add a new predicate callback to this handler. | [
"Add",
"a",
"new",
"predicate",
"callback",
"to",
"this",
"handler",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L142-L151 |
juju-solutions/charms.reactive | charms/reactive/bus.py | Handler._get_args | def _get_args(self):
"""
Lazily evaluate the args.
"""
if not hasattr(self, '_args_evaled'):
# cache the args in case handler is re-invoked due to flags change
self._args_evaled = list(chain.from_iterable(self._args))
return self._args_evaled | python | def _get_args(self):
"""
Lazily evaluate the args.
"""
if not hasattr(self, '_args_evaled'):
# cache the args in case handler is re-invoked due to flags change
self._args_evaled = list(chain.from_iterable(self._args))
return self._args_evaled | [
"def",
"_get_args",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_args_evaled'",
")",
":",
"# cache the args in case handler is re-invoked due to flags change",
"self",
".",
"_args_evaled",
"=",
"list",
"(",
"chain",
".",
"from_iterable",
"(",
... | Lazily evaluate the args. | [
"Lazily",
"evaluate",
"the",
"args",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L167-L174 |
juju-solutions/charms.reactive | charms/reactive/bus.py | Handler.invoke | def invoke(self):
"""
Invoke this handler.
"""
args = self._get_args()
self._action(*args)
for callback in self._post_callbacks:
callback() | python | def invoke(self):
"""
Invoke this handler.
"""
args = self._get_args()
self._action(*args)
for callback in self._post_callbacks:
callback() | [
"def",
"invoke",
"(",
"self",
")",
":",
"args",
"=",
"self",
".",
"_get_args",
"(",
")",
"self",
".",
"_action",
"(",
"*",
"args",
")",
"for",
"callback",
"in",
"self",
".",
"_post_callbacks",
":",
"callback",
"(",
")"
] | Invoke this handler. | [
"Invoke",
"this",
"handler",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L176-L183 |
juju-solutions/charms.reactive | charms/reactive/bus.py | Handler.register_flags | def register_flags(self, flags):
"""
Register flags as being relevant to this handler.
Relevant flags will be used to determine if the handler should
be re-invoked due to changes in the set of active flags. If this
handler has already been invoked during this :func:`dispatch` r... | python | def register_flags(self, flags):
"""
Register flags as being relevant to this handler.
Relevant flags will be used to determine if the handler should
be re-invoked due to changes in the set of active flags. If this
handler has already been invoked during this :func:`dispatch` r... | [
"def",
"register_flags",
"(",
"self",
",",
"flags",
")",
":",
"self",
".",
"_CONSUMED_FLAGS",
".",
"update",
"(",
"flags",
")",
"self",
".",
"_flags",
".",
"update",
"(",
"flags",
")"
] | Register flags as being relevant to this handler.
Relevant flags will be used to determine if the handler should
be re-invoked due to changes in the set of active flags. If this
handler has already been invoked during this :func:`dispatch` run
and none of its relevant flags have been s... | [
"Register",
"flags",
"as",
"being",
"relevant",
"to",
"this",
"handler",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L185-L199 |
juju-solutions/charms.reactive | charms/reactive/bus.py | ExternalHandler.invoke | def invoke(self):
"""
Call the external handler to be invoked.
"""
# flush to ensure external process can see flags as they currently
# are, and write flags (flush releases lock)
unitdata.kv().flush()
subprocess.check_call([self._filepath, '--invoke', self._test_o... | python | def invoke(self):
"""
Call the external handler to be invoked.
"""
# flush to ensure external process can see flags as they currently
# are, and write flags (flush releases lock)
unitdata.kv().flush()
subprocess.check_call([self._filepath, '--invoke', self._test_o... | [
"def",
"invoke",
"(",
"self",
")",
":",
"# flush to ensure external process can see flags as they currently",
"# are, and write flags (flush releases lock)",
"unitdata",
".",
"kv",
"(",
")",
".",
"flush",
"(",
")",
"subprocess",
".",
"check_call",
"(",
"[",
"self",
".",... | Call the external handler to be invoked. | [
"Call",
"the",
"external",
"handler",
"to",
"be",
"invoked",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/bus.py#L254-L261 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | hook | def hook(*hook_patterns):
"""
Register the decorated function to run when the current hook matches any of
the ``hook_patterns``.
This decorator is generally deprecated and should only be used when
absolutely necessary.
The hook patterns can use the ``{interface:...}`` and ``{A,B,...}`` syntax
... | python | def hook(*hook_patterns):
"""
Register the decorated function to run when the current hook matches any of
the ``hook_patterns``.
This decorator is generally deprecated and should only be used when
absolutely necessary.
The hook patterns can use the ``{interface:...}`` and ``{A,B,...}`` syntax
... | [
"def",
"hook",
"(",
"*",
"hook_patterns",
")",
":",
"def",
"_register",
"(",
"action",
")",
":",
"def",
"arg_gen",
"(",
")",
":",
"# use a generator to defer calling of hookenv.relation_type, for tests",
"rel",
"=",
"endpoint_from_name",
"(",
"hookenv",
".",
"relati... | Register the decorated function to run when the current hook matches any of
the ``hook_patterns``.
This decorator is generally deprecated and should only be used when
absolutely necessary.
The hook patterns can use the ``{interface:...}`` and ``{A,B,...}`` syntax
supported by :func:`~charms.reacti... | [
"Register",
"the",
"decorated",
"function",
"to",
"run",
"when",
"the",
"current",
"hook",
"matches",
"any",
"of",
"the",
"hook_patterns",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L56-L81 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | when_file_changed | def when_file_changed(*filenames, **kwargs):
"""
Register the decorated function to run when one or more files have changed.
:param list filenames: The names of one or more files to check for changes
(a callable returning the name is also accepted).
:param str hash_type: The type of hash to use... | python | def when_file_changed(*filenames, **kwargs):
"""
Register the decorated function to run when one or more files have changed.
:param list filenames: The names of one or more files to check for changes
(a callable returning the name is also accepted).
:param str hash_type: The type of hash to use... | [
"def",
"when_file_changed",
"(",
"*",
"filenames",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"_register",
"(",
"action",
")",
":",
"handler",
"=",
"Handler",
".",
"get",
"(",
"action",
")",
"handler",
".",
"add_predicate",
"(",
"partial",
"(",
"any_file_... | Register the decorated function to run when one or more files have changed.
:param list filenames: The names of one or more files to check for changes
(a callable returning the name is also accepted).
:param str hash_type: The type of hash to use for determining if a file has
changed. Defaults... | [
"Register",
"the",
"decorated",
"function",
"to",
"run",
"when",
"one",
"or",
"more",
"files",
"have",
"changed",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L179-L192 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | not_unless | def not_unless(*desired_flags):
"""
Assert that the decorated function can only be called if the desired_flags
are active.
Note that, unlike :func:`when`, this does **not** trigger the decorated
function if the flags match. It **only** raises an exception if the
function is called when the fla... | python | def not_unless(*desired_flags):
"""
Assert that the decorated function can only be called if the desired_flags
are active.
Note that, unlike :func:`when`, this does **not** trigger the decorated
function if the flags match. It **only** raises an exception if the
function is called when the fla... | [
"def",
"not_unless",
"(",
"*",
"desired_flags",
")",
":",
"def",
"_decorator",
"(",
"func",
")",
":",
"action_id",
"=",
"_action_id",
"(",
"func",
")",
"short_action_id",
"=",
"_short_action_id",
"(",
"func",
")",
"@",
"wraps",
"(",
"func",
")",
"def",
"... | Assert that the decorated function can only be called if the desired_flags
are active.
Note that, unlike :func:`when`, this does **not** trigger the decorated
function if the flags match. It **only** raises an exception if the
function is called when the flags do not match.
This is primarily for ... | [
"Assert",
"that",
"the",
"decorated",
"function",
"can",
"only",
"be",
"called",
"if",
"the",
"desired_flags",
"are",
"active",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L195-L223 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | only_once | def only_once(action=None):
"""
.. deprecated:: 0.5.0
Use :func:`when_not` in combination with :func:`set_state` instead. This
handler is deprecated because it might actually be
`called multiple times <https://github.com/juju-solutions/charms.reactive/issues/22>`_.
Register the decorat... | python | def only_once(action=None):
"""
.. deprecated:: 0.5.0
Use :func:`when_not` in combination with :func:`set_state` instead. This
handler is deprecated because it might actually be
`called multiple times <https://github.com/juju-solutions/charms.reactive/issues/22>`_.
Register the decorat... | [
"def",
"only_once",
"(",
"action",
"=",
"None",
")",
":",
"if",
"action",
"is",
"None",
":",
"# allow to be used as @only_once or @only_once()",
"return",
"only_once",
"action_id",
"=",
"_action_id",
"(",
"action",
")",
"handler",
"=",
"Handler",
".",
"get",
"("... | .. deprecated:: 0.5.0
Use :func:`when_not` in combination with :func:`set_state` instead. This
handler is deprecated because it might actually be
`called multiple times <https://github.com/juju-solutions/charms.reactive/issues/22>`_.
Register the decorated function to be run once, and only onc... | [
"..",
"deprecated",
"::",
"0",
".",
"5",
".",
"0",
"Use",
":",
"func",
":",
"when_not",
"in",
"combination",
"with",
":",
"func",
":",
"set_state",
"instead",
".",
"This",
"handler",
"is",
"deprecated",
"because",
"it",
"might",
"actually",
"be",
"called... | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L226-L245 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | collect_metrics | def collect_metrics():
"""
Register the decorated function to run for the collect_metrics hook.
"""
def _register(action):
handler = Handler.get(action)
handler.add_predicate(partial(_restricted_hook, 'collect-metrics'))
return action
return _register | python | def collect_metrics():
"""
Register the decorated function to run for the collect_metrics hook.
"""
def _register(action):
handler = Handler.get(action)
handler.add_predicate(partial(_restricted_hook, 'collect-metrics'))
return action
return _register | [
"def",
"collect_metrics",
"(",
")",
":",
"def",
"_register",
"(",
"action",
")",
":",
"handler",
"=",
"Handler",
".",
"get",
"(",
"action",
")",
"handler",
".",
"add_predicate",
"(",
"partial",
"(",
"_restricted_hook",
",",
"'collect-metrics'",
")",
")",
"... | Register the decorated function to run for the collect_metrics hook. | [
"Register",
"the",
"decorated",
"function",
"to",
"run",
"for",
"the",
"collect_metrics",
"hook",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L248-L256 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | _expand_endpoint_name | def _expand_endpoint_name(endpoint_name, flags):
"""
Populate any ``{endpoint_name}`` tags in the flag names for the given
handler, based on the handlers module / file name.
"""
return tuple(flag.format(endpoint_name=endpoint_name) for flag in flags) | python | def _expand_endpoint_name(endpoint_name, flags):
"""
Populate any ``{endpoint_name}`` tags in the flag names for the given
handler, based on the handlers module / file name.
"""
return tuple(flag.format(endpoint_name=endpoint_name) for flag in flags) | [
"def",
"_expand_endpoint_name",
"(",
"endpoint_name",
",",
"flags",
")",
":",
"return",
"tuple",
"(",
"flag",
".",
"format",
"(",
"endpoint_name",
"=",
"endpoint_name",
")",
"for",
"flag",
"in",
"flags",
")"
] | Populate any ``{endpoint_name}`` tags in the flag names for the given
handler, based on the handlers module / file name. | [
"Populate",
"any",
"{",
"endpoint_name",
"}",
"tags",
"in",
"the",
"flag",
"names",
"for",
"the",
"given",
"handler",
"based",
"on",
"the",
"handlers",
"module",
"/",
"file",
"name",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L289-L294 |
juju-solutions/charms.reactive | charms/reactive/decorators.py | _is_endpoint_method | def _is_endpoint_method(handler):
"""
from the context. Unfortunately, we can't directly detect whether
a handler is an Endpoint method, because at the time of decoration,
the class doesn't actually exist yet so it's impossible to get a
reference to it. So, we use the heuristic of seeing if the ha... | python | def _is_endpoint_method(handler):
"""
from the context. Unfortunately, we can't directly detect whether
a handler is an Endpoint method, because at the time of decoration,
the class doesn't actually exist yet so it's impossible to get a
reference to it. So, we use the heuristic of seeing if the ha... | [
"def",
"_is_endpoint_method",
"(",
"handler",
")",
":",
"params",
"=",
"signature",
"(",
"handler",
")",
".",
"parameters",
"has_self",
"=",
"len",
"(",
"params",
")",
"==",
"1",
"and",
"list",
"(",
"params",
".",
"keys",
"(",
")",
")",
"[",
"0",
"]"... | from the context. Unfortunately, we can't directly detect whether
a handler is an Endpoint method, because at the time of decoration,
the class doesn't actually exist yet so it's impossible to get a
reference to it. So, we use the heuristic of seeing if the handler
takes only a single ``self`` param a... | [
"from",
"the",
"context",
".",
"Unfortunately",
"we",
"can",
"t",
"directly",
"detect",
"whether",
"a",
"handler",
"is",
"an",
"Endpoint",
"method",
"because",
"at",
"the",
"time",
"of",
"decoration",
"the",
"class",
"doesn",
"t",
"actually",
"exist",
"yet",... | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/decorators.py#L297-L310 |
juju-solutions/charms.reactive | charms/reactive/helpers.py | any_hook | def any_hook(*hook_patterns):
"""
Assert that the currently executing hook matches one of the given patterns.
Each pattern will match one or more hooks, and can use the following
special syntax:
* ``db-relation-{joined,changed}`` can be used to match multiple hooks
(in this case, ``db-re... | python | def any_hook(*hook_patterns):
"""
Assert that the currently executing hook matches one of the given patterns.
Each pattern will match one or more hooks, and can use the following
special syntax:
* ``db-relation-{joined,changed}`` can be used to match multiple hooks
(in this case, ``db-re... | [
"def",
"any_hook",
"(",
"*",
"hook_patterns",
")",
":",
"current_hook",
"=",
"hookenv",
".",
"hook_name",
"(",
")",
"# expand {role:interface} patterns",
"i_pat",
"=",
"re",
".",
"compile",
"(",
"r'{([^:}]+):([^}]+)}'",
")",
"hook_patterns",
"=",
"_expand_replacemen... | Assert that the currently executing hook matches one of the given patterns.
Each pattern will match one or more hooks, and can use the following
special syntax:
* ``db-relation-{joined,changed}`` can be used to match multiple hooks
(in this case, ``db-relation-joined`` and ``db-relation-changed`... | [
"Assert",
"that",
"the",
"currently",
"executing",
"hook",
"matches",
"one",
"of",
"the",
"given",
"patterns",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/helpers.py#L58-L82 |
juju-solutions/charms.reactive | charms/reactive/helpers.py | any_file_changed | def any_file_changed(filenames, hash_type='md5'):
"""
Check if any of the given files have changed since the last time this
was called.
:param list filenames: Names of files to check. Accepts callables returning
the filename.
:param str hash_type: Algorithm to use to check the files.
""... | python | def any_file_changed(filenames, hash_type='md5'):
"""
Check if any of the given files have changed since the last time this
was called.
:param list filenames: Names of files to check. Accepts callables returning
the filename.
:param str hash_type: Algorithm to use to check the files.
""... | [
"def",
"any_file_changed",
"(",
"filenames",
",",
"hash_type",
"=",
"'md5'",
")",
":",
"changed",
"=",
"False",
"for",
"filename",
"in",
"filenames",
":",
"if",
"callable",
"(",
"filename",
")",
":",
"filename",
"=",
"str",
"(",
"filename",
"(",
")",
")"... | Check if any of the given files have changed since the last time this
was called.
:param list filenames: Names of files to check. Accepts callables returning
the filename.
:param str hash_type: Algorithm to use to check the files. | [
"Check",
"if",
"any",
"of",
"the",
"given",
"files",
"have",
"changed",
"since",
"the",
"last",
"time",
"this",
"was",
"called",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/helpers.py#L85-L105 |
apiaryio/dredd-hooks-python | dredd_hooks/dredd.py | load_hook_files | def load_hook_files(pathname):
"""
Loads files either defined as a glob or a single file path
sorted by filenames.
"""
global hooks
if sys.version_info[0] > 2 and sys.version_info[1] > 4:
fsglob = sorted(glob.iglob(pathname, recursive=True))
else:
fsglob = sorted(glob.iglob(... | python | def load_hook_files(pathname):
"""
Loads files either defined as a glob or a single file path
sorted by filenames.
"""
global hooks
if sys.version_info[0] > 2 and sys.version_info[1] > 4:
fsglob = sorted(glob.iglob(pathname, recursive=True))
else:
fsglob = sorted(glob.iglob(... | [
"def",
"load_hook_files",
"(",
"pathname",
")",
":",
"global",
"hooks",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
">",
"2",
"and",
"sys",
".",
"version_info",
"[",
"1",
"]",
">",
"4",
":",
"fsglob",
"=",
"sorted",
"(",
"glob",
".",
"iglob",
... | Loads files either defined as a glob or a single file path
sorted by filenames. | [
"Loads",
"files",
"either",
"defined",
"as",
"a",
"glob",
"or",
"a",
"single",
"file",
"path",
"sorted",
"by",
"filenames",
"."
] | train | https://github.com/apiaryio/dredd-hooks-python/blob/0a1b6d799572d3b738097ae88a7f2e571a16e7ff/dredd_hooks/dredd.py#L131-L170 |
juju-solutions/charms.reactive | charms/reactive/__init__.py | main | def main(relation_name=None):
"""
This is the main entry point for the reactive framework. It calls
:func:`~bus.discover` to find and load all reactive handlers (e.g.,
:func:`@when <decorators.when>` decorated blocks), and then
:func:`~bus.dispatch` to trigger handlers until the queue settles out.
... | python | def main(relation_name=None):
"""
This is the main entry point for the reactive framework. It calls
:func:`~bus.discover` to find and load all reactive handlers (e.g.,
:func:`@when <decorators.when>` decorated blocks), and then
:func:`~bus.dispatch` to trigger handlers until the queue settles out.
... | [
"def",
"main",
"(",
"relation_name",
"=",
"None",
")",
":",
"hook_name",
"=",
"hookenv",
".",
"hook_name",
"(",
")",
"restricted_mode",
"=",
"hook_name",
"in",
"[",
"'meter-status-changed'",
",",
"'collect-metrics'",
"]",
"hookenv",
".",
"log",
"(",
"'Reactive... | This is the main entry point for the reactive framework. It calls
:func:`~bus.discover` to find and load all reactive handlers (e.g.,
:func:`@when <decorators.when>` decorated blocks), and then
:func:`~bus.dispatch` to trigger handlers until the queue settles out.
Finally, :meth:`unitdata.kv().flush <c... | [
"This",
"is",
"the",
"main",
"entry",
"point",
"for",
"the",
"reactive",
"framework",
".",
"It",
"calls",
":",
"func",
":",
"~bus",
".",
"discover",
"to",
"find",
"and",
"load",
"all",
"reactive",
"handlers",
"(",
"e",
".",
"g",
".",
":",
"func",
":"... | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/__init__.py#L46-L84 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Endpoint.from_flag | def from_flag(cls, flag):
"""
Return an Endpoint subclass instance based on the given flag.
The instance that is returned depends on the endpoint name embedded
in the flag. Flags should be of the form ``endpoint.{name}.extra...``,
though for legacy purposes, the ``endpoint.`` p... | python | def from_flag(cls, flag):
"""
Return an Endpoint subclass instance based on the given flag.
The instance that is returned depends on the endpoint name embedded
in the flag. Flags should be of the form ``endpoint.{name}.extra...``,
though for legacy purposes, the ``endpoint.`` p... | [
"def",
"from_flag",
"(",
"cls",
",",
"flag",
")",
":",
"if",
"not",
"is_flag_set",
"(",
"flag",
")",
"or",
"'.'",
"not",
"in",
"flag",
":",
"return",
"None",
"parts",
"=",
"flag",
".",
"split",
"(",
"'.'",
")",
"if",
"parts",
"[",
"0",
"]",
"==",... | Return an Endpoint subclass instance based on the given flag.
The instance that is returned depends on the endpoint name embedded
in the flag. Flags should be of the form ``endpoint.{name}.extra...``,
though for legacy purposes, the ``endpoint.`` prefix can be omitted.
The ``{name}}`` ... | [
"Return",
"an",
"Endpoint",
"subclass",
"instance",
"based",
"on",
"the",
"given",
"flag",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L90-L110 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Endpoint._startup | def _startup(cls):
"""
Create Endpoint instances and manage automatic flags.
"""
for endpoint_name in sorted(hookenv.relation_types()):
# populate context based on attached relations
relf = relation_factory(endpoint_name)
if not relf or not issubclass(... | python | def _startup(cls):
"""
Create Endpoint instances and manage automatic flags.
"""
for endpoint_name in sorted(hookenv.relation_types()):
# populate context based on attached relations
relf = relation_factory(endpoint_name)
if not relf or not issubclass(... | [
"def",
"_startup",
"(",
"cls",
")",
":",
"for",
"endpoint_name",
"in",
"sorted",
"(",
"hookenv",
".",
"relation_types",
"(",
")",
")",
":",
"# populate context based on attached relations",
"relf",
"=",
"relation_factory",
"(",
"endpoint_name",
")",
"if",
"not",
... | Create Endpoint instances and manage automatic flags. | [
"Create",
"Endpoint",
"instances",
"and",
"manage",
"automatic",
"flags",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L113-L134 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Endpoint.expand_name | def expand_name(self, flag):
"""
Complete a flag for this endpoint by expanding the endpoint name.
If the flag does not already contain ``{endpoint_name}``, it will be
prefixed with ``endpoint.{endpoint_name}.``. Then, any occurance of
``{endpoint_name}`` will be replaced with `... | python | def expand_name(self, flag):
"""
Complete a flag for this endpoint by expanding the endpoint name.
If the flag does not already contain ``{endpoint_name}``, it will be
prefixed with ``endpoint.{endpoint_name}.``. Then, any occurance of
``{endpoint_name}`` will be replaced with `... | [
"def",
"expand_name",
"(",
"self",
",",
"flag",
")",
":",
"if",
"'{endpoint_name}'",
"not",
"in",
"flag",
":",
"flag",
"=",
"'endpoint.{endpoint_name}.'",
"+",
"flag",
"# use replace rather than format to prevent any other braces or braced",
"# strings from being touched",
... | Complete a flag for this endpoint by expanding the endpoint name.
If the flag does not already contain ``{endpoint_name}``, it will be
prefixed with ``endpoint.{endpoint_name}.``. Then, any occurance of
``{endpoint_name}`` will be replaced with ``self.endpoint_name``. | [
"Complete",
"a",
"flag",
"for",
"this",
"endpoint",
"by",
"expanding",
"the",
"endpoint",
"name",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L192-L204 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Endpoint._manage_flags | def _manage_flags(self):
"""
Manage automatic relation flags.
"""
already_joined = is_flag_set(self.expand_name('joined'))
hook_name = hookenv.hook_name()
rel_hook = hook_name.startswith(self.endpoint_name + '-relation-')
departed_hook = rel_hook and hook_name.end... | python | def _manage_flags(self):
"""
Manage automatic relation flags.
"""
already_joined = is_flag_set(self.expand_name('joined'))
hook_name = hookenv.hook_name()
rel_hook = hook_name.startswith(self.endpoint_name + '-relation-')
departed_hook = rel_hook and hook_name.end... | [
"def",
"_manage_flags",
"(",
"self",
")",
":",
"already_joined",
"=",
"is_flag_set",
"(",
"self",
".",
"expand_name",
"(",
"'joined'",
")",
")",
"hook_name",
"=",
"hookenv",
".",
"hook_name",
"(",
")",
"rel_hook",
"=",
"hook_name",
".",
"startswith",
"(",
... | Manage automatic relation flags. | [
"Manage",
"automatic",
"relation",
"flags",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L218-L248 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Endpoint.all_joined_units | def all_joined_units(self):
"""
A list view of all the units of all relations attached to this
:class:`~charms.reactive.endpoints.Endpoint`.
This is actually a
:class:`~charms.reactive.endpoints.CombinedUnitsView`, so the units
will be in order by relation ID and then un... | python | def all_joined_units(self):
"""
A list view of all the units of all relations attached to this
:class:`~charms.reactive.endpoints.Endpoint`.
This is actually a
:class:`~charms.reactive.endpoints.CombinedUnitsView`, so the units
will be in order by relation ID and then un... | [
"def",
"all_joined_units",
"(",
"self",
")",
":",
"if",
"self",
".",
"_all_joined_units",
"is",
"None",
":",
"units",
"=",
"chain",
".",
"from_iterable",
"(",
"rel",
".",
"units",
"for",
"rel",
"in",
"self",
".",
"relations",
")",
"self",
".",
"_all_join... | A list view of all the units of all relations attached to this
:class:`~charms.reactive.endpoints.Endpoint`.
This is actually a
:class:`~charms.reactive.endpoints.CombinedUnitsView`, so the units
will be in order by relation ID and then unit name, and you can access a
merged vie... | [
"A",
"list",
"view",
"of",
"all",
"the",
"units",
"of",
"all",
"relations",
"attached",
"to",
"this",
":",
"class",
":",
"~charms",
".",
"reactive",
".",
"endpoints",
".",
"Endpoint",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L259-L282 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Endpoint.all_departed_units | def all_departed_units(self):
"""
Collection of all units that were previously part of any relation on
this endpoint but which have since departed.
This collection is persistent and mutable. The departed units will
be kept until they are explicitly removed, to allow for reasona... | python | def all_departed_units(self):
"""
Collection of all units that were previously part of any relation on
this endpoint but which have since departed.
This collection is persistent and mutable. The departed units will
be kept until they are explicitly removed, to allow for reasona... | [
"def",
"all_departed_units",
"(",
"self",
")",
":",
"if",
"self",
".",
"_all_departed_units",
"is",
"None",
":",
"self",
".",
"_all_departed_units",
"=",
"CachedKeyList",
".",
"load",
"(",
"'reactive.endpoints.departed.{}'",
".",
"format",
"(",
"self",
".",
"end... | Collection of all units that were previously part of any relation on
this endpoint but which have since departed.
This collection is persistent and mutable. The departed units will
be kept until they are explicitly removed, to allow for reasonable
cleanup of units that have left.
... | [
"Collection",
"of",
"all",
"units",
"that",
"were",
"previously",
"part",
"of",
"any",
"relation",
"on",
"this",
"endpoint",
"but",
"which",
"have",
"since",
"departed",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L285-L320 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Relation.application_name | def application_name(self):
"""
The name of the remote application for this relation, or ``None``.
This is equivalent to::
relation.units[0].unit_name.split('/')[0]
"""
if self._application_name is None and self.units:
self._application_name = self.units... | python | def application_name(self):
"""
The name of the remote application for this relation, or ``None``.
This is equivalent to::
relation.units[0].unit_name.split('/')[0]
"""
if self._application_name is None and self.units:
self._application_name = self.units... | [
"def",
"application_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_application_name",
"is",
"None",
"and",
"self",
".",
"units",
":",
"self",
".",
"_application_name",
"=",
"self",
".",
"units",
"[",
"0",
"]",
".",
"unit_name",
".",
"split",
"(",
"... | The name of the remote application for this relation, or ``None``.
This is equivalent to::
relation.units[0].unit_name.split('/')[0] | [
"The",
"name",
"of",
"the",
"remote",
"application",
"for",
"this",
"relation",
"or",
"None",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L357-L367 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Relation.joined_units | def joined_units(self):
"""
A list view of all the units joined on this relation.
This is actually a
:class:`~charms.reactive.endpoints.CombinedUnitsView`, so the units
will be in order by unit name, and you can access a merged view of all
of the units' data with ``self.... | python | def joined_units(self):
"""
A list view of all the units joined on this relation.
This is actually a
:class:`~charms.reactive.endpoints.CombinedUnitsView`, so the units
will be in order by unit name, and you can access a merged view of all
of the units' data with ``self.... | [
"def",
"joined_units",
"(",
"self",
")",
":",
"if",
"self",
".",
"_units",
"is",
"None",
":",
"self",
".",
"_units",
"=",
"CombinedUnitsView",
"(",
"[",
"RelatedUnit",
"(",
"self",
",",
"unit_name",
")",
"for",
"unit_name",
"in",
"sorted",
"(",
"hookenv"... | A list view of all the units joined on this relation.
This is actually a
:class:`~charms.reactive.endpoints.CombinedUnitsView`, so the units
will be in order by unit name, and you can access a merged view of all
of the units' data with ``self.units.received`` and
``self.units.re... | [
"A",
"list",
"view",
"of",
"all",
"the",
"units",
"joined",
"on",
"this",
"relation",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L378-L408 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Relation.to_publish | def to_publish(self):
"""
This is the relation data that the local unit publishes so it is
visible to all related units. Use this to communicate with related
units. It is a writeable
:class:`~charms.reactive.endpoints.JSONUnitDataView`.
All values stored in this collecti... | python | def to_publish(self):
"""
This is the relation data that the local unit publishes so it is
visible to all related units. Use this to communicate with related
units. It is a writeable
:class:`~charms.reactive.endpoints.JSONUnitDataView`.
All values stored in this collecti... | [
"def",
"to_publish",
"(",
"self",
")",
":",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"self",
".",
"_data",
"=",
"JSONUnitDataView",
"(",
"hookenv",
".",
"relation_get",
"(",
"unit",
"=",
"hookenv",
".",
"local_unit",
"(",
")",
",",
"rid",
"=",
... | This is the relation data that the local unit publishes so it is
visible to all related units. Use this to communicate with related
units. It is a writeable
:class:`~charms.reactive.endpoints.JSONUnitDataView`.
All values stored in this collection will be automatically JSON
enco... | [
"This",
"is",
"the",
"relation",
"data",
"that",
"the",
"local",
"unit",
"publishes",
"so",
"it",
"is",
"visible",
"to",
"all",
"related",
"units",
".",
"Use",
"this",
"to",
"communicate",
"with",
"related",
"units",
".",
"It",
"is",
"a",
"writeable",
":... | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L411-L432 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | Relation._flush_data | def _flush_data(self):
"""
If this relation's local unit data has been modified, publish it on the
relation. This should be automatically called.
"""
if self._data and self._data.modified:
hookenv.relation_set(self.relation_id, dict(self.to_publish.data)) | python | def _flush_data(self):
"""
If this relation's local unit data has been modified, publish it on the
relation. This should be automatically called.
"""
if self._data and self._data.modified:
hookenv.relation_set(self.relation_id, dict(self.to_publish.data)) | [
"def",
"_flush_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"_data",
"and",
"self",
".",
"_data",
".",
"modified",
":",
"hookenv",
".",
"relation_set",
"(",
"self",
".",
"relation_id",
",",
"dict",
"(",
"self",
".",
"to_publish",
".",
"data",
")",
... | If this relation's local unit data has been modified, publish it on the
relation. This should be automatically called. | [
"If",
"this",
"relation",
"s",
"local",
"unit",
"data",
"has",
"been",
"modified",
"publish",
"it",
"on",
"the",
"relation",
".",
"This",
"should",
"be",
"automatically",
"called",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L449-L455 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | RelatedUnit.received | def received(self):
"""
A :class:`~charms.reactive.endpoints.JSONUnitDataView` of the data
received from this remote unit over the relation, with values being
automatically decoded as JSON.
"""
if self._data is None:
self._data = JSONUnitDataView(hookenv.relat... | python | def received(self):
"""
A :class:`~charms.reactive.endpoints.JSONUnitDataView` of the data
received from this remote unit over the relation, with values being
automatically decoded as JSON.
"""
if self._data is None:
self._data = JSONUnitDataView(hookenv.relat... | [
"def",
"received",
"(",
"self",
")",
":",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"self",
".",
"_data",
"=",
"JSONUnitDataView",
"(",
"hookenv",
".",
"relation_get",
"(",
"unit",
"=",
"self",
".",
"unit_name",
",",
"rid",
"=",
"self",
".",
"re... | A :class:`~charms.reactive.endpoints.JSONUnitDataView` of the data
received from this remote unit over the relation, with values being
automatically decoded as JSON. | [
"A",
":",
"class",
":",
"~charms",
".",
"reactive",
".",
"endpoints",
".",
"JSONUnitDataView",
"of",
"the",
"data",
"received",
"from",
"this",
"remote",
"unit",
"over",
"the",
"relation",
"with",
"values",
"being",
"automatically",
"decoded",
"as",
"JSON",
... | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L503-L513 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | CachedKeyList.load | def load(cls, cache_key, deserializer, key_attr):
"""
Load the persisted cache and return a new instance of this class.
"""
items = unitdata.kv().get(cache_key) or []
return cls(cache_key,
[deserializer(item) for item in items],
key_attr) | python | def load(cls, cache_key, deserializer, key_attr):
"""
Load the persisted cache and return a new instance of this class.
"""
items = unitdata.kv().get(cache_key) or []
return cls(cache_key,
[deserializer(item) for item in items],
key_attr) | [
"def",
"load",
"(",
"cls",
",",
"cache_key",
",",
"deserializer",
",",
"key_attr",
")",
":",
"items",
"=",
"unitdata",
".",
"kv",
"(",
")",
".",
"get",
"(",
"cache_key",
")",
"or",
"[",
"]",
"return",
"cls",
"(",
"cache_key",
",",
"[",
"deserializer"... | Load the persisted cache and return a new instance of this class. | [
"Load",
"the",
"persisted",
"cache",
"and",
"return",
"a",
"new",
"instance",
"of",
"this",
"class",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L613-L620 |
juju-solutions/charms.reactive | charms/reactive/endpoints.py | CombinedUnitsView.received | def received(self):
"""
Combined :class:`~charms.reactive.endpoints.JSONUnitDataView` of the
data of all units in this list, with automatic JSON decoding.
"""
if not hasattr(self, '_data'):
# NB: units are reversed so that lowest numbered unit takes precedence
... | python | def received(self):
"""
Combined :class:`~charms.reactive.endpoints.JSONUnitDataView` of the
data of all units in this list, with automatic JSON decoding.
"""
if not hasattr(self, '_data'):
# NB: units are reversed so that lowest numbered unit takes precedence
... | [
"def",
"received",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_data'",
")",
":",
"# NB: units are reversed so that lowest numbered unit takes precedence",
"self",
".",
"_data",
"=",
"JSONUnitDataView",
"(",
"{",
"key",
":",
"value",
"for",
... | Combined :class:`~charms.reactive.endpoints.JSONUnitDataView` of the
data of all units in this list, with automatic JSON decoding. | [
"Combined",
":",
"class",
":",
"~charms",
".",
"reactive",
".",
"endpoints",
".",
"JSONUnitDataView",
"of",
"the",
"data",
"of",
"all",
"units",
"in",
"this",
"list",
"with",
"automatic",
"JSON",
"decoding",
"."
] | train | https://github.com/juju-solutions/charms.reactive/blob/e37e781432e77c12b63d2c739bd6cd70d3230c3a/charms/reactive/endpoints.py#L728-L739 |
podio/podio-py | pypodio2/api.py | AuthorizingClient | def AuthorizingClient(domain, auth, user_agent=None):
"""Creates a Podio client using an auth object."""
http_transport = transport.HttpTransport(domain, build_headers(auth, user_agent))
return client.Client(http_transport) | python | def AuthorizingClient(domain, auth, user_agent=None):
"""Creates a Podio client using an auth object."""
http_transport = transport.HttpTransport(domain, build_headers(auth, user_agent))
return client.Client(http_transport) | [
"def",
"AuthorizingClient",
"(",
"domain",
",",
"auth",
",",
"user_agent",
"=",
"None",
")",
":",
"http_transport",
"=",
"transport",
".",
"HttpTransport",
"(",
"domain",
",",
"build_headers",
"(",
"auth",
",",
"user_agent",
")",
")",
"return",
"client",
"."... | Creates a Podio client using an auth object. | [
"Creates",
"a",
"Podio",
"client",
"using",
"an",
"auth",
"object",
"."
] | train | https://github.com/podio/podio-py/blob/5ce956034a06c98b0ef18fcd940b36da0908ad6c/pypodio2/api.py#L28-L31 |
benoitguigal/python-epson-printer | epson_printer/epsonprinter.py | PrintableImage.from_image | def from_image(cls, image):
"""
Create a PrintableImage from a PIL Image
:param image: a PIL Image
:return:
"""
(w, h) = image.size
# Thermal paper is 512 pixels wide
if w > 512:
ratio = 512. / w
h = int(h * ratio)
imag... | python | def from_image(cls, image):
"""
Create a PrintableImage from a PIL Image
:param image: a PIL Image
:return:
"""
(w, h) = image.size
# Thermal paper is 512 pixels wide
if w > 512:
ratio = 512. / w
h = int(h * ratio)
imag... | [
"def",
"from_image",
"(",
"cls",
",",
"image",
")",
":",
"(",
"w",
",",
"h",
")",
"=",
"image",
".",
"size",
"# Thermal paper is 512 pixels wide",
"if",
"w",
">",
"512",
":",
"ratio",
"=",
"512.",
"/",
"w",
"h",
"=",
"int",
"(",
"h",
"*",
"ratio",
... | Create a PrintableImage from a PIL Image
:param image: a PIL Image
:return: | [
"Create",
"a",
"PrintableImage",
"from",
"a",
"PIL",
"Image",
":",
"param",
"image",
":",
"a",
"PIL",
"Image",
":",
"return",
":"
] | train | https://github.com/benoitguigal/python-epson-printer/blob/7d89b2f21bc76d2cc4d5ad548e19a356ca92fbc5/epson_printer/epsonprinter.py#L103-L153 |
benoitguigal/python-epson-printer | epson_printer/epsonprinter.py | PrintableImage.append | def append(self, other):
"""
Append a Printable Image at the end of the current instance.
:param other: another PrintableImage
:return: PrintableImage containing data from both self and other
"""
self.data.extend(other.data)
self.height = self.height + other.heigh... | python | def append(self, other):
"""
Append a Printable Image at the end of the current instance.
:param other: another PrintableImage
:return: PrintableImage containing data from both self and other
"""
self.data.extend(other.data)
self.height = self.height + other.heigh... | [
"def",
"append",
"(",
"self",
",",
"other",
")",
":",
"self",
".",
"data",
".",
"extend",
"(",
"other",
".",
"data",
")",
"self",
".",
"height",
"=",
"self",
".",
"height",
"+",
"other",
".",
"height",
"return",
"self"
] | Append a Printable Image at the end of the current instance.
:param other: another PrintableImage
:return: PrintableImage containing data from both self and other | [
"Append",
"a",
"Printable",
"Image",
"at",
"the",
"end",
"of",
"the",
"current",
"instance",
".",
":",
"param",
"other",
":",
"another",
"PrintableImage",
":",
"return",
":",
"PrintableImage",
"containing",
"data",
"from",
"both",
"self",
"and",
"other"
] | train | https://github.com/benoitguigal/python-epson-printer/blob/7d89b2f21bc76d2cc4d5ad548e19a356ca92fbc5/epson_printer/epsonprinter.py#L155-L163 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.