partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
valid | Instruction.name | The instruction name/mnemonic | pyevmasm/evmasm.py | def name(self):
""" The instruction name/mnemonic """
if self._name == 'PUSH':
return 'PUSH%d' % self.operand_size
elif self._name == 'DUP':
return 'DUP%d' % self.pops
elif self._name == 'SWAP':
return 'SWAP%d' % (self.pops - 1)
elif self._name... | def name(self):
""" The instruction name/mnemonic """
if self._name == 'PUSH':
return 'PUSH%d' % self.operand_size
elif self._name == 'DUP':
return 'DUP%d' % self.pops
elif self._name == 'SWAP':
return 'SWAP%d' % (self.pops - 1)
elif self._name... | [
"The",
"instruction",
"name",
"/",
"mnemonic"
] | crytic/pyevmasm | python | https://github.com/crytic/pyevmasm/blob/d27daf19a36d630a31499e783b716cf1165798d8/pyevmasm/evmasm.py#L139-L149 | [
"def",
"name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_name",
"==",
"'PUSH'",
":",
"return",
"'PUSH%d'",
"%",
"self",
".",
"operand_size",
"elif",
"self",
".",
"_name",
"==",
"'DUP'",
":",
"return",
"'DUP%d'",
"%",
"self",
".",
"pops",
"elif",
"s... | d27daf19a36d630a31499e783b716cf1165798d8 |
valid | Instruction.parse_operand | Parses an operand from buf
:param buf: a buffer
:type buf: iterator/generator/string | pyevmasm/evmasm.py | def parse_operand(self, buf):
""" Parses an operand from buf
:param buf: a buffer
:type buf: iterator/generator/string
"""
buf = iter(buf)
try:
operand = 0
for _ in range(self.operand_size):
operand <<= 8
op... | def parse_operand(self, buf):
""" Parses an operand from buf
:param buf: a buffer
:type buf: iterator/generator/string
"""
buf = iter(buf)
try:
operand = 0
for _ in range(self.operand_size):
operand <<= 8
op... | [
"Parses",
"an",
"operand",
"from",
"buf"
] | crytic/pyevmasm | python | https://github.com/crytic/pyevmasm/blob/d27daf19a36d630a31499e783b716cf1165798d8/pyevmasm/evmasm.py#L151-L165 | [
"def",
"parse_operand",
"(",
"self",
",",
"buf",
")",
":",
"buf",
"=",
"iter",
"(",
"buf",
")",
"try",
":",
"operand",
"=",
"0",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"operand_size",
")",
":",
"operand",
"<<=",
"8",
"operand",
"|=",
"next",
... | d27daf19a36d630a31499e783b716cf1165798d8 |
valid | Instruction.bytes | Encoded instruction | pyevmasm/evmasm.py | def bytes(self):
""" Encoded instruction """
b = [bytes([self._opcode])]
for offset in reversed(range(self.operand_size)):
b.append(bytes([(self.operand >> offset * 8) & 0xff]))
return b''.join(b) | def bytes(self):
""" Encoded instruction """
b = [bytes([self._opcode])]
for offset in reversed(range(self.operand_size)):
b.append(bytes([(self.operand >> offset * 8) & 0xff]))
return b''.join(b) | [
"Encoded",
"instruction"
] | crytic/pyevmasm | python | https://github.com/crytic/pyevmasm/blob/d27daf19a36d630a31499e783b716cf1165798d8/pyevmasm/evmasm.py#L220-L225 | [
"def",
"bytes",
"(",
"self",
")",
":",
"b",
"=",
"[",
"bytes",
"(",
"[",
"self",
".",
"_opcode",
"]",
")",
"]",
"for",
"offset",
"in",
"reversed",
"(",
"range",
"(",
"self",
".",
"operand_size",
")",
")",
":",
"b",
".",
"append",
"(",
"bytes",
... | d27daf19a36d630a31499e783b716cf1165798d8 |
valid | reverse | reverse the key, value in dictionary file
:param rev_inputs: the files to be reversed
:return: None | helper/reverse.py | def reverse(rev_inputs=REV_INPUTS):
"""
reverse the key, value in dictionary file
:param rev_inputs: the files to be reversed
:return: None
"""
dirname = os.path.dirname(__file__)
for in_file in rev_inputs:
reversed_dict = {}
input_file = in_file + '.txt'
output_file... | def reverse(rev_inputs=REV_INPUTS):
"""
reverse the key, value in dictionary file
:param rev_inputs: the files to be reversed
:return: None
"""
dirname = os.path.dirname(__file__)
for in_file in rev_inputs:
reversed_dict = {}
input_file = in_file + '.txt'
output_file... | [
"reverse",
"the",
"key",
"value",
"in",
"dictionary",
"file",
":",
"param",
"rev_inputs",
":",
"the",
"files",
"to",
"be",
"reversed",
":",
"return",
":",
"None"
] | yichen0831/opencc-python | python | https://github.com/yichen0831/opencc-python/blob/75a7e882a250076c7d239e0fef0791815aae545d/helper/reverse.py#L22-L53 | [
"def",
"reverse",
"(",
"rev_inputs",
"=",
"REV_INPUTS",
")",
":",
"dirname",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"for",
"in_file",
"in",
"rev_inputs",
":",
"reversed_dict",
"=",
"{",
"}",
"input_file",
"=",
"in_file",
"+",
"'.tx... | 75a7e882a250076c7d239e0fef0791815aae545d |
valid | merge | merge the phrase files into one file
:param mer_inputs: the phrase files
:param mer_output: the output file
:return: None | helper/merge.py | def merge(mer_inputs=MER_INPUTS, mer_output=MER_OUTPUT):
"""
merge the phrase files into one file
:param mer_inputs: the phrase files
:param mer_output: the output file
:return: None
"""
dirname = os.path.dirname(__file__)
output_file = os.path.join(dirname, DICT_DIRECTORY, mer_output)
... | def merge(mer_inputs=MER_INPUTS, mer_output=MER_OUTPUT):
"""
merge the phrase files into one file
:param mer_inputs: the phrase files
:param mer_output: the output file
:return: None
"""
dirname = os.path.dirname(__file__)
output_file = os.path.join(dirname, DICT_DIRECTORY, mer_output)
... | [
"merge",
"the",
"phrase",
"files",
"into",
"one",
"file",
":",
"param",
"mer_inputs",
":",
"the",
"phrase",
"files",
":",
"param",
"mer_output",
":",
"the",
"output",
"file",
":",
"return",
":",
"None"
] | yichen0831/opencc-python | python | https://github.com/yichen0831/opencc-python/blob/75a7e882a250076c7d239e0fef0791815aae545d/helper/merge.py#L24-L42 | [
"def",
"merge",
"(",
"mer_inputs",
"=",
"MER_INPUTS",
",",
"mer_output",
"=",
"MER_OUTPUT",
")",
":",
"dirname",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"output_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dirname",
",",
"DIC... | 75a7e882a250076c7d239e0fef0791815aae545d |
valid | PassiveThrottle._adjust_delay | Define delay adjustment policy | pystock_crawler/throttle.py | def _adjust_delay(self, slot, response):
"""Define delay adjustment policy"""
if response.status in self.retry_http_codes:
new_delay = max(slot.delay, 1) * 4
new_delay = max(new_delay, self.mindelay)
new_delay = min(new_delay, self.maxdelay)
slot.delay = n... | def _adjust_delay(self, slot, response):
"""Define delay adjustment policy"""
if response.status in self.retry_http_codes:
new_delay = max(slot.delay, 1) * 4
new_delay = max(new_delay, self.mindelay)
new_delay = min(new_delay, self.maxdelay)
slot.delay = n... | [
"Define",
"delay",
"adjustment",
"policy"
] | eliangcs/pystock-crawler | python | https://github.com/eliangcs/pystock-crawler/blob/8b803c8944f36af46daf04c6767a74132e37a101/pystock_crawler/throttle.py#L66-L78 | [
"def",
"_adjust_delay",
"(",
"self",
",",
"slot",
",",
"response",
")",
":",
"if",
"response",
".",
"status",
"in",
"self",
".",
"retry_http_codes",
":",
"new_delay",
"=",
"max",
"(",
"slot",
".",
"delay",
",",
"1",
")",
"*",
"4",
"new_delay",
"=",
"... | 8b803c8944f36af46daf04c6767a74132e37a101 |
valid | memberness | The likelihood that the context is a "member". | pystock_crawler/loaders.py | def memberness(context):
'''The likelihood that the context is a "member".'''
if context:
texts = context.xpath('.//*[local-name()="explicitMember"]/text()').extract()
text = str(texts).lower()
if len(texts) > 1:
return 2
elif 'country' in text:
return 2
... | def memberness(context):
'''The likelihood that the context is a "member".'''
if context:
texts = context.xpath('.//*[local-name()="explicitMember"]/text()').extract()
text = str(texts).lower()
if len(texts) > 1:
return 2
elif 'country' in text:
return 2
... | [
"The",
"likelihood",
"that",
"the",
"context",
"is",
"a",
"member",
"."
] | eliangcs/pystock-crawler | python | https://github.com/eliangcs/pystock-crawler/blob/8b803c8944f36af46daf04c6767a74132e37a101/pystock_crawler/loaders.py#L300-L317 | [
"def",
"memberness",
"(",
"context",
")",
":",
"if",
"context",
":",
"texts",
"=",
"context",
".",
"xpath",
"(",
"'.//*[local-name()=\"explicitMember\"]/text()'",
")",
".",
"extract",
"(",
")",
"text",
"=",
"str",
"(",
"texts",
")",
".",
"lower",
"(",
")",... | 8b803c8944f36af46daf04c6767a74132e37a101 |
valid | EdgarSpider.parse_10qk | Parse 10-Q or 10-K XML report. | pystock_crawler/spiders/edgar.py | def parse_10qk(self, response):
'''Parse 10-Q or 10-K XML report.'''
loader = ReportItemLoader(response=response)
item = loader.load_item()
if 'doc_type' in item:
doc_type = item['doc_type']
if doc_type in ('10-Q', '10-K'):
return item
re... | def parse_10qk(self, response):
'''Parse 10-Q or 10-K XML report.'''
loader = ReportItemLoader(response=response)
item = loader.load_item()
if 'doc_type' in item:
doc_type = item['doc_type']
if doc_type in ('10-Q', '10-K'):
return item
re... | [
"Parse",
"10",
"-",
"Q",
"or",
"10",
"-",
"K",
"XML",
"report",
"."
] | eliangcs/pystock-crawler | python | https://github.com/eliangcs/pystock-crawler/blob/8b803c8944f36af46daf04c6767a74132e37a101/pystock_crawler/spiders/edgar.py#L57-L67 | [
"def",
"parse_10qk",
"(",
"self",
",",
"response",
")",
":",
"loader",
"=",
"ReportItemLoader",
"(",
"response",
"=",
"response",
")",
"item",
"=",
"loader",
".",
"load_item",
"(",
")",
"if",
"'doc_type'",
"in",
"item",
":",
"doc_type",
"=",
"item",
"[",... | 8b803c8944f36af46daf04c6767a74132e37a101 |
valid | camelcase | Convert string into camel case.
Args:
string: String to convert.
Returns:
string: Camel case string. | stringcase.py | def camelcase(string):
""" Convert string into camel case.
Args:
string: String to convert.
Returns:
string: Camel case string.
"""
string = re.sub(r"^[\-_\.]", '', str(string))
if not string:
return string
return lowercase(string[0]) + re.sub(r"[\-_\.\s]([a-z])",... | def camelcase(string):
""" Convert string into camel case.
Args:
string: String to convert.
Returns:
string: Camel case string.
"""
string = re.sub(r"^[\-_\.]", '', str(string))
if not string:
return string
return lowercase(string[0]) + re.sub(r"[\-_\.\s]([a-z])",... | [
"Convert",
"string",
"into",
"camel",
"case",
"."
] | okunishinishi/python-stringcase | python | https://github.com/okunishinishi/python-stringcase/blob/700ad111be16b384aadaddcf8199f9390575c7b6/stringcase.py#L8-L22 | [
"def",
"camelcase",
"(",
"string",
")",
":",
"string",
"=",
"re",
".",
"sub",
"(",
"r\"^[\\-_\\.]\"",
",",
"''",
",",
"str",
"(",
"string",
")",
")",
"if",
"not",
"string",
":",
"return",
"string",
"return",
"lowercase",
"(",
"string",
"[",
"0",
"]",... | 700ad111be16b384aadaddcf8199f9390575c7b6 |
valid | capitalcase | Convert string into capital case.
First letters will be uppercase.
Args:
string: String to convert.
Returns:
string: Capital case string. | stringcase.py | def capitalcase(string):
"""Convert string into capital case.
First letters will be uppercase.
Args:
string: String to convert.
Returns:
string: Capital case string.
"""
string = str(string)
if not string:
return string
return uppercase(string[0]) + string[1:] | def capitalcase(string):
"""Convert string into capital case.
First letters will be uppercase.
Args:
string: String to convert.
Returns:
string: Capital case string.
"""
string = str(string)
if not string:
return string
return uppercase(string[0]) + string[1:] | [
"Convert",
"string",
"into",
"capital",
"case",
".",
"First",
"letters",
"will",
"be",
"uppercase",
"."
] | okunishinishi/python-stringcase | python | https://github.com/okunishinishi/python-stringcase/blob/700ad111be16b384aadaddcf8199f9390575c7b6/stringcase.py#L25-L40 | [
"def",
"capitalcase",
"(",
"string",
")",
":",
"string",
"=",
"str",
"(",
"string",
")",
"if",
"not",
"string",
":",
"return",
"string",
"return",
"uppercase",
"(",
"string",
"[",
"0",
"]",
")",
"+",
"string",
"[",
"1",
":",
"]"
] | 700ad111be16b384aadaddcf8199f9390575c7b6 |
valid | pathcase | Convert string into path case.
Join punctuation with slash.
Args:
string: String to convert.
Returns:
string: Path cased string. | stringcase.py | def pathcase(string):
"""Convert string into path case.
Join punctuation with slash.
Args:
string: String to convert.
Returns:
string: Path cased string.
"""
string = snakecase(string)
if not string:
return string
return re.sub(r"_", "/", string) | def pathcase(string):
"""Convert string into path case.
Join punctuation with slash.
Args:
string: String to convert.
Returns:
string: Path cased string.
"""
string = snakecase(string)
if not string:
return string
return re.sub(r"_", "/", string) | [
"Convert",
"string",
"into",
"path",
"case",
".",
"Join",
"punctuation",
"with",
"slash",
"."
] | okunishinishi/python-stringcase | python | https://github.com/okunishinishi/python-stringcase/blob/700ad111be16b384aadaddcf8199f9390575c7b6/stringcase.py#L86-L100 | [
"def",
"pathcase",
"(",
"string",
")",
":",
"string",
"=",
"snakecase",
"(",
"string",
")",
"if",
"not",
"string",
":",
"return",
"string",
"return",
"re",
".",
"sub",
"(",
"r\"_\"",
",",
"\"/\"",
",",
"string",
")"
] | 700ad111be16b384aadaddcf8199f9390575c7b6 |
valid | backslashcase | Convert string into spinal case.
Join punctuation with backslash.
Args:
string: String to convert.
Returns:
string: Spinal cased string. | stringcase.py | def backslashcase(string):
"""Convert string into spinal case.
Join punctuation with backslash.
Args:
string: String to convert.
Returns:
string: Spinal cased string.
"""
str1 = re.sub(r"_", r"\\", snakecase(string))
return str1 | def backslashcase(string):
"""Convert string into spinal case.
Join punctuation with backslash.
Args:
string: String to convert.
Returns:
string: Spinal cased string.
"""
str1 = re.sub(r"_", r"\\", snakecase(string))
return str1 | [
"Convert",
"string",
"into",
"spinal",
"case",
".",
"Join",
"punctuation",
"with",
"backslash",
"."
] | okunishinishi/python-stringcase | python | https://github.com/okunishinishi/python-stringcase/blob/700ad111be16b384aadaddcf8199f9390575c7b6/stringcase.py#L103-L116 | [
"def",
"backslashcase",
"(",
"string",
")",
":",
"str1",
"=",
"re",
".",
"sub",
"(",
"r\"_\"",
",",
"r\"\\\\\"",
",",
"snakecase",
"(",
"string",
")",
")",
"return",
"str1"
] | 700ad111be16b384aadaddcf8199f9390575c7b6 |
valid | sentencecase | Convert string into sentence case.
First letter capped and each punctuations are joined with space.
Args:
string: String to convert.
Returns:
string: Sentence cased string. | stringcase.py | def sentencecase(string):
"""Convert string into sentence case.
First letter capped and each punctuations are joined with space.
Args:
string: String to convert.
Returns:
string: Sentence cased string.
"""
joiner = ' '
string = re.sub(r"[\-_\.\s]", joiner, str(string))
... | def sentencecase(string):
"""Convert string into sentence case.
First letter capped and each punctuations are joined with space.
Args:
string: String to convert.
Returns:
string: Sentence cased string.
"""
joiner = ' '
string = re.sub(r"[\-_\.\s]", joiner, str(string))
... | [
"Convert",
"string",
"into",
"sentence",
"case",
".",
"First",
"letter",
"capped",
"and",
"each",
"punctuations",
"are",
"joined",
"with",
"space",
"."
] | okunishinishi/python-stringcase | python | https://github.com/okunishinishi/python-stringcase/blob/700ad111be16b384aadaddcf8199f9390575c7b6/stringcase.py#L120-L138 | [
"def",
"sentencecase",
"(",
"string",
")",
":",
"joiner",
"=",
"' '",
"string",
"=",
"re",
".",
"sub",
"(",
"r\"[\\-_\\.\\s]\"",
",",
"joiner",
",",
"str",
"(",
"string",
")",
")",
"if",
"not",
"string",
":",
"return",
"string",
"return",
"capitalcase",
... | 700ad111be16b384aadaddcf8199f9390575c7b6 |
valid | snakecase | Convert string into snake case.
Join punctuation with underscore
Args:
string: String to convert.
Returns:
string: Snake cased string. | stringcase.py | def snakecase(string):
"""Convert string into snake case.
Join punctuation with underscore
Args:
string: String to convert.
Returns:
string: Snake cased string.
"""
string = re.sub(r"[\-\.\s]", '_', str(string))
if not string:
return string
return lowercase(st... | def snakecase(string):
"""Convert string into snake case.
Join punctuation with underscore
Args:
string: String to convert.
Returns:
string: Snake cased string.
"""
string = re.sub(r"[\-\.\s]", '_', str(string))
if not string:
return string
return lowercase(st... | [
"Convert",
"string",
"into",
"snake",
"case",
".",
"Join",
"punctuation",
"with",
"underscore"
] | okunishinishi/python-stringcase | python | https://github.com/okunishinishi/python-stringcase/blob/700ad111be16b384aadaddcf8199f9390575c7b6/stringcase.py#L141-L156 | [
"def",
"snakecase",
"(",
"string",
")",
":",
"string",
"=",
"re",
".",
"sub",
"(",
"r\"[\\-\\.\\s]\"",
",",
"'_'",
",",
"str",
"(",
"string",
")",
")",
"if",
"not",
"string",
":",
"return",
"string",
"return",
"lowercase",
"(",
"string",
"[",
"0",
"]... | 700ad111be16b384aadaddcf8199f9390575c7b6 |
valid | STree._check_input | Checks the validity of the input.
In case of an invalid input throws ValueError. | suffix_trees/STree.py | def _check_input(self, input):
"""Checks the validity of the input.
In case of an invalid input throws ValueError.
"""
if isinstance(input, str):
return 'st'
elif isinstance(input, list):
if all(isinstance(item, str) for item in input):
re... | def _check_input(self, input):
"""Checks the validity of the input.
In case of an invalid input throws ValueError.
"""
if isinstance(input, str):
return 'st'
elif isinstance(input, list):
if all(isinstance(item, str) for item in input):
re... | [
"Checks",
"the",
"validity",
"of",
"the",
"input",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L16-L28 | [
"def",
"_check_input",
"(",
"self",
",",
"input",
")",
":",
"if",
"isinstance",
"(",
"input",
",",
"str",
")",
":",
"return",
"'st'",
"elif",
"isinstance",
"(",
"input",
",",
"list",
")",
":",
"if",
"all",
"(",
"isinstance",
"(",
"item",
",",
"str",
... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree.build | Builds the Suffix tree on the given input.
If the input is of type List of Strings:
Generalized Suffix Tree is built.
:param x: String or List of Strings | suffix_trees/STree.py | def build(self, x):
"""Builds the Suffix tree on the given input.
If the input is of type List of Strings:
Generalized Suffix Tree is built.
:param x: String or List of Strings
"""
type = self._check_input(x)
if type == 'st':
x += next(self._terminal... | def build(self, x):
"""Builds the Suffix tree on the given input.
If the input is of type List of Strings:
Generalized Suffix Tree is built.
:param x: String or List of Strings
"""
type = self._check_input(x)
if type == 'st':
x += next(self._terminal... | [
"Builds",
"the",
"Suffix",
"tree",
"on",
"the",
"given",
"input",
".",
"If",
"the",
"input",
"is",
"of",
"type",
"List",
"of",
"Strings",
":",
"Generalized",
"Suffix",
"Tree",
"is",
"built",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L30-L43 | [
"def",
"build",
"(",
"self",
",",
"x",
")",
":",
"type",
"=",
"self",
".",
"_check_input",
"(",
"x",
")",
"if",
"type",
"==",
"'st'",
":",
"x",
"+=",
"next",
"(",
"self",
".",
"_terminalSymbolsGenerator",
"(",
")",
")",
"self",
".",
"_build",
"(",
... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._build_McCreight | Builds a Suffix tree using McCreight O(n) algorithm.
Algorithm based on:
McCreight, Edward M. "A space-economical suffix tree construction algorithm." - ACM, 1976.
Implementation based on:
UH CS - 58093 String Processing Algorithms Lecture Notes | suffix_trees/STree.py | def _build_McCreight(self, x):
"""Builds a Suffix tree using McCreight O(n) algorithm.
Algorithm based on:
McCreight, Edward M. "A space-economical suffix tree construction algorithm." - ACM, 1976.
Implementation based on:
UH CS - 58093 String Processing Algorithms Lecture Notes... | def _build_McCreight(self, x):
"""Builds a Suffix tree using McCreight O(n) algorithm.
Algorithm based on:
McCreight, Edward M. "A space-economical suffix tree construction algorithm." - ACM, 1976.
Implementation based on:
UH CS - 58093 String Processing Algorithms Lecture Notes... | [
"Builds",
"a",
"Suffix",
"tree",
"using",
"McCreight",
"O",
"(",
"n",
")",
"algorithm",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L50-L74 | [
"def",
"_build_McCreight",
"(",
"self",
",",
"x",
")",
":",
"u",
"=",
"self",
".",
"root",
"d",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"x",
")",
")",
":",
"while",
"u",
".",
"depth",
"==",
"d",
"and",
"u",
".",
"_has_transition",... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._build_generalized | Builds a Generalized Suffix Tree (GST) from the array of strings provided. | suffix_trees/STree.py | def _build_generalized(self, xs):
"""Builds a Generalized Suffix Tree (GST) from the array of strings provided.
"""
terminal_gen = self._terminalSymbolsGenerator()
_xs = ''.join([x + next(terminal_gen) for x in xs])
self.word = _xs
self._generalized_word_starts(xs)
... | def _build_generalized(self, xs):
"""Builds a Generalized Suffix Tree (GST) from the array of strings provided.
"""
terminal_gen = self._terminalSymbolsGenerator()
_xs = ''.join([x + next(terminal_gen) for x in xs])
self.word = _xs
self._generalized_word_starts(xs)
... | [
"Builds",
"a",
"Generalized",
"Suffix",
"Tree",
"(",
"GST",
")",
"from",
"the",
"array",
"of",
"strings",
"provided",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L113-L122 | [
"def",
"_build_generalized",
"(",
"self",
",",
"xs",
")",
":",
"terminal_gen",
"=",
"self",
".",
"_terminalSymbolsGenerator",
"(",
")",
"_xs",
"=",
"''",
".",
"join",
"(",
"[",
"x",
"+",
"next",
"(",
"terminal_gen",
")",
"for",
"x",
"in",
"xs",
"]",
... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._label_generalized | Helper method that labels the nodes of GST with indexes of strings
found in their descendants. | suffix_trees/STree.py | def _label_generalized(self, node):
"""Helper method that labels the nodes of GST with indexes of strings
found in their descendants.
"""
if node.is_leaf():
x = {self._get_word_start_index(node.idx)}
else:
x = {n for ns in node.transition_links for n in ns... | def _label_generalized(self, node):
"""Helper method that labels the nodes of GST with indexes of strings
found in their descendants.
"""
if node.is_leaf():
x = {self._get_word_start_index(node.idx)}
else:
x = {n for ns in node.transition_links for n in ns... | [
"Helper",
"method",
"that",
"labels",
"the",
"nodes",
"of",
"GST",
"with",
"indexes",
"of",
"strings",
"found",
"in",
"their",
"descendants",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L124-L132 | [
"def",
"_label_generalized",
"(",
"self",
",",
"node",
")",
":",
"if",
"node",
".",
"is_leaf",
"(",
")",
":",
"x",
"=",
"{",
"self",
".",
"_get_word_start_index",
"(",
"node",
".",
"idx",
")",
"}",
"else",
":",
"x",
"=",
"{",
"n",
"for",
"ns",
"i... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._get_word_start_index | Helper method that returns the index of the string based on node's
starting index | suffix_trees/STree.py | def _get_word_start_index(self, idx):
"""Helper method that returns the index of the string based on node's
starting index"""
i = 0
for _idx in self.word_starts[1:]:
if idx < _idx:
return i
else:
i+=1
return i | def _get_word_start_index(self, idx):
"""Helper method that returns the index of the string based on node's
starting index"""
i = 0
for _idx in self.word_starts[1:]:
if idx < _idx:
return i
else:
i+=1
return i | [
"Helper",
"method",
"that",
"returns",
"the",
"index",
"of",
"the",
"string",
"based",
"on",
"node",
"s",
"starting",
"index"
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L134-L143 | [
"def",
"_get_word_start_index",
"(",
"self",
",",
"idx",
")",
":",
"i",
"=",
"0",
"for",
"_idx",
"in",
"self",
".",
"word_starts",
"[",
"1",
":",
"]",
":",
"if",
"idx",
"<",
"_idx",
":",
"return",
"i",
"else",
":",
"i",
"+=",
"1",
"return",
"i"
] | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree.lcs | Returns the Largest Common Substring of Strings provided in stringIdxs.
If stringIdxs is not provided, the LCS of all strings is returned.
::param stringIdxs: Optional: List of indexes of strings. | suffix_trees/STree.py | def lcs(self, stringIdxs=-1):
"""Returns the Largest Common Substring of Strings provided in stringIdxs.
If stringIdxs is not provided, the LCS of all strings is returned.
::param stringIdxs: Optional: List of indexes of strings.
"""
if stringIdxs == -1 or not isinstance(stringI... | def lcs(self, stringIdxs=-1):
"""Returns the Largest Common Substring of Strings provided in stringIdxs.
If stringIdxs is not provided, the LCS of all strings is returned.
::param stringIdxs: Optional: List of indexes of strings.
"""
if stringIdxs == -1 or not isinstance(stringI... | [
"Returns",
"the",
"Largest",
"Common",
"Substring",
"of",
"Strings",
"provided",
"in",
"stringIdxs",
".",
"If",
"stringIdxs",
"is",
"not",
"provided",
"the",
"LCS",
"of",
"all",
"strings",
"is",
"returned",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L145-L159 | [
"def",
"lcs",
"(",
"self",
",",
"stringIdxs",
"=",
"-",
"1",
")",
":",
"if",
"stringIdxs",
"==",
"-",
"1",
"or",
"not",
"isinstance",
"(",
"stringIdxs",
",",
"list",
")",
":",
"stringIdxs",
"=",
"set",
"(",
"range",
"(",
"len",
"(",
"self",
".",
... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._find_lcs | Helper method that finds LCS by traversing the labeled GSD. | suffix_trees/STree.py | def _find_lcs(self, node, stringIdxs):
"""Helper method that finds LCS by traversing the labeled GSD."""
nodes = [self._find_lcs(n, stringIdxs)
for (n,_) in node.transition_links
if n.generalized_idxs.issuperset(stringIdxs)]
if nodes == []:
return node
... | def _find_lcs(self, node, stringIdxs):
"""Helper method that finds LCS by traversing the labeled GSD."""
nodes = [self._find_lcs(n, stringIdxs)
for (n,_) in node.transition_links
if n.generalized_idxs.issuperset(stringIdxs)]
if nodes == []:
return node
... | [
"Helper",
"method",
"that",
"finds",
"LCS",
"by",
"traversing",
"the",
"labeled",
"GSD",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L161-L171 | [
"def",
"_find_lcs",
"(",
"self",
",",
"node",
",",
"stringIdxs",
")",
":",
"nodes",
"=",
"[",
"self",
".",
"_find_lcs",
"(",
"n",
",",
"stringIdxs",
")",
"for",
"(",
"n",
",",
"_",
")",
"in",
"node",
".",
"transition_links",
"if",
"n",
".",
"genera... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._generalized_word_starts | Helper method returns the starting indexes of strings in GST | suffix_trees/STree.py | def _generalized_word_starts(self, xs):
"""Helper method returns the starting indexes of strings in GST"""
self.word_starts = []
i = 0
for n in range(len(xs)):
self.word_starts.append(i)
i += len(xs[n]) + 1 | def _generalized_word_starts(self, xs):
"""Helper method returns the starting indexes of strings in GST"""
self.word_starts = []
i = 0
for n in range(len(xs)):
self.word_starts.append(i)
i += len(xs[n]) + 1 | [
"Helper",
"method",
"returns",
"the",
"starting",
"indexes",
"of",
"strings",
"in",
"GST"
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L173-L179 | [
"def",
"_generalized_word_starts",
"(",
"self",
",",
"xs",
")",
":",
"self",
".",
"word_starts",
"=",
"[",
"]",
"i",
"=",
"0",
"for",
"n",
"in",
"range",
"(",
"len",
"(",
"xs",
")",
")",
":",
"self",
".",
"word_starts",
".",
"append",
"(",
"i",
"... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree.find | Returns starting position of the substring y in the string used for
building the Suffix tree.
:param y: String
:return: Index of the starting position of string y in the string used for building the Suffix tree
-1 if y is not a substring. | suffix_trees/STree.py | def find(self, y):
"""Returns starting position of the substring y in the string used for
building the Suffix tree.
:param y: String
:return: Index of the starting position of string y in the string used for building the Suffix tree
-1 if y is not a substring.
"... | def find(self, y):
"""Returns starting position of the substring y in the string used for
building the Suffix tree.
:param y: String
:return: Index of the starting position of string y in the string used for building the Suffix tree
-1 if y is not a substring.
"... | [
"Returns",
"starting",
"position",
"of",
"the",
"substring",
"y",
"in",
"the",
"string",
"used",
"for",
"building",
"the",
"Suffix",
"tree",
"."
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L181-L208 | [
"def",
"find",
"(",
"self",
",",
"y",
")",
":",
"node",
"=",
"self",
".",
"root",
"while",
"True",
":",
"edge",
"=",
"self",
".",
"_edgeLabel",
"(",
"node",
",",
"node",
".",
"parent",
")",
"if",
"edge",
".",
"startswith",
"(",
"y",
")",
":",
"... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._edgeLabel | Helper method, returns the edge label between a node and it's parent | suffix_trees/STree.py | def _edgeLabel(self, node, parent):
"""Helper method, returns the edge label between a node and it's parent"""
return self.word[node.idx + parent.depth : node.idx + node.depth] | def _edgeLabel(self, node, parent):
"""Helper method, returns the edge label between a node and it's parent"""
return self.word[node.idx + parent.depth : node.idx + node.depth] | [
"Helper",
"method",
"returns",
"the",
"edge",
"label",
"between",
"a",
"node",
"and",
"it",
"s",
"parent"
] | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L236-L238 | [
"def",
"_edgeLabel",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"self",
".",
"word",
"[",
"node",
".",
"idx",
"+",
"parent",
".",
"depth",
":",
"node",
".",
"idx",
"+",
"node",
".",
"depth",
"]"
] | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | STree._terminalSymbolsGenerator | Generator of unique terminal symbols used for building the Generalized Suffix Tree.
Unicode Private Use Area U+E000..U+F8FF is used to ensure that terminal symbols
are not part of the input string. | suffix_trees/STree.py | def _terminalSymbolsGenerator(self):
"""Generator of unique terminal symbols used for building the Generalized Suffix Tree.
Unicode Private Use Area U+E000..U+F8FF is used to ensure that terminal symbols
are not part of the input string.
"""
py2 = sys.version[0] < '3'
UPP... | def _terminalSymbolsGenerator(self):
"""Generator of unique terminal symbols used for building the Generalized Suffix Tree.
Unicode Private Use Area U+E000..U+F8FF is used to ensure that terminal symbols
are not part of the input string.
"""
py2 = sys.version[0] < '3'
UPP... | [
"Generator",
"of",
"unique",
"terminal",
"symbols",
"used",
"for",
"building",
"the",
"Generalized",
"Suffix",
"Tree",
".",
"Unicode",
"Private",
"Use",
"Area",
"U",
"+",
"E000",
"..",
"U",
"+",
"F8FF",
"is",
"used",
"to",
"ensure",
"that",
"terminal",
"sy... | ptrus/suffix-trees | python | https://github.com/ptrus/suffix-trees/blob/e7439c93a7b895523fad36c8c65a781710320b57/suffix_trees/STree.py#L241-L253 | [
"def",
"_terminalSymbolsGenerator",
"(",
"self",
")",
":",
"py2",
"=",
"sys",
".",
"version",
"[",
"0",
"]",
"<",
"'3'",
"UPPAs",
"=",
"list",
"(",
"list",
"(",
"range",
"(",
"0xE000",
",",
"0xF8FF",
"+",
"1",
")",
")",
"+",
"list",
"(",
"range",
... | e7439c93a7b895523fad36c8c65a781710320b57 |
valid | MPCKMeans._dist | (x - y)^T A (x - y) | active_semi_clustering/semi_supervised/pairwise_constraints/mpckmeans.py | def _dist(self, x, y, A):
"(x - y)^T A (x - y)"
return scipy.spatial.distance.mahalanobis(x, y, A) ** 2 | def _dist(self, x, y, A):
"(x - y)^T A (x - y)"
return scipy.spatial.distance.mahalanobis(x, y, A) ** 2 | [
"(",
"x",
"-",
"y",
")",
"^T",
"A",
"(",
"x",
"-",
"y",
")"
] | datamole-ai/active-semi-supervised-clustering | python | https://github.com/datamole-ai/active-semi-supervised-clustering/blob/0dcab86ea22cd66ed7ea64234efdff1c6aca7981/active_semi_clustering/semi_supervised/pairwise_constraints/mpckmeans.py#L96-L98 | [
"def",
"_dist",
"(",
"self",
",",
"x",
",",
"y",
",",
"A",
")",
":",
"return",
"scipy",
".",
"spatial",
".",
"distance",
".",
"mahalanobis",
"(",
"x",
",",
"y",
",",
"A",
")",
"**",
"2"
] | 0dcab86ea22cd66ed7ea64234efdff1c6aca7981 |
valid | ExampleOracle.query | Query the oracle to find out whether i and j should be must-linked | active_semi_clustering/active/pairwise_constraints/example_oracle.py | def query(self, i, j):
"Query the oracle to find out whether i and j should be must-linked"
if self.queries_cnt < self.max_queries_cnt:
self.queries_cnt += 1
return self.labels[i] == self.labels[j]
else:
raise MaximumQueriesExceeded | def query(self, i, j):
"Query the oracle to find out whether i and j should be must-linked"
if self.queries_cnt < self.max_queries_cnt:
self.queries_cnt += 1
return self.labels[i] == self.labels[j]
else:
raise MaximumQueriesExceeded | [
"Query",
"the",
"oracle",
"to",
"find",
"out",
"whether",
"i",
"and",
"j",
"should",
"be",
"must",
"-",
"linked"
] | datamole-ai/active-semi-supervised-clustering | python | https://github.com/datamole-ai/active-semi-supervised-clustering/blob/0dcab86ea22cd66ed7ea64234efdff1c6aca7981/active_semi_clustering/active/pairwise_constraints/example_oracle.py#L11-L17 | [
"def",
"query",
"(",
"self",
",",
"i",
",",
"j",
")",
":",
"if",
"self",
".",
"queries_cnt",
"<",
"self",
".",
"max_queries_cnt",
":",
"self",
".",
"queries_cnt",
"+=",
"1",
"return",
"self",
".",
"labels",
"[",
"i",
"]",
"==",
"self",
".",
"labels... | 0dcab86ea22cd66ed7ea64234efdff1c6aca7981 |
valid | preprocess_constraints | Create a graph of constraints for both must- and cannot-links | active_semi_clustering/semi_supervised/pairwise_constraints/constraints.py | def preprocess_constraints(ml, cl, n):
"Create a graph of constraints for both must- and cannot-links"
# Represent the graphs using adjacency-lists
ml_graph, cl_graph = {}, {}
for i in range(n):
ml_graph[i] = set()
cl_graph[i] = set()
def add_both(d, i, j):
d[i].add(j)
... | def preprocess_constraints(ml, cl, n):
"Create a graph of constraints for both must- and cannot-links"
# Represent the graphs using adjacency-lists
ml_graph, cl_graph = {}, {}
for i in range(n):
ml_graph[i] = set()
cl_graph[i] = set()
def add_both(d, i, j):
d[i].add(j)
... | [
"Create",
"a",
"graph",
"of",
"constraints",
"for",
"both",
"must",
"-",
"and",
"cannot",
"-",
"links"
] | datamole-ai/active-semi-supervised-clustering | python | https://github.com/datamole-ai/active-semi-supervised-clustering/blob/0dcab86ea22cd66ed7ea64234efdff1c6aca7981/active_semi_clustering/semi_supervised/pairwise_constraints/constraints.py#L5-L64 | [
"def",
"preprocess_constraints",
"(",
"ml",
",",
"cl",
",",
"n",
")",
":",
"# Represent the graphs using adjacency-lists",
"ml_graph",
",",
"cl_graph",
"=",
"{",
"}",
",",
"{",
"}",
"for",
"i",
"in",
"range",
"(",
"n",
")",
":",
"ml_graph",
"[",
"i",
"]"... | 0dcab86ea22cd66ed7ea64234efdff1c6aca7981 |
valid | make_pmml_pipeline | Translates a regular Scikit-Learn estimator or pipeline to a PMML pipeline.
Parameters:
----------
obj: BaseEstimator
The object.
active_fields: list of strings, optional
Feature names. If missing, "x1", "x2", .., "xn" are assumed.
target_fields: list of strings, optional
Label name(s). If missing, "y" is... | sklearn2pmml/__init__.py | def make_pmml_pipeline(obj, active_fields = None, target_fields = None):
"""Translates a regular Scikit-Learn estimator or pipeline to a PMML pipeline.
Parameters:
----------
obj: BaseEstimator
The object.
active_fields: list of strings, optional
Feature names. If missing, "x1", "x2", .., "xn" are assumed.
... | def make_pmml_pipeline(obj, active_fields = None, target_fields = None):
"""Translates a regular Scikit-Learn estimator or pipeline to a PMML pipeline.
Parameters:
----------
obj: BaseEstimator
The object.
active_fields: list of strings, optional
Feature names. If missing, "x1", "x2", .., "xn" are assumed.
... | [
"Translates",
"a",
"regular",
"Scikit",
"-",
"Learn",
"estimator",
"or",
"pipeline",
"to",
"a",
"PMML",
"pipeline",
"."
] | jpmml/sklearn2pmml | python | https://github.com/jpmml/sklearn2pmml/blob/0a455a54323989473c16f9efc9a77cef3ff64c1e/sklearn2pmml/__init__.py#L107-L128 | [
"def",
"make_pmml_pipeline",
"(",
"obj",
",",
"active_fields",
"=",
"None",
",",
"target_fields",
"=",
"None",
")",
":",
"steps",
"=",
"_filter_steps",
"(",
"_get_steps",
"(",
"obj",
")",
")",
"pipeline",
"=",
"PMMLPipeline",
"(",
"steps",
")",
"if",
"acti... | 0a455a54323989473c16f9efc9a77cef3ff64c1e |
valid | sklearn2pmml | Converts a fitted Scikit-Learn pipeline to PMML.
Parameters:
----------
pipeline: PMMLPipeline
The pipeline.
pmml: string
The path to where the PMML document should be stored.
user_classpath: list of strings, optional
The paths to JAR files that provide custom Transformer, Selector and/or Estimator conver... | sklearn2pmml/__init__.py | def sklearn2pmml(pipeline, pmml, user_classpath = [], with_repr = False, debug = False, java_encoding = "UTF-8"):
"""Converts a fitted Scikit-Learn pipeline to PMML.
Parameters:
----------
pipeline: PMMLPipeline
The pipeline.
pmml: string
The path to where the PMML document should be stored.
user_classpath... | def sklearn2pmml(pipeline, pmml, user_classpath = [], with_repr = False, debug = False, java_encoding = "UTF-8"):
"""Converts a fitted Scikit-Learn pipeline to PMML.
Parameters:
----------
pipeline: PMMLPipeline
The pipeline.
pmml: string
The path to where the PMML document should be stored.
user_classpath... | [
"Converts",
"a",
"fitted",
"Scikit",
"-",
"Learn",
"pipeline",
"to",
"PMML",
"."
] | jpmml/sklearn2pmml | python | https://github.com/jpmml/sklearn2pmml/blob/0a455a54323989473c16f9efc9a77cef3ff64c1e/sklearn2pmml/__init__.py#L181-L258 | [
"def",
"sklearn2pmml",
"(",
"pipeline",
",",
"pmml",
",",
"user_classpath",
"=",
"[",
"]",
",",
"with_repr",
"=",
"False",
",",
"debug",
"=",
"False",
",",
"java_encoding",
"=",
"\"UTF-8\"",
")",
":",
"if",
"debug",
":",
"java_version",
"=",
"_java_version... | 0a455a54323989473c16f9efc9a77cef3ff64c1e |
valid | make_tpot_pmml_config | Translates a regular TPOT configuration to a PMML-compatible TPOT configuration.
Parameters:
----------
obj: config
The configuration dictionary.
user_classpath: list of strings, optional
The paths to JAR files that provide custom Transformer, Selector and/or Estimator converter classes.
The JPMML-SkLearn c... | sklearn2pmml/__init__.py | def make_tpot_pmml_config(config, user_classpath = []):
"""Translates a regular TPOT configuration to a PMML-compatible TPOT configuration.
Parameters:
----------
obj: config
The configuration dictionary.
user_classpath: list of strings, optional
The paths to JAR files that provide custom Transformer, Select... | def make_tpot_pmml_config(config, user_classpath = []):
"""Translates a regular TPOT configuration to a PMML-compatible TPOT configuration.
Parameters:
----------
obj: config
The configuration dictionary.
user_classpath: list of strings, optional
The paths to JAR files that provide custom Transformer, Select... | [
"Translates",
"a",
"regular",
"TPOT",
"configuration",
"to",
"a",
"PMML",
"-",
"compatible",
"TPOT",
"configuration",
"."
] | jpmml/sklearn2pmml | python | https://github.com/jpmml/sklearn2pmml/blob/0a455a54323989473c16f9efc9a77cef3ff64c1e/sklearn2pmml/__init__.py#L284-L300 | [
"def",
"make_tpot_pmml_config",
"(",
"config",
",",
"user_classpath",
"=",
"[",
"]",
")",
":",
"tpot_keys",
"=",
"set",
"(",
"config",
".",
"keys",
"(",
")",
")",
"classes",
"=",
"_supported_classes",
"(",
"user_classpath",
")",
"pmml_keys",
"=",
"(",
"set... | 0a455a54323989473c16f9efc9a77cef3ff64c1e |
valid | BaseFormSetFactory.construct_formset | Returns an instance of the formset | extra_views/formsets.py | def construct_formset(self):
"""
Returns an instance of the formset
"""
formset_class = self.get_formset()
if hasattr(self, 'get_extra_form_kwargs'):
klass = type(self).__name__
raise DeprecationWarning(
'Calling {0}.get_extra_form_kwargs i... | def construct_formset(self):
"""
Returns an instance of the formset
"""
formset_class = self.get_formset()
if hasattr(self, 'get_extra_form_kwargs'):
klass = type(self).__name__
raise DeprecationWarning(
'Calling {0}.get_extra_form_kwargs i... | [
"Returns",
"an",
"instance",
"of",
"the",
"formset"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L24-L36 | [
"def",
"construct_formset",
"(",
"self",
")",
":",
"formset_class",
"=",
"self",
".",
"get_formset",
"(",
")",
"if",
"hasattr",
"(",
"self",
",",
"'get_extra_form_kwargs'",
")",
":",
"klass",
"=",
"type",
"(",
"self",
")",
".",
"__name__",
"raise",
"Deprec... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseFormSetFactory.get_formset_kwargs | Returns the keyword arguments for instantiating the formset. | extra_views/formsets.py | def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
kwargs = self.formset_kwargs.copy()
kwargs.update({
'initial': self.get_initial(),
'prefix': self.get_prefix(),
})
if self.request.method in... | def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
kwargs = self.formset_kwargs.copy()
kwargs.update({
'initial': self.get_initial(),
'prefix': self.get_prefix(),
})
if self.request.method in... | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"formset",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L68-L83 | [
"def",
"get_formset_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"self",
".",
"formset_kwargs",
".",
"copy",
"(",
")",
"kwargs",
".",
"update",
"(",
"{",
"'initial'",
":",
"self",
".",
"get_initial",
"(",
")",
",",
"'prefix'",
":",
"self",
".",
"get_... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseFormSetFactory.get_factory_kwargs | Returns the keyword arguments for calling the formset factory | extra_views/formsets.py | def get_factory_kwargs(self):
"""
Returns the keyword arguments for calling the formset factory
"""
# Perform deprecation check
for attr in ['extra', 'max_num', 'can_order', 'can_delete', 'ct_field',
'formfield_callback', 'fk_name', 'widgets', 'ct_fk_field']:... | def get_factory_kwargs(self):
"""
Returns the keyword arguments for calling the formset factory
"""
# Perform deprecation check
for attr in ['extra', 'max_num', 'can_order', 'can_delete', 'ct_field',
'formfield_callback', 'fk_name', 'widgets', 'ct_fk_field']:... | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"calling",
"the",
"formset",
"factory"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L85-L102 | [
"def",
"get_factory_kwargs",
"(",
"self",
")",
":",
"# Perform deprecation check",
"for",
"attr",
"in",
"[",
"'extra'",
",",
"'max_num'",
",",
"'can_order'",
",",
"'can_delete'",
",",
"'ct_field'",
",",
"'formfield_callback'",
",",
"'fk_name'",
",",
"'widgets'",
"... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | FormSetMixin.get_success_url | Returns the supplied URL. | extra_views/formsets.py | def get_success_url(self):
"""
Returns the supplied URL.
"""
if self.success_url:
url = self.success_url
else:
# Default to returning to the same page
url = self.request.get_full_path()
return url | def get_success_url(self):
"""
Returns the supplied URL.
"""
if self.success_url:
url = self.success_url
else:
# Default to returning to the same page
url = self.request.get_full_path()
return url | [
"Returns",
"the",
"supplied",
"URL",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L120-L129 | [
"def",
"get_success_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"success_url",
":",
"url",
"=",
"self",
".",
"success_url",
"else",
":",
"# Default to returning to the same page",
"url",
"=",
"self",
".",
"request",
".",
"get_full_path",
"(",
")",
"return"... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ModelFormSetMixin.get_formset_kwargs | Returns the keyword arguments for instantiating the formset. | extra_views/formsets.py | def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
kwargs = super(ModelFormSetMixin, self).get_formset_kwargs()
kwargs['queryset'] = self.get_queryset()
return kwargs | def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
kwargs = super(ModelFormSetMixin, self).get_formset_kwargs()
kwargs['queryset'] = self.get_queryset()
return kwargs | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"formset",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L155-L161 | [
"def",
"get_formset_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"super",
"(",
"ModelFormSetMixin",
",",
"self",
")",
".",
"get_formset_kwargs",
"(",
")",
"kwargs",
"[",
"'queryset'",
"]",
"=",
"self",
".",
"get_queryset",
"(",
")",
"return",
"kwargs"
] | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ModelFormSetMixin.formset_valid | If the formset is valid, save the associated models. | extra_views/formsets.py | def formset_valid(self, formset):
"""
If the formset is valid, save the associated models.
"""
self.object_list = formset.save()
return super(ModelFormSetMixin, self).formset_valid(formset) | def formset_valid(self, formset):
"""
If the formset is valid, save the associated models.
"""
self.object_list = formset.save()
return super(ModelFormSetMixin, self).formset_valid(formset) | [
"If",
"the",
"formset",
"is",
"valid",
"save",
"the",
"associated",
"models",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L181-L186 | [
"def",
"formset_valid",
"(",
"self",
",",
"formset",
")",
":",
"self",
".",
"object_list",
"=",
"formset",
".",
"save",
"(",
")",
"return",
"super",
"(",
"ModelFormSetMixin",
",",
"self",
")",
".",
"formset_valid",
"(",
"formset",
")"
] | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseInlineFormSetFactory.get_formset_kwargs | Returns the keyword arguments for instantiating the formset. | extra_views/formsets.py | def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
# Perform deprecation check
if hasattr(self, 'save_as_new'):
klass = type(self).__name__
raise DeprecationWarning(
'Setting `{0}.save_as_new`... | def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
# Perform deprecation check
if hasattr(self, 'save_as_new'):
klass = type(self).__name__
raise DeprecationWarning(
'Setting `{0}.save_as_new`... | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"formset",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L206-L219 | [
"def",
"get_formset_kwargs",
"(",
"self",
")",
":",
"# Perform deprecation check",
"if",
"hasattr",
"(",
"self",
",",
"'save_as_new'",
")",
":",
"klass",
"=",
"type",
"(",
"self",
")",
".",
"__name__",
"raise",
"DeprecationWarning",
"(",
"'Setting `{0}.save_as_new... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseInlineFormSetFactory.get_factory_kwargs | Returns the keyword arguments for calling the formset factory | extra_views/formsets.py | def get_factory_kwargs(self):
"""
Returns the keyword arguments for calling the formset factory
"""
kwargs = super(BaseInlineFormSetFactory, self).get_factory_kwargs()
kwargs.setdefault('fields', self.fields)
kwargs.setdefault('exclude', self.exclude)
if self.get... | def get_factory_kwargs(self):
"""
Returns the keyword arguments for calling the formset factory
"""
kwargs = super(BaseInlineFormSetFactory, self).get_factory_kwargs()
kwargs.setdefault('fields', self.fields)
kwargs.setdefault('exclude', self.exclude)
if self.get... | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"calling",
"the",
"formset",
"factory"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L221-L231 | [
"def",
"get_factory_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"super",
"(",
"BaseInlineFormSetFactory",
",",
"self",
")",
".",
"get_factory_kwargs",
"(",
")",
"kwargs",
".",
"setdefault",
"(",
"'fields'",
",",
"self",
".",
"fields",
")",
"kwargs",
".",
... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ProcessFormSetView.get | Handles GET requests and instantiates a blank version of the formset. | extra_views/formsets.py | def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates a blank version of the formset.
"""
formset = self.construct_formset()
return self.render_to_response(self.get_context_data(formset=formset)) | def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates a blank version of the formset.
"""
formset = self.construct_formset()
return self.render_to_response(self.get_context_data(formset=formset)) | [
"Handles",
"GET",
"requests",
"and",
"instantiates",
"a",
"blank",
"version",
"of",
"the",
"formset",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L264-L269 | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"formset",
"=",
"self",
".",
"construct_formset",
"(",
")",
"return",
"self",
".",
"render_to_response",
"(",
"self",
".",
"get_context_data",
"(",
"formset",... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ProcessFormSetView.post | Handles POST requests, instantiating a formset instance with the passed
POST variables and then checked for validity. | extra_views/formsets.py | def post(self, request, *args, **kwargs):
"""
Handles POST requests, instantiating a formset instance with the passed
POST variables and then checked for validity.
"""
formset = self.construct_formset()
if formset.is_valid():
return self.formset_valid(formset)... | def post(self, request, *args, **kwargs):
"""
Handles POST requests, instantiating a formset instance with the passed
POST variables and then checked for validity.
"""
formset = self.construct_formset()
if formset.is_valid():
return self.formset_valid(formset)... | [
"Handles",
"POST",
"requests",
"instantiating",
"a",
"formset",
"instance",
"with",
"the",
"passed",
"POST",
"variables",
"and",
"then",
"checked",
"for",
"validity",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/formsets.py#L271-L280 | [
"def",
"post",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"formset",
"=",
"self",
".",
"construct_formset",
"(",
")",
"if",
"formset",
".",
"is_valid",
"(",
")",
":",
"return",
"self",
".",
"formset_valid",
"(",... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | InlineFormSetFactory.construct_formset | Overrides construct_formset to attach the model class as
an attribute of the returned formset instance. | extra_views/advanced.py | def construct_formset(self):
"""
Overrides construct_formset to attach the model class as
an attribute of the returned formset instance.
"""
formset = super(InlineFormSetFactory, self).construct_formset()
formset.model = self.inline_model
return formset | def construct_formset(self):
"""
Overrides construct_formset to attach the model class as
an attribute of the returned formset instance.
"""
formset = super(InlineFormSetFactory, self).construct_formset()
formset.model = self.inline_model
return formset | [
"Overrides",
"construct_formset",
"to",
"attach",
"the",
"model",
"class",
"as",
"an",
"attribute",
"of",
"the",
"returned",
"formset",
"instance",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L28-L35 | [
"def",
"construct_formset",
"(",
"self",
")",
":",
"formset",
"=",
"super",
"(",
"InlineFormSetFactory",
",",
"self",
")",
".",
"construct_formset",
"(",
")",
"formset",
".",
"model",
"=",
"self",
".",
"inline_model",
"return",
"formset"
] | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ModelFormWithInlinesMixin.forms_valid | If the form and formsets are valid, save the associated models. | extra_views/advanced.py | def forms_valid(self, form, inlines):
"""
If the form and formsets are valid, save the associated models.
"""
response = self.form_valid(form)
for formset in inlines:
formset.save()
return response | def forms_valid(self, form, inlines):
"""
If the form and formsets are valid, save the associated models.
"""
response = self.form_valid(form)
for formset in inlines:
formset.save()
return response | [
"If",
"the",
"form",
"and",
"formsets",
"are",
"valid",
"save",
"the",
"associated",
"models",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L61-L68 | [
"def",
"forms_valid",
"(",
"self",
",",
"form",
",",
"inlines",
")",
":",
"response",
"=",
"self",
".",
"form_valid",
"(",
"form",
")",
"for",
"formset",
"in",
"inlines",
":",
"formset",
".",
"save",
"(",
")",
"return",
"response"
] | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ModelFormWithInlinesMixin.forms_invalid | If the form or formsets are invalid, re-render the context data with the
data-filled form and formsets and errors. | extra_views/advanced.py | def forms_invalid(self, form, inlines):
"""
If the form or formsets are invalid, re-render the context data with the
data-filled form and formsets and errors.
"""
return self.render_to_response(self.get_context_data(form=form, inlines=inlines)) | def forms_invalid(self, form, inlines):
"""
If the form or formsets are invalid, re-render the context data with the
data-filled form and formsets and errors.
"""
return self.render_to_response(self.get_context_data(form=form, inlines=inlines)) | [
"If",
"the",
"form",
"or",
"formsets",
"are",
"invalid",
"re",
"-",
"render",
"the",
"context",
"data",
"with",
"the",
"data",
"-",
"filled",
"form",
"and",
"formsets",
"and",
"errors",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L70-L75 | [
"def",
"forms_invalid",
"(",
"self",
",",
"form",
",",
"inlines",
")",
":",
"return",
"self",
".",
"render_to_response",
"(",
"self",
".",
"get_context_data",
"(",
"form",
"=",
"form",
",",
"inlines",
"=",
"inlines",
")",
")"
] | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ModelFormWithInlinesMixin.construct_inlines | Returns the inline formset instances | extra_views/advanced.py | def construct_inlines(self):
"""
Returns the inline formset instances
"""
inline_formsets = []
for inline_class in self.get_inlines():
inline_instance = inline_class(self.model, self.request, self.object, self.kwargs, self)
inline_formset = inline_instance... | def construct_inlines(self):
"""
Returns the inline formset instances
"""
inline_formsets = []
for inline_class in self.get_inlines():
inline_instance = inline_class(self.model, self.request, self.object, self.kwargs, self)
inline_formset = inline_instance... | [
"Returns",
"the",
"inline",
"formset",
"instances"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L77-L86 | [
"def",
"construct_inlines",
"(",
"self",
")",
":",
"inline_formsets",
"=",
"[",
"]",
"for",
"inline_class",
"in",
"self",
".",
"get_inlines",
"(",
")",
":",
"inline_instance",
"=",
"inline_class",
"(",
"self",
".",
"model",
",",
"self",
".",
"request",
","... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ProcessFormWithInlinesView.get | Handles GET requests and instantiates a blank version of the form and formsets. | extra_views/advanced.py | def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates a blank version of the form and formsets.
"""
form_class = self.get_form_class()
form = self.get_form(form_class)
inlines = self.construct_inlines()
return self.render_to_response(s... | def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates a blank version of the form and formsets.
"""
form_class = self.get_form_class()
form = self.get_form(form_class)
inlines = self.construct_inlines()
return self.render_to_response(s... | [
"Handles",
"GET",
"requests",
"and",
"instantiates",
"a",
"blank",
"version",
"of",
"the",
"form",
"and",
"formsets",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L94-L101 | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"form_class",
"=",
"self",
".",
"get_form_class",
"(",
")",
"form",
"=",
"self",
".",
"get_form",
"(",
"form_class",
")",
"inlines",
"=",
"self",
".",
"... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | ProcessFormWithInlinesView.post | Handles POST requests, instantiating a form and formset instances with the passed
POST variables and then checked for validity. | extra_views/advanced.py | def post(self, request, *args, **kwargs):
"""
Handles POST requests, instantiating a form and formset instances with the passed
POST variables and then checked for validity.
"""
form_class = self.get_form_class()
form = self.get_form(form_class)
if form.is_valid(... | def post(self, request, *args, **kwargs):
"""
Handles POST requests, instantiating a form and formset instances with the passed
POST variables and then checked for validity.
"""
form_class = self.get_form_class()
form = self.get_form(form_class)
if form.is_valid(... | [
"Handles",
"POST",
"requests",
"instantiating",
"a",
"form",
"and",
"formset",
"instances",
"with",
"the",
"passed",
"POST",
"variables",
"and",
"then",
"checked",
"for",
"validity",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L103-L121 | [
"def",
"post",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"form_class",
"=",
"self",
".",
"get_form_class",
"(",
")",
"form",
"=",
"self",
".",
"get_form",
"(",
"form_class",
")",
"if",
"form",
".",
"is_valid",
... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | NamedFormsetsMixin.get_context_data | If `inlines_names` has been defined, add each formset to the context under
its corresponding entry in `inlines_names` | extra_views/advanced.py | def get_context_data(self, **kwargs):
"""
If `inlines_names` has been defined, add each formset to the context under
its corresponding entry in `inlines_names`
"""
context = {}
inlines_names = self.get_inlines_names()
if inlines_names:
# We have forms... | def get_context_data(self, **kwargs):
"""
If `inlines_names` has been defined, add each formset to the context under
its corresponding entry in `inlines_names`
"""
context = {}
inlines_names = self.get_inlines_names()
if inlines_names:
# We have forms... | [
"If",
"inlines_names",
"has",
"been",
"defined",
"add",
"each",
"formset",
"to",
"the",
"context",
"under",
"its",
"corresponding",
"entry",
"in",
"inlines_names"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/advanced.py#L190-L204 | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"{",
"}",
"inlines_names",
"=",
"self",
".",
"get_inlines_names",
"(",
")",
"if",
"inlines_names",
":",
"# We have formset or inlines in context, but never both",
"context",
... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | SearchableListMixin.try_convert_to_date | Tries to convert word to date(datetime) using search_date_formats
Return None if word fits no one format | extra_views/contrib/mixins.py | def try_convert_to_date(self, word):
"""
Tries to convert word to date(datetime) using search_date_formats
Return None if word fits no one format
"""
for frm in self.search_date_formats:
try:
return datetime.datetime.strptime(word, frm).date()
... | def try_convert_to_date(self, word):
"""
Tries to convert word to date(datetime) using search_date_formats
Return None if word fits no one format
"""
for frm in self.search_date_formats:
try:
return datetime.datetime.strptime(word, frm).date()
... | [
"Tries",
"to",
"convert",
"word",
"to",
"date",
"(",
"datetime",
")",
"using",
"search_date_formats",
"Return",
"None",
"if",
"word",
"fits",
"no",
"one",
"format"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/contrib/mixins.py#L60-L70 | [
"def",
"try_convert_to_date",
"(",
"self",
",",
"word",
")",
":",
"for",
"frm",
"in",
"self",
".",
"search_date_formats",
":",
"try",
":",
"return",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"word",
",",
"frm",
")",
".",
"date",
"(",
")",
"exc... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | SortHelper.get_params_for_field | If sort_type is None - inverse current sort for field, if no sorted - use asc | extra_views/contrib/mixins.py | def get_params_for_field(self, field_name, sort_type=None):
"""
If sort_type is None - inverse current sort for field, if no sorted - use asc
"""
if not sort_type:
if self.initial_sort == field_name:
sort_type = 'desc' if self.initial_sort_type == 'asc' else '... | def get_params_for_field(self, field_name, sort_type=None):
"""
If sort_type is None - inverse current sort for field, if no sorted - use asc
"""
if not sort_type:
if self.initial_sort == field_name:
sort_type = 'desc' if self.initial_sort_type == 'asc' else '... | [
"If",
"sort_type",
"is",
"None",
"-",
"inverse",
"current",
"sort",
"for",
"field",
"if",
"no",
"sorted",
"-",
"use",
"asc"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/contrib/mixins.py#L120-L131 | [
"def",
"get_params_for_field",
"(",
"self",
",",
"field_name",
",",
"sort_type",
"=",
"None",
")",
":",
"if",
"not",
"sort_type",
":",
"if",
"self",
".",
"initial_sort",
"==",
"field_name",
":",
"sort_type",
"=",
"'desc'",
"if",
"self",
".",
"initial_sort_ty... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseCalendarMonthView.get_start_date | Returns the start date for a model instance | extra_views/dates.py | def get_start_date(self, obj):
"""
Returns the start date for a model instance
"""
obj_date = getattr(obj, self.get_date_field())
try:
obj_date = obj_date.date()
except AttributeError:
# It's a date rather than datetime, so we use it as is
... | def get_start_date(self, obj):
"""
Returns the start date for a model instance
"""
obj_date = getattr(obj, self.get_date_field())
try:
obj_date = obj_date.date()
except AttributeError:
# It's a date rather than datetime, so we use it as is
... | [
"Returns",
"the",
"start",
"date",
"for",
"a",
"model",
"instance"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/dates.py#L56-L66 | [
"def",
"get_start_date",
"(",
"self",
",",
"obj",
")",
":",
"obj_date",
"=",
"getattr",
"(",
"obj",
",",
"self",
".",
"get_date_field",
"(",
")",
")",
"try",
":",
"obj_date",
"=",
"obj_date",
".",
"date",
"(",
")",
"except",
"AttributeError",
":",
"# I... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseCalendarMonthView.get_end_date | Returns the end date for a model instance | extra_views/dates.py | def get_end_date(self, obj):
"""
Returns the end date for a model instance
"""
obj_date = getattr(obj, self.get_end_date_field())
try:
obj_date = obj_date.date()
except AttributeError:
# It's a date rather than datetime, so we use it as is
... | def get_end_date(self, obj):
"""
Returns the end date for a model instance
"""
obj_date = getattr(obj, self.get_end_date_field())
try:
obj_date = obj_date.date()
except AttributeError:
# It's a date rather than datetime, so we use it as is
... | [
"Returns",
"the",
"end",
"date",
"for",
"a",
"model",
"instance"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/dates.py#L68-L78 | [
"def",
"get_end_date",
"(",
"self",
",",
"obj",
")",
":",
"obj_date",
"=",
"getattr",
"(",
"obj",
",",
"self",
".",
"get_end_date_field",
"(",
")",
")",
"try",
":",
"obj_date",
"=",
"obj_date",
".",
"date",
"(",
")",
"except",
"AttributeError",
":",
"#... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseCalendarMonthView.get_first_of_week | Returns an integer representing the first day of the week.
0 represents Monday, 6 represents Sunday. | extra_views/dates.py | def get_first_of_week(self):
"""
Returns an integer representing the first day of the week.
0 represents Monday, 6 represents Sunday.
"""
if self.first_of_week is None:
raise ImproperlyConfigured("%s.first_of_week is required." % self.__class__.__name__)
if s... | def get_first_of_week(self):
"""
Returns an integer representing the first day of the week.
0 represents Monday, 6 represents Sunday.
"""
if self.first_of_week is None:
raise ImproperlyConfigured("%s.first_of_week is required." % self.__class__.__name__)
if s... | [
"Returns",
"an",
"integer",
"representing",
"the",
"first",
"day",
"of",
"the",
"week",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/dates.py#L80-L90 | [
"def",
"get_first_of_week",
"(",
"self",
")",
":",
"if",
"self",
".",
"first_of_week",
"is",
"None",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"%s.first_of_week is required.\"",
"%",
"self",
".",
"__class__",
".",
"__name__",
")",
"if",
"self",
".",
"first_of... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseCalendarMonthView.get_queryset | Returns a queryset of models for the month requested | extra_views/dates.py | def get_queryset(self):
"""
Returns a queryset of models for the month requested
"""
qs = super(BaseCalendarMonthView, self).get_queryset()
year = self.get_year()
month = self.get_month()
date_field = self.get_date_field()
end_date_field = self.get_end_d... | def get_queryset(self):
"""
Returns a queryset of models for the month requested
"""
qs = super(BaseCalendarMonthView, self).get_queryset()
year = self.get_year()
month = self.get_month()
date_field = self.get_date_field()
end_date_field = self.get_end_d... | [
"Returns",
"a",
"queryset",
"of",
"models",
"for",
"the",
"month",
"requested"
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/dates.py#L92-L153 | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"super",
"(",
"BaseCalendarMonthView",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"year",
"=",
"self",
".",
"get_year",
"(",
")",
"month",
"=",
"self",
".",
"get_month",
"(",
")",
"date_fie... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | BaseCalendarMonthView.get_context_data | Injects variables necessary for rendering the calendar into the context.
Variables added are: `calendar`, `weekdays`, `month`, `next_month` and `previous_month`. | extra_views/dates.py | def get_context_data(self, **kwargs):
"""
Injects variables necessary for rendering the calendar into the context.
Variables added are: `calendar`, `weekdays`, `month`, `next_month` and `previous_month`.
"""
data = super(BaseCalendarMonthView, self).get_context_data(**kwargs)
... | def get_context_data(self, **kwargs):
"""
Injects variables necessary for rendering the calendar into the context.
Variables added are: `calendar`, `weekdays`, `month`, `next_month` and `previous_month`.
"""
data = super(BaseCalendarMonthView, self).get_context_data(**kwargs)
... | [
"Injects",
"variables",
"necessary",
"for",
"rendering",
"the",
"calendar",
"into",
"the",
"context",
"."
] | AndrewIngram/django-extra-views | python | https://github.com/AndrewIngram/django-extra-views/blob/188e1bf1f15a44d9a599028d020083af9fb43ea7/extra_views/dates.py#L155-L239 | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"super",
"(",
"BaseCalendarMonthView",
",",
"self",
")",
".",
"get_context_data",
"(",
"*",
"*",
"kwargs",
")",
"year",
"=",
"self",
".",
"get_year",
"(",
")",
"mon... | 188e1bf1f15a44d9a599028d020083af9fb43ea7 |
valid | read_version | Read version from __init__.py without loading any files | setup.py | def read_version():
"""Read version from __init__.py without loading any files"""
finder = VersionFinder()
path = os.path.join(PROJECT_ROOT, 'colorful', '__init__.py')
with codecs.open(path, 'r', encoding='utf-8') as fp:
file_data = fp.read().encode('utf-8')
finder.visit(ast.parse(file_d... | def read_version():
"""Read version from __init__.py without loading any files"""
finder = VersionFinder()
path = os.path.join(PROJECT_ROOT, 'colorful', '__init__.py')
with codecs.open(path, 'r', encoding='utf-8') as fp:
file_data = fp.read().encode('utf-8')
finder.visit(ast.parse(file_d... | [
"Read",
"version",
"from",
"__init__",
".",
"py",
"without",
"loading",
"any",
"files"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/setup.py#L48-L56 | [
"def",
"read_version",
"(",
")",
":",
"finder",
"=",
"VersionFinder",
"(",
")",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"PROJECT_ROOT",
",",
"'colorful'",
",",
"'__init__.py'",
")",
"with",
"codecs",
".",
"open",
"(",
"path",
",",
"'r'",
",",... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | ColorfulModule.with_setup | Return a new Colorful object with the given color config. | colorful/__init__.py | def with_setup(self, colormode=None, colorpalette=None, extend_colors=False):
"""
Return a new Colorful object with the given color config.
"""
colorful = Colorful(
colormode=self.colorful.colormode,
colorpalette=copy.copy(self.colorful.colorpalette)
)
... | def with_setup(self, colormode=None, colorpalette=None, extend_colors=False):
"""
Return a new Colorful object with the given color config.
"""
colorful = Colorful(
colormode=self.colorful.colormode,
colorpalette=copy.copy(self.colorful.colorpalette)
)
... | [
"Return",
"a",
"new",
"Colorful",
"object",
"with",
"the",
"given",
"color",
"config",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/__init__.py#L42-L54 | [
"def",
"with_setup",
"(",
"self",
",",
"colormode",
"=",
"None",
",",
"colorpalette",
"=",
"None",
",",
"extend_colors",
"=",
"False",
")",
":",
"colorful",
"=",
"Colorful",
"(",
"colormode",
"=",
"self",
".",
"colorful",
".",
"colormode",
",",
"colorpalet... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | parse_colors | Parse the given color files.
Supported are:
* .txt for X11 colors
* .json for colornames | colorful/colors.py | def parse_colors(path):
"""Parse the given color files.
Supported are:
* .txt for X11 colors
* .json for colornames
"""
if path.endswith(".txt"):
return parse_rgb_txt_file(path)
elif path.endswith(".json"):
return parse_json_color_file(path)
raise TypeError("col... | def parse_colors(path):
"""Parse the given color files.
Supported are:
* .txt for X11 colors
* .json for colornames
"""
if path.endswith(".txt"):
return parse_rgb_txt_file(path)
elif path.endswith(".json"):
return parse_json_color_file(path)
raise TypeError("col... | [
"Parse",
"the",
"given",
"color",
"files",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/colors.py#L18-L30 | [
"def",
"parse_colors",
"(",
"path",
")",
":",
"if",
"path",
".",
"endswith",
"(",
"\".txt\"",
")",
":",
"return",
"parse_rgb_txt_file",
"(",
"path",
")",
"elif",
"path",
".",
"endswith",
"(",
"\".json\"",
")",
":",
"return",
"parse_json_color_file",
"(",
"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | parse_rgb_txt_file | Parse the given rgb.txt file into a Python dict.
See https://en.wikipedia.org/wiki/X11_color_names for more information
:param str path: the path to the X11 rgb.txt file | colorful/colors.py | def parse_rgb_txt_file(path):
"""
Parse the given rgb.txt file into a Python dict.
See https://en.wikipedia.org/wiki/X11_color_names for more information
:param str path: the path to the X11 rgb.txt file
"""
#: Holds the generated color dict
color_dict = {}
with open(path, 'r') as rgb... | def parse_rgb_txt_file(path):
"""
Parse the given rgb.txt file into a Python dict.
See https://en.wikipedia.org/wiki/X11_color_names for more information
:param str path: the path to the X11 rgb.txt file
"""
#: Holds the generated color dict
color_dict = {}
with open(path, 'r') as rgb... | [
"Parse",
"the",
"given",
"rgb",
".",
"txt",
"file",
"into",
"a",
"Python",
"dict",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/colors.py#L33-L53 | [
"def",
"parse_rgb_txt_file",
"(",
"path",
")",
":",
"#: Holds the generated color dict",
"color_dict",
"=",
"{",
"}",
"with",
"open",
"(",
"path",
",",
"'r'",
")",
"as",
"rgb_txt",
":",
"for",
"line",
"in",
"rgb_txt",
":",
"line",
"=",
"line",
".",
"strip"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | parse_json_color_file | Parse a JSON color file.
The JSON has to be in the following format:
.. code:: json
[{"name": "COLOR_NAME", "hex": "#HEX"}, ...]
:param str path: the path to the JSON color file | colorful/colors.py | def parse_json_color_file(path):
"""Parse a JSON color file.
The JSON has to be in the following format:
.. code:: json
[{"name": "COLOR_NAME", "hex": "#HEX"}, ...]
:param str path: the path to the JSON color file
"""
with open(path, "r") as color_file:
color_list = json.load(... | def parse_json_color_file(path):
"""Parse a JSON color file.
The JSON has to be in the following format:
.. code:: json
[{"name": "COLOR_NAME", "hex": "#HEX"}, ...]
:param str path: the path to the JSON color file
"""
with open(path, "r") as color_file:
color_list = json.load(... | [
"Parse",
"a",
"JSON",
"color",
"file",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/colors.py#L56-L72 | [
"def",
"parse_json_color_file",
"(",
"path",
")",
":",
"with",
"open",
"(",
"path",
",",
"\"r\"",
")",
"as",
"color_file",
":",
"color_list",
"=",
"json",
".",
"load",
"(",
"color_file",
")",
"# transform raw color list into color dict",
"color_dict",
"=",
"{",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | sanitize_color_palette | Sanitze the given color palette so it can
be safely used by Colorful.
It will convert colors specified in hex RGB to
a RGB channel triplet. | colorful/colors.py | def sanitize_color_palette(colorpalette):
"""
Sanitze the given color palette so it can
be safely used by Colorful.
It will convert colors specified in hex RGB to
a RGB channel triplet.
"""
new_palette = {}
def __make_valid_color_name(name):
"""
Convert the given name i... | def sanitize_color_palette(colorpalette):
"""
Sanitze the given color palette so it can
be safely used by Colorful.
It will convert colors specified in hex RGB to
a RGB channel triplet.
"""
new_palette = {}
def __make_valid_color_name(name):
"""
Convert the given name i... | [
"Sanitze",
"the",
"given",
"color",
"palette",
"so",
"it",
"can",
"be",
"safely",
"used",
"by",
"Colorful",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/colors.py#L75-L101 | [
"def",
"sanitize_color_palette",
"(",
"colorpalette",
")",
":",
"new_palette",
"=",
"{",
"}",
"def",
"__make_valid_color_name",
"(",
"name",
")",
":",
"\"\"\"\n Convert the given name into a valid colorname\n \"\"\"",
"if",
"len",
"(",
"name",
")",
"==",
"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | show | Show the modifiers and colors | examples/colors.py | def show():
"""
Show the modifiers and colors
"""
# modifiers
sys.stdout.write(colorful.bold('bold') + ' ')
sys.stdout.write(colorful.dimmed('dimmed') + ' ')
sys.stdout.write(colorful.italic('italic') + ' ')
sys.stdout.write(colorful.underlined('underlined') + ' ')
sys.stdout.write(c... | def show():
"""
Show the modifiers and colors
"""
# modifiers
sys.stdout.write(colorful.bold('bold') + ' ')
sys.stdout.write(colorful.dimmed('dimmed') + ' ')
sys.stdout.write(colorful.italic('italic') + ' ')
sys.stdout.write(colorful.underlined('underlined') + ' ')
sys.stdout.write(c... | [
"Show",
"the",
"modifiers",
"and",
"colors"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/examples/colors.py#L18-L47 | [
"def",
"show",
"(",
")",
":",
"# modifiers",
"sys",
".",
"stdout",
".",
"write",
"(",
"colorful",
".",
"bold",
"(",
"'bold'",
")",
"+",
"' '",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"colorful",
".",
"dimmed",
"(",
"'dimmed'",
")",
"+",
"' '"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | show | Show the modifiers and colors | examples/monokai.py | def show():
"""
Show the modifiers and colors
"""
with colorful.with_style('monokai') as c:
# modifiers
sys.stdout.write(c.bold('bold') + ' ')
sys.stdout.write(c.dimmed('dimmed') + ' ')
sys.stdout.write(c.italic('italic') + ' ')
sys.stdout.write(c.underlined('unde... | def show():
"""
Show the modifiers and colors
"""
with colorful.with_style('monokai') as c:
# modifiers
sys.stdout.write(c.bold('bold') + ' ')
sys.stdout.write(c.dimmed('dimmed') + ' ')
sys.stdout.write(c.italic('italic') + ' ')
sys.stdout.write(c.underlined('unde... | [
"Show",
"the",
"modifiers",
"and",
"colors"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/examples/monokai.py#L19-L49 | [
"def",
"show",
"(",
")",
":",
"with",
"colorful",
".",
"with_style",
"(",
"'monokai'",
")",
"as",
"c",
":",
"# modifiers",
"sys",
".",
"stdout",
".",
"write",
"(",
"c",
".",
"bold",
"(",
"'bold'",
")",
"+",
"' '",
")",
"sys",
".",
"stdout",
".",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | detect_color_support | Detect what color palettes are supported.
It'll return a valid color mode to use
with colorful.
:param dict env: the environment dict like returned by ``os.envion`` | colorful/terminal.py | def detect_color_support(env): # noqa
"""
Detect what color palettes are supported.
It'll return a valid color mode to use
with colorful.
:param dict env: the environment dict like returned by ``os.envion``
"""
if env.get('COLORFUL_DISABLE', '0') == '1':
return NO_COLORS
if en... | def detect_color_support(env): # noqa
"""
Detect what color palettes are supported.
It'll return a valid color mode to use
with colorful.
:param dict env: the environment dict like returned by ``os.envion``
"""
if env.get('COLORFUL_DISABLE', '0') == '1':
return NO_COLORS
if en... | [
"Detect",
"what",
"color",
"palettes",
"are",
"supported",
".",
"It",
"ll",
"return",
"a",
"valid",
"color",
"mode",
"to",
"use",
"with",
"colorful",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/terminal.py#L24-L80 | [
"def",
"detect_color_support",
"(",
"env",
")",
":",
"# noqa",
"if",
"env",
".",
"get",
"(",
"'COLORFUL_DISABLE'",
",",
"'0'",
")",
"==",
"'1'",
":",
"return",
"NO_COLORS",
"if",
"env",
".",
"get",
"(",
"'COLORFUL_FORCE_8_COLORS'",
",",
"'0'",
")",
"==",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | rgb_to_ansi256 | Convert RGB to ANSI 256 color | colorful/ansi.py | def rgb_to_ansi256(r, g, b):
"""
Convert RGB to ANSI 256 color
"""
if r == g and g == b:
if r < 8:
return 16
if r > 248:
return 231
return round(((r - 8) / 247.0) * 24) + 232
ansi_r = 36 * round(r / 255.0 * 5.0)
ansi_g = 6 * round(g / 255.0 * 5.0... | def rgb_to_ansi256(r, g, b):
"""
Convert RGB to ANSI 256 color
"""
if r == g and g == b:
if r < 8:
return 16
if r > 248:
return 231
return round(((r - 8) / 247.0) * 24) + 232
ansi_r = 36 * round(r / 255.0 * 5.0)
ansi_g = 6 * round(g / 255.0 * 5.0... | [
"Convert",
"RGB",
"to",
"ANSI",
"256",
"color"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/ansi.py#L61-L77 | [
"def",
"rgb_to_ansi256",
"(",
"r",
",",
"g",
",",
"b",
")",
":",
"if",
"r",
"==",
"g",
"and",
"g",
"==",
"b",
":",
"if",
"r",
"<",
"8",
":",
"return",
"16",
"if",
"r",
">",
"248",
":",
"return",
"231",
"return",
"round",
"(",
"(",
"(",
"r",... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | rgb_to_ansi16 | Convert RGB to ANSI 16 color | colorful/ansi.py | def rgb_to_ansi16(r, g, b, use_bright=False):
"""
Convert RGB to ANSI 16 color
"""
ansi_b = round(b / 255.0) << 2
ansi_g = round(g / 255.0) << 1
ansi_r = round(r / 255.0)
ansi = (90 if use_bright else 30) + (ansi_b | ansi_g | ansi_r)
return ansi | def rgb_to_ansi16(r, g, b, use_bright=False):
"""
Convert RGB to ANSI 16 color
"""
ansi_b = round(b / 255.0) << 2
ansi_g = round(g / 255.0) << 1
ansi_r = round(r / 255.0)
ansi = (90 if use_bright else 30) + (ansi_b | ansi_g | ansi_r)
return ansi | [
"Convert",
"RGB",
"to",
"ANSI",
"16",
"color"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/ansi.py#L80-L89 | [
"def",
"rgb_to_ansi16",
"(",
"r",
",",
"g",
",",
"b",
",",
"use_bright",
"=",
"False",
")",
":",
"ansi_b",
"=",
"round",
"(",
"b",
"/",
"255.0",
")",
"<<",
"2",
"ansi_g",
"=",
"round",
"(",
"g",
"/",
"255.0",
")",
"<<",
"1",
"ansi_r",
"=",
"rou... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | hex_to_rgb | Convert the given hex string to a
valid RGB channel triplet. | colorful/utils.py | def hex_to_rgb(value):
"""
Convert the given hex string to a
valid RGB channel triplet.
"""
value = value.lstrip('#')
check_hex(value)
length = len(value)
step = int(length / 3)
return tuple(int(value[i:i+step], 16) for i in range(0, length, step)) | def hex_to_rgb(value):
"""
Convert the given hex string to a
valid RGB channel triplet.
"""
value = value.lstrip('#')
check_hex(value)
length = len(value)
step = int(length / 3)
return tuple(int(value[i:i+step], 16) for i in range(0, length, step)) | [
"Convert",
"the",
"given",
"hex",
"string",
"to",
"a",
"valid",
"RGB",
"channel",
"triplet",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/utils.py#L30-L40 | [
"def",
"hex_to_rgb",
"(",
"value",
")",
":",
"value",
"=",
"value",
".",
"lstrip",
"(",
"'#'",
")",
"check_hex",
"(",
"value",
")",
"length",
"=",
"len",
"(",
"value",
")",
"step",
"=",
"int",
"(",
"length",
"/",
"3",
")",
"return",
"tuple",
"(",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | check_hex | Check if the given hex value is a valid RGB color
It should match the format: [0-9a-fA-F]
and be of length 3 or 6. | colorful/utils.py | def check_hex(value):
"""
Check if the given hex value is a valid RGB color
It should match the format: [0-9a-fA-F]
and be of length 3 or 6.
"""
length = len(value)
if length not in (3, 6):
raise ValueError('Hex string #{} is too long'.format(value))
regex = r'[0-9a-f]{{{length... | def check_hex(value):
"""
Check if the given hex value is a valid RGB color
It should match the format: [0-9a-fA-F]
and be of length 3 or 6.
"""
length = len(value)
if length not in (3, 6):
raise ValueError('Hex string #{} is too long'.format(value))
regex = r'[0-9a-f]{{{length... | [
"Check",
"if",
"the",
"given",
"hex",
"value",
"is",
"a",
"valid",
"RGB",
"color"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/utils.py#L43-L56 | [
"def",
"check_hex",
"(",
"value",
")",
":",
"length",
"=",
"len",
"(",
"value",
")",
"if",
"length",
"not",
"in",
"(",
"3",
",",
"6",
")",
":",
"raise",
"ValueError",
"(",
"'Hex string #{} is too long'",
".",
"format",
"(",
"value",
")",
")",
"regex",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | show | Show the modifiers and colors | examples/solarized.py | def show():
"""
Show the modifiers and colors
"""
with colorful.with_style('solarized') as c:
# modifiers
sys.stdout.write(c.bold('bold') + ' ')
sys.stdout.write(c.dimmed('dimmed') + ' ')
sys.stdout.write(c.italic('italic') + ' ')
sys.stdout.write(c.underlined('un... | def show():
"""
Show the modifiers and colors
"""
with colorful.with_style('solarized') as c:
# modifiers
sys.stdout.write(c.bold('bold') + ' ')
sys.stdout.write(c.dimmed('dimmed') + ' ')
sys.stdout.write(c.italic('italic') + ' ')
sys.stdout.write(c.underlined('un... | [
"Show",
"the",
"modifiers",
"and",
"colors"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/examples/solarized.py#L17-L49 | [
"def",
"show",
"(",
")",
":",
"with",
"colorful",
".",
"with_style",
"(",
"'solarized'",
")",
"as",
"c",
":",
"# modifiers",
"sys",
".",
"stdout",
".",
"write",
"(",
"c",
".",
"bold",
"(",
"'bold'",
")",
"+",
"' '",
")",
"sys",
".",
"stdout",
".",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | translate_rgb_to_ansi_code | Translate the given RGB color into the appropriate ANSI escape code
for the given color mode.
The offset is used for the base color which is used.
The ``colormode`` has to be one of:
* 0: no colors / disabled
* 8: use ANSI 8 colors
* 16: use ANSI 16 colors (same as 8 but with bright... | colorful/core.py | def translate_rgb_to_ansi_code(red, green, blue, offset, colormode):
"""
Translate the given RGB color into the appropriate ANSI escape code
for the given color mode.
The offset is used for the base color which is used.
The ``colormode`` has to be one of:
* 0: no colors / disabled
*... | def translate_rgb_to_ansi_code(red, green, blue, offset, colormode):
"""
Translate the given RGB color into the appropriate ANSI escape code
for the given color mode.
The offset is used for the base color which is used.
The ``colormode`` has to be one of:
* 0: no colors / disabled
*... | [
"Translate",
"the",
"given",
"RGB",
"color",
"into",
"the",
"appropriate",
"ANSI",
"escape",
"code",
"for",
"the",
"given",
"color",
"mode",
".",
"The",
"offset",
"is",
"used",
"for",
"the",
"base",
"color",
"which",
"is",
"used",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L43-L85 | [
"def",
"translate_rgb_to_ansi_code",
"(",
"red",
",",
"green",
",",
"blue",
",",
"offset",
",",
"colormode",
")",
":",
"if",
"colormode",
"==",
"terminal",
".",
"NO_COLORS",
":",
"# colors are disabled, thus return empty string",
"return",
"''",
",",
"''",
"if",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | translate_colorname_to_ansi_code | Translate the given color name to a valid
ANSI escape code.
:parma str colorname: the name of the color to resolve
:parma str offset: the offset for the color code
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:parma dict colorpalette: the color palette to use for ... | colorful/core.py | def translate_colorname_to_ansi_code(colorname, offset, colormode, colorpalette):
"""
Translate the given color name to a valid
ANSI escape code.
:parma str colorname: the name of the color to resolve
:parma str offset: the offset for the color code
:param int colormode: the color mode to use. ... | def translate_colorname_to_ansi_code(colorname, offset, colormode, colorpalette):
"""
Translate the given color name to a valid
ANSI escape code.
:parma str colorname: the name of the color to resolve
:parma str offset: the offset for the color code
:param int colormode: the color mode to use. ... | [
"Translate",
"the",
"given",
"color",
"name",
"to",
"a",
"valid",
"ANSI",
"escape",
"code",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L88-L108 | [
"def",
"translate_colorname_to_ansi_code",
"(",
"colorname",
",",
"offset",
",",
"colormode",
",",
"colorpalette",
")",
":",
"try",
":",
"red",
",",
"green",
",",
"blue",
"=",
"colorpalette",
"[",
"colorname",
"]",
"except",
"KeyError",
":",
"raise",
"Colorful... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | resolve_modifier_to_ansi_code | Resolve the given modifier name to a valid
ANSI escape code.
:param str modifiername: the name of the modifier to resolve
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:returns str: the ANSI escape code for the modifier
:raises ColorfulError: if the given modifie... | colorful/core.py | def resolve_modifier_to_ansi_code(modifiername, colormode):
"""
Resolve the given modifier name to a valid
ANSI escape code.
:param str modifiername: the name of the modifier to resolve
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:returns str: the ANSI escap... | def resolve_modifier_to_ansi_code(modifiername, colormode):
"""
Resolve the given modifier name to a valid
ANSI escape code.
:param str modifiername: the name of the modifier to resolve
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:returns str: the ANSI escap... | [
"Resolve",
"the",
"given",
"modifier",
"name",
"to",
"a",
"valid",
"ANSI",
"escape",
"code",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L111-L134 | [
"def",
"resolve_modifier_to_ansi_code",
"(",
"modifiername",
",",
"colormode",
")",
":",
"if",
"colormode",
"==",
"terminal",
".",
"NO_COLORS",
":",
"# return empty string if colors are disabled",
"return",
"''",
",",
"''",
"try",
":",
"start_code",
",",
"end_code",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | translate_style | Translate the given style to an ANSI escape code
sequence.
``style`` examples are:
* green
* bold
* red_on_black
* bold_green
* italic_yellow_on_cyan
:param str style: the style to translate
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:parma... | colorful/core.py | def translate_style(style, colormode, colorpalette):
"""
Translate the given style to an ANSI escape code
sequence.
``style`` examples are:
* green
* bold
* red_on_black
* bold_green
* italic_yellow_on_cyan
:param str style: the style to translate
:param int colormode: the... | def translate_style(style, colormode, colorpalette):
"""
Translate the given style to an ANSI escape code
sequence.
``style`` examples are:
* green
* bold
* red_on_black
* bold_green
* italic_yellow_on_cyan
:param str style: the style to translate
:param int colormode: the... | [
"Translate",
"the",
"given",
"style",
"to",
"an",
"ANSI",
"escape",
"code",
"sequence",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L137-L193 | [
"def",
"translate_style",
"(",
"style",
",",
"colormode",
",",
"colorpalette",
")",
":",
"style_parts",
"=",
"iter",
"(",
"style",
".",
"split",
"(",
"'_'",
")",
")",
"ansi_start_sequence",
"=",
"[",
"]",
"ansi_end_sequence",
"=",
"[",
"]",
"try",
":",
"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | style_string | Style the given string according to the given
ANSI style string.
:param str string: the string to style
:param tuple ansi_style: the styling string returned by ``translate_style``
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:returns: a string containing proper A... | colorful/core.py | def style_string(string, ansi_style, colormode, nested=False):
"""
Style the given string according to the given
ANSI style string.
:param str string: the string to style
:param tuple ansi_style: the styling string returned by ``translate_style``
:param int colormode: the color mode to use. See... | def style_string(string, ansi_style, colormode, nested=False):
"""
Style the given string according to the given
ANSI style string.
:param str string: the string to style
:param tuple ansi_style: the styling string returned by ``translate_style``
:param int colormode: the color mode to use. See... | [
"Style",
"the",
"given",
"string",
"according",
"to",
"the",
"given",
"ANSI",
"style",
"string",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L196-L219 | [
"def",
"style_string",
"(",
"string",
",",
"ansi_style",
",",
"colormode",
",",
"nested",
"=",
"False",
")",
":",
"ansi_start_code",
",",
"ansi_end_code",
"=",
"ansi_style",
"# replace nest placeholders with the current begin style",
"if",
"PY2",
":",
"if",
"isinstanc... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | Colorful.colorpalette | Set the colorpalette which should be used | colorful/core.py | def colorpalette(self, colorpalette):
"""
Set the colorpalette which should be used
"""
if isinstance(colorpalette, str): # we assume it's a path to a color file
colorpalette = colors.parse_colors(colorpalette)
self._colorpalette = colors.sanitize_color_palette(colo... | def colorpalette(self, colorpalette):
"""
Set the colorpalette which should be used
"""
if isinstance(colorpalette, str): # we assume it's a path to a color file
colorpalette = colors.parse_colors(colorpalette)
self._colorpalette = colors.sanitize_color_palette(colo... | [
"Set",
"the",
"colorpalette",
"which",
"should",
"be",
"used"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L354-L361 | [
"def",
"colorpalette",
"(",
"self",
",",
"colorpalette",
")",
":",
"if",
"isinstance",
"(",
"colorpalette",
",",
"str",
")",
":",
"# we assume it's a path to a color file",
"colorpalette",
"=",
"colors",
".",
"parse_colors",
"(",
"colorpalette",
")",
"self",
".",
... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | Colorful.setup | Setup this colorful object by setting a ``colormode`` and
the ``colorpalette`. The ``extend_colors`` flag is used
to extend the currently active color palette instead of
replacing it.
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:parma dict col... | colorful/core.py | def setup(self, colormode=None, colorpalette=None, extend_colors=False):
"""
Setup this colorful object by setting a ``colormode`` and
the ``colorpalette`. The ``extend_colors`` flag is used
to extend the currently active color palette instead of
replacing it.
:param int... | def setup(self, colormode=None, colorpalette=None, extend_colors=False):
"""
Setup this colorful object by setting a ``colormode`` and
the ``colorpalette`. The ``extend_colors`` flag is used
to extend the currently active color palette instead of
replacing it.
:param int... | [
"Setup",
"this",
"colorful",
"object",
"by",
"setting",
"a",
"colormode",
"and",
"the",
"colorpalette",
".",
"The",
"extend_colors",
"flag",
"is",
"used",
"to",
"extend",
"the",
"currently",
"active",
"color",
"palette",
"instead",
"of",
"replacing",
"it",
"."... | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L363-L382 | [
"def",
"setup",
"(",
"self",
",",
"colormode",
"=",
"None",
",",
"colorpalette",
"=",
"None",
",",
"extend_colors",
"=",
"False",
")",
":",
"if",
"colormode",
":",
"self",
".",
"colormode",
"=",
"colormode",
"if",
"colorpalette",
":",
"if",
"extend_colors"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | Colorful.use_style | Use a predefined style as color palette
:param str style_name: the name of the style | colorful/core.py | def use_style(self, style_name):
"""
Use a predefined style as color palette
:param str style_name: the name of the style
"""
try:
style = getattr(styles, style_name.upper())
except AttributeError:
raise ColorfulError('the style "{0}" is undefined... | def use_style(self, style_name):
"""
Use a predefined style as color palette
:param str style_name: the name of the style
"""
try:
style = getattr(styles, style_name.upper())
except AttributeError:
raise ColorfulError('the style "{0}" is undefined... | [
"Use",
"a",
"predefined",
"style",
"as",
"color",
"palette"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L427-L439 | [
"def",
"use_style",
"(",
"self",
",",
"style_name",
")",
":",
"try",
":",
"style",
"=",
"getattr",
"(",
"styles",
",",
"style_name",
".",
"upper",
"(",
")",
")",
"except",
"AttributeError",
":",
"raise",
"ColorfulError",
"(",
"'the style \"{0}\" is undefined'"... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | Colorful.format | Format the given string with the given ``args`` and ``kwargs``.
The string can contain references to ``c`` which is provided by
this colorful object.
:param str string: the string to format | colorful/core.py | def format(self, string, *args, **kwargs):
"""
Format the given string with the given ``args`` and ``kwargs``.
The string can contain references to ``c`` which is provided by
this colorful object.
:param str string: the string to format
"""
return string.format(c... | def format(self, string, *args, **kwargs):
"""
Format the given string with the given ``args`` and ``kwargs``.
The string can contain references to ``c`` which is provided by
this colorful object.
:param str string: the string to format
"""
return string.format(c... | [
"Format",
"the",
"given",
"string",
"with",
"the",
"given",
"args",
"and",
"kwargs",
".",
"The",
"string",
"can",
"contain",
"references",
"to",
"c",
"which",
"is",
"provided",
"by",
"this",
"colorful",
"object",
"."
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L441-L449 | [
"def",
"format",
"(",
"self",
",",
"string",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"string",
".",
"format",
"(",
"c",
"=",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | Colorful.print | Print the given objects to the given file stream.
See https://docs.python.org/3/library/functions.html#print
The only difference to the ``print()`` built-in is that
``Colorful.print()`` formats the string with ``c=self``.
With that stylings are possible
:param str sep: the sepe... | colorful/core.py | def print(self, *objects, **options):
"""
Print the given objects to the given file stream.
See https://docs.python.org/3/library/functions.html#print
The only difference to the ``print()`` built-in is that
``Colorful.print()`` formats the string with ``c=self``.
With th... | def print(self, *objects, **options):
"""
Print the given objects to the given file stream.
See https://docs.python.org/3/library/functions.html#print
The only difference to the ``print()`` built-in is that
``Colorful.print()`` formats the string with ``c=self``.
With th... | [
"Print",
"the",
"given",
"objects",
"to",
"the",
"given",
"file",
"stream",
".",
"See",
"https",
":",
"//",
"docs",
".",
"python",
".",
"org",
"/",
"3",
"/",
"library",
"/",
"functions",
".",
"html#print"
] | timofurrer/colorful | python | https://github.com/timofurrer/colorful/blob/919fa6da17865cc5e01e6b16119193a97d180dc9/colorful/core.py#L469-L503 | [
"def",
"print",
"(",
"self",
",",
"*",
"objects",
",",
"*",
"*",
"options",
")",
":",
"# NOTE: change signature to same as print() built-in function as",
"# soon as Python 2.7 is not supported anymore.",
"# If causes problems because of the keyword args after *args",
"all... | 919fa6da17865cc5e01e6b16119193a97d180dc9 |
valid | readattr | Read attribute from sysfs and return as string | temperusb/temper.py | def readattr(path, name):
"""
Read attribute from sysfs and return as string
"""
try:
f = open(USB_SYS_PREFIX + path + "/" + name)
return f.readline().rstrip("\n")
except IOError:
return None | def readattr(path, name):
"""
Read attribute from sysfs and return as string
"""
try:
f = open(USB_SYS_PREFIX + path + "/" + name)
return f.readline().rstrip("\n")
except IOError:
return None | [
"Read",
"attribute",
"from",
"sysfs",
"and",
"return",
"as",
"string"
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L38-L46 | [
"def",
"readattr",
"(",
"path",
",",
"name",
")",
":",
"try",
":",
"f",
"=",
"open",
"(",
"USB_SYS_PREFIX",
"+",
"path",
"+",
"\"/\"",
"+",
"name",
")",
"return",
"f",
".",
"readline",
"(",
")",
".",
"rstrip",
"(",
"\"\\n\"",
")",
"except",
"IOErro... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | find_ports | Find the port chain a device is plugged on.
This is done by searching sysfs for a device that matches the device
bus/address combination.
Useful when the underlying usb lib does not return device.port_number for
whatever reason. | temperusb/temper.py | def find_ports(device):
"""
Find the port chain a device is plugged on.
This is done by searching sysfs for a device that matches the device
bus/address combination.
Useful when the underlying usb lib does not return device.port_number for
whatever reason.
"""
bus_id = device.bus
d... | def find_ports(device):
"""
Find the port chain a device is plugged on.
This is done by searching sysfs for a device that matches the device
bus/address combination.
Useful when the underlying usb lib does not return device.port_number for
whatever reason.
"""
bus_id = device.bus
d... | [
"Find",
"the",
"port",
"chain",
"a",
"device",
"is",
"plugged",
"on",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L49-L75 | [
"def",
"find_ports",
"(",
"device",
")",
":",
"bus_id",
"=",
"device",
".",
"bus",
"dev_id",
"=",
"device",
".",
"address",
"for",
"dirent",
"in",
"os",
".",
"listdir",
"(",
"USB_SYS_PREFIX",
")",
":",
"matches",
"=",
"re",
".",
"match",
"(",
"USB_PORT... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice.set_calibration_data | Set device calibration data based on settings in /etc/temper.conf. | temperusb/temper.py | def set_calibration_data(self, scale=None, offset=None):
"""
Set device calibration data based on settings in /etc/temper.conf.
"""
if scale is not None and offset is not None:
self._scale = scale
self._offset = offset
elif scale is None and offset is None... | def set_calibration_data(self, scale=None, offset=None):
"""
Set device calibration data based on settings in /etc/temper.conf.
"""
if scale is not None and offset is not None:
self._scale = scale
self._offset = offset
elif scale is None and offset is None... | [
"Set",
"device",
"calibration",
"data",
"based",
"on",
"settings",
"in",
"/",
"etc",
"/",
"temper",
".",
"conf",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L107-L135 | [
"def",
"set_calibration_data",
"(",
"self",
",",
"scale",
"=",
"None",
",",
"offset",
"=",
"None",
")",
":",
"if",
"scale",
"is",
"not",
"None",
"and",
"offset",
"is",
"not",
"None",
":",
"self",
".",
"_scale",
"=",
"scale",
"self",
".",
"_offset",
"... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice.get_data | Get data from the USB device. | temperusb/temper.py | def get_data(self, reset_device=False):
"""
Get data from the USB device.
"""
try:
if reset_device:
self._device.reset()
# detach kernel driver from both interfaces if attached, so we can set_configuration()
for interface in [0,1]:
... | def get_data(self, reset_device=False):
"""
Get data from the USB device.
"""
try:
if reset_device:
self._device.reset()
# detach kernel driver from both interfaces if attached, so we can set_configuration()
for interface in [0,1]:
... | [
"Get",
"data",
"from",
"the",
"USB",
"device",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L207-L281 | [
"def",
"get_data",
"(",
"self",
",",
"reset_device",
"=",
"False",
")",
":",
"try",
":",
"if",
"reset_device",
":",
"self",
".",
"_device",
".",
"reset",
"(",
")",
"# detach kernel driver from both interfaces if attached, so we can set_configuration()",
"for",
"interf... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice.get_temperature | Get device temperature reading. | temperusb/temper.py | def get_temperature(self, format='celsius', sensor=0):
"""
Get device temperature reading.
"""
results = self.get_temperatures(sensors=[sensor,])
if format == 'celsius':
return results[sensor]['temperature_c']
elif format == 'fahrenheit':
return r... | def get_temperature(self, format='celsius', sensor=0):
"""
Get device temperature reading.
"""
results = self.get_temperatures(sensors=[sensor,])
if format == 'celsius':
return results[sensor]['temperature_c']
elif format == 'fahrenheit':
return r... | [
"Get",
"device",
"temperature",
"reading",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L283-L296 | [
"def",
"get_temperature",
"(",
"self",
",",
"format",
"=",
"'celsius'",
",",
"sensor",
"=",
"0",
")",
":",
"results",
"=",
"self",
".",
"get_temperatures",
"(",
"sensors",
"=",
"[",
"sensor",
",",
"]",
")",
"if",
"format",
"==",
"'celsius'",
":",
"retu... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice.get_temperatures | Get device temperature reading.
Params:
- sensors: optional list of sensors to get a reading for, examples:
[0,] - get reading for sensor 0
[0, 1,] - get reading for sensors 0 and 1
None - get readings for all sensors | temperusb/temper.py | def get_temperatures(self, sensors=None):
"""
Get device temperature reading.
Params:
- sensors: optional list of sensors to get a reading for, examples:
[0,] - get reading for sensor 0
[0, 1,] - get reading for sensors 0 and 1
None - get readings for all s... | def get_temperatures(self, sensors=None):
"""
Get device temperature reading.
Params:
- sensors: optional list of sensors to get a reading for, examples:
[0,] - get reading for sensor 0
[0, 1,] - get reading for sensors 0 and 1
None - get readings for all s... | [
"Get",
"device",
"temperature",
"reading",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L298-L343 | [
"def",
"get_temperatures",
"(",
"self",
",",
"sensors",
"=",
"None",
")",
":",
"_sensors",
"=",
"sensors",
"if",
"_sensors",
"is",
"None",
":",
"_sensors",
"=",
"list",
"(",
"range",
"(",
"0",
",",
"self",
".",
"_sensor_count",
")",
")",
"if",
"not",
... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice.get_humidity | Get device humidity reading.
Params:
- sensors: optional list of sensors to get a reading for, examples:
[0,] - get reading for sensor 0
[0, 1,] - get reading for sensors 0 and 1
None - get readings for all sensors | temperusb/temper.py | def get_humidity(self, sensors=None):
"""
Get device humidity reading.
Params:
- sensors: optional list of sensors to get a reading for, examples:
[0,] - get reading for sensor 0
[0, 1,] - get reading for sensors 0 and 1
None - get readings for all sensors
... | def get_humidity(self, sensors=None):
"""
Get device humidity reading.
Params:
- sensors: optional list of sensors to get a reading for, examples:
[0,] - get reading for sensor 0
[0, 1,] - get reading for sensors 0 and 1
None - get readings for all sensors
... | [
"Get",
"device",
"humidity",
"reading",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L345-L387 | [
"def",
"get_humidity",
"(",
"self",
",",
"sensors",
"=",
"None",
")",
":",
"_sensors",
"=",
"sensors",
"if",
"_sensors",
"is",
"None",
":",
"_sensors",
"=",
"list",
"(",
"range",
"(",
"0",
",",
"self",
".",
"_sensor_count",
")",
")",
"if",
"not",
"se... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice._control_transfer | Send device a control request with standard parameters and <data> as
payload. | temperusb/temper.py | def _control_transfer(self, data):
"""
Send device a control request with standard parameters and <data> as
payload.
"""
LOGGER.debug('Ctrl transfer: %r', data)
self._device.ctrl_transfer(bmRequestType=0x21, bRequest=0x09,
wValue=0x0200, wIndex=0x01, data_or_w... | def _control_transfer(self, data):
"""
Send device a control request with standard parameters and <data> as
payload.
"""
LOGGER.debug('Ctrl transfer: %r', data)
self._device.ctrl_transfer(bmRequestType=0x21, bRequest=0x09,
wValue=0x0200, wIndex=0x01, data_or_w... | [
"Send",
"device",
"a",
"control",
"request",
"with",
"standard",
"parameters",
"and",
"<data",
">",
"as",
"payload",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L389-L396 | [
"def",
"_control_transfer",
"(",
"self",
",",
"data",
")",
":",
"LOGGER",
".",
"debug",
"(",
"'Ctrl transfer: %r'",
",",
"data",
")",
"self",
".",
"_device",
".",
"ctrl_transfer",
"(",
"bmRequestType",
"=",
"0x21",
",",
"bRequest",
"=",
"0x09",
",",
"wValu... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | TemperDevice._interrupt_read | Read data from device. | temperusb/temper.py | def _interrupt_read(self):
"""
Read data from device.
"""
data = self._device.read(ENDPOINT, REQ_INT_LEN, timeout=TIMEOUT)
LOGGER.debug('Read data: %r', data)
return data | def _interrupt_read(self):
"""
Read data from device.
"""
data = self._device.read(ENDPOINT, REQ_INT_LEN, timeout=TIMEOUT)
LOGGER.debug('Read data: %r', data)
return data | [
"Read",
"data",
"from",
"device",
"."
] | padelt/temper-python | python | https://github.com/padelt/temper-python/blob/cbdbace7e6755b1d91a2603ab63c9cb778078f79/temperusb/temper.py#L398-L404 | [
"def",
"_interrupt_read",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"_device",
".",
"read",
"(",
"ENDPOINT",
",",
"REQ_INT_LEN",
",",
"timeout",
"=",
"TIMEOUT",
")",
"LOGGER",
".",
"debug",
"(",
"'Read data: %r'",
",",
"data",
")",
"return",
"data... | cbdbace7e6755b1d91a2603ab63c9cb778078f79 |
valid | Github.__check_looks_like_uri | Checks the URI looks like a RAW uri in github:
- 'https://raw.githubusercontent.com/github/hubot/master/README.md'
- 'https://github.com/github/hubot/raw/master/README.md'
:param uri: uri of the file | sirmordred/github.py | def __check_looks_like_uri(self, uri):
"""Checks the URI looks like a RAW uri in github:
- 'https://raw.githubusercontent.com/github/hubot/master/README.md'
- 'https://github.com/github/hubot/raw/master/README.md'
:param uri: uri of the file
"""
if uri.split('/')[2] == ... | def __check_looks_like_uri(self, uri):
"""Checks the URI looks like a RAW uri in github:
- 'https://raw.githubusercontent.com/github/hubot/master/README.md'
- 'https://github.com/github/hubot/raw/master/README.md'
:param uri: uri of the file
"""
if uri.split('/')[2] == ... | [
"Checks",
"the",
"URI",
"looks",
"like",
"a",
"RAW",
"uri",
"in",
"github",
":"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/github.py#L37-L51 | [
"def",
"__check_looks_like_uri",
"(",
"self",
",",
"uri",
")",
":",
"if",
"uri",
".",
"split",
"(",
"'/'",
")",
"[",
"2",
"]",
"==",
"'raw.githubusercontent.com'",
":",
"return",
"True",
"elif",
"uri",
".",
"split",
"(",
"'/'",
")",
"[",
"2",
"]",
"=... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | Github.read_file_from_uri | Reads the file from Github
:param uri: URI of the Github raw File
:returns: UTF-8 text with the content | sirmordred/github.py | def read_file_from_uri(self, uri):
"""Reads the file from Github
:param uri: URI of the Github raw File
:returns: UTF-8 text with the content
"""
logger.debug("Reading %s" % (uri))
self.__check_looks_like_uri(uri)
try:
req = urllib.request.Request(... | def read_file_from_uri(self, uri):
"""Reads the file from Github
:param uri: URI of the Github raw File
:returns: UTF-8 text with the content
"""
logger.debug("Reading %s" % (uri))
self.__check_looks_like_uri(uri)
try:
req = urllib.request.Request(... | [
"Reads",
"the",
"file",
"from",
"Github"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/github.py#L53-L74 | [
"def",
"read_file_from_uri",
"(",
"self",
",",
"uri",
")",
":",
"logger",
".",
"debug",
"(",
"\"Reading %s\"",
"%",
"(",
"uri",
")",
")",
"self",
".",
"__check_looks_like_uri",
"(",
"uri",
")",
"try",
":",
"req",
"=",
"urllib",
".",
"request",
".",
"Re... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | TaskRawDataArthurCollection.measure_memory | Recursively finds size of objects | sirmordred/task_collection.py | def measure_memory(cls, obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
# Important mark as seen *before* entering recursion to gracefully... | def measure_memory(cls, obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
# Important mark as seen *before* entering recursion to gracefully... | [
"Recursively",
"finds",
"size",
"of",
"objects"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/task_collection.py#L173-L191 | [
"def",
"measure_memory",
"(",
"cls",
",",
"obj",
",",
"seen",
"=",
"None",
")",
":",
"size",
"=",
"sys",
".",
"getsizeof",
"(",
"obj",
")",
"if",
"seen",
"is",
"None",
":",
"seen",
"=",
"set",
"(",
")",
"obj_id",
"=",
"id",
"(",
"obj",
")",
"if... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | TaskRawDataArthurCollection.__feed_arthur | Feed Ocean with backend data collected from arthur redis queue | sirmordred/task_collection.py | def __feed_arthur(self):
""" Feed Ocean with backend data collected from arthur redis queue"""
with self.ARTHUR_FEED_LOCK:
# This is a expensive operation so don't do it always
if (time.time() - self.ARTHUR_LAST_MEMORY_CHECK) > 5 * self.ARTHUR_LAST_MEMORY_CHECK_TIME:
... | def __feed_arthur(self):
""" Feed Ocean with backend data collected from arthur redis queue"""
with self.ARTHUR_FEED_LOCK:
# This is a expensive operation so don't do it always
if (time.time() - self.ARTHUR_LAST_MEMORY_CHECK) > 5 * self.ARTHUR_LAST_MEMORY_CHECK_TIME:
... | [
"Feed",
"Ocean",
"with",
"backend",
"data",
"collected",
"from",
"arthur",
"redis",
"queue"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/task_collection.py#L193-L242 | [
"def",
"__feed_arthur",
"(",
"self",
")",
":",
"with",
"self",
".",
"ARTHUR_FEED_LOCK",
":",
"# This is a expensive operation so don't do it always",
"if",
"(",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"ARTHUR_LAST_MEMORY_CHECK",
")",
">",
"5",
"*",
"sel... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | TaskRawDataArthurCollection.__feed_backend_arthur | Feed Ocean with backend data collected from arthur redis queue | sirmordred/task_collection.py | def __feed_backend_arthur(self, repo):
""" Feed Ocean with backend data collected from arthur redis queue"""
# Always get pending items from arthur for all data sources
self.__feed_arthur()
tag = self.backend_tag(repo)
logger.debug("Arthur items available for %s", self.arthur_... | def __feed_backend_arthur(self, repo):
""" Feed Ocean with backend data collected from arthur redis queue"""
# Always get pending items from arthur for all data sources
self.__feed_arthur()
tag = self.backend_tag(repo)
logger.debug("Arthur items available for %s", self.arthur_... | [
"Feed",
"Ocean",
"with",
"backend",
"data",
"collected",
"from",
"arthur",
"redis",
"queue"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/task_collection.py#L257-L272 | [
"def",
"__feed_backend_arthur",
"(",
"self",
",",
"repo",
")",
":",
"# Always get pending items from arthur for all data sources",
"self",
".",
"__feed_arthur",
"(",
")",
"tag",
"=",
"self",
".",
"backend_tag",
"(",
"repo",
")",
"logger",
".",
"debug",
"(",
"\"Art... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | TaskRawDataArthurCollection.__create_arthur_json | Create the JSON for configuring arthur to collect data
https://github.com/grimoirelab/arthur#adding-tasks
Sample for git:
{
"tasks": [
{
"task_id": "arthur.git",
"backend": "git",
"backend_args": {
"gitpath... | sirmordred/task_collection.py | def __create_arthur_json(self, repo, backend_args):
""" Create the JSON for configuring arthur to collect data
https://github.com/grimoirelab/arthur#adding-tasks
Sample for git:
{
"tasks": [
{
"task_id": "arthur.git",
"backend": "git"... | def __create_arthur_json(self, repo, backend_args):
""" Create the JSON for configuring arthur to collect data
https://github.com/grimoirelab/arthur#adding-tasks
Sample for git:
{
"tasks": [
{
"task_id": "arthur.git",
"backend": "git"... | [
"Create",
"the",
"JSON",
"for",
"configuring",
"arthur",
"to",
"collect",
"data"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/task_collection.py#L274-L340 | [
"def",
"__create_arthur_json",
"(",
"self",
",",
"repo",
",",
"backend_args",
")",
":",
"backend_args",
"=",
"self",
".",
"_compose_arthur_params",
"(",
"self",
".",
"backend_section",
",",
"repo",
")",
"if",
"self",
".",
"backend_section",
"==",
"'git'",
":",... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | TaskIdentitiesExport.sha_github_file | Return the GitHub SHA for a file in the repository | sirmordred/task_identities.py | def sha_github_file(cls, config, repo_file, repository_api, repository_branch):
""" Return the GitHub SHA for a file in the repository """
repo_file_sha = None
cfg = config.get_conf()
github_token = cfg['sortinghat']['identities_api_token']
headers = {"Authorization": "token " ... | def sha_github_file(cls, config, repo_file, repository_api, repository_branch):
""" Return the GitHub SHA for a file in the repository """
repo_file_sha = None
cfg = config.get_conf()
github_token = cfg['sortinghat']['identities_api_token']
headers = {"Authorization": "token " ... | [
"Return",
"the",
"GitHub",
"SHA",
"for",
"a",
"file",
"in",
"the",
"repository"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/task_identities.py#L318-L337 | [
"def",
"sha_github_file",
"(",
"cls",
",",
"config",
",",
"repo_file",
",",
"repository_api",
",",
"repository_branch",
")",
":",
"repo_file_sha",
"=",
"None",
"cfg",
"=",
"config",
".",
"get_conf",
"(",
")",
"github_token",
"=",
"cfg",
"[",
"'sortinghat'",
... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | TaskIdentitiesMerge.__get_uuids_from_profile_name | Get the uuid for a profile name | sirmordred/task_identities.py | def __get_uuids_from_profile_name(self, profile_name):
""" Get the uuid for a profile name """
uuids = []
with self.db.connect() as session:
query = session.query(Profile).\
filter(Profile.name == profile_name)
profiles = query.all()
if profil... | def __get_uuids_from_profile_name(self, profile_name):
""" Get the uuid for a profile name """
uuids = []
with self.db.connect() as session:
query = session.query(Profile).\
filter(Profile.name == profile_name)
profiles = query.all()
if profil... | [
"Get",
"the",
"uuid",
"for",
"a",
"profile",
"name"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/task_identities.py#L427-L438 | [
"def",
"__get_uuids_from_profile_name",
"(",
"self",
",",
"profile_name",
")",
":",
"uuids",
"=",
"[",
"]",
"with",
"self",
".",
"db",
".",
"connect",
"(",
")",
"as",
"session",
":",
"query",
"=",
"session",
".",
"query",
"(",
"Profile",
")",
".",
"fil... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | micro_mordred | Execute the raw and/or the enrich phases of a given backend section defined in a Mordred configuration file.
:param cfg_path: the path of a Mordred configuration file
:param backend_sections: the backend sections where the raw and/or enrich phases will be executed
:param raw: if true, it activates the coll... | utils/micro.py | def micro_mordred(cfg_path, backend_sections, raw, arthur, identities, enrich, panels):
"""Execute the raw and/or the enrich phases of a given backend section defined in a Mordred configuration file.
:param cfg_path: the path of a Mordred configuration file
:param backend_sections: the backend sections whe... | def micro_mordred(cfg_path, backend_sections, raw, arthur, identities, enrich, panels):
"""Execute the raw and/or the enrich phases of a given backend section defined in a Mordred configuration file.
:param cfg_path: the path of a Mordred configuration file
:param backend_sections: the backend sections whe... | [
"Execute",
"the",
"raw",
"and",
"/",
"or",
"the",
"enrich",
"phases",
"of",
"a",
"given",
"backend",
"section",
"defined",
"in",
"a",
"Mordred",
"configuration",
"file",
"."
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/utils/micro.py#L41-L67 | [
"def",
"micro_mordred",
"(",
"cfg_path",
",",
"backend_sections",
",",
"raw",
",",
"arthur",
",",
"identities",
",",
"enrich",
",",
"panels",
")",
":",
"config",
"=",
"Config",
"(",
"cfg_path",
")",
"if",
"raw",
":",
"for",
"backend",
"in",
"backend_sectio... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | get_raw | Execute the raw phase for a given backend section, optionally using Arthur
:param config: a Mordred config object
:param backend_section: the backend section where the raw phase is executed
:param arthur: if true, it enables Arthur to collect the raw data | utils/micro.py | def get_raw(config, backend_section, arthur):
"""Execute the raw phase for a given backend section, optionally using Arthur
:param config: a Mordred config object
:param backend_section: the backend section where the raw phase is executed
:param arthur: if true, it enables Arthur to collect the raw dat... | def get_raw(config, backend_section, arthur):
"""Execute the raw phase for a given backend section, optionally using Arthur
:param config: a Mordred config object
:param backend_section: the backend section where the raw phase is executed
:param arthur: if true, it enables Arthur to collect the raw dat... | [
"Execute",
"the",
"raw",
"phase",
"for",
"a",
"given",
"backend",
"section",
"optionally",
"using",
"Arthur"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/utils/micro.py#L70-L89 | [
"def",
"get_raw",
"(",
"config",
",",
"backend_section",
",",
"arthur",
")",
":",
"if",
"arthur",
":",
"task",
"=",
"TaskRawDataArthurCollection",
"(",
"config",
",",
"backend_section",
"=",
"backend_section",
")",
"else",
":",
"task",
"=",
"TaskRawDataCollectio... | d6ac94d28d707fae23170064d078f1edf937d13e |
valid | get_identities | Execute the merge identities phase
:param config: a Mordred config object | utils/micro.py | def get_identities(config):
"""Execute the merge identities phase
:param config: a Mordred config object
"""
TaskProjects(config).execute()
task = TaskIdentitiesMerge(config)
task.execute()
logging.info("Merging identities finished!") | def get_identities(config):
"""Execute the merge identities phase
:param config: a Mordred config object
"""
TaskProjects(config).execute()
task = TaskIdentitiesMerge(config)
task.execute()
logging.info("Merging identities finished!") | [
"Execute",
"the",
"merge",
"identities",
"phase"
] | chaoss/grimoirelab-sirmordred | python | https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/utils/micro.py#L92-L101 | [
"def",
"get_identities",
"(",
"config",
")",
":",
"TaskProjects",
"(",
"config",
")",
".",
"execute",
"(",
")",
"task",
"=",
"TaskIdentitiesMerge",
"(",
"config",
")",
"task",
".",
"execute",
"(",
")",
"logging",
".",
"info",
"(",
"\"Merging identities finis... | d6ac94d28d707fae23170064d078f1edf937d13e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.