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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | ComplementMembership | Change (x not in y) to not(x in y). | efilter/parsers/common/ast_transforms.py | def ComplementMembership(*args, **kwargs):
"""Change (x not in y) to not(x in y)."""
return ast.Complement(
ast.Membership(*args, **kwargs), **kwargs) | def ComplementMembership(*args, **kwargs):
"""Change (x not in y) to not(x in y)."""
return ast.Complement(
ast.Membership(*args, **kwargs), **kwargs) | [
"Change",
"(",
"x",
"not",
"in",
"y",
")",
"to",
"not",
"(",
"x",
"in",
"y",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/ast_transforms.py#L49-L52 | [
"def",
"ComplementMembership",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"ast",
".",
"Complement",
"(",
"ast",
".",
"Membership",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
",",
"*",
"*",
"kwargs",
")"
] | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | ReverseComplementMembership | Change (x doesn't contain y) to not(y in x). | efilter/parsers/common/ast_transforms.py | def ReverseComplementMembership(x, y, **kwargs):
"""Change (x doesn't contain y) to not(y in x)."""
return ast.Complement(
ast.Membership(y, x, **kwargs), **kwargs) | def ReverseComplementMembership(x, y, **kwargs):
"""Change (x doesn't contain y) to not(y in x)."""
return ast.Complement(
ast.Membership(y, x, **kwargs), **kwargs) | [
"Change",
"(",
"x",
"doesn",
"t",
"contain",
"y",
")",
"to",
"not",
"(",
"y",
"in",
"x",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/ast_transforms.py#L60-L63 | [
"def",
"ReverseComplementMembership",
"(",
"x",
",",
"y",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"ast",
".",
"Complement",
"(",
"ast",
".",
"Membership",
"(",
"y",
",",
"x",
",",
"*",
"*",
"kwargs",
")",
",",
"*",
"*",
"kwargs",
")"
] | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | __solve_for_repeated | Helper: solve 'expr' always returning an IRepeated.
If the result of solving 'expr' is a list or a tuple of IStructured objects
then treat is as a repeated value of IStructured objects because that's
what the called meant to do. This is a convenience helper so users of the
API don't have to create IRep... | efilter/transforms/solve.py | def __solve_for_repeated(expr, vars):
"""Helper: solve 'expr' always returning an IRepeated.
If the result of solving 'expr' is a list or a tuple of IStructured objects
then treat is as a repeated value of IStructured objects because that's
what the called meant to do. This is a convenience helper so u... | def __solve_for_repeated(expr, vars):
"""Helper: solve 'expr' always returning an IRepeated.
If the result of solving 'expr' is a list or a tuple of IStructured objects
then treat is as a repeated value of IStructured objects because that's
what the called meant to do. This is a convenience helper so u... | [
"Helper",
":",
"solve",
"expr",
"always",
"returning",
"an",
"IRepeated",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L84-L108 | [
"def",
"__solve_for_repeated",
"(",
"expr",
",",
"vars",
")",
":",
"var",
"=",
"solve",
"(",
"expr",
",",
"vars",
")",
".",
"value",
"if",
"(",
"var",
"and",
"isinstance",
"(",
"var",
",",
"(",
"tuple",
",",
"list",
")",
")",
"and",
"protocol",
"."... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | __solve_for_scalar | Helper: solve 'expr' always returning a scalar (not IRepeated).
If the output of 'expr' is a single value or a single RowTuple with a single
column then return the value in that column. Otherwise raise.
Arguments:
expr: Expression to solve.
vars: The scope.
Returns:
A scalar v... | efilter/transforms/solve.py | def __solve_for_scalar(expr, vars):
"""Helper: solve 'expr' always returning a scalar (not IRepeated).
If the output of 'expr' is a single value or a single RowTuple with a single
column then return the value in that column. Otherwise raise.
Arguments:
expr: Expression to solve.
vars: ... | def __solve_for_scalar(expr, vars):
"""Helper: solve 'expr' always returning a scalar (not IRepeated).
If the output of 'expr' is a single value or a single RowTuple with a single
column then return the value in that column. Otherwise raise.
Arguments:
expr: Expression to solve.
vars: ... | [
"Helper",
":",
"solve",
"expr",
"always",
"returning",
"a",
"scalar",
"(",
"not",
"IRepeated",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L111-L145 | [
"def",
"__solve_for_scalar",
"(",
"expr",
",",
"vars",
")",
":",
"var",
"=",
"solve",
"(",
"expr",
",",
"vars",
")",
".",
"value",
"try",
":",
"scalar",
"=",
"repeated",
".",
"getvalue",
"(",
"var",
")",
"except",
"TypeError",
":",
"raise",
"errors",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | __solve_and_destructure_repeated | Helper: solve 'expr' always returning a list of scalars.
If the output of 'expr' is one or more row tuples with only a single column
then return a repeated value of values in that column. If there are more
than one column per row then raise.
This returns a list because there's no point in wrapping the... | efilter/transforms/solve.py | def __solve_and_destructure_repeated(expr, vars):
"""Helper: solve 'expr' always returning a list of scalars.
If the output of 'expr' is one or more row tuples with only a single column
then return a repeated value of values in that column. If there are more
than one column per row then raise.
Thi... | def __solve_and_destructure_repeated(expr, vars):
"""Helper: solve 'expr' always returning a list of scalars.
If the output of 'expr' is one or more row tuples with only a single column
then return a repeated value of values in that column. If there are more
than one column per row then raise.
Thi... | [
"Helper",
":",
"solve",
"expr",
"always",
"returning",
"a",
"list",
"of",
"scalars",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L148-L195 | [
"def",
"__solve_and_destructure_repeated",
"(",
"expr",
",",
"vars",
")",
":",
"iterable",
",",
"isrepeating",
"=",
"__solve_for_repeated",
"(",
"expr",
",",
"vars",
")",
"if",
"iterable",
"is",
"None",
":",
"return",
"(",
")",
",",
"isrepeating",
"if",
"not... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_var | Returns the value of the var named in the expression. | efilter/transforms/solve.py | def solve_var(expr, vars):
"""Returns the value of the var named in the expression."""
try:
return Result(structured.resolve(vars, expr.value), ())
except (KeyError, AttributeError) as e:
# Raise a better exception for accessing a non-existent member.
raise errors.EfilterKeyError(roo... | def solve_var(expr, vars):
"""Returns the value of the var named in the expression."""
try:
return Result(structured.resolve(vars, expr.value), ())
except (KeyError, AttributeError) as e:
# Raise a better exception for accessing a non-existent member.
raise errors.EfilterKeyError(roo... | [
"Returns",
"the",
"value",
"of",
"the",
"var",
"named",
"in",
"the",
"expression",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L234-L256 | [
"def",
"solve_var",
"(",
"expr",
",",
"vars",
")",
":",
"try",
":",
"return",
"Result",
"(",
"structured",
".",
"resolve",
"(",
"vars",
",",
"expr",
".",
"value",
")",
",",
"(",
")",
")",
"except",
"(",
"KeyError",
",",
"AttributeError",
")",
"as",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_select | Use IAssociative.select to get key (rhs) from the data (lhs).
This operation supports both scalars and repeated values on the LHS -
selecting from a repeated value implies a map-like operation and returns a
new repeated value. | efilter/transforms/solve.py | def solve_select(expr, vars):
"""Use IAssociative.select to get key (rhs) from the data (lhs).
This operation supports both scalars and repeated values on the LHS -
selecting from a repeated value implies a map-like operation and returns a
new repeated value.
"""
data, _ = __solve_for_repeated(... | def solve_select(expr, vars):
"""Use IAssociative.select to get key (rhs) from the data (lhs).
This operation supports both scalars and repeated values on the LHS -
selecting from a repeated value implies a map-like operation and returns a
new repeated value.
"""
data, _ = __solve_for_repeated(... | [
"Use",
"IAssociative",
".",
"select",
"to",
"get",
"key",
"(",
"rhs",
")",
"from",
"the",
"data",
"(",
"lhs",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L260-L288 | [
"def",
"solve_select",
"(",
"expr",
",",
"vars",
")",
":",
"data",
",",
"_",
"=",
"__solve_for_repeated",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"key",
"=",
"solve",
"(",
"expr",
".",
"rhs",
",",
"vars",
")",
".",
"value",
"try",
":",
"results"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_resolve | Use IStructured.resolve to get member (rhs) from the object (lhs).
This operation supports both scalars and repeated values on the LHS -
resolving from a repeated value implies a map-like operation and returns a
new repeated values. | efilter/transforms/solve.py | def solve_resolve(expr, vars):
"""Use IStructured.resolve to get member (rhs) from the object (lhs).
This operation supports both scalars and repeated values on the LHS -
resolving from a repeated value implies a map-like operation and returns a
new repeated values.
"""
objs, _ = __solve_for_re... | def solve_resolve(expr, vars):
"""Use IStructured.resolve to get member (rhs) from the object (lhs).
This operation supports both scalars and repeated values on the LHS -
resolving from a repeated value implies a map-like operation and returns a
new repeated values.
"""
objs, _ = __solve_for_re... | [
"Use",
"IStructured",
".",
"resolve",
"to",
"get",
"member",
"(",
"rhs",
")",
"from",
"the",
"object",
"(",
"lhs",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L292-L322 | [
"def",
"solve_resolve",
"(",
"expr",
",",
"vars",
")",
":",
"objs",
",",
"_",
"=",
"__solve_for_repeated",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"member",
"=",
"solve",
"(",
"expr",
".",
"rhs",
",",
"vars",
")",
".",
"value",
"try",
":",
"resu... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_apply | Returns the result of applying function (lhs) to its arguments (rest).
We use IApplicative to apply the function, because that gives the host
application an opportunity to compare the function being called against
a whitelist. EFILTER will never directly call a function that wasn't
provided through a p... | efilter/transforms/solve.py | def solve_apply(expr, vars):
"""Returns the result of applying function (lhs) to its arguments (rest).
We use IApplicative to apply the function, because that gives the host
application an opportunity to compare the function being called against
a whitelist. EFILTER will never directly call a function ... | def solve_apply(expr, vars):
"""Returns the result of applying function (lhs) to its arguments (rest).
We use IApplicative to apply the function, because that gives the host
application an opportunity to compare the function being called against
a whitelist. EFILTER will never directly call a function ... | [
"Returns",
"the",
"result",
"of",
"applying",
"function",
"(",
"lhs",
")",
"to",
"its",
"arguments",
"(",
"rest",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L326-L350 | [
"def",
"solve_apply",
"(",
"expr",
",",
"vars",
")",
":",
"func",
"=",
"__solve_for_scalar",
"(",
"expr",
".",
"func",
",",
"vars",
")",
"args",
"=",
"[",
"]",
"kwargs",
"=",
"{",
"}",
"for",
"arg",
"in",
"expr",
".",
"args",
":",
"if",
"isinstance... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_bind | Build a RowTuple from key/value pairs under the bind.
The Bind subtree is arranged as follows:
Bind
| First KV Pair
| | First Key Expression
| | First Value Expression
| Second KV Pair
| | Second Key Expression
| | Second Value Expression
Etc...
As we evaluate the subtree, eac... | efilter/transforms/solve.py | def solve_bind(expr, vars):
"""Build a RowTuple from key/value pairs under the bind.
The Bind subtree is arranged as follows:
Bind
| First KV Pair
| | First Key Expression
| | First Value Expression
| Second KV Pair
| | Second Key Expression
| | Second Value Expression
Etc...
... | def solve_bind(expr, vars):
"""Build a RowTuple from key/value pairs under the bind.
The Bind subtree is arranged as follows:
Bind
| First KV Pair
| | First Key Expression
| | First Value Expression
| Second KV Pair
| | Second Key Expression
| | Second Value Expression
Etc...
... | [
"Build",
"a",
"RowTuple",
"from",
"key",
"/",
"value",
"pairs",
"under",
"the",
"bind",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L354-L388 | [
"def",
"solve_bind",
"(",
"expr",
",",
"vars",
")",
":",
"value_expressions",
"=",
"[",
"]",
"keys",
"=",
"[",
"]",
"for",
"pair",
"in",
"expr",
".",
"children",
":",
"keys",
".",
"append",
"(",
"solve",
"(",
"pair",
".",
"key",
",",
"vars",
")",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_repeat | Build a repeated value from subexpressions. | efilter/transforms/solve.py | def solve_repeat(expr, vars):
"""Build a repeated value from subexpressions."""
try:
result = repeated.meld(*[solve(x, vars).value for x in expr.children])
return Result(result, ())
except TypeError:
raise errors.EfilterTypeError(
root=expr, query=expr.source,
... | def solve_repeat(expr, vars):
"""Build a repeated value from subexpressions."""
try:
result = repeated.meld(*[solve(x, vars).value for x in expr.children])
return Result(result, ())
except TypeError:
raise errors.EfilterTypeError(
root=expr, query=expr.source,
... | [
"Build",
"a",
"repeated",
"value",
"from",
"subexpressions",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L392-L400 | [
"def",
"solve_repeat",
"(",
"expr",
",",
"vars",
")",
":",
"try",
":",
"result",
"=",
"repeated",
".",
"meld",
"(",
"*",
"[",
"solve",
"(",
"x",
",",
"vars",
")",
".",
"value",
"for",
"x",
"in",
"expr",
".",
"children",
"]",
")",
"return",
"Resul... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_tuple | Build a tuple from subexpressions. | efilter/transforms/solve.py | def solve_tuple(expr, vars):
"""Build a tuple from subexpressions."""
result = tuple(solve(x, vars).value for x in expr.children)
return Result(result, ()) | def solve_tuple(expr, vars):
"""Build a tuple from subexpressions."""
result = tuple(solve(x, vars).value for x in expr.children)
return Result(result, ()) | [
"Build",
"a",
"tuple",
"from",
"subexpressions",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L404-L407 | [
"def",
"solve_tuple",
"(",
"expr",
",",
"vars",
")",
":",
"result",
"=",
"tuple",
"(",
"solve",
"(",
"x",
",",
"vars",
")",
".",
"value",
"for",
"x",
"in",
"expr",
".",
"children",
")",
"return",
"Result",
"(",
"result",
",",
"(",
")",
")"
] | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_ifelse | Evaluate conditions and return the one that matches. | efilter/transforms/solve.py | def solve_ifelse(expr, vars):
"""Evaluate conditions and return the one that matches."""
for condition, result in expr.conditions():
if boolean.asbool(solve(condition, vars).value):
return solve(result, vars)
return solve(expr.default(), vars) | def solve_ifelse(expr, vars):
"""Evaluate conditions and return the one that matches."""
for condition, result in expr.conditions():
if boolean.asbool(solve(condition, vars).value):
return solve(result, vars)
return solve(expr.default(), vars) | [
"Evaluate",
"conditions",
"and",
"return",
"the",
"one",
"that",
"matches",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L411-L417 | [
"def",
"solve_ifelse",
"(",
"expr",
",",
"vars",
")",
":",
"for",
"condition",
",",
"result",
"in",
"expr",
".",
"conditions",
"(",
")",
":",
"if",
"boolean",
".",
"asbool",
"(",
"solve",
"(",
"condition",
",",
"vars",
")",
".",
"value",
")",
":",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_map | Solves the map-form, by recursively calling its RHS with new vars.
let-forms are binary expressions. The LHS should evaluate to an IAssociative
that can be used as new vars with which to solve a new query, of which
the RHS is the root. In most cases, the LHS will be a Var (var).
Typically, map-forms r... | efilter/transforms/solve.py | def solve_map(expr, vars):
"""Solves the map-form, by recursively calling its RHS with new vars.
let-forms are binary expressions. The LHS should evaluate to an IAssociative
that can be used as new vars with which to solve a new query, of which
the RHS is the root. In most cases, the LHS will be a Var ... | def solve_map(expr, vars):
"""Solves the map-form, by recursively calling its RHS with new vars.
let-forms are binary expressions. The LHS should evaluate to an IAssociative
that can be used as new vars with which to solve a new query, of which
the RHS is the root. In most cases, the LHS will be a Var ... | [
"Solves",
"the",
"map",
"-",
"form",
"by",
"recursively",
"calling",
"its",
"RHS",
"with",
"new",
"vars",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L421-L446 | [
"def",
"solve_map",
"(",
"expr",
",",
"vars",
")",
":",
"lhs_values",
",",
"_",
"=",
"__solve_for_repeated",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"def",
"lazy_map",
"(",
")",
":",
"try",
":",
"for",
"lhs_value",
"in",
"repeated",
".",
"getvalues"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_let | Solves a let-form by calling RHS with nested scope. | efilter/transforms/solve.py | def solve_let(expr, vars):
"""Solves a let-form by calling RHS with nested scope."""
lhs_value = solve(expr.lhs, vars).value
if not isinstance(lhs_value, structured.IStructured):
raise errors.EfilterTypeError(
root=expr.lhs, query=expr.original,
message="The LHS of 'let' must... | def solve_let(expr, vars):
"""Solves a let-form by calling RHS with nested scope."""
lhs_value = solve(expr.lhs, vars).value
if not isinstance(lhs_value, structured.IStructured):
raise errors.EfilterTypeError(
root=expr.lhs, query=expr.original,
message="The LHS of 'let' must... | [
"Solves",
"a",
"let",
"-",
"form",
"by",
"calling",
"RHS",
"with",
"nested",
"scope",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L450-L459 | [
"def",
"solve_let",
"(",
"expr",
",",
"vars",
")",
":",
"lhs_value",
"=",
"solve",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
".",
"value",
"if",
"not",
"isinstance",
"(",
"lhs_value",
",",
"structured",
".",
"IStructured",
")",
":",
"raise",
"errors",... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_filter | Filter values on the LHS by evaluating RHS with each value.
Returns any LHS values for which RHS evaluates to a true value. | efilter/transforms/solve.py | def solve_filter(expr, vars):
"""Filter values on the LHS by evaluating RHS with each value.
Returns any LHS values for which RHS evaluates to a true value.
"""
lhs_values, _ = __solve_for_repeated(expr.lhs, vars)
def lazy_filter():
for lhs_value in repeated.getvalues(lhs_values):
... | def solve_filter(expr, vars):
"""Filter values on the LHS by evaluating RHS with each value.
Returns any LHS values for which RHS evaluates to a true value.
"""
lhs_values, _ = __solve_for_repeated(expr.lhs, vars)
def lazy_filter():
for lhs_value in repeated.getvalues(lhs_values):
... | [
"Filter",
"values",
"on",
"the",
"LHS",
"by",
"evaluating",
"RHS",
"with",
"each",
"value",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L463-L475 | [
"def",
"solve_filter",
"(",
"expr",
",",
"vars",
")",
":",
"lhs_values",
",",
"_",
"=",
"__solve_for_repeated",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"def",
"lazy_filter",
"(",
")",
":",
"for",
"lhs_value",
"in",
"repeated",
".",
"getvalues",
"(",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_sort | Sort values on the LHS by the value they yield when passed to RHS. | efilter/transforms/solve.py | def solve_sort(expr, vars):
"""Sort values on the LHS by the value they yield when passed to RHS."""
lhs_values = repeated.getvalues(__solve_for_repeated(expr.lhs, vars)[0])
sort_expression = expr.rhs
def _key_func(x):
return solve(sort_expression, __nest_scope(expr.lhs, vars, x)).value
r... | def solve_sort(expr, vars):
"""Sort values on the LHS by the value they yield when passed to RHS."""
lhs_values = repeated.getvalues(__solve_for_repeated(expr.lhs, vars)[0])
sort_expression = expr.rhs
def _key_func(x):
return solve(sort_expression, __nest_scope(expr.lhs, vars, x)).value
r... | [
"Sort",
"values",
"on",
"the",
"LHS",
"by",
"the",
"value",
"they",
"yield",
"when",
"passed",
"to",
"RHS",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L528-L539 | [
"def",
"solve_sort",
"(",
"expr",
",",
"vars",
")",
":",
"lhs_values",
"=",
"repeated",
".",
"getvalues",
"(",
"__solve_for_repeated",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"[",
"0",
"]",
")",
"sort_expression",
"=",
"expr",
".",
"rhs",
"def",
"_k... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_each | Return True if RHS evaluates to a true value with each state of LHS.
If LHS evaluates to a normal IAssociative object then this is the same as
a regular let-form, except the return value is always a boolean. If LHS
evaluates to a repeared var (see efilter.protocols.repeated) of
IAssociative objects the... | efilter/transforms/solve.py | def solve_each(expr, vars):
"""Return True if RHS evaluates to a true value with each state of LHS.
If LHS evaluates to a normal IAssociative object then this is the same as
a regular let-form, except the return value is always a boolean. If LHS
evaluates to a repeared var (see efilter.protocols.repeat... | def solve_each(expr, vars):
"""Return True if RHS evaluates to a true value with each state of LHS.
If LHS evaluates to a normal IAssociative object then this is the same as
a regular let-form, except the return value is always a boolean. If LHS
evaluates to a repeared var (see efilter.protocols.repeat... | [
"Return",
"True",
"if",
"RHS",
"evaluates",
"to",
"a",
"true",
"value",
"with",
"each",
"state",
"of",
"LHS",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L543-L560 | [
"def",
"solve_each",
"(",
"expr",
",",
"vars",
")",
":",
"lhs_values",
",",
"_",
"=",
"__solve_for_repeated",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"for",
"lhs_value",
"in",
"repeated",
".",
"getvalues",
"(",
"lhs_values",
")",
":",
"result",
"=",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_cast | Get cast LHS to RHS. | efilter/transforms/solve.py | def solve_cast(expr, vars):
"""Get cast LHS to RHS."""
lhs = solve(expr.lhs, vars).value
t = solve(expr.rhs, vars).value
if t is None:
raise errors.EfilterTypeError(
root=expr, query=expr.source,
message="Cannot find type named %r." % expr.rhs.value)
if not isinstan... | def solve_cast(expr, vars):
"""Get cast LHS to RHS."""
lhs = solve(expr.lhs, vars).value
t = solve(expr.rhs, vars).value
if t is None:
raise errors.EfilterTypeError(
root=expr, query=expr.source,
message="Cannot find type named %r." % expr.rhs.value)
if not isinstan... | [
"Get",
"cast",
"LHS",
"to",
"RHS",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L586-L608 | [
"def",
"solve_cast",
"(",
"expr",
",",
"vars",
")",
":",
"lhs",
"=",
"solve",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
".",
"value",
"t",
"=",
"solve",
"(",
"expr",
".",
"rhs",
",",
"vars",
")",
".",
"value",
"if",
"t",
"is",
"None",
":",
"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | solve_isinstance | Typecheck whether LHS is type on the RHS. | efilter/transforms/solve.py | def solve_isinstance(expr, vars):
"""Typecheck whether LHS is type on the RHS."""
lhs = solve(expr.lhs, vars)
try:
t = solve(expr.rhs, vars).value
except errors.EfilterKeyError:
t = None
if t is None:
raise errors.EfilterTypeError(
root=expr.rhs, query=expr.sour... | def solve_isinstance(expr, vars):
"""Typecheck whether LHS is type on the RHS."""
lhs = solve(expr.lhs, vars)
try:
t = solve(expr.rhs, vars).value
except errors.EfilterKeyError:
t = None
if t is None:
raise errors.EfilterTypeError(
root=expr.rhs, query=expr.sour... | [
"Typecheck",
"whether",
"LHS",
"is",
"type",
"on",
"the",
"RHS",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/solve.py#L612-L631 | [
"def",
"solve_isinstance",
"(",
"expr",
",",
"vars",
")",
":",
"lhs",
"=",
"solve",
"(",
"expr",
".",
"lhs",
",",
"vars",
")",
"try",
":",
"t",
"=",
"solve",
"(",
"expr",
".",
"rhs",
",",
"vars",
")",
".",
"value",
"except",
"errors",
".",
"Efilt... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | set_version | mod_root
a VERSION file containes the version strings is created in mod_root,
during installation. That file is used at runtime to get the version
information. | setup.py | def set_version(mod_root):
"""
mod_root
a VERSION file containes the version strings is created in mod_root,
during installation. That file is used at runtime to get the version
information.
"""
try:
version_base = None
version_detail = None
# ge... | def set_version(mod_root):
"""
mod_root
a VERSION file containes the version strings is created in mod_root,
during installation. That file is used at runtime to get the version
information.
"""
try:
version_base = None
version_detail = None
# ge... | [
"mod_root",
"a",
"VERSION",
"file",
"containes",
"the",
"version",
"strings",
"is",
"created",
"in",
"mod_root",
"during",
"installation",
".",
"That",
"file",
"is",
"used",
"at",
"runtime",
"to",
"get",
"the",
"version",
"information",
"."
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/setup.py#L26-L111 | [
"def",
"set_version",
"(",
"mod_root",
")",
":",
"try",
":",
"version_base",
"=",
"None",
"version_detail",
"=",
"None",
"# get version from './VERSION'",
"src_root",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"if",
"not",
"src_root",
":",
... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | makeDataFiles | Create distutils data_files structure from dir
distutil will copy all file rooted under dir into prefix, excluding
dir itself, just like 'ditto src dst' works, and unlike 'cp -r src
dst, which copy src into dst'.
Typical usage:
# install the contents of 'wiki' under sys.prefix+'share/moin'
... | setup.py | def makeDataFiles(prefix, dir):
""" Create distutils data_files structure from dir
distutil will copy all file rooted under dir into prefix, excluding
dir itself, just like 'ditto src dst' works, and unlike 'cp -r src
dst, which copy src into dst'.
Typical usage:
# install the contents of 'w... | def makeDataFiles(prefix, dir):
""" Create distutils data_files structure from dir
distutil will copy all file rooted under dir into prefix, excluding
dir itself, just like 'ditto src dst' works, and unlike 'cp -r src
dst, which copy src into dst'.
Typical usage:
# install the contents of 'w... | [
"Create",
"distutils",
"data_files",
"structure",
"from",
"dir",
"distutil",
"will",
"copy",
"all",
"file",
"rooted",
"under",
"dir",
"into",
"prefix",
"excluding",
"dir",
"itself",
"just",
"like",
"ditto",
"src",
"dst",
"works",
"and",
"unlike",
"cp",
"-",
... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/setup.py#L126-L153 | [
"def",
"makeDataFiles",
"(",
"prefix",
",",
"dir",
")",
":",
"# Strip 'dir/' from of path before joining with prefix",
"dir",
"=",
"dir",
".",
"rstrip",
"(",
"'/'",
")",
"strip",
"=",
"len",
"(",
"dir",
")",
"+",
"1",
"found",
"=",
"[",
"]",
"os",
".",
"... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | visit | Visit directory, create distutil tuple
Add distutil tuple for each directory using this format:
(destination, [dirname/file1, dirname/file2, ...])
distutil will copy later file1, file2, ... info destination. | setup.py | def visit((prefix, strip, found), dirname, names):
""" Visit directory, create distutil tuple
Add distutil tuple for each directory using this format:
(destination, [dirname/file1, dirname/file2, ...])
distutil will copy later file1, file2, ... info destination.
"""
files = []
# Iterate ... | def visit((prefix, strip, found), dirname, names):
""" Visit directory, create distutil tuple
Add distutil tuple for each directory using this format:
(destination, [dirname/file1, dirname/file2, ...])
distutil will copy later file1, file2, ... info destination.
"""
files = []
# Iterate ... | [
"Visit",
"directory",
"create",
"distutil",
"tuple",
"Add",
"distutil",
"tuple",
"for",
"each",
"directory",
"using",
"this",
"format",
":",
"(",
"destination",
"[",
"dirname",
"/",
"file1",
"dirname",
"/",
"file2",
"...",
"]",
")",
"distutil",
"will",
"copy... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/setup.py#L155-L174 | [
"def",
"visit",
"(",
"(",
"prefix",
",",
"strip",
",",
"found",
")",
",",
"dirname",
",",
"names",
")",
":",
"files",
"=",
"[",
"]",
"# Iterate over a copy of names, modify names",
"for",
"name",
"in",
"names",
"[",
":",
"]",
":",
"path",
"=",
"os",
".... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | isgood | Whether name should be installed | setup.py | def isgood(name):
""" Whether name should be installed """
if not isbad(name):
if name.endswith('.py') or name.endswith('.json') or name.endswith('.tar'):
return True
return False | def isgood(name):
""" Whether name should be installed """
if not isbad(name):
if name.endswith('.py') or name.endswith('.json') or name.endswith('.tar'):
return True
return False | [
"Whether",
"name",
"should",
"be",
"installed"
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/setup.py#L183-L188 | [
"def",
"isgood",
"(",
"name",
")",
":",
"if",
"not",
"isbad",
"(",
"name",
")",
":",
"if",
"name",
".",
"endswith",
"(",
"'.py'",
")",
"or",
"name",
".",
"endswith",
"(",
"'.json'",
")",
"or",
"name",
".",
"endswith",
"(",
"'.tar'",
")",
":",
"re... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor._initialize_workflow | **Purpose**: Initialize the PST of the workflow with a uid and type checks | src/radical/entk/appman/wfprocessor.py | def _initialize_workflow(self):
"""
**Purpose**: Initialize the PST of the workflow with a uid and type checks
"""
try:
self._prof.prof('initializing workflow', uid=self._uid)
for p in self._workflow:
p._assign_uid(self._sid)
self._... | def _initialize_workflow(self):
"""
**Purpose**: Initialize the PST of the workflow with a uid and type checks
"""
try:
self._prof.prof('initializing workflow', uid=self._uid)
for p in self._workflow:
p._assign_uid(self._sid)
self._... | [
"**",
"Purpose",
"**",
":",
"Initialize",
"the",
"PST",
"of",
"the",
"workflow",
"with",
"a",
"uid",
"and",
"type",
"checks"
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L87-L104 | [
"def",
"_initialize_workflow",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_prof",
".",
"prof",
"(",
"'initializing workflow'",
",",
"uid",
"=",
"self",
".",
"_uid",
")",
"for",
"p",
"in",
"self",
".",
"_workflow",
":",
"p",
".",
"_assign_uid",
"(... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor._enqueue | **Purpose**: This is the function that is run in the enqueue thread. This function extracts Tasks from the
copy of workflow that exists in the WFprocessor object and pushes them to the queues in the pending_q list.
Since this thread works on the copy of the workflow, every state update to the Task, Stag... | src/radical/entk/appman/wfprocessor.py | def _enqueue(self, local_prof):
"""
**Purpose**: This is the function that is run in the enqueue thread. This function extracts Tasks from the
copy of workflow that exists in the WFprocessor object and pushes them to the queues in the pending_q list.
Since this thread works on the copy o... | def _enqueue(self, local_prof):
"""
**Purpose**: This is the function that is run in the enqueue thread. This function extracts Tasks from the
copy of workflow that exists in the WFprocessor object and pushes them to the queues in the pending_q list.
Since this thread works on the copy o... | [
"**",
"Purpose",
"**",
":",
"This",
"is",
"the",
"function",
"that",
"is",
"run",
"in",
"the",
"enqueue",
"thread",
".",
"This",
"function",
"extracts",
"Tasks",
"from",
"the",
"copy",
"of",
"workflow",
"that",
"exists",
"in",
"the",
"WFprocessor",
"object... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L106-L271 | [
"def",
"_enqueue",
"(",
"self",
",",
"local_prof",
")",
":",
"try",
":",
"local_prof",
".",
"prof",
"(",
"'enqueue-thread started'",
",",
"uid",
"=",
"self",
".",
"_uid",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"'enqueue-thread started'",
")",
"# Ac... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor._dequeue | **Purpose**: This is the function that is run in the dequeue thread. This function extracts Tasks from the
completed queus and updates the copy of workflow that exists in the WFprocessor object.
Since this thread works on the copy of the workflow, every state update to the Task, Stage and Pipeline is
... | src/radical/entk/appman/wfprocessor.py | def _dequeue(self, local_prof):
"""
**Purpose**: This is the function that is run in the dequeue thread. This function extracts Tasks from the
completed queus and updates the copy of workflow that exists in the WFprocessor object.
Since this thread works on the copy of the workflow, ever... | def _dequeue(self, local_prof):
"""
**Purpose**: This is the function that is run in the dequeue thread. This function extracts Tasks from the
completed queus and updates the copy of workflow that exists in the WFprocessor object.
Since this thread works on the copy of the workflow, ever... | [
"**",
"Purpose",
"**",
":",
"This",
"is",
"the",
"function",
"that",
"is",
"run",
"in",
"the",
"dequeue",
"thread",
".",
"This",
"function",
"extracts",
"Tasks",
"from",
"the",
"completed",
"queus",
"and",
"updates",
"the",
"copy",
"of",
"workflow",
"that"... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L273-L456 | [
"def",
"_dequeue",
"(",
"self",
",",
"local_prof",
")",
":",
"try",
":",
"local_prof",
".",
"prof",
"(",
"'dequeue-thread started'",
",",
"uid",
"=",
"self",
".",
"_uid",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"'Dequeue thread started'",
")",
"mq_c... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor._wfp | **Purpose**: This is the function executed in the wfp process. The function is used to simply create
and spawn two threads: enqueue, dequeue. The enqueue thread pushes ready tasks to the queues in the pending_q slow
list whereas the dequeue thread pulls completed tasks from the queues in the completed_q... | src/radical/entk/appman/wfprocessor.py | def _wfp(self):
"""
**Purpose**: This is the function executed in the wfp process. The function is used to simply create
and spawn two threads: enqueue, dequeue. The enqueue thread pushes ready tasks to the queues in the pending_q slow
list whereas the dequeue thread pulls completed task... | def _wfp(self):
"""
**Purpose**: This is the function executed in the wfp process. The function is used to simply create
and spawn two threads: enqueue, dequeue. The enqueue thread pushes ready tasks to the queues in the pending_q slow
list whereas the dequeue thread pulls completed task... | [
"**",
"Purpose",
"**",
":",
"This",
"is",
"the",
"function",
"executed",
"in",
"the",
"wfp",
"process",
".",
"The",
"function",
"is",
"used",
"to",
"simply",
"create",
"and",
"spawn",
"two",
"threads",
":",
"enqueue",
"dequeue",
".",
"The",
"enqueue",
"t... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L458-L569 | [
"def",
"_wfp",
"(",
"self",
")",
":",
"try",
":",
"local_prof",
"=",
"ru",
".",
"Profiler",
"(",
"name",
"=",
"'radical.entk.%s'",
"%",
"self",
".",
"_uid",
"+",
"'-proc'",
",",
"path",
"=",
"self",
".",
"_path",
")",
"local_prof",
".",
"prof",
"(",
... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor.start_processor | **Purpose**: Method to start the wfp process. The wfp function
is not to be accessed directly. The function is started in a separate
process using this method. | src/radical/entk/appman/wfprocessor.py | def start_processor(self):
"""
**Purpose**: Method to start the wfp process. The wfp function
is not to be accessed directly. The function is started in a separate
process using this method.
"""
if not self._wfp_process:
try:
self._prof.prof... | def start_processor(self):
"""
**Purpose**: Method to start the wfp process. The wfp function
is not to be accessed directly. The function is started in a separate
process using this method.
"""
if not self._wfp_process:
try:
self._prof.prof... | [
"**",
"Purpose",
"**",
":",
"Method",
"to",
"start",
"the",
"wfp",
"process",
".",
"The",
"wfp",
"function",
"is",
"not",
"to",
"be",
"accessed",
"directly",
".",
"The",
"function",
"is",
"started",
"in",
"a",
"separate",
"process",
"using",
"this",
"met... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L575-L610 | [
"def",
"start_processor",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_wfp_process",
":",
"try",
":",
"self",
".",
"_prof",
".",
"prof",
"(",
"'creating wfp process'",
",",
"uid",
"=",
"self",
".",
"_uid",
")",
"self",
".",
"_wfp_process",
"=",
"... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor.terminate_processor | **Purpose**: Method to terminate the wfp process. This method is
blocking as it waits for the wfp process to terminate (aka join). | src/radical/entk/appman/wfprocessor.py | def terminate_processor(self):
"""
**Purpose**: Method to terminate the wfp process. This method is
blocking as it waits for the wfp process to terminate (aka join).
"""
try:
if self.check_processor():
self._logger.debug(
'Attempt... | def terminate_processor(self):
"""
**Purpose**: Method to terminate the wfp process. This method is
blocking as it waits for the wfp process to terminate (aka join).
"""
try:
if self.check_processor():
self._logger.debug(
'Attempt... | [
"**",
"Purpose",
"**",
":",
"Method",
"to",
"terminate",
"the",
"wfp",
"process",
".",
"This",
"method",
"is",
"blocking",
"as",
"it",
"waits",
"for",
"the",
"wfp",
"process",
"to",
"terminate",
"(",
"aka",
"join",
")",
"."
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L612-L636 | [
"def",
"terminate_processor",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"check_processor",
"(",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Attempting to end WFprocessor... event: %s'",
"%",
"self",
".",
"_wfp_terminate",
".",
"is_set",
... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | WFprocessor.workflow_incomplete | **Purpose**: Method to check if the workflow execution is incomplete. | src/radical/entk/appman/wfprocessor.py | def workflow_incomplete(self):
"""
**Purpose**: Method to check if the workflow execution is incomplete.
"""
try:
for pipe in self._workflow:
with pipe.lock:
if pipe.completed:
pass
else:
... | def workflow_incomplete(self):
"""
**Purpose**: Method to check if the workflow execution is incomplete.
"""
try:
for pipe in self._workflow:
with pipe.lock:
if pipe.completed:
pass
else:
... | [
"**",
"Purpose",
"**",
":",
"Method",
"to",
"check",
"if",
"the",
"workflow",
"execution",
"is",
"incomplete",
"."
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/appman/wfprocessor.py#L638-L655 | [
"def",
"workflow_incomplete",
"(",
"self",
")",
":",
"try",
":",
"for",
"pipe",
"in",
"self",
".",
"_workflow",
":",
"with",
"pipe",
".",
"lock",
":",
"if",
"pipe",
".",
"completed",
":",
"pass",
"else",
":",
"return",
"True",
"return",
"False",
"excep... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | meld | Return the repeated value, or the first value if there's only one.
This is a convenience function, equivalent to calling
getvalue(repeated(x)) to get x.
This function skips over instances of None in values (None is not allowed
in repeated variables).
Examples:
meld("foo", "bar") # => List... | efilter/protocols/repeated.py | def meld(*values):
"""Return the repeated value, or the first value if there's only one.
This is a convenience function, equivalent to calling
getvalue(repeated(x)) to get x.
This function skips over instances of None in values (None is not allowed
in repeated variables).
Examples:
me... | def meld(*values):
"""Return the repeated value, or the first value if there's only one.
This is a convenience function, equivalent to calling
getvalue(repeated(x)) to get x.
This function skips over instances of None in values (None is not allowed
in repeated variables).
Examples:
me... | [
"Return",
"the",
"repeated",
"value",
"or",
"the",
"first",
"value",
"if",
"there",
"s",
"only",
"one",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocols/repeated.py#L55-L78 | [
"def",
"meld",
"(",
"*",
"values",
")",
":",
"values",
"=",
"[",
"x",
"for",
"x",
"in",
"values",
"if",
"x",
"is",
"not",
"None",
"]",
"if",
"not",
"values",
":",
"return",
"None",
"result",
"=",
"repeated",
"(",
"*",
"values",
")",
"if",
"isrepe... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | getvalue | Return the single value of x or raise TypError if more than one value. | efilter/protocols/repeated.py | def getvalue(x):
"""Return the single value of x or raise TypError if more than one value."""
if isrepeating(x):
raise TypeError(
"Ambiguous call to getvalue for %r which has more than one value."
% x)
for value in getvalues(x):
return value | def getvalue(x):
"""Return the single value of x or raise TypError if more than one value."""
if isrepeating(x):
raise TypeError(
"Ambiguous call to getvalue for %r which has more than one value."
% x)
for value in getvalues(x):
return value | [
"Return",
"the",
"single",
"value",
"of",
"x",
"or",
"raise",
"TypError",
"if",
"more",
"than",
"one",
"value",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocols/repeated.py#L120-L128 | [
"def",
"getvalue",
"(",
"x",
")",
":",
"if",
"isrepeating",
"(",
"x",
")",
":",
"raise",
"TypeError",
"(",
"\"Ambiguous call to getvalue for %r which has more than one value.\"",
"%",
"x",
")",
"for",
"value",
"in",
"getvalues",
"(",
"x",
")",
":",
"return",
"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Task.luid | Unique ID of the current task (fully qualified).
example:
>>> task.luid
pipe.0001.stage.0004.task.0234
:getter: Returns the fully qualified uid of the current task
:type: String | src/radical/entk/task/task.py | def luid(self):
"""
Unique ID of the current task (fully qualified).
example:
>>> task.luid
pipe.0001.stage.0004.task.0234
:getter: Returns the fully qualified uid of the current task
:type: String
"""
p_elem = self.parent_pipeline.get('n... | def luid(self):
"""
Unique ID of the current task (fully qualified).
example:
>>> task.luid
pipe.0001.stage.0004.task.0234
:getter: Returns the fully qualified uid of the current task
:type: String
"""
p_elem = self.parent_pipeline.get('n... | [
"Unique",
"ID",
"of",
"the",
"current",
"task",
"(",
"fully",
"qualified",
")",
"."
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/task/task.py#L88-L111 | [
"def",
"luid",
"(",
"self",
")",
":",
"p_elem",
"=",
"self",
".",
"parent_pipeline",
".",
"get",
"(",
"'name'",
")",
"if",
"not",
"p_elem",
":",
"p_elem",
"=",
"self",
".",
"parent_pipeline",
"[",
"'uid'",
"]",
"s_elem",
"=",
"self",
".",
"parent_stage... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | Task.to_dict | Convert current Task into a dictionary
:return: python dictionary | src/radical/entk/task/task.py | def to_dict(self):
"""
Convert current Task into a dictionary
:return: python dictionary
"""
task_desc_as_dict = {
'uid': self._uid,
'name': self._name,
'state': self._state,
'state_history': self._state_history,
'pre... | def to_dict(self):
"""
Convert current Task into a dictionary
:return: python dictionary
"""
task_desc_as_dict = {
'uid': self._uid,
'name': self._name,
'state': self._state,
'state_history': self._state_history,
'pre... | [
"Convert",
"current",
"Task",
"into",
"a",
"dictionary"
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/task/task.py#L724-L764 | [
"def",
"to_dict",
"(",
"self",
")",
":",
"task_desc_as_dict",
"=",
"{",
"'uid'",
":",
"self",
".",
"_uid",
",",
"'name'",
":",
"self",
".",
"_name",
",",
"'state'",
":",
"self",
".",
"_state",
",",
"'state_history'",
":",
"self",
".",
"_state_history",
... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | Task.from_dict | Create a Task from a dictionary. The change is in inplace.
:argument: python dictionary
:return: None | src/radical/entk/task/task.py | def from_dict(self, d):
"""
Create a Task from a dictionary. The change is in inplace.
:argument: python dictionary
:return: None
"""
if 'uid' in d:
if d['uid']:
self._uid = d['uid']
if 'name' in d:
if d['name']:
... | def from_dict(self, d):
"""
Create a Task from a dictionary. The change is in inplace.
:argument: python dictionary
:return: None
"""
if 'uid' in d:
if d['uid']:
self._uid = d['uid']
if 'name' in d:
if d['name']:
... | [
"Create",
"a",
"Task",
"from",
"a",
"dictionary",
".",
"The",
"change",
"is",
"in",
"inplace",
"."
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/task/task.py#L766-L948 | [
"def",
"from_dict",
"(",
"self",
",",
"d",
")",
":",
"if",
"'uid'",
"in",
"d",
":",
"if",
"d",
"[",
"'uid'",
"]",
":",
"self",
".",
"_uid",
"=",
"d",
"[",
"'uid'",
"]",
"if",
"'name'",
"in",
"d",
":",
"if",
"d",
"[",
"'name'",
"]",
":",
"se... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | Task._assign_uid | Purpose: Assign a uid to the current object based on the sid passed | src/radical/entk/task/task.py | def _assign_uid(self, sid):
"""
Purpose: Assign a uid to the current object based on the sid passed
"""
self._uid = ru.generate_id(
'task.%(item_counter)04d', ru.ID_CUSTOM, namespace=sid) | def _assign_uid(self, sid):
"""
Purpose: Assign a uid to the current object based on the sid passed
"""
self._uid = ru.generate_id(
'task.%(item_counter)04d', ru.ID_CUSTOM, namespace=sid) | [
"Purpose",
":",
"Assign",
"a",
"uid",
"to",
"the",
"current",
"object",
"based",
"on",
"the",
"sid",
"passed"
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/task/task.py#L954-L959 | [
"def",
"_assign_uid",
"(",
"self",
",",
"sid",
")",
":",
"self",
".",
"_uid",
"=",
"ru",
".",
"generate_id",
"(",
"'task.%(item_counter)04d'",
",",
"ru",
".",
"ID_CUSTOM",
",",
"namespace",
"=",
"sid",
")"
] | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | Task._validate | Purpose: Validate that the state of the task is 'DESCRIBED' and that an executable has been specified for the
task. | src/radical/entk/task/task.py | def _validate(self):
"""
Purpose: Validate that the state of the task is 'DESCRIBED' and that an executable has been specified for the
task.
"""
if self._state is not states.INITIAL:
raise ValueError(obj=self._uid,
attribute='state',
... | def _validate(self):
"""
Purpose: Validate that the state of the task is 'DESCRIBED' and that an executable has been specified for the
task.
"""
if self._state is not states.INITIAL:
raise ValueError(obj=self._uid,
attribute='state',
... | [
"Purpose",
":",
"Validate",
"that",
"the",
"state",
"of",
"the",
"task",
"is",
"DESCRIBED",
"and",
"that",
"an",
"executable",
"has",
"been",
"specified",
"for",
"the",
"task",
"."
] | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/task/task.py#L961-L975 | [
"def",
"_validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
"is",
"not",
"states",
".",
"INITIAL",
":",
"raise",
"ValueError",
"(",
"obj",
"=",
"self",
".",
"_uid",
",",
"attribute",
"=",
"'state'",
",",
"expected_value",
"=",
"states",
"."... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | TaskManager._process_tasks | **Purpose**: The new thread that gets spawned by the main tmgr process invokes this function. This
function receives tasks from 'task_queue' and submits them to the RADICAL Pilot RTS. | src/radical/entk/execman/rp/task_manager.py | def _process_tasks(self, task_queue, rmgr, logger, mq_hostname, port, local_prof, sid):
'''
**Purpose**: The new thread that gets spawned by the main tmgr process invokes this function. This
function receives tasks from 'task_queue' and submits them to the RADICAL Pilot RTS.
'''
... | def _process_tasks(self, task_queue, rmgr, logger, mq_hostname, port, local_prof, sid):
'''
**Purpose**: The new thread that gets spawned by the main tmgr process invokes this function. This
function receives tasks from 'task_queue' and submits them to the RADICAL Pilot RTS.
'''
... | [
"**",
"Purpose",
"**",
":",
"The",
"new",
"thread",
"that",
"gets",
"spawned",
"by",
"the",
"main",
"tmgr",
"process",
"invokes",
"this",
"function",
".",
"This",
"function",
"receives",
"tasks",
"from",
"task_queue",
"and",
"submits",
"them",
"to",
"the",
... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/execman/rp/task_manager.py#L187-L330 | [
"def",
"_process_tasks",
"(",
"self",
",",
"task_queue",
",",
"rmgr",
",",
"logger",
",",
"mq_hostname",
",",
"port",
",",
"local_prof",
",",
"sid",
")",
":",
"placeholder_dict",
"=",
"dict",
"(",
")",
"def",
"load_placeholder",
"(",
"task",
",",
"rts_uid"... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | infer_type | Try to infer the type of x[y] if y is a known value (literal). | efilter/transforms/infer_type.py | def infer_type(expr, scope):
"""Try to infer the type of x[y] if y is a known value (literal)."""
# Do we know what the key even is?
if isinstance(expr.key, ast.Literal):
key = expr.key.value
else:
return protocol.AnyType
container_type = infer_type(expr.value, scope)
try:
... | def infer_type(expr, scope):
"""Try to infer the type of x[y] if y is a known value (literal)."""
# Do we know what the key even is?
if isinstance(expr.key, ast.Literal):
key = expr.key.value
else:
return protocol.AnyType
container_type = infer_type(expr.value, scope)
try:
... | [
"Try",
"to",
"infer",
"the",
"type",
"of",
"x",
"[",
"y",
"]",
"if",
"y",
"is",
"a",
"known",
"value",
"(",
"literal",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/infer_type.py#L108-L123 | [
"def",
"infer_type",
"(",
"expr",
",",
"scope",
")",
":",
"# Do we know what the key even is?",
"if",
"isinstance",
"(",
"expr",
".",
"key",
",",
"ast",
".",
"Literal",
")",
":",
"key",
"=",
"expr",
".",
"key",
".",
"value",
"else",
":",
"return",
"proto... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | infer_type | Try to infer the type of x.y if y is a known value (literal). | efilter/transforms/infer_type.py | def infer_type(expr, scope):
"""Try to infer the type of x.y if y is a known value (literal)."""
# Do we know what the member is?
if isinstance(expr.member, ast.Literal):
member = expr.member.value
else:
return protocol.AnyType
container_type = infer_type(expr.obj, scope)
try:
... | def infer_type(expr, scope):
"""Try to infer the type of x.y if y is a known value (literal)."""
# Do we know what the member is?
if isinstance(expr.member, ast.Literal):
member = expr.member.value
else:
return protocol.AnyType
container_type = infer_type(expr.obj, scope)
try:
... | [
"Try",
"to",
"infer",
"the",
"type",
"of",
"x",
".",
"y",
"if",
"y",
"is",
"a",
"known",
"value",
"(",
"literal",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/infer_type.py#L127-L142 | [
"def",
"infer_type",
"(",
"expr",
",",
"scope",
")",
":",
"# Do we know what the member is?",
"if",
"isinstance",
"(",
"expr",
".",
"member",
",",
"ast",
".",
"Literal",
")",
":",
"member",
"=",
"expr",
".",
"member",
".",
"value",
"else",
":",
"return",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | TaskManager._tmgr | **Purpose**: Method to be run by the tmgr process. This method receives a Task from the pending_queue
and submits it to the RTS. Currently, it also converts Tasks into CUDs and CUs into (partially described) Tasks.
This conversion is necessary since the current RTS is RADICAL Pilot. Once Tasks are recov... | src/radical/entk/execman/mock/task_manager.py | def _tmgr(self, uid, rmgr, logger, mq_hostname, port, pending_queue, completed_queue):
"""
**Purpose**: Method to be run by the tmgr process. This method receives a Task from the pending_queue
and submits it to the RTS. Currently, it also converts Tasks into CUDs and CUs into (partially describe... | def _tmgr(self, uid, rmgr, logger, mq_hostname, port, pending_queue, completed_queue):
"""
**Purpose**: Method to be run by the tmgr process. This method receives a Task from the pending_queue
and submits it to the RTS. Currently, it also converts Tasks into CUDs and CUs into (partially describe... | [
"**",
"Purpose",
"**",
":",
"Method",
"to",
"be",
"run",
"by",
"the",
"tmgr",
"process",
".",
"This",
"method",
"receives",
"a",
"Task",
"from",
"the",
"pending_queue",
"and",
"submits",
"it",
"to",
"the",
"RTS",
".",
"Currently",
"it",
"also",
"converts... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/execman/mock/task_manager.py#L59-L171 | [
"def",
"_tmgr",
"(",
"self",
",",
"uid",
",",
"rmgr",
",",
"logger",
",",
"mq_hostname",
",",
"port",
",",
"pending_queue",
",",
"completed_queue",
")",
":",
"try",
":",
"def",
"heartbeat_response",
"(",
"mq_channel",
")",
":",
"try",
":",
"# Get request f... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | TaskManager.start_manager | **Purpose**: Method to start the tmgr process. The tmgr function
is not to be accessed directly. The function is started in a separate
thread using this method. | src/radical/entk/execman/mock/task_manager.py | def start_manager(self):
"""
**Purpose**: Method to start the tmgr process. The tmgr function
is not to be accessed directly. The function is started in a separate
thread using this method.
"""
if not self._tmgr_process:
try:
self._prof.prof... | def start_manager(self):
"""
**Purpose**: Method to start the tmgr process. The tmgr function
is not to be accessed directly. The function is started in a separate
thread using this method.
"""
if not self._tmgr_process:
try:
self._prof.prof... | [
"**",
"Purpose",
"**",
":",
"Method",
"to",
"start",
"the",
"tmgr",
"process",
".",
"The",
"tmgr",
"function",
"is",
"not",
"to",
"be",
"accessed",
"directly",
".",
"The",
"function",
"is",
"started",
"in",
"a",
"separate",
"thread",
"using",
"this",
"me... | radical-cybertools/radical.entk | python | https://github.com/radical-cybertools/radical.entk/blob/945f6c93c9a62db90ad191b306418d5c1cdd9d24/src/radical/entk/execman/mock/task_manager.py#L277-L317 | [
"def",
"start_manager",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_tmgr_process",
":",
"try",
":",
"self",
".",
"_prof",
".",
"prof",
"(",
"'creating tmgr process'",
",",
"uid",
"=",
"self",
".",
"_uid",
")",
"self",
".",
"_tmgr_terminate",
"=",
... | 945f6c93c9a62db90ad191b306418d5c1cdd9d24 |
train | keyword | Case-insensitive keyword match. | efilter/parsers/common/grammar.py | def keyword(tokens, expected):
"""Case-insensitive keyword match."""
try:
token = next(iter(tokens))
except StopIteration:
return
if token and token.name == "symbol" and token.value.lower() == expected:
return TokenMatch(None, token.value, (token,)) | def keyword(tokens, expected):
"""Case-insensitive keyword match."""
try:
token = next(iter(tokens))
except StopIteration:
return
if token and token.name == "symbol" and token.value.lower() == expected:
return TokenMatch(None, token.value, (token,)) | [
"Case",
"-",
"insensitive",
"keyword",
"match",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L234-L242 | [
"def",
"keyword",
"(",
"tokens",
",",
"expected",
")",
":",
"try",
":",
"token",
"=",
"next",
"(",
"iter",
"(",
"tokens",
")",
")",
"except",
"StopIteration",
":",
"return",
"if",
"token",
"and",
"token",
".",
"name",
"==",
"\"symbol\"",
"and",
"token"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | multi_keyword | Match a case-insensitive keyword consisting of multiple tokens. | efilter/parsers/common/grammar.py | def multi_keyword(tokens, keyword_parts):
"""Match a case-insensitive keyword consisting of multiple tokens."""
tokens = iter(tokens)
matched_tokens = []
limit = len(keyword_parts)
for idx in six.moves.range(limit):
try:
token = next(tokens)
except StopIteration:
... | def multi_keyword(tokens, keyword_parts):
"""Match a case-insensitive keyword consisting of multiple tokens."""
tokens = iter(tokens)
matched_tokens = []
limit = len(keyword_parts)
for idx in six.moves.range(limit):
try:
token = next(tokens)
except StopIteration:
... | [
"Match",
"a",
"case",
"-",
"insensitive",
"keyword",
"consisting",
"of",
"multiple",
"tokens",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L245-L263 | [
"def",
"multi_keyword",
"(",
"tokens",
",",
"keyword_parts",
")",
":",
"tokens",
"=",
"iter",
"(",
"tokens",
")",
"matched_tokens",
"=",
"[",
"]",
"limit",
"=",
"len",
"(",
"keyword_parts",
")",
"for",
"idx",
"in",
"six",
".",
"moves",
".",
"range",
"(... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | prefix | Match a prefix of an operator. | efilter/parsers/common/grammar.py | def prefix(tokens, operator_table):
"""Match a prefix of an operator."""
operator, matched_tokens = operator_table.prefix.match(tokens)
if operator:
return TokenMatch(operator, None, matched_tokens) | def prefix(tokens, operator_table):
"""Match a prefix of an operator."""
operator, matched_tokens = operator_table.prefix.match(tokens)
if operator:
return TokenMatch(operator, None, matched_tokens) | [
"Match",
"a",
"prefix",
"of",
"an",
"operator",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L281-L285 | [
"def",
"prefix",
"(",
"tokens",
",",
"operator_table",
")",
":",
"operator",
",",
"matched_tokens",
"=",
"operator_table",
".",
"prefix",
".",
"match",
"(",
"tokens",
")",
"if",
"operator",
":",
"return",
"TokenMatch",
"(",
"operator",
",",
"None",
",",
"m... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | infix | Match an infix of an operator. | efilter/parsers/common/grammar.py | def infix(tokens, operator_table):
"""Match an infix of an operator."""
operator, matched_tokens = operator_table.infix.match(tokens)
if operator:
return TokenMatch(operator, None, matched_tokens) | def infix(tokens, operator_table):
"""Match an infix of an operator."""
operator, matched_tokens = operator_table.infix.match(tokens)
if operator:
return TokenMatch(operator, None, matched_tokens) | [
"Match",
"an",
"infix",
"of",
"an",
"operator",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L288-L292 | [
"def",
"infix",
"(",
"tokens",
",",
"operator_table",
")",
":",
"operator",
",",
"matched_tokens",
"=",
"operator_table",
".",
"infix",
".",
"match",
"(",
"tokens",
")",
"if",
"operator",
":",
"return",
"TokenMatch",
"(",
"operator",
",",
"None",
",",
"mat... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | suffix | Match a suffix of an operator. | efilter/parsers/common/grammar.py | def suffix(tokens, operator_table):
"""Match a suffix of an operator."""
operator, matched_tokens = operator_table.suffix.match(tokens)
if operator:
return TokenMatch(operator, None, matched_tokens) | def suffix(tokens, operator_table):
"""Match a suffix of an operator."""
operator, matched_tokens = operator_table.suffix.match(tokens)
if operator:
return TokenMatch(operator, None, matched_tokens) | [
"Match",
"a",
"suffix",
"of",
"an",
"operator",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L295-L299 | [
"def",
"suffix",
"(",
"tokens",
",",
"operator_table",
")",
":",
"operator",
",",
"matched_tokens",
"=",
"operator_table",
".",
"suffix",
".",
"match",
"(",
"tokens",
")",
"if",
"operator",
":",
"return",
"TokenMatch",
"(",
"operator",
",",
"None",
",",
"m... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | token_name | Match a token name (type). | efilter/parsers/common/grammar.py | def token_name(tokens, expected):
"""Match a token name (type)."""
try:
token = next(iter(tokens))
except StopIteration:
return
if token and token.name == expected:
return TokenMatch(None, token.value, (token,)) | def token_name(tokens, expected):
"""Match a token name (type)."""
try:
token = next(iter(tokens))
except StopIteration:
return
if token and token.name == expected:
return TokenMatch(None, token.value, (token,)) | [
"Match",
"a",
"token",
"name",
"(",
"type",
")",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L302-L310 | [
"def",
"token_name",
"(",
"tokens",
",",
"expected",
")",
":",
"try",
":",
"token",
"=",
"next",
"(",
"iter",
"(",
"tokens",
")",
")",
"except",
"StopIteration",
":",
"return",
"if",
"token",
"and",
"token",
".",
"name",
"==",
"expected",
":",
"return"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | match_tokens | Generate a grammar function that will match 'expected_tokens' only. | efilter/parsers/common/grammar.py | def match_tokens(expected_tokens):
"""Generate a grammar function that will match 'expected_tokens' only."""
if isinstance(expected_tokens, Token):
# Match a single token.
def _grammar_func(tokens):
try:
next_token = next(iter(tokens))
except StopIteration... | def match_tokens(expected_tokens):
"""Generate a grammar function that will match 'expected_tokens' only."""
if isinstance(expected_tokens, Token):
# Match a single token.
def _grammar_func(tokens):
try:
next_token = next(iter(tokens))
except StopIteration... | [
"Generate",
"a",
"grammar",
"function",
"that",
"will",
"match",
"expected_tokens",
"only",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/common/grammar.py#L313-L338 | [
"def",
"match_tokens",
"(",
"expected_tokens",
")",
":",
"if",
"isinstance",
"(",
"expected_tokens",
",",
"Token",
")",
":",
"# Match a single token.",
"def",
"_grammar_func",
"(",
"tokens",
")",
":",
"try",
":",
"next_token",
"=",
"next",
"(",
"iter",
"(",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | set_metric | Create/Increment a metric. | redis_metrics/utils.py | def set_metric(slug, value, category=None, expire=None, date=None):
"""Create/Increment a metric."""
get_r().set_metric(slug, value, category=category, expire=expire, date=date) | def set_metric(slug, value, category=None, expire=None, date=None):
"""Create/Increment a metric."""
get_r().set_metric(slug, value, category=category, expire=expire, date=date) | [
"Create",
"/",
"Increment",
"a",
"metric",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/utils.py#L18-L20 | [
"def",
"set_metric",
"(",
"slug",
",",
"value",
",",
"category",
"=",
"None",
",",
"expire",
"=",
"None",
",",
"date",
"=",
"None",
")",
":",
"get_r",
"(",
")",
".",
"set_metric",
"(",
"slug",
",",
"value",
",",
"category",
"=",
"category",
",",
"e... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | metric | Create/Increment a metric. | redis_metrics/utils.py | def metric(slug, num=1, category=None, expire=None, date=None):
"""Create/Increment a metric."""
get_r().metric(slug, num=num, category=category, expire=expire, date=date) | def metric(slug, num=1, category=None, expire=None, date=None):
"""Create/Increment a metric."""
get_r().metric(slug, num=num, category=category, expire=expire, date=date) | [
"Create",
"/",
"Increment",
"a",
"metric",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/utils.py#L23-L25 | [
"def",
"metric",
"(",
"slug",
",",
"num",
"=",
"1",
",",
"category",
"=",
"None",
",",
"expire",
"=",
"None",
",",
"date",
"=",
"None",
")",
":",
"get_r",
"(",
")",
".",
"metric",
"(",
"slug",
",",
"num",
"=",
"num",
",",
"category",
"=",
"cate... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | Parser.expression | An expression is an atom or an infix expression.
Grammar (sort of, actually a precedence-climbing parser):
expression = atom [ binary_operator expression ] .
Args:
previous_precedence: What operator precedence should we start with? | efilter/parsers/dottysql/parser.py | def expression(self, previous_precedence=0):
"""An expression is an atom or an infix expression.
Grammar (sort of, actually a precedence-climbing parser):
expression = atom [ binary_operator expression ] .
Args:
previous_precedence: What operator precedence should we st... | def expression(self, previous_precedence=0):
"""An expression is an atom or an infix expression.
Grammar (sort of, actually a precedence-climbing parser):
expression = atom [ binary_operator expression ] .
Args:
previous_precedence: What operator precedence should we st... | [
"An",
"expression",
"is",
"an",
"atom",
"or",
"an",
"infix",
"expression",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L143-L154 | [
"def",
"expression",
"(",
"self",
",",
"previous_precedence",
"=",
"0",
")",
":",
"lhs",
"=",
"self",
".",
"atom",
"(",
")",
"return",
"self",
".",
"operator",
"(",
"lhs",
",",
"previous_precedence",
")"
] | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.atom | Parse an atom, which is most things.
Grammar:
atom =
[ prefix ]
( select_expression
| any_expression
| func_application
| let_expr
| var
| literal
| list
|... | efilter/parsers/dottysql/parser.py | def atom(self):
"""Parse an atom, which is most things.
Grammar:
atom =
[ prefix ]
( select_expression
| any_expression
| func_application
| let_expr
| var
| literal
... | def atom(self):
"""Parse an atom, which is most things.
Grammar:
atom =
[ prefix ]
( select_expression
| any_expression
| func_application
| let_expr
| var
| literal
... | [
"Parse",
"an",
"atom",
"which",
"is",
"most",
"things",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L156-L259 | [
"def",
"atom",
"(",
"self",
")",
":",
"# Parameter replacement with literals.",
"if",
"self",
".",
"tokens",
".",
"accept",
"(",
"grammar",
".",
"param",
")",
":",
"return",
"self",
".",
"param",
"(",
")",
"# Let expressions (let(x = 5, y = 10) x + y)",
"if",
"s... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.accept_operator | Accept the next binary operator only if it's of higher precedence. | efilter/parsers/dottysql/parser.py | def accept_operator(self, precedence):
"""Accept the next binary operator only if it's of higher precedence."""
match = grammar.infix(self.tokens)
if not match:
return
if match.operator.precedence < precedence:
return
# The next thing is an operator that... | def accept_operator(self, precedence):
"""Accept the next binary operator only if it's of higher precedence."""
match = grammar.infix(self.tokens)
if not match:
return
if match.operator.precedence < precedence:
return
# The next thing is an operator that... | [
"Accept",
"the",
"next",
"binary",
"operator",
"only",
"if",
"it",
"s",
"of",
"higher",
"precedence",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L315-L325 | [
"def",
"accept_operator",
"(",
"self",
",",
"precedence",
")",
":",
"match",
"=",
"grammar",
".",
"infix",
"(",
"self",
".",
"tokens",
")",
"if",
"not",
"match",
":",
"return",
"if",
"match",
".",
"operator",
".",
"precedence",
"<",
"precedence",
":",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.operator | Climb operator precedence as long as there are operators.
This function implements a basic precedence climbing parser to deal
with binary operators in a sane fashion. The outer loop will keep
spinning as long as the next token is an operator with a precedence
of at least 'min_precedence... | efilter/parsers/dottysql/parser.py | def operator(self, lhs, min_precedence):
"""Climb operator precedence as long as there are operators.
This function implements a basic precedence climbing parser to deal
with binary operators in a sane fashion. The outer loop will keep
spinning as long as the next token is an operator w... | def operator(self, lhs, min_precedence):
"""Climb operator precedence as long as there are operators.
This function implements a basic precedence climbing parser to deal
with binary operators in a sane fashion. The outer loop will keep
spinning as long as the next token is an operator w... | [
"Climb",
"operator",
"precedence",
"as",
"long",
"as",
"there",
"are",
"operators",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L327-L377 | [
"def",
"operator",
"(",
"self",
",",
"lhs",
",",
"min_precedence",
")",
":",
"# Spin as long as the next token is an operator of higher",
"# precedence. (This may not do anything, which is fine.)",
"while",
"self",
".",
"accept_operator",
"(",
"precedence",
"=",
"min_precedence... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.dot_rhs | Match the right-hand side of a dot (.) operator.
The RHS must be a symbol token, but it is interpreted as a literal
string (because that's what goes in the AST of Resolve.) | efilter/parsers/dottysql/parser.py | def dot_rhs(self):
"""Match the right-hand side of a dot (.) operator.
The RHS must be a symbol token, but it is interpreted as a literal
string (because that's what goes in the AST of Resolve.)
"""
self.tokens.expect(common_grammar.symbol)
return ast.Literal(self.tokens... | def dot_rhs(self):
"""Match the right-hand side of a dot (.) operator.
The RHS must be a symbol token, but it is interpreted as a literal
string (because that's what goes in the AST of Resolve.)
"""
self.tokens.expect(common_grammar.symbol)
return ast.Literal(self.tokens... | [
"Match",
"the",
"right",
"-",
"hand",
"side",
"of",
"a",
"dot",
"(",
".",
")",
"operator",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L379-L388 | [
"def",
"dot_rhs",
"(",
"self",
")",
":",
"self",
".",
"tokens",
".",
"expect",
"(",
"common_grammar",
".",
"symbol",
")",
"return",
"ast",
".",
"Literal",
"(",
"self",
".",
"tokens",
".",
"matched",
".",
"value",
",",
"start",
"=",
"self",
".",
"toke... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.select | First part of an SQL query. | efilter/parsers/dottysql/parser.py | def select(self):
"""First part of an SQL query."""
# Try to match the asterisk, any or list of vars.
if self.tokens.accept(grammar.select_any):
return self.select_any()
if self.tokens.accept(grammar.select_all):
# The FROM after SELECT * is required.
... | def select(self):
"""First part of an SQL query."""
# Try to match the asterisk, any or list of vars.
if self.tokens.accept(grammar.select_any):
return self.select_any()
if self.tokens.accept(grammar.select_all):
# The FROM after SELECT * is required.
... | [
"First",
"part",
"of",
"an",
"SQL",
"query",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L392-L403 | [
"def",
"select",
"(",
"self",
")",
":",
"# Try to match the asterisk, any or list of vars.",
"if",
"self",
".",
"tokens",
".",
"accept",
"(",
"grammar",
".",
"select_any",
")",
":",
"return",
"self",
".",
"select_any",
"(",
")",
"if",
"self",
".",
"tokens",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser._guess_name_of | Tries to guess what variable name 'expr' ends in.
This is a heuristic that roughly emulates what most SQL databases
name columns, based on selected variable names or applied functions. | efilter/parsers/dottysql/parser.py | def _guess_name_of(self, expr):
"""Tries to guess what variable name 'expr' ends in.
This is a heuristic that roughly emulates what most SQL databases
name columns, based on selected variable names or applied functions.
"""
if isinstance(expr, ast.Var):
return expr.v... | def _guess_name_of(self, expr):
"""Tries to guess what variable name 'expr' ends in.
This is a heuristic that roughly emulates what most SQL databases
name columns, based on selected variable names or applied functions.
"""
if isinstance(expr, ast.Var):
return expr.v... | [
"Tries",
"to",
"guess",
"what",
"variable",
"name",
"expr",
"ends",
"in",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L439-L459 | [
"def",
"_guess_name_of",
"(",
"self",
",",
"expr",
")",
":",
"if",
"isinstance",
"(",
"expr",
",",
"ast",
".",
"Var",
")",
":",
"return",
"expr",
".",
"value",
"if",
"isinstance",
"(",
"expr",
",",
"ast",
".",
"Resolve",
")",
":",
"# We know the RHS of... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.select_limit | Match LIMIT take [OFFSET drop]. | efilter/parsers/dottysql/parser.py | def select_limit(self, source_expression):
"""Match LIMIT take [OFFSET drop]."""
start = self.tokens.matched.start
# The expression right after LIMIT is the count to take.
limit_count_expression = self.expression()
# Optional OFFSET follows.
if self.tokens.accept(gramma... | def select_limit(self, source_expression):
"""Match LIMIT take [OFFSET drop]."""
start = self.tokens.matched.start
# The expression right after LIMIT is the count to take.
limit_count_expression = self.expression()
# Optional OFFSET follows.
if self.tokens.accept(gramma... | [
"Match",
"LIMIT",
"take",
"[",
"OFFSET",
"drop",
"]",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L573-L607 | [
"def",
"select_limit",
"(",
"self",
",",
"source_expression",
")",
":",
"start",
"=",
"self",
".",
"tokens",
".",
"matched",
".",
"start",
"# The expression right after LIMIT is the count to take.",
"limit_count_expression",
"=",
"self",
".",
"expression",
"(",
")",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.builtin | Parse the pseudo-function application subgrammar. | efilter/parsers/dottysql/parser.py | def builtin(self, keyword):
"""Parse the pseudo-function application subgrammar."""
# The match includes the lparen token, so the keyword is just the first
# token in the match, not the whole thing.
keyword_start = self.tokens.matched.first.start
keyword_end = self.tokens.matched... | def builtin(self, keyword):
"""Parse the pseudo-function application subgrammar."""
# The match includes the lparen token, so the keyword is just the first
# token in the match, not the whole thing.
keyword_start = self.tokens.matched.first.start
keyword_end = self.tokens.matched... | [
"Parse",
"the",
"pseudo",
"-",
"function",
"application",
"subgrammar",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L611-L638 | [
"def",
"builtin",
"(",
"self",
",",
"keyword",
")",
":",
"# The match includes the lparen token, so the keyword is just the first",
"# token in the match, not the whole thing.",
"keyword_start",
"=",
"self",
".",
"tokens",
".",
"matched",
".",
"first",
".",
"start",
"keywor... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.application | Parse the function application subgrammar.
Function application can, conceptually, be thought of as a mixfix
operator, similar to the way array subscripting works. However, it is
not clear at this point whether we want to allow it to work as such,
because doing so would permit queries t... | efilter/parsers/dottysql/parser.py | def application(self, func):
"""Parse the function application subgrammar.
Function application can, conceptually, be thought of as a mixfix
operator, similar to the way array subscripting works. However, it is
not clear at this point whether we want to allow it to work as such,
... | def application(self, func):
"""Parse the function application subgrammar.
Function application can, conceptually, be thought of as a mixfix
operator, similar to the way array subscripting works. However, it is
not clear at this point whether we want to allow it to work as such,
... | [
"Parse",
"the",
"function",
"application",
"subgrammar",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L666-L695 | [
"def",
"application",
"(",
"self",
",",
"func",
")",
":",
"start",
"=",
"self",
".",
"tokens",
".",
"matched",
".",
"start",
"if",
"self",
".",
"tokens",
".",
"accept",
"(",
"common_grammar",
".",
"rparen",
")",
":",
"# That was easy.",
"return",
"ast",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Parser.list | Parse a list (tuple) which can contain any combination of types. | efilter/parsers/dottysql/parser.py | def list(self):
"""Parse a list (tuple) which can contain any combination of types."""
start = self.tokens.matched.start
if self.tokens.accept(common_grammar.rbracket):
return ast.Tuple(start=start, end=self.tokens.matched.end,
source=self.original)
... | def list(self):
"""Parse a list (tuple) which can contain any combination of types."""
start = self.tokens.matched.start
if self.tokens.accept(common_grammar.rbracket):
return ast.Tuple(start=start, end=self.tokens.matched.end,
source=self.original)
... | [
"Parse",
"a",
"list",
"(",
"tuple",
")",
"which",
"can",
"contain",
"any",
"combination",
"of",
"types",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/parsers/dottysql/parser.py#L699-L714 | [
"def",
"list",
"(",
"self",
")",
":",
"start",
"=",
"self",
".",
"tokens",
".",
"matched",
".",
"start",
"if",
"self",
".",
"tokens",
".",
"accept",
"(",
"common_grammar",
".",
"rbracket",
")",
":",
"return",
"ast",
".",
"Tuple",
"(",
"start",
"=",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | RowTuple.get_singleton | If the row only has one column, return that value; otherwise raise.
Raises:
ValueError, if count of columns is not 1. | efilter/ext/row_tuple.py | def get_singleton(self):
"""If the row only has one column, return that value; otherwise raise.
Raises:
ValueError, if count of columns is not 1.
"""
only_value = None
for value in six.itervalues(self.ordered_dict):
# This loop will raise if it runs more ... | def get_singleton(self):
"""If the row only has one column, return that value; otherwise raise.
Raises:
ValueError, if count of columns is not 1.
"""
only_value = None
for value in six.itervalues(self.ordered_dict):
# This loop will raise if it runs more ... | [
"If",
"the",
"row",
"only",
"has",
"one",
"column",
"return",
"that",
"value",
";",
"otherwise",
"raise",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/ext/row_tuple.py#L93-L110 | [
"def",
"get_singleton",
"(",
"self",
")",
":",
"only_value",
"=",
"None",
"for",
"value",
"in",
"six",
".",
"itervalues",
"(",
"self",
".",
"ordered_dict",
")",
":",
"# This loop will raise if it runs more than once.",
"if",
"only_value",
"is",
"not",
"None",
":... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Command._cpu | Record CPU usage. | redis_metrics/management/commands/system_metric.py | def _cpu(self):
"""Record CPU usage."""
value = int(psutil.cpu_percent())
set_metric("cpu", value, category=self.category)
gauge("cpu", value) | def _cpu(self):
"""Record CPU usage."""
value = int(psutil.cpu_percent())
set_metric("cpu", value, category=self.category)
gauge("cpu", value) | [
"Record",
"CPU",
"usage",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/management/commands/system_metric.py#L83-L87 | [
"def",
"_cpu",
"(",
"self",
")",
":",
"value",
"=",
"int",
"(",
"psutil",
".",
"cpu_percent",
"(",
")",
")",
"set_metric",
"(",
"\"cpu\"",
",",
"value",
",",
"category",
"=",
"self",
".",
"category",
")",
"gauge",
"(",
"\"cpu\"",
",",
"value",
")"
] | 2c92332920113d28c39234b949aa496b39a091d1 |
train | Command._mem | Record Memory usage. | redis_metrics/management/commands/system_metric.py | def _mem(self):
"""Record Memory usage."""
value = int(psutil.virtual_memory().percent)
set_metric("memory", value, category=self.category)
gauge("memory", value) | def _mem(self):
"""Record Memory usage."""
value = int(psutil.virtual_memory().percent)
set_metric("memory", value, category=self.category)
gauge("memory", value) | [
"Record",
"Memory",
"usage",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/management/commands/system_metric.py#L89-L93 | [
"def",
"_mem",
"(",
"self",
")",
":",
"value",
"=",
"int",
"(",
"psutil",
".",
"virtual_memory",
"(",
")",
".",
"percent",
")",
"set_metric",
"(",
"\"memory\"",
",",
"value",
",",
"category",
"=",
"self",
".",
"category",
")",
"gauge",
"(",
"\"memory\"... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | Command._disk | Record Disk usage. | redis_metrics/management/commands/system_metric.py | def _disk(self):
"""Record Disk usage."""
mountpoints = [
p.mountpoint for p in psutil.disk_partitions()
if p.device.endswith(self.device)
]
if len(mountpoints) != 1:
raise CommandError("Unknown device: {0}".format(self.device))
value = int(ps... | def _disk(self):
"""Record Disk usage."""
mountpoints = [
p.mountpoint for p in psutil.disk_partitions()
if p.device.endswith(self.device)
]
if len(mountpoints) != 1:
raise CommandError("Unknown device: {0}".format(self.device))
value = int(ps... | [
"Record",
"Disk",
"usage",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/management/commands/system_metric.py#L95-L106 | [
"def",
"_disk",
"(",
"self",
")",
":",
"mountpoints",
"=",
"[",
"p",
".",
"mountpoint",
"for",
"p",
"in",
"psutil",
".",
"disk_partitions",
"(",
")",
"if",
"p",
".",
"device",
".",
"endswith",
"(",
"self",
".",
"device",
")",
"]",
"if",
"len",
"(",... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | Command._net | Record Network usage. | redis_metrics/management/commands/system_metric.py | def _net(self):
"""Record Network usage."""
data = psutil.network_io_counters(pernic=True)
if self.device not in data:
raise CommandError("Unknown device: {0}".format(self.device))
# Network bytes sent
value = data[self.device].bytes_sent
metric("net-{0}-sent... | def _net(self):
"""Record Network usage."""
data = psutil.network_io_counters(pernic=True)
if self.device not in data:
raise CommandError("Unknown device: {0}".format(self.device))
# Network bytes sent
value = data[self.device].bytes_sent
metric("net-{0}-sent... | [
"Record",
"Network",
"usage",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/management/commands/system_metric.py#L108-L121 | [
"def",
"_net",
"(",
"self",
")",
":",
"data",
"=",
"psutil",
".",
"network_io_counters",
"(",
"pernic",
"=",
"True",
")",
"if",
"self",
".",
"device",
"not",
"in",
"data",
":",
"raise",
"CommandError",
"(",
"\"Unknown device: {0}\"",
".",
"format",
"(",
... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | implements | Does the object 'obj' implement the 'prococol'? | efilter/protocol.py | def implements(obj, protocol):
"""Does the object 'obj' implement the 'prococol'?"""
if isinstance(obj, type):
raise TypeError("First argument to implements must be an instance. "
"Got %r." % obj)
return isinstance(obj, protocol) or issubclass(AnyType, protocol) | def implements(obj, protocol):
"""Does the object 'obj' implement the 'prococol'?"""
if isinstance(obj, type):
raise TypeError("First argument to implements must be an instance. "
"Got %r." % obj)
return isinstance(obj, protocol) or issubclass(AnyType, protocol) | [
"Does",
"the",
"object",
"obj",
"implement",
"the",
"prococol",
"?"
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L73-L78 | [
"def",
"implements",
"(",
"obj",
",",
"protocol",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"type",
")",
":",
"raise",
"TypeError",
"(",
"\"First argument to implements must be an instance. \"",
"\"Got %r.\"",
"%",
"obj",
")",
"return",
"isinstance",
"(",
"... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | isa | Does the type 'cls' participate in the 'protocol'? | efilter/protocol.py | def isa(cls, protocol):
"""Does the type 'cls' participate in the 'protocol'?"""
if not isinstance(cls, type):
raise TypeError("First argument to isa must be a type. Got %s." %
repr(cls))
if not isinstance(protocol, type):
raise TypeError(("Second argument to isa mus... | def isa(cls, protocol):
"""Does the type 'cls' participate in the 'protocol'?"""
if not isinstance(cls, type):
raise TypeError("First argument to isa must be a type. Got %s." %
repr(cls))
if not isinstance(protocol, type):
raise TypeError(("Second argument to isa mus... | [
"Does",
"the",
"type",
"cls",
"participate",
"in",
"the",
"protocol",
"?"
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L81-L90 | [
"def",
"isa",
"(",
"cls",
",",
"protocol",
")",
":",
"if",
"not",
"isinstance",
"(",
"cls",
",",
"type",
")",
":",
"raise",
"TypeError",
"(",
"\"First argument to isa must be a type. Got %s.\"",
"%",
"repr",
"(",
"cls",
")",
")",
"if",
"not",
"isinstance",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Protocol.implemented | Assert that protocol 'cls' is implemented for type 'for_type'.
This will cause 'for_type' to be registered with the protocol 'cls'.
Subsequently, protocol.isa(for_type, cls) will return True, as will
isinstance, issubclass and others.
Raises:
TypeError if 'for_type' doesn't... | efilter/protocol.py | def implemented(cls, for_type):
"""Assert that protocol 'cls' is implemented for type 'for_type'.
This will cause 'for_type' to be registered with the protocol 'cls'.
Subsequently, protocol.isa(for_type, cls) will return True, as will
isinstance, issubclass and others.
Raises:
... | def implemented(cls, for_type):
"""Assert that protocol 'cls' is implemented for type 'for_type'.
This will cause 'for_type' to be registered with the protocol 'cls'.
Subsequently, protocol.isa(for_type, cls) will return True, as will
isinstance, issubclass and others.
Raises:
... | [
"Assert",
"that",
"protocol",
"cls",
"is",
"implemented",
"for",
"type",
"for_type",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L126-L144 | [
"def",
"implemented",
"(",
"cls",
",",
"for_type",
")",
":",
"for",
"function",
"in",
"cls",
".",
"required",
"(",
")",
":",
"if",
"not",
"function",
".",
"implemented_for_type",
"(",
"for_type",
")",
":",
"raise",
"TypeError",
"(",
"\"%r doesn't implement %... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Protocol.__get_type_args | Parse the arguments and return a tuple of types to implement for.
Raises:
ValueError or TypeError as appropriate. | efilter/protocol.py | def __get_type_args(for_type=None, for_types=None):
"""Parse the arguments and return a tuple of types to implement for.
Raises:
ValueError or TypeError as appropriate.
"""
if for_type:
if for_types:
raise ValueError("Cannot pass both for_type and... | def __get_type_args(for_type=None, for_types=None):
"""Parse the arguments and return a tuple of types to implement for.
Raises:
ValueError or TypeError as appropriate.
"""
if for_type:
if for_types:
raise ValueError("Cannot pass both for_type and... | [
"Parse",
"the",
"arguments",
"and",
"return",
"a",
"tuple",
"of",
"types",
"to",
"implement",
"for",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L147-L164 | [
"def",
"__get_type_args",
"(",
"for_type",
"=",
"None",
",",
"for_types",
"=",
"None",
")",
":",
"if",
"for_type",
":",
"if",
"for_types",
":",
"raise",
"ValueError",
"(",
"\"Cannot pass both for_type and for_types.\"",
")",
"for_types",
"=",
"(",
"for_type",
",... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Protocol.implicit_static | Automatically generate implementations for a type.
Implement the protocol for the 'for_type' type by dispatching each
member function of the protocol to an instance method of the same name
declared on the type 'for_type'.
Arguments:
for_type: The type to implictly implement... | efilter/protocol.py | def implicit_static(cls, for_type=None, for_types=None):
"""Automatically generate implementations for a type.
Implement the protocol for the 'for_type' type by dispatching each
member function of the protocol to an instance method of the same name
declared on the type 'for_type'.
... | def implicit_static(cls, for_type=None, for_types=None):
"""Automatically generate implementations for a type.
Implement the protocol for the 'for_type' type by dispatching each
member function of the protocol to an instance method of the same name
declared on the type 'for_type'.
... | [
"Automatically",
"generate",
"implementations",
"for",
"a",
"type",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L187-L219 | [
"def",
"implicit_static",
"(",
"cls",
",",
"for_type",
"=",
"None",
",",
"for_types",
"=",
"None",
")",
":",
"for",
"type_",
"in",
"cls",
".",
"__get_type_args",
"(",
"for_type",
",",
"for_types",
")",
":",
"implementations",
"=",
"{",
"}",
"for",
"funct... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Protocol._build_late_dispatcher | Return a function that calls method 'func_name' on objects.
This is useful for building late-bound dynamic dispatch.
Arguments:
func_name: The name of the instance method that should be called.
Returns:
A function that takes an 'obj' parameter, followed by *args and
... | efilter/protocol.py | def _build_late_dispatcher(func_name):
"""Return a function that calls method 'func_name' on objects.
This is useful for building late-bound dynamic dispatch.
Arguments:
func_name: The name of the instance method that should be called.
Returns:
A function that ... | def _build_late_dispatcher(func_name):
"""Return a function that calls method 'func_name' on objects.
This is useful for building late-bound dynamic dispatch.
Arguments:
func_name: The name of the instance method that should be called.
Returns:
A function that ... | [
"Return",
"a",
"function",
"that",
"calls",
"method",
"func_name",
"on",
"objects",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L222-L245 | [
"def",
"_build_late_dispatcher",
"(",
"func_name",
")",
":",
"def",
"_late_dynamic_dispatcher",
"(",
"obj",
",",
"*",
"args",
")",
":",
"method",
"=",
"getattr",
"(",
"obj",
",",
"func_name",
",",
"None",
")",
"if",
"not",
"callable",
"(",
"method",
")",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Protocol.implicit_dynamic | Automatically generate late dynamic dispatchers to type.
This is similar to 'implicit_static', except instead of binding the
instance methods, it generates a dispatcher that will call whatever
instance method of the same name happens to be available at time of
dispatch.
This ha... | efilter/protocol.py | def implicit_dynamic(cls, for_type=None, for_types=None):
"""Automatically generate late dynamic dispatchers to type.
This is similar to 'implicit_static', except instead of binding the
instance methods, it generates a dispatcher that will call whatever
instance method of the same name ... | def implicit_dynamic(cls, for_type=None, for_types=None):
"""Automatically generate late dynamic dispatchers to type.
This is similar to 'implicit_static', except instead of binding the
instance methods, it generates a dispatcher that will call whatever
instance method of the same name ... | [
"Automatically",
"generate",
"late",
"dynamic",
"dispatchers",
"to",
"type",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L248-L268 | [
"def",
"implicit_dynamic",
"(",
"cls",
",",
"for_type",
"=",
"None",
",",
"for_types",
"=",
"None",
")",
":",
"for",
"type_",
"in",
"cls",
".",
"__get_type_args",
"(",
"for_type",
",",
"for_types",
")",
":",
"implementations",
"=",
"{",
"}",
"for",
"func... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | Protocol.implement | Provide protocol implementation for a type.
Register all implementations of multimethod functions in this
protocol and add the type into the abstract base class of the
protocol.
Arguments:
implementations: A dict of (function, implementation), where each
fun... | efilter/protocol.py | def implement(cls, implementations, for_type=None, for_types=None):
"""Provide protocol implementation for a type.
Register all implementations of multimethod functions in this
protocol and add the type into the abstract base class of the
protocol.
Arguments:
implem... | def implement(cls, implementations, for_type=None, for_types=None):
"""Provide protocol implementation for a type.
Register all implementations of multimethod functions in this
protocol and add the type into the abstract base class of the
protocol.
Arguments:
implem... | [
"Provide",
"protocol",
"implementation",
"for",
"a",
"type",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/protocol.py#L271-L294 | [
"def",
"implement",
"(",
"cls",
",",
"implementations",
",",
"for_type",
"=",
"None",
",",
"for_types",
"=",
"None",
")",
":",
"for",
"type_",
"in",
"cls",
".",
"__get_type_args",
"(",
"for_type",
",",
"for_types",
")",
":",
"cls",
".",
"_implement_for_typ... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | TagFile._parse_query | Parse one of the rules as either objectfilter or dottysql.
Example:
_parse_query("5 + 5")
# Returns Sum(Literal(5), Literal(5))
Arguments:
source: A rule in either objectfilter or dottysql syntax.
Returns:
The AST to represent the rule. | sample_projects/tagging/tag.py | def _parse_query(self, source):
"""Parse one of the rules as either objectfilter or dottysql.
Example:
_parse_query("5 + 5")
# Returns Sum(Literal(5), Literal(5))
Arguments:
source: A rule in either objectfilter or dottysql syntax.
Returns:
... | def _parse_query(self, source):
"""Parse one of the rules as either objectfilter or dottysql.
Example:
_parse_query("5 + 5")
# Returns Sum(Literal(5), Literal(5))
Arguments:
source: A rule in either objectfilter or dottysql syntax.
Returns:
... | [
"Parse",
"one",
"of",
"the",
"rules",
"as",
"either",
"objectfilter",
"or",
"dottysql",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/sample_projects/tagging/tag.py#L96-L114 | [
"def",
"_parse_query",
"(",
"self",
",",
"source",
")",
":",
"if",
"self",
".",
"OBJECTFILTER_WORDS",
".",
"search",
"(",
"source",
")",
":",
"syntax_",
"=",
"\"objectfilter\"",
"else",
":",
"syntax_",
"=",
"None",
"# Default it is.",
"return",
"query",
".",... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | TagFile._parse_tagfile | Parse the tagfile and yield tuples of tag_name, list of rule ASTs. | sample_projects/tagging/tag.py | def _parse_tagfile(self):
"""Parse the tagfile and yield tuples of tag_name, list of rule ASTs."""
rules = None
tag = None
for line in self.original:
match = self.TAG_DECL_LINE.match(line)
if match:
if tag and rules:
yield tag, ... | def _parse_tagfile(self):
"""Parse the tagfile and yield tuples of tag_name, list of rule ASTs."""
rules = None
tag = None
for line in self.original:
match = self.TAG_DECL_LINE.match(line)
if match:
if tag and rules:
yield tag, ... | [
"Parse",
"the",
"tagfile",
"and",
"yield",
"tuples",
"of",
"tag_name",
"list",
"of",
"rule",
"ASTs",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/sample_projects/tagging/tag.py#L116-L132 | [
"def",
"_parse_tagfile",
"(",
"self",
")",
":",
"rules",
"=",
"None",
"tag",
"=",
"None",
"for",
"line",
"in",
"self",
".",
"original",
":",
"match",
"=",
"self",
".",
"TAG_DECL_LINE",
".",
"match",
"(",
"line",
")",
"if",
"match",
":",
"if",
"tag",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | normalize | Normalize both sides, but don't eliminate the expression. | efilter/transforms/normalize.py | def normalize(expr):
"""Normalize both sides, but don't eliminate the expression."""
lhs = normalize(expr.lhs)
rhs = normalize(expr.rhs)
return type(expr)(lhs, rhs, start=lhs.start, end=rhs.end) | def normalize(expr):
"""Normalize both sides, but don't eliminate the expression."""
lhs = normalize(expr.lhs)
rhs = normalize(expr.rhs)
return type(expr)(lhs, rhs, start=lhs.start, end=rhs.end) | [
"Normalize",
"both",
"sides",
"but",
"don",
"t",
"eliminate",
"the",
"expression",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/normalize.py#L64-L68 | [
"def",
"normalize",
"(",
"expr",
")",
":",
"lhs",
"=",
"normalize",
"(",
"expr",
".",
"lhs",
")",
"rhs",
"=",
"normalize",
"(",
"expr",
".",
"rhs",
")",
"return",
"type",
"(",
"expr",
")",
"(",
"lhs",
",",
"rhs",
",",
"start",
"=",
"lhs",
".",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | normalize | No elimination, but normalize arguments. | efilter/transforms/normalize.py | def normalize(expr):
"""No elimination, but normalize arguments."""
args = [normalize(arg) for arg in expr.args]
return type(expr)(expr.func, *args, start=expr.start, end=expr.end) | def normalize(expr):
"""No elimination, but normalize arguments."""
args = [normalize(arg) for arg in expr.args]
return type(expr)(expr.func, *args, start=expr.start, end=expr.end) | [
"No",
"elimination",
"but",
"normalize",
"arguments",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/normalize.py#L72-L76 | [
"def",
"normalize",
"(",
"expr",
")",
":",
"args",
"=",
"[",
"normalize",
"(",
"arg",
")",
"for",
"arg",
"in",
"expr",
".",
"args",
"]",
"return",
"type",
"(",
"expr",
")",
"(",
"expr",
".",
"func",
",",
"*",
"args",
",",
"start",
"=",
"expr",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | normalize | Pass through n-ary expressions, and eliminate empty branches.
Variadic and binary expressions recursively visit all their children.
If all children are eliminated then the parent expression is also
eliminated:
(& [removed] [removed]) => [removed]
If only one child is left, it is promoted to repl... | efilter/transforms/normalize.py | def normalize(expr):
"""Pass through n-ary expressions, and eliminate empty branches.
Variadic and binary expressions recursively visit all their children.
If all children are eliminated then the parent expression is also
eliminated:
(& [removed] [removed]) => [removed]
If only one child is ... | def normalize(expr):
"""Pass through n-ary expressions, and eliminate empty branches.
Variadic and binary expressions recursively visit all their children.
If all children are eliminated then the parent expression is also
eliminated:
(& [removed] [removed]) => [removed]
If only one child is ... | [
"Pass",
"through",
"n",
"-",
"ary",
"expressions",
"and",
"eliminate",
"empty",
"branches",
"."
] | google/dotty | python | https://github.com/google/dotty/blob/b145131499be0c4b755fc2e2ac19be11a50bce6a/efilter/transforms/normalize.py#L80-L112 | [
"def",
"normalize",
"(",
"expr",
")",
":",
"children",
"=",
"[",
"]",
"for",
"child",
"in",
"expr",
".",
"children",
":",
"branch",
"=",
"normalize",
"(",
"child",
")",
"if",
"branch",
"is",
"None",
":",
"continue",
"if",
"type",
"(",
"branch",
")",
... | b145131499be0c4b755fc2e2ac19be11a50bce6a |
train | dedupe | Remove duplicates from a sequence (of hashable items) while maintaining
order. NOTE: This only works if items in the list are hashable types.
Taken from the Python Cookbook, 3rd ed. Such a great book! | redis_metrics/models.py | def dedupe(items):
"""Remove duplicates from a sequence (of hashable items) while maintaining
order. NOTE: This only works if items in the list are hashable types.
Taken from the Python Cookbook, 3rd ed. Such a great book!
"""
seen = set()
for item in items:
if item not in seen:
... | def dedupe(items):
"""Remove duplicates from a sequence (of hashable items) while maintaining
order. NOTE: This only works if items in the list are hashable types.
Taken from the Python Cookbook, 3rd ed. Such a great book!
"""
seen = set()
for item in items:
if item not in seen:
... | [
"Remove",
"duplicates",
"from",
"a",
"sequence",
"(",
"of",
"hashable",
"items",
")",
"while",
"maintaining",
"order",
".",
"NOTE",
":",
"This",
"only",
"works",
"if",
"items",
"in",
"the",
"list",
"are",
"hashable",
"types",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L18-L29 | [
"def",
"dedupe",
"(",
"items",
")",
":",
"seen",
"=",
"set",
"(",
")",
"for",
"item",
"in",
"items",
":",
"if",
"item",
"not",
"in",
"seen",
":",
"yield",
"item",
"seen",
".",
"add",
"(",
"item",
")"
] | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R._date_range | Returns a generator that yields ``datetime.datetime`` objects from
the ``since`` date until ``to`` (default: *now*).
* ``granularity`` -- The granularity at which the generated datetime
objects should be created: seconds, minutes, hourly, daily, weekly,
monthly, or yearly
* ... | redis_metrics/models.py | def _date_range(self, granularity, since, to=None):
"""Returns a generator that yields ``datetime.datetime`` objects from
the ``since`` date until ``to`` (default: *now*).
* ``granularity`` -- The granularity at which the generated datetime
objects should be created: seconds, minutes,... | def _date_range(self, granularity, since, to=None):
"""Returns a generator that yields ``datetime.datetime`` objects from
the ``since`` date until ``to`` (default: *now*).
* ``granularity`` -- The granularity at which the generated datetime
objects should be created: seconds, minutes,... | [
"Returns",
"a",
"generator",
"that",
"yields",
"datetime",
".",
"datetime",
"objects",
"from",
"the",
"since",
"date",
"until",
"to",
"(",
"default",
":",
"*",
"now",
"*",
")",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L91-L144 | [
"def",
"_date_range",
"(",
"self",
",",
"granularity",
",",
"since",
",",
"to",
"=",
"None",
")",
":",
"if",
"since",
"is",
"None",
":",
"since",
"=",
"datetime",
".",
"utcnow",
"(",
")",
"-",
"timedelta",
"(",
"days",
"=",
"7",
")",
"# Default to 7 ... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R._category_slugs | Returns a set of the metric slugs for the given category | redis_metrics/models.py | def _category_slugs(self, category):
"""Returns a set of the metric slugs for the given category"""
key = self._category_key(category)
slugs = self.r.smembers(key)
return slugs | def _category_slugs(self, category):
"""Returns a set of the metric slugs for the given category"""
key = self._category_key(category)
slugs = self.r.smembers(key)
return slugs | [
"Returns",
"a",
"set",
"of",
"the",
"metric",
"slugs",
"for",
"the",
"given",
"category"
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L154-L158 | [
"def",
"_category_slugs",
"(",
"self",
",",
"category",
")",
":",
"key",
"=",
"self",
".",
"_category_key",
"(",
"category",
")",
"slugs",
"=",
"self",
".",
"r",
".",
"smembers",
"(",
"key",
")",
"return",
"slugs"
] | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R._categorize | Add the ``slug`` to the ``category``. We store category data as
as set, with a key of the form::
c:<category name>
The data is set of metric slugs::
"slug-a", "slug-b", ... | redis_metrics/models.py | def _categorize(self, slug, category):
"""Add the ``slug`` to the ``category``. We store category data as
as set, with a key of the form::
c:<category name>
The data is set of metric slugs::
"slug-a", "slug-b", ...
"""
key = self._category_key(category... | def _categorize(self, slug, category):
"""Add the ``slug`` to the ``category``. We store category data as
as set, with a key of the form::
c:<category name>
The data is set of metric slugs::
"slug-a", "slug-b", ...
"""
key = self._category_key(category... | [
"Add",
"the",
"slug",
"to",
"the",
"category",
".",
"We",
"store",
"category",
"data",
"as",
"as",
"set",
"with",
"a",
"key",
"of",
"the",
"form",
"::"
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L160-L175 | [
"def",
"_categorize",
"(",
"self",
",",
"slug",
",",
"category",
")",
":",
"key",
"=",
"self",
".",
"_category_key",
"(",
"category",
")",
"self",
".",
"r",
".",
"sadd",
"(",
"key",
",",
"slug",
")",
"# Store all category names in a Redis set, for easy retriev... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R._granularities | Returns a generator of all possible granularities based on the
MIN_GRANULARITY and MAX_GRANULARITY settings. | redis_metrics/models.py | def _granularities(self):
"""Returns a generator of all possible granularities based on the
MIN_GRANULARITY and MAX_GRANULARITY settings.
"""
keep = False
for g in GRANULARITIES:
if g == app_settings.MIN_GRANULARITY and not keep:
keep = True
... | def _granularities(self):
"""Returns a generator of all possible granularities based on the
MIN_GRANULARITY and MAX_GRANULARITY settings.
"""
keep = False
for g in GRANULARITIES:
if g == app_settings.MIN_GRANULARITY and not keep:
keep = True
... | [
"Returns",
"a",
"generator",
"of",
"all",
"possible",
"granularities",
"based",
"on",
"the",
"MIN_GRANULARITY",
"and",
"MAX_GRANULARITY",
"settings",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L177-L189 | [
"def",
"_granularities",
"(",
"self",
")",
":",
"keep",
"=",
"False",
"for",
"g",
"in",
"GRANULARITIES",
":",
"if",
"g",
"==",
"app_settings",
".",
"MIN_GRANULARITY",
"and",
"not",
"keep",
":",
"keep",
"=",
"True",
"elif",
"g",
"==",
"app_settings",
".",... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R._build_key_patterns | Builds an OrderedDict of metric keys and patterns for the given slug
and date. | redis_metrics/models.py | def _build_key_patterns(self, slug, date):
"""Builds an OrderedDict of metric keys and patterns for the given slug
and date."""
# we want to keep the order, from smallest to largest granularity
patts = OrderedDict()
metric_key_patterns = self._metric_key_patterns()
for g ... | def _build_key_patterns(self, slug, date):
"""Builds an OrderedDict of metric keys and patterns for the given slug
and date."""
# we want to keep the order, from smallest to largest granularity
patts = OrderedDict()
metric_key_patterns = self._metric_key_patterns()
for g ... | [
"Builds",
"an",
"OrderedDict",
"of",
"metric",
"keys",
"and",
"patterns",
"for",
"the",
"given",
"slug",
"and",
"date",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L206-L215 | [
"def",
"_build_key_patterns",
"(",
"self",
",",
"slug",
",",
"date",
")",
":",
"# we want to keep the order, from smallest to largest granularity",
"patts",
"=",
"OrderedDict",
"(",
")",
"metric_key_patterns",
"=",
"self",
".",
"_metric_key_patterns",
"(",
")",
"for",
... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R._build_keys | Builds redis keys used to store metrics.
* ``slug`` -- a slug used for a metric, e.g. "user-signups"
* ``date`` -- (optional) A ``datetime.datetime`` object used to
generate the time period for the metric. If omitted, the current date
and time (in UTC) will be used.
* ``gran... | redis_metrics/models.py | def _build_keys(self, slug, date=None, granularity='all'):
"""Builds redis keys used to store metrics.
* ``slug`` -- a slug used for a metric, e.g. "user-signups"
* ``date`` -- (optional) A ``datetime.datetime`` object used to
generate the time period for the metric. If omitted, the c... | def _build_keys(self, slug, date=None, granularity='all'):
"""Builds redis keys used to store metrics.
* ``slug`` -- a slug used for a metric, e.g. "user-signups"
* ``date`` -- (optional) A ``datetime.datetime`` object used to
generate the time period for the metric. If omitted, the c... | [
"Builds",
"redis",
"keys",
"used",
"to",
"store",
"metrics",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L217-L236 | [
"def",
"_build_keys",
"(",
"self",
",",
"slug",
",",
"date",
"=",
"None",
",",
"granularity",
"=",
"'all'",
")",
":",
"slug",
"=",
"slugify",
"(",
"slug",
")",
"# Ensure slugs have a consistent format",
"if",
"date",
"is",
"None",
":",
"date",
"=",
"dateti... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.metric_slugs_by_category | Return a dictionary of metrics data indexed by category:
{<category_name>: set(<slug1>, <slug2>, ...)} | redis_metrics/models.py | def metric_slugs_by_category(self):
"""Return a dictionary of metrics data indexed by category:
{<category_name>: set(<slug1>, <slug2>, ...)}
"""
result = OrderedDict()
categories = sorted(self.r.smembers(self._categories_key))
for category in categories:
... | def metric_slugs_by_category(self):
"""Return a dictionary of metrics data indexed by category:
{<category_name>: set(<slug1>, <slug2>, ...)}
"""
result = OrderedDict()
categories = sorted(self.r.smembers(self._categories_key))
for category in categories:
... | [
"Return",
"a",
"dictionary",
"of",
"metrics",
"data",
"indexed",
"by",
"category",
":"
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L243-L263 | [
"def",
"metric_slugs_by_category",
"(",
"self",
")",
":",
"result",
"=",
"OrderedDict",
"(",
")",
"categories",
"=",
"sorted",
"(",
"self",
".",
"r",
".",
"smembers",
"(",
"self",
".",
"_categories_key",
")",
")",
"for",
"category",
"in",
"categories",
":"... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.delete_metric | Removes all keys for the given ``slug``. | redis_metrics/models.py | def delete_metric(self, slug):
"""Removes all keys for the given ``slug``."""
# To remove all keys for a slug, I need to retrieve them all from
# the set of metric keys, This uses the redis "keys" command, which is
# inefficient, but this shouldn't be used all that often.
prefix... | def delete_metric(self, slug):
"""Removes all keys for the given ``slug``."""
# To remove all keys for a slug, I need to retrieve them all from
# the set of metric keys, This uses the redis "keys" command, which is
# inefficient, but this shouldn't be used all that often.
prefix... | [
"Removes",
"all",
"keys",
"for",
"the",
"given",
"slug",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L265-L276 | [
"def",
"delete_metric",
"(",
"self",
",",
"slug",
")",
":",
"# To remove all keys for a slug, I need to retrieve them all from",
"# the set of metric keys, This uses the redis \"keys\" command, which is",
"# inefficient, but this shouldn't be used all that often.",
"prefix",
"=",
"\"m:{0}:... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.set_metric | Assigns a specific value to the *current* metric. You can use this
to start a metric at a value greater than 0 or to reset a metric.
The given slug will be used to generate Redis keys at the following
granularities: Seconds, Minutes, Hours, Day, Week, Month, and Year.
Parameters:
... | redis_metrics/models.py | def set_metric(self, slug, value, category=None, expire=None, date=None):
"""Assigns a specific value to the *current* metric. You can use this
to start a metric at a value greater than 0 or to reset a metric.
The given slug will be used to generate Redis keys at the following
granulari... | def set_metric(self, slug, value, category=None, expire=None, date=None):
"""Assigns a specific value to the *current* metric. You can use this
to start a metric at a value greater than 0 or to reset a metric.
The given slug will be used to generate Redis keys at the following
granulari... | [
"Assigns",
"a",
"specific",
"value",
"to",
"the",
"*",
"current",
"*",
"metric",
".",
"You",
"can",
"use",
"this",
"to",
"start",
"a",
"metric",
"at",
"a",
"value",
"greater",
"than",
"0",
"or",
"to",
"reset",
"a",
"metric",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L278-L325 | [
"def",
"set_metric",
"(",
"self",
",",
"slug",
",",
"value",
",",
"category",
"=",
"None",
",",
"expire",
"=",
"None",
",",
"date",
"=",
"None",
")",
":",
"keys",
"=",
"self",
".",
"_build_keys",
"(",
"slug",
",",
"date",
"=",
"date",
")",
"# Add t... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.metric | Records a metric, creating it if it doesn't exist or incrementing it
if it does. All metrics are prefixed with 'm', and automatically
aggregate for Seconds, Minutes, Hours, Day, Week, Month, and Year.
Parameters:
* ``slug`` -- a unique value to identify the metric; used in
co... | redis_metrics/models.py | def metric(self, slug, num=1, category=None, expire=None, date=None):
"""Records a metric, creating it if it doesn't exist or incrementing it
if it does. All metrics are prefixed with 'm', and automatically
aggregate for Seconds, Minutes, Hours, Day, Week, Month, and Year.
Parameters:
... | def metric(self, slug, num=1, category=None, expire=None, date=None):
"""Records a metric, creating it if it doesn't exist or incrementing it
if it does. All metrics are prefixed with 'm', and automatically
aggregate for Seconds, Minutes, Hours, Day, Week, Month, and Year.
Parameters:
... | [
"Records",
"a",
"metric",
"creating",
"it",
"if",
"it",
"doesn",
"t",
"exist",
"or",
"incrementing",
"it",
"if",
"it",
"does",
".",
"All",
"metrics",
"are",
"prefixed",
"with",
"m",
"and",
"automatically",
"aggregate",
"for",
"Seconds",
"Minutes",
"Hours",
... | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L327-L370 | [
"def",
"metric",
"(",
"self",
",",
"slug",
",",
"num",
"=",
"1",
",",
"category",
"=",
"None",
",",
"expire",
"=",
"None",
",",
"date",
"=",
"None",
")",
":",
"# Add the slug to the set of metric slugs",
"self",
".",
"r",
".",
"sadd",
"(",
"self",
".",... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.get_metric | Get the current values for a metric.
Returns a dictionary with metric values accumulated for the seconds,
minutes, hours, day, week, month, and year. | redis_metrics/models.py | def get_metric(self, slug):
"""Get the current values for a metric.
Returns a dictionary with metric values accumulated for the seconds,
minutes, hours, day, week, month, and year.
"""
results = OrderedDict()
granularities = self._granularities()
keys = self._bu... | def get_metric(self, slug):
"""Get the current values for a metric.
Returns a dictionary with metric values accumulated for the seconds,
minutes, hours, day, week, month, and year.
"""
results = OrderedDict()
granularities = self._granularities()
keys = self._bu... | [
"Get",
"the",
"current",
"values",
"for",
"a",
"metric",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L372-L384 | [
"def",
"get_metric",
"(",
"self",
",",
"slug",
")",
":",
"results",
"=",
"OrderedDict",
"(",
")",
"granularities",
"=",
"self",
".",
"_granularities",
"(",
")",
"keys",
"=",
"self",
".",
"_build_keys",
"(",
"slug",
")",
"for",
"granularity",
",",
"key",
... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.get_metrics | Get the metrics for multiple slugs.
Returns a list of two-tuples containing the metric slug and a
dictionary like the one returned by ``get_metric``::
(
some-metric, {
'seconds': 0, 'minutes': 0, 'hours': 0,
'day': 0, 'week': 0, 'mont... | redis_metrics/models.py | def get_metrics(self, slug_list):
"""Get the metrics for multiple slugs.
Returns a list of two-tuples containing the metric slug and a
dictionary like the one returned by ``get_metric``::
(
some-metric, {
'seconds': 0, 'minutes': 0, 'hours': 0,
... | def get_metrics(self, slug_list):
"""Get the metrics for multiple slugs.
Returns a list of two-tuples containing the metric slug and a
dictionary like the one returned by ``get_metric``::
(
some-metric, {
'seconds': 0, 'minutes': 0, 'hours': 0,
... | [
"Get",
"the",
"metrics",
"for",
"multiple",
"slugs",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L386-L412 | [
"def",
"get_metrics",
"(",
"self",
",",
"slug_list",
")",
":",
"# meh. I should have been consistent here, but I'm lazy, so support these",
"# value names instead of granularity names, but respect the min/max",
"# granularity settings.",
"keys",
"=",
"[",
"'seconds'",
",",
"'minutes'... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.get_category_metrics | Get metrics belonging to the given category | redis_metrics/models.py | def get_category_metrics(self, category):
"""Get metrics belonging to the given category"""
slug_list = self._category_slugs(category)
return self.get_metrics(slug_list) | def get_category_metrics(self, category):
"""Get metrics belonging to the given category"""
slug_list = self._category_slugs(category)
return self.get_metrics(slug_list) | [
"Get",
"metrics",
"belonging",
"to",
"the",
"given",
"category"
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L414-L417 | [
"def",
"get_category_metrics",
"(",
"self",
",",
"category",
")",
":",
"slug_list",
"=",
"self",
".",
"_category_slugs",
"(",
"category",
")",
"return",
"self",
".",
"get_metrics",
"(",
"slug_list",
")"
] | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.delete_category | Removes the category from Redis. This doesn't touch the metrics;
they simply become uncategorized. | redis_metrics/models.py | def delete_category(self, category):
"""Removes the category from Redis. This doesn't touch the metrics;
they simply become uncategorized."""
# Remove mapping of metrics-to-category
category_key = self._category_key(category)
self.r.delete(category_key)
# Remove category... | def delete_category(self, category):
"""Removes the category from Redis. This doesn't touch the metrics;
they simply become uncategorized."""
# Remove mapping of metrics-to-category
category_key = self._category_key(category)
self.r.delete(category_key)
# Remove category... | [
"Removes",
"the",
"category",
"from",
"Redis",
".",
"This",
"doesn",
"t",
"touch",
"the",
"metrics",
";",
"they",
"simply",
"become",
"uncategorized",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L419-L427 | [
"def",
"delete_category",
"(",
"self",
",",
"category",
")",
":",
"# Remove mapping of metrics-to-category",
"category_key",
"=",
"self",
".",
"_category_key",
"(",
"category",
")",
"self",
".",
"r",
".",
"delete",
"(",
"category_key",
")",
"# Remove category from S... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.reset_category | Resets (or creates) a category containing a list of metrics.
* ``category`` -- A category name
* ``metric_slugs`` -- a list of all metrics that are members of the
category. | redis_metrics/models.py | def reset_category(self, category, metric_slugs):
"""Resets (or creates) a category containing a list of metrics.
* ``category`` -- A category name
* ``metric_slugs`` -- a list of all metrics that are members of the
category.
"""
key = self._category_key(category)
... | def reset_category(self, category, metric_slugs):
"""Resets (or creates) a category containing a list of metrics.
* ``category`` -- A category name
* ``metric_slugs`` -- a list of all metrics that are members of the
category.
"""
key = self._category_key(category)
... | [
"Resets",
"(",
"or",
"creates",
")",
"a",
"category",
"containing",
"a",
"list",
"of",
"metrics",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L429-L444 | [
"def",
"reset_category",
"(",
"self",
",",
"category",
",",
"metric_slugs",
")",
":",
"key",
"=",
"self",
".",
"_category_key",
"(",
"category",
")",
"if",
"len",
"(",
"metric_slugs",
")",
"==",
"0",
":",
"# If there are no metrics, just remove the category",
"s... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.get_metric_history | Get history for one or more metrics.
* ``slugs`` -- a slug OR a list of slugs
* ``since`` -- the date from which we start pulling metrics
* ``to`` -- the date until which we start pulling metrics
* ``granularity`` -- seconds, minutes, hourly,
daily, weekly, ... | redis_metrics/models.py | def get_metric_history(self, slugs, since=None, to=None, granularity='daily'):
"""Get history for one or more metrics.
* ``slugs`` -- a slug OR a list of slugs
* ``since`` -- the date from which we start pulling metrics
* ``to`` -- the date until which we start pulling metrics
*... | def get_metric_history(self, slugs, since=None, to=None, granularity='daily'):
"""Get history for one or more metrics.
* ``slugs`` -- a slug OR a list of slugs
* ``since`` -- the date from which we start pulling metrics
* ``to`` -- the date until which we start pulling metrics
*... | [
"Get",
"history",
"for",
"one",
"or",
"more",
"metrics",
"."
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L446-L487 | [
"def",
"get_metric_history",
"(",
"self",
",",
"slugs",
",",
"since",
"=",
"None",
",",
"to",
"=",
"None",
",",
"granularity",
"=",
"'daily'",
")",
":",
"if",
"not",
"type",
"(",
"slugs",
")",
"==",
"list",
":",
"slugs",
"=",
"[",
"slugs",
"]",
"# ... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.get_metric_history_as_columns | Provides the same data as ``get_metric_history``, but in a columnar
format. If you had the following yearly history, for example::
[
('m:bar:y:2012', '1'),
('m:bar:y:2013', '2'),
('m:foo:y:2012', '3'),
('m:foo:y:2013', '4')
... | redis_metrics/models.py | def get_metric_history_as_columns(self, slugs, since=None,
granularity='daily'):
"""Provides the same data as ``get_metric_history``, but in a columnar
format. If you had the following yearly history, for example::
[
('m:bar:y:2012', '1'... | def get_metric_history_as_columns(self, slugs, since=None,
granularity='daily'):
"""Provides the same data as ``get_metric_history``, but in a columnar
format. If you had the following yearly history, for example::
[
('m:bar:y:2012', '1'... | [
"Provides",
"the",
"same",
"data",
"as",
"get_metric_history",
"but",
"in",
"a",
"columnar",
"format",
".",
"If",
"you",
"had",
"the",
"following",
"yearly",
"history",
"for",
"example",
"::"
] | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L489-L535 | [
"def",
"get_metric_history_as_columns",
"(",
"self",
",",
"slugs",
",",
"since",
"=",
"None",
",",
"granularity",
"=",
"'daily'",
")",
":",
"history",
"=",
"self",
".",
"get_metric_history",
"(",
"slugs",
",",
"since",
",",
"granularity",
"=",
"granularity",
... | 2c92332920113d28c39234b949aa496b39a091d1 |
train | R.get_metric_history_chart_data | Provides the same data as ``get_metric_history``, but with metrics
data arranged in a format that's easy to plot with Chart.js. If you had
the following yearly history, for example::
[
('m:bar:y:2012', '1'),
('m:bar:y:2013', '2'),
('m:bar:y:20... | redis_metrics/models.py | def get_metric_history_chart_data(self, slugs, since=None, granularity='daily'):
"""Provides the same data as ``get_metric_history``, but with metrics
data arranged in a format that's easy to plot with Chart.js. If you had
the following yearly history, for example::
[
... | def get_metric_history_chart_data(self, slugs, since=None, granularity='daily'):
"""Provides the same data as ``get_metric_history``, but with metrics
data arranged in a format that's easy to plot with Chart.js. If you had
the following yearly history, for example::
[
... | [
"Provides",
"the",
"same",
"data",
"as",
"get_metric_history",
"but",
"with",
"metrics",
"data",
"arranged",
"in",
"a",
"format",
"that",
"s",
"easy",
"to",
"plot",
"with",
"Chart",
".",
"js",
".",
"If",
"you",
"had",
"the",
"following",
"yearly",
"history... | bradmontgomery/django-redis-metrics | python | https://github.com/bradmontgomery/django-redis-metrics/blob/2c92332920113d28c39234b949aa496b39a091d1/redis_metrics/models.py#L537-L592 | [
"def",
"get_metric_history_chart_data",
"(",
"self",
",",
"slugs",
",",
"since",
"=",
"None",
",",
"granularity",
"=",
"'daily'",
")",
":",
"slugs",
"=",
"sorted",
"(",
"slugs",
")",
"history",
"=",
"self",
".",
"get_metric_history",
"(",
"slugs",
",",
"si... | 2c92332920113d28c39234b949aa496b39a091d1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.