repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
GoogleCloudPlatform/datastore-ndb-python
ndb/polymodel.py
PolyModel._get_kind
def _get_kind(cls): """Override. Make sure that the kind returned is the root class of the polymorphic hierarchy. """ bases = cls._get_hierarchy() if not bases: # We have to jump through some hoops to call the superclass' # _get_kind() method. First, this is called by the metaclass...
python
def _get_kind(cls): """Override. Make sure that the kind returned is the root class of the polymorphic hierarchy. """ bases = cls._get_hierarchy() if not bases: # We have to jump through some hoops to call the superclass' # _get_kind() method. First, this is called by the metaclass...
[ "def", "_get_kind", "(", "cls", ")", ":", "bases", "=", "cls", ".", "_get_hierarchy", "(", ")", "if", "not", "bases", ":", "# We have to jump through some hoops to call the superclass'", "# _get_kind() method. First, this is called by the metaclass", "# before the PolyModel na...
Override. Make sure that the kind returned is the root class of the polymorphic hierarchy.
[ "Override", "." ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L206-L222
train
GoogleCloudPlatform/datastore-ndb-python
ndb/polymodel.py
PolyModel._get_hierarchy
def _get_hierarchy(cls): """Internal helper to return the list of polymorphic base classes. This returns a list of class objects, e.g. [Animal, Feline, Cat]. """ bases = [] for base in cls.mro(): # pragma: no branch if hasattr(base, '_get_hierarchy'): bases.append(base) del bases...
python
def _get_hierarchy(cls): """Internal helper to return the list of polymorphic base classes. This returns a list of class objects, e.g. [Animal, Feline, Cat]. """ bases = [] for base in cls.mro(): # pragma: no branch if hasattr(base, '_get_hierarchy'): bases.append(base) del bases...
[ "def", "_get_hierarchy", "(", "cls", ")", ":", "bases", "=", "[", "]", "for", "base", "in", "cls", ".", "mro", "(", ")", ":", "# pragma: no branch", "if", "hasattr", "(", "base", ",", "'_get_hierarchy'", ")", ":", "bases", ".", "append", "(", "base", ...
Internal helper to return the list of polymorphic base classes. This returns a list of class objects, e.g. [Animal, Feline, Cat].
[ "Internal", "helper", "to", "return", "the", "list", "of", "polymorphic", "base", "classes", "." ]
cf4cab3f1f69cd04e1a9229871be466b53729f3f
https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L242-L253
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_common.py
find_env_paths_in_basedirs
def find_env_paths_in_basedirs(base_dirs): """Returns all potential envs in a basedir""" # get potential env path in the base_dirs env_path = [] for base_dir in base_dirs: env_path.extend(glob.glob(os.path.join( os.path.expanduser(base_dir), '*', ''))) # self.log.info("Found the ...
python
def find_env_paths_in_basedirs(base_dirs): """Returns all potential envs in a basedir""" # get potential env path in the base_dirs env_path = [] for base_dir in base_dirs: env_path.extend(glob.glob(os.path.join( os.path.expanduser(base_dir), '*', ''))) # self.log.info("Found the ...
[ "def", "find_env_paths_in_basedirs", "(", "base_dirs", ")", ":", "# get potential env path in the base_dirs", "env_path", "=", "[", "]", "for", "base_dir", "in", "base_dirs", ":", "env_path", ".", "extend", "(", "glob", ".", "glob", "(", "os", ".", "path", ".", ...
Returns all potential envs in a basedir
[ "Returns", "all", "potential", "envs", "in", "a", "basedir" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L12-L21
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_common.py
convert_to_env_data
def convert_to_env_data(mgr, env_paths, validator_func, activate_func, name_template, display_name_template, name_prefix): """Converts a list of paths to environments to env_data. env_data is a structure {name -> (ressourcedir, kernel spec)} """ env_data = {} for venv_dir in...
python
def convert_to_env_data(mgr, env_paths, validator_func, activate_func, name_template, display_name_template, name_prefix): """Converts a list of paths to environments to env_data. env_data is a structure {name -> (ressourcedir, kernel spec)} """ env_data = {} for venv_dir in...
[ "def", "convert_to_env_data", "(", "mgr", ",", "env_paths", ",", "validator_func", ",", "activate_func", ",", "name_template", ",", "display_name_template", ",", "name_prefix", ")", ":", "env_data", "=", "{", "}", "for", "venv_dir", "in", "env_paths", ":", "venv...
Converts a list of paths to environments to env_data. env_data is a structure {name -> (ressourcedir, kernel spec)}
[ "Converts", "a", "list", "of", "paths", "to", "environments", "to", "env_data", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L24-L60
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_common.py
validate_IPykernel
def validate_IPykernel(venv_dir): """Validates that this env contains an IPython kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ python_exe_name = find_exe(venv_dir, "python") if python_exe_name is None: python_exe_name = find_exe(venv_dir, "py...
python
def validate_IPykernel(venv_dir): """Validates that this env contains an IPython kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ python_exe_name = find_exe(venv_dir, "python") if python_exe_name is None: python_exe_name = find_exe(venv_dir, "py...
[ "def", "validate_IPykernel", "(", "venv_dir", ")", ":", "python_exe_name", "=", "find_exe", "(", "venv_dir", ",", "\"python\"", ")", "if", "python_exe_name", "is", "None", ":", "python_exe_name", "=", "find_exe", "(", "venv_dir", ",", "\"python2\"", ")", "if", ...
Validates that this env contains an IPython kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir)
[ "Validates", "that", "this", "env", "contains", "an", "IPython", "kernel", "and", "returns", "info", "to", "start", "it" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L63-L93
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_common.py
validate_IRkernel
def validate_IRkernel(venv_dir): """Validates that this env contains an IRkernel kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ r_exe_name = find_exe(venv_dir, "R") if r_exe_name is None: return [], None, None # check if this is really an...
python
def validate_IRkernel(venv_dir): """Validates that this env contains an IRkernel kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir) """ r_exe_name = find_exe(venv_dir, "R") if r_exe_name is None: return [], None, None # check if this is really an...
[ "def", "validate_IRkernel", "(", "venv_dir", ")", ":", "r_exe_name", "=", "find_exe", "(", "venv_dir", ",", "\"R\"", ")", "if", "r_exe_name", "is", "None", ":", "return", "[", "]", ",", "None", ",", "None", "# check if this is really an IRkernel **kernel**", "im...
Validates that this env contains an IRkernel kernel and returns info to start it Returns: tuple (ARGV, language, resource_dir)
[ "Validates", "that", "this", "env", "contains", "an", "IRkernel", "kernel", "and", "returns", "info", "to", "start", "it" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L96-L121
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_common.py
find_exe
def find_exe(env_dir, name): """Finds a exe with that name in the environment path""" if platform.system() == "Windows": name = name + ".exe" # find the binary exe_name = os.path.join(env_dir, name) if not os.path.exists(exe_name): exe_name = os.path.join(env_dir, "bin", name) ...
python
def find_exe(env_dir, name): """Finds a exe with that name in the environment path""" if platform.system() == "Windows": name = name + ".exe" # find the binary exe_name = os.path.join(env_dir, name) if not os.path.exists(exe_name): exe_name = os.path.join(env_dir, "bin", name) ...
[ "def", "find_exe", "(", "env_dir", ",", "name", ")", ":", "if", "platform", ".", "system", "(", ")", "==", "\"Windows\"", ":", "name", "=", "name", "+", "\".exe\"", "# find the binary", "exe_name", "=", "os", ".", "path", ".", "join", "(", "env_dir", "...
Finds a exe with that name in the environment path
[ "Finds", "a", "exe", "with", "that", "name", "in", "the", "environment", "path" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L124-L138
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_virtualenv.py
get_virtualenv_env_data
def get_virtualenv_env_data(mgr): """Finds kernel specs from virtualenv environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_virtualenv_envs: return {} mgr.log.debug("Looking for virtualenv environments in %s...", mgr.virtualenv_env_dirs) # fi...
python
def get_virtualenv_env_data(mgr): """Finds kernel specs from virtualenv environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_virtualenv_envs: return {} mgr.log.debug("Looking for virtualenv environments in %s...", mgr.virtualenv_env_dirs) # fi...
[ "def", "get_virtualenv_env_data", "(", "mgr", ")", ":", "if", "not", "mgr", ".", "find_virtualenv_envs", ":", "return", "{", "}", "mgr", ".", "log", ".", "debug", "(", "\"Looking for virtualenv environments in %s...\"", ",", "mgr", ".", "virtualenv_env_dirs", ")",...
Finds kernel specs from virtualenv environments env_data is a structure {name -> (resourcedir, kernel spec)}
[ "Finds", "kernel", "specs", "from", "virtualenv", "environments" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_virtualenv.py#L12-L35
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
source_bash
def source_bash(args, stdin=None): """Simply bash-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['bash', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
python
def source_bash(args, stdin=None): """Simply bash-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['bash', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
[ "def", "source_bash", "(", "args", ",", "stdin", "=", "None", ")", ":", "args", "=", "list", "(", "args", ")", "new_args", "=", "[", "'bash'", ",", "'--sourcer=source'", "]", "new_args", ".", "extend", "(", "args", ")", "return", "source_foreign", "(", ...
Simply bash-specific wrapper around source-foreign Returns a dict to be used as a new environment
[ "Simply", "bash", "-", "specific", "wrapper", "around", "source", "-", "foreign" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L66-L73
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
source_zsh
def source_zsh(args, stdin=None): """Simply zsh-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['zsh', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
python
def source_zsh(args, stdin=None): """Simply zsh-specific wrapper around source-foreign Returns a dict to be used as a new environment""" args = list(args) new_args = ['zsh', '--sourcer=source'] new_args.extend(args) return source_foreign(new_args, stdin=stdin)
[ "def", "source_zsh", "(", "args", ",", "stdin", "=", "None", ")", ":", "args", "=", "list", "(", "args", ")", "new_args", "=", "[", "'zsh'", ",", "'--sourcer=source'", "]", "new_args", ".", "extend", "(", "args", ")", "return", "source_foreign", "(", "...
Simply zsh-specific wrapper around source-foreign Returns a dict to be used as a new environment
[ "Simply", "zsh", "-", "specific", "wrapper", "around", "source", "-", "foreign" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L75-L82
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
source_cmd
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign. returns a dict to be used as a new environment """ args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): raise RuntimeError("C...
python
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign. returns a dict to be used as a new environment """ args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): raise RuntimeError("C...
[ "def", "source_cmd", "(", "args", ",", "stdin", "=", "None", ")", ":", "args", "=", "list", "(", "args", ")", "fpath", "=", "locate_binary", "(", "args", "[", "0", "]", ")", "args", "[", "0", "]", "=", "fpath", "if", "fpath", "else", "args", "[",...
Simple cmd.exe-specific wrapper around source-foreign. returns a dict to be used as a new environment
[ "Simple", "cmd", ".", "exe", "-", "specific", "wrapper", "around", "source", "-", "foreign", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L85-L105
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
argvquote
def argvquote(arg, force=False): """ Returns an argument quoted in such a way that that CommandLineToArgvW on Windows will return the argument string unchanged. This is the same thing Popen does when supplied with an list of arguments. Arguments in a command line should be separated by spaces; this ...
python
def argvquote(arg, force=False): """ Returns an argument quoted in such a way that that CommandLineToArgvW on Windows will return the argument string unchanged. This is the same thing Popen does when supplied with an list of arguments. Arguments in a command line should be separated by spaces; this ...
[ "def", "argvquote", "(", "arg", ",", "force", "=", "False", ")", ":", "if", "not", "force", "and", "len", "(", "arg", ")", "!=", "0", "and", "not", "any", "(", "[", "c", "in", "arg", "for", "c", "in", "' \\t\\n\\v\"'", "]", ")", ":", "return", ...
Returns an argument quoted in such a way that that CommandLineToArgvW on Windows will return the argument string unchanged. This is the same thing Popen does when supplied with an list of arguments. Arguments in a command line should be separated by spaces; this function does not add these spaces. This ...
[ "Returns", "an", "argument", "quoted", "in", "such", "a", "way", "that", "that", "CommandLineToArgvW", "on", "Windows", "will", "return", "the", "argument", "string", "unchanged", ".", "This", "is", "the", "same", "thing", "Popen", "does", "when", "supplied", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L124-L155
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
escape_windows_cmd_string
def escape_windows_cmd_string(s): """Returns a string that is usable by the Windows cmd.exe. The escaping is based on details here and emperical testing: http://www.robvanderwoude.com/escapechars.php """ for c in '()%!^<>&|"': s = s.replace(c, '^' + c) s = s.replace('/?', '/.') retur...
python
def escape_windows_cmd_string(s): """Returns a string that is usable by the Windows cmd.exe. The escaping is based on details here and emperical testing: http://www.robvanderwoude.com/escapechars.php """ for c in '()%!^<>&|"': s = s.replace(c, '^' + c) s = s.replace('/?', '/.') retur...
[ "def", "escape_windows_cmd_string", "(", "s", ")", ":", "for", "c", "in", "'()%!^<>&|\"'", ":", "s", "=", "s", ".", "replace", "(", "c", ",", "'^'", "+", "c", ")", "s", "=", "s", ".", "replace", "(", "'/?'", ",", "'/.'", ")", "return", "s" ]
Returns a string that is usable by the Windows cmd.exe. The escaping is based on details here and emperical testing: http://www.robvanderwoude.com/escapechars.php
[ "Returns", "a", "string", "that", "is", "usable", "by", "the", "Windows", "cmd", ".", "exe", ".", "The", "escaping", "is", "based", "on", "details", "here", "and", "emperical", "testing", ":", "http", ":", "//", "www", ".", "robvanderwoude", ".", "com", ...
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L158-L166
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
source_foreign
def source_foreign(args, stdin=None): """Sources a file written in a foreign shell language.""" parser = _ensure_source_foreign_parser() ns = parser.parse_args(args) if ns.prevcmd is not None: pass # don't change prevcmd if given explicitly elif os.path.isfile(ns.files_or_code[0]): ...
python
def source_foreign(args, stdin=None): """Sources a file written in a foreign shell language.""" parser = _ensure_source_foreign_parser() ns = parser.parse_args(args) if ns.prevcmd is not None: pass # don't change prevcmd if given explicitly elif os.path.isfile(ns.files_or_code[0]): ...
[ "def", "source_foreign", "(", "args", ",", "stdin", "=", "None", ")", ":", "parser", "=", "_ensure_source_foreign_parser", "(", ")", "ns", "=", "parser", ".", "parse_args", "(", "args", ")", "if", "ns", ".", "prevcmd", "is", "not", "None", ":", "pass", ...
Sources a file written in a foreign shell language.
[ "Sources", "a", "file", "written", "in", "a", "foreign", "shell", "language", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L169-L204
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
_is_executable_file
def _is_executable_file(path): """Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. This function was forked from pexpect originally: Copyright (c) 2013-2014, Pexpect development team Copyright (c) 2012,...
python
def _is_executable_file(path): """Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. This function was forked from pexpect originally: Copyright (c) 2013-2014, Pexpect development team Copyright (c) 2012,...
[ "def", "_is_executable_file", "(", "path", ")", ":", "# follow symlinks,", "fpath", "=", "os", ".", "path", ".", "realpath", "(", "path", ")", "if", "not", "os", ".", "path", ".", "isfile", "(", "fpath", ")", ":", "# non-files (directories, fifo, etc.)", "re...
Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. This function was forked from pexpect originally: Copyright (c) 2013-2014, Pexpect development team Copyright (c) 2012, Noah Spurrier <noah@noah.org> PE...
[ "Checks", "that", "path", "is", "an", "executable", "regular", "file", "or", "a", "symlink", "towards", "one", ".", "This", "is", "roughly", "os", ".", "path", "isfile", "(", "path", ")", "and", "os", ".", "access", "(", "path", "os", ".", "X_OK", ")...
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L244-L271
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
foreign_shell_data
def foreign_shell_data(shell, interactive=True, login=False, envcmd=None, aliascmd=None, extra_args=(), currenv=None, safe=False, prevcmd='', postcmd='', funcscmd=None, sourcer=None, use_tmpfile=False, tmpfile_ext=None, runcmd=N...
python
def foreign_shell_data(shell, interactive=True, login=False, envcmd=None, aliascmd=None, extra_args=(), currenv=None, safe=False, prevcmd='', postcmd='', funcscmd=None, sourcer=None, use_tmpfile=False, tmpfile_ext=None, runcmd=N...
[ "def", "foreign_shell_data", "(", "shell", ",", "interactive", "=", "True", ",", "login", "=", "False", ",", "envcmd", "=", "None", ",", "aliascmd", "=", "None", ",", "extra_args", "=", "(", ")", ",", "currenv", "=", "None", ",", "safe", "=", "False", ...
Extracts data from a foreign (non-xonsh) shells. Currently this gets the environment, aliases, and functions but may be extended in the future. Parameters ---------- shell : str The name of the shell, such as 'bash' or '/bin/sh'. interactive : bool, optional Whether the shell should...
[ "Extracts", "data", "from", "a", "foreign", "(", "non", "-", "xonsh", ")", "shells", ".", "Currently", "this", "gets", "the", "environment", "aliases", "and", "functions", "but", "may", "be", "extended", "in", "the", "future", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L328-L443
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
to_bool
def to_bool(x): """"Converts to a boolean in a semantically meaningful way.""" if isinstance(x, bool): return x elif isinstance(x, str): return False if x.lower() in _FALSES else True else: return bool(x)
python
def to_bool(x): """"Converts to a boolean in a semantically meaningful way.""" if isinstance(x, bool): return x elif isinstance(x, str): return False if x.lower() in _FALSES else True else: return bool(x)
[ "def", "to_bool", "(", "x", ")", ":", "if", "isinstance", "(", "x", ",", "bool", ")", ":", "return", "x", "elif", "isinstance", "(", "x", ",", "str", ")", ":", "return", "False", "if", "x", ".", "lower", "(", ")", "in", "_FALSES", "else", "True",...
Converts to a boolean in a semantically meaningful way.
[ "Converts", "to", "a", "boolean", "in", "a", "semantically", "meaningful", "way", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L445-L452
train
Cadair/jupyter_environment_kernels
environment_kernels/activate_helper.py
parse_env
def parse_env(s): """Parses the environment portion of string into a dict.""" m = ENV_RE.search(s) if m is None: return {} g1 = m.group(1) env = dict(ENV_SPLIT_RE.findall(g1)) return env
python
def parse_env(s): """Parses the environment portion of string into a dict.""" m = ENV_RE.search(s) if m is None: return {} g1 = m.group(1) env = dict(ENV_SPLIT_RE.findall(g1)) return env
[ "def", "parse_env", "(", "s", ")", ":", "m", "=", "ENV_RE", ".", "search", "(", "s", ")", "if", "m", "is", "None", ":", "return", "{", "}", "g1", "=", "m", ".", "group", "(", "1", ")", "env", "=", "dict", "(", "ENV_SPLIT_RE", ".", "findall", ...
Parses the environment portion of string into a dict.
[ "Parses", "the", "environment", "portion", "of", "string", "into", "a", "dict", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L511-L518
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_conda.py
get_conda_env_data
def get_conda_env_data(mgr): """Finds kernel specs from conda environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_conda_envs: return {} mgr.log.debug("Looking for conda environments in %s...", mgr.conda_env_dirs) # find all potential env paths...
python
def get_conda_env_data(mgr): """Finds kernel specs from conda environments env_data is a structure {name -> (resourcedir, kernel spec)} """ if not mgr.find_conda_envs: return {} mgr.log.debug("Looking for conda environments in %s...", mgr.conda_env_dirs) # find all potential env paths...
[ "def", "get_conda_env_data", "(", "mgr", ")", ":", "if", "not", "mgr", ".", "find_conda_envs", ":", "return", "{", "}", "mgr", ".", "log", ".", "debug", "(", "\"Looking for conda environments in %s...\"", ",", "mgr", ".", "conda_env_dirs", ")", "# find all poten...
Finds kernel specs from conda environments env_data is a structure {name -> (resourcedir, kernel spec)}
[ "Finds", "kernel", "specs", "from", "conda", "environments" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_conda.py#L10-L42
train
Cadair/jupyter_environment_kernels
environment_kernels/envs_conda.py
_find_conda_env_paths_from_conda
def _find_conda_env_paths_from_conda(mgr): """Returns a list of path as given by `conda env list --json`. Returns empty list, if conda couldn't be called. """ # this is expensive, so make it configureable... if not mgr.use_conda_directly: return [] mgr.log.debug("Looking for conda envir...
python
def _find_conda_env_paths_from_conda(mgr): """Returns a list of path as given by `conda env list --json`. Returns empty list, if conda couldn't be called. """ # this is expensive, so make it configureable... if not mgr.use_conda_directly: return [] mgr.log.debug("Looking for conda envir...
[ "def", "_find_conda_env_paths_from_conda", "(", "mgr", ")", ":", "# this is expensive, so make it configureable...", "if", "not", "mgr", ".", "use_conda_directly", ":", "return", "[", "]", "mgr", ".", "log", ".", "debug", "(", "\"Looking for conda environments by calling ...
Returns a list of path as given by `conda env list --json`. Returns empty list, if conda couldn't be called.
[ "Returns", "a", "list", "of", "path", "as", "given", "by", "conda", "env", "list", "--", "json", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_conda.py#L62-L91
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager.validate_env
def validate_env(self, envname): """ Check the name of the environment against the black list and the whitelist. If a whitelist is specified only it is checked. """ if self.whitelist_envs and envname in self.whitelist_envs: return True elif self.whitelist_envs...
python
def validate_env(self, envname): """ Check the name of the environment against the black list and the whitelist. If a whitelist is specified only it is checked. """ if self.whitelist_envs and envname in self.whitelist_envs: return True elif self.whitelist_envs...
[ "def", "validate_env", "(", "self", ",", "envname", ")", ":", "if", "self", ".", "whitelist_envs", "and", "envname", "in", "self", ".", "whitelist_envs", ":", "return", "True", "elif", "self", ".", "whitelist_envs", ":", "return", "False", "if", "self", "....
Check the name of the environment against the black list and the whitelist. If a whitelist is specified only it is checked.
[ "Check", "the", "name", "of", "the", "environment", "against", "the", "black", "list", "and", "the", "whitelist", ".", "If", "a", "whitelist", "is", "specified", "only", "it", "is", "checked", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L128-L144
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager._get_env_data
def _get_env_data(self, reload=False): """Get the data about the available environments. env_data is a structure {name -> (resourcedir, kernel spec)} """ # This is called much too often and finding-process is really expensive :-( if not reload and getattr(self, "_env_data_cache...
python
def _get_env_data(self, reload=False): """Get the data about the available environments. env_data is a structure {name -> (resourcedir, kernel spec)} """ # This is called much too often and finding-process is really expensive :-( if not reload and getattr(self, "_env_data_cache...
[ "def", "_get_env_data", "(", "self", ",", "reload", "=", "False", ")", ":", "# This is called much too often and finding-process is really expensive :-(", "if", "not", "reload", "and", "getattr", "(", "self", ",", "\"_env_data_cache\"", ",", "{", "}", ")", ":", "ret...
Get the data about the available environments. env_data is a structure {name -> (resourcedir, kernel spec)}
[ "Get", "the", "data", "about", "the", "available", "environments", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L154-L174
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager.find_kernel_specs_for_envs
def find_kernel_specs_for_envs(self): """Returns a dict mapping kernel names to resource directories.""" data = self._get_env_data() return {name: data[name][0] for name in data}
python
def find_kernel_specs_for_envs(self): """Returns a dict mapping kernel names to resource directories.""" data = self._get_env_data() return {name: data[name][0] for name in data}
[ "def", "find_kernel_specs_for_envs", "(", "self", ")", ":", "data", "=", "self", ".", "_get_env_data", "(", ")", "return", "{", "name", ":", "data", "[", "name", "]", "[", "0", "]", "for", "name", "in", "data", "}" ]
Returns a dict mapping kernel names to resource directories.
[ "Returns", "a", "dict", "mapping", "kernel", "names", "to", "resource", "directories", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L176-L179
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager.get_all_kernel_specs_for_envs
def get_all_kernel_specs_for_envs(self): """Returns the dict of name -> kernel_spec for all environments""" data = self._get_env_data() return {name: data[name][1] for name in data}
python
def get_all_kernel_specs_for_envs(self): """Returns the dict of name -> kernel_spec for all environments""" data = self._get_env_data() return {name: data[name][1] for name in data}
[ "def", "get_all_kernel_specs_for_envs", "(", "self", ")", ":", "data", "=", "self", ".", "_get_env_data", "(", ")", "return", "{", "name", ":", "data", "[", "name", "]", "[", "1", "]", "for", "name", "in", "data", "}" ]
Returns the dict of name -> kernel_spec for all environments
[ "Returns", "the", "dict", "of", "name", "-", ">", "kernel_spec", "for", "all", "environments" ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L181-L185
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager.find_kernel_specs
def find_kernel_specs(self): """Returns a dict mapping kernel names to resource directories.""" # let real installed kernels overwrite envs with the same name: # this is the same order as the get_kernel_spec way, which also prefers # kernels from the jupyter dir over env kernels. ...
python
def find_kernel_specs(self): """Returns a dict mapping kernel names to resource directories.""" # let real installed kernels overwrite envs with the same name: # this is the same order as the get_kernel_spec way, which also prefers # kernels from the jupyter dir over env kernels. ...
[ "def", "find_kernel_specs", "(", "self", ")", ":", "# let real installed kernels overwrite envs with the same name:", "# this is the same order as the get_kernel_spec way, which also prefers", "# kernels from the jupyter dir over env kernels.", "specs", "=", "self", ".", "find_kernel_specs...
Returns a dict mapping kernel names to resource directories.
[ "Returns", "a", "dict", "mapping", "kernel", "names", "to", "resource", "directories", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L187-L195
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager.get_all_specs
def get_all_specs(self): """Returns a dict mapping kernel names and resource directories. """ # This is new in 4.1 -> https://github.com/jupyter/jupyter_client/pull/93 specs = self.get_all_kernel_specs_for_envs() specs.update(super(EnvironmentKernelSpecManager, self).get_all_spec...
python
def get_all_specs(self): """Returns a dict mapping kernel names and resource directories. """ # This is new in 4.1 -> https://github.com/jupyter/jupyter_client/pull/93 specs = self.get_all_kernel_specs_for_envs() specs.update(super(EnvironmentKernelSpecManager, self).get_all_spec...
[ "def", "get_all_specs", "(", "self", ")", ":", "# This is new in 4.1 -> https://github.com/jupyter/jupyter_client/pull/93", "specs", "=", "self", ".", "get_all_kernel_specs_for_envs", "(", ")", "specs", ".", "update", "(", "super", "(", "EnvironmentKernelSpecManager", ",", ...
Returns a dict mapping kernel names and resource directories.
[ "Returns", "a", "dict", "mapping", "kernel", "names", "and", "resource", "directories", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L197-L203
train
Cadair/jupyter_environment_kernels
environment_kernels/core.py
EnvironmentKernelSpecManager.get_kernel_spec
def get_kernel_spec(self, kernel_name): """Returns a :class:`KernelSpec` instance for the given kernel_name. Raises :exc:`NoSuchKernel` if the given kernel name is not found. """ try: return super(EnvironmentKernelSpecManager, self).get_kernel_spec(k...
python
def get_kernel_spec(self, kernel_name): """Returns a :class:`KernelSpec` instance for the given kernel_name. Raises :exc:`NoSuchKernel` if the given kernel name is not found. """ try: return super(EnvironmentKernelSpecManager, self).get_kernel_spec(k...
[ "def", "get_kernel_spec", "(", "self", ",", "kernel_name", ")", ":", "try", ":", "return", "super", "(", "EnvironmentKernelSpecManager", ",", "self", ")", ".", "get_kernel_spec", "(", "kernel_name", ")", "except", "(", "NoSuchKernel", ",", "FileNotFoundError", "...
Returns a :class:`KernelSpec` instance for the given kernel_name. Raises :exc:`NoSuchKernel` if the given kernel name is not found.
[ "Returns", "a", ":", "class", ":", "KernelSpec", "instance", "for", "the", "given", "kernel_name", "." ]
3da304550b511bda7d5d39280379b5ca39bb31bc
https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L205-L219
train
opendatakosovo/cyrillic-transliteration
cyrtranslit/__init__.py
to_latin
def to_latin(string_to_transliterate, lang_code='sr'): ''' Transliterate serbian cyrillic string of characters to latin string of characters. :param string_to_transliterate: The cyrillic string to transliterate into latin characters. :param lang_code: Indicates the cyrillic language code we are translating ...
python
def to_latin(string_to_transliterate, lang_code='sr'): ''' Transliterate serbian cyrillic string of characters to latin string of characters. :param string_to_transliterate: The cyrillic string to transliterate into latin characters. :param lang_code: Indicates the cyrillic language code we are translating ...
[ "def", "to_latin", "(", "string_to_transliterate", ",", "lang_code", "=", "'sr'", ")", ":", "# First check if we support the cyrillic alphabet we want to transliterate to latin.", "if", "lang_code", ".", "lower", "(", ")", "not", "in", "TRANSLIT_DICT", ":", "# If we don't s...
Transliterate serbian cyrillic string of characters to latin string of characters. :param string_to_transliterate: The cyrillic string to transliterate into latin characters. :param lang_code: Indicates the cyrillic language code we are translating from. Defaults to Serbian (sr). :return: A string of latin ...
[ "Transliterate", "serbian", "cyrillic", "string", "of", "characters", "to", "latin", "string", "of", "characters", ".", ":", "param", "string_to_transliterate", ":", "The", "cyrillic", "string", "to", "transliterate", "into", "latin", "characters", ".", ":", "para...
84dad6208759d1dc540161e28414026d0e2908f6
https://github.com/opendatakosovo/cyrillic-transliteration/blob/84dad6208759d1dc540161e28414026d0e2908f6/cyrtranslit/__init__.py#L17-L59
train
opendatakosovo/cyrillic-transliteration
cyrtranslit/__init__.py
to_cyrillic
def to_cyrillic(string_to_transliterate, lang_code='sr'): ''' Transliterate serbian latin string of characters to cyrillic string of characters. :param string_to_transliterate: The latin string to transliterate into cyrillic characters. :param lang_code: Indicates the cyrillic language code we are translati...
python
def to_cyrillic(string_to_transliterate, lang_code='sr'): ''' Transliterate serbian latin string of characters to cyrillic string of characters. :param string_to_transliterate: The latin string to transliterate into cyrillic characters. :param lang_code: Indicates the cyrillic language code we are translati...
[ "def", "to_cyrillic", "(", "string_to_transliterate", ",", "lang_code", "=", "'sr'", ")", ":", "# First check if we support the cyrillic alphabet we want to transliterate to latin.", "if", "lang_code", ".", "lower", "(", ")", "not", "in", "TRANSLIT_DICT", ":", "# If we don'...
Transliterate serbian latin string of characters to cyrillic string of characters. :param string_to_transliterate: The latin string to transliterate into cyrillic characters. :param lang_code: Indicates the cyrillic language code we are translating to. Defaults to Serbian (sr). :return: A string of cyrillic...
[ "Transliterate", "serbian", "latin", "string", "of", "characters", "to", "cyrillic", "string", "of", "characters", ".", ":", "param", "string_to_transliterate", ":", "The", "latin", "string", "to", "transliterate", "into", "cyrillic", "characters", ".", ":", "para...
84dad6208759d1dc540161e28414026d0e2908f6
https://github.com/opendatakosovo/cyrillic-transliteration/blob/84dad6208759d1dc540161e28414026d0e2908f6/cyrtranslit/__init__.py#L62-L137
train
jpadilla/django-rest-framework-xml
rest_framework_xml/parsers.py
XMLParser.parse
def parse(self, stream, media_type=None, parser_context=None): """ Parses the incoming bytestream as XML and returns the resulting data. """ assert etree, 'XMLParser requires defusedxml to be installed' parser_context = parser_context or {} encoding = parser_context.get(...
python
def parse(self, stream, media_type=None, parser_context=None): """ Parses the incoming bytestream as XML and returns the resulting data. """ assert etree, 'XMLParser requires defusedxml to be installed' parser_context = parser_context or {} encoding = parser_context.get(...
[ "def", "parse", "(", "self", ",", "stream", ",", "media_type", "=", "None", ",", "parser_context", "=", "None", ")", ":", "assert", "etree", ",", "'XMLParser requires defusedxml to be installed'", "parser_context", "=", "parser_context", "or", "{", "}", "encoding"...
Parses the incoming bytestream as XML and returns the resulting data.
[ "Parses", "the", "incoming", "bytestream", "as", "XML", "and", "returns", "the", "resulting", "data", "." ]
71c2f88b40c80ffd5029022147a57cc7341ef013
https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/parsers.py#L23-L38
train
jpadilla/django-rest-framework-xml
rest_framework_xml/parsers.py
XMLParser._xml_convert
def _xml_convert(self, element): """ convert the xml `element` into the corresponding python object """ children = list(element) if len(children) == 0: return self._type_convert(element.text) else: # if the fist child tag is list-item means all c...
python
def _xml_convert(self, element): """ convert the xml `element` into the corresponding python object """ children = list(element) if len(children) == 0: return self._type_convert(element.text) else: # if the fist child tag is list-item means all c...
[ "def", "_xml_convert", "(", "self", ",", "element", ")", ":", "children", "=", "list", "(", "element", ")", "if", "len", "(", "children", ")", "==", "0", ":", "return", "self", ".", "_type_convert", "(", "element", ".", "text", ")", "else", ":", "# i...
convert the xml `element` into the corresponding python object
[ "convert", "the", "xml", "element", "into", "the", "corresponding", "python", "object" ]
71c2f88b40c80ffd5029022147a57cc7341ef013
https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/parsers.py#L40-L60
train
jpadilla/django-rest-framework-xml
rest_framework_xml/parsers.py
XMLParser._type_convert
def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent Python type """ if value is None: return value try: return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S') except ValueError: ...
python
def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent Python type """ if value is None: return value try: return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S') except ValueError: ...
[ "def", "_type_convert", "(", "self", ",", "value", ")", ":", "if", "value", "is", "None", ":", "return", "value", "try", ":", "return", "datetime", ".", "datetime", ".", "strptime", "(", "value", ",", "'%Y-%m-%d %H:%M:%S'", ")", "except", "ValueError", ":"...
Converts the value returned by the XMl parse into the equivalent Python type
[ "Converts", "the", "value", "returned", "by", "the", "XMl", "parse", "into", "the", "equivalent", "Python", "type" ]
71c2f88b40c80ffd5029022147a57cc7341ef013
https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/parsers.py#L62-L85
train
jpadilla/django-rest-framework-xml
rest_framework_xml/renderers.py
XMLRenderer.render
def render(self, data, accepted_media_type=None, renderer_context=None): """ Renders `data` into serialized XML. """ if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() xml.startE...
python
def render(self, data, accepted_media_type=None, renderer_context=None): """ Renders `data` into serialized XML. """ if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() xml.startE...
[ "def", "render", "(", "self", ",", "data", ",", "accepted_media_type", "=", "None", ",", "renderer_context", "=", "None", ")", ":", "if", "data", "is", "None", ":", "return", "''", "stream", "=", "StringIO", "(", ")", "xml", "=", "SimplerXMLGenerator", "...
Renders `data` into serialized XML.
[ "Renders", "data", "into", "serialized", "XML", "." ]
71c2f88b40c80ffd5029022147a57cc7341ef013
https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/renderers.py#L24-L41
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.open
def open(self): """Open a connection to the device.""" device_type = 'cisco_ios' if self.transport == 'telnet': device_type = 'cisco_ios_telnet' self.device = ConnectHandler(device_type=device_type, host=self.hostname, ...
python
def open(self): """Open a connection to the device.""" device_type = 'cisco_ios' if self.transport == 'telnet': device_type = 'cisco_ios_telnet' self.device = ConnectHandler(device_type=device_type, host=self.hostname, ...
[ "def", "open", "(", "self", ")", ":", "device_type", "=", "'cisco_ios'", "if", "self", ".", "transport", "==", "'telnet'", ":", "device_type", "=", "'cisco_ios_telnet'", "self", ".", "device", "=", "ConnectHandler", "(", "device_type", "=", "device_type", ",",...
Open a connection to the device.
[ "Open", "a", "connection", "to", "the", "device", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L131-L142
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._create_tmp_file
def _create_tmp_file(config): """Write temp file and for use with inline config and SCP.""" tmp_dir = tempfile.gettempdir() rand_fname = py23_compat.text_type(uuid.uuid4()) filename = os.path.join(tmp_dir, rand_fname) with open(filename, 'wt') as fobj: fobj.write(conf...
python
def _create_tmp_file(config): """Write temp file and for use with inline config and SCP.""" tmp_dir = tempfile.gettempdir() rand_fname = py23_compat.text_type(uuid.uuid4()) filename = os.path.join(tmp_dir, rand_fname) with open(filename, 'wt') as fobj: fobj.write(conf...
[ "def", "_create_tmp_file", "(", "config", ")", ":", "tmp_dir", "=", "tempfile", ".", "gettempdir", "(", ")", "rand_fname", "=", "py23_compat", ".", "text_type", "(", "uuid", ".", "uuid4", "(", ")", ")", "filename", "=", "os", ".", "path", ".", "join", ...
Write temp file and for use with inline config and SCP.
[ "Write", "temp", "file", "and", "for", "use", "with", "inline", "config", "and", "SCP", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L201-L208
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._load_candidate_wrapper
def _load_candidate_wrapper(self, source_file=None, source_config=None, dest_file=None, file_system=None): """ Transfer file to remote device for either merge or replace operations Returns (return_status, msg) """ return_status = False msg...
python
def _load_candidate_wrapper(self, source_file=None, source_config=None, dest_file=None, file_system=None): """ Transfer file to remote device for either merge or replace operations Returns (return_status, msg) """ return_status = False msg...
[ "def", "_load_candidate_wrapper", "(", "self", ",", "source_file", "=", "None", ",", "source_config", "=", "None", ",", "dest_file", "=", "None", ",", "file_system", "=", "None", ")", ":", "return_status", "=", "False", "msg", "=", "''", "if", "source_file",...
Transfer file to remote device for either merge or replace operations Returns (return_status, msg)
[ "Transfer", "file", "to", "remote", "device", "for", "either", "merge", "or", "replace", "operations" ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L210-L245
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.load_replace_candidate
def load_replace_candidate(self, filename=None, config=None): """ SCP file to device filesystem, defaults to candidate_config. Return None or raise exception """ self.config_replace = True return_status, msg = self._load_candidate_wrapper(source_file=filename, ...
python
def load_replace_candidate(self, filename=None, config=None): """ SCP file to device filesystem, defaults to candidate_config. Return None or raise exception """ self.config_replace = True return_status, msg = self._load_candidate_wrapper(source_file=filename, ...
[ "def", "load_replace_candidate", "(", "self", ",", "filename", "=", "None", ",", "config", "=", "None", ")", ":", "self", ".", "config_replace", "=", "True", "return_status", ",", "msg", "=", "self", ".", "_load_candidate_wrapper", "(", "source_file", "=", "...
SCP file to device filesystem, defaults to candidate_config. Return None or raise exception
[ "SCP", "file", "to", "device", "filesystem", "defaults", "to", "candidate_config", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L247-L259
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.load_merge_candidate
def load_merge_candidate(self, filename=None, config=None): """ SCP file to remote device. Merge configuration in: copy <file> running-config """ self.config_replace = False return_status, msg = self._load_candidate_wrapper(source_file=filename, ...
python
def load_merge_candidate(self, filename=None, config=None): """ SCP file to remote device. Merge configuration in: copy <file> running-config """ self.config_replace = False return_status, msg = self._load_candidate_wrapper(source_file=filename, ...
[ "def", "load_merge_candidate", "(", "self", ",", "filename", "=", "None", ",", "config", "=", "None", ")", ":", "self", ".", "config_replace", "=", "False", "return_status", ",", "msg", "=", "self", ".", "_load_candidate_wrapper", "(", "source_file", "=", "f...
SCP file to remote device. Merge configuration in: copy <file> running-config
[ "SCP", "file", "to", "remote", "device", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L261-L273
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._commit_hostname_handler
def _commit_hostname_handler(self, cmd): """Special handler for hostname change on commit operation.""" current_prompt = self.device.find_prompt().strip() terminating_char = current_prompt[-1] pattern = r"[>#{}]\s*$".format(terminating_char) # Look exclusively for trailing patter...
python
def _commit_hostname_handler(self, cmd): """Special handler for hostname change on commit operation.""" current_prompt = self.device.find_prompt().strip() terminating_char = current_prompt[-1] pattern = r"[>#{}]\s*$".format(terminating_char) # Look exclusively for trailing patter...
[ "def", "_commit_hostname_handler", "(", "self", ",", "cmd", ")", ":", "current_prompt", "=", "self", ".", "device", ".", "find_prompt", "(", ")", ".", "strip", "(", ")", "terminating_char", "=", "current_prompt", "[", "-", "1", "]", "pattern", "=", "r\"[>#...
Special handler for hostname change on commit operation.
[ "Special", "handler", "for", "hostname", "change", "on", "commit", "operation", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L378-L387
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.commit_config
def commit_config(self): """ If replacement operation, perform 'configure replace' for the entire config. If merge operation, perform copy <file> running-config. """ # Always generate a rollback config on commit self._gen_rollback_cfg() if self.config_replace: ...
python
def commit_config(self): """ If replacement operation, perform 'configure replace' for the entire config. If merge operation, perform copy <file> running-config. """ # Always generate a rollback config on commit self._gen_rollback_cfg() if self.config_replace: ...
[ "def", "commit_config", "(", "self", ")", ":", "# Always generate a rollback config on commit", "self", ".", "_gen_rollback_cfg", "(", ")", "if", "self", ".", "config_replace", ":", "# Replace operation", "filename", "=", "self", ".", "candidate_cfg", "cfg_file", "=",...
If replacement operation, perform 'configure replace' for the entire config. If merge operation, perform copy <file> running-config.
[ "If", "replacement", "operation", "perform", "configure", "replace", "for", "the", "entire", "config", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L389-L434
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.discard_config
def discard_config(self): """Set candidate_cfg to current running-config. Erase the merge_cfg file.""" discard_candidate = 'copy running-config {}'.format(self._gen_full_path(self.candidate_cfg)) discard_merge = 'copy null: {}'.format(self._gen_full_path(self.merge_cfg)) self._disable_co...
python
def discard_config(self): """Set candidate_cfg to current running-config. Erase the merge_cfg file.""" discard_candidate = 'copy running-config {}'.format(self._gen_full_path(self.candidate_cfg)) discard_merge = 'copy null: {}'.format(self._gen_full_path(self.merge_cfg)) self._disable_co...
[ "def", "discard_config", "(", "self", ")", ":", "discard_candidate", "=", "'copy running-config {}'", ".", "format", "(", "self", ".", "_gen_full_path", "(", "self", ".", "candidate_cfg", ")", ")", "discard_merge", "=", "'copy null: {}'", ".", "format", "(", "se...
Set candidate_cfg to current running-config. Erase the merge_cfg file.
[ "Set", "candidate_cfg", "to", "current", "running", "-", "config", ".", "Erase", "the", "merge_cfg", "file", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L436-L443
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._xfer_file
def _xfer_file(self, source_file=None, source_config=None, dest_file=None, file_system=None, TransferClass=FileTransfer): """Transfer file to remote device. By default, this will use Secure Copy if self.inline_transfer is set, then will use Netmiko InlineTransfer method to tr...
python
def _xfer_file(self, source_file=None, source_config=None, dest_file=None, file_system=None, TransferClass=FileTransfer): """Transfer file to remote device. By default, this will use Secure Copy if self.inline_transfer is set, then will use Netmiko InlineTransfer method to tr...
[ "def", "_xfer_file", "(", "self", ",", "source_file", "=", "None", ",", "source_config", "=", "None", ",", "dest_file", "=", "None", ",", "file_system", "=", "None", ",", "TransferClass", "=", "FileTransfer", ")", ":", "if", "not", "source_file", "and", "n...
Transfer file to remote device. By default, this will use Secure Copy if self.inline_transfer is set, then will use Netmiko InlineTransfer method to transfer inline using either SSH or telnet (plus TCL onbox). Return (status, msg) status = boolean msg = details on what ...
[ "Transfer", "file", "to", "remote", "device", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L485-L534
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._gen_full_path
def _gen_full_path(self, filename, file_system=None): """Generate full file path on remote device.""" if file_system is None: return '{}/{}'.format(self.dest_file_system, filename) else: if ":" not in file_system: raise ValueError("Invalid file_system spec...
python
def _gen_full_path(self, filename, file_system=None): """Generate full file path on remote device.""" if file_system is None: return '{}/{}'.format(self.dest_file_system, filename) else: if ":" not in file_system: raise ValueError("Invalid file_system spec...
[ "def", "_gen_full_path", "(", "self", ",", "filename", ",", "file_system", "=", "None", ")", ":", "if", "file_system", "is", "None", ":", "return", "'{}/{}'", ".", "format", "(", "self", ".", "dest_file_system", ",", "filename", ")", "else", ":", "if", "...
Generate full file path on remote device.
[ "Generate", "full", "file", "path", "on", "remote", "device", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L546-L553
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._gen_rollback_cfg
def _gen_rollback_cfg(self): """Save a configuration that can be used for rollback.""" cfg_file = self._gen_full_path(self.rollback_cfg) cmd = 'copy running-config {}'.format(cfg_file) self._disable_confirm() self.device.send_command_expect(cmd) self._enable_confirm()
python
def _gen_rollback_cfg(self): """Save a configuration that can be used for rollback.""" cfg_file = self._gen_full_path(self.rollback_cfg) cmd = 'copy running-config {}'.format(cfg_file) self._disable_confirm() self.device.send_command_expect(cmd) self._enable_confirm()
[ "def", "_gen_rollback_cfg", "(", "self", ")", ":", "cfg_file", "=", "self", ".", "_gen_full_path", "(", "self", ".", "rollback_cfg", ")", "cmd", "=", "'copy running-config {}'", ".", "format", "(", "cfg_file", ")", "self", ".", "_disable_confirm", "(", ")", ...
Save a configuration that can be used for rollback.
[ "Save", "a", "configuration", "that", "can", "be", "used", "for", "rollback", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L555-L561
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._check_file_exists
def _check_file_exists(self, cfg_file): """ Check that the file exists on remote device using full path. cfg_file is full path i.e. flash:/file_name For example # dir flash:/candidate_config.txt Directory of flash:/candidate_config.txt 33 -rw- 5592 Dec...
python
def _check_file_exists(self, cfg_file): """ Check that the file exists on remote device using full path. cfg_file is full path i.e. flash:/file_name For example # dir flash:/candidate_config.txt Directory of flash:/candidate_config.txt 33 -rw- 5592 Dec...
[ "def", "_check_file_exists", "(", "self", ",", "cfg_file", ")", ":", "cmd", "=", "'dir {}'", ".", "format", "(", "cfg_file", ")", "success_pattern", "=", "'Directory of {}'", ".", "format", "(", "cfg_file", ")", "output", "=", "self", ".", "device", ".", "...
Check that the file exists on remote device using full path. cfg_file is full path i.e. flash:/file_name For example # dir flash:/candidate_config.txt Directory of flash:/candidate_config.txt 33 -rw- 5592 Dec 18 2015 10:50:22 -08:00 candidate_config.txt retu...
[ "Check", "that", "the", "file", "exists", "on", "remote", "device", "using", "full", "path", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L563-L584
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver._expand_interface_name
def _expand_interface_name(self, interface_brief): """ Obtain the full interface name from the abbreviated name. Cache mappings in self.interface_map. """ if self.interface_map.get(interface_brief): return self.interface_map.get(interface_brief) command = 'sh...
python
def _expand_interface_name(self, interface_brief): """ Obtain the full interface name from the abbreviated name. Cache mappings in self.interface_map. """ if self.interface_map.get(interface_brief): return self.interface_map.get(interface_brief) command = 'sh...
[ "def", "_expand_interface_name", "(", "self", ",", "interface_brief", ")", ":", "if", "self", ".", "interface_map", ".", "get", "(", "interface_brief", ")", ":", "return", "self", ".", "interface_map", ".", "get", "(", "interface_brief", ")", "command", "=", ...
Obtain the full interface name from the abbreviated name. Cache mappings in self.interface_map.
[ "Obtain", "the", "full", "interface", "name", "from", "the", "abbreviated", "name", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L586-L602
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_lldp_neighbors
def get_lldp_neighbors(self): """IOS implementation of get_lldp_neighbors.""" lldp = {} command = 'show lldp neighbors' output = self._send_command(command) # Check if router supports the command if '% Invalid input' in output: return {} # Process th...
python
def get_lldp_neighbors(self): """IOS implementation of get_lldp_neighbors.""" lldp = {} command = 'show lldp neighbors' output = self._send_command(command) # Check if router supports the command if '% Invalid input' in output: return {} # Process th...
[ "def", "get_lldp_neighbors", "(", "self", ")", ":", "lldp", "=", "{", "}", "command", "=", "'show lldp neighbors'", "output", "=", "self", ".", "_send_command", "(", "command", ")", "# Check if router supports the command", "if", "'% Invalid input'", "in", "output",...
IOS implementation of get_lldp_neighbors.
[ "IOS", "implementation", "of", "get_lldp_neighbors", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L690-L738
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_lldp_neighbors_detail
def get_lldp_neighbors_detail(self, interface=''): """ IOS implementation of get_lldp_neighbors_detail. Calls get_lldp_neighbors. """ lldp = {} lldp_neighbors = self.get_lldp_neighbors() # Filter to specific interface if interface: lldp_data ...
python
def get_lldp_neighbors_detail(self, interface=''): """ IOS implementation of get_lldp_neighbors_detail. Calls get_lldp_neighbors. """ lldp = {} lldp_neighbors = self.get_lldp_neighbors() # Filter to specific interface if interface: lldp_data ...
[ "def", "get_lldp_neighbors_detail", "(", "self", ",", "interface", "=", "''", ")", ":", "lldp", "=", "{", "}", "lldp_neighbors", "=", "self", ".", "get_lldp_neighbors", "(", ")", "# Filter to specific interface", "if", "interface", ":", "lldp_data", "=", "lldp_n...
IOS implementation of get_lldp_neighbors_detail. Calls get_lldp_neighbors.
[ "IOS", "implementation", "of", "get_lldp_neighbors_detail", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L773-L828
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_facts
def get_facts(self): """Return a set of facts from the devices.""" # default values. vendor = u'Cisco' uptime = -1 serial_number, fqdn, os_version, hostname, domain_name = ('Unknown',) * 5 # obtain output from device show_ver = self._send_command('show version') ...
python
def get_facts(self): """Return a set of facts from the devices.""" # default values. vendor = u'Cisco' uptime = -1 serial_number, fqdn, os_version, hostname, domain_name = ('Unknown',) * 5 # obtain output from device show_ver = self._send_command('show version') ...
[ "def", "get_facts", "(", "self", ")", ":", "# default values.", "vendor", "=", "u'Cisco'", "uptime", "=", "-", "1", "serial_number", ",", "fqdn", ",", "os_version", ",", "hostname", ",", "domain_name", "=", "(", "'Unknown'", ",", ")", "*", "5", "# obtain o...
Return a set of facts from the devices.
[ "Return", "a", "set", "of", "facts", "from", "the", "devices", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L858-L926
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_interfaces
def get_interfaces(self): """ Get interface details. last_flapped is not implemented Example Output: { u'Vlan1': { 'description': u'N/A', 'is_enabled': True, 'is_up': True, 'last_flapped': -1.0, ...
python
def get_interfaces(self): """ Get interface details. last_flapped is not implemented Example Output: { u'Vlan1': { 'description': u'N/A', 'is_enabled': True, 'is_up': True, 'last_flapped': -1.0, ...
[ "def", "get_interfaces", "(", "self", ")", ":", "# default values.", "last_flapped", "=", "-", "1.0", "command", "=", "'show interfaces'", "output", "=", "self", ".", "_send_command", "(", "command", ")", "interface", "=", "description", "=", "mac_address", "=",...
Get interface details. last_flapped is not implemented Example Output: { u'Vlan1': { 'description': u'N/A', 'is_enabled': True, 'is_up': True, 'last_flapped': -1.0, 'mac_address': u'a493.4cc1.67a7', ...
[ "Get", "interface", "details", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L928-L1023
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_interfaces_ip
def get_interfaces_ip(self): """ Get interface ip details. Returns a dict of dicts Example Output: { u'FastEthernet8': { 'ipv4': { u'10.66.43.169': { 'prefix_length': 22}}}, u'Loopback555': { 'ipv4': { u'192.168.1.1': { 'prefix_length': 24}}, ...
python
def get_interfaces_ip(self): """ Get interface ip details. Returns a dict of dicts Example Output: { u'FastEthernet8': { 'ipv4': { u'10.66.43.169': { 'prefix_length': 22}}}, u'Loopback555': { 'ipv4': { u'192.168.1.1': { 'prefix_length': 24}}, ...
[ "def", "get_interfaces_ip", "(", "self", ")", ":", "interfaces", "=", "{", "}", "command", "=", "'show ip interface'", "show_ip_interface", "=", "self", ".", "_send_command", "(", "command", ")", "command", "=", "'show ipv6 interface'", "show_ipv6_interface", "=", ...
Get interface ip details. Returns a dict of dicts Example Output: { u'FastEthernet8': { 'ipv4': { u'10.66.43.169': { 'prefix_length': 22}}}, u'Loopback555': { 'ipv4': { u'192.168.1.1': { 'prefix_length': 24}}, 'ipv6': { u'1::1': { ...
[ "Get", "interface", "ip", "details", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1025-L1091
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.bgp_time_conversion
def bgp_time_conversion(bgp_uptime): """ Convert string time to seconds. Examples 00:14:23 00:13:40 00:00:21 00:00:13 00:00:49 1d11h 1d17h 1w0d 8w5d 1y28w never """ bgp_uptime = bgp_uptime.st...
python
def bgp_time_conversion(bgp_uptime): """ Convert string time to seconds. Examples 00:14:23 00:13:40 00:00:21 00:00:13 00:00:49 1d11h 1d17h 1w0d 8w5d 1y28w never """ bgp_uptime = bgp_uptime.st...
[ "def", "bgp_time_conversion", "(", "bgp_uptime", ")", ":", "bgp_uptime", "=", "bgp_uptime", ".", "strip", "(", ")", "uptime_letters", "=", "set", "(", "[", "'w'", ",", "'h'", ",", "'d'", "]", ")", "if", "'never'", "in", "bgp_uptime", ":", "return", "-", ...
Convert string time to seconds. Examples 00:14:23 00:13:40 00:00:21 00:00:13 00:00:49 1d11h 1d17h 1w0d 8w5d 1y28w never
[ "Convert", "string", "time", "to", "seconds", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1094-L1141
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_bgp_neighbors
def get_bgp_neighbors(self): """BGP neighbor information. Currently no VRF support. Supports both IPv4 and IPv6. """ supported_afi = ['ipv4', 'ipv6'] bgp_neighbor_data = dict() bgp_neighbor_data['global'] = {} # get summary output from device cmd_bgp_al...
python
def get_bgp_neighbors(self): """BGP neighbor information. Currently no VRF support. Supports both IPv4 and IPv6. """ supported_afi = ['ipv4', 'ipv6'] bgp_neighbor_data = dict() bgp_neighbor_data['global'] = {} # get summary output from device cmd_bgp_al...
[ "def", "get_bgp_neighbors", "(", "self", ")", ":", "supported_afi", "=", "[", "'ipv4'", ",", "'ipv6'", "]", "bgp_neighbor_data", "=", "dict", "(", ")", "bgp_neighbor_data", "[", "'global'", "]", "=", "{", "}", "# get summary output from device", "cmd_bgp_all_sum",...
BGP neighbor information. Currently no VRF support. Supports both IPv4 and IPv6.
[ "BGP", "neighbor", "information", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1143-L1419
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_environment
def get_environment(self): """ Get environment facts. power and fan are currently not implemented cpu is using 1-minute average cpu hard-coded to cpu0 (i.e. only a single CPU) """ environment = {} cpu_cmd = 'show proc cpu' mem_cmd = 'show memory s...
python
def get_environment(self): """ Get environment facts. power and fan are currently not implemented cpu is using 1-minute average cpu hard-coded to cpu0 (i.e. only a single CPU) """ environment = {} cpu_cmd = 'show proc cpu' mem_cmd = 'show memory s...
[ "def", "get_environment", "(", "self", ")", ":", "environment", "=", "{", "}", "cpu_cmd", "=", "'show proc cpu'", "mem_cmd", "=", "'show memory statistics'", "temp_cmd", "=", "'show env temperature status'", "output", "=", "self", ".", "_send_command", "(", "cpu_cmd...
Get environment facts. power and fan are currently not implemented cpu is using 1-minute average cpu hard-coded to cpu0 (i.e. only a single CPU)
[ "Get", "environment", "facts", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1520-L1581
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_arp_table
def get_arp_table(self): """ Get arp table information. Return a list of dictionaries having the following set of keys: * interface (string) * mac (string) * ip (string) * age (float) For example:: [ { ...
python
def get_arp_table(self): """ Get arp table information. Return a list of dictionaries having the following set of keys: * interface (string) * mac (string) * ip (string) * age (float) For example:: [ { ...
[ "def", "get_arp_table", "(", "self", ")", ":", "arp_table", "=", "[", "]", "command", "=", "'show arp | exclude Incomplete'", "output", "=", "self", ".", "_send_command", "(", "command", ")", "# Skip the first line which is a header", "output", "=", "output", ".", ...
Get arp table information. Return a list of dictionaries having the following set of keys: * interface (string) * mac (string) * ip (string) * age (float) For example:: [ { 'interface' : 'MgmtEth0/RSP0/CPU0...
[ "Get", "arp", "table", "information", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1583-L1650
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.cli
def cli(self, commands): """ Execute a list of commands and return the output in a dictionary format using the command as the key. Example input: ['show clock', 'show calendar'] Output example: { 'show calendar': u'22:02:01 UTC Thu Feb 18 2016', 's...
python
def cli(self, commands): """ Execute a list of commands and return the output in a dictionary format using the command as the key. Example input: ['show clock', 'show calendar'] Output example: { 'show calendar': u'22:02:01 UTC Thu Feb 18 2016', 's...
[ "def", "cli", "(", "self", ",", "commands", ")", ":", "cli_output", "=", "dict", "(", ")", "if", "type", "(", "commands", ")", "is", "not", "list", ":", "raise", "TypeError", "(", "'Please enter a valid list of commands!'", ")", "for", "command", "in", "co...
Execute a list of commands and return the output in a dictionary format using the command as the key. Example input: ['show clock', 'show calendar'] Output example: { 'show calendar': u'22:02:01 UTC Thu Feb 18 2016', 'show clock': u'*22:01:51.165 UTC Thu Feb 18 20...
[ "Execute", "a", "list", "of", "commands", "and", "return", "the", "output", "in", "a", "dictionary", "format", "using", "the", "command", "as", "the", "key", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1652-L1676
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_mac_address_table
def get_mac_address_table(self): """ Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address Table, having the following keys * mac (string) * interface (string) * vlan (int) * active (boolean) * static (...
python
def get_mac_address_table(self): """ Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address Table, having the following keys * mac (string) * interface (string) * vlan (int) * active (boolean) * static (...
[ "def", "get_mac_address_table", "(", "self", ")", ":", "RE_MACTABLE_DEFAULT", "=", "r\"^\"", "+", "MAC_REGEX", "RE_MACTABLE_6500_1", "=", "r\"^\\*\\s+{}\\s+{}\\s+\"", ".", "format", "(", "VLAN_REGEX", ",", "MAC_REGEX", ")", "# 7 fields", "RE_MACTABLE_6500_2", "=", "r\...
Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address Table, having the following keys * mac (string) * interface (string) * vlan (int) * active (boolean) * static (boolean) * moves (int) * last...
[ "Returns", "a", "lists", "of", "dictionaries", ".", "Each", "dictionary", "represents", "an", "entry", "in", "the", "MAC", "Address", "Table", "having", "the", "following", "keys", "*", "mac", "(", "string", ")", "*", "interface", "(", "string", ")", "*", ...
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1742-L1903
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.traceroute
def traceroute(self, destination, source=C.TRACEROUTE_SOURCE, ttl=C.TRACEROUTE_TTL, timeout=C.TRACEROUTE_TIMEOUT, vrf=C.TRACEROUTE_VRF): """ Executes traceroute on the device and returns a dictionary with the result. :param destination: Host or IP Address of the destination ...
python
def traceroute(self, destination, source=C.TRACEROUTE_SOURCE, ttl=C.TRACEROUTE_TTL, timeout=C.TRACEROUTE_TIMEOUT, vrf=C.TRACEROUTE_VRF): """ Executes traceroute on the device and returns a dictionary with the result. :param destination: Host or IP Address of the destination ...
[ "def", "traceroute", "(", "self", ",", "destination", ",", "source", "=", "C", ".", "TRACEROUTE_SOURCE", ",", "ttl", "=", "C", ".", "TRACEROUTE_TTL", ",", "timeout", "=", "C", ".", "TRACEROUTE_TIMEOUT", ",", "vrf", "=", "C", ".", "TRACEROUTE_VRF", ")", "...
Executes traceroute on the device and returns a dictionary with the result. :param destination: Host or IP Address of the destination :param source (optional): Use a specific IP Address to execute the traceroute :param ttl (optional): Maimum number of hops -> int (0-255) :param timeout ...
[ "Executes", "traceroute", "on", "the", "device", "and", "returns", "a", "dictionary", "with", "the", "result", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L2033-L2147
train
napalm-automation/napalm-ios
napalm_ios/ios.py
IOSDriver.get_config
def get_config(self, retrieve='all'): """Implementation of get_config for IOS. Returns the startup or/and running configuration as dictionary. The keys of the dictionary represent the type of configuration (startup or running). The candidate is always empty string, since IOS doe...
python
def get_config(self, retrieve='all'): """Implementation of get_config for IOS. Returns the startup or/and running configuration as dictionary. The keys of the dictionary represent the type of configuration (startup or running). The candidate is always empty string, since IOS doe...
[ "def", "get_config", "(", "self", ",", "retrieve", "=", "'all'", ")", ":", "configs", "=", "{", "'startup'", ":", "''", ",", "'running'", ":", "''", ",", "'candidate'", ":", "''", ",", "}", "if", "retrieve", "in", "(", "'startup'", ",", "'all'", ")",...
Implementation of get_config for IOS. Returns the startup or/and running configuration as dictionary. The keys of the dictionary represent the type of configuration (startup or running). The candidate is always empty string, since IOS does not support candidate configuration.
[ "Implementation", "of", "get_config", "for", "IOS", "." ]
7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81
https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L2149-L2174
train
adafruit/Adafruit_Python_ADXL345
Adafruit_ADXL345/ADXL345.py
ADXL345.set_range
def set_range(self, value): """Set the range of the accelerometer to the provided value. Range value should be one of these constants: - ADXL345_RANGE_2_G = +/-2G - ADXL345_RANGE_4_G = +/-4G - ADXL345_RANGE_8_G = +/-8G - ADXL345_RANGE_16_G = +/-16G ...
python
def set_range(self, value): """Set the range of the accelerometer to the provided value. Range value should be one of these constants: - ADXL345_RANGE_2_G = +/-2G - ADXL345_RANGE_4_G = +/-4G - ADXL345_RANGE_8_G = +/-8G - ADXL345_RANGE_16_G = +/-16G ...
[ "def", "set_range", "(", "self", ",", "value", ")", ":", "# Read the data format register to preserve bits. Update the data", "# rate, make sure that the FULL-RES bit is enabled for range scaling", "format_reg", "=", "self", ".", "_device", ".", "readU8", "(", "ADXL345_REG_DATA_...
Set the range of the accelerometer to the provided value. Range value should be one of these constants: - ADXL345_RANGE_2_G = +/-2G - ADXL345_RANGE_4_G = +/-4G - ADXL345_RANGE_8_G = +/-8G - ADXL345_RANGE_16_G = +/-16G
[ "Set", "the", "range", "of", "the", "accelerometer", "to", "the", "provided", "value", ".", "Range", "value", "should", "be", "one", "of", "these", "constants", ":", "-", "ADXL345_RANGE_2_G", "=", "+", "/", "-", "2G", "-", "ADXL345_RANGE_4_G", "=", "+", ...
d897bcaa16b5fe365463ae0c2791d0c155becd05
https://github.com/adafruit/Adafruit_Python_ADXL345/blob/d897bcaa16b5fe365463ae0c2791d0c155becd05/Adafruit_ADXL345/ADXL345.py#L70-L84
train
adafruit/Adafruit_Python_ADXL345
Adafruit_ADXL345/ADXL345.py
ADXL345.read
def read(self): """Read the current value of the accelerometer and return it as a tuple of signed 16-bit X, Y, Z axis values. """ raw = self._device.readList(ADXL345_REG_DATAX0, 6) return struct.unpack('<hhh', raw)
python
def read(self): """Read the current value of the accelerometer and return it as a tuple of signed 16-bit X, Y, Z axis values. """ raw = self._device.readList(ADXL345_REG_DATAX0, 6) return struct.unpack('<hhh', raw)
[ "def", "read", "(", "self", ")", ":", "raw", "=", "self", ".", "_device", ".", "readList", "(", "ADXL345_REG_DATAX0", ",", "6", ")", "return", "struct", ".", "unpack", "(", "'<hhh'", ",", "raw", ")" ]
Read the current value of the accelerometer and return it as a tuple of signed 16-bit X, Y, Z axis values.
[ "Read", "the", "current", "value", "of", "the", "accelerometer", "and", "return", "it", "as", "a", "tuple", "of", "signed", "16", "-", "bit", "X", "Y", "Z", "axis", "values", "." ]
d897bcaa16b5fe365463ae0c2791d0c155becd05
https://github.com/adafruit/Adafruit_Python_ADXL345/blob/d897bcaa16b5fe365463ae0c2791d0c155becd05/Adafruit_ADXL345/ADXL345.py#L122-L127
train
piface/pifacedigitalio
pifacedigitalio/core.py
deinit
def deinit(bus=DEFAULT_SPI_BUS, chip_select=DEFAULT_SPI_CHIP_SELECT): """Stops interrupts on all boards. Only required when using :func:`digital_read` and :func:`digital_write`. :param bus: SPI bus /dev/spidev<bus>.<chipselect> (default: {bus}) :type bus: int :param chip_select: SPI chip...
python
def deinit(bus=DEFAULT_SPI_BUS, chip_select=DEFAULT_SPI_CHIP_SELECT): """Stops interrupts on all boards. Only required when using :func:`digital_read` and :func:`digital_write`. :param bus: SPI bus /dev/spidev<bus>.<chipselect> (default: {bus}) :type bus: int :param chip_select: SPI chip...
[ "def", "deinit", "(", "bus", "=", "DEFAULT_SPI_BUS", ",", "chip_select", "=", "DEFAULT_SPI_CHIP_SELECT", ")", ":", "global", "_pifacedigitals", "for", "pfd", "in", "_pifacedigitals", ":", "try", ":", "pfd", ".", "deinit_board", "(", ")", "except", "AttributeErro...
Stops interrupts on all boards. Only required when using :func:`digital_read` and :func:`digital_write`. :param bus: SPI bus /dev/spidev<bus>.<chipselect> (default: {bus}) :type bus: int :param chip_select: SPI chip select /dev/spidev<bus>.<chipselect> (default: {chip}) :type chip_select: i...
[ "Stops", "interrupts", "on", "all", "boards", ".", "Only", "required", "when", "using", ":", "func", ":", "digital_read", "and", ":", "func", ":", "digital_write", "." ]
d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4
https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/pifacedigitalio/core.py#L176-L192
train
piface/pifacedigitalio
pifacedigitalio/core.py
digital_write
def digital_write(pin_num, value, hardware_addr=0): """Writes the value to the input pin specified. .. note:: This function is for familiarality with users of other types of IO board. Consider accessing the ``output_pins`` attribute of a PiFaceDigital object: >>> pfd = PiFaceDigital(hardw...
python
def digital_write(pin_num, value, hardware_addr=0): """Writes the value to the input pin specified. .. note:: This function is for familiarality with users of other types of IO board. Consider accessing the ``output_pins`` attribute of a PiFaceDigital object: >>> pfd = PiFaceDigital(hardw...
[ "def", "digital_write", "(", "pin_num", ",", "value", ",", "hardware_addr", "=", "0", ")", ":", "_get_pifacedigital", "(", "hardware_addr", ")", ".", "output_pins", "[", "pin_num", "]", ".", "value", "=", "value" ]
Writes the value to the input pin specified. .. note:: This function is for familiarality with users of other types of IO board. Consider accessing the ``output_pins`` attribute of a PiFaceDigital object: >>> pfd = PiFaceDigital(hardware_addr) >>> pfd.output_pins[pin_num].value = 1 ...
[ "Writes", "the", "value", "to", "the", "input", "pin", "specified", "." ]
d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4
https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/pifacedigitalio/core.py#L216-L233
train
piface/pifacedigitalio
pifacedigitalio/core.py
digital_write_pullup
def digital_write_pullup(pin_num, value, hardware_addr=0): """Writes the value to the input pullup specified. .. note:: This function is for familiarality with users of other types of IO board. Consider accessing the ``gppub`` attribute of a PiFaceDigital object: >>> pfd = PiFaceDigital(h...
python
def digital_write_pullup(pin_num, value, hardware_addr=0): """Writes the value to the input pullup specified. .. note:: This function is for familiarality with users of other types of IO board. Consider accessing the ``gppub`` attribute of a PiFaceDigital object: >>> pfd = PiFaceDigital(h...
[ "def", "digital_write_pullup", "(", "pin_num", ",", "value", ",", "hardware_addr", "=", "0", ")", ":", "_get_pifacedigital", "(", "hardware_addr", ")", ".", "gppub", ".", "bits", "[", "pin_num", "]", ".", "value", "=", "value" ]
Writes the value to the input pullup specified. .. note:: This function is for familiarality with users of other types of IO board. Consider accessing the ``gppub`` attribute of a PiFaceDigital object: >>> pfd = PiFaceDigital(hardware_addr) >>> hex(pfd.gppub.value) 0xff >...
[ "Writes", "the", "value", "to", "the", "input", "pullup", "specified", "." ]
d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4
https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/pifacedigitalio/core.py#L258-L277
train
piface/pifacedigitalio
examples/simplewebcontrol.py
get_my_ip
def get_my_ip(): """Returns this computers IP address as a string.""" ip = subprocess.check_output(GET_IP_CMD, shell=True).decode('utf-8')[:-1] return ip.strip()
python
def get_my_ip(): """Returns this computers IP address as a string.""" ip = subprocess.check_output(GET_IP_CMD, shell=True).decode('utf-8')[:-1] return ip.strip()
[ "def", "get_my_ip", "(", ")", ":", "ip", "=", "subprocess", ".", "check_output", "(", "GET_IP_CMD", ",", "shell", "=", "True", ")", ".", "decode", "(", "'utf-8'", ")", "[", ":", "-", "1", "]", "return", "ip", ".", "strip", "(", ")" ]
Returns this computers IP address as a string.
[ "Returns", "this", "computers", "IP", "address", "as", "a", "string", "." ]
d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4
https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/examples/simplewebcontrol.py#L72-L75
train
piface/pifacedigitalio
examples/simplewebcontrol.py
PiFaceWebHandler.set_output_port
def set_output_port(self, new_value, old_value=0): """Sets the output port value to new_value, defaults to old_value.""" print("Setting output port to {}.".format(new_value)) port_value = old_value try: port_value = int(new_value) # dec except ValueError: ...
python
def set_output_port(self, new_value, old_value=0): """Sets the output port value to new_value, defaults to old_value.""" print("Setting output port to {}.".format(new_value)) port_value = old_value try: port_value = int(new_value) # dec except ValueError: ...
[ "def", "set_output_port", "(", "self", ",", "new_value", ",", "old_value", "=", "0", ")", ":", "print", "(", "\"Setting output port to {}.\"", ".", "format", "(", "new_value", ")", ")", "port_value", "=", "old_value", "try", ":", "port_value", "=", "int", "(...
Sets the output port value to new_value, defaults to old_value.
[ "Sets", "the", "output", "port", "value", "to", "new_value", "defaults", "to", "old_value", "." ]
d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4
https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/examples/simplewebcontrol.py#L59-L69
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper._request_api
def _request_api(self, **kwargs): """Wrap the calls the url, with the given arguments. :param str url: Url to call with the given arguments :param str method: [POST | GET] Method to use on the request :param int status: Expected status code """ _url = kwargs.get('url') ...
python
def _request_api(self, **kwargs): """Wrap the calls the url, with the given arguments. :param str url: Url to call with the given arguments :param str method: [POST | GET] Method to use on the request :param int status: Expected status code """ _url = kwargs.get('url') ...
[ "def", "_request_api", "(", "self", ",", "*", "*", "kwargs", ")", ":", "_url", "=", "kwargs", ".", "get", "(", "'url'", ")", "_method", "=", "kwargs", ".", "get", "(", "'method'", ",", "'GET'", ")", "_status", "=", "kwargs", ".", "get", "(", "'stat...
Wrap the calls the url, with the given arguments. :param str url: Url to call with the given arguments :param str method: [POST | GET] Method to use on the request :param int status: Expected status code
[ "Wrap", "the", "calls", "the", "url", "with", "the", "given", "arguments", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L119-L147
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_infos_with_id
def get_infos_with_id(self, uid): """Get info about a user based on his id. :return: JSON """ _logid = uid _user_info_url = USER_INFO_URL.format(logid=_logid) return self._request_api(url=_user_info_url).json()
python
def get_infos_with_id(self, uid): """Get info about a user based on his id. :return: JSON """ _logid = uid _user_info_url = USER_INFO_URL.format(logid=_logid) return self._request_api(url=_user_info_url).json()
[ "def", "get_infos_with_id", "(", "self", ",", "uid", ")", ":", "_logid", "=", "uid", "_user_info_url", "=", "USER_INFO_URL", ".", "format", "(", "logid", "=", "_logid", ")", "return", "self", ".", "_request_api", "(", "url", "=", "_user_info_url", ")", "."...
Get info about a user based on his id. :return: JSON
[ "Get", "info", "about", "a", "user", "based", "on", "his", "id", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L157-L165
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_current_activities
def get_current_activities(self, login=None, **kwargs): """Get the current activities of user. Either use the `login` param, or the client's login if unset. :return: JSON """ _login = kwargs.get( 'login', login or self._login ) _activity_...
python
def get_current_activities(self, login=None, **kwargs): """Get the current activities of user. Either use the `login` param, or the client's login if unset. :return: JSON """ _login = kwargs.get( 'login', login or self._login ) _activity_...
[ "def", "get_current_activities", "(", "self", ",", "login", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", "or", "self", ".", "_login", ")", "_activity_url", "=", "ACTIVITY_URL", ".", ...
Get the current activities of user. Either use the `login` param, or the client's login if unset. :return: JSON
[ "Get", "the", "current", "activities", "of", "user", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L175-L187
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_notifications
def get_notifications(self, login=None, **kwargs): """Get the current notifications of a user. :return: JSON """ _login = kwargs.get( 'login', login or self._login ) _notif_url = NOTIF_URL.format(login=_login) return self._request_api(url...
python
def get_notifications(self, login=None, **kwargs): """Get the current notifications of a user. :return: JSON """ _login = kwargs.get( 'login', login or self._login ) _notif_url = NOTIF_URL.format(login=_login) return self._request_api(url...
[ "def", "get_notifications", "(", "self", ",", "login", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", "or", "self", ".", "_login", ")", "_notif_url", "=", "NOTIF_URL", ".", "format", ...
Get the current notifications of a user. :return: JSON
[ "Get", "the", "current", "notifications", "of", "a", "user", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L189-L200
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_grades
def get_grades(self, login=None, promotion=None, **kwargs): """Get a user's grades on a single promotion based on his login. Either use the `login` param, or the client's login if unset. :return: JSON """ _login = kwargs.get( 'login', login or self._logi...
python
def get_grades(self, login=None, promotion=None, **kwargs): """Get a user's grades on a single promotion based on his login. Either use the `login` param, or the client's login if unset. :return: JSON """ _login = kwargs.get( 'login', login or self._logi...
[ "def", "get_grades", "(", "self", ",", "login", "=", "None", ",", "promotion", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", "or", "self", ".", "_login", ")", "_promotion_id", "=", ...
Get a user's grades on a single promotion based on his login. Either use the `login` param, or the client's login if unset. :return: JSON
[ "Get", "a", "user", "s", "grades", "on", "a", "single", "promotion", "based", "on", "his", "login", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L202-L215
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_picture
def get_picture(self, login=None, **kwargs): """Get a user's picture. :param str login: Login of the user to check :return: JSON """ _login = kwargs.get( 'login', login or self._login ) _activities_url = PICTURE_URL.format(login=_login) ...
python
def get_picture(self, login=None, **kwargs): """Get a user's picture. :param str login: Login of the user to check :return: JSON """ _login = kwargs.get( 'login', login or self._login ) _activities_url = PICTURE_URL.format(login=_login) ...
[ "def", "get_picture", "(", "self", ",", "login", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", "or", "self", ".", "_login", ")", "_activities_url", "=", "PICTURE_URL", ".", "format", ...
Get a user's picture. :param str login: Login of the user to check :return: JSON
[ "Get", "a", "user", "s", "picture", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L217-L229
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_projects
def get_projects(self, **kwargs): """Get a user's project. :param str login: User's login (Default: self._login) :return: JSON """ _login = kwargs.get('login', self._login) search_url = SEARCH_URL.format(login=_login) return self._request_api(url=search_url).jso...
python
def get_projects(self, **kwargs): """Get a user's project. :param str login: User's login (Default: self._login) :return: JSON """ _login = kwargs.get('login', self._login) search_url = SEARCH_URL.format(login=_login) return self._request_api(url=search_url).jso...
[ "def", "get_projects", "(", "self", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "self", ".", "_login", ")", "search_url", "=", "SEARCH_URL", ".", "format", "(", "login", "=", "_login", ")", "return", "...
Get a user's project. :param str login: User's login (Default: self._login) :return: JSON
[ "Get", "a", "user", "s", "project", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L231-L240
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_activities_for_project
def get_activities_for_project(self, module=None, **kwargs): """Get the related activities of a project. :param str module: Stages of a given module :return: JSON """ _module_id = kwargs.get('module', module) _activities_url = ACTIVITIES_URL.format(module_id=_module_id)...
python
def get_activities_for_project(self, module=None, **kwargs): """Get the related activities of a project. :param str module: Stages of a given module :return: JSON """ _module_id = kwargs.get('module', module) _activities_url = ACTIVITIES_URL.format(module_id=_module_id)...
[ "def", "get_activities_for_project", "(", "self", ",", "module", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_module_id", "=", "kwargs", ".", "get", "(", "'module'", ",", "module", ")", "_activities_url", "=", "ACTIVITIES_URL", ".", "format", "(", "mo...
Get the related activities of a project. :param str module: Stages of a given module :return: JSON
[ "Get", "the", "related", "activities", "of", "a", "project", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L242-L251
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_group_for_activity
def get_group_for_activity(self, module=None, project=None, **kwargs): """Get groups for activity. :param str module: Base module :param str module: Project which contains the group requested :return: JSON """ _module_id = kwargs.get('module', module) _project_i...
python
def get_group_for_activity(self, module=None, project=None, **kwargs): """Get groups for activity. :param str module: Base module :param str module: Project which contains the group requested :return: JSON """ _module_id = kwargs.get('module', module) _project_i...
[ "def", "get_group_for_activity", "(", "self", ",", "module", "=", "None", ",", "project", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_module_id", "=", "kwargs", ".", "get", "(", "'module'", ",", "module", ")", "_project_id", "=", "kwargs", ".", "...
Get groups for activity. :param str module: Base module :param str module: Project which contains the group requested :return: JSON
[ "Get", "groups", "for", "activity", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L253-L264
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_students
def get_students(self, **kwargs): """Get users by promotion id. :param int promotion: Promotion ID :return: JSON """ _promotion_id = kwargs.get('promotion') _url = PROMOTION_URL.format(promo_id=_promotion_id) return self._request_api(url=_url).json()
python
def get_students(self, **kwargs): """Get users by promotion id. :param int promotion: Promotion ID :return: JSON """ _promotion_id = kwargs.get('promotion') _url = PROMOTION_URL.format(promo_id=_promotion_id) return self._request_api(url=_url).json()
[ "def", "get_students", "(", "self", ",", "*", "*", "kwargs", ")", ":", "_promotion_id", "=", "kwargs", ".", "get", "(", "'promotion'", ")", "_url", "=", "PROMOTION_URL", ".", "format", "(", "promo_id", "=", "_promotion_id", ")", "return", "self", ".", "_...
Get users by promotion id. :param int promotion: Promotion ID :return: JSON
[ "Get", "users", "by", "promotion", "id", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L266-L275
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_log_events
def get_log_events(self, login=None, **kwargs): """Get a user's log events. :param str login: User's login (Default: self._login) :return: JSON """ _login = kwargs.get( 'login', login ) log_events_url = GSA_EVENTS_URL.format(login=_login)...
python
def get_log_events(self, login=None, **kwargs): """Get a user's log events. :param str login: User's login (Default: self._login) :return: JSON """ _login = kwargs.get( 'login', login ) log_events_url = GSA_EVENTS_URL.format(login=_login)...
[ "def", "get_log_events", "(", "self", ",", "login", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", ")", "log_events_url", "=", "GSA_EVENTS_URL", ".", "format", "(", "login", "=", "_log...
Get a user's log events. :param str login: User's login (Default: self._login) :return: JSON
[ "Get", "a", "user", "s", "log", "events", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L277-L289
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_events
def get_events(self, login=None, start_date=None, end_date=None, **kwargs): """Get a user's events. :param str login: User's login (Default: self._login) :param str start_date: Start date :param str end_date: To date :return: JSON """ _login = kwargs.get( ...
python
def get_events(self, login=None, start_date=None, end_date=None, **kwargs): """Get a user's events. :param str login: User's login (Default: self._login) :param str start_date: Start date :param str end_date: To date :return: JSON """ _login = kwargs.get( ...
[ "def", "get_events", "(", "self", ",", "login", "=", "None", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", ")", "log_events_url", "=...
Get a user's events. :param str login: User's login (Default: self._login) :param str start_date: Start date :param str end_date: To date :return: JSON
[ "Get", "a", "user", "s", "events", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L291-L309
train
tbobm/etnawrapper
etnawrapper/etna.py
EtnaWrapper.get_logs
def get_logs(self, login=None, **kwargs): """Get a user's logs. :param str login: User's login (Default: self._login) :return: JSON """ _login = kwargs.get( 'login', login ) log_events_url = GSA_LOGS_URL.format(login=_login) retur...
python
def get_logs(self, login=None, **kwargs): """Get a user's logs. :param str login: User's login (Default: self._login) :return: JSON """ _login = kwargs.get( 'login', login ) log_events_url = GSA_LOGS_URL.format(login=_login) retur...
[ "def", "get_logs", "(", "self", ",", "login", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_login", "=", "kwargs", ".", "get", "(", "'login'", ",", "login", ")", "log_events_url", "=", "GSA_LOGS_URL", ".", "format", "(", "login", "=", "_login", "...
Get a user's logs. :param str login: User's login (Default: self._login) :return: JSON
[ "Get", "a", "user", "s", "logs", "." ]
0f1759646a30f658cf75fd521fd6e9cef5cd09c4
https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L311-L323
train
slok/prometheus-python
prometheus/negotiator.py
Negotiator.negotiate
def negotiate(cls, headers): """ Process headers dict to return the format class (not the instance) """ # set lower keys headers = {k.lower(): v for k, v in headers.items()} accept = headers.get('accept', "*/*") parsed_accept = accept.split(";") pars...
python
def negotiate(cls, headers): """ Process headers dict to return the format class (not the instance) """ # set lower keys headers = {k.lower(): v for k, v in headers.items()} accept = headers.get('accept', "*/*") parsed_accept = accept.split(";") pars...
[ "def", "negotiate", "(", "cls", ",", "headers", ")", ":", "# set lower keys", "headers", "=", "{", "k", ".", "lower", "(", ")", ":", "v", "for", "k", ",", "v", "in", "headers", ".", "items", "(", ")", "}", "accept", "=", "headers", ".", "get", "(...
Process headers dict to return the format class (not the instance)
[ "Process", "headers", "dict", "to", "return", "the", "format", "class", "(", "not", "the", "instance", ")" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/negotiator.py#L26-L51
train
slok/prometheus-python
prometheus/registry.py
Registry.register
def register(self, collector): """ Registers a collector""" if not isinstance(collector, Collector): raise TypeError( "Can't register instance, not a valid type of collector") if collector.name in self.collectors: raise ValueError("Collector already exist...
python
def register(self, collector): """ Registers a collector""" if not isinstance(collector, Collector): raise TypeError( "Can't register instance, not a valid type of collector") if collector.name in self.collectors: raise ValueError("Collector already exist...
[ "def", "register", "(", "self", ",", "collector", ")", ":", "if", "not", "isinstance", "(", "collector", ",", "Collector", ")", ":", "raise", "TypeError", "(", "\"Can't register instance, not a valid type of collector\"", ")", "if", "collector", ".", "name", "in",...
Registers a collector
[ "Registers", "a", "collector" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/registry.py#L15-L25
train
slok/prometheus-python
prometheus/pusher.py
Pusher.add
def add(self, registry): """ Add works like replace, but only previously pushed metrics with the same name (and the same job and instance) will be replaced. (It uses HTTP method 'POST' to push to the Pushgateway.) """ # POST payload = self.formatter.marshall(regis...
python
def add(self, registry): """ Add works like replace, but only previously pushed metrics with the same name (and the same job and instance) will be replaced. (It uses HTTP method 'POST' to push to the Pushgateway.) """ # POST payload = self.formatter.marshall(regis...
[ "def", "add", "(", "self", ",", "registry", ")", ":", "# POST", "payload", "=", "self", ".", "formatter", ".", "marshall", "(", "registry", ")", "r", "=", "requests", ".", "post", "(", "self", ".", "path", ",", "data", "=", "payload", ",", "headers",...
Add works like replace, but only previously pushed metrics with the same name (and the same job and instance) will be replaced. (It uses HTTP method 'POST' to push to the Pushgateway.)
[ "Add", "works", "like", "replace", "but", "only", "previously", "pushed", "metrics", "with", "the", "same", "name", "(", "and", "the", "same", "job", "and", "instance", ")", "will", "be", "replaced", ".", "(", "It", "uses", "HTTP", "method", "POST", "to"...
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/pusher.py#L31-L38
train
slok/prometheus-python
prometheus/pusher.py
Pusher.replace
def replace(self, registry): """ Push triggers a metric collection and pushes all collected metrics to the Pushgateway specified by addr Note that all previously pushed metrics with the same job and instance will be replaced with the metrics pushed by this call. (...
python
def replace(self, registry): """ Push triggers a metric collection and pushes all collected metrics to the Pushgateway specified by addr Note that all previously pushed metrics with the same job and instance will be replaced with the metrics pushed by this call. (...
[ "def", "replace", "(", "self", ",", "registry", ")", ":", "# PUT", "payload", "=", "self", ".", "formatter", ".", "marshall", "(", "registry", ")", "r", "=", "requests", ".", "put", "(", "self", ".", "path", ",", "data", "=", "payload", ",", "headers...
Push triggers a metric collection and pushes all collected metrics to the Pushgateway specified by addr Note that all previously pushed metrics with the same job and instance will be replaced with the metrics pushed by this call. (It uses HTTP method 'PUT' to push to the ...
[ "Push", "triggers", "a", "metric", "collection", "and", "pushes", "all", "collected", "metrics", "to", "the", "Pushgateway", "specified", "by", "addr", "Note", "that", "all", "previously", "pushed", "metrics", "with", "the", "same", "job", "and", "instance", "...
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/pusher.py#L40-L49
train
slok/prometheus-python
prometheus/formats.py
TextFormat.marshall_lines
def marshall_lines(self, collector): """ Marshalls a collector and returns the storage/transfer format in a tuple, this tuple has reprensentation format per element. """ if isinstance(collector, collectors.Counter): exec_method = self._format_counter elif isinsta...
python
def marshall_lines(self, collector): """ Marshalls a collector and returns the storage/transfer format in a tuple, this tuple has reprensentation format per element. """ if isinstance(collector, collectors.Counter): exec_method = self._format_counter elif isinsta...
[ "def", "marshall_lines", "(", "self", ",", "collector", ")", ":", "if", "isinstance", "(", "collector", ",", "collectors", ".", "Counter", ")", ":", "exec_method", "=", "self", ".", "_format_counter", "elif", "isinstance", "(", "collector", ",", "collectors", ...
Marshalls a collector and returns the storage/transfer format in a tuple, this tuple has reprensentation format per element.
[ "Marshalls", "a", "collector", "and", "returns", "the", "storage", "/", "transfer", "format", "in", "a", "tuple", "this", "tuple", "has", "reprensentation", "format", "per", "element", "." ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/formats.py#L132-L165
train
slok/prometheus-python
prometheus/formats.py
TextFormat.marshall
def marshall(self, registry): """Marshalls a full registry (various collectors)""" blocks = [] for i in registry.get_all(): blocks.append(self.marshall_collector(i)) # Sort? used in tests blocks = sorted(blocks) # Needs EOF blocks.append("") ...
python
def marshall(self, registry): """Marshalls a full registry (various collectors)""" blocks = [] for i in registry.get_all(): blocks.append(self.marshall_collector(i)) # Sort? used in tests blocks = sorted(blocks) # Needs EOF blocks.append("") ...
[ "def", "marshall", "(", "self", ",", "registry", ")", ":", "blocks", "=", "[", "]", "for", "i", "in", "registry", ".", "get_all", "(", ")", ":", "blocks", ".", "append", "(", "self", ".", "marshall_collector", "(", "i", ")", ")", "# Sort? used in tests...
Marshalls a full registry (various collectors)
[ "Marshalls", "a", "full", "registry", "(", "various", "collectors", ")" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/formats.py#L172-L185
train
slok/prometheus-python
prometheus/formats.py
ProtobufFormat.marshall
def marshall(self, registry): """Returns bytes""" result = b"" for i in registry.get_all(): # Each message needs to be prefixed with a varint with the size of # the message (MetrycType) # https://github.com/matttproud/golang_protobuf_extensions/blob/master/ex...
python
def marshall(self, registry): """Returns bytes""" result = b"" for i in registry.get_all(): # Each message needs to be prefixed with a varint with the size of # the message (MetrycType) # https://github.com/matttproud/golang_protobuf_extensions/blob/master/ex...
[ "def", "marshall", "(", "self", ",", "registry", ")", ":", "result", "=", "b\"\"", "for", "i", "in", "registry", ".", "get_all", "(", ")", ":", "# Each message needs to be prefixed with a varint with the size of", "# the message (MetrycType)", "# https://github.com/matttp...
Returns bytes
[ "Returns", "bytes" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/formats.py#L291-L304
train
slok/prometheus-python
examples/trigonometry_example.py
gather_data
def gather_data(registry): """Gathers the metrics""" # Get the host name of the machine host = socket.gethostname() # Create our collectors trig_metric = Gauge("trigonometry_example", "Various trigonometry examples.", {'host': host}) # register ...
python
def gather_data(registry): """Gathers the metrics""" # Get the host name of the machine host = socket.gethostname() # Create our collectors trig_metric = Gauge("trigonometry_example", "Various trigonometry examples.", {'host': host}) # register ...
[ "def", "gather_data", "(", "registry", ")", ":", "# Get the host name of the machine", "host", "=", "socket", ".", "gethostname", "(", ")", "# Create our collectors", "trig_metric", "=", "Gauge", "(", "\"trigonometry_example\"", ",", "\"Various trigonometry examples.\"", ...
Gathers the metrics
[ "Gathers", "the", "metrics" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/examples/trigonometry_example.py#L20-L44
train
slok/prometheus-python
prometheus/collectors.py
Collector.set_value
def set_value(self, labels, value): """ Sets a value in the container""" if labels: self._label_names_correct(labels) with mutex: self.values[labels] = value
python
def set_value(self, labels, value): """ Sets a value in the container""" if labels: self._label_names_correct(labels) with mutex: self.values[labels] = value
[ "def", "set_value", "(", "self", ",", "labels", ",", "value", ")", ":", "if", "labels", ":", "self", ".", "_label_names_correct", "(", "labels", ")", "with", "mutex", ":", "self", ".", "values", "[", "labels", "]", "=", "value" ]
Sets a value in the container
[ "Sets", "a", "value", "in", "the", "container" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/collectors.py#L38-L45
train
slok/prometheus-python
prometheus/collectors.py
Collector._label_names_correct
def _label_names_correct(self, labels): """Raise exception (ValueError) if labels not correct""" for k, v in labels.items(): # Check reserved labels if k in RESTRICTED_LABELS_NAMES: raise ValueError("Labels not correct") # Check prefixes ...
python
def _label_names_correct(self, labels): """Raise exception (ValueError) if labels not correct""" for k, v in labels.items(): # Check reserved labels if k in RESTRICTED_LABELS_NAMES: raise ValueError("Labels not correct") # Check prefixes ...
[ "def", "_label_names_correct", "(", "self", ",", "labels", ")", ":", "for", "k", ",", "v", "in", "labels", ".", "items", "(", ")", ":", "# Check reserved labels", "if", "k", "in", "RESTRICTED_LABELS_NAMES", ":", "raise", "ValueError", "(", "\"Labels not correc...
Raise exception (ValueError) if labels not correct
[ "Raise", "exception", "(", "ValueError", ")", "if", "labels", "not", "correct" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/collectors.py#L57-L69
train
slok/prometheus-python
prometheus/collectors.py
Collector.get_all
def get_all(self): """ Returns a list populated by tuples of 2 elements, first one is a dict with all the labels and the second elemnt is the value of the metric itself """ with mutex: items = self.values.items() result = [] for k, v in items:...
python
def get_all(self): """ Returns a list populated by tuples of 2 elements, first one is a dict with all the labels and the second elemnt is the value of the metric itself """ with mutex: items = self.values.items() result = [] for k, v in items:...
[ "def", "get_all", "(", "self", ")", ":", "with", "mutex", ":", "items", "=", "self", ".", "values", ".", "items", "(", ")", "result", "=", "[", "]", "for", "k", ",", "v", "in", "items", ":", "# Check if is a single value dict (custom empty key)", "if", "...
Returns a list populated by tuples of 2 elements, first one is a dict with all the labels and the second elemnt is the value of the metric itself
[ "Returns", "a", "list", "populated", "by", "tuples", "of", "2", "elements", "first", "one", "is", "a", "dict", "with", "all", "the", "labels", "and", "the", "second", "elemnt", "is", "the", "value", "of", "the", "metric", "itself" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/collectors.py#L71-L88
train
slok/prometheus-python
prometheus/collectors.py
Gauge.add
def add(self, labels, value): """ Add adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.) """ try: current = self.get_value(labels) except KeyError: current = 0 self.set_value(labels, current ...
python
def add(self, labels, value): """ Add adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.) """ try: current = self.get_value(labels) except KeyError: current = 0 self.set_value(labels, current ...
[ "def", "add", "(", "self", ",", "labels", ",", "value", ")", ":", "try", ":", "current", "=", "self", ".", "get_value", "(", "labels", ")", "except", "KeyError", ":", "current", "=", "0", "self", ".", "set_value", "(", "labels", ",", "current", "+", ...
Add adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.)
[ "Add", "adds", "the", "given", "value", "to", "the", "Gauge", ".", "(", "The", "value", "can", "be", "negative", "resulting", "in", "a", "decrease", "of", "the", "Gauge", ".", ")" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/collectors.py#L153-L163
train
slok/prometheus-python
prometheus/collectors.py
Summary.add
def add(self, labels, value): """Add adds a single observation to the summary.""" if type(value) not in (float, int): raise TypeError("Summary only works with digits (int, float)") # We have already a lock for data but not for the estimator with mutex: try: ...
python
def add(self, labels, value): """Add adds a single observation to the summary.""" if type(value) not in (float, int): raise TypeError("Summary only works with digits (int, float)") # We have already a lock for data but not for the estimator with mutex: try: ...
[ "def", "add", "(", "self", ",", "labels", ",", "value", ")", ":", "if", "type", "(", "value", ")", "not", "in", "(", "float", ",", "int", ")", ":", "raise", "TypeError", "(", "\"Summary only works with digits (int, float)\"", ")", "# We have already a lock for...
Add adds a single observation to the summary.
[ "Add", "adds", "a", "single", "observation", "to", "the", "summary", "." ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/collectors.py#L195-L209
train
slok/prometheus-python
prometheus/collectors.py
Summary.get
def get(self, labels): """ Get gets the data in the form of 0.5, 0.9 and 0.99 percentiles. Also you get sum and count, all in a dict """ return_data = {} # We have already a lock for data but not for the estimator with mutex: e = self.get_value(labels) ...
python
def get(self, labels): """ Get gets the data in the form of 0.5, 0.9 and 0.99 percentiles. Also you get sum and count, all in a dict """ return_data = {} # We have already a lock for data but not for the estimator with mutex: e = self.get_value(labels) ...
[ "def", "get", "(", "self", ",", "labels", ")", ":", "return_data", "=", "{", "}", "# We have already a lock for data but not for the estimator", "with", "mutex", ":", "e", "=", "self", ".", "get_value", "(", "labels", ")", "# Set invariants data (default to 0.50, 0.90...
Get gets the data in the form of 0.5, 0.9 and 0.99 percentiles. Also you get sum and count, all in a dict
[ "Get", "gets", "the", "data", "in", "the", "form", "of", "0", ".", "5", "0", ".", "9", "and", "0", ".", "99", "percentiles", ".", "Also", "you", "get", "sum", "and", "count", "all", "in", "a", "dict" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/prometheus/collectors.py#L211-L231
train
slok/prometheus-python
examples/memory_cpu_usage_example.py
gather_data
def gather_data(registry): """Gathers the metrics""" # Get the host name of the machine host = socket.gethostname() # Create our collectors ram_metric = Gauge("memory_usage_bytes", "Memory usage in bytes.", {'host': host}) cpu_metric = Gauge("cpu_usage_percent", "CPU usa...
python
def gather_data(registry): """Gathers the metrics""" # Get the host name of the machine host = socket.gethostname() # Create our collectors ram_metric = Gauge("memory_usage_bytes", "Memory usage in bytes.", {'host': host}) cpu_metric = Gauge("cpu_usage_percent", "CPU usa...
[ "def", "gather_data", "(", "registry", ")", ":", "# Get the host name of the machine", "host", "=", "socket", ".", "gethostname", "(", ")", "# Create our collectors", "ram_metric", "=", "Gauge", "(", "\"memory_usage_bytes\"", ",", "\"Memory usage in bytes.\"", ",", "{",...
Gathers the metrics
[ "Gathers", "the", "metrics" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/examples/memory_cpu_usage_example.py#L20-L50
train
slok/prometheus-python
examples/timing_write_io_example.py
gather_data
def gather_data(registry): """Gathers the metrics""" # Get the host name of the machine host = socket.gethostname() # Create our collectors io_metric = Summary("write_file_io_example", "Writing io file in disk example.", {'host': host}) # regist...
python
def gather_data(registry): """Gathers the metrics""" # Get the host name of the machine host = socket.gethostname() # Create our collectors io_metric = Summary("write_file_io_example", "Writing io file in disk example.", {'host': host}) # regist...
[ "def", "gather_data", "(", "registry", ")", ":", "# Get the host name of the machine", "host", "=", "socket", ".", "gethostname", "(", ")", "# Create our collectors", "io_metric", "=", "Summary", "(", "\"write_file_io_example\"", ",", "\"Writing io file in disk example.\"",...
Gathers the metrics
[ "Gathers", "the", "metrics" ]
51c6de3cdcd4e36eae6e1643b136f486b57a18cd
https://github.com/slok/prometheus-python/blob/51c6de3cdcd4e36eae6e1643b136f486b57a18cd/examples/timing_write_io_example.py#L20-L49
train
knipknap/Gelatin
Gelatin/generator/Builder.py
Node.get_child
def get_child(self, name, attribs=None): """ Returns the first child that matches the given name and attributes. """ if name == '.': if attribs is None or len(attribs) == 0: return self if attribs == self.attribs: return sel...
python
def get_child(self, name, attribs=None): """ Returns the first child that matches the given name and attributes. """ if name == '.': if attribs is None or len(attribs) == 0: return self if attribs == self.attribs: return sel...
[ "def", "get_child", "(", "self", ",", "name", ",", "attribs", "=", "None", ")", ":", "if", "name", "==", "'.'", ":", "if", "attribs", "is", "None", "or", "len", "(", "attribs", ")", "==", "0", ":", "return", "self", "if", "attribs", "==", "self", ...
Returns the first child that matches the given name and attributes.
[ "Returns", "the", "first", "child", "that", "matches", "the", "given", "name", "and", "attributes", "." ]
d2afa85a48034d6ee34580e49e16542f31ad208e
https://github.com/knipknap/Gelatin/blob/d2afa85a48034d6ee34580e49e16542f31ad208e/Gelatin/generator/Builder.py#L96-L106
train
knipknap/Gelatin
Gelatin/generator/Builder.py
Builder.create
def create(self, path, data=None): """ Creates the given node, regardless of whether or not it already exists. Returns the new node. """ node = self.current[-1] path = self._splitpath(path) n_items = len(path) for n, item in enumerate(path): ...
python
def create(self, path, data=None): """ Creates the given node, regardless of whether or not it already exists. Returns the new node. """ node = self.current[-1] path = self._splitpath(path) n_items = len(path) for n, item in enumerate(path): ...
[ "def", "create", "(", "self", ",", "path", ",", "data", "=", "None", ")", ":", "node", "=", "self", ".", "current", "[", "-", "1", "]", "path", "=", "self", ".", "_splitpath", "(", "path", ")", "n_items", "=", "len", "(", "path", ")", "for", "n...
Creates the given node, regardless of whether or not it already exists. Returns the new node.
[ "Creates", "the", "given", "node", "regardless", "of", "whether", "or", "not", "it", "already", "exists", ".", "Returns", "the", "new", "node", "." ]
d2afa85a48034d6ee34580e49e16542f31ad208e
https://github.com/knipknap/Gelatin/blob/d2afa85a48034d6ee34580e49e16542f31ad208e/Gelatin/generator/Builder.py#L174-L199
train
knipknap/Gelatin
Gelatin/generator/Builder.py
Builder.add
def add(self, path, data=None, replace=False): """ Creates the given node if it does not exist. Returns the (new or existing) node. """ node = self.current[-1] for item in self._splitpath(path): tag, attribs = self._splittag(item) next_node = node....
python
def add(self, path, data=None, replace=False): """ Creates the given node if it does not exist. Returns the (new or existing) node. """ node = self.current[-1] for item in self._splitpath(path): tag, attribs = self._splittag(item) next_node = node....
[ "def", "add", "(", "self", ",", "path", ",", "data", "=", "None", ",", "replace", "=", "False", ")", ":", "node", "=", "self", ".", "current", "[", "-", "1", "]", "for", "item", "in", "self", ".", "_splitpath", "(", "path", ")", ":", "tag", ","...
Creates the given node if it does not exist. Returns the (new or existing) node.
[ "Creates", "the", "given", "node", "if", "it", "does", "not", "exist", ".", "Returns", "the", "(", "new", "or", "existing", ")", "node", "." ]
d2afa85a48034d6ee34580e49e16542f31ad208e
https://github.com/knipknap/Gelatin/blob/d2afa85a48034d6ee34580e49e16542f31ad208e/Gelatin/generator/Builder.py#L201-L221
train
knipknap/Gelatin
Gelatin/generator/Builder.py
Builder.add_attribute
def add_attribute(self, path, name, value): """ Creates the given attribute and sets it to the given value. Returns the (new or existing) node to which the attribute was added. """ node = self.add(path) node.attribs.append((name, value)) return node
python
def add_attribute(self, path, name, value): """ Creates the given attribute and sets it to the given value. Returns the (new or existing) node to which the attribute was added. """ node = self.add(path) node.attribs.append((name, value)) return node
[ "def", "add_attribute", "(", "self", ",", "path", ",", "name", ",", "value", ")", ":", "node", "=", "self", ".", "add", "(", "path", ")", "node", ".", "attribs", ".", "append", "(", "(", "name", ",", "value", ")", ")", "return", "node" ]
Creates the given attribute and sets it to the given value. Returns the (new or existing) node to which the attribute was added.
[ "Creates", "the", "given", "attribute", "and", "sets", "it", "to", "the", "given", "value", ".", "Returns", "the", "(", "new", "or", "existing", ")", "node", "to", "which", "the", "attribute", "was", "added", "." ]
d2afa85a48034d6ee34580e49e16542f31ad208e
https://github.com/knipknap/Gelatin/blob/d2afa85a48034d6ee34580e49e16542f31ad208e/Gelatin/generator/Builder.py#L223-L230
train
knipknap/Gelatin
Gelatin/generator/Builder.py
Builder.open
def open(self, path): """ Creates and enters the given node, regardless of whether it already exists. Returns the new node. """ self.current.append(self.create(path)) return self.current[-1]
python
def open(self, path): """ Creates and enters the given node, regardless of whether it already exists. Returns the new node. """ self.current.append(self.create(path)) return self.current[-1]
[ "def", "open", "(", "self", ",", "path", ")", ":", "self", ".", "current", ".", "append", "(", "self", ".", "create", "(", "path", ")", ")", "return", "self", ".", "current", "[", "-", "1", "]" ]
Creates and enters the given node, regardless of whether it already exists. Returns the new node.
[ "Creates", "and", "enters", "the", "given", "node", "regardless", "of", "whether", "it", "already", "exists", ".", "Returns", "the", "new", "node", "." ]
d2afa85a48034d6ee34580e49e16542f31ad208e
https://github.com/knipknap/Gelatin/blob/d2afa85a48034d6ee34580e49e16542f31ad208e/Gelatin/generator/Builder.py#L232-L239
train