partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
valid
CorniceSwagger._extract_transform_colander_schema
Extract schema from view args and transform it using the pipeline of schema transformers :param args: Arguments from the view decorator. :rtype: colander.MappingSchema() :returns: View schema cloned and transformed
cornice_swagger/swagger.py
def _extract_transform_colander_schema(self, args): """ Extract schema from view args and transform it using the pipeline of schema transformers :param args: Arguments from the view decorator. :rtype: colander.MappingSchema() :returns: View schema cloned and...
def _extract_transform_colander_schema(self, args): """ Extract schema from view args and transform it using the pipeline of schema transformers :param args: Arguments from the view decorator. :rtype: colander.MappingSchema() :returns: View schema cloned and...
[ "Extract", "schema", "from", "view", "args", "and", "transform", "it", "using", "the", "pipeline", "of", "schema", "transformers" ]
Cornices/cornice.ext.swagger
python
https://github.com/Cornices/cornice.ext.swagger/blob/c31a5cc8d5dd112b11dc41ccb6d09b423b537abc/cornice_swagger/swagger.py#L687-L705
[ "def", "_extract_transform_colander_schema", "(", "self", ",", "args", ")", ":", "schema", "=", "args", ".", "get", "(", "'schema'", ",", "colander", ".", "MappingSchema", "(", ")", ")", "if", "not", "isinstance", "(", "schema", ",", "colander", ".", "Sche...
c31a5cc8d5dd112b11dc41ccb6d09b423b537abc
valid
main
Creates arguments and parses user input
limf/cli.py
def main(): """Creates arguments and parses user input""" parser = argparse.ArgumentParser( description=_('Uploads selected file to working pomf.se clone')) parser.add_argument('files', metavar='file', nargs='*', type=str, help=_('Files to upload')) parser.add_argument('-...
def main(): """Creates arguments and parses user input""" parser = argparse.ArgumentParser( description=_('Uploads selected file to working pomf.se clone')) parser.add_argument('files', metavar='file', nargs='*', type=str, help=_('Files to upload')) parser.add_argument('-...
[ "Creates", "arguments", "and", "parses", "user", "input" ]
lc-guy/limf
python
https://github.com/lc-guy/limf/blob/ad380feb70ef8e579a91ca09c807efec9e8af565/limf/cli.py#L10-L60
[ "def", "main", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "_", "(", "'Uploads selected file to working pomf.se clone'", ")", ")", "parser", ".", "add_argument", "(", "'files'", ",", "metavar", "=", "'file'", ",", ...
ad380feb70ef8e579a91ca09c807efec9e8af565
valid
ParameterConverter.convert
Convert node schema into a parameter object.
cornice_swagger/converters/parameters.py
def convert(self, schema_node, definition_handler): """ Convert node schema into a parameter object. """ converted = { 'name': schema_node.name, 'in': self._in, 'required': schema_node.required } if schema_node.description: ...
def convert(self, schema_node, definition_handler): """ Convert node schema into a parameter object. """ converted = { 'name': schema_node.name, 'in': self._in, 'required': schema_node.required } if schema_node.description: ...
[ "Convert", "node", "schema", "into", "a", "parameter", "object", "." ]
Cornices/cornice.ext.swagger
python
https://github.com/Cornices/cornice.ext.swagger/blob/c31a5cc8d5dd112b11dc41ccb6d09b423b537abc/cornice_swagger/converters/parameters.py#L9-L33
[ "def", "convert", "(", "self", ",", "schema_node", ",", "definition_handler", ")", ":", "converted", "=", "{", "'name'", ":", "schema_node", ".", "name", ",", "'in'", ":", "self", ".", "_in", ",", "'required'", ":", "schema_node", ".", "required", "}", "...
c31a5cc8d5dd112b11dc41ccb6d09b423b537abc
valid
cornice_enable_openapi_view
:param config: Pyramid configurator object :param api_path: where to expose swagger JSON definition view :param permission: pyramid permission for those views :param route_factory: factory for context object for those routes :param kwargs: kwargs that will be pass...
cornice_swagger/__init__.py
def cornice_enable_openapi_view( config, api_path='/api-explorer/swagger.json', permission=NO_PERMISSION_REQUIRED, route_factory=None, **kwargs): """ :param config: Pyramid configurator object :param api_path: where to expose swagger JSON definition view :...
def cornice_enable_openapi_view( config, api_path='/api-explorer/swagger.json', permission=NO_PERMISSION_REQUIRED, route_factory=None, **kwargs): """ :param config: Pyramid configurator object :param api_path: where to expose swagger JSON definition view :...
[ ":", "param", "config", ":", "Pyramid", "configurator", "object", ":", "param", "api_path", ":", "where", "to", "expose", "swagger", "JSON", "definition", "view", ":", "param", "permission", ":", "pyramid", "permission", "for", "those", "views", ":", "param", ...
Cornices/cornice.ext.swagger
python
https://github.com/Cornices/cornice.ext.swagger/blob/c31a5cc8d5dd112b11dc41ccb6d09b423b537abc/cornice_swagger/__init__.py#L38-L62
[ "def", "cornice_enable_openapi_view", "(", "config", ",", "api_path", "=", "'/api-explorer/swagger.json'", ",", "permission", "=", "NO_PERMISSION_REQUIRED", ",", "route_factory", "=", "None", ",", "*", "*", "kwargs", ")", ":", "config", ".", "registry", ".", "sett...
c31a5cc8d5dd112b11dc41ccb6d09b423b537abc
valid
cornice_enable_openapi_explorer
:param config: Pyramid configurator object :param api_explorer_path: where to expose Swagger UI interface view :param permission: pyramid permission for those views :param route_factory: factory for context object for those routes This registers and configures the view t...
cornice_swagger/__init__.py
def cornice_enable_openapi_explorer( config, api_explorer_path='/api-explorer', permission=NO_PERMISSION_REQUIRED, route_factory=None, **kwargs): """ :param config: Pyramid configurator object :param api_explorer_path: where to expose Swagger UI interf...
def cornice_enable_openapi_explorer( config, api_explorer_path='/api-explorer', permission=NO_PERMISSION_REQUIRED, route_factory=None, **kwargs): """ :param config: Pyramid configurator object :param api_explorer_path: where to expose Swagger UI interf...
[ ":", "param", "config", ":", "Pyramid", "configurator", "object", ":", "param", "api_explorer_path", ":", "where", "to", "expose", "Swagger", "UI", "interface", "view", ":", "param", "permission", ":", "pyramid", "permission", "for", "those", "views", ":", "pa...
Cornices/cornice.ext.swagger
python
https://github.com/Cornices/cornice.ext.swagger/blob/c31a5cc8d5dd112b11dc41ccb6d09b423b537abc/cornice_swagger/__init__.py#L65-L87
[ "def", "cornice_enable_openapi_explorer", "(", "config", ",", "api_explorer_path", "=", "'/api-explorer'", ",", "permission", "=", "NO_PERMISSION_REQUIRED", ",", "route_factory", "=", "None", ",", "*", "*", "kwargs", ")", ":", "config", ".", "add_route", "(", "'co...
c31a5cc8d5dd112b11dc41ccb6d09b423b537abc
valid
trim
Remove the tabs to spaces, and remove the extra spaces / tabs that are in front of the text in docstrings. Implementation taken from http://www.python.org/dev/peps/pep-0257/
cornice_swagger/util.py
def trim(docstring): """ Remove the tabs to spaces, and remove the extra spaces / tabs that are in front of the text in docstrings. Implementation taken from http://www.python.org/dev/peps/pep-0257/ """ if not docstring: return '' # Convert tabs to spaces (following the normal Pytho...
def trim(docstring): """ Remove the tabs to spaces, and remove the extra spaces / tabs that are in front of the text in docstrings. Implementation taken from http://www.python.org/dev/peps/pep-0257/ """ if not docstring: return '' # Convert tabs to spaces (following the normal Pytho...
[ "Remove", "the", "tabs", "to", "spaces", "and", "remove", "the", "extra", "spaces", "/", "tabs", "that", "are", "in", "front", "of", "the", "text", "in", "docstrings", "." ]
Cornices/cornice.ext.swagger
python
https://github.com/Cornices/cornice.ext.swagger/blob/c31a5cc8d5dd112b11dc41ccb6d09b423b537abc/cornice_swagger/util.py#L6-L20
[ "def", "trim", "(", "docstring", ")", ":", "if", "not", "docstring", ":", "return", "''", "# Convert tabs to spaces (following the normal Python rules)", "# and split into a list of lines:", "lines", "=", "six", ".", "u", "(", "docstring", ")", ".", "expandtabs", "(",...
c31a5cc8d5dd112b11dc41ccb6d09b423b537abc
valid
merge_dicts
Merge b into a recursively, without overwriting values. :param base: the dict that will be altered. :param changes: changes to update base.
cornice_swagger/util.py
def merge_dicts(base, changes): """Merge b into a recursively, without overwriting values. :param base: the dict that will be altered. :param changes: changes to update base. """ for k, v in changes.items(): if isinstance(v, dict): merge_dicts(base.setdefault(k, {}), v) ...
def merge_dicts(base, changes): """Merge b into a recursively, without overwriting values. :param base: the dict that will be altered. :param changes: changes to update base. """ for k, v in changes.items(): if isinstance(v, dict): merge_dicts(base.setdefault(k, {}), v) ...
[ "Merge", "b", "into", "a", "recursively", "without", "overwriting", "values", "." ]
Cornices/cornice.ext.swagger
python
https://github.com/Cornices/cornice.ext.swagger/blob/c31a5cc8d5dd112b11dc41ccb6d09b423b537abc/cornice_swagger/util.py#L32-L42
[ "def", "merge_dicts", "(", "base", ",", "changes", ")", ":", "for", "k", ",", "v", "in", "changes", ".", "items", "(", ")", ":", "if", "isinstance", "(", "v", ",", "dict", ")", ":", "merge_dicts", "(", "base", ".", "setdefault", "(", "k", ",", "{...
c31a5cc8d5dd112b11dc41ccb6d09b423b537abc
valid
get_transition_viewset_method
Create a viewset method for the provided `transition_name`
drf_fsm_transitions/viewset_mixins.py
def get_transition_viewset_method(transition_name, **kwargs): ''' Create a viewset method for the provided `transition_name` ''' @detail_route(methods=['post'], **kwargs) def inner_func(self, request, pk=None, **kwargs): object = self.get_object() transition_method = getattr(object, ...
def get_transition_viewset_method(transition_name, **kwargs): ''' Create a viewset method for the provided `transition_name` ''' @detail_route(methods=['post'], **kwargs) def inner_func(self, request, pk=None, **kwargs): object = self.get_object() transition_method = getattr(object, ...
[ "Create", "a", "viewset", "method", "for", "the", "provided", "transition_name" ]
jacobh/drf-fsm-transitions
python
https://github.com/jacobh/drf-fsm-transitions/blob/9cc792d4e570145dd08724bedd32676a6a58cf1f/drf_fsm_transitions/viewset_mixins.py#L5-L22
[ "def", "get_transition_viewset_method", "(", "transition_name", ",", "*", "*", "kwargs", ")", ":", "@", "detail_route", "(", "methods", "=", "[", "'post'", "]", ",", "*", "*", "kwargs", ")", "def", "inner_func", "(", "self", ",", "request", ",", "pk", "=...
9cc792d4e570145dd08724bedd32676a6a58cf1f
valid
get_viewset_transition_action_mixin
Find all transitions defined on `model`, then create a corresponding viewset action method for each and apply it to `Mixin`. Finally, return `Mixin`
drf_fsm_transitions/viewset_mixins.py
def get_viewset_transition_action_mixin(model, **kwargs): ''' Find all transitions defined on `model`, then create a corresponding viewset action method for each and apply it to `Mixin`. Finally, return `Mixin` ''' instance = model() class Mixin(object): save_after_transition = True...
def get_viewset_transition_action_mixin(model, **kwargs): ''' Find all transitions defined on `model`, then create a corresponding viewset action method for each and apply it to `Mixin`. Finally, return `Mixin` ''' instance = model() class Mixin(object): save_after_transition = True...
[ "Find", "all", "transitions", "defined", "on", "model", "then", "create", "a", "corresponding", "viewset", "action", "method", "for", "each", "and", "apply", "it", "to", "Mixin", ".", "Finally", "return", "Mixin" ]
jacobh/drf-fsm-transitions
python
https://github.com/jacobh/drf-fsm-transitions/blob/9cc792d4e570145dd08724bedd32676a6a58cf1f/drf_fsm_transitions/viewset_mixins.py#L25-L45
[ "def", "get_viewset_transition_action_mixin", "(", "model", ",", "*", "*", "kwargs", ")", ":", "instance", "=", "model", "(", ")", "class", "Mixin", "(", "object", ")", ":", "save_after_transition", "=", "True", "transitions", "=", "instance", ".", "get_all_st...
9cc792d4e570145dd08724bedd32676a6a58cf1f
valid
fresh_cookies
Refresh the project from the original cookiecutter template.
tasks.py
def fresh_cookies(ctx, mold=''): """Refresh the project from the original cookiecutter template.""" mold = mold or "https://github.com/Springerle/py-generic-project.git" # TODO: URL from config tmpdir = os.path.join(tempfile.gettempdir(), "cc-upgrade-pygments-markdown-lexer") if os.path.isdir('.git'):...
def fresh_cookies(ctx, mold=''): """Refresh the project from the original cookiecutter template.""" mold = mold or "https://github.com/Springerle/py-generic-project.git" # TODO: URL from config tmpdir = os.path.join(tempfile.gettempdir(), "cc-upgrade-pygments-markdown-lexer") if os.path.isdir('.git'):...
[ "Refresh", "the", "project", "from", "the", "original", "cookiecutter", "template", "." ]
jhermann/pygments-markdown-lexer
python
https://github.com/jhermann/pygments-markdown-lexer/blob/e651a9a3f664285b01451eb39232b1ad9af65956/tasks.py#L32-L57
[ "def", "fresh_cookies", "(", "ctx", ",", "mold", "=", "''", ")", ":", "mold", "=", "mold", "or", "\"https://github.com/Springerle/py-generic-project.git\"", "# TODO: URL from config", "tmpdir", "=", "os", ".", "path", ".", "join", "(", "tempfile", ".", "gettempdir...
e651a9a3f664285b01451eb39232b1ad9af65956
valid
ci
Perform continuous integration tasks.
tasks.py
def ci(ctx): """Perform continuous integration tasks.""" opts = [''] # 'tox' makes no sense in Travis if os.environ.get('TRAVIS', '').lower() == 'true': opts += ['test.pytest'] else: opts += ['test.tox'] ctx.run("invoke --echo --pty clean --all build --docs check --reports{}".f...
def ci(ctx): """Perform continuous integration tasks.""" opts = [''] # 'tox' makes no sense in Travis if os.environ.get('TRAVIS', '').lower() == 'true': opts += ['test.pytest'] else: opts += ['test.tox'] ctx.run("invoke --echo --pty clean --all build --docs check --reports{}".f...
[ "Perform", "continuous", "integration", "tasks", "." ]
jhermann/pygments-markdown-lexer
python
https://github.com/jhermann/pygments-markdown-lexer/blob/e651a9a3f664285b01451eb39232b1ad9af65956/tasks.py#L65-L75
[ "def", "ci", "(", "ctx", ")", ":", "opts", "=", "[", "''", "]", "# 'tox' makes no sense in Travis", "if", "os", ".", "environ", ".", "get", "(", "'TRAVIS'", ",", "''", ")", ".", "lower", "(", ")", "==", "'true'", ":", "opts", "+=", "[", "'test.pytest...
e651a9a3f664285b01451eb39232b1ad9af65956
valid
_build_metadata
Return project's metadata as a dict.
setup.py
def _build_metadata(): # pylint: disable=too-many-locals, too-many-branches "Return project's metadata as a dict." # Handle metadata in package source expected_keys = ('url', 'version', 'license', 'author', 'author_email', 'long_description', 'keywords') metadata = {} with io.open(srcfile('src', pac...
def _build_metadata(): # pylint: disable=too-many-locals, too-many-branches "Return project's metadata as a dict." # Handle metadata in package source expected_keys = ('url', 'version', 'license', 'author', 'author_email', 'long_description', 'keywords') metadata = {} with io.open(srcfile('src', pac...
[ "Return", "project", "s", "metadata", "as", "a", "dict", "." ]
jhermann/pygments-markdown-lexer
python
https://github.com/jhermann/pygments-markdown-lexer/blob/e651a9a3f664285b01451eb39232b1ad9af65956/setup.py#L91-L187
[ "def", "_build_metadata", "(", ")", ":", "# pylint: disable=too-many-locals, too-many-branches", "# Handle metadata in package source", "expected_keys", "=", "(", "'url'", ",", "'version'", ",", "'license'", ",", "'author'", ",", "'author_email'", ",", "'long_description'", ...
e651a9a3f664285b01451eb39232b1ad9af65956
valid
py_hash
Generate a number in the range [0, num_buckets). Args: key (int): The key to hash. num_buckets (int): Number of buckets to use. Returns: The bucket number `key` computes to. Raises: ValueError: If `num_buckets` is not a positive number.
jump/__init__.py
def py_hash(key, num_buckets): """Generate a number in the range [0, num_buckets). Args: key (int): The key to hash. num_buckets (int): Number of buckets to use. Returns: The bucket number `key` computes to. Raises: ValueError: If `num_buckets` is not a positive number...
def py_hash(key, num_buckets): """Generate a number in the range [0, num_buckets). Args: key (int): The key to hash. num_buckets (int): Number of buckets to use. Returns: The bucket number `key` computes to. Raises: ValueError: If `num_buckets` is not a positive number...
[ "Generate", "a", "number", "in", "the", "range", "[", "0", "num_buckets", ")", "." ]
lithammer/python-jump-consistent-hash
python
https://github.com/lithammer/python-jump-consistent-hash/blob/62d3c7c1736971a779769cbbae87598b2f3992b9/jump/__init__.py#L19-L42
[ "def", "py_hash", "(", "key", ",", "num_buckets", ")", ":", "b", ",", "j", "=", "-", "1", ",", "0", "if", "num_buckets", "<", "1", ":", "raise", "ValueError", "(", "'num_buckets must be a positive number'", ")", "while", "j", "<", "num_buckets", ":", "b"...
62d3c7c1736971a779769cbbae87598b2f3992b9
valid
setup
Initializer for Sphinx extension API. See http://www.sphinx-doc.org/en/stable/extdev/index.html#dev-extensions.
src/pygments_markdown_lexer/__init__.py
def setup(app): """ Initializer for Sphinx extension API. See http://www.sphinx-doc.org/en/stable/extdev/index.html#dev-extensions. """ lexer = MarkdownLexer() for alias in lexer.aliases: app.add_lexer(alias, lexer) return dict(version=__version__)
def setup(app): """ Initializer for Sphinx extension API. See http://www.sphinx-doc.org/en/stable/extdev/index.html#dev-extensions. """ lexer = MarkdownLexer() for alias in lexer.aliases: app.add_lexer(alias, lexer) return dict(version=__version__)
[ "Initializer", "for", "Sphinx", "extension", "API", "." ]
jhermann/pygments-markdown-lexer
python
https://github.com/jhermann/pygments-markdown-lexer/blob/e651a9a3f664285b01451eb39232b1ad9af65956/src/pygments_markdown_lexer/__init__.py#L34-L43
[ "def", "setup", "(", "app", ")", ":", "lexer", "=", "MarkdownLexer", "(", ")", "for", "alias", "in", "lexer", ".", "aliases", ":", "app", ".", "add_lexer", "(", "alias", ",", "lexer", ")", "return", "dict", "(", "version", "=", "__version__", ")" ]
e651a9a3f664285b01451eb39232b1ad9af65956
valid
MdStat.load
Return a dict of stats.
pymdstat/pymdstat.py
def load(self): """Return a dict of stats.""" ret = {} # Read the mdstat file with open(self.get_path(), 'r') as f: # lines is a list of line (with \n) lines = f.readlines() # First line: get the personalities # The "Personalities" line tells you...
def load(self): """Return a dict of stats.""" ret = {} # Read the mdstat file with open(self.get_path(), 'r') as f: # lines is a list of line (with \n) lines = f.readlines() # First line: get the personalities # The "Personalities" line tells you...
[ "Return", "a", "dict", "of", "stats", "." ]
nicolargo/pymdstat
python
https://github.com/nicolargo/pymdstat/blob/97fd47117e687463205fb562269feb9f95d59620/pymdstat/pymdstat.py#L75-L96
[ "def", "load", "(", "self", ")", ":", "ret", "=", "{", "}", "# Read the mdstat file", "with", "open", "(", "self", ".", "get_path", "(", ")", ",", "'r'", ")", "as", "f", ":", "# lines is a list of line (with \\n)", "lines", "=", "f", ".", "readlines", "(...
97fd47117e687463205fb562269feb9f95d59620
valid
MdStat.get_personalities
Return a list of personalities readed from the input line.
pymdstat/pymdstat.py
def get_personalities(self, line): """Return a list of personalities readed from the input line.""" return [split('\W+', i)[1] for i in line.split(':')[1].split(' ') if i.startswith('[')]
def get_personalities(self, line): """Return a list of personalities readed from the input line.""" return [split('\W+', i)[1] for i in line.split(':')[1].split(' ') if i.startswith('[')]
[ "Return", "a", "list", "of", "personalities", "readed", "from", "the", "input", "line", "." ]
nicolargo/pymdstat
python
https://github.com/nicolargo/pymdstat/blob/97fd47117e687463205fb562269feb9f95d59620/pymdstat/pymdstat.py#L98-L100
[ "def", "get_personalities", "(", "self", ",", "line", ")", ":", "return", "[", "split", "(", "'\\W+'", ",", "i", ")", "[", "1", "]", "for", "i", "in", "line", ".", "split", "(", "':'", ")", "[", "1", "]", ".", "split", "(", "' '", ")", "if", ...
97fd47117e687463205fb562269feb9f95d59620
valid
MdStat.get_arrays
Return a dict of arrays.
pymdstat/pymdstat.py
def get_arrays(self, lines, personalities=[]): """Return a dict of arrays.""" ret = {} i = 0 while i < len(lines): try: # First array line: get the md device md_device = self.get_md_device_name(lines[i]) except IndexError: ...
def get_arrays(self, lines, personalities=[]): """Return a dict of arrays.""" ret = {} i = 0 while i < len(lines): try: # First array line: get the md device md_device = self.get_md_device_name(lines[i]) except IndexError: ...
[ "Return", "a", "dict", "of", "arrays", "." ]
nicolargo/pymdstat
python
https://github.com/nicolargo/pymdstat/blob/97fd47117e687463205fb562269feb9f95d59620/pymdstat/pymdstat.py#L102-L124
[ "def", "get_arrays", "(", "self", ",", "lines", ",", "personalities", "=", "[", "]", ")", ":", "ret", "=", "{", "}", "i", "=", "0", "while", "i", "<", "len", "(", "lines", ")", ":", "try", ":", "# First array line: get the md device", "md_device", "=",...
97fd47117e687463205fb562269feb9f95d59620
valid
MdStat.get_md_device
Return a dict of md device define in the line.
pymdstat/pymdstat.py
def get_md_device(self, line, personalities=[]): """Return a dict of md device define in the line.""" ret = {} splitted = split('\W+', line) # Raid status # Active or 'started'. An inactive array is usually faulty. # Stopped arrays aren't visible here. ret['statu...
def get_md_device(self, line, personalities=[]): """Return a dict of md device define in the line.""" ret = {} splitted = split('\W+', line) # Raid status # Active or 'started'. An inactive array is usually faulty. # Stopped arrays aren't visible here. ret['statu...
[ "Return", "a", "dict", "of", "md", "device", "define", "in", "the", "line", "." ]
nicolargo/pymdstat
python
https://github.com/nicolargo/pymdstat/blob/97fd47117e687463205fb562269feb9f95d59620/pymdstat/pymdstat.py#L126-L146
[ "def", "get_md_device", "(", "self", ",", "line", ",", "personalities", "=", "[", "]", ")", ":", "ret", "=", "{", "}", "splitted", "=", "split", "(", "'\\W+'", ",", "line", ")", "# Raid status", "# Active or 'started'. An inactive array is usually faulty.", "# S...
97fd47117e687463205fb562269feb9f95d59620
valid
MdStat.get_md_status
Return a dict of md status define in the line.
pymdstat/pymdstat.py
def get_md_status(self, line): """Return a dict of md status define in the line.""" ret = {} splitted = split('\W+', line) if len(splitted) < 7: ret['available'] = None ret['used'] = None ret['config'] = None else: # The final 2 en...
def get_md_status(self, line): """Return a dict of md status define in the line.""" ret = {} splitted = split('\W+', line) if len(splitted) < 7: ret['available'] = None ret['used'] = None ret['config'] = None else: # The final 2 en...
[ "Return", "a", "dict", "of", "md", "status", "define", "in", "the", "line", "." ]
nicolargo/pymdstat
python
https://github.com/nicolargo/pymdstat/blob/97fd47117e687463205fb562269feb9f95d59620/pymdstat/pymdstat.py#L148-L166
[ "def", "get_md_status", "(", "self", ",", "line", ")", ":", "ret", "=", "{", "}", "splitted", "=", "split", "(", "'\\W+'", ",", "line", ")", "if", "len", "(", "splitted", ")", "<", "7", ":", "ret", "[", "'available'", "]", "=", "None", "ret", "["...
97fd47117e687463205fb562269feb9f95d59620
valid
MdStat.get_components
Return a dict of components in the line. key: device name (ex: 'sdc1') value: device role number
pymdstat/pymdstat.py
def get_components(self, line, with_type=True): """Return a dict of components in the line. key: device name (ex: 'sdc1') value: device role number """ ret = {} # Ignore (F) (see test 08) line2 = reduce(lambda x, y: x + y, split('\(.+\)', line)) if with_...
def get_components(self, line, with_type=True): """Return a dict of components in the line. key: device name (ex: 'sdc1') value: device role number """ ret = {} # Ignore (F) (see test 08) line2 = reduce(lambda x, y: x + y, split('\(.+\)', line)) if with_...
[ "Return", "a", "dict", "of", "components", "in", "the", "line", "." ]
nicolargo/pymdstat
python
https://github.com/nicolargo/pymdstat/blob/97fd47117e687463205fb562269feb9f95d59620/pymdstat/pymdstat.py#L168-L184
[ "def", "get_components", "(", "self", ",", "line", ",", "with_type", "=", "True", ")", ":", "ret", "=", "{", "}", "# Ignore (F) (see test 08)", "line2", "=", "reduce", "(", "lambda", "x", ",", "y", ":", "x", "+", "y", ",", "split", "(", "'\\(.+\\)'", ...
97fd47117e687463205fb562269feb9f95d59620
valid
register_receivers
Register signal receivers which send events.
invenio_stats/receivers.py
def register_receivers(app, config): """Register signal receivers which send events.""" for event_name, event_config in config.items(): event_builders = [ obj_or_import_string(func) for func in event_config.get('event_builders', []) ] signal = obj_or_import_strin...
def register_receivers(app, config): """Register signal receivers which send events.""" for event_name, event_config in config.items(): event_builders = [ obj_or_import_string(func) for func in event_config.get('event_builders', []) ] signal = obj_or_import_strin...
[ "Register", "signal", "receivers", "which", "send", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/receivers.py#L42-L53
[ "def", "register_receivers", "(", "app", ",", "config", ")", ":", "for", "event_name", ",", "event_config", "in", "config", ".", "items", "(", ")", ":", "event_builders", "=", "[", "obj_or_import_string", "(", "func", ")", "for", "func", "in", "event_config"...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
RuleChecker.check
:param query:
protector/rules/prevent_delete.py
def check(self, query): """ :param query: """ if query.get_type() != Keyword.DELETE: return Ok(True) return Err("Delete queries are forbidden.")
def check(self, query): """ :param query: """ if query.get_type() != Keyword.DELETE: return Ok(True) return Err("Delete queries are forbidden.")
[ ":", "param", "query", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/rules/prevent_delete.py#L17-L24
[ "def", "check", "(", "self", ",", "query", ")", ":", "if", "query", ".", "get_type", "(", ")", "!=", "Keyword", ".", "DELETE", ":", "return", "Ok", "(", "True", ")", "return", "Err", "(", "\"Delete queries are forbidden.\"", ")" ]
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
InternalMailbox.set_scheduled
Returns True if state was successfully changed from idle to scheduled.
actors/internal/mailbox.py
def set_scheduled(self): """ Returns True if state was successfully changed from idle to scheduled. """ with self._idle_lock: if self._idle: self._idle = False return True return False
def set_scheduled(self): """ Returns True if state was successfully changed from idle to scheduled. """ with self._idle_lock: if self._idle: self._idle = False return True return False
[ "Returns", "True", "if", "state", "was", "successfully", "changed", "from", "idle", "to", "scheduled", "." ]
tamland/python-actors
python
https://github.com/tamland/python-actors/blob/9f826ab2947c665d61363a6ebc401e9e42cc6238/actors/internal/mailbox.py#L79-L87
[ "def", "set_scheduled", "(", "self", ")", ":", "with", "self", ".", "_idle_lock", ":", "if", "self", ".", "_idle", ":", "self", ".", "_idle", "=", "False", "return", "True", "return", "False" ]
9f826ab2947c665d61363a6ebc401e9e42cc6238
valid
StatsQueryResource.post
Get statistics.
invenio_stats/views.py
def post(self, **kwargs): """Get statistics.""" data = request.get_json(force=False) if data is None: data = {} result = {} for query_name, config in data.items(): if config is None or not isinstance(config, dict) \ or (set(config.keys(...
def post(self, **kwargs): """Get statistics.""" data = request.get_json(force=False) if data is None: data = {} result = {} for query_name, config in data.items(): if config is None or not isinstance(config, dict) \ or (set(config.keys(...
[ "Get", "statistics", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/views.py#L44-L81
[ "def", "post", "(", "self", ",", "*", "*", "kwargs", ")", ":", "data", "=", "request", ".", "get_json", "(", "force", "=", "False", ")", "if", "data", "is", "None", ":", "data", "=", "{", "}", "result", "=", "{", "}", "for", "query_name", ",", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
RuleChecker.check
:param query:
protector/rules/too_many_datapoints.py
def check(self, query): """ :param query: """ if query.get_type() not in {Keyword.SELECT, Keyword.DELETE}: # Only select and delete queries deal with time durations # All others are not affected by this rule. Bailing out. return Ok(True) datap...
def check(self, query): """ :param query: """ if query.get_type() not in {Keyword.SELECT, Keyword.DELETE}: # Only select and delete queries deal with time durations # All others are not affected by this rule. Bailing out. return Ok(True) datap...
[ ":", "param", "query", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/rules/too_many_datapoints.py#L21-L37
[ "def", "check", "(", "self", ",", "query", ")", ":", "if", "query", ".", "get_type", "(", ")", "not", "in", "{", "Keyword", ".", "SELECT", ",", "Keyword", ".", "DELETE", "}", ":", "# Only select and delete queries deal with time durations", "# All others are not...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
StatAggregator._get_oldest_event_timestamp
Search for the oldest event timestamp.
invenio_stats/aggregations.py
def _get_oldest_event_timestamp(self): """Search for the oldest event timestamp.""" # Retrieve the oldest event in order to start aggregation # from there query_events = Search( using=self.client, index=self.event_index )[0:1].sort( {'timestamp...
def _get_oldest_event_timestamp(self): """Search for the oldest event timestamp.""" # Retrieve the oldest event in order to start aggregation # from there query_events = Search( using=self.client, index=self.event_index )[0:1].sort( {'timestamp...
[ "Search", "for", "the", "oldest", "event", "timestamp", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L132-L147
[ "def", "_get_oldest_event_timestamp", "(", "self", ")", ":", "# Retrieve the oldest event in order to start aggregation", "# from there", "query_events", "=", "Search", "(", "using", "=", "self", ".", "client", ",", "index", "=", "self", ".", "event_index", ")", "[", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator.get_bookmark
Get last aggregation date.
invenio_stats/aggregations.py
def get_bookmark(self): """Get last aggregation date.""" if not Index(self.aggregation_alias, using=self.client).exists(): if not Index(self.event_index, using=self.client).exists(): return datetime.date.today() return...
def get_bookmark(self): """Get last aggregation date.""" if not Index(self.aggregation_alias, using=self.client).exists(): if not Index(self.event_index, using=self.client).exists(): return datetime.date.today() return...
[ "Get", "last", "aggregation", "date", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L149-L175
[ "def", "get_bookmark", "(", "self", ")", ":", "if", "not", "Index", "(", "self", ".", "aggregation_alias", ",", "using", "=", "self", ".", "client", ")", ".", "exists", "(", ")", ":", "if", "not", "Index", "(", "self", ".", "event_index", ",", "using...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator.set_bookmark
Set bookmark for starting next aggregation.
invenio_stats/aggregations.py
def set_bookmark(self): """Set bookmark for starting next aggregation.""" def _success_date(): bookmark = { 'date': self.new_bookmark or datetime.datetime.utcnow(). strftime(self.doc_id_suffix) } yield dict(_index=self.last_index_writt...
def set_bookmark(self): """Set bookmark for starting next aggregation.""" def _success_date(): bookmark = { 'date': self.new_bookmark or datetime.datetime.utcnow(). strftime(self.doc_id_suffix) } yield dict(_index=self.last_index_writt...
[ "Set", "bookmark", "for", "starting", "next", "aggregation", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L177-L191
[ "def", "set_bookmark", "(", "self", ")", ":", "def", "_success_date", "(", ")", ":", "bookmark", "=", "{", "'date'", ":", "self", ".", "new_bookmark", "or", "datetime", ".", "datetime", ".", "utcnow", "(", ")", ".", "strftime", "(", "self", ".", "doc_i...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator._format_range_dt
Format range filter datetime to the closest aggregation interval.
invenio_stats/aggregations.py
def _format_range_dt(self, d): """Format range filter datetime to the closest aggregation interval.""" if not isinstance(d, six.string_types): d = d.isoformat() return '{0}||/{1}'.format( d, self.dt_rounding_map[self.aggregation_interval])
def _format_range_dt(self, d): """Format range filter datetime to the closest aggregation interval.""" if not isinstance(d, six.string_types): d = d.isoformat() return '{0}||/{1}'.format( d, self.dt_rounding_map[self.aggregation_interval])
[ "Format", "range", "filter", "datetime", "to", "the", "closest", "aggregation", "interval", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L193-L198
[ "def", "_format_range_dt", "(", "self", ",", "d", ")", ":", "if", "not", "isinstance", "(", "d", ",", "six", ".", "string_types", ")", ":", "d", "=", "d", ".", "isoformat", "(", ")", "return", "'{0}||/{1}'", ".", "format", "(", "d", ",", "self", "....
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator.agg_iter
Aggregate and return dictionary to be indexed in ES.
invenio_stats/aggregations.py
def agg_iter(self, lower_limit=None, upper_limit=None): """Aggregate and return dictionary to be indexed in ES.""" lower_limit = lower_limit or self.get_bookmark().isoformat() upper_limit = upper_limit or ( datetime.datetime.utcnow().replace(microsecond=0).isoformat()) aggreg...
def agg_iter(self, lower_limit=None, upper_limit=None): """Aggregate and return dictionary to be indexed in ES.""" lower_limit = lower_limit or self.get_bookmark().isoformat() upper_limit = upper_limit or ( datetime.datetime.utcnow().replace(microsecond=0).isoformat()) aggreg...
[ "Aggregate", "and", "return", "dictionary", "to", "be", "indexed", "in", "ES", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L200-L268
[ "def", "agg_iter", "(", "self", ",", "lower_limit", "=", "None", ",", "upper_limit", "=", "None", ")", ":", "lower_limit", "=", "lower_limit", "or", "self", ".", "get_bookmark", "(", ")", ".", "isoformat", "(", ")", "upper_limit", "=", "upper_limit", "or",...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator.run
Calculate statistics aggregations.
invenio_stats/aggregations.py
def run(self, start_date=None, end_date=None, update_bookmark=True): """Calculate statistics aggregations.""" # If no events have been indexed there is nothing to aggregate if not Index(self.event_index, using=self.client).exists(): return lower_limit = start_date or self.get...
def run(self, start_date=None, end_date=None, update_bookmark=True): """Calculate statistics aggregations.""" # If no events have been indexed there is nothing to aggregate if not Index(self.event_index, using=self.client).exists(): return lower_limit = start_date or self.get...
[ "Calculate", "statistics", "aggregations", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L270-L308
[ "def", "run", "(", "self", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "update_bookmark", "=", "True", ")", ":", "# If no events have been indexed there is nothing to aggregate", "if", "not", "Index", "(", "self", ".", "event_index", ",", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator.list_bookmarks
List the aggregation's bookmarks.
invenio_stats/aggregations.py
def list_bookmarks(self, start_date=None, end_date=None, limit=None): """List the aggregation's bookmarks.""" query = Search( using=self.client, index=self.aggregation_alias, doc_type=self.bookmark_doc_type ).sort({'date': {'order': 'desc'}}) range_ar...
def list_bookmarks(self, start_date=None, end_date=None, limit=None): """List the aggregation's bookmarks.""" query = Search( using=self.client, index=self.aggregation_alias, doc_type=self.bookmark_doc_type ).sort({'date': {'order': 'desc'}}) range_ar...
[ "List", "the", "aggregation", "s", "bookmarks", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L310-L328
[ "def", "list_bookmarks", "(", "self", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "limit", "=", "None", ")", ":", "query", "=", "Search", "(", "using", "=", "self", ".", "client", ",", "index", "=", "self", ".", "aggregation_alia...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
StatAggregator.delete
Delete aggregation documents.
invenio_stats/aggregations.py
def delete(self, start_date=None, end_date=None): """Delete aggregation documents.""" aggs_query = Search( using=self.client, index=self.aggregation_alias, doc_type=self.aggregation_doc_type ).extra(_source=False) range_args = {} if start_date...
def delete(self, start_date=None, end_date=None): """Delete aggregation documents.""" aggs_query = Search( using=self.client, index=self.aggregation_alias, doc_type=self.aggregation_doc_type ).extra(_source=False) range_args = {} if start_date...
[ "Delete", "aggregation", "documents", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/aggregations.py#L330-L368
[ "def", "delete", "(", "self", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ")", ":", "aggs_query", "=", "Search", "(", "using", "=", "self", ".", "client", ",", "index", "=", "self", ".", "aggregation_alias", ",", "doc_type", "=", "sel...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ResolutionParser.parse
Extract the data resolution of a query in seconds E.g. "group by time(99s)" => 99 :param group_by_stmt: A raw InfluxDB group by statement
protector/parser/subparsers/resolution.py
def parse(self, group_by_stmt): """ Extract the data resolution of a query in seconds E.g. "group by time(99s)" => 99 :param group_by_stmt: A raw InfluxDB group by statement """ if not group_by_stmt: return Resolution.MAX_RESOLUTION m = self.GROUP_BY...
def parse(self, group_by_stmt): """ Extract the data resolution of a query in seconds E.g. "group by time(99s)" => 99 :param group_by_stmt: A raw InfluxDB group by statement """ if not group_by_stmt: return Resolution.MAX_RESOLUTION m = self.GROUP_BY...
[ "Extract", "the", "data", "resolution", "of", "a", "query", "in", "seconds", "E", ".", "g", ".", "group", "by", "time", "(", "99s", ")", "=", ">", "99" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/subparsers/resolution.py#L20-L39
[ "def", "parse", "(", "self", ",", "group_by_stmt", ")", ":", "if", "not", "group_by_stmt", ":", "return", "Resolution", ".", "MAX_RESOLUTION", "m", "=", "self", ".", "GROUP_BY_TIME_PATTERN", ".", "match", "(", "group_by_stmt", ")", "if", "not", "m", ":", "...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
Future.get
Return value on success, or raise exception on failure.
actors/future.py
def get(self, timeout=None): """ Return value on success, or raise exception on failure. """ result = None try: result = self._result.get(True, timeout=timeout) except Empty: raise Timeout() if isinstance(result, Failure): six....
def get(self, timeout=None): """ Return value on success, or raise exception on failure. """ result = None try: result = self._result.get(True, timeout=timeout) except Empty: raise Timeout() if isinstance(result, Failure): six....
[ "Return", "value", "on", "success", "or", "raise", "exception", "on", "failure", "." ]
tamland/python-actors
python
https://github.com/tamland/python-actors/blob/9f826ab2947c665d61363a6ebc401e9e42cc6238/actors/future.py#L35-L48
[ "def", "get", "(", "self", ",", "timeout", "=", "None", ")", ":", "result", "=", "None", "try", ":", "result", "=", "self", ".", "_result", ".", "get", "(", "True", ",", "timeout", "=", "timeout", ")", "except", "Empty", ":", "raise", "Timeout", "(...
9f826ab2947c665d61363a6ebc401e9e42cc6238
valid
_events_process
Process stats events.
invenio_stats/cli.py
def _events_process(event_types=None, eager=False): """Process stats events.""" event_types = event_types or list(current_stats.enabled_events) if eager: process_events.apply((event_types,), throw=True) click.secho('Events processed successfully.', fg='green') else: process_event...
def _events_process(event_types=None, eager=False): """Process stats events.""" event_types = event_types or list(current_stats.enabled_events) if eager: process_events.apply((event_types,), throw=True) click.secho('Events processed successfully.', fg='green') else: process_event...
[ "Process", "stats", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/cli.py#L83-L91
[ "def", "_events_process", "(", "event_types", "=", "None", ",", "eager", "=", "False", ")", ":", "event_types", "=", "event_types", "or", "list", "(", "current_stats", ".", "enabled_events", ")", "if", "eager", ":", "process_events", ".", "apply", "(", "(", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_aggregations_process
Process stats aggregations.
invenio_stats/cli.py
def _aggregations_process(aggregation_types=None, start_date=None, end_date=None, update_bookmark=False, eager=False): """Process stats aggregations.""" aggregation_types = (aggregation_types or list(current_stats.enabled_aggregations)...
def _aggregations_process(aggregation_types=None, start_date=None, end_date=None, update_bookmark=False, eager=False): """Process stats aggregations.""" aggregation_types = (aggregation_types or list(current_stats.enabled_aggregations)...
[ "Process", "stats", "aggregations", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/cli.py#L106-L122
[ "def", "_aggregations_process", "(", "aggregation_types", "=", "None", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "update_bookmark", "=", "False", ",", "eager", "=", "False", ")", ":", "aggregation_types", "=", "(", "aggregation_types", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_aggregations_delete
Delete computed aggregations.
invenio_stats/cli.py
def _aggregations_delete(aggregation_types=None, start_date=None, end_date=None): """Delete computed aggregations.""" aggregation_types = (aggregation_types or list(current_stats.enabled_aggregations)) for a in aggregation_types: aggr_cfg = current_s...
def _aggregations_delete(aggregation_types=None, start_date=None, end_date=None): """Delete computed aggregations.""" aggregation_types = (aggregation_types or list(current_stats.enabled_aggregations)) for a in aggregation_types: aggr_cfg = current_s...
[ "Delete", "computed", "aggregations", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/cli.py#L132-L141
[ "def", "_aggregations_delete", "(", "aggregation_types", "=", "None", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ")", ":", "aggregation_types", "=", "(", "aggregation_types", "or", "list", "(", "current_stats", ".", "enabled_aggregations", ")", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_aggregations_list_bookmarks
List aggregation bookmarks.
invenio_stats/cli.py
def _aggregations_list_bookmarks(aggregation_types=None, start_date=None, end_date=None, limit=None): """List aggregation bookmarks.""" aggregation_types = (aggregation_types or list(current_stats.enabled_aggregations)) for a in aggregation_types: ...
def _aggregations_list_bookmarks(aggregation_types=None, start_date=None, end_date=None, limit=None): """List aggregation bookmarks.""" aggregation_types = (aggregation_types or list(current_stats.enabled_aggregations)) for a in aggregation_types: ...
[ "List", "aggregation", "bookmarks", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/cli.py#L150-L162
[ "def", "_aggregations_list_bookmarks", "(", "aggregation_types", "=", "None", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "limit", "=", "None", ")", ":", "aggregation_types", "=", "(", "aggregation_types", "or", "list", "(", "current_stats...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_InvenioStatsState._events_config
Load events configuration.
invenio_stats/ext.py
def _events_config(self): """Load events configuration.""" # import iter_entry_points here so that it can be mocked in tests result = {} for ep in iter_entry_points( group=self.entry_point_group_events): for cfg in ep.load()(): if cfg['event_ty...
def _events_config(self): """Load events configuration.""" # import iter_entry_points here so that it can be mocked in tests result = {} for ep in iter_entry_points( group=self.entry_point_group_events): for cfg in ep.load()(): if cfg['event_ty...
[ "Load", "events", "configuration", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/ext.py#L44-L62
[ "def", "_events_config", "(", "self", ")", ":", "# import iter_entry_points here so that it can be mocked in tests", "result", "=", "{", "}", "for", "ep", "in", "iter_entry_points", "(", "group", "=", "self", ".", "entry_point_group_events", ")", ":", "for", "cfg", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_InvenioStatsState._aggregations_config
Load aggregation configurations.
invenio_stats/ext.py
def _aggregations_config(self): """Load aggregation configurations.""" result = {} for ep in iter_entry_points( group=self.entry_point_group_aggs): for cfg in ep.load()(): if cfg['aggregation_name'] not in self.enabled_aggregations: ...
def _aggregations_config(self): """Load aggregation configurations.""" result = {} for ep in iter_entry_points( group=self.entry_point_group_aggs): for cfg in ep.load()(): if cfg['aggregation_name'] not in self.enabled_aggregations: ...
[ "Load", "aggregation", "configurations", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/ext.py#L93-L110
[ "def", "_aggregations_config", "(", "self", ")", ":", "result", "=", "{", "}", "for", "ep", "in", "iter_entry_points", "(", "group", "=", "self", ".", "entry_point_group_aggs", ")", ":", "for", "cfg", "in", "ep", ".", "load", "(", ")", "(", ")", ":", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_InvenioStatsState._queries_config
Load queries configuration.
invenio_stats/ext.py
def _queries_config(self): """Load queries configuration.""" result = {} for ep in iter_entry_points(group=self.entry_point_group_queries): for cfg in ep.load()(): if cfg['query_name'] not in self.enabled_queries: continue elif cfg[...
def _queries_config(self): """Load queries configuration.""" result = {} for ep in iter_entry_points(group=self.entry_point_group_queries): for cfg in ep.load()(): if cfg['query_name'] not in self.enabled_queries: continue elif cfg[...
[ "Load", "queries", "configuration", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/ext.py#L138-L154
[ "def", "_queries_config", "(", "self", ")", ":", "result", "=", "{", "}", "for", "ep", "in", "iter_entry_points", "(", "group", "=", "self", ".", "entry_point_group_queries", ")", ":", "for", "cfg", "in", "ep", ".", "load", "(", ")", "(", ")", ":", "...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_InvenioStatsState.publish
Publish events.
invenio_stats/ext.py
def publish(self, event_type, events): """Publish events.""" assert event_type in self.events current_queues.queues['stats-{}'.format(event_type)].publish(events)
def publish(self, event_type, events): """Publish events.""" assert event_type in self.events current_queues.queues['stats-{}'.format(event_type)].publish(events)
[ "Publish", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/ext.py#L189-L192
[ "def", "publish", "(", "self", ",", "event_type", ",", "events", ")", ":", "assert", "event_type", "in", "self", ".", "events", "current_queues", ".", "queues", "[", "'stats-{}'", ".", "format", "(", "event_type", ")", "]", ".", "publish", "(", "events", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
_InvenioStatsState.consume
Comsume all pending events.
invenio_stats/ext.py
def consume(self, event_type, no_ack=True, payload=True): """Comsume all pending events.""" assert event_type in self.events return current_queues.queues['stats-{}'.format(event_type)].consume( payload=payload)
def consume(self, event_type, no_ack=True, payload=True): """Comsume all pending events.""" assert event_type in self.events return current_queues.queues['stats-{}'.format(event_type)].consume( payload=payload)
[ "Comsume", "all", "pending", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/ext.py#L194-L198
[ "def", "consume", "(", "self", ",", "event_type", ",", "no_ack", "=", "True", ",", "payload", "=", "True", ")", ":", "assert", "event_type", "in", "self", ".", "events", "return", "current_queues", ".", "queues", "[", "'stats-{}'", ".", "format", "(", "e...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
InvenioStats.init_app
Flask application initialization.
invenio_stats/ext.py
def init_app(self, app, entry_point_group_events='invenio_stats.events', entry_point_group_aggs='invenio_stats.aggregations', entry_point_group_queries='invenio_stats.queries'): """Flask application initialization.""" self.init_config(app) stat...
def init_app(self, app, entry_point_group_events='invenio_stats.events', entry_point_group_aggs='invenio_stats.aggregations', entry_point_group_queries='invenio_stats.queries'): """Flask application initialization.""" self.init_config(app) stat...
[ "Flask", "application", "initialization", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/ext.py#L209-L230
[ "def", "init_app", "(", "self", ",", "app", ",", "entry_point_group_events", "=", "'invenio_stats.events'", ",", "entry_point_group_aggs", "=", "'invenio_stats.aggregations'", ",", "entry_point_group_queries", "=", "'invenio_stats.queries'", ")", ":", "self", ".", "init_c...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ActorRef.tell
Send a message to this actor. Asynchronous fire-and-forget. :param message: The message to send. :type message: Any :param sender: The sender of the message. If provided it will be made available to the receiving actor via the :attr:`Actor.sender` attribute. :type sender: :...
actors/ref.py
def tell(self, message, sender=no_sender): """ Send a message to this actor. Asynchronous fire-and-forget. :param message: The message to send. :type message: Any :param sender: The sender of the message. If provided it will be made available to the receiving actor via the ...
def tell(self, message, sender=no_sender): """ Send a message to this actor. Asynchronous fire-and-forget. :param message: The message to send. :type message: Any :param sender: The sender of the message. If provided it will be made available to the receiving actor via the ...
[ "Send", "a", "message", "to", "this", "actor", ".", "Asynchronous", "fire", "-", "and", "-", "forget", "." ]
tamland/python-actors
python
https://github.com/tamland/python-actors/blob/9f826ab2947c665d61363a6ebc401e9e42cc6238/actors/ref.py#L26-L39
[ "def", "tell", "(", "self", ",", "message", ",", "sender", "=", "no_sender", ")", ":", "if", "sender", "is", "not", "no_sender", "and", "not", "isinstance", "(", "sender", ",", "ActorRef", ")", ":", "raise", "ValueError", "(", "\"Sender must be actor referen...
9f826ab2947c665d61363a6ebc401e9e42cc6238
valid
get_anonymization_salt
Get the anonymization salt based on the event timestamp's day.
invenio_stats/utils.py
def get_anonymization_salt(ts): """Get the anonymization salt based on the event timestamp's day.""" salt_key = 'stats:salt:{}'.format(ts.date().isoformat()) salt = current_cache.get(salt_key) if not salt: salt_bytes = os.urandom(32) salt = b64encode(salt_bytes).decode('utf-8') c...
def get_anonymization_salt(ts): """Get the anonymization salt based on the event timestamp's day.""" salt_key = 'stats:salt:{}'.format(ts.date().isoformat()) salt = current_cache.get(salt_key) if not salt: salt_bytes = os.urandom(32) salt = b64encode(salt_bytes).decode('utf-8') c...
[ "Get", "the", "anonymization", "salt", "based", "on", "the", "event", "timestamp", "s", "day", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/utils.py#L24-L32
[ "def", "get_anonymization_salt", "(", "ts", ")", ":", "salt_key", "=", "'stats:salt:{}'", ".", "format", "(", "ts", ".", "date", "(", ")", ".", "isoformat", "(", ")", ")", "salt", "=", "current_cache", ".", "get", "(", "salt_key", ")", "if", "not", "sa...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
get_geoip
Lookup country for IP address.
invenio_stats/utils.py
def get_geoip(ip): """Lookup country for IP address.""" reader = geolite2.reader() ip_data = reader.get(ip) or {} return ip_data.get('country', {}).get('iso_code')
def get_geoip(ip): """Lookup country for IP address.""" reader = geolite2.reader() ip_data = reader.get(ip) or {} return ip_data.get('country', {}).get('iso_code')
[ "Lookup", "country", "for", "IP", "address", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/utils.py#L35-L39
[ "def", "get_geoip", "(", "ip", ")", ":", "reader", "=", "geolite2", ".", "reader", "(", ")", "ip_data", "=", "reader", ".", "get", "(", "ip", ")", "or", "{", "}", "return", "ip_data", ".", "get", "(", "'country'", ",", "{", "}", ")", ".", "get", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
get_user
User information. .. note:: **Privacy note** A users IP address, user agent string, and user id (if logged in) is sent to a message queue, where it is stored for about 5 minutes. The information is used to: - Detect robot visits from the user agent string. - Generate an anonymi...
invenio_stats/utils.py
def get_user(): """User information. .. note:: **Privacy note** A users IP address, user agent string, and user id (if logged in) is sent to a message queue, where it is stored for about 5 minutes. The information is used to: - Detect robot visits from the user agent string. ...
def get_user(): """User information. .. note:: **Privacy note** A users IP address, user agent string, and user id (if logged in) is sent to a message queue, where it is stored for about 5 minutes. The information is used to: - Detect robot visits from the user agent string. ...
[ "User", "information", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/utils.py#L42-L64
[ "def", "get_user", "(", ")", ":", "return", "dict", "(", "ip_address", "=", "request", ".", "remote_addr", ",", "user_agent", "=", "request", ".", "user_agent", ".", "string", ",", "user_id", "=", "(", "current_user", ".", "get_id", "(", ")", "if", "curr...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
default_permission_factory
Default permission factory. It enables by default the statistics if they don't have a dedicated permission factory.
invenio_stats/utils.py
def default_permission_factory(query_name, params): """Default permission factory. It enables by default the statistics if they don't have a dedicated permission factory. """ from invenio_stats import current_stats if current_stats.queries[query_name].permission_factory is None: return ...
def default_permission_factory(query_name, params): """Default permission factory. It enables by default the statistics if they don't have a dedicated permission factory. """ from invenio_stats import current_stats if current_stats.queries[query_name].permission_factory is None: return ...
[ "Default", "permission", "factory", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/utils.py#L97-L109
[ "def", "default_permission_factory", "(", "query_name", ",", "params", ")", ":", "from", "invenio_stats", "import", "current_stats", "if", "current_stats", ".", "queries", "[", "query_name", "]", ".", "permission_factory", "is", "None", ":", "return", "AllowAllPermi...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
load_config
Load settings from default config and optionally overwrite with config file and commandline parameters (in that order).
protector/config/loader.py
def load_config(): """ Load settings from default config and optionally overwrite with config file and commandline parameters (in that order). """ # We start with the default config config = flatten(default_config.DEFAULT_CONFIG) # Read commandline arguments cli_config = flatten(par...
def load_config(): """ Load settings from default config and optionally overwrite with config file and commandline parameters (in that order). """ # We start with the default config config = flatten(default_config.DEFAULT_CONFIG) # Read commandline arguments cli_config = flatten(par...
[ "Load", "settings", "from", "default", "config", "and", "optionally", "overwrite", "with", "config", "file", "and", "commandline", "parameters", "(", "in", "that", "order", ")", "." ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/config/loader.py#L12-L39
[ "def", "load_config", "(", ")", ":", "# We start with the default config", "config", "=", "flatten", "(", "default_config", ".", "DEFAULT_CONFIG", ")", "# Read commandline arguments", "cli_config", "=", "flatten", "(", "parse_args", "(", ")", ")", "if", "\"configfile\...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
parse_configfile
Read settings from file :param configfile:
protector/config/loader.py
def parse_configfile(configfile): """ Read settings from file :param configfile: """ with open(configfile) as f: try: return yaml.safe_load(f) except Exception as e: logging.fatal("Could not load default config file: %s", e) exit(-1)
def parse_configfile(configfile): """ Read settings from file :param configfile: """ with open(configfile) as f: try: return yaml.safe_load(f) except Exception as e: logging.fatal("Could not load default config file: %s", e) exit(-1)
[ "Read", "settings", "from", "file", ":", "param", "configfile", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/config/loader.py#L48-L58
[ "def", "parse_configfile", "(", "configfile", ")", ":", "with", "open", "(", "configfile", ")", "as", "f", ":", "try", ":", "return", "yaml", ".", "safe_load", "(", "f", ")", "except", "Exception", "as", "e", ":", "logging", ".", "fatal", "(", "\"Could...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
register_templates
Register elasticsearch templates for events.
invenio_stats/templates.py
def register_templates(): """Register elasticsearch templates for events.""" event_templates = [current_stats._events_config[e] ['templates'] for e in current_stats._events_config] aggregation_templates = [current_stats._aggregations_confi...
def register_templates(): """Register elasticsearch templates for events.""" event_templates = [current_stats._events_config[e] ['templates'] for e in current_stats._events_config] aggregation_templates = [current_stats._aggregations_confi...
[ "Register", "elasticsearch", "templates", "for", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/templates.py#L14-L24
[ "def", "register_templates", "(", ")", ":", "event_templates", "=", "[", "current_stats", ".", "_events_config", "[", "e", "]", "[", "'templates'", "]", "for", "e", "in", "current_stats", ".", "_events_config", "]", "aggregation_templates", "=", "[", "current_st...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
RuleChecker.check
:param query:
protector/rules/short_series_name.py
def check(self, query): """ :param query: """ if query.get_type() in {Keyword.LIST, Keyword.DROP}: series = query.series_stmt else: series = query.from_stmt if len(series) >= self.min_series_name_length: return Ok(True) return...
def check(self, query): """ :param query: """ if query.get_type() in {Keyword.LIST, Keyword.DROP}: series = query.series_stmt else: series = query.from_stmt if len(series) >= self.min_series_name_length: return Ok(True) return...
[ ":", "param", "query", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/rules/short_series_name.py#L21-L33
[ "def", "check", "(", "self", ",", "query", ")", ":", "if", "query", ".", "get_type", "(", ")", "in", "{", "Keyword", ".", "LIST", ",", "Keyword", ".", "DROP", "}", ":", "series", "=", "query", ".", "series_stmt", "else", ":", "series", "=", "query"...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
process_events
Index statistics events.
invenio_stats/tasks.py
def process_events(event_types): """Index statistics events.""" results = [] for e in event_types: processor = current_stats.events[e].processor_class( **current_stats.events[e].processor_config) results.append((e, processor.run())) return results
def process_events(event_types): """Index statistics events.""" results = [] for e in event_types: processor = current_stats.events[e].processor_class( **current_stats.events[e].processor_config) results.append((e, processor.run())) return results
[ "Index", "statistics", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/tasks.py#L20-L27
[ "def", "process_events", "(", "event_types", ")", ":", "results", "=", "[", "]", "for", "e", "in", "event_types", ":", "processor", "=", "current_stats", ".", "events", "[", "e", "]", ".", "processor_class", "(", "*", "*", "current_stats", ".", "events", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
aggregate_events
Aggregate indexed events.
invenio_stats/tasks.py
def aggregate_events(aggregations, start_date=None, end_date=None, update_bookmark=True): """Aggregate indexed events.""" start_date = dateutil_parse(start_date) if start_date else None end_date = dateutil_parse(end_date) if end_date else None results = [] for a in aggregations:...
def aggregate_events(aggregations, start_date=None, end_date=None, update_bookmark=True): """Aggregate indexed events.""" start_date = dateutil_parse(start_date) if start_date else None end_date = dateutil_parse(end_date) if end_date else None results = [] for a in aggregations:...
[ "Aggregate", "indexed", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/tasks.py#L31-L42
[ "def", "aggregate_events", "(", "aggregations", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "update_bookmark", "=", "True", ")", ":", "start_date", "=", "dateutil_parse", "(", "start_date", ")", "if", "start_date", "else", "None", "end_d...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ask
Send a message to `actor` and return a :class:`Future` holding a possible reply. To receive a result, the actor MUST send a reply to `sender`. :param actor: :type actor: :class:`ActorRef`. :param message: :type message: :type: Any :return: A future holding the result.
actors/utils/ask.py
def ask(actor, message): """ Send a message to `actor` and return a :class:`Future` holding a possible reply. To receive a result, the actor MUST send a reply to `sender`. :param actor: :type actor: :class:`ActorRef`. :param message: :type message: :type: Any :return: A future ho...
def ask(actor, message): """ Send a message to `actor` and return a :class:`Future` holding a possible reply. To receive a result, the actor MUST send a reply to `sender`. :param actor: :type actor: :class:`ActorRef`. :param message: :type message: :type: Any :return: A future ho...
[ "Send", "a", "message", "to", "actor", "and", "return", "a", ":", "class", ":", "Future", "holding", "a", "possible", "reply", "." ]
tamland/python-actors
python
https://github.com/tamland/python-actors/blob/9f826ab2947c665d61363a6ebc401e9e42cc6238/actors/utils/ask.py#L30-L47
[ "def", "ask", "(", "actor", ",", "message", ")", ":", "sender", "=", "PromiseActorRef", "(", ")", "actor", ".", "tell", "(", "message", ",", "sender", ")", "return", "sender", ".", "promise", ".", "future" ]
9f826ab2947c665d61363a6ebc401e9e42cc6238
valid
ProxyRequestHandler.get_queries
Get a list of all queries (q=... parameters) from an URL parameter string :param parameters: The url parameter list
protector/proxy/request_handler.py
def get_queries(parameters): """ Get a list of all queries (q=... parameters) from an URL parameter string :param parameters: The url parameter list """ parsed_params = urlparse.parse_qs(parameters) if 'q' not in parsed_params: return [] queries = pars...
def get_queries(parameters): """ Get a list of all queries (q=... parameters) from an URL parameter string :param parameters: The url parameter list """ parsed_params = urlparse.parse_qs(parameters) if 'q' not in parsed_params: return [] queries = pars...
[ "Get", "a", "list", "of", "all", "queries", "(", "q", "=", "...", "parameters", ")", "from", "an", "URL", "parameter", "string", ":", "param", "parameters", ":", "The", "url", "parameter", "list" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/proxy/request_handler.py#L119-L133
[ "def", "get_queries", "(", "parameters", ")", ":", "parsed_params", "=", "urlparse", ".", "parse_qs", "(", "parameters", ")", "if", "'q'", "not", "in", "parsed_params", ":", "return", "[", "]", "queries", "=", "parsed_params", "[", "'q'", "]", "# Check if on...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
ProxyRequestHandler._handle_request
Run the actual request
protector/proxy/request_handler.py
def _handle_request(self, scheme, netloc, path, headers, body=None, method="GET"): """ Run the actual request """ backend_url = "{}://{}{}".format(scheme, netloc, path) try: response = self.http_request.request(backend_url, method=method, body=body, headers=dict(heade...
def _handle_request(self, scheme, netloc, path, headers, body=None, method="GET"): """ Run the actual request """ backend_url = "{}://{}{}".format(scheme, netloc, path) try: response = self.http_request.request(backend_url, method=method, body=body, headers=dict(heade...
[ "Run", "the", "actual", "request" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/proxy/request_handler.py#L162-L173
[ "def", "_handle_request", "(", "self", ",", "scheme", ",", "netloc", ",", "path", ",", "headers", ",", "body", "=", "None", ",", "method", "=", "\"GET\"", ")", ":", "backend_url", "=", "\"{}://{}{}\"", ".", "format", "(", "scheme", ",", "netloc", ",", ...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
ProxyRequestHandler.send_error
Send and log plain text error reply. :param code: :param message:
protector/proxy/request_handler.py
def send_error(self, code, message=None): """ Send and log plain text error reply. :param code: :param message: """ message = message.strip() self.log_error("code %d, message %s", code, message) self.send_response(code) self.send_header("Content-Ty...
def send_error(self, code, message=None): """ Send and log plain text error reply. :param code: :param message: """ message = message.strip() self.log_error("code %d, message %s", code, message) self.send_response(code) self.send_header("Content-Ty...
[ "Send", "and", "log", "plain", "text", "error", "reply", ".", ":", "param", "code", ":", ":", "param", "message", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/proxy/request_handler.py#L185-L198
[ "def", "send_error", "(", "self", ",", "code", ",", "message", "=", "None", ")", ":", "message", "=", "message", ".", "strip", "(", ")", "self", ".", "log_error", "(", "\"code %d, message %s\"", ",", "code", ",", "message", ")", "self", ".", "send_respon...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
ProxyRequestHandler._return_response
:type result: HTTPResponse
protector/proxy/request_handler.py
def _return_response(self, response): """ :type result: HTTPResponse """ self.filter_headers(response.msg) if "content-length" in response.msg: del response.msg["content-length"] self.send_response(response.status, response.reason) for header_key, hea...
def _return_response(self, response): """ :type result: HTTPResponse """ self.filter_headers(response.msg) if "content-length" in response.msg: del response.msg["content-length"] self.send_response(response.status, response.reason) for header_key, hea...
[ ":", "type", "result", ":", "HTTPResponse" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/proxy/request_handler.py#L200-L214
[ "def", "_return_response", "(", "self", ",", "response", ")", ":", "self", ".", "filter_headers", "(", "response", ".", "msg", ")", "if", "\"content-length\"", "in", "response", ".", "msg", ":", "del", "response", ".", "msg", "[", "\"content-length\"", "]", ...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
anonymize_user
Preprocess an event by anonymizing user information. The anonymization is done by removing fields that can uniquely identify a user, such as the user's ID, session ID, IP address and User Agent, and hashing them to produce a ``visitor_id`` and ``unique_session_id``. To further secure the method, a rand...
invenio_stats/processors.py
def anonymize_user(doc): """Preprocess an event by anonymizing user information. The anonymization is done by removing fields that can uniquely identify a user, such as the user's ID, session ID, IP address and User Agent, and hashing them to produce a ``visitor_id`` and ``unique_session_id``. To f...
def anonymize_user(doc): """Preprocess an event by anonymizing user information. The anonymization is done by removing fields that can uniquely identify a user, such as the user's ID, session ID, IP address and User Agent, and hashing them to produce a ``visitor_id`` and ``unique_session_id``. To f...
[ "Preprocess", "an", "event", "by", "anonymizing", "user", "information", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/processors.py#L27-L95
[ "def", "anonymize_user", "(", "doc", ")", ":", "ip", "=", "doc", ".", "pop", "(", "'ip_address'", ",", "None", ")", "if", "ip", ":", "doc", ".", "update", "(", "{", "'country'", ":", "get_geoip", "(", "ip", ")", "}", ")", "user_id", "=", "doc", "...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
hash_id
Generate event id, optimized for ES.
invenio_stats/processors.py
def hash_id(iso_timestamp, msg): """Generate event id, optimized for ES.""" return '{0}-{1}'.format(iso_timestamp, hashlib.sha1( msg.get('unique_id').encode('utf-8') + str(msg.get('visitor_id')). ...
def hash_id(iso_timestamp, msg): """Generate event id, optimized for ES.""" return '{0}-{1}'.format(iso_timestamp, hashlib.sha1( msg.get('unique_id').encode('utf-8') + str(msg.get('visitor_id')). ...
[ "Generate", "event", "id", "optimized", "for", "ES", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/processors.py#L127-L134
[ "def", "hash_id", "(", "iso_timestamp", ",", "msg", ")", ":", "return", "'{0}-{1}'", ".", "format", "(", "iso_timestamp", ",", "hashlib", ".", "sha1", "(", "msg", ".", "get", "(", "'unique_id'", ")", ".", "encode", "(", "'utf-8'", ")", "+", "str", "(",...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
EventsIndexer.actionsiter
Iterator.
invenio_stats/processors.py
def actionsiter(self): """Iterator.""" for msg in self.queue.consume(): try: for preproc in self.preprocessors: msg = preproc(msg) if msg is None: break if msg is None: continu...
def actionsiter(self): """Iterator.""" for msg in self.queue.consume(): try: for preproc in self.preprocessors: msg = preproc(msg) if msg is None: break if msg is None: continu...
[ "Iterator", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/processors.py#L171-L203
[ "def", "actionsiter", "(", "self", ")", ":", "for", "msg", "in", "self", ".", "queue", ".", "consume", "(", ")", ":", "try", ":", "for", "preproc", "in", "self", ".", "preprocessors", ":", "msg", "=", "preproc", "(", "msg", ")", "if", "msg", "is", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
EventsIndexer.run
Process events queue.
invenio_stats/processors.py
def run(self): """Process events queue.""" return elasticsearch.helpers.bulk( self.client, self.actionsiter(), stats_only=True, chunk_size=50 )
def run(self): """Process events queue.""" return elasticsearch.helpers.bulk( self.client, self.actionsiter(), stats_only=True, chunk_size=50 )
[ "Process", "events", "queue", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/processors.py#L205-L212
[ "def", "run", "(", "self", ")", ":", "return", "elasticsearch", ".", "helpers", ".", "bulk", "(", "self", ".", "client", ",", "self", ".", "actionsiter", "(", ")", ",", "stats_only", "=", "True", ",", "chunk_size", "=", "50", ")" ]
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
DatapointsParser.parse
num_datapoints = min(duration/resolution, limit) :param duration_seconds: Time duration (in seconds) for which datapoints should be returned :param resolution_seconds: Time interval (in seconds) between data points :param limit: Maximum number of datapoints to return
protector/parser/subparsers/datapoints.py
def parse(duration_seconds, resolution_seconds=Resolution.MAX_RESOLUTION, limit=None): """ num_datapoints = min(duration/resolution, limit) :param duration_seconds: Time duration (in seconds) for which datapoints should be returned :param resolution_seconds: Time interval (in seconds) b...
def parse(duration_seconds, resolution_seconds=Resolution.MAX_RESOLUTION, limit=None): """ num_datapoints = min(duration/resolution, limit) :param duration_seconds: Time duration (in seconds) for which datapoints should be returned :param resolution_seconds: Time interval (in seconds) b...
[ "num_datapoints", "=", "min", "(", "duration", "/", "resolution", "limit", ")" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/subparsers/datapoints.py#L11-L31
[ "def", "parse", "(", "duration_seconds", ",", "resolution_seconds", "=", "Resolution", ".", "MAX_RESOLUTION", ",", "limit", "=", "None", ")", ":", "if", "not", "duration_seconds", "or", "duration_seconds", "<", "0", ":", "return", "0", "if", "not", "resolution...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
DummyWriter.create_series
Write one data point for each series name to initialize the series :param num_series: Number of different series names to create :param batch_size: Number of series to create at the same time :return:
contrib/helpers/dummy_writer.py
def create_series(self, num_series, batch_size=5000): """ Write one data point for each series name to initialize the series :param num_series: Number of different series names to create :param batch_size: Number of series to create at the same time :return: """ d...
def create_series(self, num_series, batch_size=5000): """ Write one data point for each series name to initialize the series :param num_series: Number of different series names to create :param batch_size: Number of series to create at the same time :return: """ d...
[ "Write", "one", "data", "point", "for", "each", "series", "name", "to", "initialize", "the", "series", ":", "param", "num_series", ":", "Number", "of", "different", "series", "names", "to", "create", ":", "param", "batch_size", ":", "Number", "of", "series",...
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/contrib/helpers/dummy_writer.py#L36-L48
[ "def", "create_series", "(", "self", ",", "num_series", ",", "batch_size", "=", "5000", ")", ":", "datapoints", "=", "[", "]", "for", "_", "in", "range", "(", "num_series", ")", ":", "name", "=", "self", ".", "dummy_seriesname", "(", ")", "datapoints", ...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
DummyWriter.write_points
Create sample datapoints between two dates with the given resolution (in seconds) :param series_name: :param start_date: :param end_date: :param resolution: :param batch_size:
contrib/helpers/dummy_writer.py
def write_points(self, series_name, start_date, end_date, resolution=10, batch_size=5000): """ Create sample datapoints between two dates with the given resolution (in seconds) :param series_name: :param start_date: :param end_date: :param resolution: :param batch...
def write_points(self, series_name, start_date, end_date, resolution=10, batch_size=5000): """ Create sample datapoints between two dates with the given resolution (in seconds) :param series_name: :param start_date: :param end_date: :param resolution: :param batch...
[ "Create", "sample", "datapoints", "between", "two", "dates", "with", "the", "given", "resolution", "(", "in", "seconds", ")", ":", "param", "series_name", ":", ":", "param", "start_date", ":", ":", "param", "end_date", ":", ":", "param", "resolution", ":", ...
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/contrib/helpers/dummy_writer.py#L56-L80
[ "def", "write_points", "(", "self", ",", "series_name", ",", "start_date", ",", "end_date", ",", "resolution", "=", "10", ",", "batch_size", "=", "5000", ")", ":", "start_ts", "=", "int", "(", "start_date", ".", "strftime", "(", "\"%s\"", ")", ")", "end_...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
register_events
Register sample events.
invenio_stats/contrib/registrations.py
def register_events(): """Register sample events.""" return [ dict( event_type='file-download', templates='invenio_stats.contrib.file_download', processor_class=EventsIndexer, processor_config=dict( preprocessors=[ flag_...
def register_events(): """Register sample events.""" return [ dict( event_type='file-download', templates='invenio_stats.contrib.file_download', processor_class=EventsIndexer, processor_config=dict( preprocessors=[ flag_...
[ "Register", "sample", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/contrib/registrations.py#L19-L42
[ "def", "register_events", "(", ")", ":", "return", "[", "dict", "(", "event_type", "=", "'file-download'", ",", "templates", "=", "'invenio_stats.contrib.file_download'", ",", "processor_class", "=", "EventsIndexer", ",", "processor_config", "=", "dict", "(", "prepr...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
register_aggregations
Register sample aggregations.
invenio_stats/contrib/registrations.py
def register_aggregations(): """Register sample aggregations.""" return [dict( aggregation_name='file-download-agg', templates='invenio_stats.contrib.aggregations.aggr_file_download', aggregator_class=StatAggregator, aggregator_config=dict( client=current_search_clien...
def register_aggregations(): """Register sample aggregations.""" return [dict( aggregation_name='file-download-agg', templates='invenio_stats.contrib.aggregations.aggr_file_download', aggregator_class=StatAggregator, aggregator_config=dict( client=current_search_clien...
[ "Register", "sample", "aggregations", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/contrib/registrations.py#L45-L84
[ "def", "register_aggregations", "(", ")", ":", "return", "[", "dict", "(", "aggregation_name", "=", "'file-download-agg'", ",", "templates", "=", "'invenio_stats.contrib.aggregations.aggr_file_download'", ",", "aggregator_class", "=", "StatAggregator", ",", "aggregator_conf...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
register_queries
Register queries.
invenio_stats/contrib/registrations.py
def register_queries(): """Register queries.""" return [ dict( query_name='bucket-file-download-histogram', query_class=ESDateHistogramQuery, query_config=dict( index='stats-file-download', doc_type='file-download-day-aggregation', ...
def register_queries(): """Register queries.""" return [ dict( query_name='bucket-file-download-histogram', query_class=ESDateHistogramQuery, query_config=dict( index='stats-file-download', doc_type='file-download-day-aggregation', ...
[ "Register", "queries", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/contrib/registrations.py#L87-L121
[ "def", "register_queries", "(", ")", ":", "return", "[", "dict", "(", "query_name", "=", "'bucket-file-download-histogram'", ",", "query_class", "=", "ESDateHistogramQuery", ",", "query_config", "=", "dict", "(", "index", "=", "'stats-file-download'", ",", "doc_type...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
RuleChecker.check
:param query:
protector/rules/negative_groupby_statement.py
def check(self, query): """ :param query: """ if query.get_type() not in {Keyword.SELECT}: # Bailing out for non select queries return Ok(True) if query.get_resolution() > 0: return Ok(True) return Err("Group by statements need a posi...
def check(self, query): """ :param query: """ if query.get_type() not in {Keyword.SELECT}: # Bailing out for non select queries return Ok(True) if query.get_resolution() > 0: return Ok(True) return Err("Group by statements need a posi...
[ ":", "param", "query", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/rules/negative_groupby_statement.py#L17-L28
[ "def", "check", "(", "self", ",", "query", ")", ":", "if", "query", ".", "get_type", "(", ")", "not", "in", "{", "Keyword", ".", "SELECT", "}", ":", "# Bailing out for non select queries", "return", "Ok", "(", "True", ")", "if", "query", ".", "get_resolu...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
declare_queues
Index statistics events.
invenio_stats/queues.py
def declare_queues(): """Index statistics events.""" return [dict(name='stats-{0}'.format(event['event_type']), exchange=current_stats.exchange) for event in current_stats._events_config.values()]
def declare_queues(): """Index statistics events.""" return [dict(name='stats-{0}'.format(event['event_type']), exchange=current_stats.exchange) for event in current_stats._events_config.values()]
[ "Index", "statistics", "events", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queues.py#L14-L18
[ "def", "declare_queues", "(", ")", ":", "return", "[", "dict", "(", "name", "=", "'stats-{0}'", ".", "format", "(", "event", "[", "'event_type'", "]", ")", ",", "exchange", "=", "current_stats", ".", "exchange", ")", "for", "event", "in", "current_stats", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
QueryParser.parse
Parse a raw query string into fields :param raw_query_string: Raw InfluxDB query string
protector/parser/query_parser.py
def parse(self, raw_query_string): """ Parse a raw query string into fields :param raw_query_string: Raw InfluxDB query string """ self._reset() if not isinstance(raw_query_string, basestring): return None query_string = self._cleanup(raw_query_stri...
def parse(self, raw_query_string): """ Parse a raw query string into fields :param raw_query_string: Raw InfluxDB query string """ self._reset() if not isinstance(raw_query_string, basestring): return None query_string = self._cleanup(raw_query_stri...
[ "Parse", "a", "raw", "query", "string", "into", "fields", ":", "param", "raw_query_string", ":", "Raw", "InfluxDB", "query", "string" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L37-L64
[ "def", "parse", "(", "self", ",", "raw_query_string", ")", ":", "self", ".", "_reset", "(", ")", "if", "not", "isinstance", "(", "raw_query_string", ",", "basestring", ")", ":", "return", "None", "query_string", "=", "self", ".", "_cleanup", "(", "raw_quer...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser.create_query_object
Analyze query tokens and create an InfluxDBStatement from them Return None on error :param tokens: A list of InfluxDB query tokens
protector/parser/query_parser.py
def create_query_object(self, tokens): """ Analyze query tokens and create an InfluxDBStatement from them Return None on error :param tokens: A list of InfluxDB query tokens """ try: query_type = tokens['type'] return getattr(self, 'create_%s_query...
def create_query_object(self, tokens): """ Analyze query tokens and create an InfluxDBStatement from them Return None on error :param tokens: A list of InfluxDB query tokens """ try: query_type = tokens['type'] return getattr(self, 'create_%s_query...
[ "Analyze", "query", "tokens", "and", "create", "an", "InfluxDBStatement", "from", "them", "Return", "None", "on", "error", ":", "param", "tokens", ":", "A", "list", "of", "InfluxDB", "query", "tokens" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L127-L137
[ "def", "create_query_object", "(", "self", ",", "tokens", ")", ":", "try", ":", "query_type", "=", "tokens", "[", "'type'", "]", "return", "getattr", "(", "self", ",", "'create_%s_query'", "%", "query_type", ")", "(", "tokens", ")", "except", "(", "KeyErro...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser.create_select_query
Parse tokens of select query :param tokens: A list of InfluxDB query tokens
protector/parser/query_parser.py
def create_select_query(self, tokens): """ Parse tokens of select query :param tokens: A list of InfluxDB query tokens """ if not tokens[Keyword.SELECT]: return None if not tokens[Keyword.FROM]: return None return SelectQuery( ...
def create_select_query(self, tokens): """ Parse tokens of select query :param tokens: A list of InfluxDB query tokens """ if not tokens[Keyword.SELECT]: return None if not tokens[Keyword.FROM]: return None return SelectQuery( ...
[ "Parse", "tokens", "of", "select", "query", ":", "param", "tokens", ":", "A", "list", "of", "InfluxDB", "query", "tokens" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L139-L160
[ "def", "create_select_query", "(", "self", ",", "tokens", ")", ":", "if", "not", "tokens", "[", "Keyword", ".", "SELECT", "]", ":", "return", "None", "if", "not", "tokens", "[", "Keyword", ".", "FROM", "]", ":", "return", "None", "return", "SelectQuery",...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser.create_list_query
Parse tokens of list query :param tokens: A list of InfluxDB query tokens
protector/parser/query_parser.py
def create_list_query(self, tokens): """ Parse tokens of list query :param tokens: A list of InfluxDB query tokens """ if not tokens[Keyword.SERIES]: # A list series keyword is allowed # without a series name or regex tokens[Keyword.SERIES] = '...
def create_list_query(self, tokens): """ Parse tokens of list query :param tokens: A list of InfluxDB query tokens """ if not tokens[Keyword.SERIES]: # A list series keyword is allowed # without a series name or regex tokens[Keyword.SERIES] = '...
[ "Parse", "tokens", "of", "list", "query", ":", "param", "tokens", ":", "A", "list", "of", "InfluxDB", "query", "tokens" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L162-L171
[ "def", "create_list_query", "(", "self", ",", "tokens", ")", ":", "if", "not", "tokens", "[", "Keyword", ".", "SERIES", "]", ":", "# A list series keyword is allowed", "# without a series name or regex", "tokens", "[", "Keyword", ".", "SERIES", "]", "=", "''", "...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser.create_drop_query
Parse tokens of drop query :param tokens: A list of InfluxDB query tokens
protector/parser/query_parser.py
def create_drop_query(self, tokens): """ Parse tokens of drop query :param tokens: A list of InfluxDB query tokens """ if not tokens[Keyword.SERIES]: return None return DropQuery(self.parse_keyword(Keyword.SERIES, tokens))
def create_drop_query(self, tokens): """ Parse tokens of drop query :param tokens: A list of InfluxDB query tokens """ if not tokens[Keyword.SERIES]: return None return DropQuery(self.parse_keyword(Keyword.SERIES, tokens))
[ "Parse", "tokens", "of", "drop", "query", ":", "param", "tokens", ":", "A", "list", "of", "InfluxDB", "query", "tokens" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L173-L180
[ "def", "create_drop_query", "(", "self", ",", "tokens", ")", ":", "if", "not", "tokens", "[", "Keyword", ".", "SERIES", "]", ":", "return", "None", "return", "DropQuery", "(", "self", ".", "parse_keyword", "(", "Keyword", ".", "SERIES", ",", "tokens", ")...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser.create_delete_query
Parse tokens of delete query :param tokens: A list of InfluxDB query tokens
protector/parser/query_parser.py
def create_delete_query(self, tokens): """ Parse tokens of delete query :param tokens: A list of InfluxDB query tokens """ # From keyword is required if not tokens[Keyword.FROM]: return None where_stmt = self.parse_keyword(Keyword.WHERE, tokens) ...
def create_delete_query(self, tokens): """ Parse tokens of delete query :param tokens: A list of InfluxDB query tokens """ # From keyword is required if not tokens[Keyword.FROM]: return None where_stmt = self.parse_keyword(Keyword.WHERE, tokens) ...
[ "Parse", "tokens", "of", "delete", "query", ":", "param", "tokens", ":", "A", "list", "of", "InfluxDB", "query", "tokens" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L182-L197
[ "def", "create_delete_query", "(", "self", ",", "tokens", ")", ":", "# From keyword is required", "if", "not", "tokens", "[", "Keyword", ".", "FROM", "]", ":", "return", "None", "where_stmt", "=", "self", ".", "parse_keyword", "(", "Keyword", ".", "WHERE", "...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser._parse_time
Parse the date range for the query E.g. WHERE time > now() - 48h AND time < now() - 24h would result in DateRange(datetime_start, datetime_end) where datetime_start would be parsed from now() - 48h and datetime_end would be parsed from now() - 24h :param tokens:...
protector/parser/query_parser.py
def _parse_time(self, tokens): """ Parse the date range for the query E.g. WHERE time > now() - 48h AND time < now() - 24h would result in DateRange(datetime_start, datetime_end) where datetime_start would be parsed from now() - 48h and datetime_end would...
def _parse_time(self, tokens): """ Parse the date range for the query E.g. WHERE time > now() - 48h AND time < now() - 24h would result in DateRange(datetime_start, datetime_end) where datetime_start would be parsed from now() - 48h and datetime_end would...
[ "Parse", "the", "date", "range", "for", "the", "query" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L212-L226
[ "def", "_parse_time", "(", "self", ",", "tokens", ")", ":", "return", "self", ".", "time_parser", ".", "parse", "(", "self", ".", "parse_keyword", "(", "Keyword", ".", "WHERE", ",", "tokens", ")", ")" ]
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser._parse_resolution
Parse resolution from the GROUP BY statement. E.g. GROUP BY time(10s) would mean a 10 second resolution :param tokens: :return:
protector/parser/query_parser.py
def _parse_resolution(self, tokens): """ Parse resolution from the GROUP BY statement. E.g. GROUP BY time(10s) would mean a 10 second resolution :param tokens: :return: """ return self.resolution_parser.parse(self.parse_keyword(Keyword.GROUP_BY, tokens))
def _parse_resolution(self, tokens): """ Parse resolution from the GROUP BY statement. E.g. GROUP BY time(10s) would mean a 10 second resolution :param tokens: :return: """ return self.resolution_parser.parse(self.parse_keyword(Keyword.GROUP_BY, tokens))
[ "Parse", "resolution", "from", "the", "GROUP", "BY", "statement", ".", "E", ".", "g", ".", "GROUP", "BY", "time", "(", "10s", ")", "would", "mean", "a", "10", "second", "resolution", ":", "param", "tokens", ":", ":", "return", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L228-L235
[ "def", "_parse_resolution", "(", "self", ",", "tokens", ")", ":", "return", "self", ".", "resolution_parser", ".", "parse", "(", "self", ".", "parse_keyword", "(", "Keyword", ".", "GROUP_BY", ",", "tokens", ")", ")" ]
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
QueryParser._parse_datapoints
Parse the number of datapoints of a query. This can be calculated from the given duration and resolution of the query. E.g. if the query has a duation of 2*60*60 = 7200 seconds and a resolution of 10 seconds then the number of datapoints would be 7200/10 => 7200 datapoints. :param parse...
protector/parser/query_parser.py
def _parse_datapoints(self, parsed_duration, parsed_resolution, limit): """ Parse the number of datapoints of a query. This can be calculated from the given duration and resolution of the query. E.g. if the query has a duation of 2*60*60 = 7200 seconds and a resolution of 10 seconds ...
def _parse_datapoints(self, parsed_duration, parsed_resolution, limit): """ Parse the number of datapoints of a query. This can be calculated from the given duration and resolution of the query. E.g. if the query has a duation of 2*60*60 = 7200 seconds and a resolution of 10 seconds ...
[ "Parse", "the", "number", "of", "datapoints", "of", "a", "query", ".", "This", "can", "be", "calculated", "from", "the", "given", "duration", "and", "resolution", "of", "the", "query", ".", "E", ".", "g", ".", "if", "the", "query", "has", "a", "duation...
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/parser/query_parser.py#L252-L264
[ "def", "_parse_datapoints", "(", "self", ",", "parsed_duration", ",", "parsed_resolution", ",", "limit", ")", ":", "return", "self", ".", "datapoints_parser", ".", "parse", "(", "parsed_duration", ",", "parsed_resolution", ",", "limit", ")" ]
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
RuleChecker.check
:param query:
protector/rules/query_old_data.py
def check(self, query): """ :param query: """ if query.get_type() not in {Keyword.SELECT}: # Only select queries need to be checked here # All others are not affected by this rule. Bailing out. return Ok(True) earliest_date = query.get_earlies...
def check(self, query): """ :param query: """ if query.get_type() not in {Keyword.SELECT}: # Only select queries need to be checked here # All others are not affected by this rule. Bailing out. return Ok(True) earliest_date = query.get_earlies...
[ ":", "param", "query", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/rules/query_old_data.py#L22-L40
[ "def", "check", "(", "self", ",", "query", ")", ":", "if", "query", ".", "get_type", "(", ")", "not", "in", "{", "Keyword", ".", "SELECT", "}", ":", "# Only select queries need to be checked here", "# All others are not affected by this rule. Bailing out.", "return", ...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
ESQuery.extract_date
Extract date from string if necessary. :returns: the extracted date.
invenio_stats/queries.py
def extract_date(self, date): """Extract date from string if necessary. :returns: the extracted date. """ if isinstance(date, six.string_types): try: date = dateutil.parser.parse(date) except ValueError: raise ValueError( ...
def extract_date(self, date): """Extract date from string if necessary. :returns: the extracted date. """ if isinstance(date, six.string_types): try: date = dateutil.parser.parse(date) except ValueError: raise ValueError( ...
[ "Extract", "date", "from", "string", "if", "necessary", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L38-L54
[ "def", "extract_date", "(", "self", ",", "date", ")", ":", "if", "isinstance", "(", "date", ",", "six", ".", "string_types", ")", ":", "try", ":", "date", "=", "dateutil", ".", "parser", ".", "parse", "(", "date", ")", "except", "ValueError", ":", "r...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESDateHistogramQuery.validate_arguments
Validate query arguments.
invenio_stats/queries.py
def validate_arguments(self, interval, start_date, end_date, **kwargs): """Validate query arguments.""" if interval not in self.allowed_intervals: raise InvalidRequestInputError( 'Invalid aggregation time interval for statistic {}.' ).format(self.query_name) ...
def validate_arguments(self, interval, start_date, end_date, **kwargs): """Validate query arguments.""" if interval not in self.allowed_intervals: raise InvalidRequestInputError( 'Invalid aggregation time interval for statistic {}.' ).format(self.query_name) ...
[ "Validate", "query", "arguments", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L97-L108
[ "def", "validate_arguments", "(", "self", ",", "interval", ",", "start_date", ",", "end_date", ",", "*", "*", "kwargs", ")", ":", "if", "interval", "not", "in", "self", ".", "allowed_intervals", ":", "raise", "InvalidRequestInputError", "(", "'Invalid aggregatio...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESDateHistogramQuery.build_query
Build the elasticsearch query.
invenio_stats/queries.py
def build_query(self, interval, start_date, end_date, **kwargs): """Build the elasticsearch query.""" agg_query = Search(using=self.client, index=self.index, doc_type=self.doc_type)[0:0] if start_date is not None or end_date is not None: ...
def build_query(self, interval, start_date, end_date, **kwargs): """Build the elasticsearch query.""" agg_query = Search(using=self.client, index=self.index, doc_type=self.doc_type)[0:0] if start_date is not None or end_date is not None: ...
[ "Build", "the", "elasticsearch", "query", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L110-L149
[ "def", "build_query", "(", "self", ",", "interval", ",", "start_date", ",", "end_date", ",", "*", "*", "kwargs", ")", ":", "agg_query", "=", "Search", "(", "using", "=", "self", ".", "client", ",", "index", "=", "self", ".", "index", ",", "doc_type", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESDateHistogramQuery.process_query_result
Build the result using the query result.
invenio_stats/queries.py
def process_query_result(self, query_result, interval, start_date, end_date): """Build the result using the query result.""" def build_buckets(agg): """Build recursively result buckets.""" bucket_result = dict( key=agg['key'], ...
def process_query_result(self, query_result, interval, start_date, end_date): """Build the result using the query result.""" def build_buckets(agg): """Build recursively result buckets.""" bucket_result = dict( key=agg['key'], ...
[ "Build", "the", "result", "using", "the", "query", "result", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L151-L179
[ "def", "process_query_result", "(", "self", ",", "query_result", ",", "interval", ",", "start_date", ",", "end_date", ")", ":", "def", "build_buckets", "(", "agg", ")", ":", "\"\"\"Build recursively result buckets.\"\"\"", "bucket_result", "=", "dict", "(", "key", ...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESTermsQuery.validate_arguments
Validate query arguments.
invenio_stats/queries.py
def validate_arguments(self, start_date, end_date, **kwargs): """Validate query arguments.""" if set(kwargs) < set(self.required_filters): raise InvalidRequestInputError( 'Missing one of the required parameters {0} in ' 'query {1}'.format(set(self.required_fil...
def validate_arguments(self, start_date, end_date, **kwargs): """Validate query arguments.""" if set(kwargs) < set(self.required_filters): raise InvalidRequestInputError( 'Missing one of the required parameters {0} in ' 'query {1}'.format(set(self.required_fil...
[ "Validate", "query", "arguments", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L225-L232
[ "def", "validate_arguments", "(", "self", ",", "start_date", ",", "end_date", ",", "*", "*", "kwargs", ")", ":", "if", "set", "(", "kwargs", ")", "<", "set", "(", "self", ".", "required_filters", ")", ":", "raise", "InvalidRequestInputError", "(", "'Missin...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESTermsQuery.build_query
Build the elasticsearch query.
invenio_stats/queries.py
def build_query(self, start_date, end_date, **kwargs): """Build the elasticsearch query.""" agg_query = Search(using=self.client, index=self.index, doc_type=self.doc_type)[0:0] if start_date is not None or end_date is not None: ti...
def build_query(self, start_date, end_date, **kwargs): """Build the elasticsearch query.""" agg_query = Search(using=self.client, index=self.index, doc_type=self.doc_type)[0:0] if start_date is not None or end_date is not None: ti...
[ "Build", "the", "elasticsearch", "query", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L234-L276
[ "def", "build_query", "(", "self", ",", "start_date", ",", "end_date", ",", "*", "*", "kwargs", ")", ":", "agg_query", "=", "Search", "(", "using", "=", "self", ".", "client", ",", "index", "=", "self", ".", "index", ",", "doc_type", "=", "self", "."...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESTermsQuery.process_query_result
Build the result using the query result.
invenio_stats/queries.py
def process_query_result(self, query_result, start_date, end_date): """Build the result using the query result.""" def build_buckets(agg, fields, bucket_result): """Build recursively result buckets.""" # Add metric results for current bucket for metric in self.metric_...
def process_query_result(self, query_result, start_date, end_date): """Build the result using the query result.""" def build_buckets(agg, fields, bucket_result): """Build recursively result buckets.""" # Add metric results for current bucket for metric in self.metric_...
[ "Build", "the", "result", "using", "the", "query", "result", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L278-L310
[ "def", "process_query_result", "(", "self", ",", "query_result", ",", "start_date", ",", "end_date", ")", ":", "def", "build_buckets", "(", "agg", ",", "fields", ",", "bucket_result", ")", ":", "\"\"\"Build recursively result buckets.\"\"\"", "# Add metric results for c...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ESTermsQuery.run
Run the query.
invenio_stats/queries.py
def run(self, start_date=None, end_date=None, **kwargs): """Run the query.""" start_date = self.extract_date(start_date) if start_date else None end_date = self.extract_date(end_date) if end_date else None self.validate_arguments(start_date, end_date, **kwargs) agg_query = self....
def run(self, start_date=None, end_date=None, **kwargs): """Run the query.""" start_date = self.extract_date(start_date) if start_date else None end_date = self.extract_date(end_date) if end_date else None self.validate_arguments(start_date, end_date, **kwargs) agg_query = self....
[ "Run", "the", "query", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/queries.py#L312-L321
[ "def", "run", "(", "self", ",", "start_date", "=", "None", ",", "end_date", "=", "None", ",", "*", "*", "kwargs", ")", ":", "start_date", "=", "self", ".", "extract_date", "(", "start_date", ")", "if", "start_date", "else", "None", "end_date", "=", "se...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
ThreadingHTTPServer.handle_error
Overwrite error handling to suppress socket/ssl related errors :param client_address: Address of client :param request: Request causing an error
protector/proxy/server.py
def handle_error(self, request, client_address): """ Overwrite error handling to suppress socket/ssl related errors :param client_address: Address of client :param request: Request causing an error """ cls, e = sys.exc_info()[:2] if cls is socket.error or cls is s...
def handle_error(self, request, client_address): """ Overwrite error handling to suppress socket/ssl related errors :param client_address: Address of client :param request: Request causing an error """ cls, e = sys.exc_info()[:2] if cls is socket.error or cls is s...
[ "Overwrite", "error", "handling", "to", "suppress", "socket", "/", "ssl", "related", "errors", ":", "param", "client_address", ":", "Address", "of", "client", ":", "param", "request", ":", "Request", "causing", "an", "error" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/proxy/server.py#L17-L27
[ "def", "handle_error", "(", "self", ",", "request", ",", "client_address", ")", ":", "cls", ",", "e", "=", "sys", ".", "exc_info", "(", ")", "[", ":", "2", "]", "if", "cls", "is", "socket", ".", "error", "or", "cls", "is", "ssl", ".", "SSLError", ...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
file_download_event_builder
Build a file-download event.
invenio_stats/contrib/event_builders.py
def file_download_event_builder(event, sender_app, obj=None, **kwargs): """Build a file-download event.""" event.update(dict( # When: timestamp=datetime.datetime.utcnow().isoformat(), # What: bucket_id=str(obj.bucket_id), file_id=str(obj.file_id), file_key=obj.key...
def file_download_event_builder(event, sender_app, obj=None, **kwargs): """Build a file-download event.""" event.update(dict( # When: timestamp=datetime.datetime.utcnow().isoformat(), # What: bucket_id=str(obj.bucket_id), file_id=str(obj.file_id), file_key=obj.key...
[ "Build", "a", "file", "-", "download", "event", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/contrib/event_builders.py#L20-L34
[ "def", "file_download_event_builder", "(", "event", ",", "sender_app", ",", "obj", "=", "None", ",", "*", "*", "kwargs", ")", ":", "event", ".", "update", "(", "dict", "(", "# When:", "timestamp", "=", "datetime", ".", "datetime", ".", "utcnow", "(", ")"...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
record_view_event_builder
Build a record-view event.
invenio_stats/contrib/event_builders.py
def record_view_event_builder(event, sender_app, pid=None, record=None, **kwargs): """Build a record-view event.""" event.update(dict( # When: timestamp=datetime.datetime.utcnow().isoformat(), # What: record_id=str(record.id), pid_type=pid.pi...
def record_view_event_builder(event, sender_app, pid=None, record=None, **kwargs): """Build a record-view event.""" event.update(dict( # When: timestamp=datetime.datetime.utcnow().isoformat(), # What: record_id=str(record.id), pid_type=pid.pi...
[ "Build", "a", "record", "-", "view", "event", "." ]
inveniosoftware/invenio-stats
python
https://github.com/inveniosoftware/invenio-stats/blob/d877ae5462084abb4a28a20f1ebb3d636769c1bc/invenio_stats/contrib/event_builders.py#L49-L63
[ "def", "record_view_event_builder", "(", "event", ",", "sender_app", ",", "pid", "=", "None", ",", "record", "=", "None", ",", "*", "*", "kwargs", ")", ":", "event", ".", "update", "(", "dict", "(", "# When:", "timestamp", "=", "datetime", ".", "datetime...
d877ae5462084abb4a28a20f1ebb3d636769c1bc
valid
main
Setup consumer
protector/__main__.py
def main(): """ Setup consumer """ config = loader.load_config() if config.version: show_version() if config.show_rules: show_rules() if not config.configfile and not (hasattr(config, "status") or hasattr(config, "stop")): show_configfile_warning() # Check if we ...
def main(): """ Setup consumer """ config = loader.load_config() if config.version: show_version() if config.show_rules: show_rules() if not config.configfile and not (hasattr(config, "status") or hasattr(config, "stop")): show_configfile_warning() # Check if we ...
[ "Setup", "consumer" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/__main__.py#L16-L30
[ "def", "main", "(", ")", ":", "config", "=", "loader", ".", "load_config", "(", ")", "if", "config", ".", "version", ":", "show_version", "(", ")", "if", "config", ".", "show_rules", ":", "show_rules", "(", ")", "if", "not", "config", ".", "configfile"...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
check_write_permissions
Check if we can write to the given file Otherwise since we might detach the process to run in the background we might never find out that writing failed and get an ugly exit message on startup. For example: ERROR: Child exited immediately with non-zero exit code 127 So we catch this error upfront ...
protector/__main__.py
def check_write_permissions(file): """ Check if we can write to the given file Otherwise since we might detach the process to run in the background we might never find out that writing failed and get an ugly exit message on startup. For example: ERROR: Child exited immediately with non-zero exi...
def check_write_permissions(file): """ Check if we can write to the given file Otherwise since we might detach the process to run in the background we might never find out that writing failed and get an ugly exit message on startup. For example: ERROR: Child exited immediately with non-zero exi...
[ "Check", "if", "we", "can", "write", "to", "the", "given", "file" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/__main__.py#L33-L50
[ "def", "check_write_permissions", "(", "file", ")", ":", "try", ":", "open", "(", "file", ",", "'a'", ")", "except", "IOError", ":", "print", "(", "\"Can't open file {}. \"", "\"Please grant write permissions or change the path in your config\"", ".", "format", "(", "...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
show_rules
Show the list of available rules and quit :return:
protector/__main__.py
def show_rules(): """ Show the list of available rules and quit :return: """ from rules.loader import import_rules from rules.rule_list import all_rules rules = import_rules(all_rules) print("") for name, rule in rules.iteritems(): heading = "{} (`{}`)".format(rule.descriptio...
def show_rules(): """ Show the list of available rules and quit :return: """ from rules.loader import import_rules from rules.rule_list import all_rules rules = import_rules(all_rules) print("") for name, rule in rules.iteritems(): heading = "{} (`{}`)".format(rule.descriptio...
[ "Show", "the", "list", "of", "available", "rules", "and", "quit", ":", "return", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/__main__.py#L53-L68
[ "def", "show_rules", "(", ")", ":", "from", "rules", ".", "loader", "import", "import_rules", "from", "rules", ".", "rule_list", "import", "all_rules", "rules", "=", "import_rules", "(", "all_rules", ")", "print", "(", "\"\"", ")", "for", "name", ",", "rul...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
start_proxy
Start the http proxy :param config: :return:
protector/__main__.py
def start_proxy(config): """ Start the http proxy :param config: :return: """ protector = Protector(config.rules, config.whitelist) protector_daemon = ProtectorDaemon(config=config, protector=protector) daemon = daemonocle.Daemon( pidfile=config.pidfile, detach=(not conf...
def start_proxy(config): """ Start the http proxy :param config: :return: """ protector = Protector(config.rules, config.whitelist) protector_daemon = ProtectorDaemon(config=config, protector=protector) daemon = daemonocle.Daemon( pidfile=config.pidfile, detach=(not conf...
[ "Start", "the", "http", "proxy", ":", "param", "config", ":", ":", "return", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/protector/__main__.py#L92-L107
[ "def", "start_proxy", "(", "config", ")", ":", "protector", "=", "Protector", "(", "config", ".", "rules", ",", "config", ".", "whitelist", ")", "protector_daemon", "=", "ProtectorDaemon", "(", "config", "=", "config", ",", "protector", "=", "protector", ")"...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
batches
From http://stackoverflow.com/a/8290508/270334 :param n: :param iterable:
contrib/helpers/benchmark.py
def batches(iterable, n=1): """ From http://stackoverflow.com/a/8290508/270334 :param n: :param iterable: """ l = len(iterable) for ndx in range(0, l, n): yield iterable[ndx:min(ndx + n, l)]
def batches(iterable, n=1): """ From http://stackoverflow.com/a/8290508/270334 :param n: :param iterable: """ l = len(iterable) for ndx in range(0, l, n): yield iterable[ndx:min(ndx + n, l)]
[ "From", "http", ":", "//", "stackoverflow", ".", "com", "/", "a", "/", "8290508", "/", "270334", ":", "param", "n", ":", ":", "param", "iterable", ":" ]
trivago/Protector
python
https://github.com/trivago/Protector/blob/7ebe7bde965e27737b961a0cb5740724d174fdc7/contrib/helpers/benchmark.py#L9-L17
[ "def", "batches", "(", "iterable", ",", "n", "=", "1", ")", ":", "l", "=", "len", "(", "iterable", ")", "for", "ndx", "in", "range", "(", "0", ",", "l", ",", "n", ")", ":", "yield", "iterable", "[", "ndx", ":", "min", "(", "ndx", "+", "n", ...
7ebe7bde965e27737b961a0cb5740724d174fdc7
valid
_is_root
Checks if the user is rooted.
jupyterpip/__init__.py
def _is_root(): """Checks if the user is rooted.""" import os import ctypes try: return os.geteuid() == 0 except AttributeError: return ctypes.windll.shell32.IsUserAnAdmin() != 0 return False
def _is_root(): """Checks if the user is rooted.""" import os import ctypes try: return os.geteuid() == 0 except AttributeError: return ctypes.windll.shell32.IsUserAnAdmin() != 0 return False
[ "Checks", "if", "the", "user", "is", "rooted", "." ]
jdfreder/jupyter-pip
python
https://github.com/jdfreder/jupyter-pip/blob/9f04c6096f1169b08aeaf6221616a5fb48111044/jupyterpip/__init__.py#L1-L9
[ "def", "_is_root", "(", ")", ":", "import", "os", "import", "ctypes", "try", ":", "return", "os", ".", "geteuid", "(", ")", "==", "0", "except", "AttributeError", ":", "return", "ctypes", ".", "windll", ".", "shell32", ".", "IsUserAnAdmin", "(", ")", "...
9f04c6096f1169b08aeaf6221616a5fb48111044