Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
NameAliasMixin.get_real_name | (self) | Returns the real name (object name) of this identifier. | Returns the real name (object name) of this identifier. | def get_real_name(self):
"""Returns the real name (object name) of this identifier."""
# a.b
dot_idx, _ = self.token_next_by(m=(T.Punctuation, '.'))
return self._get_first_name(dot_idx, real_name=True) | [
"def",
"get_real_name",
"(",
"self",
")",
":",
"# a.b",
"dot_idx",
",",
"_",
"=",
"self",
".",
"token_next_by",
"(",
"m",
"=",
"(",
"T",
".",
"Punctuation",
",",
"'.'",
")",
")",
"return",
"self",
".",
"_get_first_name",
"(",
"dot_idx",
",",
"real_name... | [
18,
4
] | [
22,
60
] | python | en | ['en', 'en', 'en'] | True |
NameAliasMixin.get_alias | (self) | Returns the alias for this identifier or ``None``. | Returns the alias for this identifier or ``None``. | def get_alias(self):
"""Returns the alias for this identifier or ``None``."""
# "name AS alias"
kw_idx, kw = self.token_next_by(m=(T.Keyword, 'AS'))
if kw is not None:
return self._get_first_name(kw_idx + 1, keywords=True)
# "name alias" or "complicated column expre... | [
"def",
"get_alias",
"(",
"self",
")",
":",
"# \"name AS alias\"",
"kw_idx",
",",
"kw",
"=",
"self",
".",
"token_next_by",
"(",
"m",
"=",
"(",
"T",
".",
"Keyword",
",",
"'AS'",
")",
")",
"if",
"kw",
"is",
"not",
"None",
":",
"return",
"self",
".",
"... | [
24,
4
] | [
35,
53
] | python | en | ['en', 'en', 'en'] | True |
Token.flatten | (self) | Resolve subgroups. | Resolve subgroups. | def flatten(self):
"""Resolve subgroups."""
yield self | [
"def",
"flatten",
"(",
"self",
")",
":",
"yield",
"self"
] | [
83,
4
] | [
85,
18
] | python | en | ['et', 'la', 'en'] | False |
Token.match | (self, ttype, values, regex=False) | Checks whether the token matches the given arguments.
*ttype* is a token type. If this token doesn't match the given token
type.
*values* is a list of possible values for this token. The values
are OR'ed together so if only one of the values matches ``True``
is returned. Except ... | Checks whether the token matches the given arguments. | def match(self, ttype, values, regex=False):
"""Checks whether the token matches the given arguments.
*ttype* is a token type. If this token doesn't match the given token
type.
*values* is a list of possible values for this token. The values
are OR'ed together so if only one of ... | [
"def",
"match",
"(",
"self",
",",
"ttype",
",",
"values",
",",
"regex",
"=",
"False",
")",
":",
"type_matched",
"=",
"self",
".",
"ttype",
"is",
"ttype",
"if",
"not",
"type_matched",
"or",
"values",
"is",
"None",
":",
"return",
"type_matched",
"if",
"i... | [
87,
4
] | [
119,
40
] | python | en | ['en', 'en', 'en'] | True |
Token.within | (self, group_cls) | Returns ``True`` if this token is within *group_cls*.
Use this method for example to check if an identifier is within
a function: ``t.within(sql.Function)``.
| Returns ``True`` if this token is within *group_cls*. | def within(self, group_cls):
"""Returns ``True`` if this token is within *group_cls*.
Use this method for example to check if an identifier is within
a function: ``t.within(sql.Function)``.
"""
parent = self.parent
while parent:
if isinstance(parent, group_cl... | [
"def",
"within",
"(",
"self",
",",
"group_cls",
")",
":",
"parent",
"=",
"self",
".",
"parent",
"while",
"parent",
":",
"if",
"isinstance",
"(",
"parent",
",",
"group_cls",
")",
":",
"return",
"True",
"parent",
"=",
"parent",
".",
"parent",
"return",
"... | [
121,
4
] | [
132,
20
] | python | en | ['en', 'en', 'en'] | True |
Token.is_child_of | (self, other) | Returns ``True`` if this token is a direct child of *other*. | Returns ``True`` if this token is a direct child of *other*. | def is_child_of(self, other):
"""Returns ``True`` if this token is a direct child of *other*."""
return self.parent == other | [
"def",
"is_child_of",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"parent",
"==",
"other"
] | [
134,
4
] | [
136,
35
] | python | en | ['en', 'en', 'en'] | True |
Token.has_ancestor | (self, other) | Returns ``True`` if *other* is in this tokens ancestry. | Returns ``True`` if *other* is in this tokens ancestry. | def has_ancestor(self, other):
"""Returns ``True`` if *other* is in this tokens ancestry."""
parent = self.parent
while parent:
if parent == other:
return True
parent = parent.parent
return False | [
"def",
"has_ancestor",
"(",
"self",
",",
"other",
")",
":",
"parent",
"=",
"self",
".",
"parent",
"while",
"parent",
":",
"if",
"parent",
"==",
"other",
":",
"return",
"True",
"parent",
"=",
"parent",
".",
"parent",
"return",
"False"
] | [
138,
4
] | [
145,
20
] | python | en | ['en', 'en', 'en'] | True |
TokenList._pprint_tree | (self, max_depth=None, depth=0, f=None, _pre='') | Pretty-print the object tree. | Pretty-print the object tree. | def _pprint_tree(self, max_depth=None, depth=0, f=None, _pre=''):
"""Pretty-print the object tree."""
token_count = len(self.tokens)
for idx, token in enumerate(self.tokens):
cls = token._get_repr_name()
value = token._get_repr_value()
last = idx == (token_co... | [
"def",
"_pprint_tree",
"(",
"self",
",",
"max_depth",
"=",
"None",
",",
"depth",
"=",
"0",
",",
"f",
"=",
"None",
",",
"_pre",
"=",
"''",
")",
":",
"token_count",
"=",
"len",
"(",
"self",
".",
"tokens",
")",
"for",
"idx",
",",
"token",
"in",
"enu... | [
179,
4
] | [
195,
78
] | python | en | ['en', 'mt', 'en'] | True |
TokenList.get_token_at_offset | (self, offset) | Returns the token that is on position offset. | Returns the token that is on position offset. | def get_token_at_offset(self, offset):
"""Returns the token that is on position offset."""
idx = 0
for token in self.flatten():
end = idx + len(token.value)
if idx <= offset < end:
return token
idx = end | [
"def",
"get_token_at_offset",
"(",
"self",
",",
"offset",
")",
":",
"idx",
"=",
"0",
"for",
"token",
"in",
"self",
".",
"flatten",
"(",
")",
":",
"end",
"=",
"idx",
"+",
"len",
"(",
"token",
".",
"value",
")",
"if",
"idx",
"<=",
"offset",
"<",
"e... | [
197,
4
] | [
204,
21
] | python | en | ['en', 'en', 'en'] | True |
TokenList.flatten | (self) | Generator yielding ungrouped tokens.
This method is recursively called for all child tokens.
| Generator yielding ungrouped tokens. | def flatten(self):
"""Generator yielding ungrouped tokens.
This method is recursively called for all child tokens.
"""
for token in self.tokens:
if token.is_group:
yield from token.flatten()
else:
yield token | [
"def",
"flatten",
"(",
"self",
")",
":",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"if",
"token",
".",
"is_group",
":",
"yield",
"from",
"token",
".",
"flatten",
"(",
")",
"else",
":",
"yield",
"token"
] | [
206,
4
] | [
215,
27
] | python | en | ['en', 'en', 'es'] | True |
TokenList._token_matching | (self, funcs, start=0, end=None, reverse=False) | next token that match functions | next token that match functions | def _token_matching(self, funcs, start=0, end=None, reverse=False):
"""next token that match functions"""
if start is None:
return None
if not isinstance(funcs, (list, tuple)):
funcs = (funcs,)
if reverse:
assert end is None
for idx in ra... | [
"def",
"_token_matching",
"(",
"self",
",",
"funcs",
",",
"start",
"=",
"0",
",",
"end",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"if",
"start",
"is",
"None",
":",
"return",
"None",
"if",
"not",
"isinstance",
"(",
"funcs",
",",
"(",
"li... | [
226,
4
] | [
246,
25
] | python | en | ['en', 'en', 'en'] | True |
TokenList.token_first | (self, skip_ws=True, skip_cm=False) | Returns the first child token.
If *skip_ws* is ``True`` (the default), whitespace
tokens are ignored.
if *skip_cm* is ``True`` (default: ``False``), comments are
ignored too.
| Returns the first child token. | def token_first(self, skip_ws=True, skip_cm=False):
"""Returns the first child token.
If *skip_ws* is ``True`` (the default), whitespace
tokens are ignored.
if *skip_cm* is ``True`` (default: ``False``), comments are
ignored too.
"""
# this on is inconsistent, u... | [
"def",
"token_first",
"(",
"self",
",",
"skip_ws",
"=",
"True",
",",
"skip_cm",
"=",
"False",
")",
":",
"# this on is inconsistent, using Comment instead of T.Comment...",
"def",
"matcher",
"(",
"tk",
")",
":",
"return",
"not",
"(",
"(",
"skip_ws",
"and",
"tk",
... | [
248,
4
] | [
261,
47
] | python | en | ['en', 'de', 'en'] | True |
TokenList.token_prev | (self, idx, skip_ws=True, skip_cm=False) | Returns the previous token relative to *idx*.
If *skip_ws* is ``True`` (the default) whitespace tokens are ignored.
If *skip_cm* is ``True`` comments are ignored.
``None`` is returned if there's no previous token.
| Returns the previous token relative to *idx*. | def token_prev(self, idx, skip_ws=True, skip_cm=False):
"""Returns the previous token relative to *idx*.
If *skip_ws* is ``True`` (the default) whitespace tokens are ignored.
If *skip_cm* is ``True`` comments are ignored.
``None`` is returned if there's no previous token.
"""
... | [
"def",
"token_prev",
"(",
"self",
",",
"idx",
",",
"skip_ws",
"=",
"True",
",",
"skip_cm",
"=",
"False",
")",
":",
"return",
"self",
".",
"token_next",
"(",
"idx",
",",
"skip_ws",
",",
"skip_cm",
",",
"_reverse",
"=",
"True",
")"
] | [
275,
4
] | [
282,
68
] | python | en | ['en', 'gl', 'en'] | True |
TokenList.token_next | (self, idx, skip_ws=True, skip_cm=False, _reverse=False) | Returns the next token relative to *idx*.
If *skip_ws* is ``True`` (the default) whitespace tokens are ignored.
If *skip_cm* is ``True`` comments are ignored.
``None`` is returned if there's no next token.
| Returns the next token relative to *idx*. | def token_next(self, idx, skip_ws=True, skip_cm=False, _reverse=False):
"""Returns the next token relative to *idx*.
If *skip_ws* is ``True`` (the default) whitespace tokens are ignored.
If *skip_cm* is ``True`` comments are ignored.
``None`` is returned if there's no next token.
... | [
"def",
"token_next",
"(",
"self",
",",
"idx",
",",
"skip_ws",
"=",
"True",
",",
"skip_cm",
"=",
"False",
",",
"_reverse",
"=",
"False",
")",
":",
"if",
"idx",
"is",
"None",
":",
"return",
"None",
",",
"None",
"idx",
"+=",
"1",
"# alot of code usage cur... | [
285,
4
] | [
299,
67
] | python | en | ['en', 'nl', 'en'] | True |
TokenList.token_index | (self, token, start=0) | Return list index of token. | Return list index of token. | def token_index(self, token, start=0):
"""Return list index of token."""
start = start if isinstance(start, int) else self.token_index(start)
return start + self.tokens[start:].index(token) | [
"def",
"token_index",
"(",
"self",
",",
"token",
",",
"start",
"=",
"0",
")",
":",
"start",
"=",
"start",
"if",
"isinstance",
"(",
"start",
",",
"int",
")",
"else",
"self",
".",
"token_index",
"(",
"start",
")",
"return",
"start",
"+",
"self",
".",
... | [
301,
4
] | [
304,
55
] | python | en | ['en', 'de', 'en'] | True |
TokenList.group_tokens | (self, grp_cls, start, end, include_end=True,
extend=False) | Replace tokens by an instance of *grp_cls*. | Replace tokens by an instance of *grp_cls*. | def group_tokens(self, grp_cls, start, end, include_end=True,
extend=False):
"""Replace tokens by an instance of *grp_cls*."""
start_idx = start
start = self.tokens[start_idx]
end_idx = end + include_end
# will be needed later for new group_clauses
... | [
"def",
"group_tokens",
"(",
"self",
",",
"grp_cls",
",",
"start",
",",
"end",
",",
"include_end",
"=",
"True",
",",
"extend",
"=",
"False",
")",
":",
"start_idx",
"=",
"start",
"start",
"=",
"self",
".",
"tokens",
"[",
"start_idx",
"]",
"end_idx",
"=",... | [
306,
4
] | [
334,
18
] | python | en | ['en', 'en', 'en'] | True |
TokenList.insert_before | (self, where, token) | Inserts *token* before *where*. | Inserts *token* before *where*. | def insert_before(self, where, token):
"""Inserts *token* before *where*."""
if not isinstance(where, int):
where = self.token_index(where)
token.parent = self
self.tokens.insert(where, token) | [
"def",
"insert_before",
"(",
"self",
",",
"where",
",",
"token",
")",
":",
"if",
"not",
"isinstance",
"(",
"where",
",",
"int",
")",
":",
"where",
"=",
"self",
".",
"token_index",
"(",
"where",
")",
"token",
".",
"parent",
"=",
"self",
"self",
".",
... | [
336,
4
] | [
341,
40
] | python | en | ['en', 'en', 'en'] | True |
TokenList.insert_after | (self, where, token, skip_ws=True) | Inserts *token* after *where*. | Inserts *token* after *where*. | def insert_after(self, where, token, skip_ws=True):
"""Inserts *token* after *where*."""
if not isinstance(where, int):
where = self.token_index(where)
nidx, next_ = self.token_next(where, skip_ws=skip_ws)
token.parent = self
if next_ is None:
self.tokens.... | [
"def",
"insert_after",
"(",
"self",
",",
"where",
",",
"token",
",",
"skip_ws",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"where",
",",
"int",
")",
":",
"where",
"=",
"self",
".",
"token_index",
"(",
"where",
")",
"nidx",
",",
"next_",
... | [
343,
4
] | [
352,
43
] | python | en | ['en', 'en', 'en'] | True |
TokenList.has_alias | (self) | Returns ``True`` if an alias is present. | Returns ``True`` if an alias is present. | def has_alias(self):
"""Returns ``True`` if an alias is present."""
return self.get_alias() is not None | [
"def",
"has_alias",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_alias",
"(",
")",
"is",
"not",
"None"
] | [
354,
4
] | [
356,
43
] | python | en | ['en', 'lb', 'en'] | True |
TokenList.get_alias | (self) | Returns the alias for this identifier or ``None``. | Returns the alias for this identifier or ``None``. | def get_alias(self):
"""Returns the alias for this identifier or ``None``."""
return None | [
"def",
"get_alias",
"(",
"self",
")",
":",
"return",
"None"
] | [
358,
4
] | [
360,
19
] | python | en | ['en', 'en', 'en'] | True |
TokenList.get_name | (self) | Returns the name of this identifier.
This is either it's alias or it's real name. The returned valued can
be considered as the name under which the object corresponding to
this identifier is known within the current statement.
| Returns the name of this identifier. | def get_name(self):
"""Returns the name of this identifier.
This is either it's alias or it's real name. The returned valued can
be considered as the name under which the object corresponding to
this identifier is known within the current statement.
"""
return self.get_a... | [
"def",
"get_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_alias",
"(",
")",
"or",
"self",
".",
"get_real_name",
"(",
")"
] | [
362,
4
] | [
369,
55
] | python | en | ['en', 'en', 'en'] | True |
TokenList.get_real_name | (self) | Returns the real name (object name) of this identifier. | Returns the real name (object name) of this identifier. | def get_real_name(self):
"""Returns the real name (object name) of this identifier."""
return None | [
"def",
"get_real_name",
"(",
"self",
")",
":",
"return",
"None"
] | [
371,
4
] | [
373,
19
] | python | en | ['en', 'en', 'en'] | True |
TokenList.get_parent_name | (self) | Return name of the parent object if any.
A parent object is identified by the first occurring dot.
| Return name of the parent object if any. | def get_parent_name(self):
"""Return name of the parent object if any.
A parent object is identified by the first occurring dot.
"""
dot_idx, _ = self.token_next_by(m=(T.Punctuation, '.'))
_, prev_ = self.token_prev(dot_idx)
return remove_quotes(prev_.value) if prev_ is ... | [
"def",
"get_parent_name",
"(",
"self",
")",
":",
"dot_idx",
",",
"_",
"=",
"self",
".",
"token_next_by",
"(",
"m",
"=",
"(",
"T",
".",
"Punctuation",
",",
"'.'",
")",
")",
"_",
",",
"prev_",
"=",
"self",
".",
"token_prev",
"(",
"dot_idx",
")",
"ret... | [
375,
4
] | [
382,
72
] | python | en | ['en', 'en', 'en'] | True |
TokenList._get_first_name | (self, idx=None, reverse=False, keywords=False,
real_name=False) | Returns the name of the first token with a name | Returns the name of the first token with a name | def _get_first_name(self, idx=None, reverse=False, keywords=False,
real_name=False):
"""Returns the name of the first token with a name"""
tokens = self.tokens[idx:] if idx else self.tokens
tokens = reversed(tokens) if reverse else tokens
types = [T.Name, T.Wildc... | [
"def",
"_get_first_name",
"(",
"self",
",",
"idx",
"=",
"None",
",",
"reverse",
"=",
"False",
",",
"keywords",
"=",
"False",
",",
"real_name",
"=",
"False",
")",
":",
"tokens",
"=",
"self",
".",
"tokens",
"[",
"idx",
":",
"]",
"if",
"idx",
"else",
... | [
384,
4
] | [
399,
79
] | python | en | ['en', 'en', 'en'] | True |
Statement.get_type | (self) | Returns the type of a statement.
The returned value is a string holding an upper-cased reprint of
the first DML or DDL keyword. If the first token in this group
isn't a DML or DDL keyword "UNKNOWN" is returned.
Whitespaces and comments at the beginning of the statement
are igno... | Returns the type of a statement. | def get_type(self):
"""Returns the type of a statement.
The returned value is a string holding an upper-cased reprint of
the first DML or DDL keyword. If the first token in this group
isn't a DML or DDL keyword "UNKNOWN" is returned.
Whitespaces and comments at the beginning of... | [
"def",
"get_type",
"(",
"self",
")",
":",
"first_token",
"=",
"self",
".",
"token_first",
"(",
"skip_cm",
"=",
"True",
")",
"if",
"first_token",
"is",
"None",
":",
"# An \"empty\" statement that either has not tokens at all",
"# or only whitespace tokens.",
"return",
... | [
405,
4
] | [
438,
24
] | python | en | ['en', 'en', 'en'] | True |
Identifier.is_wildcard | (self) | Return ``True`` if this identifier contains a wildcard. | Return ``True`` if this identifier contains a wildcard. | def is_wildcard(self):
"""Return ``True`` if this identifier contains a wildcard."""
_, token = self.token_next_by(t=T.Wildcard)
return token is not None | [
"def",
"is_wildcard",
"(",
"self",
")",
":",
"_",
",",
"token",
"=",
"self",
".",
"token_next_by",
"(",
"t",
"=",
"T",
".",
"Wildcard",
")",
"return",
"token",
"is",
"not",
"None"
] | [
447,
4
] | [
450,
32
] | python | en | ['en', 'en', 'en'] | True |
Identifier.get_typecast | (self) | Returns the typecast or ``None`` of this object as a string. | Returns the typecast or ``None`` of this object as a string. | def get_typecast(self):
"""Returns the typecast or ``None`` of this object as a string."""
midx, marker = self.token_next_by(m=(T.Punctuation, '::'))
nidx, next_ = self.token_next(midx, skip_ws=False)
return next_.value if next_ else None | [
"def",
"get_typecast",
"(",
"self",
")",
":",
"midx",
",",
"marker",
"=",
"self",
".",
"token_next_by",
"(",
"m",
"=",
"(",
"T",
".",
"Punctuation",
",",
"'::'",
")",
")",
"nidx",
",",
"next_",
"=",
"self",
".",
"token_next",
"(",
"midx",
",",
"ski... | [
452,
4
] | [
456,
45
] | python | en | ['en', 'en', 'en'] | True |
Identifier.get_ordering | (self) | Returns the ordering or ``None`` as uppercase string. | Returns the ordering or ``None`` as uppercase string. | def get_ordering(self):
"""Returns the ordering or ``None`` as uppercase string."""
_, ordering = self.token_next_by(t=T.Keyword.Order)
return ordering.normalized if ordering else None | [
"def",
"get_ordering",
"(",
"self",
")",
":",
"_",
",",
"ordering",
"=",
"self",
".",
"token_next_by",
"(",
"t",
"=",
"T",
".",
"Keyword",
".",
"Order",
")",
"return",
"ordering",
".",
"normalized",
"if",
"ordering",
"else",
"None"
] | [
458,
4
] | [
461,
56
] | python | en | ['en', 'en', 'en'] | True |
Identifier.get_array_indices | (self) | Returns an iterator of index token lists | Returns an iterator of index token lists | def get_array_indices(self):
"""Returns an iterator of index token lists"""
for token in self.tokens:
if isinstance(token, SquareBrackets):
# Use [1:-1] index to discard the square brackets
yield token.tokens[1:-1] | [
"def",
"get_array_indices",
"(",
"self",
")",
":",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"if",
"isinstance",
"(",
"token",
",",
"SquareBrackets",
")",
":",
"# Use [1:-1] index to discard the square brackets",
"yield",
"token",
".",
"tokens",
"[",
"1"... | [
463,
4
] | [
469,
40
] | python | en | ['en', 'en', 'en'] | True |
IdentifierList.get_identifiers | (self) | Returns the identifiers.
Whitespaces and punctuations are not included in this generator.
| Returns the identifiers. | def get_identifiers(self):
"""Returns the identifiers.
Whitespaces and punctuations are not included in this generator.
"""
for token in self.tokens:
if not (token.is_whitespace or token.match(T.Punctuation, ',')):
yield token | [
"def",
"get_identifiers",
"(",
"self",
")",
":",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"if",
"not",
"(",
"token",
".",
"is_whitespace",
"or",
"token",
".",
"match",
"(",
"T",
".",
"Punctuation",
",",
"','",
")",
")",
":",
"yield",
"token"... | [
475,
4
] | [
482,
27
] | python | en | ['en', 'nl', 'en'] | True |
Case.get_cases | (self, skip_ws=False) | Returns a list of 2-tuples (condition, value).
If an ELSE exists condition is None.
| Returns a list of 2-tuples (condition, value). | def get_cases(self, skip_ws=False):
"""Returns a list of 2-tuples (condition, value).
If an ELSE exists condition is None.
"""
CONDITION = 1
VALUE = 2
ret = []
mode = CONDITION
for token in self.tokens:
# Set mode from the current statement
... | [
"def",
"get_cases",
"(",
"self",
",",
"skip_ws",
"=",
"False",
")",
":",
"CONDITION",
"=",
"1",
"VALUE",
"=",
"2",
"ret",
"=",
"[",
"]",
"mode",
"=",
"CONDITION",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"# Set mode from the current statement",
... | [
566,
4
] | [
611,
18
] | python | en | ['en', 'en', 'en'] | True |
Function.get_parameters | (self) | Return a list of parameters. | Return a list of parameters. | def get_parameters(self):
"""Return a list of parameters."""
parenthesis = self.tokens[-1]
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier), t=T.Literal):
... | [
"def",
"get_parameters",
"(",
"self",
")",
":",
"parenthesis",
"=",
"self",
".",
"tokens",
"[",
"-",
"1",
"]",
"for",
"token",
"in",
"parenthesis",
".",
"tokens",
":",
"if",
"isinstance",
"(",
"token",
",",
"IdentifierList",
")",
":",
"return",
"token",
... | [
617,
4
] | [
625,
17
] | python | en | ['en', 'en', 'en'] | True |
Player._object_distance | (self, object1, object2) | Computes distance between two objects. | Computes distance between two objects. | def _object_distance(self, object1, object2):
"""Computes distance between two objects."""
return np.linalg.norm(np.array(object1) - np.array(object2)) | [
"def",
"_object_distance",
"(",
"self",
",",
"object1",
",",
"object2",
")",
":",
"return",
"np",
".",
"linalg",
".",
"norm",
"(",
"np",
".",
"array",
"(",
"object1",
")",
"-",
"np",
".",
"array",
"(",
"object2",
")",
")"
] | [
35,
2
] | [
37,
64
] | python | en | ['fr', 'en', 'en'] | True |
Player._direction_action | (self, delta) | For required movement direction vector returns appropriate action. | For required movement direction vector returns appropriate action. | def _direction_action(self, delta):
"""For required movement direction vector returns appropriate action."""
all_directions = [
football_action_set.action_top,
football_action_set.action_top_left,
football_action_set.action_left,
football_action_set.action_bottom_left,
fo... | [
"def",
"_direction_action",
"(",
"self",
",",
"delta",
")",
":",
"all_directions",
"=",
"[",
"football_action_set",
".",
"action_top",
",",
"football_action_set",
".",
"action_top_left",
",",
"football_action_set",
".",
"action_left",
",",
"football_action_set",
".",
... | [
39,
2
] | [
57,
41
] | python | en | ['fr', 'en', 'en'] | True |
Player._closest_opponent_to_object | (self, o) | For a given object returns the closest opponent.
Args:
o: Source object.
Returns:
Closest opponent. | For a given object returns the closest opponent. | def _closest_opponent_to_object(self, o):
"""For a given object returns the closest opponent.
Args:
o: Source object.
Returns:
Closest opponent."""
min_d = None
closest = None
for p in self._observation['right_team']:
d = self._object_distance(o, p)
if min_d is None or ... | [
"def",
"_closest_opponent_to_object",
"(",
"self",
",",
"o",
")",
":",
"min_d",
"=",
"None",
"closest",
"=",
"None",
"for",
"p",
"in",
"self",
".",
"_observation",
"[",
"'right_team'",
"]",
":",
"d",
"=",
"self",
".",
"_object_distance",
"(",
"o",
",",
... | [
59,
2
] | [
75,
18
] | python | en | ['en', 'en', 'en'] | True |
Player._closest_front_opponent | (self, o, target) | For an object and its movement direction returns the closest opponent.
Args:
o: Source object.
target: Movement direction.
Returns:
Closest front opponent. | For an object and its movement direction returns the closest opponent. | def _closest_front_opponent(self, o, target):
"""For an object and its movement direction returns the closest opponent.
Args:
o: Source object.
target: Movement direction.
Returns:
Closest front opponent."""
delta = target - o
min_d = None
closest = None
for p in self._ob... | [
"def",
"_closest_front_opponent",
"(",
"self",
",",
"o",
",",
"target",
")",
":",
"delta",
"=",
"target",
"-",
"o",
"min_d",
"=",
"None",
"closest",
"=",
"None",
"for",
"p",
"in",
"self",
".",
"_observation",
"[",
"'right_team'",
"]",
":",
"delta_opp",
... | [
77,
2
] | [
99,
18
] | python | en | ['en', 'en', 'en'] | True |
Player._score_pass_target | (self, active, player) | Computes score of the pass between players.
Args:
active: Player doing the pass.
player: Player receiving the pass.
Returns:
Score of the pass.
| Computes score of the pass between players. | def _score_pass_target(self, active, player):
"""Computes score of the pass between players.
Args:
active: Player doing the pass.
player: Player receiving the pass.
Returns:
Score of the pass.
"""
opponent = self._closest_opponent_to_object(player)
dist = self._object_distanc... | [
"def",
"_score_pass_target",
"(",
"self",
",",
"active",
",",
"player",
")",
":",
"opponent",
"=",
"self",
".",
"_closest_opponent_to_object",
"(",
"player",
")",
"dist",
"=",
"self",
".",
"_object_distance",
"(",
"player",
",",
"opponent",
")",
"trajectory",
... | [
101,
2
] | [
121,
29
] | python | en | ['en', 'en', 'en'] | True |
Player._best_pass_target | (self, active) | Computes best pass a given player can do.
Args:
active: Player doing the pass.
Returns:
Best target player receiving the pass.
| Computes best pass a given player can do. | def _best_pass_target(self, active):
"""Computes best pass a given player can do.
Args:
active: Player doing the pass.
Returns:
Best target player receiving the pass.
"""
best_score = None
best_target = None
for player in self._observation['left_team']:
if self._object_di... | [
"def",
"_best_pass_target",
"(",
"self",
",",
"active",
")",
":",
"best_score",
"=",
"None",
"best_target",
"=",
"None",
"for",
"player",
"in",
"self",
".",
"_observation",
"[",
"'left_team'",
"]",
":",
"if",
"self",
".",
"_object_distance",
"(",
"player",
... | [
123,
2
] | [
141,
22
] | python | en | ['en', 'en', 'en'] | True |
Player._avoid_opponent | (self, active, opponent, target) | Computes movement action to avoid a given opponent.
Args:
active: Active player.
opponent: Opponent to be avoided.
target: Original movement direction of the active player.
Returns:
Action to perform to avoid the opponent.
| Computes movement action to avoid a given opponent. | def _avoid_opponent(self, active, opponent, target):
"""Computes movement action to avoid a given opponent.
Args:
active: Active player.
opponent: Opponent to be avoided.
target: Original movement direction of the active player.
Returns:
Action to perform to avoid the opponent.
... | [
"def",
"_avoid_opponent",
"(",
"self",
",",
"active",
",",
"opponent",
",",
"target",
")",
":",
"# Choose a perpendicular direction to the opponent, towards the target.",
"delta",
"=",
"opponent",
"-",
"active",
"delta_t",
"=",
"target",
"-",
"active",
"new_delta",
"=... | [
143,
2
] | [
161,
44
] | python | en | ['en', 'en', 'en'] | True |
Player._get_action | (self) | Returns action to perform for the current observations. | Returns action to perform for the current observations. | def _get_action(self):
"""Returns action to perform for the current observations."""
active = self._observation['left_team'][self._observation['active']]
# Corner etc. - just pass the ball
if self._observation['game_mode'] != 0:
return football_action_set.action_long_pass
if self._observation... | [
"def",
"_get_action",
"(",
"self",
")",
":",
"active",
"=",
"self",
".",
"_observation",
"[",
"'left_team'",
"]",
"[",
"self",
".",
"_observation",
"[",
"'active'",
"]",
"]",
"# Corner etc. - just pass the ball",
"if",
"self",
".",
"_observation",
"[",
"'game_... | [
163,
2
] | [
208,
22
] | python | en | ['en', 'en', 'en'] | True |
reg | (request) |
This fixture initializes an awx settings registry object and passes it as
an argument into the test function.
|
This fixture initializes an awx settings registry object and passes it as
an argument into the test function.
| def reg(request):
"""
This fixture initializes an awx settings registry object and passes it as
an argument into the test function.
"""
cache = LocMemCache(str(uuid4()), {}) # make a new random cache each time
settings = LazySettings()
registry = SettingsRegistry(settings)
# @pytest.ma... | [
"def",
"reg",
"(",
"request",
")",
":",
"cache",
"=",
"LocMemCache",
"(",
"str",
"(",
"uuid4",
"(",
")",
")",
",",
"{",
"}",
")",
"# make a new random cache each time",
"settings",
"=",
"LazySettings",
"(",
")",
"registry",
"=",
"SettingsRegistry",
"(",
"s... | [
18,
0
] | [
36,
19
] | python | en | ['en', 'error', 'th'] | False |
test_duplicate_setting_registration | (reg) | ensure that settings cannot be registered twice. | ensure that settings cannot be registered twice. | def test_duplicate_setting_registration(reg):
"ensure that settings cannot be registered twice."
with pytest.raises(ImproperlyConfigured):
for i in range(2):
reg.register('AWX_SOME_SETTING_ENABLED', field_class=fields.BooleanField, category=_('System'), category_slug='system') | [
"def",
"test_duplicate_setting_registration",
"(",
"reg",
")",
":",
"with",
"pytest",
".",
"raises",
"(",
"ImproperlyConfigured",
")",
":",
"for",
"i",
"in",
"range",
"(",
"2",
")",
":",
"reg",
".",
"register",
"(",
"'AWX_SOME_SETTING_ENABLED'",
",",
"field_cl... | [
53,
0
] | [
57,
131
] | python | en | ['en', 'en', 'en'] | True |
test_field_class_required_for_registration | (reg) | settings must specify a field class to register | settings must specify a field class to register | def test_field_class_required_for_registration(reg):
"settings must specify a field class to register"
with pytest.raises(ImproperlyConfigured):
reg.register('AWX_SOME_SETTING_ENABLED') | [
"def",
"test_field_class_required_for_registration",
"(",
"reg",
")",
":",
"with",
"pytest",
".",
"raises",
"(",
"ImproperlyConfigured",
")",
":",
"reg",
".",
"register",
"(",
"'AWX_SOME_SETTING_ENABLED'",
")"
] | [
60,
0
] | [
63,
48
] | python | en | ['en', 'en', 'en'] | True |
_AwxTaskError.TaskCancel | (self, task, rc) | Canceled flag caused run_pexpect to kill the job run | Canceled flag caused run_pexpect to kill the job run | def TaskCancel(self, task, rc):
"""Canceled flag caused run_pexpect to kill the job run"""
message = "{} was canceled (rc={})".format(task.log_format, rc)
e = self.build_exception(task, message)
e.rc = rc
e.awx_task_error_type = "TaskCancel"
return e | [
"def",
"TaskCancel",
"(",
"self",
",",
"task",
",",
"rc",
")",
":",
"message",
"=",
"\"{} was canceled (rc={})\"",
".",
"format",
"(",
"task",
".",
"log_format",
",",
"rc",
")",
"e",
"=",
"self",
".",
"build_exception",
"(",
"task",
",",
"message",
")",
... | [
13,
4
] | [
19,
16
] | python | en | ['en', 'ga', 'en'] | True |
_AwxTaskError.TaskError | (self, task, rc) | Userspace error (non-zero exit code) in run_pexpect subprocess | Userspace error (non-zero exit code) in run_pexpect subprocess | def TaskError(self, task, rc):
"""Userspace error (non-zero exit code) in run_pexpect subprocess"""
message = "{} encountered an error (rc={}), please see task stdout for details.".format(task.log_format, rc)
e = self.build_exception(task, message)
e.rc = rc
e.awx_task_error_type... | [
"def",
"TaskError",
"(",
"self",
",",
"task",
",",
"rc",
")",
":",
"message",
"=",
"\"{} encountered an error (rc={}), please see task stdout for details.\"",
".",
"format",
"(",
"task",
".",
"log_format",
",",
"rc",
")",
"e",
"=",
"self",
".",
"build_exception",
... | [
21,
4
] | [
27,
16
] | python | en | ['eu', 'it', 'en'] | False |
check_realm_emoji_update | (var_name: str, event: Dict[str, object]) |
The way we send realm emojis is kinda clumsy--we
send a dict mapping the emoji id to a sub_dict with
the fields (including the id). Ideally we can streamline
this and just send a list of dicts. The clients can make
a Map as needed.
|
The way we send realm emojis is kinda clumsy--we
send a dict mapping the emoji id to a sub_dict with
the fields (including the id). Ideally we can streamline
this and just send a list of dicts. The clients can make
a Map as needed.
| def check_realm_emoji_update(var_name: str, event: Dict[str, object]) -> None:
"""
The way we send realm emojis is kinda clumsy--we
send a dict mapping the emoji id to a sub_dict with
the fields (including the id). Ideally we can streamline
this and just send a list of dicts. The clients can make
... | [
"def",
"check_realm_emoji_update",
"(",
"var_name",
":",
"str",
",",
"event",
":",
"Dict",
"[",
"str",
",",
"object",
"]",
")",
"->",
"None",
":",
"_check_realm_emoji_update",
"(",
"var_name",
",",
"event",
")",
"assert",
"isinstance",
"(",
"event",
"[",
"... | [
720,
0
] | [
732,
27
] | python | en | ['en', 'error', 'th'] | False |
check_realm_update | (
var_name: str,
event: Dict[str, object],
prop: str,
) |
Realm updates have these two fields:
property
value
We check not only the basic schema, but also that
the value people actually matches the type from
Realm.property_types that we have configured
for the property.
|
Realm updates have these two fields: | def check_realm_update(
var_name: str,
event: Dict[str, object],
prop: str,
) -> None:
"""
Realm updates have these two fields:
property
value
We check not only the basic schema, but also that
the value people actually matches the type from
Realm.property_types that we ... | [
"def",
"check_realm_update",
"(",
"var_name",
":",
"str",
",",
"event",
":",
"Dict",
"[",
"str",
",",
"object",
"]",
",",
"prop",
":",
"str",
",",
")",
"->",
"None",
":",
"_check_realm_update",
"(",
"var_name",
",",
"event",
")",
"assert",
"prop",
"=="... | [
849,
0
] | [
890,
73
] | python | en | ['en', 'error', 'th'] | False |
check_update_display_settings | (
var_name: str,
event: Dict[str, object],
) |
Display setting events have a "setting" field that
is more specifically typed according to the
UserProfile.property_types dictionary.
|
Display setting events have a "setting" field that
is more specifically typed according to the
UserProfile.property_types dictionary.
| def check_update_display_settings(
var_name: str,
event: Dict[str, object],
) -> None:
"""
Display setting events have a "setting" field that
is more specifically typed according to the
UserProfile.property_types dictionary.
"""
_check_update_display_settings(var_name, event)
setting... | [
"def",
"check_update_display_settings",
"(",
"var_name",
":",
"str",
",",
"event",
":",
"Dict",
"[",
"str",
",",
"object",
"]",
",",
")",
"->",
"None",
":",
"_check_update_display_settings",
"(",
"var_name",
",",
"event",
")",
"setting_name",
"=",
"event",
"... | [
1385,
0
] | [
1405,
50
] | python | en | ['en', 'error', 'th'] | False |
check_update_global_notifications | (
var_name: str,
event: Dict[str, object],
desired_val: Union[bool, int, str],
) |
See UserProfile.notification_setting_types for
more details.
|
See UserProfile.notification_setting_types for
more details.
| def check_update_global_notifications(
var_name: str,
event: Dict[str, object],
desired_val: Union[bool, int, str],
) -> None:
"""
See UserProfile.notification_setting_types for
more details.
"""
_check_update_global_notifications(var_name, event)
setting_name = event["notification_n... | [
"def",
"check_update_global_notifications",
"(",
"var_name",
":",
"str",
",",
"event",
":",
"Dict",
"[",
"str",
",",
"object",
"]",
",",
"desired_val",
":",
"Union",
"[",
"bool",
",",
"int",
",",
"str",
"]",
",",
")",
"->",
"None",
":",
"_check_update_gl... | [
1419,
0
] | [
1435,
44
] | python | en | ['en', 'error', 'th'] | False |
MyApp.build | (self) |
Build and return the root widget.
|
Build and return the root widget.
| def build(self):
"""
Build and return the root widget.
"""
# The line below is optional. You could leave it out or use one of the
# standard options, such as SettingsWithSidebar, SettingsWithSpinner
# etc.
self.settings_cls = MySettingsWithTabbedPanel
# W... | [
"def",
"build",
"(",
"self",
")",
":",
"# The line below is optional. You could leave it out or use one of the",
"# standard options, such as SettingsWithSidebar, SettingsWithSpinner",
"# etc.",
"self",
".",
"settings_cls",
"=",
"MySettingsWithTabbedPanel",
"# We apply the saved configur... | [
51,
4
] | [
65,
19
] | python | en | ['en', 'error', 'th'] | False |
MyApp.build_config | (self, config) |
Set the default values for the configs sections.
|
Set the default values for the configs sections.
| def build_config(self, config):
"""
Set the default values for the configs sections.
"""
config.setdefaults('My Label', {'text': 'Hello', 'font_size': 20}) | [
"def",
"build_config",
"(",
"self",
",",
"config",
")",
":",
"config",
".",
"setdefaults",
"(",
"'My Label'",
",",
"{",
"'text'",
":",
"'Hello'",
",",
"'font_size'",
":",
"20",
"}",
")"
] | [
67,
4
] | [
71,
74
] | python | en | ['en', 'error', 'th'] | False |
MyApp.build_settings | (self, settings) |
Add our custom section to the default configuration object.
|
Add our custom section to the default configuration object.
| def build_settings(self, settings):
"""
Add our custom section to the default configuration object.
"""
# We use the string defined above for our JSON, but it could also be
# loaded from a file as follows:
# settings.add_json_panel('My Label', self.config, 'settings.j... | [
"def",
"build_settings",
"(",
"self",
",",
"settings",
")",
":",
"# We use the string defined above for our JSON, but it could also be",
"# loaded from a file as follows:",
"# settings.add_json_panel('My Label', self.config, 'settings.json')",
"settings",
".",
"add_json_panel",
"(",
... | [
73,
4
] | [
80,
67
] | python | en | ['en', 'error', 'th'] | False |
MyApp.on_config_change | (self, config, section, key, value) |
Respond to changes in the configuration.
|
Respond to changes in the configuration.
| def on_config_change(self, config, section, key, value):
"""
Respond to changes in the configuration.
"""
Logger.info("main.py: App.on_config_change: {0}, {1}, {2}, {3}".format(
config, section, key, value))
if section == "My Label":
if key == "text":
... | [
"def",
"on_config_change",
"(",
"self",
",",
"config",
",",
"section",
",",
"key",
",",
"value",
")",
":",
"Logger",
".",
"info",
"(",
"\"main.py: App.on_config_change: {0}, {1}, {2}, {3}\"",
".",
"format",
"(",
"config",
",",
"section",
",",
"key",
",",
"valu... | [
82,
4
] | [
93,
60
] | python | en | ['en', 'error', 'th'] | False |
MyApp.close_settings | (self, settings=None) |
The settings panel has been closed.
|
The settings panel has been closed.
| def close_settings(self, settings=None):
"""
The settings panel has been closed.
"""
Logger.info("main.py: App.close_settings: {0}".format(settings))
super(MyApp, self).close_settings(settings) | [
"def",
"close_settings",
"(",
"self",
",",
"settings",
"=",
"None",
")",
":",
"Logger",
".",
"info",
"(",
"\"main.py: App.close_settings: {0}\"",
".",
"format",
"(",
"settings",
")",
")",
"super",
"(",
"MyApp",
",",
"self",
")",
".",
"close_settings",
"(",
... | [
95,
4
] | [
100,
51
] | python | en | ['en', 'error', 'th'] | False |
putchunk | (fp, cid, *data) | Write a PNG chunk (including CRC field) | Write a PNG chunk (including CRC field) | def putchunk(fp, cid, *data):
"""Write a PNG chunk (including CRC field)"""
data = b"".join(data)
fp.write(o32(len(data)) + cid)
fp.write(data)
crc = _crc32(data, _crc32(cid))
fp.write(o32(crc)) | [
"def",
"putchunk",
"(",
"fp",
",",
"cid",
",",
"*",
"data",
")",
":",
"data",
"=",
"b\"\"",
".",
"join",
"(",
"data",
")",
"fp",
".",
"write",
"(",
"o32",
"(",
"len",
"(",
"data",
")",
")",
"+",
"cid",
")",
"fp",
".",
"write",
"(",
"data",
... | [
1012,
0
] | [
1020,
22
] | python | en | ['en', 'en', 'en'] | True |
getchunks | (im, **params) | Return a list of PNG chunks representing this image. | Return a list of PNG chunks representing this image. | def getchunks(im, **params):
"""Return a list of PNG chunks representing this image."""
class collector:
data = []
def write(self, data):
pass
def append(self, chunk):
self.data.append(chunk)
def append(fp, cid, *data):
data = b"".join(data)
... | [
"def",
"getchunks",
"(",
"im",
",",
"*",
"*",
"params",
")",
":",
"class",
"collector",
":",
"data",
"=",
"[",
"]",
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"pass",
"def",
"append",
"(",
"self",
",",
"chunk",
")",
":",
"self",
".",
"... | [
1359,
0
] | [
1384,
18
] | python | en | ['en', 'en', 'en'] | True |
ChunkStream.read | (self) | Fetch a new chunk. Returns header information. | Fetch a new chunk. Returns header information. | def read(self):
"""Fetch a new chunk. Returns header information."""
cid = None
if self.queue:
cid, pos, length = self.queue.pop()
self.fp.seek(pos)
else:
s = self.fp.read(8)
cid = s[4:]
pos = self.fp.tell()
length ... | [
"def",
"read",
"(",
"self",
")",
":",
"cid",
"=",
"None",
"if",
"self",
".",
"queue",
":",
"cid",
",",
"pos",
",",
"length",
"=",
"self",
".",
"queue",
".",
"pop",
"(",
")",
"self",
".",
"fp",
".",
"seek",
"(",
"pos",
")",
"else",
":",
"s",
... | [
151,
4
] | [
168,
31
] | python | en | ['en', 'en', 'en'] | True |
ChunkStream.call | (self, cid, pos, length) | Call the appropriate chunk handler | Call the appropriate chunk handler | def call(self, cid, pos, length):
"""Call the appropriate chunk handler"""
logger.debug("STREAM %r %s %s", cid, pos, length)
return getattr(self, "chunk_" + cid.decode("ascii"))(pos, length) | [
"def",
"call",
"(",
"self",
",",
"cid",
",",
"pos",
",",
"length",
")",
":",
"logger",
".",
"debug",
"(",
"\"STREAM %r %s %s\"",
",",
"cid",
",",
"pos",
",",
"length",
")",
"return",
"getattr",
"(",
"self",
",",
"\"chunk_\"",
"+",
"cid",
".",
"decode... | [
183,
4
] | [
187,
73
] | python | en | ['en', 'en', 'en'] | True |
ChunkStream.crc | (self, cid, data) | Read and verify checksum | Read and verify checksum | def crc(self, cid, data):
"""Read and verify checksum"""
# Skip CRC checks for ancillary chunks if allowed to load truncated
# images
# 5th byte of first char is 1 [specs, section 5.4]
if ImageFile.LOAD_TRUNCATED_IMAGES and (i8(cid[0]) >> 5 & 1):
self.crc_skip(cid, d... | [
"def",
"crc",
"(",
"self",
",",
"cid",
",",
"data",
")",
":",
"# Skip CRC checks for ancillary chunks if allowed to load truncated",
"# images",
"# 5th byte of first char is 1 [specs, section 5.4]",
"if",
"ImageFile",
".",
"LOAD_TRUNCATED_IMAGES",
"and",
"(",
"i8",
"(",
"ci... | [
189,
4
] | [
209,
20
] | python | en | ['en', 'pt', 'en'] | True |
ChunkStream.crc_skip | (self, cid, data) | Read checksum. Used if the C module is not present | Read checksum. Used if the C module is not present | def crc_skip(self, cid, data):
"""Read checksum. Used if the C module is not present"""
self.fp.read(4) | [
"def",
"crc_skip",
"(",
"self",
",",
"cid",
",",
"data",
")",
":",
"self",
".",
"fp",
".",
"read",
"(",
"4",
")"
] | [
211,
4
] | [
214,
23
] | python | en | ['en', 'en', 'en'] | True |
iTXt.__new__ | (cls, text, lang=None, tkey=None) |
:param cls: the class to use when creating the instance
:param text: value for this key
:param lang: language code
:param tkey: UTF-8 version of the key name
|
:param cls: the class to use when creating the instance
:param text: value for this key
:param lang: language code
:param tkey: UTF-8 version of the key name
| def __new__(cls, text, lang=None, tkey=None):
"""
:param cls: the class to use when creating the instance
:param text: value for this key
:param lang: language code
:param tkey: UTF-8 version of the key name
"""
self = str.__new__(cls, text)
self.lang = l... | [
"def",
"__new__",
"(",
"cls",
",",
"text",
",",
"lang",
"=",
"None",
",",
"tkey",
"=",
"None",
")",
":",
"self",
"=",
"str",
".",
"__new__",
"(",
"cls",
",",
"text",
")",
"self",
".",
"lang",
"=",
"lang",
"self",
".",
"tkey",
"=",
"tkey",
"retu... | [
245,
4
] | [
256,
19
] | python | en | ['en', 'error', 'th'] | False |
PngInfo.add | (self, cid, data, after_idat=False) | Appends an arbitrary chunk. Use with caution.
:param cid: a byte string, 4 bytes long.
:param data: a byte string of the encoded data
:param after_idat: for use with private chunks. Whether the chunk
should be written after IDAT
| Appends an arbitrary chunk. Use with caution. | def add(self, cid, data, after_idat=False):
"""Appends an arbitrary chunk. Use with caution.
:param cid: a byte string, 4 bytes long.
:param data: a byte string of the encoded data
:param after_idat: for use with private chunks. Whether the chunk
should be wri... | [
"def",
"add",
"(",
"self",
",",
"cid",
",",
"data",
",",
"after_idat",
"=",
"False",
")",
":",
"chunk",
"=",
"[",
"cid",
",",
"data",
"]",
"if",
"after_idat",
":",
"chunk",
".",
"append",
"(",
"True",
")",
"self",
".",
"chunks",
".",
"append",
"(... | [
268,
4
] | [
281,
40
] | python | en | ['en', 'en', 'en'] | True |
PngInfo.add_itxt | (self, key, value, lang="", tkey="", zip=False) | Appends an iTXt chunk.
:param key: latin-1 encodable text key name
:param value: value for this key
:param lang: language code
:param tkey: UTF-8 version of the key name
:param zip: compression flag
| Appends an iTXt chunk. | def add_itxt(self, key, value, lang="", tkey="", zip=False):
"""Appends an iTXt chunk.
:param key: latin-1 encodable text key name
:param value: value for this key
:param lang: language code
:param tkey: UTF-8 version of the key name
:param zip: compression flag
... | [
"def",
"add_itxt",
"(",
"self",
",",
"key",
",",
"value",
",",
"lang",
"=",
"\"\"",
",",
"tkey",
"=",
"\"\"",
",",
"zip",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"bytes",
")",
":",
"key",
"=",
"key",
".",
"encode",
"... | [
283,
4
] | [
309,
84
] | python | en | ['en', 'en', 'en'] | True |
PngInfo.add_text | (self, key, value, zip=False) | Appends a text chunk.
:param key: latin-1 encodable text key name
:param value: value for this key, text or an
:py:class:`PIL.PngImagePlugin.iTXt` instance
:param zip: compression flag
| Appends a text chunk. | def add_text(self, key, value, zip=False):
"""Appends a text chunk.
:param key: latin-1 encodable text key name
:param value: value for this key, text or an
:py:class:`PIL.PngImagePlugin.iTXt` instance
:param zip: compression flag
"""
if isinstance(value, iTX... | [
"def",
"add_text",
"(",
"self",
",",
"key",
",",
"value",
",",
"zip",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"iTXt",
")",
":",
"return",
"self",
".",
"add_itxt",
"(",
"key",
",",
"value",
",",
"value",
".",
"lang",
",",
"v... | [
311,
4
] | [
336,
50
] | python | en | ['en', 'en', 'en'] | True |
PngImageFile.verify | (self) | Verify PNG file | Verify PNG file | def verify(self):
"""Verify PNG file"""
if self.fp is None:
raise RuntimeError("verify must be called directly after open")
# back up to beginning of IDAT block
self.fp.seek(self.tile[0][2] - 8)
self.png.verify()
self.png.close()
if self._exclusive... | [
"def",
"verify",
"(",
"self",
")",
":",
"if",
"self",
".",
"fp",
"is",
"None",
":",
"raise",
"RuntimeError",
"(",
"\"verify must be called directly after open\"",
")",
"# back up to beginning of IDAT block",
"self",
".",
"fp",
".",
"seek",
"(",
"self",
".",
"til... | [
756,
4
] | [
770,
22
] | python | en | ['en', 'fr', 'en'] | True |
PngImageFile.load_prepare | (self) | internal: prepare to read PNG file | internal: prepare to read PNG file | def load_prepare(self):
"""internal: prepare to read PNG file"""
if self.info.get("interlace"):
self.decoderconfig = self.decoderconfig + (1,)
self.__idat = self.__prepare_idat # used by load_read()
ImageFile.ImageFile.load_prepare(self) | [
"def",
"load_prepare",
"(",
"self",
")",
":",
"if",
"self",
".",
"info",
".",
"get",
"(",
"\"interlace\"",
")",
":",
"self",
".",
"decoderconfig",
"=",
"self",
".",
"decoderconfig",
"+",
"(",
"1",
",",
")",
"self",
".",
"__idat",
"=",
"self",
".",
... | [
863,
4
] | [
870,
46
] | python | en | ['en', 'en', 'en'] | True |
PngImageFile.load_read | (self, read_bytes) | internal: read more image data | internal: read more image data | def load_read(self, read_bytes):
"""internal: read more image data"""
while self.__idat == 0:
# end of chunk, skip forward to next one
self.fp.read(4) # CRC
cid, pos, length = self.png.read()
if cid not in [b"IDAT", b"DDAT", b"fdAT"]:
... | [
"def",
"load_read",
"(",
"self",
",",
"read_bytes",
")",
":",
"while",
"self",
".",
"__idat",
"==",
"0",
":",
"# end of chunk, skip forward to next one",
"self",
".",
"fp",
".",
"read",
"(",
"4",
")",
"# CRC",
"cid",
",",
"pos",
",",
"length",
"=",
"self... | [
872,
4
] | [
903,
39
] | python | en | ['fr', 'en', 'en'] | True |
PngImageFile.load_end | (self) | internal: finished reading image data | internal: finished reading image data | def load_end(self):
"""internal: finished reading image data"""
while True:
self.fp.read(4) # CRC
try:
cid, pos, length = self.png.read()
except (struct.error, SyntaxError):
break
if cid == b"IEND":
break
... | [
"def",
"load_end",
"(",
"self",
")",
":",
"while",
"True",
":",
"self",
".",
"fp",
".",
"read",
"(",
"4",
")",
"# CRC",
"try",
":",
"cid",
",",
"pos",
",",
"length",
"=",
"self",
".",
"png",
".",
"read",
"(",
")",
"except",
"(",
"struct",
".",
... | [
905,
4
] | [
965,
65
] | python | en | ['fr', 'zu', 'en'] | False |
NearestFilter.__init__ | (self, N) |
Keeps the count threshold.
|
Keeps the count threshold.
| def __init__(self, N):
"""
Keeps the count threshold.
"""
self.N = N | [
"def",
"__init__",
"(",
"self",
",",
"N",
")",
":",
"self",
".",
"N",
"=",
"N"
] | [
30,
4
] | [
34,
18
] | python | en | ['en', 'error', 'th'] | False |
NearestFilter.filter_vectors | (self, input_list) |
Returns subset of specified input list.
|
Returns subset of specified input list.
| def filter_vectors(self, input_list):
"""
Returns subset of specified input list.
"""
try:
# Return filtered (vector, data, distance )tuple list. Will fail
# if input is list of (vector, data) tuples.
sorted_list = sorted(input_list, key=lambda x: x[2]... | [
"def",
"filter_vectors",
"(",
"self",
",",
"input_list",
")",
":",
"try",
":",
"# Return filtered (vector, data, distance )tuple list. Will fail",
"# if input is list of (vector, data) tuples.",
"sorted_list",
"=",
"sorted",
"(",
"input_list",
",",
"key",
"=",
"lambda",
"x"... | [
36,
4
] | [
47,
29
] | python | en | ['en', 'error', 'th'] | False |
GoodnessOfFitResults.export_results_as_csv | (self, keys_of_interest, output_dir, file_name) | write result to file | write result to file | def export_results_as_csv(self, keys_of_interest, output_dir, file_name):
if self.results_df is None:
self.generate_results_dataframe(keys_of_interest=keys_of_interest)
file_results = io.get_full_path(output_dir=output_dir, suffix=".csv", file_name=file_name)
file_handle_results_csv = open(file_resul... | [
"def",
"export_results_as_csv",
"(",
"self",
",",
"keys_of_interest",
",",
"output_dir",
",",
"file_name",
")",
":",
"if",
"self",
".",
"results_df",
"is",
"None",
":",
"self",
".",
"generate_results_dataframe",
"(",
"keys_of_interest",
"=",
"keys_of_interest",
")... | [
40,
2
] | [
55,
37
] | python | en | ['en', 'en', 'en'] | True |
GoodnessOfFitResults.plot_metric | (self, plot_dicts, metric='hellinger_distance', keys_of_interest=None,
figsize=(20,8), layout=None, fig=None, color=None, log_scale_x=True, log_scale_y=True) |
Generates a plot for a metric with axis x representing the n_observations and y representing the metric.
Args:
graph_dicts: a list of dicts, each element representing the data for one curve on the plot, example:
graph_dicts = [
{ "estimator": "KernelMixtureNetwo... |
Generates a plot for a metric with axis x representing the n_observations and y representing the metric.
Args: | def plot_metric(self, plot_dicts, metric='hellinger_distance', keys_of_interest=None,
figsize=(20,8), layout=None, fig=None, color=None, log_scale_x=True, log_scale_y=True):
"""
Generates a plot for a metric with axis x representing the n_observations and y representing the metric.
Args:
... | [
"def",
"plot_metric",
"(",
"self",
",",
"plot_dicts",
",",
"metric",
"=",
"'hellinger_distance'",
",",
"keys_of_interest",
"=",
"None",
",",
"figsize",
"=",
"(",
"20",
",",
"8",
")",
",",
"layout",
"=",
"None",
",",
"fig",
"=",
"None",
",",
"color",
"=... | [
57,
2
] | [
134,
14
] | python | en | ['en', 'error', 'th'] | False |
GoodnessOfFitResults.plot_densities | (self, selector, configs, metric="hellinger_distance", simulator="EconDensity", mode="pdf", xlim=(-5, 5), ylim=(-5, 5),
resolution=100, ) | Compares the fitted density (see modes) against the original density
Args:
xlim: 2-tuple specifying the x axis limits
ylim: 2-tuple specifying the y axis limits
resolution: integer specifying the resolution of plot
mode: spefify which dist to plot ["pdf", "cdf", "joint_pdf"]
| Compares the fitted density (see modes) against the original density | def plot_densities(self, selector, configs, metric="hellinger_distance", simulator="EconDensity", mode="pdf", xlim=(-5, 5), ylim=(-5, 5),
resolution=100, ):
assert self.results_df is not None, "first generate results df"
assert simulator in list(self.results_df["simulator"]), simulator + " ... | [
"def",
"plot_densities",
"(",
"self",
",",
"selector",
",",
"configs",
",",
"metric",
"=",
"\"hellinger_distance\"",
",",
"simulator",
"=",
"\"EconDensity\"",
",",
"mode",
"=",
"\"pdf\"",
",",
"xlim",
"=",
"(",
"-",
"5",
",",
"5",
")",
",",
"ylim",
"=",
... | [
137,
2
] | [
192,
14
] | python | en | ['en', 'en', 'en'] | True |
query_for_ids | (query: QuerySet, user_ids: List[int], field: str) |
This function optimizes searches of the form
`user_profile_id in (1, 2, 3, 4)` by quickly
building the where clauses. Profiling shows significant
speedups over the normal Django-based approach.
Use this very carefully! Also, the caller should
guard against empty lists of user_ids.
|
This function optimizes searches of the form
`user_profile_id in (1, 2, 3, 4)` by quickly
building the where clauses. Profiling shows significant
speedups over the normal Django-based approach. | def query_for_ids(query: QuerySet, user_ids: List[int], field: str) -> QuerySet:
"""
This function optimizes searches of the form
`user_profile_id in (1, 2, 3, 4)` by quickly
building the where clauses. Profiling shows significant
speedups over the normal Django-based approach.
Use this very c... | [
"def",
"query_for_ids",
"(",
"query",
":",
"QuerySet",
",",
"user_ids",
":",
"List",
"[",
"int",
"]",
",",
"field",
":",
"str",
")",
"->",
"QuerySet",
":",
"assert",
"user_ids",
"clause",
"=",
"f\"{field} IN %s\"",
"query",
"=",
"query",
".",
"extra",
"(... | [
98,
0
] | [
114,
16
] | python | en | ['en', 'error', 'th'] | False |
get_display_recipient_by_id | (
recipient_id: int, recipient_type: int, recipient_type_id: Optional[int]
) |
returns: an object describing the recipient (using a cache).
If the type is a stream, the type_id must be an int; a string is returned.
Otherwise, type_id may be None; an array of recipient dicts is returned.
|
returns: an object describing the recipient (using a cache).
If the type is a stream, the type_id must be an int; a string is returned.
Otherwise, type_id may be None; an array of recipient dicts is returned.
| def get_display_recipient_by_id(
recipient_id: int, recipient_type: int, recipient_type_id: Optional[int]
) -> DisplayRecipientT:
"""
returns: an object describing the recipient (using a cache).
If the type is a stream, the type_id must be an int; a string is returned.
Otherwise, type_id may be None... | [
"def",
"get_display_recipient_by_id",
"(",
"recipient_id",
":",
"int",
",",
"recipient_type",
":",
"int",
",",
"recipient_type_id",
":",
"Optional",
"[",
"int",
"]",
")",
"->",
"DisplayRecipientT",
":",
"# Have to import here, to avoid circular dependency.",
"from",
"ze... | [
128,
0
] | [
142,
60
] | python | en | ['en', 'error', 'th'] | False |
realm_filters_for_realm | (realm_id: int) |
Processes data from `linkifiers_for_realm` to return to older clients,
which use the `realm_filters` events.
|
Processes data from `linkifiers_for_realm` to return to older clients,
which use the `realm_filters` events.
| def realm_filters_for_realm(realm_id: int) -> List[Tuple[str, str, int]]:
"""
Processes data from `linkifiers_for_realm` to return to older clients,
which use the `realm_filters` events.
"""
linkifiers = linkifiers_for_realm(realm_id)
realm_filters: List[Tuple[str, str, int]] = []
for linkif... | [
"def",
"realm_filters_for_realm",
"(",
"realm_id",
":",
"int",
")",
"->",
"List",
"[",
"Tuple",
"[",
"str",
",",
"str",
",",
"int",
"]",
"]",
":",
"linkifiers",
"=",
"linkifiers_for_realm",
"(",
"realm_id",
")",
"realm_filters",
":",
"List",
"[",
"Tuple",
... | [
1023,
0
] | [
1032,
24
] | python | en | ['en', 'error', 'th'] | False |
get_active_streams | (realm: Optional[Realm]) |
Return all streams (including invite-only streams) that have not been deactivated.
|
Return all streams (including invite-only streams) that have not been deactivated.
| def get_active_streams(realm: Optional[Realm]) -> QuerySet:
# TODO: Change return type to QuerySet[Stream]
# NOTE: Return value is used as a QuerySet, so cannot currently be Sequence[QuerySet]
"""
Return all streams (including invite-only streams) that have not been deactivated.
"""
return Strea... | [
"def",
"get_active_streams",
"(",
"realm",
":",
"Optional",
"[",
"Realm",
"]",
")",
"->",
"QuerySet",
":",
"# TODO: Change return type to QuerySet[Stream]",
"# NOTE: Return value is used as a QuerySet, so cannot currently be Sequence[QuerySet]",
"return",
"Stream",
".",
"objects"... | [
2067,
0
] | [
2073,
64
] | python | en | ['en', 'error', 'th'] | False |
get_stream | (stream_name: str, realm: Realm) |
Callers that don't have a Realm object already available should use
get_realm_stream directly, to avoid unnecessarily fetching the
Realm object.
|
Callers that don't have a Realm object already available should use
get_realm_stream directly, to avoid unnecessarily fetching the
Realm object.
| def get_stream(stream_name: str, realm: Realm) -> Stream:
"""
Callers that don't have a Realm object already available should use
get_realm_stream directly, to avoid unnecessarily fetching the
Realm object.
"""
return get_realm_stream(stream_name, realm.id) | [
"def",
"get_stream",
"(",
"stream_name",
":",
"str",
",",
"realm",
":",
"Realm",
")",
"->",
"Stream",
":",
"return",
"get_realm_stream",
"(",
"stream_name",
",",
"realm",
".",
"id",
")"
] | [
2076,
0
] | [
2082,
50
] | python | en | ['en', 'error', 'th'] | False |
bulk_get_huddle_user_ids | (recipients: List[Recipient]) |
Takes a list of huddle-type recipients, returns a dict
mapping recipient id to list of user ids in the huddle.
|
Takes a list of huddle-type recipients, returns a dict
mapping recipient id to list of user ids in the huddle.
| def bulk_get_huddle_user_ids(recipients: List[Recipient]) -> Dict[int, List[int]]:
"""
Takes a list of huddle-type recipients, returns a dict
mapping recipient id to list of user ids in the huddle.
"""
assert all(recipient.type == Recipient.HUDDLE for recipient in recipients)
if not recipients:
... | [
"def",
"bulk_get_huddle_user_ids",
"(",
"recipients",
":",
"List",
"[",
"Recipient",
"]",
")",
"->",
"Dict",
"[",
"int",
",",
"List",
"[",
"int",
"]",
"]",
":",
"assert",
"all",
"(",
"recipient",
".",
"type",
"==",
"Recipient",
".",
"HUDDLE",
"for",
"r... | [
2144,
0
] | [
2165,
22
] | python | en | ['en', 'error', 'th'] | False |
Realm.authentication_methods_dict | (self) | Returns the a mapping from authentication flags to their status,
showing only those authentication flags that are supported on
the current server (i.e. if EmailAuthBackend is not configured
on the server, this will not return an entry for "Email"). | Returns the a mapping from authentication flags to their status,
showing only those authentication flags that are supported on
the current server (i.e. if EmailAuthBackend is not configured
on the server, this will not return an entry for "Email"). | def authentication_methods_dict(self) -> Dict[str, bool]:
"""Returns the a mapping from authentication flags to their status,
showing only those authentication flags that are supported on
the current server (i.e. if EmailAuthBackend is not configured
on the server, this will not return a... | [
"def",
"authentication_methods_dict",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"bool",
"]",
":",
"# This mapping needs to be imported from here due to the cyclic",
"# dependency.",
"from",
"zproject",
".",
"backends",
"import",
"AUTH_BACKEND_NAME_MAP",
"ret",
":",... | [
582,
4
] | [
600,
18
] | python | en | ['en', 'en', 'en'] | True |
Realm.get_admin_users_and_bots | (
self, include_realm_owners: bool = True
) | Use this in contexts where we want administrative users as well as
bots with administrator privileges, like send_event calls for
notifications to all administrator users.
| Use this in contexts where we want administrative users as well as
bots with administrator privileges, like send_event calls for
notifications to all administrator users.
| def get_admin_users_and_bots(
self, include_realm_owners: bool = True
) -> Sequence["UserProfile"]:
"""Use this in contexts where we want administrative users as well as
bots with administrator privileges, like send_event calls for
notifications to all administrator users.
""... | [
"def",
"get_admin_users_and_bots",
"(",
"self",
",",
"include_realm_owners",
":",
"bool",
"=",
"True",
")",
"->",
"Sequence",
"[",
"\"UserProfile\"",
"]",
":",
"if",
"include_realm_owners",
":",
"roles",
"=",
"[",
"UserProfile",
".",
"ROLE_REALM_ADMINISTRATOR",
",... | [
613,
4
] | [
630,
9
] | python | en | ['en', 'en', 'en'] | True |
Realm.get_human_admin_users | (self, include_realm_owners: bool = True) | Use this in contexts where we want only human users with
administrative privileges, like sending an email to all of a
realm's administrators (bots don't have real email addresses).
| Use this in contexts where we want only human users with
administrative privileges, like sending an email to all of a
realm's administrators (bots don't have real email addresses).
| def get_human_admin_users(self, include_realm_owners: bool = True) -> QuerySet:
"""Use this in contexts where we want only human users with
administrative privileges, like sending an email to all of a
realm's administrators (bots don't have real email addresses).
"""
if include_r... | [
"def",
"get_human_admin_users",
"(",
"self",
",",
"include_realm_owners",
":",
"bool",
"=",
"True",
")",
"->",
"QuerySet",
":",
"if",
"include_realm_owners",
":",
"roles",
"=",
"[",
"UserProfile",
".",
"ROLE_REALM_ADMINISTRATOR",
",",
"UserProfile",
".",
"ROLE_REA... | [
632,
4
] | [
648,
9
] | python | en | ['en', 'en', 'en'] | True |
Realm.get_first_human_user | (self) | A useful value for communications with newly created realms.
Has a few fundamental limitations:
* Its value will be effectively random for realms imported from Slack or
other third-party tools.
* The user may be deactivated, etc., so it's not something that's useful
for feat... | A useful value for communications with newly created realms.
Has a few fundamental limitations: | def get_first_human_user(self) -> Optional["UserProfile"]:
"""A useful value for communications with newly created realms.
Has a few fundamental limitations:
* Its value will be effectively random for realms imported from Slack or
other third-party tools.
* The user may be dea... | [
"def",
"get_first_human_user",
"(",
"self",
")",
"->",
"Optional",
"[",
"\"UserProfile\"",
"]",
":",
"return",
"UserProfile",
".",
"objects",
".",
"filter",
"(",
"realm",
"=",
"self",
",",
"is_bot",
"=",
"False",
")",
".",
"order_by",
"(",
"\"id\"",
")",
... | [
662,
4
] | [
671,
90
] | python | en | ['en', 'en', 'en'] | True |
Realm.display_subdomain | (self) | Likely to be temporary function to avoid signup messages being sent
to an empty topic | Likely to be temporary function to avoid signup messages being sent
to an empty topic | def display_subdomain(self) -> str:
"""Likely to be temporary function to avoid signup messages being sent
to an empty topic"""
if self.string_id == "":
return "."
return self.string_id | [
"def",
"display_subdomain",
"(",
"self",
")",
"->",
"str",
":",
"if",
"self",
".",
"string_id",
"==",
"\"\"",
":",
"return",
"\".\"",
"return",
"self",
".",
"string_id"
] | [
727,
4
] | [
732,
29
] | python | en | ['en', 'en', 'en'] | True |
RealmFilter.clean | (self) | Validate whether the set of parameters in the URL Format string
match the set of parameters in the regular expression.
Django's `full_clean` calls `clean_fields` followed by `clean` method
and stores all ValidationErrors from all stages to return as JSON.
| Validate whether the set of parameters in the URL Format string
match the set of parameters in the regular expression. | def clean(self) -> None:
"""Validate whether the set of parameters in the URL Format string
match the set of parameters in the regular expression.
Django's `full_clean` calls `clean_fields` followed by `clean` method
and stores all ValidationErrors from all stages to return as JSON.
... | [
"def",
"clean",
"(",
"self",
")",
"->",
"None",
":",
"# Extract variables present in the pattern",
"pattern",
"=",
"filter_pattern_validator",
"(",
"self",
".",
"pattern",
")",
"group_set",
"=",
"set",
"(",
"pattern",
".",
"groupindex",
".",
"keys",
"(",
")",
... | [
959,
4
] | [
999,
13
] | python | en | ['en', 'en', 'en'] | True |
UserProfile.can_admin_user | (self, target_user: "UserProfile") | Returns whether this user has permission to modify target_user | Returns whether this user has permission to modify target_user | def can_admin_user(self, target_user: "UserProfile") -> bool:
"""Returns whether this user has permission to modify target_user"""
if target_user.bot_owner == self:
return True
elif self.is_realm_admin and self.realm == target_user.realm:
return True
else:
... | [
"def",
"can_admin_user",
"(",
"self",
",",
"target_user",
":",
"\"UserProfile\"",
")",
"->",
"bool",
":",
"if",
"target_user",
".",
"bot_owner",
"==",
"self",
":",
"return",
"True",
"elif",
"self",
".",
"is_realm_admin",
"and",
"self",
".",
"realm",
"==",
... | [
1518,
4
] | [
1525,
24
] | python | en | ['en', 'en', 'en'] | True |
Message.topic_name | (self) |
Please start using this helper to facilitate an
eventual switch over to a separate topic table.
|
Please start using this helper to facilitate an
eventual switch over to a separate topic table.
| def topic_name(self) -> str:
"""
Please start using this helper to facilitate an
eventual switch over to a separate topic table.
"""
return self.subject | [
"def",
"topic_name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"subject"
] | [
2245,
4
] | [
2250,
27
] | python | en | ['en', 'error', 'th'] | False |
Message.is_stream_message | (self) |
Find out whether a message is a stream message by
looking up its recipient.type. TODO: Make this
an easier operation by denormalizing the message
type onto Message, either explicitly (message.type)
or implicitly (message.stream_id is not None).
|
Find out whether a message is a stream message by
looking up its recipient.type. TODO: Make this
an easier operation by denormalizing the message
type onto Message, either explicitly (message.type)
or implicitly (message.stream_id is not None).
| def is_stream_message(self) -> bool:
"""
Find out whether a message is a stream message by
looking up its recipient.type. TODO: Make this
an easier operation by denormalizing the message
type onto Message, either explicitly (message.type)
or implicitly (message.stream_id... | [
"def",
"is_stream_message",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"recipient",
".",
"type",
"==",
"Recipient",
".",
"STREAM"
] | [
2255,
4
] | [
2263,
54
] | python | en | ['en', 'error', 'th'] | False |
Message.sent_by_human | (self) | Used to determine whether a message was sent by a full Zulip UI
style client (and thus whether the message should be treated
as sent by a human and automatically marked as read for the
sender). The purpose of this distinction is to ensure that
message sent to the user by e.g. a Google C... | Used to determine whether a message was sent by a full Zulip UI
style client (and thus whether the message should be treated
as sent by a human and automatically marked as read for the
sender). The purpose of this distinction is to ensure that
message sent to the user by e.g. a Google C... | def sent_by_human(self) -> bool:
"""Used to determine whether a message was sent by a full Zulip UI
style client (and thus whether the message should be treated
as sent by a human and automatically marked as read for the
sender). The purpose of this distinction is to ensure that
... | [
"def",
"sent_by_human",
"(",
"self",
")",
"->",
"bool",
":",
"sending_client",
"=",
"self",
".",
"sending_client",
".",
"name",
".",
"lower",
"(",
")",
"return",
"(",
"sending_client",
"in",
"(",
"\"zulipandroid\"",
",",
"\"zulipios\"",
",",
"\"zulipdesktop\""... | [
2283,
4
] | [
2308,
46
] | python | en | ['en', 'en', 'en'] | True |
Message.is_status_message | (content: str, rendered_content: str) |
"status messages" start with /me and have special rendering:
/me loves chocolate -> Full Name loves chocolate
|
"status messages" start with /me and have special rendering:
/me loves chocolate -> Full Name loves chocolate
| def is_status_message(content: str, rendered_content: str) -> bool:
"""
"status messages" start with /me and have special rendering:
/me loves chocolate -> Full Name loves chocolate
"""
if content.startswith("/me "):
return True
return False | [
"def",
"is_status_message",
"(",
"content",
":",
"str",
",",
"rendered_content",
":",
"str",
")",
"->",
"bool",
":",
"if",
"content",
".",
"startswith",
"(",
"\"/me \"",
")",
":",
"return",
"True",
"return",
"False"
] | [
2311,
4
] | [
2318,
20
] | python | en | ['en', 'error', 'th'] | False |
AbstractUserMessage.flags_list_for_flags | (val: int) |
This function is highly optimized, because it actually slows down
sending messages in a naive implementation.
|
This function is highly optimized, because it actually slows down
sending messages in a naive implementation.
| def flags_list_for_flags(val: int) -> List[str]:
"""
This function is highly optimized, because it actually slows down
sending messages in a naive implementation.
"""
flags = []
mask = 1
for flag in UserMessage.ALL_FLAGS:
if (val & mask) and flag not i... | [
"def",
"flags_list_for_flags",
"(",
"val",
":",
"int",
")",
"->",
"List",
"[",
"str",
"]",
":",
"flags",
"=",
"[",
"]",
"mask",
"=",
"1",
"for",
"flag",
"in",
"UserMessage",
".",
"ALL_FLAGS",
":",
"if",
"(",
"val",
"&",
"mask",
")",
"and",
"flag",
... | [
2593,
4
] | [
2604,
20
] | python | en | ['en', 'error', 'th'] | False |
expand_reqs | (fpath: str) |
Returns a sorted list of unique dependencies specified by the requirements file `fpath`.
Removes comments from the output and recursively visits files specified inside `fpath`.
`fpath` can be either an absolute path or a relative path.
|
Returns a sorted list of unique dependencies specified by the requirements file `fpath`.
Removes comments from the output and recursively visits files specified inside `fpath`.
`fpath` can be either an absolute path or a relative path.
| def expand_reqs(fpath: str) -> List[str]:
"""
Returns a sorted list of unique dependencies specified by the requirements file `fpath`.
Removes comments from the output and recursively visits files specified inside `fpath`.
`fpath` can be either an absolute path or a relative path.
"""
absfpath =... | [
"def",
"expand_reqs",
"(",
"fpath",
":",
"str",
")",
"->",
"List",
"[",
"str",
"]",
":",
"absfpath",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"fpath",
")",
"output",
"=",
"expand_reqs_helper",
"(",
"absfpath",
")",
"return",
"sorted",
"(",
"set",
... | [
22,
0
] | [
30,
30
] | python | en | ['en', 'error', 'th'] | False |
python_version | () |
Returns the Python version as string 'Python major.minor.patchlevel'
|
Returns the Python version as string 'Python major.minor.patchlevel'
| def python_version() -> str:
"""
Returns the Python version as string 'Python major.minor.patchlevel'
"""
return subprocess.check_output(["/usr/bin/python3", "-VV"], universal_newlines=True) | [
"def",
"python_version",
"(",
")",
"->",
"str",
":",
"return",
"subprocess",
".",
"check_output",
"(",
"[",
"\"/usr/bin/python3\"",
",",
"\"-VV\"",
"]",
",",
"universal_newlines",
"=",
"True",
")"
] | [
33,
0
] | [
37,
88
] | python | en | ['en', 'error', 'th'] | False |
load_time_series_csv | (file_path, delimiter=',', time_format=None, time_columns=None) | Loads a .csv time series file (e.g. EuroStoxx50) as a pandas dataframe and applies some basic formatting.
The basic formatting includes:
a) if no time column is available in the .csv, calling this function sorts the data according to the first column
b) if a time column is available (i.e. some column containing ... | Loads a .csv time series file (e.g. EuroStoxx50) as a pandas dataframe and applies some basic formatting.
The basic formatting includes:
a) if no time column is available in the .csv, calling this function sorts the data according to the first column
b) if a time column is available (i.e. some column containing ... | def load_time_series_csv(file_path, delimiter=',', time_format=None, time_columns=None):
""" Loads a .csv time series file (e.g. EuroStoxx50) as a pandas dataframe and applies some basic formatting.
The basic formatting includes:
a) if no time column is available in the .csv, calling this function sorts the data ... | [
"def",
"load_time_series_csv",
"(",
"file_path",
",",
"delimiter",
"=",
"','",
",",
"time_format",
"=",
"None",
",",
"time_columns",
"=",
"None",
")",
":",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"file_path",
")",
",",
"\"invalid path to output direct... | [
64,
0
] | [
111,
20
] | python | en | ['en', 'el-Latn', 'en'] | True |
default_types | () |
We use our own set of default media types rather than the system-supplied
ones. This ensures consistent media type behaviour across varied
environments. The defaults are based on those shipped with nginx, with
some custom additions.
|
We use our own set of default media types rather than the system-supplied
ones. This ensures consistent media type behaviour across varied
environments. The defaults are based on those shipped with nginx, with
some custom additions.
| def default_types():
"""
We use our own set of default media types rather than the system-supplied
ones. This ensures consistent media type behaviour across varied
environments. The defaults are based on those shipped with nginx, with
some custom additions.
"""
return {
".3gp": "vi... | [
"def",
"default_types",
"(",
")",
":",
"return",
"{",
"\".3gp\"",
":",
"\"video/3gpp\"",
",",
"\".3gpp\"",
":",
"\"video/3gpp\"",
",",
"\".7z\"",
":",
"\"application/x-7z-compressed\"",
",",
"\".ai\"",
":",
"\"application/postscript\"",
",",
"\".asf\"",
":",
"\"vide... | [
19,
0
] | [
128,
5
] | python | en | ['en', 'error', 'th'] | False |
start_acserver_with_systemd | () |
Running acserver with systemd unit (daemon) so that we can check the status when launched.
|
Running acserver with systemd unit (daemon) so that we can check the status when launched.
| def start_acserver_with_systemd():
"""
Running acserver with systemd unit (daemon) so that we can check the status when launched.
"""
out = subprocess.check_output(["systemd-run", "%s/acserver/acserver" % RUNTIME_PATH, "%s/ac-config.yml" % RUNTIME_PATH],stderr=subprocess.STDOUT).decode()
return r... | [
"def",
"start_acserver_with_systemd",
"(",
")",
":",
"out",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"\"systemd-run\"",
",",
"\"%s/acserver/acserver\"",
"%",
"RUNTIME_PATH",
",",
"\"%s/ac-config.yml\"",
"%",
"RUNTIME_PATH",
"]",
",",
"stderr",
"=",
"subproc... | [
30,
0
] | [
35,
63
] | python | en | ['en', 'error', 'th'] | False |
check_password | (environ, username, password) |
Authenticates against Django's auth database
mod_wsgi docs specify None, True, False as return value depending
on whether the user exists and authenticates.
|
Authenticates against Django's auth database | def check_password(environ, username, password):
"""
Authenticates against Django's auth database
mod_wsgi docs specify None, True, False as return value depending
on whether the user exists and authenticates.
"""
# db connection state is managed similarly to the wsgi handler
# as mod_wsgi... | [
"def",
"check_password",
"(",
"environ",
",",
"username",
",",
"password",
")",
":",
"# db connection state is managed similarly to the wsgi handler",
"# as mod_wsgi may call these functions outside of a request/response cycle",
"db",
".",
"reset_queries",
"(",
")",
"try",
":",
... | [
7,
0
] | [
28,
34
] | python | en | ['en', 'error', 'th'] | False |
groups_for_user | (environ, username) |
Authorizes a user based on groups
|
Authorizes a user based on groups
| def groups_for_user(environ, username):
"""
Authorizes a user based on groups
"""
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return []
if not user.is_active:
... | [
"def",
"groups_for_user",
"(",
"environ",
",",
"username",
")",
":",
"db",
".",
"reset_queries",
"(",
")",
"try",
":",
"try",
":",
"user",
"=",
"UserModel",
".",
"_default_manager",
".",
"get_by_natural_key",
"(",
"username",
")",
"except",
"UserModel",
".",... | [
31,
0
] | [
47,
34
] | python | en | ['en', 'error', 'th'] | False |
BaseHeuristic.warning | (self, response) |
Return a valid 1xx warning header value describing the cache
adjustments.
The response is provided too allow warnings like 113
http://tools.ietf.org/html/rfc7234#section-5.5.4 where we need
to explicitly say response is over 24 hours old.
|
Return a valid 1xx warning header value describing the cache
adjustments. | def warning(self, response):
"""
Return a valid 1xx warning header value describing the cache
adjustments.
The response is provided too allow warnings like 113
http://tools.ietf.org/html/rfc7234#section-5.5.4 where we need
to explicitly say response is over 24 hours old.... | [
"def",
"warning",
"(",
"self",
",",
"response",
")",
":",
"return",
"'110 - \"Response is Stale\"'"
] | [
21,
4
] | [
30,
42
] | python | en | ['en', 'error', 'th'] | False |
BaseHeuristic.update_headers | (self, response) | Update the response headers with any new headers.
NOTE: This SHOULD always include some Warning header to
signify that the response was cached by the client, not
by way of the provided headers.
| Update the response headers with any new headers. | def update_headers(self, response):
"""Update the response headers with any new headers.
NOTE: This SHOULD always include some Warning header to
signify that the response was cached by the client, not
by way of the provided headers.
"""
return {} | [
"def",
"update_headers",
"(",
"self",
",",
"response",
")",
":",
"return",
"{",
"}"
] | [
32,
4
] | [
39,
17
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.