repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
Calysto/calysto | calysto/ai/Numeric.py | outerproduct | def outerproduct(a, b):
"""Numeric.outerproduct([0.46474895, 0.46348238, 0.53923529, 0.46428344, 0.50223047],
[-0.16049719, 0.17086812, 0.1692107 , 0.17433657, 0.1738235 ,
0.17292975, 0.17553493, 0.17222987, -0.17038313, 0.17725782,
0.18428386]) =>
[[-0.0745909, 0.07941078, 0.078... | python | def outerproduct(a, b):
"""Numeric.outerproduct([0.46474895, 0.46348238, 0.53923529, 0.46428344, 0.50223047],
[-0.16049719, 0.17086812, 0.1692107 , 0.17433657, 0.1738235 ,
0.17292975, 0.17553493, 0.17222987, -0.17038313, 0.17725782,
0.18428386]) =>
[[-0.0745909, 0.07941078, 0.078... | [
"def",
"outerproduct",
"(",
"a",
",",
"b",
")",
":",
"result",
"=",
"zeros",
"(",
"(",
"len",
"(",
"a",
")",
",",
"len",
"(",
"b",
")",
")",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"a",
")",
")",
":",
"for",
"j",
"in",
"range",
"... | Numeric.outerproduct([0.46474895, 0.46348238, 0.53923529, 0.46428344, 0.50223047],
[-0.16049719, 0.17086812, 0.1692107 , 0.17433657, 0.1738235 ,
0.17292975, 0.17553493, 0.17222987, -0.17038313, 0.17725782,
0.18428386]) =>
[[-0.0745909, 0.07941078, 0.07864049, 0.08102274, 0.08078429... | [
"Numeric",
".",
"outerproduct",
"(",
"[",
"0",
".",
"46474895",
"0",
".",
"46348238",
"0",
".",
"53923529",
"0",
".",
"46428344",
"0",
".",
"50223047",
"]",
"[",
"-",
"0",
".",
"16049719",
"0",
".",
"17086812",
"0",
".",
"1692107",
"0",
".",
"17433... | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/Numeric.py#L176-L195 |
Calysto/calysto | calysto/ai/Numeric.py | add.reduce | def reduce(vector):
"""
Can be a vector or matrix. If data are bool, sum Trues.
"""
if type(vector) is list: # matrix
return array(list(map(add.reduce, vector)))
else:
return sum(vector) | python | def reduce(vector):
"""
Can be a vector or matrix. If data are bool, sum Trues.
"""
if type(vector) is list: # matrix
return array(list(map(add.reduce, vector)))
else:
return sum(vector) | [
"def",
"reduce",
"(",
"vector",
")",
":",
"if",
"type",
"(",
"vector",
")",
"is",
"list",
":",
"# matrix",
"return",
"array",
"(",
"list",
"(",
"map",
"(",
"add",
".",
"reduce",
",",
"vector",
")",
")",
")",
"else",
":",
"return",
"sum",
"(",
"ve... | Can be a vector or matrix. If data are bool, sum Trues. | [
"Can",
"be",
"a",
"vector",
"or",
"matrix",
".",
"If",
"data",
"are",
"bool",
"sum",
"Trues",
"."
] | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/Numeric.py#L156-L163 |
Calysto/calysto | calysto/ai/Numeric.py | multiply.reduce | def reduce(vector):
"""
Can be a vector or matrix. If data are bool, sum Trues.
"""
if type(vector) is list: # matrix
return array(list(map(multiply.reduce, vector)))
else:
return reduce(operator.mul, vector) | python | def reduce(vector):
"""
Can be a vector or matrix. If data are bool, sum Trues.
"""
if type(vector) is list: # matrix
return array(list(map(multiply.reduce, vector)))
else:
return reduce(operator.mul, vector) | [
"def",
"reduce",
"(",
"vector",
")",
":",
"if",
"type",
"(",
"vector",
")",
"is",
"list",
":",
"# matrix",
"return",
"array",
"(",
"list",
"(",
"map",
"(",
"multiply",
".",
"reduce",
",",
"vector",
")",
")",
")",
"else",
":",
"return",
"reduce",
"(... | Can be a vector or matrix. If data are bool, sum Trues. | [
"Can",
"be",
"a",
"vector",
"or",
"matrix",
".",
"If",
"data",
"are",
"bool",
"sum",
"Trues",
"."
] | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/Numeric.py#L167-L174 |
marshallward/f90nml | f90nml/fpy.py | pycomplex | def pycomplex(v_str):
"""Convert string repr of Fortran complex to Python complex."""
assert isinstance(v_str, str)
if v_str[0] == '(' and v_str[-1] == ')' and len(v_str.split(',')) == 2:
v_re, v_im = v_str[1:-1].split(',', 1)
# NOTE: Failed float(str) will raise ValueError
return ... | python | def pycomplex(v_str):
"""Convert string repr of Fortran complex to Python complex."""
assert isinstance(v_str, str)
if v_str[0] == '(' and v_str[-1] == ')' and len(v_str.split(',')) == 2:
v_re, v_im = v_str[1:-1].split(',', 1)
# NOTE: Failed float(str) will raise ValueError
return ... | [
"def",
"pycomplex",
"(",
"v_str",
")",
":",
"assert",
"isinstance",
"(",
"v_str",
",",
"str",
")",
"if",
"v_str",
"[",
"0",
"]",
"==",
"'('",
"and",
"v_str",
"[",
"-",
"1",
"]",
"==",
"')'",
"and",
"len",
"(",
"v_str",
".",
"split",
"(",
"','",
... | Convert string repr of Fortran complex to Python complex. | [
"Convert",
"string",
"repr",
"of",
"Fortran",
"complex",
"to",
"Python",
"complex",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/fpy.py#L20-L31 |
marshallward/f90nml | f90nml/fpy.py | pybool | def pybool(v_str, strict_logical=True):
"""Convert string repr of Fortran logical to Python logical."""
assert isinstance(v_str, str)
assert isinstance(strict_logical, bool)
if strict_logical:
v_bool = v_str.lower()
else:
try:
if v_str.startswith('.'):
v_... | python | def pybool(v_str, strict_logical=True):
"""Convert string repr of Fortran logical to Python logical."""
assert isinstance(v_str, str)
assert isinstance(strict_logical, bool)
if strict_logical:
v_bool = v_str.lower()
else:
try:
if v_str.startswith('.'):
v_... | [
"def",
"pybool",
"(",
"v_str",
",",
"strict_logical",
"=",
"True",
")",
":",
"assert",
"isinstance",
"(",
"v_str",
",",
"str",
")",
"assert",
"isinstance",
"(",
"strict_logical",
",",
"bool",
")",
"if",
"strict_logical",
":",
"v_bool",
"=",
"v_str",
".",
... | Convert string repr of Fortran logical to Python logical. | [
"Convert",
"string",
"repr",
"of",
"Fortran",
"logical",
"to",
"Python",
"logical",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/fpy.py#L34-L56 |
marshallward/f90nml | f90nml/fpy.py | pystr | def pystr(v_str):
"""Convert string repr of Fortran string to Python string."""
assert isinstance(v_str, str)
if v_str[0] in ("'", '"') and v_str[0] == v_str[-1]:
quote = v_str[0]
out = v_str[1:-1]
else:
# NOTE: This is non-standard Fortran.
# For example, gfortran... | python | def pystr(v_str):
"""Convert string repr of Fortran string to Python string."""
assert isinstance(v_str, str)
if v_str[0] in ("'", '"') and v_str[0] == v_str[-1]:
quote = v_str[0]
out = v_str[1:-1]
else:
# NOTE: This is non-standard Fortran.
# For example, gfortran... | [
"def",
"pystr",
"(",
"v_str",
")",
":",
"assert",
"isinstance",
"(",
"v_str",
",",
"str",
")",
"if",
"v_str",
"[",
"0",
"]",
"in",
"(",
"\"'\"",
",",
"'\"'",
")",
"and",
"v_str",
"[",
"0",
"]",
"==",
"v_str",
"[",
"-",
"1",
"]",
":",
"quote",
... | Convert string repr of Fortran string to Python string. | [
"Convert",
"string",
"repr",
"of",
"Fortran",
"string",
"to",
"Python",
"string",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/fpy.py#L59-L76 |
marshallward/f90nml | f90nml/parser.py | pad_array | def pad_array(v, idx):
"""Expand lists in multidimensional arrays to pad unset values."""
i_v, i_s = idx[0]
if len(idx) > 1:
# Append missing subarrays
v.extend([[] for _ in range(len(v), i_v - i_s + 1)])
# Pad elements
for e in v:
pad_array(e, idx[1:])
else... | python | def pad_array(v, idx):
"""Expand lists in multidimensional arrays to pad unset values."""
i_v, i_s = idx[0]
if len(idx) > 1:
# Append missing subarrays
v.extend([[] for _ in range(len(v), i_v - i_s + 1)])
# Pad elements
for e in v:
pad_array(e, idx[1:])
else... | [
"def",
"pad_array",
"(",
"v",
",",
"idx",
")",
":",
"i_v",
",",
"i_s",
"=",
"idx",
"[",
"0",
"]",
"if",
"len",
"(",
"idx",
")",
">",
"1",
":",
"# Append missing subarrays",
"v",
".",
"extend",
"(",
"[",
"[",
"]",
"for",
"_",
"in",
"range",
"(",... | Expand lists in multidimensional arrays to pad unset values. | [
"Expand",
"lists",
"in",
"multidimensional",
"arrays",
"to",
"pad",
"unset",
"values",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L837-L849 |
marshallward/f90nml | f90nml/parser.py | merge_values | def merge_values(src, new):
"""Merge two lists or dicts into a single element."""
if isinstance(src, dict) and isinstance(new, dict):
return merge_dicts(src, new)
else:
if not isinstance(src, list):
src = [src]
if not isinstance(new, list):
new = [new]
... | python | def merge_values(src, new):
"""Merge two lists or dicts into a single element."""
if isinstance(src, dict) and isinstance(new, dict):
return merge_dicts(src, new)
else:
if not isinstance(src, list):
src = [src]
if not isinstance(new, list):
new = [new]
... | [
"def",
"merge_values",
"(",
"src",
",",
"new",
")",
":",
"if",
"isinstance",
"(",
"src",
",",
"dict",
")",
"and",
"isinstance",
"(",
"new",
",",
"dict",
")",
":",
"return",
"merge_dicts",
"(",
"src",
",",
"new",
")",
"else",
":",
"if",
"not",
"isin... | Merge two lists or dicts into a single element. | [
"Merge",
"two",
"lists",
"or",
"dicts",
"into",
"a",
"single",
"element",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L852-L862 |
marshallward/f90nml | f90nml/parser.py | merge_lists | def merge_lists(src, new):
"""Update a value list with a list of new or updated values."""
l_min, l_max = (src, new) if len(src) < len(new) else (new, src)
l_min.extend(None for i in range(len(l_min), len(l_max)))
for i, val in enumerate(new):
if isinstance(val, dict) and isinstance(src[i], di... | python | def merge_lists(src, new):
"""Update a value list with a list of new or updated values."""
l_min, l_max = (src, new) if len(src) < len(new) else (new, src)
l_min.extend(None for i in range(len(l_min), len(l_max)))
for i, val in enumerate(new):
if isinstance(val, dict) and isinstance(src[i], di... | [
"def",
"merge_lists",
"(",
"src",
",",
"new",
")",
":",
"l_min",
",",
"l_max",
"=",
"(",
"src",
",",
"new",
")",
"if",
"len",
"(",
"src",
")",
"<",
"len",
"(",
"new",
")",
"else",
"(",
"new",
",",
"src",
")",
"l_min",
".",
"extend",
"(",
"Non... | Update a value list with a list of new or updated values. | [
"Update",
"a",
"value",
"list",
"with",
"a",
"list",
"of",
"new",
"or",
"updated",
"values",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L865-L881 |
marshallward/f90nml | f90nml/parser.py | merge_dicts | def merge_dicts(src, patch):
"""Merge contents of dict `patch` into `src`."""
for key in patch:
if key in src:
if isinstance(src[key], dict) and isinstance(patch[key], dict):
merge_dicts(src[key], patch[key])
else:
src[key] = merge_values(src[key],... | python | def merge_dicts(src, patch):
"""Merge contents of dict `patch` into `src`."""
for key in patch:
if key in src:
if isinstance(src[key], dict) and isinstance(patch[key], dict):
merge_dicts(src[key], patch[key])
else:
src[key] = merge_values(src[key],... | [
"def",
"merge_dicts",
"(",
"src",
",",
"patch",
")",
":",
"for",
"key",
"in",
"patch",
":",
"if",
"key",
"in",
"src",
":",
"if",
"isinstance",
"(",
"src",
"[",
"key",
"]",
",",
"dict",
")",
"and",
"isinstance",
"(",
"patch",
"[",
"key",
"]",
",",... | Merge contents of dict `patch` into `src`. | [
"Merge",
"contents",
"of",
"dict",
"patch",
"into",
"src",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L884-L895 |
marshallward/f90nml | f90nml/parser.py | delist | def delist(values):
"""Reduce lists of zero or one elements to individual values."""
assert isinstance(values, list)
if not values:
return None
elif len(values) == 1:
return values[0]
return values | python | def delist(values):
"""Reduce lists of zero or one elements to individual values."""
assert isinstance(values, list)
if not values:
return None
elif len(values) == 1:
return values[0]
return values | [
"def",
"delist",
"(",
"values",
")",
":",
"assert",
"isinstance",
"(",
"values",
",",
"list",
")",
"if",
"not",
"values",
":",
"return",
"None",
"elif",
"len",
"(",
"values",
")",
"==",
"1",
":",
"return",
"values",
"[",
"0",
"]",
"return",
"values"
... | Reduce lists of zero or one elements to individual values. | [
"Reduce",
"lists",
"of",
"zero",
"or",
"one",
"elements",
"to",
"individual",
"values",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L898-L907 |
marshallward/f90nml | f90nml/parser.py | count_values | def count_values(tokens):
"""Identify the number of values ahead of the current token."""
ntoks = 0
for tok in tokens:
if tok in ('=', '/', '$', '&'):
if ntoks > 0 and tok == '=':
ntoks -= 1
break
elif tok in whitespace + ',':
continue
... | python | def count_values(tokens):
"""Identify the number of values ahead of the current token."""
ntoks = 0
for tok in tokens:
if tok in ('=', '/', '$', '&'):
if ntoks > 0 and tok == '=':
ntoks -= 1
break
elif tok in whitespace + ',':
continue
... | [
"def",
"count_values",
"(",
"tokens",
")",
":",
"ntoks",
"=",
"0",
"for",
"tok",
"in",
"tokens",
":",
"if",
"tok",
"in",
"(",
"'='",
",",
"'/'",
",",
"'$'",
",",
"'&'",
")",
":",
"if",
"ntoks",
">",
"0",
"and",
"tok",
"==",
"'='",
":",
"ntoks",... | Identify the number of values ahead of the current token. | [
"Identify",
"the",
"number",
"of",
"values",
"ahead",
"of",
"the",
"current",
"token",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L910-L923 |
marshallward/f90nml | f90nml/parser.py | Parser.comment_tokens | def comment_tokens(self, value):
"""Validate and set the comment token string."""
if not isinstance(value, str):
raise TypeError('comment_tokens attribute must be a string.')
self._comment_tokens = value | python | def comment_tokens(self, value):
"""Validate and set the comment token string."""
if not isinstance(value, str):
raise TypeError('comment_tokens attribute must be a string.')
self._comment_tokens = value | [
"def",
"comment_tokens",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"'comment_tokens attribute must be a string.'",
")",
"self",
".",
"_comment_tokens",
"=",
"value"
] | Validate and set the comment token string. | [
"Validate",
"and",
"set",
"the",
"comment",
"token",
"string",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L65-L69 |
marshallward/f90nml | f90nml/parser.py | Parser.default_start_index | def default_start_index(self, value):
"""Validate and set the default start index."""
if not isinstance(value, int):
raise TypeError('default_start_index attribute must be of int '
'type.')
self._default_start_index = value | python | def default_start_index(self, value):
"""Validate and set the default start index."""
if not isinstance(value, int):
raise TypeError('default_start_index attribute must be of int '
'type.')
self._default_start_index = value | [
"def",
"default_start_index",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"int",
")",
":",
"raise",
"TypeError",
"(",
"'default_start_index attribute must be of int '",
"'type.'",
")",
"self",
".",
"_default_start_index",
"="... | Validate and set the default start index. | [
"Validate",
"and",
"set",
"the",
"default",
"start",
"index",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L107-L112 |
marshallward/f90nml | f90nml/parser.py | Parser.sparse_arrays | def sparse_arrays(self, value):
"""Validate and enable spare arrays."""
if not isinstance(value, bool):
raise TypeError('sparse_arrays attribute must be a logical type.')
self._sparse_arrays = value | python | def sparse_arrays(self, value):
"""Validate and enable spare arrays."""
if not isinstance(value, bool):
raise TypeError('sparse_arrays attribute must be a logical type.')
self._sparse_arrays = value | [
"def",
"sparse_arrays",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"'sparse_arrays attribute must be a logical type.'",
")",
"self",
".",
"_sparse_arrays",
"=",
"value"
] | Validate and enable spare arrays. | [
"Validate",
"and",
"enable",
"spare",
"arrays",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L127-L131 |
marshallward/f90nml | f90nml/parser.py | Parser.global_start_index | def global_start_index(self, value):
"""Set the global start index."""
if not isinstance(value, int) and value is not None:
raise TypeError('global_start_index attribute must be of int '
'type.')
self._global_start_index = value | python | def global_start_index(self, value):
"""Set the global start index."""
if not isinstance(value, int) and value is not None:
raise TypeError('global_start_index attribute must be of int '
'type.')
self._global_start_index = value | [
"def",
"global_start_index",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"int",
")",
"and",
"value",
"is",
"not",
"None",
":",
"raise",
"TypeError",
"(",
"'global_start_index attribute must be of int '",
"'type.'",
")",
"... | Set the global start index. | [
"Set",
"the",
"global",
"start",
"index",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L170-L175 |
marshallward/f90nml | f90nml/parser.py | Parser.row_major | def row_major(self, value):
"""Validate and set row-major format for multidimensional arrays."""
if value is not None:
if not isinstance(value, bool):
raise TypeError(
'f90nml: error: row_major must be a logical value.')
else:
s... | python | def row_major(self, value):
"""Validate and set row-major format for multidimensional arrays."""
if value is not None:
if not isinstance(value, bool):
raise TypeError(
'f90nml: error: row_major must be a logical value.')
else:
s... | [
"def",
"row_major",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"'f90nml: error: row_major must be a logical value.'",
")",
"else",
"... | Validate and set row-major format for multidimensional arrays. | [
"Validate",
"and",
"set",
"row",
"-",
"major",
"format",
"for",
"multidimensional",
"arrays",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L192-L199 |
marshallward/f90nml | f90nml/parser.py | Parser.strict_logical | def strict_logical(self, value):
"""Validate and set the strict logical flag."""
if value is not None:
if not isinstance(value, bool):
raise TypeError(
'f90nml: error: strict_logical must be a logical value.')
else:
self._strict... | python | def strict_logical(self, value):
"""Validate and set the strict logical flag."""
if value is not None:
if not isinstance(value, bool):
raise TypeError(
'f90nml: error: strict_logical must be a logical value.')
else:
self._strict... | [
"def",
"strict_logical",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"'f90nml: error: strict_logical must be a logical value.'",
")",
"... | Validate and set the strict logical flag. | [
"Validate",
"and",
"set",
"the",
"strict",
"logical",
"flag",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L221-L228 |
marshallward/f90nml | f90nml/parser.py | Parser.read | def read(self, nml_fname, nml_patch_in=None, patch_fname=None):
"""Parse a Fortran namelist file and store the contents.
>>> parser = f90nml.Parser()
>>> data_nml = parser.read('data.nml')
"""
# For switching based on files versus paths
nml_is_path = not hasattr(nml_fnam... | python | def read(self, nml_fname, nml_patch_in=None, patch_fname=None):
"""Parse a Fortran namelist file and store the contents.
>>> parser = f90nml.Parser()
>>> data_nml = parser.read('data.nml')
"""
# For switching based on files versus paths
nml_is_path = not hasattr(nml_fnam... | [
"def",
"read",
"(",
"self",
",",
"nml_fname",
",",
"nml_patch_in",
"=",
"None",
",",
"patch_fname",
"=",
"None",
")",
":",
"# For switching based on files versus paths",
"nml_is_path",
"=",
"not",
"hasattr",
"(",
"nml_fname",
",",
"'read'",
")",
"patch_is_path",
... | Parse a Fortran namelist file and store the contents.
>>> parser = f90nml.Parser()
>>> data_nml = parser.read('data.nml') | [
"Parse",
"a",
"Fortran",
"namelist",
"file",
"and",
"store",
"the",
"contents",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L230-L272 |
marshallward/f90nml | f90nml/parser.py | Parser._readstream | def _readstream(self, nml_file, nml_patch_in=None):
"""Parse an input stream containing a Fortran namelist."""
nml_patch = nml_patch_in if nml_patch_in is not None else Namelist()
tokenizer = Tokenizer()
f90lex = []
for line in nml_file:
toks = tokenizer.parse(line)
... | python | def _readstream(self, nml_file, nml_patch_in=None):
"""Parse an input stream containing a Fortran namelist."""
nml_patch = nml_patch_in if nml_patch_in is not None else Namelist()
tokenizer = Tokenizer()
f90lex = []
for line in nml_file:
toks = tokenizer.parse(line)
... | [
"def",
"_readstream",
"(",
"self",
",",
"nml_file",
",",
"nml_patch_in",
"=",
"None",
")",
":",
"nml_patch",
"=",
"nml_patch_in",
"if",
"nml_patch_in",
"is",
"not",
"None",
"else",
"Namelist",
"(",
")",
"tokenizer",
"=",
"Tokenizer",
"(",
")",
"f90lex",
"=... | Parse an input stream containing a Fortran namelist. | [
"Parse",
"an",
"input",
"stream",
"containing",
"a",
"Fortran",
"namelist",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L282-L406 |
marshallward/f90nml | f90nml/parser.py | Parser._parse_variable | def _parse_variable(self, parent, patch_nml=None):
"""Parse a variable and return its name and values."""
if not patch_nml:
patch_nml = Namelist()
v_name = self.prior_token
v_values = []
# Patch state
patch_values = None
# Derived type parent index ... | python | def _parse_variable(self, parent, patch_nml=None):
"""Parse a variable and return its name and values."""
if not patch_nml:
patch_nml = Namelist()
v_name = self.prior_token
v_values = []
# Patch state
patch_values = None
# Derived type parent index ... | [
"def",
"_parse_variable",
"(",
"self",
",",
"parent",
",",
"patch_nml",
"=",
"None",
")",
":",
"if",
"not",
"patch_nml",
":",
"patch_nml",
"=",
"Namelist",
"(",
")",
"v_name",
"=",
"self",
".",
"prior_token",
"v_values",
"=",
"[",
"]",
"# Patch state",
"... | Parse a variable and return its name and values. | [
"Parse",
"a",
"variable",
"and",
"return",
"its",
"name",
"and",
"values",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L408-L637 |
marshallward/f90nml | f90nml/parser.py | Parser._parse_indices | def _parse_indices(self):
"""Parse a sequence of Fortran vector indices as a list of tuples."""
v_name = self.prior_token
v_indices = []
while self.token in (',', '('):
v_indices.append(self._parse_index(v_name))
return v_indices | python | def _parse_indices(self):
"""Parse a sequence of Fortran vector indices as a list of tuples."""
v_name = self.prior_token
v_indices = []
while self.token in (',', '('):
v_indices.append(self._parse_index(v_name))
return v_indices | [
"def",
"_parse_indices",
"(",
"self",
")",
":",
"v_name",
"=",
"self",
".",
"prior_token",
"v_indices",
"=",
"[",
"]",
"while",
"self",
".",
"token",
"in",
"(",
"','",
",",
"'('",
")",
":",
"v_indices",
".",
"append",
"(",
"self",
".",
"_parse_index",
... | Parse a sequence of Fortran vector indices as a list of tuples. | [
"Parse",
"a",
"sequence",
"of",
"Fortran",
"vector",
"indices",
"as",
"a",
"list",
"of",
"tuples",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L639-L647 |
marshallward/f90nml | f90nml/parser.py | Parser._parse_index | def _parse_index(self, v_name):
"""Parse Fortran vector indices into a tuple of Python indices."""
i_start = i_end = i_stride = None
# Start index
self._update_tokens()
try:
i_start = int(self.token)
self._update_tokens()
except ValueError:
... | python | def _parse_index(self, v_name):
"""Parse Fortran vector indices into a tuple of Python indices."""
i_start = i_end = i_stride = None
# Start index
self._update_tokens()
try:
i_start = int(self.token)
self._update_tokens()
except ValueError:
... | [
"def",
"_parse_index",
"(",
"self",
",",
"v_name",
")",
":",
"i_start",
"=",
"i_end",
"=",
"i_stride",
"=",
"None",
"# Start index",
"self",
".",
"_update_tokens",
"(",
")",
"try",
":",
"i_start",
"=",
"int",
"(",
"self",
".",
"token",
")",
"self",
"."... | Parse Fortran vector indices into a tuple of Python indices. | [
"Parse",
"Fortran",
"vector",
"indices",
"into",
"a",
"tuple",
"of",
"Python",
"indices",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L649-L704 |
marshallward/f90nml | f90nml/parser.py | Parser._parse_value | def _parse_value(self, write_token=True, override=None):
"""Convert string repr of Fortran type to equivalent Python type."""
v_str = self.prior_token
# Construct the complex string
if v_str == '(':
v_re = self.token
self._update_tokens(write_token)
... | python | def _parse_value(self, write_token=True, override=None):
"""Convert string repr of Fortran type to equivalent Python type."""
v_str = self.prior_token
# Construct the complex string
if v_str == '(':
v_re = self.token
self._update_tokens(write_token)
... | [
"def",
"_parse_value",
"(",
"self",
",",
"write_token",
"=",
"True",
",",
"override",
"=",
"None",
")",
":",
"v_str",
"=",
"self",
".",
"prior_token",
"# Construct the complex string",
"if",
"v_str",
"==",
"'('",
":",
"v_re",
"=",
"self",
".",
"token",
"se... | Convert string repr of Fortran type to equivalent Python type. | [
"Convert",
"string",
"repr",
"of",
"Fortran",
"type",
"to",
"equivalent",
"Python",
"type",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L706-L737 |
marshallward/f90nml | f90nml/parser.py | Parser._update_tokens | def _update_tokens(self, write_token=True, override=None,
patch_skip=False):
"""Update tokens to the next available values."""
next_token = next(self.tokens)
patch_value = ''
patch_tokens = ''
if self.pfile and write_token:
token = override if... | python | def _update_tokens(self, write_token=True, override=None,
patch_skip=False):
"""Update tokens to the next available values."""
next_token = next(self.tokens)
patch_value = ''
patch_tokens = ''
if self.pfile and write_token:
token = override if... | [
"def",
"_update_tokens",
"(",
"self",
",",
"write_token",
"=",
"True",
",",
"override",
"=",
"None",
",",
"patch_skip",
"=",
"False",
")",
":",
"next_token",
"=",
"next",
"(",
"self",
".",
"tokens",
")",
"patch_value",
"=",
"''",
"patch_tokens",
"=",
"''... | Update tokens to the next available values. | [
"Update",
"tokens",
"to",
"the",
"next",
"available",
"values",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L739-L779 |
marshallward/f90nml | f90nml/parser.py | Parser._append_value | def _append_value(self, v_values, next_value, v_idx=None, n_vals=1):
"""Update a list of parsed values with a new value."""
for _ in range(n_vals):
if v_idx:
try:
v_i = next(v_idx)
except StopIteration:
# Repeating comma... | python | def _append_value(self, v_values, next_value, v_idx=None, n_vals=1):
"""Update a list of parsed values with a new value."""
for _ in range(n_vals):
if v_idx:
try:
v_i = next(v_idx)
except StopIteration:
# Repeating comma... | [
"def",
"_append_value",
"(",
"self",
",",
"v_values",
",",
"next_value",
",",
"v_idx",
"=",
"None",
",",
"n_vals",
"=",
"1",
")",
":",
"for",
"_",
"in",
"range",
"(",
"n_vals",
")",
":",
"if",
"v_idx",
":",
"try",
":",
"v_i",
"=",
"next",
"(",
"v... | Update a list of parsed values with a new value. | [
"Update",
"a",
"list",
"of",
"parsed",
"values",
"with",
"a",
"new",
"value",
"."
] | train | https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/parser.py#L781-L832 |
Calysto/calysto | calysto/widget/__init__.py | display_pil_image | def display_pil_image(im):
"""Displayhook function for PIL Images, rendered as PNG."""
from IPython.core import display
b = BytesIO()
im.save(b, format='png')
data = b.getvalue()
ip_img = display.Image(data=data, format='png', embed=True)
return ip_img._repr_png_() | python | def display_pil_image(im):
"""Displayhook function for PIL Images, rendered as PNG."""
from IPython.core import display
b = BytesIO()
im.save(b, format='png')
data = b.getvalue()
ip_img = display.Image(data=data, format='png', embed=True)
return ip_img._repr_png_() | [
"def",
"display_pil_image",
"(",
"im",
")",
":",
"from",
"IPython",
".",
"core",
"import",
"display",
"b",
"=",
"BytesIO",
"(",
")",
"im",
".",
"save",
"(",
"b",
",",
"format",
"=",
"'png'",
")",
"data",
"=",
"b",
".",
"getvalue",
"(",
")",
"ip_img... | Displayhook function for PIL Images, rendered as PNG. | [
"Displayhook",
"function",
"for",
"PIL",
"Images",
"rendered",
"as",
"PNG",
"."
] | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/widget/__init__.py#L9-L17 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient._prepare_uri | def _prepare_uri(self, service_name, **parameters):
"""Prepare the URI for a request
:param service_name: The target service
:type service_name: str
:param kwargs: query parameters
:return: The uri of the request
"""
query_parameters = []
for key, value i... | python | def _prepare_uri(self, service_name, **parameters):
"""Prepare the URI for a request
:param service_name: The target service
:type service_name: str
:param kwargs: query parameters
:return: The uri of the request
"""
query_parameters = []
for key, value i... | [
"def",
"_prepare_uri",
"(",
"self",
",",
"service_name",
",",
"*",
"*",
"parameters",
")",
":",
"query_parameters",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"parameters",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"(",
... | Prepare the URI for a request
:param service_name: The target service
:type service_name: str
:param kwargs: query parameters
:return: The uri of the request | [
"Prepare",
"the",
"URI",
"for",
"a",
"request"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L39-L60 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient._handle_rate_exceeded | def _handle_rate_exceeded(self, response): # pragma: no cover
"""Handles rate exceeded errors"""
waiting_time = int(response.headers.get("Retry-After", 10))
time.sleep(waiting_time) | python | def _handle_rate_exceeded(self, response): # pragma: no cover
"""Handles rate exceeded errors"""
waiting_time = int(response.headers.get("Retry-After", 10))
time.sleep(waiting_time) | [
"def",
"_handle_rate_exceeded",
"(",
"self",
",",
"response",
")",
":",
"# pragma: no cover",
"waiting_time",
"=",
"int",
"(",
"response",
".",
"headers",
".",
"get",
"(",
"\"Retry-After\"",
",",
"10",
")",
")",
"time",
".",
"sleep",
"(",
"waiting_time",
")"... | Handles rate exceeded errors | [
"Handles",
"rate",
"exceeded",
"errors"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L64-L67 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient._send | def _send(self, send_method, service_name, data=None, **kwargs):
"""Send a request to the AppNexus API (used for internal routing)
:param send_method: The method sending the request (usualy requests.*)
:type send_method: function
:param service_name: The target service
:param da... | python | def _send(self, send_method, service_name, data=None, **kwargs):
"""Send a request to the AppNexus API (used for internal routing)
:param send_method: The method sending the request (usualy requests.*)
:type send_method: function
:param service_name: The target service
:param da... | [
"def",
"_send",
"(",
"self",
",",
"send_method",
",",
"service_name",
",",
"data",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"valid_response",
"=",
"False",
"raw",
"=",
"kwargs",
".",
"pop",
"(",
"\"raw\"",
",",
"False",
")",
"while",
"not",
"v... | Send a request to the AppNexus API (used for internal routing)
:param send_method: The method sending the request (usualy requests.*)
:type send_method: function
:param service_name: The target service
:param data: The payload of the request (optionnal)
:type data: anything JSON... | [
"Send",
"a",
"request",
"to",
"the",
"AppNexus",
"API",
"(",
"used",
"for",
"internal",
"routing",
")"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L69-L108 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient.update_token | def update_token(self):
"""Request a new token and store it for future use"""
logger.info('updating token')
if None in self.credentials.values():
raise RuntimeError("You must provide an username and a password")
credentials = dict(auth=self.credentials)
url = self.tes... | python | def update_token(self):
"""Request a new token and store it for future use"""
logger.info('updating token')
if None in self.credentials.values():
raise RuntimeError("You must provide an username and a password")
credentials = dict(auth=self.credentials)
url = self.tes... | [
"def",
"update_token",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"'updating token'",
")",
"if",
"None",
"in",
"self",
".",
"credentials",
".",
"values",
"(",
")",
":",
"raise",
"RuntimeError",
"(",
"\"You must provide an username and a password\"",
")",... | Request a new token and store it for future use | [
"Request",
"a",
"new",
"token",
"and",
"store",
"it",
"for",
"future",
"use"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L110-L129 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient.check_errors | def check_errors(self, response, data):
"""Check for errors and raise an appropriate error if needed"""
if "error_id" in data:
error_id = data["error_id"]
if error_id in self.error_ids:
raise self.error_ids[error_id](response)
if "error_code" in data:
... | python | def check_errors(self, response, data):
"""Check for errors and raise an appropriate error if needed"""
if "error_id" in data:
error_id = data["error_id"]
if error_id in self.error_ids:
raise self.error_ids[error_id](response)
if "error_code" in data:
... | [
"def",
"check_errors",
"(",
"self",
",",
"response",
",",
"data",
")",
":",
"if",
"\"error_id\"",
"in",
"data",
":",
"error_id",
"=",
"data",
"[",
"\"error_id\"",
"]",
"if",
"error_id",
"in",
"self",
".",
"error_ids",
":",
"raise",
"self",
".",
"error_id... | Check for errors and raise an appropriate error if needed | [
"Check",
"for",
"errors",
"and",
"raise",
"an",
"appropriate",
"error",
"if",
"needed"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L131-L142 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient.get | def get(self, service_name, **kwargs):
"""Retrieve data from AppNexus API"""
return self._send(requests.get, service_name, **kwargs) | python | def get(self, service_name, **kwargs):
"""Retrieve data from AppNexus API"""
return self._send(requests.get, service_name, **kwargs) | [
"def",
"get",
"(",
"self",
",",
"service_name",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_send",
"(",
"requests",
".",
"get",
",",
"service_name",
",",
"*",
"*",
"kwargs",
")"
] | Retrieve data from AppNexus API | [
"Retrieve",
"data",
"from",
"AppNexus",
"API"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L144-L146 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient.modify | def modify(self, service_name, json, **kwargs):
"""Modify an AppNexus object"""
return self._send(requests.put, service_name, json, **kwargs) | python | def modify(self, service_name, json, **kwargs):
"""Modify an AppNexus object"""
return self._send(requests.put, service_name, json, **kwargs) | [
"def",
"modify",
"(",
"self",
",",
"service_name",
",",
"json",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_send",
"(",
"requests",
".",
"put",
",",
"service_name",
",",
"json",
",",
"*",
"*",
"kwargs",
")"
] | Modify an AppNexus object | [
"Modify",
"an",
"AppNexus",
"object"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L148-L150 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient.create | def create(self, service_name, json, **kwargs):
"""Create a new AppNexus object"""
return self._send(requests.post, service_name, json, **kwargs) | python | def create(self, service_name, json, **kwargs):
"""Create a new AppNexus object"""
return self._send(requests.post, service_name, json, **kwargs) | [
"def",
"create",
"(",
"self",
",",
"service_name",
",",
"json",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_send",
"(",
"requests",
".",
"post",
",",
"service_name",
",",
"json",
",",
"*",
"*",
"kwargs",
")"
] | Create a new AppNexus object | [
"Create",
"a",
"new",
"AppNexus",
"object"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L152-L154 |
numberly/appnexus-client | appnexus/client.py | AppNexusClient.delete | def delete(self, service_name, *ids, **kwargs):
"""Delete an AppNexus object"""
return self._send(requests.delete, service_name, id=ids, **kwargs) | python | def delete(self, service_name, *ids, **kwargs):
"""Delete an AppNexus object"""
return self._send(requests.delete, service_name, id=ids, **kwargs) | [
"def",
"delete",
"(",
"self",
",",
"service_name",
",",
"*",
"ids",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_send",
"(",
"requests",
".",
"delete",
",",
"service_name",
",",
"id",
"=",
"ids",
",",
"*",
"*",
"kwargs",
")"
] | Delete an AppNexus object | [
"Delete",
"an",
"AppNexus",
"object"
] | train | https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/client.py#L156-L158 |
Calysto/calysto | calysto/zgraphics.py | GraphWin.plot | def plot(self, x, y, color="black"):
"""
Uses coordinant system.
"""
p = Point(x, y)
p.fill(color)
p.draw(self) | python | def plot(self, x, y, color="black"):
"""
Uses coordinant system.
"""
p = Point(x, y)
p.fill(color)
p.draw(self) | [
"def",
"plot",
"(",
"self",
",",
"x",
",",
"y",
",",
"color",
"=",
"\"black\"",
")",
":",
"p",
"=",
"Point",
"(",
"x",
",",
"y",
")",
"p",
".",
"fill",
"(",
"color",
")",
"p",
".",
"draw",
"(",
"self",
")"
] | Uses coordinant system. | [
"Uses",
"coordinant",
"system",
"."
] | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/zgraphics.py#L71-L77 |
Calysto/calysto | calysto/zgraphics.py | GraphWin.plotPixel | def plotPixel(self, x, y, color="black"):
"""
Doesn't use coordinant system.
"""
p = Point(x, y)
p.fill(color)
p.draw(self)
p.t = lambda v: v
p.tx = lambda v: v
p.ty = lambda v: v | python | def plotPixel(self, x, y, color="black"):
"""
Doesn't use coordinant system.
"""
p = Point(x, y)
p.fill(color)
p.draw(self)
p.t = lambda v: v
p.tx = lambda v: v
p.ty = lambda v: v | [
"def",
"plotPixel",
"(",
"self",
",",
"x",
",",
"y",
",",
"color",
"=",
"\"black\"",
")",
":",
"p",
"=",
"Point",
"(",
"x",
",",
"y",
")",
"p",
".",
"fill",
"(",
"color",
")",
"p",
".",
"draw",
"(",
"self",
")",
"p",
".",
"t",
"=",
"lambda"... | Doesn't use coordinant system. | [
"Doesn",
"t",
"use",
"coordinant",
"system",
"."
] | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/zgraphics.py#L79-L88 |
Calysto/calysto | calysto/zgraphics.py | GraphWin.getMouse | def getMouse(self):
"""
Waits for a mouse click.
"""
# FIXME: this isn't working during an executing cell
self.mouse_x.value = -1
self.mouse_y.value = -1
while self.mouse_x.value == -1 and self.mouse_y.value == -1:
time.sleep(.1)
return (self.m... | python | def getMouse(self):
"""
Waits for a mouse click.
"""
# FIXME: this isn't working during an executing cell
self.mouse_x.value = -1
self.mouse_y.value = -1
while self.mouse_x.value == -1 and self.mouse_y.value == -1:
time.sleep(.1)
return (self.m... | [
"def",
"getMouse",
"(",
"self",
")",
":",
"# FIXME: this isn't working during an executing cell",
"self",
".",
"mouse_x",
".",
"value",
"=",
"-",
"1",
"self",
".",
"mouse_y",
".",
"value",
"=",
"-",
"1",
"while",
"self",
".",
"mouse_x",
".",
"value",
"==",
... | Waits for a mouse click. | [
"Waits",
"for",
"a",
"mouse",
"click",
"."
] | train | https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/zgraphics.py#L90-L99 |
Robpol86/sphinxcontrib-disqus | sphinxcontrib/disqus.py | event_html_page_context | def event_html_page_context(app, pagename, templatename, context, doctree):
"""Called when the HTML builder has created a context dictionary to render a template with.
Conditionally adding disqus.js to <head /> if the directive is used in a page.
:param sphinx.application.Sphinx app: Sphinx application ob... | python | def event_html_page_context(app, pagename, templatename, context, doctree):
"""Called when the HTML builder has created a context dictionary to render a template with.
Conditionally adding disqus.js to <head /> if the directive is used in a page.
:param sphinx.application.Sphinx app: Sphinx application ob... | [
"def",
"event_html_page_context",
"(",
"app",
",",
"pagename",
",",
"templatename",
",",
"context",
",",
"doctree",
")",
":",
"assert",
"app",
"or",
"pagename",
"or",
"templatename",
"# Unused, for linting.",
"if",
"'script_files'",
"in",
"context",
"and",
"doctre... | Called when the HTML builder has created a context dictionary to render a template with.
Conditionally adding disqus.js to <head /> if the directive is used in a page.
:param sphinx.application.Sphinx app: Sphinx application object.
:param str pagename: Name of the page being rendered (without .html or an... | [
"Called",
"when",
"the",
"HTML",
"builder",
"has",
"created",
"a",
"context",
"dictionary",
"to",
"render",
"a",
"template",
"with",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-disqus/blob/1da36bcb83b82b6493a33481c03a0956a557bd5c/sphinxcontrib/disqus.py#L102-L116 |
Robpol86/sphinxcontrib-disqus | sphinxcontrib/disqus.py | setup | def setup(app):
"""Called by Sphinx during phase 0 (initialization).
:param app: Sphinx application object.
:returns: Extension version.
:rtype: dict
"""
app.add_config_value('disqus_shortname', None, True)
app.add_directive('disqus', DisqusDirective)
app.add_node(DisqusNode, html=(Dis... | python | def setup(app):
"""Called by Sphinx during phase 0 (initialization).
:param app: Sphinx application object.
:returns: Extension version.
:rtype: dict
"""
app.add_config_value('disqus_shortname', None, True)
app.add_directive('disqus', DisqusDirective)
app.add_node(DisqusNode, html=(Dis... | [
"def",
"setup",
"(",
"app",
")",
":",
"app",
".",
"add_config_value",
"(",
"'disqus_shortname'",
",",
"None",
",",
"True",
")",
"app",
".",
"add_directive",
"(",
"'disqus'",
",",
"DisqusDirective",
")",
"app",
".",
"add_node",
"(",
"DisqusNode",
",",
"html... | Called by Sphinx during phase 0 (initialization).
:param app: Sphinx application object.
:returns: Extension version.
:rtype: dict | [
"Called",
"by",
"Sphinx",
"during",
"phase",
"0",
"(",
"initialization",
")",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-disqus/blob/1da36bcb83b82b6493a33481c03a0956a557bd5c/sphinxcontrib/disqus.py#L119-L132 |
Robpol86/sphinxcontrib-disqus | sphinxcontrib/disqus.py | DisqusNode.visit | def visit(spht, node):
"""Append opening tags to document body list."""
html_attrs = {
'ids': ['disqus_thread'],
'data-disqus-shortname': node.disqus_shortname,
'data-disqus-identifier': node.disqus_identifier,
}
spht.body.append(spht.starttag(node, 'd... | python | def visit(spht, node):
"""Append opening tags to document body list."""
html_attrs = {
'ids': ['disqus_thread'],
'data-disqus-shortname': node.disqus_shortname,
'data-disqus-identifier': node.disqus_identifier,
}
spht.body.append(spht.starttag(node, 'd... | [
"def",
"visit",
"(",
"spht",
",",
"node",
")",
":",
"html_attrs",
"=",
"{",
"'ids'",
":",
"[",
"'disqus_thread'",
"]",
",",
"'data-disqus-shortname'",
":",
"node",
".",
"disqus_shortname",
",",
"'data-disqus-identifier'",
":",
"node",
".",
"disqus_identifier",
... | Append opening tags to document body list. | [
"Append",
"opening",
"tags",
"to",
"document",
"body",
"list",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-disqus/blob/1da36bcb83b82b6493a33481c03a0956a557bd5c/sphinxcontrib/disqus.py#L44-L51 |
Robpol86/sphinxcontrib-disqus | sphinxcontrib/disqus.py | DisqusDirective.get_shortname | def get_shortname(self):
"""Validate and returns disqus_shortname config value.
:returns: disqus_shortname config value.
:rtype: str
"""
disqus_shortname = self.state.document.settings.env.config.disqus_shortname
if not disqus_shortname:
raise ExtensionError(... | python | def get_shortname(self):
"""Validate and returns disqus_shortname config value.
:returns: disqus_shortname config value.
:rtype: str
"""
disqus_shortname = self.state.document.settings.env.config.disqus_shortname
if not disqus_shortname:
raise ExtensionError(... | [
"def",
"get_shortname",
"(",
"self",
")",
":",
"disqus_shortname",
"=",
"self",
".",
"state",
".",
"document",
".",
"settings",
".",
"env",
".",
"config",
".",
"disqus_shortname",
"if",
"not",
"disqus_shortname",
":",
"raise",
"ExtensionError",
"(",
"'disqus_s... | Validate and returns disqus_shortname config value.
:returns: disqus_shortname config value.
:rtype: str | [
"Validate",
"and",
"returns",
"disqus_shortname",
"config",
"value",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-disqus/blob/1da36bcb83b82b6493a33481c03a0956a557bd5c/sphinxcontrib/disqus.py#L64-L75 |
Robpol86/sphinxcontrib-disqus | sphinxcontrib/disqus.py | DisqusDirective.get_identifier | def get_identifier(self):
"""Validate and returns disqus_identifier option value.
:returns: disqus_identifier config value.
:rtype: str
"""
if 'disqus_identifier' in self.options:
return self.options['disqus_identifier']
title_nodes = self.state.document.tra... | python | def get_identifier(self):
"""Validate and returns disqus_identifier option value.
:returns: disqus_identifier config value.
:rtype: str
"""
if 'disqus_identifier' in self.options:
return self.options['disqus_identifier']
title_nodes = self.state.document.tra... | [
"def",
"get_identifier",
"(",
"self",
")",
":",
"if",
"'disqus_identifier'",
"in",
"self",
".",
"options",
":",
"return",
"self",
".",
"options",
"[",
"'disqus_identifier'",
"]",
"title_nodes",
"=",
"self",
".",
"state",
".",
"document",
".",
"traverse",
"("... | Validate and returns disqus_identifier option value.
:returns: disqus_identifier config value.
:rtype: str | [
"Validate",
"and",
"returns",
"disqus_identifier",
"option",
"value",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-disqus/blob/1da36bcb83b82b6493a33481c03a0956a557bd5c/sphinxcontrib/disqus.py#L77-L89 |
Robpol86/sphinxcontrib-disqus | sphinxcontrib/disqus.py | DisqusDirective.run | def run(self):
"""Executed by Sphinx.
:returns: Single DisqusNode instance with config values passed as arguments.
:rtype: list
"""
disqus_shortname = self.get_shortname()
disqus_identifier = self.get_identifier()
return [DisqusNode(disqus_shortname, disqus_ident... | python | def run(self):
"""Executed by Sphinx.
:returns: Single DisqusNode instance with config values passed as arguments.
:rtype: list
"""
disqus_shortname = self.get_shortname()
disqus_identifier = self.get_identifier()
return [DisqusNode(disqus_shortname, disqus_ident... | [
"def",
"run",
"(",
"self",
")",
":",
"disqus_shortname",
"=",
"self",
".",
"get_shortname",
"(",
")",
"disqus_identifier",
"=",
"self",
".",
"get_identifier",
"(",
")",
"return",
"[",
"DisqusNode",
"(",
"disqus_shortname",
",",
"disqus_identifier",
")",
"]"
] | Executed by Sphinx.
:returns: Single DisqusNode instance with config values passed as arguments.
:rtype: list | [
"Executed",
"by",
"Sphinx",
"."
] | train | https://github.com/Robpol86/sphinxcontrib-disqus/blob/1da36bcb83b82b6493a33481c03a0956a557bd5c/sphinxcontrib/disqus.py#L91-L99 |
yougov/pmxbot | pmxbot/core.py | attach | def attach(func, params):
"""
Given a function and a namespace of possible parameters,
bind any params matching the signature of the function
to that function.
"""
sig = inspect.signature(func)
params = Projection(sig.parameters.keys(), params)
return functools.partial(func, **params) | python | def attach(func, params):
"""
Given a function and a namespace of possible parameters,
bind any params matching the signature of the function
to that function.
"""
sig = inspect.signature(func)
params = Projection(sig.parameters.keys(), params)
return functools.partial(func, **params) | [
"def",
"attach",
"(",
"func",
",",
"params",
")",
":",
"sig",
"=",
"inspect",
".",
"signature",
"(",
"func",
")",
"params",
"=",
"Projection",
"(",
"sig",
".",
"parameters",
".",
"keys",
"(",
")",
",",
"params",
")",
"return",
"functools",
".",
"part... | Given a function and a namespace of possible parameters,
bind any params matching the signature of the function
to that function. | [
"Given",
"a",
"function",
"and",
"a",
"namespace",
"of",
"possible",
"parameters",
"bind",
"any",
"params",
"matching",
"the",
"signature",
"of",
"the",
"function",
"to",
"that",
"function",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L212-L220 |
yougov/pmxbot | pmxbot/core.py | init_config | def init_config(overrides):
"""
Install the config dict as pmxbot.config, setting overrides,
and return the result.
"""
pmxbot.config = config = ConfigDict()
config.setdefault('bot_nickname', 'pmxbot')
config.update(overrides)
return config | python | def init_config(overrides):
"""
Install the config dict as pmxbot.config, setting overrides,
and return the result.
"""
pmxbot.config = config = ConfigDict()
config.setdefault('bot_nickname', 'pmxbot')
config.update(overrides)
return config | [
"def",
"init_config",
"(",
"overrides",
")",
":",
"pmxbot",
".",
"config",
"=",
"config",
"=",
"ConfigDict",
"(",
")",
"config",
".",
"setdefault",
"(",
"'bot_nickname'",
",",
"'pmxbot'",
")",
"config",
".",
"update",
"(",
"overrides",
")",
"return",
"conf... | Install the config dict as pmxbot.config, setting overrides,
and return the result. | [
"Install",
"the",
"config",
"dict",
"as",
"pmxbot",
".",
"config",
"setting",
"overrides",
"and",
"return",
"the",
"result",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L583-L591 |
yougov/pmxbot | pmxbot/core.py | initialize | def initialize(config):
"Initialize the bot with a dictionary of config items"
config = init_config(config)
_setup_logging()
_load_library_extensions()
if not Handler._registry:
raise RuntimeError("No handlers registered")
class_ = _load_bot_class()
config.setdefault('log_channels', [])
config.setdefault('... | python | def initialize(config):
"Initialize the bot with a dictionary of config items"
config = init_config(config)
_setup_logging()
_load_library_extensions()
if not Handler._registry:
raise RuntimeError("No handlers registered")
class_ = _load_bot_class()
config.setdefault('log_channels', [])
config.setdefault('... | [
"def",
"initialize",
"(",
"config",
")",
":",
"config",
"=",
"init_config",
"(",
"config",
")",
"_setup_logging",
"(",
")",
"_load_library_extensions",
"(",
")",
"if",
"not",
"Handler",
".",
"_registry",
":",
"raise",
"RuntimeError",
"(",
"\"No handlers register... | Initialize the bot with a dictionary of config items | [
"Initialize",
"the",
"bot",
"with",
"a",
"dictionary",
"of",
"config",
"items"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L594-L622 |
yougov/pmxbot | pmxbot/core.py | _load_filters | def _load_filters():
"""
Locate all entry points by the name 'pmxbot_filters', each of
which should refer to a callable(channel, msg) that must return
True for the message not to be excluded.
"""
group = 'pmxbot_filters'
eps = entrypoints.get_group_all(group=group)
return [ep.load() for ep in eps] | python | def _load_filters():
"""
Locate all entry points by the name 'pmxbot_filters', each of
which should refer to a callable(channel, msg) that must return
True for the message not to be excluded.
"""
group = 'pmxbot_filters'
eps = entrypoints.get_group_all(group=group)
return [ep.load() for ep in eps] | [
"def",
"_load_filters",
"(",
")",
":",
"group",
"=",
"'pmxbot_filters'",
"eps",
"=",
"entrypoints",
".",
"get_group_all",
"(",
"group",
"=",
"group",
")",
"return",
"[",
"ep",
".",
"load",
"(",
")",
"for",
"ep",
"in",
"eps",
"]"
] | Locate all entry points by the name 'pmxbot_filters', each of
which should refer to a callable(channel, msg) that must return
True for the message not to be excluded. | [
"Locate",
"all",
"entry",
"points",
"by",
"the",
"name",
"pmxbot_filters",
"each",
"of",
"which",
"should",
"refer",
"to",
"a",
"callable",
"(",
"channel",
"msg",
")",
"that",
"must",
"return",
"True",
"for",
"the",
"message",
"not",
"to",
"be",
"excluded"... | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L654-L662 |
yougov/pmxbot | pmxbot/core.py | Sentinel.augment_items | def augment_items(cls, items, **defaults):
"""
Iterate over the items, keeping a adding properties as supplied by
Sentinel objects encountered.
>>> from more_itertools.recipes import consume
>>> res = Sentinel.augment_items(['a', 'b', NoLog, 'c'], secret=False)
>>> res = tuple(res)
>>> consume(map(print,... | python | def augment_items(cls, items, **defaults):
"""
Iterate over the items, keeping a adding properties as supplied by
Sentinel objects encountered.
>>> from more_itertools.recipes import consume
>>> res = Sentinel.augment_items(['a', 'b', NoLog, 'c'], secret=False)
>>> res = tuple(res)
>>> consume(map(print,... | [
"def",
"augment_items",
"(",
"cls",
",",
"items",
",",
"*",
"*",
"defaults",
")",
":",
"properties",
"=",
"defaults",
"for",
"item",
"in",
"items",
":",
"# allow the Sentinel to be just the class itself, which is to be",
"# constructed with no parameters.",
"if",
"isin... | Iterate over the items, keeping a adding properties as supplied by
Sentinel objects encountered.
>>> from more_itertools.recipes import consume
>>> res = Sentinel.augment_items(['a', 'b', NoLog, 'c'], secret=False)
>>> res = tuple(res)
>>> consume(map(print, res))
a
b
c
>>> [msg.secret for msg in res... | [
"Iterate",
"over",
"the",
"items",
"keeping",
"a",
"adding",
"properties",
"as",
"supplied",
"by",
"Sentinel",
"objects",
"encountered",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L54-L96 |
yougov/pmxbot | pmxbot/core.py | Handler.find_matching | def find_matching(cls, message, channel):
"""
Yield ``cls`` subclasses that match message and channel
"""
return (
handler
for handler in cls._registry
if isinstance(handler, cls)
and handler.match(message, channel)
) | python | def find_matching(cls, message, channel):
"""
Yield ``cls`` subclasses that match message and channel
"""
return (
handler
for handler in cls._registry
if isinstance(handler, cls)
and handler.match(message, channel)
) | [
"def",
"find_matching",
"(",
"cls",
",",
"message",
",",
"channel",
")",
":",
"return",
"(",
"handler",
"for",
"handler",
"in",
"cls",
".",
"_registry",
"if",
"isinstance",
"(",
"handler",
",",
"cls",
")",
"and",
"handler",
".",
"match",
"(",
"message",
... | Yield ``cls`` subclasses that match message and channel | [
"Yield",
"cls",
"subclasses",
"that",
"match",
"message",
"and",
"channel"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L145-L154 |
yougov/pmxbot | pmxbot/core.py | Handler.decorate | def decorate(self, func):
"""
Decorate a handler function. The handler should accept keyword
parameters for values supplied by the bot, a subset of:
- client
- connection (alias for client)
- event
- channel
- nick
- rest
"""
self.func = func
self._set_implied_name()
self.register()
return f... | python | def decorate(self, func):
"""
Decorate a handler function. The handler should accept keyword
parameters for values supplied by the bot, a subset of:
- client
- connection (alias for client)
- event
- channel
- nick
- rest
"""
self.func = func
self._set_implied_name()
self.register()
return f... | [
"def",
"decorate",
"(",
"self",
",",
"func",
")",
":",
"self",
".",
"func",
"=",
"func",
"self",
".",
"_set_implied_name",
"(",
")",
"self",
".",
"register",
"(",
")",
"return",
"func"
] | Decorate a handler function. The handler should accept keyword
parameters for values supplied by the bot, a subset of:
- client
- connection (alias for client)
- event
- channel
- nick
- rest | [
"Decorate",
"a",
"handler",
"function",
".",
"The",
"handler",
"should",
"accept",
"keyword",
"parameters",
"for",
"values",
"supplied",
"by",
"the",
"bot",
"a",
"subset",
"of",
":",
"-",
"client",
"-",
"connection",
"(",
"alias",
"for",
"client",
")",
"-"... | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L165-L179 |
yougov/pmxbot | pmxbot/core.py | Handler._set_implied_name | def _set_implied_name(self):
"Allow the name of this handler to default to the function name."
if getattr(self, 'name', None) is None:
self.name = self.func.__name__
self.name = self.name.lower() | python | def _set_implied_name(self):
"Allow the name of this handler to default to the function name."
if getattr(self, 'name', None) is None:
self.name = self.func.__name__
self.name = self.name.lower() | [
"def",
"_set_implied_name",
"(",
"self",
")",
":",
"if",
"getattr",
"(",
"self",
",",
"'name'",
",",
"None",
")",
"is",
"None",
":",
"self",
".",
"name",
"=",
"self",
".",
"func",
".",
"__name__",
"self",
".",
"name",
"=",
"self",
".",
"name",
".",... | Allow the name of this handler to default to the function name. | [
"Allow",
"the",
"name",
"of",
"this",
"handler",
"to",
"default",
"to",
"the",
"function",
"name",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L181-L185 |
yougov/pmxbot | pmxbot/core.py | CommandHandler._set_doc | def _set_doc(self, func):
"""
If no doc was explicitly set, use the function's docstring, trimming
whitespace and replacing newlines with spaces.
"""
if not self.doc and func.__doc__:
self.doc = func.__doc__.strip().replace('\n', ' ') | python | def _set_doc(self, func):
"""
If no doc was explicitly set, use the function's docstring, trimming
whitespace and replacing newlines with spaces.
"""
if not self.doc and func.__doc__:
self.doc = func.__doc__.strip().replace('\n', ' ') | [
"def",
"_set_doc",
"(",
"self",
",",
"func",
")",
":",
"if",
"not",
"self",
".",
"doc",
"and",
"func",
".",
"__doc__",
":",
"self",
".",
"doc",
"=",
"func",
".",
"__doc__",
".",
"strip",
"(",
")",
".",
"replace",
"(",
"'\\n'",
",",
"' '",
")"
] | If no doc was explicitly set, use the function's docstring, trimming
whitespace and replacing newlines with spaces. | [
"If",
"no",
"doc",
"was",
"explicitly",
"set",
"use",
"the",
"function",
"s",
"docstring",
"trimming",
"whitespace",
"and",
"replacing",
"newlines",
"with",
"spaces",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L259-L265 |
yougov/pmxbot | pmxbot/core.py | Bot.allow | def allow(self, channel, message):
"""
Allow plugins to filter content.
"""
return all(
filter(channel, message)
for filter in _load_filters()
) | python | def allow(self, channel, message):
"""
Allow plugins to filter content.
"""
return all(
filter(channel, message)
for filter in _load_filters()
) | [
"def",
"allow",
"(",
"self",
",",
"channel",
",",
"message",
")",
":",
"return",
"all",
"(",
"filter",
"(",
"channel",
",",
"message",
")",
"for",
"filter",
"in",
"_load_filters",
"(",
")",
")"
] | Allow plugins to filter content. | [
"Allow",
"plugins",
"to",
"filter",
"content",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L468-L475 |
yougov/pmxbot | pmxbot/core.py | Bot._handle_output | def _handle_output(self, channel, output):
"""
Given an initial channel and a sequence of messages or sentinels,
output the messages.
"""
augmented = Sentinel.augment_items(output, channel=channel, secret=False)
for message in augmented:
self.out(message.channel, message, not message.secret) | python | def _handle_output(self, channel, output):
"""
Given an initial channel and a sequence of messages or sentinels,
output the messages.
"""
augmented = Sentinel.augment_items(output, channel=channel, secret=False)
for message in augmented:
self.out(message.channel, message, not message.secret) | [
"def",
"_handle_output",
"(",
"self",
",",
"channel",
",",
"output",
")",
":",
"augmented",
"=",
"Sentinel",
".",
"augment_items",
"(",
"output",
",",
"channel",
"=",
"channel",
",",
"secret",
"=",
"False",
")",
"for",
"message",
"in",
"augmented",
":",
... | Given an initial channel and a sequence of messages or sentinels,
output the messages. | [
"Given",
"an",
"initial",
"channel",
"and",
"a",
"sequence",
"of",
"messages",
"or",
"sentinels",
"output",
"the",
"messages",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L492-L499 |
yougov/pmxbot | pmxbot/core.py | Bot.handle_action | def handle_action(self, channel, nick, msg):
"Core message parser and dispatcher"
messages = ()
for handler in Handler.find_matching(msg, channel):
exception_handler = functools.partial(
self._handle_exception,
handler=handler,
)
rest = handler.process(msg)
client = connection = event = None
... | python | def handle_action(self, channel, nick, msg):
"Core message parser and dispatcher"
messages = ()
for handler in Handler.find_matching(msg, channel):
exception_handler = functools.partial(
self._handle_exception,
handler=handler,
)
rest = handler.process(msg)
client = connection = event = None
... | [
"def",
"handle_action",
"(",
"self",
",",
"channel",
",",
"nick",
",",
"msg",
")",
":",
"messages",
"=",
"(",
")",
"for",
"handler",
"in",
"Handler",
".",
"find_matching",
"(",
"msg",
",",
"channel",
")",
":",
"exception_handler",
"=",
"functools",
".",
... | Core message parser and dispatcher | [
"Core",
"message",
"parser",
"and",
"dispatcher"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L501-L520 |
yougov/pmxbot | pmxbot/core.py | Bot.handle_scheduled | def handle_scheduled(self, target):
"""
target is a Handler or simple callable
"""
if not isinstance(target, Handler):
return target()
return self._handle_scheduled(target) | python | def handle_scheduled(self, target):
"""
target is a Handler or simple callable
"""
if not isinstance(target, Handler):
return target()
return self._handle_scheduled(target) | [
"def",
"handle_scheduled",
"(",
"self",
",",
"target",
")",
":",
"if",
"not",
"isinstance",
"(",
"target",
",",
"Handler",
")",
":",
"return",
"target",
"(",
")",
"return",
"self",
".",
"_handle_scheduled",
"(",
"target",
")"
] | target is a Handler or simple callable | [
"target",
"is",
"a",
"Handler",
"or",
"simple",
"callable"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/core.py#L526-L533 |
yougov/pmxbot | pmxbot/rolls.py | log_leave | def log_leave(event, nick, channel):
"""
Log a quit or part event.
"""
if channel not in pmxbot.config.log_channels:
return
ParticipantLogger.store.log(nick, channel, event.type) | python | def log_leave(event, nick, channel):
"""
Log a quit or part event.
"""
if channel not in pmxbot.config.log_channels:
return
ParticipantLogger.store.log(nick, channel, event.type) | [
"def",
"log_leave",
"(",
"event",
",",
"nick",
",",
"channel",
")",
":",
"if",
"channel",
"not",
"in",
"pmxbot",
".",
"config",
".",
"log_channels",
":",
"return",
"ParticipantLogger",
".",
"store",
".",
"log",
"(",
"nick",
",",
"channel",
",",
"event",
... | Log a quit or part event. | [
"Log",
"a",
"quit",
"or",
"part",
"event",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/rolls.py#L43-L49 |
yougov/pmxbot | pmxbot/karma.py | karma | def karma(nick, rest):
"Return or change the karma value for some(one|thing)"
karmee = rest.strip('++').strip('--').strip('~~')
if '++' in rest:
Karma.store.change(karmee, 1)
elif '--' in rest:
Karma.store.change(karmee, -1)
elif '~~' in rest:
change = random.choice([-1, 0, 1])
Karma.store.change(karmee, c... | python | def karma(nick, rest):
"Return or change the karma value for some(one|thing)"
karmee = rest.strip('++').strip('--').strip('~~')
if '++' in rest:
Karma.store.change(karmee, 1)
elif '--' in rest:
Karma.store.change(karmee, -1)
elif '~~' in rest:
change = random.choice([-1, 0, 1])
Karma.store.change(karmee, c... | [
"def",
"karma",
"(",
"nick",
",",
"rest",
")",
":",
"karmee",
"=",
"rest",
".",
"strip",
"(",
"'++'",
")",
".",
"strip",
"(",
"'--'",
")",
".",
"strip",
"(",
"'~~'",
")",
"if",
"'++'",
"in",
"rest",
":",
"Karma",
".",
"store",
".",
"change",
"(... | Return or change the karma value for some(one|thing) | [
"Return",
"or",
"change",
"the",
"karma",
"value",
"for",
"some",
"(",
"one|thing",
")"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/karma.py#L271-L301 |
yougov/pmxbot | pmxbot/karma.py | top10 | def top10(rest):
"""
Return the top n (default 10) highest entities by Karmic value.
Use negative numbers for the bottom N.
"""
if rest:
topn = int(rest)
else:
topn = 10
selection = Karma.store.list(topn)
res = ' '.join('(%s: %s)' % (', '.join(n), k) for n, k in selection)
return res | python | def top10(rest):
"""
Return the top n (default 10) highest entities by Karmic value.
Use negative numbers for the bottom N.
"""
if rest:
topn = int(rest)
else:
topn = 10
selection = Karma.store.list(topn)
res = ' '.join('(%s: %s)' % (', '.join(n), k) for n, k in selection)
return res | [
"def",
"top10",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"topn",
"=",
"int",
"(",
"rest",
")",
"else",
":",
"topn",
"=",
"10",
"selection",
"=",
"Karma",
".",
"store",
".",
"list",
"(",
"topn",
")",
"res",
"=",
"' '",
".",
"join",
"(",
"'(%s: ... | Return the top n (default 10) highest entities by Karmic value.
Use negative numbers for the bottom N. | [
"Return",
"the",
"top",
"n",
"(",
"default",
"10",
")",
"highest",
"entities",
"by",
"Karmic",
"value",
".",
"Use",
"negative",
"numbers",
"for",
"the",
"bottom",
"N",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/karma.py#L305-L316 |
yougov/pmxbot | pmxbot/karma.py | Karma.link | def link(self, thing1, thing2):
"""
Link thing1 and thing2, adding the karma of each into
a single entry.
If any thing does not exist, it is created.
"""
thing1 = thing1.strip().lower()
thing2 = thing2.strip().lower()
if thing1 == thing2:
raise SameName("Attempted to link two of the same name")
sel... | python | def link(self, thing1, thing2):
"""
Link thing1 and thing2, adding the karma of each into
a single entry.
If any thing does not exist, it is created.
"""
thing1 = thing1.strip().lower()
thing2 = thing2.strip().lower()
if thing1 == thing2:
raise SameName("Attempted to link two of the same name")
sel... | [
"def",
"link",
"(",
"self",
",",
"thing1",
",",
"thing2",
")",
":",
"thing1",
"=",
"thing1",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"thing2",
"=",
"thing2",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"if",
"thing1",
"==",
"thing2",
... | Link thing1 and thing2, adding the karma of each into
a single entry.
If any thing does not exist, it is created. | [
"Link",
"thing1",
"and",
"thing2",
"adding",
"the",
"karma",
"of",
"each",
"into",
"a",
"single",
"entry",
".",
"If",
"any",
"thing",
"does",
"not",
"exist",
"it",
"is",
"created",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/karma.py#L27-L39 |
yougov/pmxbot | pmxbot/karma.py | SQLiteKarma._get | def _get(self, id):
"Return keys and value for karma id"
VALUE_SQL = "SELECT karmavalue from karma_values where karmaid = ?"
KEYS_SQL = "SELECT karmakey from karma_keys where karmaid = ?"
value = self.db.execute(VALUE_SQL, [id]).fetchall()[0][0]
keys_cur = self.db.execute(KEYS_SQL, [id]).fetchall()
keys = s... | python | def _get(self, id):
"Return keys and value for karma id"
VALUE_SQL = "SELECT karmavalue from karma_values where karmaid = ?"
KEYS_SQL = "SELECT karmakey from karma_keys where karmaid = ?"
value = self.db.execute(VALUE_SQL, [id]).fetchall()[0][0]
keys_cur = self.db.execute(KEYS_SQL, [id]).fetchall()
keys = s... | [
"def",
"_get",
"(",
"self",
",",
"id",
")",
":",
"VALUE_SQL",
"=",
"\"SELECT karmavalue from karma_values where karmaid = ?\"",
"KEYS_SQL",
"=",
"\"SELECT karmakey from karma_keys where karmaid = ?\"",
"value",
"=",
"self",
".",
"db",
".",
"execute",
"(",
"VALUE_SQL",
"... | Return keys and value for karma id | [
"Return",
"keys",
"and",
"value",
"for",
"karma",
"id"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/karma.py#L162-L169 |
yougov/pmxbot | pmxbot/karma.py | MongoDBKarma.repair_duplicate_names | def repair_duplicate_names(self):
"""
Prior to 1101.1.1, pmxbot would incorrectly create new karma records
for individuals with multiple names.
This routine corrects those records.
"""
for name in self._all_names():
cur = self.db.find({'names': name})
main_doc = next(cur)
for duplicate in cur:
... | python | def repair_duplicate_names(self):
"""
Prior to 1101.1.1, pmxbot would incorrectly create new karma records
for individuals with multiple names.
This routine corrects those records.
"""
for name in self._all_names():
cur = self.db.find({'names': name})
main_doc = next(cur)
for duplicate in cur:
... | [
"def",
"repair_duplicate_names",
"(",
"self",
")",
":",
"for",
"name",
"in",
"self",
".",
"_all_names",
"(",
")",
":",
"cur",
"=",
"self",
".",
"db",
".",
"find",
"(",
"{",
"'names'",
":",
"name",
"}",
")",
"main_doc",
"=",
"next",
"(",
"cur",
")",... | Prior to 1101.1.1, pmxbot would incorrectly create new karma records
for individuals with multiple names.
This routine corrects those records. | [
"Prior",
"to",
"1101",
".",
"1",
".",
"1",
"pmxbot",
"would",
"incorrectly",
"create",
"new",
"karma",
"records",
"for",
"individuals",
"with",
"multiple",
"names",
".",
"This",
"routine",
"corrects",
"those",
"records",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/karma.py#L251-L267 |
yougov/pmxbot | pmxbot/notify.py | donotify | def donotify(nick, rest):
"notify <nick> <message>"
opts = rest.split(' ')
to = opts[0]
Notify.store.notify(nick, to, ' '.join(opts[1:]))
return "Will do!" | python | def donotify(nick, rest):
"notify <nick> <message>"
opts = rest.split(' ')
to = opts[0]
Notify.store.notify(nick, to, ' '.join(opts[1:]))
return "Will do!" | [
"def",
"donotify",
"(",
"nick",
",",
"rest",
")",
":",
"opts",
"=",
"rest",
".",
"split",
"(",
"' '",
")",
"to",
"=",
"opts",
"[",
"0",
"]",
"Notify",
".",
"store",
".",
"notify",
"(",
"nick",
",",
"to",
",",
"' '",
".",
"join",
"(",
"opts",
... | notify <nick> <message> | [
"notify",
"<nick",
">",
"<message",
">"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/notify.py#L93-L98 |
yougov/pmxbot | pmxbot/notify.py | SQLiteNotify.lookup | def lookup(self, nick):
query = """
SELECT fromnick, message, notifytime, notifyid
FROM notify WHERE tonick = ?
"""
''' Ugly, but will work with sqlite3 or pysqlite2 '''
messages = [
{
'fromnick': x[0],
'message': x[1],
'notifytime': x[2],
'notifyid': x[3],
}
for x in self.db.exec... | python | def lookup(self, nick):
query = """
SELECT fromnick, message, notifytime, notifyid
FROM notify WHERE tonick = ?
"""
''' Ugly, but will work with sqlite3 or pysqlite2 '''
messages = [
{
'fromnick': x[0],
'message': x[1],
'notifytime': x[2],
'notifyid': x[3],
}
for x in self.db.exec... | [
"def",
"lookup",
"(",
"self",
",",
"nick",
")",
":",
"query",
"=",
"\"\"\"\n\t\t\tSELECT fromnick, message, notifytime, notifyid\n\t\t\tFROM notify WHERE tonick = ?\n\t\t\"\"\"",
"messages",
"=",
"[",
"{",
"'fromnick'",
":",
"x",
"[",
"0",
"]",
",",
"'message'",
":",
... | Ugly, but will work with sqlite3 or pysqlite2 | [
"Ugly",
"but",
"will",
"work",
"with",
"sqlite3",
"or",
"pysqlite2"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/notify.py#L36-L58 |
yougov/pmxbot | pmxbot/commands.py | google | def google(rest):
"Look up a phrase on google"
API_URL = 'https://www.googleapis.com/customsearch/v1?'
try:
key = pmxbot.config['Google API key']
except KeyError:
return "Configure 'Google API key' in config"
# Use a custom search that searches everything normally
# http://stackoverflow.com/a/11206266/70170
... | python | def google(rest):
"Look up a phrase on google"
API_URL = 'https://www.googleapis.com/customsearch/v1?'
try:
key = pmxbot.config['Google API key']
except KeyError:
return "Configure 'Google API key' in config"
# Use a custom search that searches everything normally
# http://stackoverflow.com/a/11206266/70170
... | [
"def",
"google",
"(",
"rest",
")",
":",
"API_URL",
"=",
"'https://www.googleapis.com/customsearch/v1?'",
"try",
":",
"key",
"=",
"pmxbot",
".",
"config",
"[",
"'Google API key'",
"]",
"except",
"KeyError",
":",
"return",
"\"Configure 'Google API key' in config\"",
"# ... | Look up a phrase on google | [
"Look",
"up",
"a",
"phrase",
"on",
"google"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L28-L51 |
yougov/pmxbot | pmxbot/commands.py | boo | def boo(rest):
"Boo someone"
slapee = rest
karma.Karma.store.change(slapee, -1)
return "/me BOOO %s!!! BOOO!!!" % slapee | python | def boo(rest):
"Boo someone"
slapee = rest
karma.Karma.store.change(slapee, -1)
return "/me BOOO %s!!! BOOO!!!" % slapee | [
"def",
"boo",
"(",
"rest",
")",
":",
"slapee",
"=",
"rest",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"slapee",
",",
"-",
"1",
")",
"return",
"\"/me BOOO %s!!! BOOO!!!\"",
"%",
"slapee"
] | Boo someone | [
"Boo",
"someone"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L73-L77 |
yougov/pmxbot | pmxbot/commands.py | troutslap | def troutslap(rest):
"Slap some(one|thing) with a fish"
slapee = rest
karma.Karma.store.change(slapee, -1)
return "/me slaps %s around a bit with a large trout" % slapee | python | def troutslap(rest):
"Slap some(one|thing) with a fish"
slapee = rest
karma.Karma.store.change(slapee, -1)
return "/me slaps %s around a bit with a large trout" % slapee | [
"def",
"troutslap",
"(",
"rest",
")",
":",
"slapee",
"=",
"rest",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"slapee",
",",
"-",
"1",
")",
"return",
"\"/me slaps %s around a bit with a large trout\"",
"%",
"slapee"
] | Slap some(one|thing) with a fish | [
"Slap",
"some",
"(",
"one|thing",
")",
"with",
"a",
"fish"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L81-L85 |
yougov/pmxbot | pmxbot/commands.py | keelhaul | def keelhaul(rest):
"Inflict great pain and embarassment on some(one|thing)"
keelee = rest
karma.Karma.store.change(keelee, -1)
return (
"/me straps %s to a dirty rope, tosses 'em overboard and pulls "
"with great speed. Yarrr!" % keelee) | python | def keelhaul(rest):
"Inflict great pain and embarassment on some(one|thing)"
keelee = rest
karma.Karma.store.change(keelee, -1)
return (
"/me straps %s to a dirty rope, tosses 'em overboard and pulls "
"with great speed. Yarrr!" % keelee) | [
"def",
"keelhaul",
"(",
"rest",
")",
":",
"keelee",
"=",
"rest",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"keelee",
",",
"-",
"1",
")",
"return",
"(",
"\"/me straps %s to a dirty rope, tosses 'em overboard and pulls \"",
"\"with great speed. Yarrr!\"... | Inflict great pain and embarassment on some(one|thing) | [
"Inflict",
"great",
"pain",
"and",
"embarassment",
"on",
"some",
"(",
"one|thing",
")"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L89-L95 |
yougov/pmxbot | pmxbot/commands.py | annoy | def annoy():
"Annoy everyone with meaningless banter"
def a1():
yield 'OOOOOOOHHH, WHAT DO YOU DO WITH A DRUNKEN SAILOR'
yield 'WHAT DO YOU DO WITH A DRUNKEN SAILOR'
yield "WHAT DO YOU DO WITH A DRUNKEN SAILOR, EARLY IN THE MORNIN'?"
def a2():
yield "I'M HENRY THE EIGHTH I AM"
yield "HENRY THE EIGHTH I AM... | python | def annoy():
"Annoy everyone with meaningless banter"
def a1():
yield 'OOOOOOOHHH, WHAT DO YOU DO WITH A DRUNKEN SAILOR'
yield 'WHAT DO YOU DO WITH A DRUNKEN SAILOR'
yield "WHAT DO YOU DO WITH A DRUNKEN SAILOR, EARLY IN THE MORNIN'?"
def a2():
yield "I'M HENRY THE EIGHTH I AM"
yield "HENRY THE EIGHTH I AM... | [
"def",
"annoy",
"(",
")",
":",
"def",
"a1",
"(",
")",
":",
"yield",
"'OOOOOOOHHH, WHAT DO YOU DO WITH A DRUNKEN SAILOR'",
"yield",
"'WHAT DO YOU DO WITH A DRUNKEN SAILOR'",
"yield",
"\"WHAT DO YOU DO WITH A DRUNKEN SAILOR, EARLY IN THE MORNIN'?\"",
"def",
"a2",
"(",
")",
":",... | Annoy everyone with meaningless banter | [
"Annoy",
"everyone",
"with",
"meaningless",
"banter"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L99-L133 |
yougov/pmxbot | pmxbot/commands.py | rubberstamp | def rubberstamp(rest):
"Approve something"
parts = ["Bad credit? No credit? Slow credit?"]
rest = rest.strip()
if rest:
parts.append("%s is" % rest)
karma.Karma.store.change(rest, 1)
parts.append("APPROVED!")
return " ".join(parts) | python | def rubberstamp(rest):
"Approve something"
parts = ["Bad credit? No credit? Slow credit?"]
rest = rest.strip()
if rest:
parts.append("%s is" % rest)
karma.Karma.store.change(rest, 1)
parts.append("APPROVED!")
return " ".join(parts) | [
"def",
"rubberstamp",
"(",
"rest",
")",
":",
"parts",
"=",
"[",
"\"Bad credit? No credit? Slow credit?\"",
"]",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"rest",
":",
"parts",
".",
"append",
"(",
"\"%s is\"",
"%",
"rest",
")",
"karma",
".",
"Kar... | Approve something | [
"Approve",
"something"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L162-L170 |
yougov/pmxbot | pmxbot/commands.py | cheer | def cheer(rest):
"Cheer for something"
if rest:
karma.Karma.store.change(rest, 1)
return "/me cheers for %s!" % rest
karma.Karma.store.change('the day', 1)
return "/me cheers!" | python | def cheer(rest):
"Cheer for something"
if rest:
karma.Karma.store.change(rest, 1)
return "/me cheers for %s!" % rest
karma.Karma.store.change('the day', 1)
return "/me cheers!" | [
"def",
"cheer",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"rest",
",",
"1",
")",
"return",
"\"/me cheers for %s!\"",
"%",
"rest",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"'the ... | Cheer for something | [
"Cheer",
"for",
"something"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L174-L180 |
yougov/pmxbot | pmxbot/commands.py | golfclap | def golfclap(rest):
"Clap for something"
clapv = random.choice(phrases.clapvl)
adv = random.choice(phrases.advl)
adj = random.choice(phrases.adjl)
if rest:
clapee = rest.strip()
karma.Karma.store.change(clapee, 1)
return "/me claps %s for %s, %s %s." % (clapv, rest, adv, adj)
return "/me claps %s, %s %s." %... | python | def golfclap(rest):
"Clap for something"
clapv = random.choice(phrases.clapvl)
adv = random.choice(phrases.advl)
adj = random.choice(phrases.adjl)
if rest:
clapee = rest.strip()
karma.Karma.store.change(clapee, 1)
return "/me claps %s for %s, %s %s." % (clapv, rest, adv, adj)
return "/me claps %s, %s %s." %... | [
"def",
"golfclap",
"(",
"rest",
")",
":",
"clapv",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"clapvl",
")",
"adv",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"advl",
")",
"adj",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"a... | Clap for something | [
"Clap",
"for",
"something"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L184-L193 |
yougov/pmxbot | pmxbot/commands.py | featurecreep | def featurecreep():
"Generate feature creep (P+C http://www.dack.com/web/bullshit.html)"
verb = random.choice(phrases.fcverbs).capitalize()
adjective = random.choice(phrases.fcadjectives)
noun = random.choice(phrases.fcnouns)
return '%s %s %s!' % (verb, adjective, noun) | python | def featurecreep():
"Generate feature creep (P+C http://www.dack.com/web/bullshit.html)"
verb = random.choice(phrases.fcverbs).capitalize()
adjective = random.choice(phrases.fcadjectives)
noun = random.choice(phrases.fcnouns)
return '%s %s %s!' % (verb, adjective, noun) | [
"def",
"featurecreep",
"(",
")",
":",
"verb",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"fcverbs",
")",
".",
"capitalize",
"(",
")",
"adjective",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"fcadjectives",
")",
"noun",
"=",
"random",
".... | Generate feature creep (P+C http://www.dack.com/web/bullshit.html) | [
"Generate",
"feature",
"creep",
"(",
"P",
"+",
"C",
"http",
":",
"//",
"www",
".",
"dack",
".",
"com",
"/",
"web",
"/",
"bullshit",
".",
"html",
")"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L197-L202 |
yougov/pmxbot | pmxbot/commands.py | job | def job():
"Generate a job title, http://www.cubefigures.com/job.html"
j1 = random.choice(phrases.jobs1)
j2 = random.choice(phrases.jobs2)
j3 = random.choice(phrases.jobs3)
return '%s %s %s' % (j1, j2, j3) | python | def job():
"Generate a job title, http://www.cubefigures.com/job.html"
j1 = random.choice(phrases.jobs1)
j2 = random.choice(phrases.jobs2)
j3 = random.choice(phrases.jobs3)
return '%s %s %s' % (j1, j2, j3) | [
"def",
"job",
"(",
")",
":",
"j1",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"jobs1",
")",
"j2",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"jobs2",
")",
"j3",
"=",
"random",
".",
"choice",
"(",
"phrases",
".",
"jobs3",
")",
"ret... | Generate a job title, http://www.cubefigures.com/job.html | [
"Generate",
"a",
"job",
"title",
"http",
":",
"//",
"www",
".",
"cubefigures",
".",
"com",
"/",
"job",
".",
"html"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L206-L211 |
yougov/pmxbot | pmxbot/commands.py | oregontrail | def oregontrail(channel, nick, rest):
"It's edutainment!"
rest = rest.strip()
if rest:
who = rest.strip()
else:
who = random.choice([nick, channel, 'pmxbot'])
action = random.choice(phrases.otrail_actions)
if action in ('has', 'has died from'):
issue = random.choice(phrases.otrail_issues)
text = '%s %s %s... | python | def oregontrail(channel, nick, rest):
"It's edutainment!"
rest = rest.strip()
if rest:
who = rest.strip()
else:
who = random.choice([nick, channel, 'pmxbot'])
action = random.choice(phrases.otrail_actions)
if action in ('has', 'has died from'):
issue = random.choice(phrases.otrail_issues)
text = '%s %s %s... | [
"def",
"oregontrail",
"(",
"channel",
",",
"nick",
",",
"rest",
")",
":",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"rest",
":",
"who",
"=",
"rest",
".",
"strip",
"(",
")",
"else",
":",
"who",
"=",
"random",
".",
"choice",
"(",
"[",
"n... | It's edutainment! | [
"It",
"s",
"edutainment!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L232-L245 |
yougov/pmxbot | pmxbot/commands.py | zinger | def zinger(rest):
"ZING!"
name = 'you'
if rest:
name = rest.strip()
karma.Karma.store.change(name, -1)
return "OH MAN!!! %s TOTALLY GOT ZING'D!" % (name.upper()) | python | def zinger(rest):
"ZING!"
name = 'you'
if rest:
name = rest.strip()
karma.Karma.store.change(name, -1)
return "OH MAN!!! %s TOTALLY GOT ZING'D!" % (name.upper()) | [
"def",
"zinger",
"(",
"rest",
")",
":",
"name",
"=",
"'you'",
"if",
"rest",
":",
"name",
"=",
"rest",
".",
"strip",
"(",
")",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"name",
",",
"-",
"1",
")",
"return",
"\"OH MAN!!! %s TOTALLY GOT Z... | ZING! | [
"ZING!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L249-L255 |
yougov/pmxbot | pmxbot/commands.py | motivate | def motivate(channel, rest):
"Motivate someone"
if rest:
r = rest.strip()
m = re.match(r'^(.+)\s*\bfor\b\s*(.+)$', r)
if m:
r = m.groups()[0].strip()
else:
r = channel
karma.Karma.store.change(r, 1)
return "you're doing good work, %s!" % r | python | def motivate(channel, rest):
"Motivate someone"
if rest:
r = rest.strip()
m = re.match(r'^(.+)\s*\bfor\b\s*(.+)$', r)
if m:
r = m.groups()[0].strip()
else:
r = channel
karma.Karma.store.change(r, 1)
return "you're doing good work, %s!" % r | [
"def",
"motivate",
"(",
"channel",
",",
"rest",
")",
":",
"if",
"rest",
":",
"r",
"=",
"rest",
".",
"strip",
"(",
")",
"m",
"=",
"re",
".",
"match",
"(",
"r'^(.+)\\s*\\bfor\\b\\s*(.+)$'",
",",
"r",
")",
"if",
"m",
":",
"r",
"=",
"m",
".",
"groups... | Motivate someone | [
"Motivate",
"someone"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L259-L269 |
yougov/pmxbot | pmxbot/commands.py | demotivate | def demotivate(channel, rest):
"Demotivate someone"
if rest:
r = rest.strip()
else:
r = channel
karma.Karma.store.change(r, -1)
return "you're doing horrible work, %s!" % r | python | def demotivate(channel, rest):
"Demotivate someone"
if rest:
r = rest.strip()
else:
r = channel
karma.Karma.store.change(r, -1)
return "you're doing horrible work, %s!" % r | [
"def",
"demotivate",
"(",
"channel",
",",
"rest",
")",
":",
"if",
"rest",
":",
"r",
"=",
"rest",
".",
"strip",
"(",
")",
"else",
":",
"r",
"=",
"channel",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"r",
",",
"-",
"1",
")",
"return... | Demotivate someone | [
"Demotivate",
"someone"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L292-L299 |
yougov/pmxbot | pmxbot/commands.py | eball | def eball(rest):
"Ask the magic 8ball a question"
try:
url = 'https://8ball.delegator.com/magic/JSON/'
url += rest
result = requests.get(url).json()['magic']['answer']
except Exception:
result = util.wchoice(phrases.ball8_opts)
return result | python | def eball(rest):
"Ask the magic 8ball a question"
try:
url = 'https://8ball.delegator.com/magic/JSON/'
url += rest
result = requests.get(url).json()['magic']['answer']
except Exception:
result = util.wchoice(phrases.ball8_opts)
return result | [
"def",
"eball",
"(",
"rest",
")",
":",
"try",
":",
"url",
"=",
"'https://8ball.delegator.com/magic/JSON/'",
"url",
"+=",
"rest",
"result",
"=",
"requests",
".",
"get",
"(",
"url",
")",
".",
"json",
"(",
")",
"[",
"'magic'",
"]",
"[",
"'answer'",
"]",
"... | Ask the magic 8ball a question | [
"Ask",
"the",
"magic",
"8ball",
"a",
"question"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L303-L311 |
yougov/pmxbot | pmxbot/commands.py | roll | def roll(rest, nick):
"Roll a die, default = 100."
if rest:
rest = rest.strip()
die = int(rest)
else:
die = 100
myroll = random.randint(1, die)
return "%s rolls %s" % (nick, myroll) | python | def roll(rest, nick):
"Roll a die, default = 100."
if rest:
rest = rest.strip()
die = int(rest)
else:
die = 100
myroll = random.randint(1, die)
return "%s rolls %s" % (nick, myroll) | [
"def",
"roll",
"(",
"rest",
",",
"nick",
")",
":",
"if",
"rest",
":",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"die",
"=",
"int",
"(",
"rest",
")",
"else",
":",
"die",
"=",
"100",
"myroll",
"=",
"random",
".",
"randint",
"(",
"1",
",",
"d... | Roll a die, default = 100. | [
"Roll",
"a",
"die",
"default",
"=",
"100",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L321-L329 |
yougov/pmxbot | pmxbot/commands.py | ticker | def ticker(rest):
"Look up a ticker symbol's current trading value"
ticker = rest.upper()
# let's use Yahoo's nifty csv facility, and pull last time/price both
symbol = 's'
last_trade_price = 'l1'
last_trade_time = 't1'
change_percent = 'p2'
format = ''.join((symbol, last_trade_time, last_trade_price, change_pe... | python | def ticker(rest):
"Look up a ticker symbol's current trading value"
ticker = rest.upper()
# let's use Yahoo's nifty csv facility, and pull last time/price both
symbol = 's'
last_trade_price = 'l1'
last_trade_time = 't1'
change_percent = 'p2'
format = ''.join((symbol, last_trade_time, last_trade_price, change_pe... | [
"def",
"ticker",
"(",
"rest",
")",
":",
"ticker",
"=",
"rest",
".",
"upper",
"(",
")",
"# let's use Yahoo's nifty csv facility, and pull last time/price both",
"symbol",
"=",
"'s'",
"last_trade_price",
"=",
"'l1'",
"last_trade_time",
"=",
"'t1'",
"change_percent",
"="... | Look up a ticker symbol's current trading value | [
"Look",
"up",
"a",
"ticker",
"symbol",
"s",
"current",
"trading",
"value"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L347-L364 |
yougov/pmxbot | pmxbot/commands.py | pick | def pick(rest):
"Pick between a few options"
question = rest.strip()
choices = util.splitem(question)
if len(choices) == 1:
return "I can't pick if you give me only one choice!"
else:
pick = random.choice(choices)
certainty = random.sample(phrases.certainty_opts, 1)[0]
return "%s... %s %s" % (pick, certain... | python | def pick(rest):
"Pick between a few options"
question = rest.strip()
choices = util.splitem(question)
if len(choices) == 1:
return "I can't pick if you give me only one choice!"
else:
pick = random.choice(choices)
certainty = random.sample(phrases.certainty_opts, 1)[0]
return "%s... %s %s" % (pick, certain... | [
"def",
"pick",
"(",
"rest",
")",
":",
"question",
"=",
"rest",
".",
"strip",
"(",
")",
"choices",
"=",
"util",
".",
"splitem",
"(",
"question",
")",
"if",
"len",
"(",
"choices",
")",
"==",
"1",
":",
"return",
"\"I can't pick if you give me only one choice!... | Pick between a few options | [
"Pick",
"between",
"a",
"few",
"options"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L368-L377 |
yougov/pmxbot | pmxbot/commands.py | lunch | def lunch(rest):
"Pick where to go to lunch"
rs = rest.strip()
if not rs:
return "Give me an area and I'll pick a place: (%s)" % (
', '.join(list(pmxbot.config.lunch_choices)))
if rs not in pmxbot.config.lunch_choices:
return "I didn't recognize that area; here's what i have: (%s)" % (
', '.join(list(pmxb... | python | def lunch(rest):
"Pick where to go to lunch"
rs = rest.strip()
if not rs:
return "Give me an area and I'll pick a place: (%s)" % (
', '.join(list(pmxbot.config.lunch_choices)))
if rs not in pmxbot.config.lunch_choices:
return "I didn't recognize that area; here's what i have: (%s)" % (
', '.join(list(pmxb... | [
"def",
"lunch",
"(",
"rest",
")",
":",
"rs",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"not",
"rs",
":",
"return",
"\"Give me an area and I'll pick a place: (%s)\"",
"%",
"(",
"', '",
".",
"join",
"(",
"list",
"(",
"pmxbot",
".",
"config",
".",
"lunch_c... | Pick where to go to lunch | [
"Pick",
"where",
"to",
"go",
"to",
"lunch"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L381-L391 |
yougov/pmxbot | pmxbot/commands.py | password | def password(rest):
"""
Generate a random password, similar to
http://www.pctools.com/guides/password
"""
charsets = [
string.ascii_lowercase,
string.ascii_uppercase,
string.digits,
string.punctuation,
]
passwd = []
try:
length = rest.strip() or 12
length = int(length)
except ValueError:
return ... | python | def password(rest):
"""
Generate a random password, similar to
http://www.pctools.com/guides/password
"""
charsets = [
string.ascii_lowercase,
string.ascii_uppercase,
string.digits,
string.punctuation,
]
passwd = []
try:
length = rest.strip() or 12
length = int(length)
except ValueError:
return ... | [
"def",
"password",
"(",
"rest",
")",
":",
"charsets",
"=",
"[",
"string",
".",
"ascii_lowercase",
",",
"string",
".",
"ascii_uppercase",
",",
"string",
".",
"digits",
",",
"string",
".",
"punctuation",
",",
"]",
"passwd",
"=",
"[",
"]",
"try",
":",
"le... | Generate a random password, similar to
http://www.pctools.com/guides/password | [
"Generate",
"a",
"random",
"password",
"similar",
"to",
"http",
":",
"//",
"www",
".",
"pctools",
".",
"com",
"/",
"guides",
"/",
"password"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L395-L423 |
yougov/pmxbot | pmxbot/commands.py | insult | def insult(rest):
"Generate a random insult from datahamster"
# not supplying any style will automatically redirect to a random
url = 'http://autoinsult.datahamster.com/'
ins_type = random.randrange(4)
ins_url = url + "?style={ins_type}".format(**locals())
insre = re.compile('<div class="insult" id="insult">(.*?)... | python | def insult(rest):
"Generate a random insult from datahamster"
# not supplying any style will automatically redirect to a random
url = 'http://autoinsult.datahamster.com/'
ins_type = random.randrange(4)
ins_url = url + "?style={ins_type}".format(**locals())
insre = re.compile('<div class="insult" id="insult">(.*?)... | [
"def",
"insult",
"(",
"rest",
")",
":",
"# not supplying any style will automatically redirect to a random",
"url",
"=",
"'http://autoinsult.datahamster.com/'",
"ins_type",
"=",
"random",
".",
"randrange",
"(",
"4",
")",
"ins_url",
"=",
"url",
"+",
"\"?style={ins_type}\""... | Generate a random insult from datahamster | [
"Generate",
"a",
"random",
"insult",
"from",
"datahamster"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L427-L450 |
yougov/pmxbot | pmxbot/commands.py | compliment | def compliment(rest):
"""
Generate a random compliment from
http://www.madsci.org/cgi-bin/cgiwrap/~lynn/jardin/SCG
"""
compurl = 'http://www.madsci.org/cgi-bin/cgiwrap/~lynn/jardin/SCG'
comphtml = ''.join([i.decode() for i in urllib.request.urlopen(compurl)])
compmark1 = '<h2>\n\n'
compmark2 = '\n</h2>'
compli... | python | def compliment(rest):
"""
Generate a random compliment from
http://www.madsci.org/cgi-bin/cgiwrap/~lynn/jardin/SCG
"""
compurl = 'http://www.madsci.org/cgi-bin/cgiwrap/~lynn/jardin/SCG'
comphtml = ''.join([i.decode() for i in urllib.request.urlopen(compurl)])
compmark1 = '<h2>\n\n'
compmark2 = '\n</h2>'
compli... | [
"def",
"compliment",
"(",
"rest",
")",
":",
"compurl",
"=",
"'http://www.madsci.org/cgi-bin/cgiwrap/~lynn/jardin/SCG'",
"comphtml",
"=",
"''",
".",
"join",
"(",
"[",
"i",
".",
"decode",
"(",
")",
"for",
"i",
"in",
"urllib",
".",
"request",
".",
"urlopen",
"(... | Generate a random compliment from
http://www.madsci.org/cgi-bin/cgiwrap/~lynn/jardin/SCG | [
"Generate",
"a",
"random",
"compliment",
"from",
"http",
":",
"//",
"www",
".",
"madsci",
".",
"org",
"/",
"cgi",
"-",
"bin",
"/",
"cgiwrap",
"/",
"~lynn",
"/",
"jardin",
"/",
"SCG"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L454-L477 |
yougov/pmxbot | pmxbot/commands.py | emer_comp | def emer_comp(rest):
"Return a random compliment from http://emergencycompliment.com/"
comps = util.load_emergency_compliments()
compliment = random.choice(comps)
if rest:
complimentee = rest.strip()
karma.Karma.store.change(complimentee, 1)
return "%s: %s" % (complimentee, compliment)
return compliment | python | def emer_comp(rest):
"Return a random compliment from http://emergencycompliment.com/"
comps = util.load_emergency_compliments()
compliment = random.choice(comps)
if rest:
complimentee = rest.strip()
karma.Karma.store.change(complimentee, 1)
return "%s: %s" % (complimentee, compliment)
return compliment | [
"def",
"emer_comp",
"(",
"rest",
")",
":",
"comps",
"=",
"util",
".",
"load_emergency_compliments",
"(",
")",
"compliment",
"=",
"random",
".",
"choice",
"(",
"comps",
")",
"if",
"rest",
":",
"complimentee",
"=",
"rest",
".",
"strip",
"(",
")",
"karma",
... | Return a random compliment from http://emergencycompliment.com/ | [
"Return",
"a",
"random",
"compliment",
"from",
"http",
":",
"//",
"emergencycompliment",
".",
"com",
"/"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L481-L489 |
yougov/pmxbot | pmxbot/commands.py | gettowork | def gettowork(channel, nick, rest):
"You really ought to, ya know..."
suggestions = [
"Um, might I suggest working now",
"Get to work",
(
"Between the coffee break, the smoking break, the lunch break, "
"the tea break, the bagel break, and the water cooler break, "
"may I suggest a work break. It’s wh... | python | def gettowork(channel, nick, rest):
"You really ought to, ya know..."
suggestions = [
"Um, might I suggest working now",
"Get to work",
(
"Between the coffee break, the smoking break, the lunch break, "
"the tea break, the bagel break, and the water cooler break, "
"may I suggest a work break. It’s wh... | [
"def",
"gettowork",
"(",
"channel",
",",
"nick",
",",
"rest",
")",
":",
"suggestions",
"=",
"[",
"\"Um, might I suggest working now\"",
",",
"\"Get to work\"",
",",
"(",
"\"Between the coffee break, the smoking break, the lunch break, \"",
"\"the tea break, the bagel break, and... | You really ought to, ya know... | [
"You",
"really",
"ought",
"to",
"ya",
"know",
"..."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L493-L515 |
yougov/pmxbot | pmxbot/commands.py | bitchingisuseless | def bitchingisuseless(channel, rest):
"It really is, ya know..."
rest = rest.strip()
if rest:
karma.Karma.store.change(rest, -1)
else:
karma.Karma.store.change(channel, -1)
rest = "foo'"
advice = 'Quiet bitching is useless, %s. Do something about it.' % rest
return advice | python | def bitchingisuseless(channel, rest):
"It really is, ya know..."
rest = rest.strip()
if rest:
karma.Karma.store.change(rest, -1)
else:
karma.Karma.store.change(channel, -1)
rest = "foo'"
advice = 'Quiet bitching is useless, %s. Do something about it.' % rest
return advice | [
"def",
"bitchingisuseless",
"(",
"channel",
",",
"rest",
")",
":",
"rest",
"=",
"rest",
".",
"strip",
"(",
")",
"if",
"rest",
":",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"rest",
",",
"-",
"1",
")",
"else",
":",
"karma",
".",
"Ka... | It really is, ya know... | [
"It",
"really",
"is",
"ya",
"know",
"..."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L519-L528 |
yougov/pmxbot | pmxbot/commands.py | curse | def curse(rest):
"Curse the day!"
if rest:
cursee = rest
else:
cursee = 'the day'
karma.Karma.store.change(cursee, -1)
return "/me curses %s!" % cursee | python | def curse(rest):
"Curse the day!"
if rest:
cursee = rest
else:
cursee = 'the day'
karma.Karma.store.change(cursee, -1)
return "/me curses %s!" % cursee | [
"def",
"curse",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"cursee",
"=",
"rest",
"else",
":",
"cursee",
"=",
"'the day'",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"cursee",
",",
"-",
"1",
")",
"return",
"\"/me curses %s!\"",
"%",
"cur... | Curse the day! | [
"Curse",
"the",
"day!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L532-L539 |
yougov/pmxbot | pmxbot/commands.py | stab | def stab(nick, rest):
"Stab, shank or shiv some(one|thing)!"
if rest:
stabee = rest
else:
stabee = 'wildly at anything'
if random.random() < 0.9:
karma.Karma.store.change(stabee, -1)
weapon = random.choice(phrases.weapon_opts)
weaponadj = random.choice(phrases.weapon_adjs)
violentact = random.choice(phr... | python | def stab(nick, rest):
"Stab, shank or shiv some(one|thing)!"
if rest:
stabee = rest
else:
stabee = 'wildly at anything'
if random.random() < 0.9:
karma.Karma.store.change(stabee, -1)
weapon = random.choice(phrases.weapon_opts)
weaponadj = random.choice(phrases.weapon_adjs)
violentact = random.choice(phr... | [
"def",
"stab",
"(",
"nick",
",",
"rest",
")",
":",
"if",
"rest",
":",
"stabee",
"=",
"rest",
"else",
":",
"stabee",
"=",
"'wildly at anything'",
"if",
"random",
".",
"random",
"(",
")",
"<",
"0.9",
":",
"karma",
".",
"Karma",
".",
"store",
".",
"ch... | Stab, shank or shiv some(one|thing)! | [
"Stab",
"shank",
"or",
"shiv",
"some",
"(",
"one|thing",
")",
"!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L554-L577 |
yougov/pmxbot | pmxbot/commands.py | disembowel | def disembowel(rest):
"Disembowel some(one|thing)!"
if rest:
stabee = rest
karma.Karma.store.change(stabee, -1)
else:
stabee = "someone nearby"
return (
"/me takes %s, brings them down to the basement, ties them to a "
"leaky pipe, and once bored of playing with them mercifully "
"ritually disembowels t... | python | def disembowel(rest):
"Disembowel some(one|thing)!"
if rest:
stabee = rest
karma.Karma.store.change(stabee, -1)
else:
stabee = "someone nearby"
return (
"/me takes %s, brings them down to the basement, ties them to a "
"leaky pipe, and once bored of playing with them mercifully "
"ritually disembowels t... | [
"def",
"disembowel",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"stabee",
"=",
"rest",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"stabee",
",",
"-",
"1",
")",
"else",
":",
"stabee",
"=",
"\"someone nearby\"",
"return",
"(",
"\"/me takes %... | Disembowel some(one|thing)! | [
"Disembowel",
"some",
"(",
"one|thing",
")",
"!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L581-L591 |
yougov/pmxbot | pmxbot/commands.py | embowel | def embowel(rest):
"Embowel some(one|thing)!"
if rest:
stabee = rest
karma.Karma.store.change(stabee, 1)
else:
stabee = "someone nearby"
return (
"/me (wearing a bright pink cape and yellow tights) swoops in "
"through an open window, snatches %s, races out of the basement, "
"takes them to the hospital... | python | def embowel(rest):
"Embowel some(one|thing)!"
if rest:
stabee = rest
karma.Karma.store.change(stabee, 1)
else:
stabee = "someone nearby"
return (
"/me (wearing a bright pink cape and yellow tights) swoops in "
"through an open window, snatches %s, races out of the basement, "
"takes them to the hospital... | [
"def",
"embowel",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"stabee",
"=",
"rest",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"stabee",
",",
"1",
")",
"else",
":",
"stabee",
"=",
"\"someone nearby\"",
"return",
"(",
"\"/me (wearing a bright... | Embowel some(one|thing)! | [
"Embowel",
"some",
"(",
"one|thing",
")",
"!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L595-L606 |
yougov/pmxbot | pmxbot/commands.py | chain | def chain(rest, nick):
"Chain some(one|thing) down."
chainee = rest or "someone nearby"
if chainee == 'cperry':
tmpl = "/me ties the chains extra tight around {chainee}"
elif random.random() < .9:
tmpl = (
"/me chains {chainee} to the nearest desk. "
"you ain't going home, buddy."
)
else:
karma.Karma... | python | def chain(rest, nick):
"Chain some(one|thing) down."
chainee = rest or "someone nearby"
if chainee == 'cperry':
tmpl = "/me ties the chains extra tight around {chainee}"
elif random.random() < .9:
tmpl = (
"/me chains {chainee} to the nearest desk. "
"you ain't going home, buddy."
)
else:
karma.Karma... | [
"def",
"chain",
"(",
"rest",
",",
"nick",
")",
":",
"chainee",
"=",
"rest",
"or",
"\"someone nearby\"",
"if",
"chainee",
"==",
"'cperry'",
":",
"tmpl",
"=",
"\"/me ties the chains extra tight around {chainee}\"",
"elif",
"random",
".",
"random",
"(",
")",
"<",
... | Chain some(one|thing) down. | [
"Chain",
"some",
"(",
"one|thing",
")",
"down",
"."
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L610-L627 |
yougov/pmxbot | pmxbot/commands.py | bless | def bless(rest):
"Bless the day!"
if rest:
blesse = rest
else:
blesse = 'the day'
karma.Karma.store.change(blesse, 1)
return "/me blesses %s!" % blesse | python | def bless(rest):
"Bless the day!"
if rest:
blesse = rest
else:
blesse = 'the day'
karma.Karma.store.change(blesse, 1)
return "/me blesses %s!" % blesse | [
"def",
"bless",
"(",
"rest",
")",
":",
"if",
"rest",
":",
"blesse",
"=",
"rest",
"else",
":",
"blesse",
"=",
"'the day'",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"blesse",
",",
"1",
")",
"return",
"\"/me blesses %s!\"",
"%",
"blesse"
] | Bless the day! | [
"Bless",
"the",
"day!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L631-L638 |
yougov/pmxbot | pmxbot/commands.py | blame | def blame(channel, rest, nick):
"Pass the buck!"
if rest:
blamee = rest
else:
blamee = channel
karma.Karma.store.change(nick, -1)
if random.randint(1, 10) == 1:
yield "/me jumps atop the chair and points back at %s." % nick
yield (
"stop blaming the world for your problems, you bitter, "
"two-faced s... | python | def blame(channel, rest, nick):
"Pass the buck!"
if rest:
blamee = rest
else:
blamee = channel
karma.Karma.store.change(nick, -1)
if random.randint(1, 10) == 1:
yield "/me jumps atop the chair and points back at %s." % nick
yield (
"stop blaming the world for your problems, you bitter, "
"two-faced s... | [
"def",
"blame",
"(",
"channel",
",",
"rest",
",",
"nick",
")",
":",
"if",
"rest",
":",
"blamee",
"=",
"rest",
"else",
":",
"blamee",
"=",
"channel",
"karma",
".",
"Karma",
".",
"store",
".",
"change",
"(",
"nick",
",",
"-",
"1",
")",
"if",
"rando... | Pass the buck! | [
"Pass",
"the",
"buck!"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L642-L660 |
yougov/pmxbot | pmxbot/commands.py | calc | def calc(rest):
"Perform a basic calculation"
mo = calc_exp.match(rest)
if mo:
try:
return str(eval(rest))
except Exception:
return "eval failed... check your syntax"
else:
return "misformatted arithmetic!" | python | def calc(rest):
"Perform a basic calculation"
mo = calc_exp.match(rest)
if mo:
try:
return str(eval(rest))
except Exception:
return "eval failed... check your syntax"
else:
return "misformatted arithmetic!" | [
"def",
"calc",
"(",
"rest",
")",
":",
"mo",
"=",
"calc_exp",
".",
"match",
"(",
"rest",
")",
"if",
"mo",
":",
"try",
":",
"return",
"str",
"(",
"eval",
"(",
"rest",
")",
")",
"except",
"Exception",
":",
"return",
"\"eval failed... check your syntax\"",
... | Perform a basic calculation | [
"Perform",
"a",
"basic",
"calculation"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L706-L715 |
yougov/pmxbot | pmxbot/commands.py | define | def define(rest):
"Define a word"
word = rest.strip()
res = util.lookup(word)
fmt = (
'{lookup.provider} says: {res}' if res else
"{lookup.provider} does not have a definition for that.")
return fmt.format(**dict(locals(), lookup=util.lookup)) | python | def define(rest):
"Define a word"
word = rest.strip()
res = util.lookup(word)
fmt = (
'{lookup.provider} says: {res}' if res else
"{lookup.provider} does not have a definition for that.")
return fmt.format(**dict(locals(), lookup=util.lookup)) | [
"def",
"define",
"(",
"rest",
")",
":",
"word",
"=",
"rest",
".",
"strip",
"(",
")",
"res",
"=",
"util",
".",
"lookup",
"(",
"word",
")",
"fmt",
"=",
"(",
"'{lookup.provider} says: {res}'",
"if",
"res",
"else",
"\"{lookup.provider} does not have a definition f... | Define a word | [
"Define",
"a",
"word"
] | train | https://github.com/yougov/pmxbot/blob/5da84a3258a0fd73cb35b60e39769a5d7bfb2ba7/pmxbot/commands.py#L719-L726 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.