repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Compare
def visit_Compare(self, node: ast.Compare) -> Any: """Recursively visit the comparators and apply the operations on them.""" # pylint: disable=too-many-branches left = self.visit(node=node.left) comparators = [self.visit(node=comparator) for comparator in node.comparators] resu...
python
def visit_Compare(self, node: ast.Compare) -> Any: """Recursively visit the comparators and apply the operations on them.""" # pylint: disable=too-many-branches left = self.visit(node=node.left) comparators = [self.visit(node=comparator) for comparator in node.comparators] resu...
[ "def", "visit_Compare", "(", "self", ",", "node", ":", "ast", ".", "Compare", ")", "->", "Any", ":", "# pylint: disable=too-many-branches", "left", "=", "self", ".", "visit", "(", "node", "=", "node", ".", "left", ")", "comparators", "=", "[", "self", "....
Recursively visit the comparators and apply the operations on them.
[ "Recursively", "visit", "the", "comparators", "and", "apply", "the", "operations", "on", "them", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L207-L247
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Call
def visit_Call(self, node: ast.Call) -> Any: """Visit the function and the arguments and finally make the function call with them.""" func = self.visit(node=node.func) args = [] # type: List[Any] for arg_node in node.args: if isinstance(arg_node, ast.Starred): ...
python
def visit_Call(self, node: ast.Call) -> Any: """Visit the function and the arguments and finally make the function call with them.""" func = self.visit(node=node.func) args = [] # type: List[Any] for arg_node in node.args: if isinstance(arg_node, ast.Starred): ...
[ "def", "visit_Call", "(", "self", ",", "node", ":", "ast", ".", "Call", ")", "->", "Any", ":", "func", "=", "self", ".", "visit", "(", "node", "=", "node", ".", "func", ")", "args", "=", "[", "]", "# type: List[Any]", "for", "arg_node", "in", "node...
Visit the function and the arguments and finally make the function call with them.
[ "Visit", "the", "function", "and", "the", "arguments", "and", "finally", "make", "the", "function", "call", "with", "them", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L249-L273
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_IfExp
def visit_IfExp(self, node: ast.IfExp) -> Any: """Visit the ``test``, and depending on its outcome, the ``body`` or ``orelse``.""" test = self.visit(node=node.test) if test: result = self.visit(node=node.body) else: result = self.visit(node=node.orelse) ...
python
def visit_IfExp(self, node: ast.IfExp) -> Any: """Visit the ``test``, and depending on its outcome, the ``body`` or ``orelse``.""" test = self.visit(node=node.test) if test: result = self.visit(node=node.body) else: result = self.visit(node=node.orelse) ...
[ "def", "visit_IfExp", "(", "self", ",", "node", ":", "ast", ".", "IfExp", ")", "->", "Any", ":", "test", "=", "self", ".", "visit", "(", "node", "=", "node", ".", "test", ")", "if", "test", ":", "result", "=", "self", ".", "visit", "(", "node", ...
Visit the ``test``, and depending on its outcome, the ``body`` or ``orelse``.
[ "Visit", "the", "test", "and", "depending", "on", "its", "outcome", "the", "body", "or", "orelse", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L275-L285
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Attribute
def visit_Attribute(self, node: ast.Attribute) -> Any: """Visit the node's ``value`` and get the attribute from the result.""" value = self.visit(node=node.value) if not isinstance(node.ctx, ast.Load): raise NotImplementedError( "Can only compute a value of Load on th...
python
def visit_Attribute(self, node: ast.Attribute) -> Any: """Visit the node's ``value`` and get the attribute from the result.""" value = self.visit(node=node.value) if not isinstance(node.ctx, ast.Load): raise NotImplementedError( "Can only compute a value of Load on th...
[ "def", "visit_Attribute", "(", "self", ",", "node", ":", "ast", ".", "Attribute", ")", "->", "Any", ":", "value", "=", "self", ".", "visit", "(", "node", "=", "node", ".", "value", ")", "if", "not", "isinstance", "(", "node", ".", "ctx", ",", "ast"...
Visit the node's ``value`` and get the attribute from the result.
[ "Visit", "the", "node", "s", "value", "and", "get", "the", "attribute", "from", "the", "result", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L287-L297
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Index
def visit_Index(self, node: ast.Index) -> Any: """Visit the node's ``value``.""" result = self.visit(node=node.value) self.recomputed_values[node] = result return result
python
def visit_Index(self, node: ast.Index) -> Any: """Visit the node's ``value``.""" result = self.visit(node=node.value) self.recomputed_values[node] = result return result
[ "def", "visit_Index", "(", "self", ",", "node", ":", "ast", ".", "Index", ")", "->", "Any", ":", "result", "=", "self", ".", "visit", "(", "node", "=", "node", ".", "value", ")", "self", ".", "recomputed_values", "[", "node", "]", "=", "result", "r...
Visit the node's ``value``.
[ "Visit", "the", "node", "s", "value", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L299-L304
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Slice
def visit_Slice(self, node: ast.Slice) -> slice: """Visit ``lower``, ``upper`` and ``step`` and recompute the node as a ``slice``.""" lower = None # type: Optional[int] if node.lower is not None: lower = self.visit(node=node.lower) upper = None # type: Optional[int] ...
python
def visit_Slice(self, node: ast.Slice) -> slice: """Visit ``lower``, ``upper`` and ``step`` and recompute the node as a ``slice``.""" lower = None # type: Optional[int] if node.lower is not None: lower = self.visit(node=node.lower) upper = None # type: Optional[int] ...
[ "def", "visit_Slice", "(", "self", ",", "node", ":", "ast", ".", "Slice", ")", "->", "slice", ":", "lower", "=", "None", "# type: Optional[int]", "if", "node", ".", "lower", "is", "not", "None", ":", "lower", "=", "self", ".", "visit", "(", "node", "...
Visit ``lower``, ``upper`` and ``step`` and recompute the node as a ``slice``.
[ "Visit", "lower", "upper", "and", "step", "and", "recompute", "the", "node", "as", "a", "slice", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L306-L323
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_ExtSlice
def visit_ExtSlice(self, node: ast.ExtSlice) -> Tuple[Any, ...]: """Visit each dimension of the advanced slicing and assemble the dimensions in a tuple.""" result = tuple(self.visit(node=dim) for dim in node.dims) self.recomputed_values[node] = result return result
python
def visit_ExtSlice(self, node: ast.ExtSlice) -> Tuple[Any, ...]: """Visit each dimension of the advanced slicing and assemble the dimensions in a tuple.""" result = tuple(self.visit(node=dim) for dim in node.dims) self.recomputed_values[node] = result return result
[ "def", "visit_ExtSlice", "(", "self", ",", "node", ":", "ast", ".", "ExtSlice", ")", "->", "Tuple", "[", "Any", ",", "...", "]", ":", "result", "=", "tuple", "(", "self", ".", "visit", "(", "node", "=", "dim", ")", "for", "dim", "in", "node", "."...
Visit each dimension of the advanced slicing and assemble the dimensions in a tuple.
[ "Visit", "each", "dimension", "of", "the", "advanced", "slicing", "and", "assemble", "the", "dimensions", "in", "a", "tuple", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L325-L330
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Subscript
def visit_Subscript(self, node: ast.Subscript) -> Any: """Visit the ``slice`` and a ``value`` and get the element.""" value = self.visit(node=node.value) a_slice = self.visit(node=node.slice) result = value[a_slice] self.recomputed_values[node] = result return result
python
def visit_Subscript(self, node: ast.Subscript) -> Any: """Visit the ``slice`` and a ``value`` and get the element.""" value = self.visit(node=node.value) a_slice = self.visit(node=node.slice) result = value[a_slice] self.recomputed_values[node] = result return result
[ "def", "visit_Subscript", "(", "self", ",", "node", ":", "ast", ".", "Subscript", ")", "->", "Any", ":", "value", "=", "self", ".", "visit", "(", "node", "=", "node", ".", "value", ")", "a_slice", "=", "self", ".", "visit", "(", "node", "=", "node"...
Visit the ``slice`` and a ``value`` and get the element.
[ "Visit", "the", "slice", "and", "a", "value", "and", "get", "the", "element", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L332-L340
train
Parquery/icontract
icontract/_recompute.py
Visitor._execute_comprehension
def _execute_comprehension(self, node: Union[ast.ListComp, ast.SetComp, ast.GeneratorExp, ast.DictComp]) -> Any: """Compile the generator or comprehension from the node and execute the compiled code.""" args = [ast.arg(arg=name) for name in sorted(self._name_to_value.keys())] func_def_node = as...
python
def _execute_comprehension(self, node: Union[ast.ListComp, ast.SetComp, ast.GeneratorExp, ast.DictComp]) -> Any: """Compile the generator or comprehension from the node and execute the compiled code.""" args = [ast.arg(arg=name) for name in sorted(self._name_to_value.keys())] func_def_node = as...
[ "def", "_execute_comprehension", "(", "self", ",", "node", ":", "Union", "[", "ast", ".", "ListComp", ",", "ast", ".", "SetComp", ",", "ast", ".", "GeneratorExp", ",", "ast", ".", "DictComp", "]", ")", "->", "Any", ":", "args", "=", "[", "ast", ".", ...
Compile the generator or comprehension from the node and execute the compiled code.
[ "Compile", "the", "generator", "or", "comprehension", "from", "the", "node", "and", "execute", "the", "compiled", "code", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L342-L364
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_GeneratorExp
def visit_GeneratorExp(self, node: ast.GeneratorExp) -> Any: """Compile the generator expression as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) # Do not set the computed value of the...
python
def visit_GeneratorExp(self, node: ast.GeneratorExp) -> Any: """Compile the generator expression as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) # Do not set the computed value of the...
[ "def", "visit_GeneratorExp", "(", "self", ",", "node", ":", "ast", ".", "GeneratorExp", ")", "->", "Any", ":", "result", "=", "self", ".", "_execute_comprehension", "(", "node", "=", "node", ")", "for", "generator", "in", "node", ".", "generators", ":", ...
Compile the generator expression as a function and call it.
[ "Compile", "the", "generator", "expression", "as", "a", "function", "and", "call", "it", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L366-L374
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_ListComp
def visit_ListComp(self, node: ast.ListComp) -> Any: """Compile the list comprehension as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) self.recomputed_values[node] = result re...
python
def visit_ListComp(self, node: ast.ListComp) -> Any: """Compile the list comprehension as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) self.recomputed_values[node] = result re...
[ "def", "visit_ListComp", "(", "self", ",", "node", ":", "ast", ".", "ListComp", ")", "->", "Any", ":", "result", "=", "self", ".", "_execute_comprehension", "(", "node", "=", "node", ")", "for", "generator", "in", "node", ".", "generators", ":", "self", ...
Compile the list comprehension as a function and call it.
[ "Compile", "the", "list", "comprehension", "as", "a", "function", "and", "call", "it", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L376-L384
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_SetComp
def visit_SetComp(self, node: ast.SetComp) -> Any: """Compile the set comprehension as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) self.recomputed_values[node] = result retur...
python
def visit_SetComp(self, node: ast.SetComp) -> Any: """Compile the set comprehension as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) self.recomputed_values[node] = result retur...
[ "def", "visit_SetComp", "(", "self", ",", "node", ":", "ast", ".", "SetComp", ")", "->", "Any", ":", "result", "=", "self", ".", "_execute_comprehension", "(", "node", "=", "node", ")", "for", "generator", "in", "node", ".", "generators", ":", "self", ...
Compile the set comprehension as a function and call it.
[ "Compile", "the", "set", "comprehension", "as", "a", "function", "and", "call", "it", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L386-L394
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_DictComp
def visit_DictComp(self, node: ast.DictComp) -> Any: """Compile the dictionary comprehension as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) self.recomputed_values[node] = result ...
python
def visit_DictComp(self, node: ast.DictComp) -> Any: """Compile the dictionary comprehension as a function and call it.""" result = self._execute_comprehension(node=node) for generator in node.generators: self.visit(generator.iter) self.recomputed_values[node] = result ...
[ "def", "visit_DictComp", "(", "self", ",", "node", ":", "ast", ".", "DictComp", ")", "->", "Any", ":", "result", "=", "self", ".", "_execute_comprehension", "(", "node", "=", "node", ")", "for", "generator", "in", "node", ".", "generators", ":", "self", ...
Compile the dictionary comprehension as a function and call it.
[ "Compile", "the", "dictionary", "comprehension", "as", "a", "function", "and", "call", "it", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L396-L404
train
Parquery/icontract
icontract/_recompute.py
Visitor.visit_Return
def visit_Return(self, node: ast.Return) -> Any: # pylint: disable=no-self-use """Raise an exception that this node is unexpected.""" raise AssertionError("Unexpected return node during the re-computation: {}".format(ast.dump(node)))
python
def visit_Return(self, node: ast.Return) -> Any: # pylint: disable=no-self-use """Raise an exception that this node is unexpected.""" raise AssertionError("Unexpected return node during the re-computation: {}".format(ast.dump(node)))
[ "def", "visit_Return", "(", "self", ",", "node", ":", "ast", ".", "Return", ")", "->", "Any", ":", "# pylint: disable=no-self-use", "raise", "AssertionError", "(", "\"Unexpected return node during the re-computation: {}\"", ".", "format", "(", "ast", ".", "dump", "(...
Raise an exception that this node is unexpected.
[ "Raise", "an", "exception", "that", "this", "node", "is", "unexpected", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L413-L415
train
Parquery/icontract
icontract/_recompute.py
Visitor.generic_visit
def generic_visit(self, node: ast.AST) -> None: """Raise an exception that this node has not been handled.""" raise NotImplementedError("Unhandled recomputation of the node: {} {}".format(type(node), node))
python
def generic_visit(self, node: ast.AST) -> None: """Raise an exception that this node has not been handled.""" raise NotImplementedError("Unhandled recomputation of the node: {} {}".format(type(node), node))
[ "def", "generic_visit", "(", "self", ",", "node", ":", "ast", ".", "AST", ")", "->", "None", ":", "raise", "NotImplementedError", "(", "\"Unhandled recomputation of the node: {} {}\"", ".", "format", "(", "type", "(", "node", ")", ",", "node", ")", ")" ]
Raise an exception that this node has not been handled.
[ "Raise", "an", "exception", "that", "this", "node", "has", "not", "been", "handled", "." ]
846e3187869a9ba790e9b893c98e5055e1cce274
https://github.com/Parquery/icontract/blob/846e3187869a9ba790e9b893c98e5055e1cce274/icontract/_recompute.py#L417-L419
train
lang-uk/tokenize-uk
tokenize_uk/tokenize_uk.py
tokenize_words
def tokenize_words(string): """ Tokenize input text to words. :param string: Text to tokenize :type string: str or unicode :return: words :rtype: list of strings """ string = six.text_type(string) return re.findall(WORD_TOKENIZATION_RULES, string)
python
def tokenize_words(string): """ Tokenize input text to words. :param string: Text to tokenize :type string: str or unicode :return: words :rtype: list of strings """ string = six.text_type(string) return re.findall(WORD_TOKENIZATION_RULES, string)
[ "def", "tokenize_words", "(", "string", ")", ":", "string", "=", "six", ".", "text_type", "(", "string", ")", "return", "re", ".", "findall", "(", "WORD_TOKENIZATION_RULES", ",", "string", ")" ]
Tokenize input text to words. :param string: Text to tokenize :type string: str or unicode :return: words :rtype: list of strings
[ "Tokenize", "input", "text", "to", "words", "." ]
52769b0f43af29d4a5863a7836364b3b9c10dd09
https://github.com/lang-uk/tokenize-uk/blob/52769b0f43af29d4a5863a7836364b3b9c10dd09/tokenize_uk/tokenize_uk.py#L44-L54
train
lang-uk/tokenize-uk
tokenize_uk/tokenize_uk.py
tokenize_sents
def tokenize_sents(string): """ Tokenize input text to sentences. :param string: Text to tokenize :type string: str or unicode :return: sentences :rtype: list of strings """ string = six.text_type(string) spans = [] for match in re.finditer('[^\s]+', string): spans.appe...
python
def tokenize_sents(string): """ Tokenize input text to sentences. :param string: Text to tokenize :type string: str or unicode :return: sentences :rtype: list of strings """ string = six.text_type(string) spans = [] for match in re.finditer('[^\s]+', string): spans.appe...
[ "def", "tokenize_sents", "(", "string", ")", ":", "string", "=", "six", ".", "text_type", "(", "string", ")", "spans", "=", "[", "]", "for", "match", "in", "re", ".", "finditer", "(", "'[^\\s]+'", ",", "string", ")", ":", "spans", ".", "append", "(",...
Tokenize input text to sentences. :param string: Text to tokenize :type string: str or unicode :return: sentences :rtype: list of strings
[ "Tokenize", "input", "text", "to", "sentences", "." ]
52769b0f43af29d4a5863a7836364b3b9c10dd09
https://github.com/lang-uk/tokenize-uk/blob/52769b0f43af29d4a5863a7836364b3b9c10dd09/tokenize_uk/tokenize_uk.py#L57-L91
train
lang-uk/tokenize-uk
tokenize_uk/tokenize_uk.py
tokenize_text
def tokenize_text(string): """ Tokenize input text to paragraphs, sentences and words. Tokenization to paragraphs is done using simple Newline algorithm For sentences and words tokenizers above are used :param string: Text to tokenize :type string: str or unicode :return: text, tokenized i...
python
def tokenize_text(string): """ Tokenize input text to paragraphs, sentences and words. Tokenization to paragraphs is done using simple Newline algorithm For sentences and words tokenizers above are used :param string: Text to tokenize :type string: str or unicode :return: text, tokenized i...
[ "def", "tokenize_text", "(", "string", ")", ":", "string", "=", "six", ".", "text_type", "(", "string", ")", "rez", "=", "[", "]", "for", "part", "in", "string", ".", "split", "(", "'\\n'", ")", ":", "par", "=", "[", "]", "for", "sent", "in", "to...
Tokenize input text to paragraphs, sentences and words. Tokenization to paragraphs is done using simple Newline algorithm For sentences and words tokenizers above are used :param string: Text to tokenize :type string: str or unicode :return: text, tokenized into paragraphs, sentences and words ...
[ "Tokenize", "input", "text", "to", "paragraphs", "sentences", "and", "words", "." ]
52769b0f43af29d4a5863a7836364b3b9c10dd09
https://github.com/lang-uk/tokenize-uk/blob/52769b0f43af29d4a5863a7836364b3b9c10dd09/tokenize_uk/tokenize_uk.py#L94-L114
train
interedition/collatex
collatex-pythonport/collatex/experimental_astar_aligner.py
ExperimentalAstarAligner.collate
def collate(self, graph, collation): ''' :type graph: VariantGraph :type collation: Collation ''' # Build the variant graph for the first witness # this is easy: generate a vertex for every token first_witness = collation.witnesses[0] tokens = first_witnes...
python
def collate(self, graph, collation): ''' :type graph: VariantGraph :type collation: Collation ''' # Build the variant graph for the first witness # this is easy: generate a vertex for every token first_witness = collation.witnesses[0] tokens = first_witnes...
[ "def", "collate", "(", "self", ",", "graph", ",", "collation", ")", ":", "# Build the variant graph for the first witness", "# this is easy: generate a vertex for every token", "first_witness", "=", "collation", ".", "witnesses", "[", "0", "]", "tokens", "=", "first_witne...
:type graph: VariantGraph :type collation: Collation
[ ":", "type", "graph", ":", "VariantGraph", ":", "type", "collation", ":", "Collation" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/experimental_astar_aligner.py#L21-L64
train
interedition/collatex
collatex-pythonport/collatex/experimental_astar_aligner.py
Aligner.align
def align(self): ''' Every step we have 3 choices: 1) Move pointer witness a --> omission 2) Move pointer witness b --> addition 3) Move pointer of both witness a/b --> match Note: a replacement is omission followed by an addition or the other way around Choice ...
python
def align(self): ''' Every step we have 3 choices: 1) Move pointer witness a --> omission 2) Move pointer witness b --> addition 3) Move pointer of both witness a/b --> match Note: a replacement is omission followed by an addition or the other way around Choice ...
[ "def", "align", "(", "self", ")", ":", "# extract tokens from witness (note that this can be done in a streaming manner if desired)", "tokens_a", "=", "self", ".", "witness_a", ".", "tokens", "(", ")", "tokens_b", "=", "self", ".", "witness_b", ".", "tokens", "(", ")"...
Every step we have 3 choices: 1) Move pointer witness a --> omission 2) Move pointer witness b --> addition 3) Move pointer of both witness a/b --> match Note: a replacement is omission followed by an addition or the other way around Choice 1 and 2 are only possible if token a ...
[ "Every", "step", "we", "have", "3", "choices", ":", "1", ")", "Move", "pointer", "witness", "a", "--", ">", "omission", "2", ")", "Move", "pointer", "witness", "b", "--", ">", "addition", "3", ")", "Move", "pointer", "of", "both", "witness", "a", "/"...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/experimental_astar_aligner.py#L276-L299
train
interedition/collatex
collatex-pythonport/collatex/core_classes.py
VariantGraph.connect
def connect(self, source, target, witnesses): """ :type source: integer :type target: integer """ # print("Adding Edge: "+source+":"+target) if self.graph.has_edge(source, target): self.graph[source][target]["label"] += ", " + str(witnesses) else: ...
python
def connect(self, source, target, witnesses): """ :type source: integer :type target: integer """ # print("Adding Edge: "+source+":"+target) if self.graph.has_edge(source, target): self.graph[source][target]["label"] += ", " + str(witnesses) else: ...
[ "def", "connect", "(", "self", ",", "source", ",", "target", ",", "witnesses", ")", ":", "# print(\"Adding Edge: \"+source+\":\"+target)", "if", "self", ".", "graph", ".", "has_edge", "(", "source", ",", "target", ")", ":", "self", ".", "graph", "[", "source...
:type source: integer :type target: integer
[ ":", "type", "source", ":", "integer", ":", "type", "target", ":", "integer" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/core_classes.py#L238-L247
train
interedition/collatex
collatex-pythonport/collatex/core_classes.py
VariantGraph.connect_near
def connect_near(self, source, target, weight): # Near edges are added to self.near_graph, not self.graph, to avoid cycles """ :type source: integer :type target: integer """ self.near_graph.add_edge(source, target, weight = weight, type='near')
python
def connect_near(self, source, target, weight): # Near edges are added to self.near_graph, not self.graph, to avoid cycles """ :type source: integer :type target: integer """ self.near_graph.add_edge(source, target, weight = weight, type='near')
[ "def", "connect_near", "(", "self", ",", "source", ",", "target", ",", "weight", ")", ":", "# Near edges are added to self.near_graph, not self.graph, to avoid cycles", "self", ".", "near_graph", ".", "add_edge", "(", "source", ",", "target", ",", "weight", "=", "we...
:type source: integer :type target: integer
[ ":", "type", "source", ":", "integer", ":", "type", "target", ":", "integer" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/core_classes.py#L249-L255
train
interedition/collatex
collatex-pythonport/collatex/core_classes.py
CollationAlgorithm.merge
def merge(self, graph, witness_sigil, witness_tokens, alignments={}): """ :type graph: VariantGraph """ # NOTE: token_to_vertex only contains newly generated vertices token_to_vertex = {} last = graph.start for token in witness_tokens: vertex = alignme...
python
def merge(self, graph, witness_sigil, witness_tokens, alignments={}): """ :type graph: VariantGraph """ # NOTE: token_to_vertex only contains newly generated vertices token_to_vertex = {} last = graph.start for token in witness_tokens: vertex = alignme...
[ "def", "merge", "(", "self", ",", "graph", ",", "witness_sigil", ",", "witness_tokens", ",", "alignments", "=", "{", "}", ")", ":", "# NOTE: token_to_vertex only contains newly generated vertices", "token_to_vertex", "=", "{", "}", "last", "=", "graph", ".", "star...
:type graph: VariantGraph
[ ":", "type", "graph", ":", "VariantGraph" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/core_classes.py#L296-L314
train
interedition/collatex
collatex-pythonport/collatex/edit_graph_aligner.py
EditGraphAligner.collate
def collate(self, graph): """ :type graph: VariantGraph """ # prepare the token index self.token_index.prepare() self.vertex_array = [None] * len(self.token_index.token_array) # Build the variant graph for the first witness # this is easy: generate a vert...
python
def collate(self, graph): """ :type graph: VariantGraph """ # prepare the token index self.token_index.prepare() self.vertex_array = [None] * len(self.token_index.token_array) # Build the variant graph for the first witness # this is easy: generate a vert...
[ "def", "collate", "(", "self", ",", "graph", ")", ":", "# prepare the token index", "self", ".", "token_index", ".", "prepare", "(", ")", "self", ".", "vertex_array", "=", "[", "None", "]", "*", "len", "(", "self", ".", "token_index", ".", "token_array", ...
:type graph: VariantGraph
[ ":", "type", "graph", ":", "VariantGraph" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/edit_graph_aligner.py#L195-L260
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet._parse
def _parse(self, pattern): """Parse string of comma-separated x-y/step -like ranges""" # Comma separated ranges if pattern.find(',') < 0: subranges = [pattern] else: subranges = pattern.split(',') for subrange in subranges: if subrange.find('/...
python
def _parse(self, pattern): """Parse string of comma-separated x-y/step -like ranges""" # Comma separated ranges if pattern.find(',') < 0: subranges = [pattern] else: subranges = pattern.split(',') for subrange in subranges: if subrange.find('/...
[ "def", "_parse", "(", "self", ",", "pattern", ")", ":", "# Comma separated ranges", "if", "pattern", ".", "find", "(", "','", ")", "<", "0", ":", "subranges", "=", "[", "pattern", "]", "else", ":", "subranges", "=", "pattern", ".", "split", "(", "','",...
Parse string of comma-separated x-y/step -like ranges
[ "Parse", "string", "of", "comma", "-", "separated", "x", "-", "y", "/", "step", "-", "like", "ranges" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L123-L178
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.fromlist
def fromlist(cls, rnglist, autostep=None): """Class method that returns a new RangeSet with ranges from provided list.""" inst = RangeSet(autostep=autostep) inst.updaten(rnglist) return inst
python
def fromlist(cls, rnglist, autostep=None): """Class method that returns a new RangeSet with ranges from provided list.""" inst = RangeSet(autostep=autostep) inst.updaten(rnglist) return inst
[ "def", "fromlist", "(", "cls", ",", "rnglist", ",", "autostep", "=", "None", ")", ":", "inst", "=", "RangeSet", "(", "autostep", "=", "autostep", ")", "inst", ".", "updaten", "(", "rnglist", ")", "return", "inst" ]
Class method that returns a new RangeSet with ranges from provided list.
[ "Class", "method", "that", "returns", "a", "new", "RangeSet", "with", "ranges", "from", "provided", "list", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L181-L186
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.fromone
def fromone(cls, index, pad=0, autostep=None): """Class method that returns a new RangeSet of one single item or a single range (from integer or slice object).""" inst = RangeSet(autostep=autostep) # support slice object with duck-typing try: inst.add(index, pad) ...
python
def fromone(cls, index, pad=0, autostep=None): """Class method that returns a new RangeSet of one single item or a single range (from integer or slice object).""" inst = RangeSet(autostep=autostep) # support slice object with duck-typing try: inst.add(index, pad) ...
[ "def", "fromone", "(", "cls", ",", "index", ",", "pad", "=", "0", ",", "autostep", "=", "None", ")", ":", "inst", "=", "RangeSet", "(", "autostep", "=", "autostep", ")", "# support slice object with duck-typing", "try", ":", "inst", ".", "add", "(", "ind...
Class method that returns a new RangeSet of one single item or a single range (from integer or slice object).
[ "Class", "method", "that", "returns", "a", "new", "RangeSet", "of", "one", "single", "item", "or", "a", "single", "range", "(", "from", "integer", "or", "slice", "object", ")", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L189-L200
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.set_autostep
def set_autostep(self, val): """Set autostep value (property)""" if val is None: # disabled by default for pdsh compat (+inf is 1E400, but a bug in # python 2.4 makes it impossible to be pickled, so we use less) # NOTE: Later, we could consider sys.maxint here ...
python
def set_autostep(self, val): """Set autostep value (property)""" if val is None: # disabled by default for pdsh compat (+inf is 1E400, but a bug in # python 2.4 makes it impossible to be pickled, so we use less) # NOTE: Later, we could consider sys.maxint here ...
[ "def", "set_autostep", "(", "self", ",", "val", ")", ":", "if", "val", "is", "None", ":", "# disabled by default for pdsh compat (+inf is 1E400, but a bug in", "# python 2.4 makes it impossible to be pickled, so we use less)", "# NOTE: Later, we could consider sys.maxint here", "self...
Set autostep value (property)
[ "Set", "autostep", "value", "(", "property", ")" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L209-L218
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.striter
def striter(self): """Iterate over each (optionally padded) string element in RangeSet.""" pad = self.padding or 0 for i in self._sorted(): yield "%0*d" % (pad, i)
python
def striter(self): """Iterate over each (optionally padded) string element in RangeSet.""" pad = self.padding or 0 for i in self._sorted(): yield "%0*d" % (pad, i)
[ "def", "striter", "(", "self", ")", ":", "pad", "=", "self", ".", "padding", "or", "0", "for", "i", "in", "self", ".", "_sorted", "(", ")", ":", "yield", "\"%0*d\"", "%", "(", "pad", ",", "i", ")" ]
Iterate over each (optionally padded) string element in RangeSet.
[ "Iterate", "over", "each", "(", "optionally", "padded", ")", "string", "element", "in", "RangeSet", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L230-L234
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.contiguous
def contiguous(self): """Object-based iterator over contiguous range sets.""" pad = self.padding or 0 for sli in self._contiguous_slices(): yield RangeSet.fromone(slice(sli.start, sli.stop, sli.step), pad)
python
def contiguous(self): """Object-based iterator over contiguous range sets.""" pad = self.padding or 0 for sli in self._contiguous_slices(): yield RangeSet.fromone(slice(sli.start, sli.stop, sli.step), pad)
[ "def", "contiguous", "(", "self", ")", ":", "pad", "=", "self", ".", "padding", "or", "0", "for", "sli", "in", "self", ".", "_contiguous_slices", "(", ")", ":", "yield", "RangeSet", ".", "fromone", "(", "slice", "(", "sli", ".", "start", ",", "sli", ...
Object-based iterator over contiguous range sets.
[ "Object", "-", "based", "iterator", "over", "contiguous", "range", "sets", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L236-L240
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet._strslices
def _strslices(self): """Stringify slices list (x-y/step format)""" pad = self.padding or 0 for sli in self.slices(): if sli.start + 1 == sli.stop: yield "%0*d" % (pad, sli.start) else: assert sli.step >= 0, "Internal error: sli.step < 0" ...
python
def _strslices(self): """Stringify slices list (x-y/step format)""" pad = self.padding or 0 for sli in self.slices(): if sli.start + 1 == sli.stop: yield "%0*d" % (pad, sli.start) else: assert sli.step >= 0, "Internal error: sli.step < 0" ...
[ "def", "_strslices", "(", "self", ")", ":", "pad", "=", "self", ".", "padding", "or", "0", "for", "sli", "in", "self", ".", "slices", "(", ")", ":", "if", "sli", ".", "start", "+", "1", "==", "sli", ".", "stop", ":", "yield", "\"%0*d\"", "%", "...
Stringify slices list (x-y/step format)
[ "Stringify", "slices", "list", "(", "x", "-", "y", "/", "step", "format", ")" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L271-L283
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet._contiguous_slices
def _contiguous_slices(self): """Internal iterator over contiguous slices in RangeSet.""" k = j = None for i in self._sorted(): if k is None: k = j = i if i - j > 1: yield slice(k, j + 1, 1) k = i j = i i...
python
def _contiguous_slices(self): """Internal iterator over contiguous slices in RangeSet.""" k = j = None for i in self._sorted(): if k is None: k = j = i if i - j > 1: yield slice(k, j + 1, 1) k = i j = i i...
[ "def", "_contiguous_slices", "(", "self", ")", ":", "k", "=", "j", "=", "None", "for", "i", "in", "self", ".", "_sorted", "(", ")", ":", "if", "k", "is", "None", ":", "k", "=", "j", "=", "i", "if", "i", "-", "j", ">", "1", ":", "yield", "sl...
Internal iterator over contiguous slices in RangeSet.
[ "Internal", "iterator", "over", "contiguous", "slices", "in", "RangeSet", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L293-L304
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet._folded_slices
def _folded_slices(self): """Internal generator that is able to retrieve ranges organized by step. Complexity: O(n) with n = number of ranges in tree.""" if len(self) == 0: return prng = None # pending range istart = None # processing starting indice ...
python
def _folded_slices(self): """Internal generator that is able to retrieve ranges organized by step. Complexity: O(n) with n = number of ranges in tree.""" if len(self) == 0: return prng = None # pending range istart = None # processing starting indice ...
[ "def", "_folded_slices", "(", "self", ")", ":", "if", "len", "(", "self", ")", "==", "0", ":", "return", "prng", "=", "None", "# pending range", "istart", "=", "None", "# processing starting indice", "m", "=", "0", "# processing step", "for", "sli", "in", ...
Internal generator that is able to retrieve ranges organized by step. Complexity: O(n) with n = number of ranges in tree.
[ "Internal", "generator", "that", "is", "able", "to", "retrieve", "ranges", "organized", "by", "step", ".", "Complexity", ":", "O", "(", "n", ")", "with", "n", "=", "number", "of", "ranges", "in", "tree", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L306-L406
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.split
def split(self, nbr): """ Split the rangeset into nbr sub-rangesets (at most). Each sub-rangeset will have the same number of elements more or less 1. Current rangeset remains unmodified. Returns an iterator. >>> RangeSet("1-5").split(3) RangeSet("1-2") ...
python
def split(self, nbr): """ Split the rangeset into nbr sub-rangesets (at most). Each sub-rangeset will have the same number of elements more or less 1. Current rangeset remains unmodified. Returns an iterator. >>> RangeSet("1-5").split(3) RangeSet("1-2") ...
[ "def", "split", "(", "self", ",", "nbr", ")", ":", "assert", "(", "nbr", ">", "0", ")", "# We put the same number of element in each sub-nodeset.", "slice_size", "=", "len", "(", "self", ")", "/", "nbr", "left", "=", "len", "(", "self", ")", "%", "nbr", ...
Split the rangeset into nbr sub-rangesets (at most). Each sub-rangeset will have the same number of elements more or less 1. Current rangeset remains unmodified. Returns an iterator. >>> RangeSet("1-5").split(3) RangeSet("1-2") RangeSet("3-4") RangeSet("foo5")
[ "Split", "the", "rangeset", "into", "nbr", "sub", "-", "rangesets", "(", "at", "most", ")", ".", "Each", "sub", "-", "rangeset", "will", "have", "the", "same", "number", "of", "elements", "more", "or", "less", "1", ".", "Current", "rangeset", "remains", ...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L433-L455
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.add_range
def add_range(self, start, stop, step=1, pad=0): """ Add a range (start, stop, step and padding length) to RangeSet. Like the Python built-in function range(), the last element is the largest start + i * step less than stop. """ assert start < stop, "please provide ordere...
python
def add_range(self, start, stop, step=1, pad=0): """ Add a range (start, stop, step and padding length) to RangeSet. Like the Python built-in function range(), the last element is the largest start + i * step less than stop. """ assert start < stop, "please provide ordere...
[ "def", "add_range", "(", "self", ",", "start", ",", "stop", ",", "step", "=", "1", ",", "pad", "=", "0", ")", ":", "assert", "start", "<", "stop", ",", "\"please provide ordered node index ranges\"", "assert", "step", ">", "0", "assert", "pad", ">=", "0"...
Add a range (start, stop, step and padding length) to RangeSet. Like the Python built-in function range(), the last element is the largest start + i * step less than stop.
[ "Add", "a", "range", "(", "start", "stop", "step", "and", "padding", "length", ")", "to", "RangeSet", ".", "Like", "the", "Python", "built", "-", "in", "function", "range", "()", "the", "last", "element", "is", "the", "largest", "start", "+", "i", "*",...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L457-L470
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.copy
def copy(self): """Return a shallow copy of a RangeSet.""" cpy = self.__class__() cpy._autostep = self._autostep cpy.padding = self.padding cpy.update(self) return cpy
python
def copy(self): """Return a shallow copy of a RangeSet.""" cpy = self.__class__() cpy._autostep = self._autostep cpy.padding = self.padding cpy.update(self) return cpy
[ "def", "copy", "(", "self", ")", ":", "cpy", "=", "self", ".", "__class__", "(", ")", "cpy", ".", "_autostep", "=", "self", ".", "_autostep", "cpy", ".", "padding", "=", "self", ".", "padding", "cpy", ".", "update", "(", "self", ")", "return", "cpy...
Return a shallow copy of a RangeSet.
[ "Return", "a", "shallow", "copy", "of", "a", "RangeSet", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L472-L478
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet._wrap_set_op
def _wrap_set_op(self, fun, arg): """Wrap built-in set operations for RangeSet to workaround built-in set base class issues (RangeSet.__new/init__ not called)""" result = fun(self, arg) result._autostep = self._autostep result.padding = self.padding return result
python
def _wrap_set_op(self, fun, arg): """Wrap built-in set operations for RangeSet to workaround built-in set base class issues (RangeSet.__new/init__ not called)""" result = fun(self, arg) result._autostep = self._autostep result.padding = self.padding return result
[ "def", "_wrap_set_op", "(", "self", ",", "fun", ",", "arg", ")", ":", "result", "=", "fun", "(", "self", ",", "arg", ")", "result", ".", "_autostep", "=", "self", ".", "_autostep", "result", ".", "padding", "=", "self", ".", "padding", "return", "res...
Wrap built-in set operations for RangeSet to workaround built-in set base class issues (RangeSet.__new/init__ not called)
[ "Wrap", "built", "-", "in", "set", "operations", "for", "RangeSet", "to", "workaround", "built", "-", "in", "set", "base", "class", "issues", "(", "RangeSet", ".", "__new", "/", "init__", "not", "called", ")" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L504-L510
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.intersection
def intersection(self, other): """Return the intersection of two RangeSets as a new RangeSet. (I.e. all elements that are in both sets.) """ #NOTE: This is a work around # Python 3 return as the result of set.intersection a new set instance. # Python 2 however returns a...
python
def intersection(self, other): """Return the intersection of two RangeSets as a new RangeSet. (I.e. all elements that are in both sets.) """ #NOTE: This is a work around # Python 3 return as the result of set.intersection a new set instance. # Python 2 however returns a...
[ "def", "intersection", "(", "self", ",", "other", ")", ":", "#NOTE: This is a work around ", "# Python 3 return as the result of set.intersection a new set instance.", "# Python 2 however returns as a the result a ClusterShell.RangeSet.RangeSet instance.", "# ORIGINAL CODE: return self._wrap_s...
Return the intersection of two RangeSets as a new RangeSet. (I.e. all elements that are in both sets.)
[ "Return", "the", "intersection", "of", "two", "RangeSets", "as", "a", "new", "RangeSet", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L537-L548
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.difference
def difference(self, other): """Return the difference of two RangeSets as a new RangeSet. (I.e. all elements that are in this set and not in the other.) """ #NOTE: This is a work around # Python 3 return as the result of set.intersection a new set instance. # Python 2 ho...
python
def difference(self, other): """Return the difference of two RangeSets as a new RangeSet. (I.e. all elements that are in this set and not in the other.) """ #NOTE: This is a work around # Python 3 return as the result of set.intersection a new set instance. # Python 2 ho...
[ "def", "difference", "(", "self", ",", "other", ")", ":", "#NOTE: This is a work around", "# Python 3 return as the result of set.intersection a new set instance.", "# Python 2 however returns as a the result a ClusterShell.RangeSet.RangeSet instance.", "# ORIGINAL CODE: return self._wrap_set_...
Return the difference of two RangeSets as a new RangeSet. (I.e. all elements that are in this set and not in the other.)
[ "Return", "the", "difference", "of", "two", "RangeSets", "as", "a", "new", "RangeSet", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L575-L586
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.issubset
def issubset(self, other): """Report whether another set contains this RangeSet.""" self._binary_sanity_check(other) return set.issubset(self, other)
python
def issubset(self, other): """Report whether another set contains this RangeSet.""" self._binary_sanity_check(other) return set.issubset(self, other)
[ "def", "issubset", "(", "self", ",", "other", ")", ":", "self", ".", "_binary_sanity_check", "(", "other", ")", "return", "set", ".", "issubset", "(", "self", ",", "other", ")" ]
Report whether another set contains this RangeSet.
[ "Report", "whether", "another", "set", "contains", "this", "RangeSet", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L604-L607
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.issuperset
def issuperset(self, other): """Report whether this RangeSet contains another set.""" self._binary_sanity_check(other) return set.issuperset(self, other)
python
def issuperset(self, other): """Report whether this RangeSet contains another set.""" self._binary_sanity_check(other) return set.issuperset(self, other)
[ "def", "issuperset", "(", "self", ",", "other", ")", ":", "self", ".", "_binary_sanity_check", "(", "other", ")", "return", "set", ".", "issuperset", "(", "self", ",", "other", ")" ]
Report whether this RangeSet contains another set.
[ "Report", "whether", "this", "RangeSet", "contains", "another", "set", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L609-L612
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.difference_update
def difference_update(self, other, strict=False): """Remove all elements of another set from this RangeSet. If strict is True, raise KeyError if an element cannot be removed. (strict is a RangeSet addition)""" if strict and other not in self: raise KeyError(other.dif...
python
def difference_update(self, other, strict=False): """Remove all elements of another set from this RangeSet. If strict is True, raise KeyError if an element cannot be removed. (strict is a RangeSet addition)""" if strict and other not in self: raise KeyError(other.dif...
[ "def", "difference_update", "(", "self", ",", "other", ",", "strict", "=", "False", ")", ":", "if", "strict", "and", "other", "not", "in", "self", ":", "raise", "KeyError", "(", "other", ".", "difference", "(", "self", ")", "[", "0", "]", ")", "set",...
Remove all elements of another set from this RangeSet. If strict is True, raise KeyError if an element cannot be removed. (strict is a RangeSet addition)
[ "Remove", "all", "elements", "of", "another", "set", "from", "this", "RangeSet", ".", "If", "strict", "is", "True", "raise", "KeyError", "if", "an", "element", "cannot", "be", "removed", ".", "(", "strict", "is", "a", "RangeSet", "addition", ")" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L677-L684
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.update
def update(self, iterable): """Add all integers from an iterable (such as a list).""" if isinstance(iterable, RangeSet): # keep padding unless is has not been defined yet if self.padding is None and iterable.padding is not None: self.padding = iterable.padding ...
python
def update(self, iterable): """Add all integers from an iterable (such as a list).""" if isinstance(iterable, RangeSet): # keep padding unless is has not been defined yet if self.padding is None and iterable.padding is not None: self.padding = iterable.padding ...
[ "def", "update", "(", "self", ",", "iterable", ")", ":", "if", "isinstance", "(", "iterable", ",", "RangeSet", ")", ":", "# keep padding unless is has not been defined yet", "if", "self", ".", "padding", "is", "None", "and", "iterable", ".", "padding", "is", "...
Add all integers from an iterable (such as a list).
[ "Add", "all", "integers", "from", "an", "iterable", "(", "such", "as", "a", "list", ")", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L688-L695
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.updaten
def updaten(self, rangesets): """ Update a rangeset with the union of itself and several others. """ for rng in rangesets: if isinstance(rng, set): self.update(rng) else: self.update(RangeSet(rng))
python
def updaten(self, rangesets): """ Update a rangeset with the union of itself and several others. """ for rng in rangesets: if isinstance(rng, set): self.update(rng) else: self.update(RangeSet(rng))
[ "def", "updaten", "(", "self", ",", "rangesets", ")", ":", "for", "rng", "in", "rangesets", ":", "if", "isinstance", "(", "rng", ",", "set", ")", ":", "self", ".", "update", "(", "rng", ")", "else", ":", "self", ".", "update", "(", "RangeSet", "(",...
Update a rangeset with the union of itself and several others.
[ "Update", "a", "rangeset", "with", "the", "union", "of", "itself", "and", "several", "others", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L697-L705
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.add
def add(self, element, pad=0): """Add an element to a RangeSet. This has no effect if the element is already present. """ set.add(self, int(element)) if pad > 0 and self.padding is None: self.padding = pad
python
def add(self, element, pad=0): """Add an element to a RangeSet. This has no effect if the element is already present. """ set.add(self, int(element)) if pad > 0 and self.padding is None: self.padding = pad
[ "def", "add", "(", "self", ",", "element", ",", "pad", "=", "0", ")", ":", "set", ".", "add", "(", "self", ",", "int", "(", "element", ")", ")", "if", "pad", ">", "0", "and", "self", ".", "padding", "is", "None", ":", "self", ".", "padding", ...
Add an element to a RangeSet. This has no effect if the element is already present.
[ "Add", "an", "element", "to", "a", "RangeSet", ".", "This", "has", "no", "effect", "if", "the", "element", "is", "already", "present", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L716-L722
train
interedition/collatex
collatex-pythonport/ClusterShell/RangeSet.py
RangeSet.discard
def discard(self, element): """Remove element from the RangeSet if it is a member. If the element is not a member, do nothing. """ try: i = int(element) set.discard(self, i) except ValueError: pass
python
def discard(self, element): """Remove element from the RangeSet if it is a member. If the element is not a member, do nothing. """ try: i = int(element) set.discard(self, i) except ValueError: pass
[ "def", "discard", "(", "self", ",", "element", ")", ":", "try", ":", "i", "=", "int", "(", "element", ")", "set", ".", "discard", "(", "self", ",", "i", ")", "except", "ValueError", ":", "pass" ]
Remove element from the RangeSet if it is a member. If the element is not a member, do nothing.
[ "Remove", "element", "from", "the", "RangeSet", "if", "it", "is", "a", "member", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/ClusterShell/RangeSet.py#L732-L741
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
_open
def _open(filename, mode="r"): """ Universal open file facility. With normal files, this function behaves as the open builtin. With gzip-ed files, it decompress or compress according to the specified mode. In addition, when filename is '-', it opens the standard input or output according to the ...
python
def _open(filename, mode="r"): """ Universal open file facility. With normal files, this function behaves as the open builtin. With gzip-ed files, it decompress or compress according to the specified mode. In addition, when filename is '-', it opens the standard input or output according to the ...
[ "def", "_open", "(", "filename", ",", "mode", "=", "\"r\"", ")", ":", "if", "filename", ".", "endswith", "(", "\".gz\"", ")", ":", "return", "GzipFile", "(", "filename", ",", "mode", ",", "COMPRESSION_LEVEL", ")", "elif", "filename", "==", "\"-\"", ":", ...
Universal open file facility. With normal files, this function behaves as the open builtin. With gzip-ed files, it decompress or compress according to the specified mode. In addition, when filename is '-', it opens the standard input or output according to the specified mode. Mode are expected to be...
[ "Universal", "open", "file", "facility", ".", "With", "normal", "files", "this", "function", "behaves", "as", "the", "open", "builtin", ".", "With", "gzip", "-", "ed", "files", "it", "decompress", "or", "compress", "according", "to", "the", "specified", "mod...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L62-L80
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
_radixPass
def _radixPass(a, b, r, n, K): """ Stable sort of the sequence a according to the keys given in r. >>> a=range(5) >>> b=[0]*5 >>> r=[2,1,3,0,4] >>> _radixPass(a, b, r, 5, 5) >>> b [3, 1, 0, 2, 4] When n is less than the length of a, the end of b must be left unaltered. >>> b=[...
python
def _radixPass(a, b, r, n, K): """ Stable sort of the sequence a according to the keys given in r. >>> a=range(5) >>> b=[0]*5 >>> r=[2,1,3,0,4] >>> _radixPass(a, b, r, 5, 5) >>> b [3, 1, 0, 2, 4] When n is less than the length of a, the end of b must be left unaltered. >>> b=[...
[ "def", "_radixPass", "(", "a", ",", "b", ",", "r", ",", "n", ",", "K", ")", ":", "c", "=", "_array", "(", "\"i\"", ",", "[", "0", "]", "*", "(", "K", "+", "1", ")", ")", "# counter array", "for", "i", "in", "range", "(", "n", ")", ":", "#...
Stable sort of the sequence a according to the keys given in r. >>> a=range(5) >>> b=[0]*5 >>> r=[2,1,3,0,4] >>> _radixPass(a, b, r, 5, 5) >>> b [3, 1, 0, 2, 4] When n is less than the length of a, the end of b must be left unaltered. >>> b=[5]*5 >>> _radixPass(a, b, r, 2, 2) ...
[ "Stable", "sort", "of", "the", "sequence", "a", "according", "to", "the", "keys", "given", "in", "r", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L83-L136
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
_nbOperations
def _nbOperations(n): """ Exact number of atomic operations in _radixPass. """ if n < 2: return 0 else: n0 = (n + 2) // 3 n02 = n0 + n // 3 return 3 * (n02) + n0 + _nbOperations(n02)
python
def _nbOperations(n): """ Exact number of atomic operations in _radixPass. """ if n < 2: return 0 else: n0 = (n + 2) // 3 n02 = n0 + n // 3 return 3 * (n02) + n0 + _nbOperations(n02)
[ "def", "_nbOperations", "(", "n", ")", ":", "if", "n", "<", "2", ":", "return", "0", "else", ":", "n0", "=", "(", "n", "+", "2", ")", "//", "3", "n02", "=", "n0", "+", "n", "//", "3", "return", "3", "*", "(", "n02", ")", "+", "n0", "+", ...
Exact number of atomic operations in _radixPass.
[ "Exact", "number", "of", "atomic", "operations", "in", "_radixPass", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L139-L149
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
_suffixArrayWithTrace
def _suffixArrayWithTrace(s, SA, n, K, operations, totalOperations): """ This function is a rewrite in Python of the C implementation proposed in Kärkkäinen and Sanders paper. Find the suffix array SA of s[0..n-1] in {1..K}^n Require s[n]=s[n+1]=s[n+2]=0, n>=2 """ if _trace: _traceSuffi...
python
def _suffixArrayWithTrace(s, SA, n, K, operations, totalOperations): """ This function is a rewrite in Python of the C implementation proposed in Kärkkäinen and Sanders paper. Find the suffix array SA of s[0..n-1] in {1..K}^n Require s[n]=s[n+1]=s[n+2]=0, n>=2 """ if _trace: _traceSuffi...
[ "def", "_suffixArrayWithTrace", "(", "s", ",", "SA", ",", "n", ",", "K", ",", "operations", ",", "totalOperations", ")", ":", "if", "_trace", ":", "_traceSuffixArray", "(", "operations", ",", "totalOperations", ")", "n0", "=", "(", "n", "+", "2", ")", ...
This function is a rewrite in Python of the C implementation proposed in Kärkkäinen and Sanders paper. Find the suffix array SA of s[0..n-1] in {1..K}^n Require s[n]=s[n+1]=s[n+2]=0, n>=2
[ "This", "function", "is", "a", "rewrite", "in", "Python", "of", "the", "C", "implementation", "proposed", "in", "Kärkkäinen", "and", "Sanders", "paper", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L161-L281
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
_longestCommonPrefix
def _longestCommonPrefix(seq1, seq2, start1=0, start2=0): """ Returns the length of the longest common prefix of seq1 starting at offset start1 and seq2 starting at offset start2. >>> _longestCommonPrefix("abcdef", "abcghj") 3 >>> _longestCommonPrefix("abcghj", "abcdef") 3 >>> _longes...
python
def _longestCommonPrefix(seq1, seq2, start1=0, start2=0): """ Returns the length of the longest common prefix of seq1 starting at offset start1 and seq2 starting at offset start2. >>> _longestCommonPrefix("abcdef", "abcghj") 3 >>> _longestCommonPrefix("abcghj", "abcdef") 3 >>> _longes...
[ "def", "_longestCommonPrefix", "(", "seq1", ",", "seq2", ",", "start1", "=", "0", ",", "start2", "=", "0", ")", ":", "len1", "=", "len", "(", "seq1", ")", "-", "start1", "len2", "=", "len", "(", "seq2", ")", "-", "start2", "# We set seq2 as the shortes...
Returns the length of the longest common prefix of seq1 starting at offset start1 and seq2 starting at offset start2. >>> _longestCommonPrefix("abcdef", "abcghj") 3 >>> _longestCommonPrefix("abcghj", "abcdef") 3 >>> _longestCommonPrefix("miss", "") 0 >>> _longestCommonPrefix("", "mr"...
[ "Returns", "the", "length", "of", "the", "longest", "common", "prefix", "of", "seq1", "starting", "at", "offset", "start1", "and", "seq2", "starting", "at", "offset", "start2", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L297-L351
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
LCP
def LCP(SA): """ Compute the longest common prefix for every adjacent suffixes. The result is a list of same size as SA. Given two suffixes at positions i and i+1, their LCP is stored at position i+1. A zero is stored at position 0 of the output. >>> SA=SuffixArray("abba", unit=UNIT_BYTE) ...
python
def LCP(SA): """ Compute the longest common prefix for every adjacent suffixes. The result is a list of same size as SA. Given two suffixes at positions i and i+1, their LCP is stored at position i+1. A zero is stored at position 0 of the output. >>> SA=SuffixArray("abba", unit=UNIT_BYTE) ...
[ "def", "LCP", "(", "SA", ")", ":", "string", "=", "SA", ".", "string", "length", "=", "SA", ".", "length", "lcps", "=", "_array", "(", "\"i\"", ",", "[", "0", "]", "*", "length", ")", "SA", "=", "SA", ".", "SA", "if", "_trace", ":", "delta", ...
Compute the longest common prefix for every adjacent suffixes. The result is a list of same size as SA. Given two suffixes at positions i and i+1, their LCP is stored at position i+1. A zero is stored at position 0 of the output. >>> SA=SuffixArray("abba", unit=UNIT_BYTE) >>> SA._LCP_values ...
[ "Compute", "the", "longest", "common", "prefix", "for", "every", "adjacent", "suffixes", ".", "The", "result", "is", "a", "list", "of", "same", "size", "as", "SA", ".", "Given", "two", "suffixes", "at", "positions", "i", "and", "i", "+", "1", "their", ...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L354-L403
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
parseArgv
def parseArgv(): """ Command line option parser. """ parser = OptionParser() parser.usage = r""" cat <TEXT> | %prog [--unit <UNIT>] [--output <SA_FILE>] Create the suffix array of TEXT with the processing UNIT and optionally store it in SA_FILE for subsequent use. UNIT may be set to 'byte', 'charac...
python
def parseArgv(): """ Command line option parser. """ parser = OptionParser() parser.usage = r""" cat <TEXT> | %prog [--unit <UNIT>] [--output <SA_FILE>] Create the suffix array of TEXT with the processing UNIT and optionally store it in SA_FILE for subsequent use. UNIT may be set to 'byte', 'charac...
[ "def", "parseArgv", "(", ")", ":", "parser", "=", "OptionParser", "(", ")", "parser", ".", "usage", "=", "r\"\"\" cat <TEXT> | %prog [--unit <UNIT>] [--output <SA_FILE>]\n\nCreate the suffix array of TEXT with the processing UNIT and optionally store it in SA_FILE for subsequent use.\nUN...
Command line option parser.
[ "Command", "line", "option", "parser", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L909-L965
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
main
def main(): """ Entry point for the standalone script. """ (options, strings) = parseArgv() global _suffixArray, _trace ############# # Verbosity # ############# _trace = options.verbose ################### # Processing unit # ################### if options.unit ==...
python
def main(): """ Entry point for the standalone script. """ (options, strings) = parseArgv() global _suffixArray, _trace ############# # Verbosity # ############# _trace = options.verbose ################### # Processing unit # ################### if options.unit ==...
[ "def", "main", "(", ")", ":", "(", "options", ",", "strings", ")", "=", "parseArgv", "(", ")", "global", "_suffixArray", ",", "_trace", "#############", "# Verbosity #", "#############", "_trace", "=", "options", ".", "verbose", "###################", "# Process...
Entry point for the standalone script.
[ "Entry", "point", "for", "the", "standalone", "script", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L968-L1046
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.addFeatureSA
def addFeatureSA(self, callback, default=None, name=None): """ Add a feature to the suffix array. The callback must return a sequence such that the feature at position i is attached to the suffix referenced by self.SA[i]. It is called with one argument: the instance of S...
python
def addFeatureSA(self, callback, default=None, name=None): """ Add a feature to the suffix array. The callback must return a sequence such that the feature at position i is attached to the suffix referenced by self.SA[i]. It is called with one argument: the instance of S...
[ "def", "addFeatureSA", "(", "self", ",", "callback", ",", "default", "=", "None", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "featureName", "=", "callback", ".", "__name__", "else", ":", "featureName", "=", "name", "featureValue...
Add a feature to the suffix array. The callback must return a sequence such that the feature at position i is attached to the suffix referenced by self.SA[i]. It is called with one argument: the instance of SuffixArray self. The callback may traverse self.SA in any fashion. ...
[ "Add", "a", "feature", "to", "the", "suffix", "array", ".", "The", "callback", "must", "return", "a", "sequence", "such", "that", "the", "feature", "at", "position", "i", "is", "attached", "to", "the", "suffix", "referenced", "by", "self", ".", "SA", "["...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L458-L547
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.addFeature
def addFeature(self, callback, default=None, name=None, arguments=None): """ Add a feature to the suffix array. The callback must return the feature corresponding to the suffix at position self.SA[i]. The callback must be callable (a function or lambda). The argument nam...
python
def addFeature(self, callback, default=None, name=None, arguments=None): """ Add a feature to the suffix array. The callback must return the feature corresponding to the suffix at position self.SA[i]. The callback must be callable (a function or lambda). The argument nam...
[ "def", "addFeature", "(", "self", ",", "callback", ",", "default", "=", "None", ",", "name", "=", "None", ",", "arguments", "=", "None", ")", ":", "if", "name", "is", "None", ":", "featureName", "=", "callback", ".", "__name__", "else", ":", "featureNa...
Add a feature to the suffix array. The callback must return the feature corresponding to the suffix at position self.SA[i]. The callback must be callable (a function or lambda). The argument names of the callback are used to determine the data needed. If an argument is the name ...
[ "Add", "a", "feature", "to", "the", "suffix", "array", ".", "The", "callback", "must", "return", "the", "feature", "corresponding", "to", "the", "suffix", "at", "position", "self", ".", "SA", "[", "i", "]", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L549-L598
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.tokenize
def tokenize(self, string): """ Tokenizer utility. When processing byte, outputs the string unaltered. The character unit type is used for unicode data, the string is decoded according to the encoding provided. In the case of word unit, EOL characters are detached from th...
python
def tokenize(self, string): """ Tokenizer utility. When processing byte, outputs the string unaltered. The character unit type is used for unicode data, the string is decoded according to the encoding provided. In the case of word unit, EOL characters are detached from th...
[ "def", "tokenize", "(", "self", ",", "string", ")", ":", "if", "self", ".", "unit", "==", "UNIT_WORD", ":", "# the EOL character is treated as a word, hence a substitution", "# before split", "return", "[", "token", "for", "token", "in", "string", ".", "replace", ...
Tokenizer utility. When processing byte, outputs the string unaltered. The character unit type is used for unicode data, the string is decoded according to the encoding provided. In the case of word unit, EOL characters are detached from the preceding word, and outputs the list o...
[ "Tokenizer", "utility", ".", "When", "processing", "byte", "outputs", "the", "string", "unaltered", ".", "The", "character", "unit", "type", "is", "used", "for", "unicode", "data", "the", "string", "is", "decoded", "according", "to", "the", "encoding", "provid...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L600-L642
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.reprString
def reprString(self, string, length): """ Output a string of length tokens in the original form. If string is an integer, it is considered as an offset in the text. Otherwise string is considered as a sequence of ids (see voc and tokId). >>> SA=SuffixArray('mississippi',...
python
def reprString(self, string, length): """ Output a string of length tokens in the original form. If string is an integer, it is considered as an offset in the text. Otherwise string is considered as a sequence of ids (see voc and tokId). >>> SA=SuffixArray('mississippi',...
[ "def", "reprString", "(", "self", ",", "string", ",", "length", ")", ":", "if", "isinstance", "(", "string", ",", "int", ")", ":", "length", "=", "min", "(", "length", ",", "self", ".", "length", "-", "string", ")", "string", "=", "self", ".", "str...
Output a string of length tokens in the original form. If string is an integer, it is considered as an offset in the text. Otherwise string is considered as a sequence of ids (see voc and tokId). >>> SA=SuffixArray('mississippi', UNIT_BYTE) >>> SA.reprString(0, 3) 'mis' ...
[ "Output", "a", "string", "of", "length", "tokens", "in", "the", "original", "form", ".", "If", "string", "is", "an", "integer", "it", "is", "considered", "as", "an", "offset", "in", "the", "text", ".", "Otherwise", "string", "is", "considered", "as", "a"...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L644-L680
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.toFile
def toFile(self, filename): """ Save the suffix array instance including all features attached in filename. Accept any filename following the _open conventions, for example if it ends with .gz the file created will be a compressed GZip file. """ start = _time() ...
python
def toFile(self, filename): """ Save the suffix array instance including all features attached in filename. Accept any filename following the _open conventions, for example if it ends with .gz the file created will be a compressed GZip file. """ start = _time() ...
[ "def", "toFile", "(", "self", ",", "filename", ")", ":", "start", "=", "_time", "(", ")", "fd", "=", "_open", "(", "filename", ",", "\"w\"", ")", "savedData", "=", "[", "self", ".", "string", ",", "self", ".", "unit", ",", "self", ".", "voc", ","...
Save the suffix array instance including all features attached in filename. Accept any filename following the _open conventions, for example if it ends with .gz the file created will be a compressed GZip file.
[ "Save", "the", "suffix", "array", "instance", "including", "all", "features", "attached", "in", "filename", ".", "Accept", "any", "filename", "following", "the", "_open", "conventions", "for", "example", "if", "it", "ends", "with", ".", "gz", "the", "file", ...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L708-L736
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.fromFile
def fromFile(cls, filename): """ Load a suffix array instance from filename, a file created by toFile. Accept any filename following the _open conventions. """ self = cls.__new__(cls) # new instance which does not call __init__ start = _time() savedData...
python
def fromFile(cls, filename): """ Load a suffix array instance from filename, a file created by toFile. Accept any filename following the _open conventions. """ self = cls.__new__(cls) # new instance which does not call __init__ start = _time() savedData...
[ "def", "fromFile", "(", "cls", ",", "filename", ")", ":", "self", "=", "cls", ".", "__new__", "(", "cls", ")", "# new instance which does not call __init__", "start", "=", "_time", "(", ")", "savedData", "=", "_loads", "(", "_open", "(", "filename", ",", "...
Load a suffix array instance from filename, a file created by toFile. Accept any filename following the _open conventions.
[ "Load", "a", "suffix", "array", "instance", "from", "filename", "a", "file", "created", "by", "toFile", ".", "Accept", "any", "filename", "following", "the", "_open", "conventions", "." ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L739-L774
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray._findOne
def _findOne(self, subString): """ >>> SA=SuffixArray("mississippi", unit=UNIT_BYTE) >>> SA._findOne("ippi") 1 >>> SA._findOne("missi") 4 """ SA = self.SA LCPs = self._LCP_values string = self.string try: subString = _...
python
def _findOne(self, subString): """ >>> SA=SuffixArray("mississippi", unit=UNIT_BYTE) >>> SA._findOne("ippi") 1 >>> SA._findOne("missi") 4 """ SA = self.SA LCPs = self._LCP_values string = self.string try: subString = _...
[ "def", "_findOne", "(", "self", ",", "subString", ")", ":", "SA", "=", "self", ".", "SA", "LCPs", "=", "self", ".", "_LCP_values", "string", "=", "self", ".", "string", "try", ":", "subString", "=", "_array", "(", "\"i\"", ",", "[", "self", ".", "t...
>>> SA=SuffixArray("mississippi", unit=UNIT_BYTE) >>> SA._findOne("ippi") 1 >>> SA._findOne("missi") 4
[ ">>>", "SA", "=", "SuffixArray", "(", "mississippi", "unit", "=", "UNIT_BYTE", ")", ">>>", "SA", ".", "_findOne", "(", "ippi", ")", "1" ]
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L776-L822
train
interedition/collatex
collatex-pythonport/collatex/linsuffarr.py
SuffixArray.find
def find(self, subString, features=[]): """ Dichotomy search of subString in the suffix array. As soon as a suffix which starts with subString is found, it uses the LCPs in order to find the other matching suffixes. The outputs consists in a list of tuple (pos, feature0, feature...
python
def find(self, subString, features=[]): """ Dichotomy search of subString in the suffix array. As soon as a suffix which starts with subString is found, it uses the LCPs in order to find the other matching suffixes. The outputs consists in a list of tuple (pos, feature0, feature...
[ "def", "find", "(", "self", ",", "subString", ",", "features", "=", "[", "]", ")", ":", "SA", "=", "self", ".", "SA", "LCPs", "=", "self", ".", "_LCP_values", "string", "=", "self", ".", "string", "middle", "=", "self", ".", "_findOne", "(", "subSt...
Dichotomy search of subString in the suffix array. As soon as a suffix which starts with subString is found, it uses the LCPs in order to find the other matching suffixes. The outputs consists in a list of tuple (pos, feature0, feature1, ...) where feature0, feature1, ... are the featur...
[ "Dichotomy", "search", "of", "subString", "in", "the", "suffix", "array", ".", "As", "soon", "as", "a", "suffix", "which", "starts", "with", "subString", "is", "found", "it", "uses", "the", "LCPs", "in", "order", "to", "find", "the", "other", "matching", ...
76dd1fcc36047bc66a87d31142e72e98b5347821
https://github.com/interedition/collatex/blob/76dd1fcc36047bc66a87d31142e72e98b5347821/collatex-pythonport/collatex/linsuffarr.py#L824-L906
train
sramana/pyatom
pyatom.py
escape
def escape(s, quote=False): """Replace special characters "&", "<" and ">" to HTML-safe sequences. If the optional flag `quote` is `True`, the quotation mark character (") is also translated. There is a special handling for `None` which escapes to an empty string. :param s: the string to escape. ...
python
def escape(s, quote=False): """Replace special characters "&", "<" and ">" to HTML-safe sequences. If the optional flag `quote` is `True`, the quotation mark character (") is also translated. There is a special handling for `None` which escapes to an empty string. :param s: the string to escape. ...
[ "def", "escape", "(", "s", ",", "quote", "=", "False", ")", ":", "if", "s", "is", "None", ":", "return", "''", "elif", "hasattr", "(", "s", ",", "'__html__'", ")", ":", "return", "s", ".", "__html__", "(", ")", "elif", "not", "isinstance", "(", "...
Replace special characters "&", "<" and ">" to HTML-safe sequences. If the optional flag `quote` is `True`, the quotation mark character (") is also translated. There is a special handling for `None` which escapes to an empty string. :param s: the string to escape. :param quote: set to true to al...
[ "Replace", "special", "characters", "&", "<", "and", ">", "to", "HTML", "-", "safe", "sequences", ".", "If", "the", "optional", "flag", "quote", "is", "True", "the", "quotation", "mark", "character", "(", ")", "is", "also", "translated", "." ]
9b937ac86926a1aa0e14ae774d1cc303f46327d5
https://github.com/sramana/pyatom/blob/9b937ac86926a1aa0e14ae774d1cc303f46327d5/pyatom.py#L42-L61
train
sramana/pyatom
pyatom.py
AtomFeed.add
def add(self, *args, **kwargs): """Add a new entry to the feed. This function can either be called with a :class:`FeedEntry` or some keyword and positional arguments that are forwarded to the :class:`FeedEntry` constructor. """ if len(args) == 1 and not kwargs and isinstance(arg...
python
def add(self, *args, **kwargs): """Add a new entry to the feed. This function can either be called with a :class:`FeedEntry` or some keyword and positional arguments that are forwarded to the :class:`FeedEntry` constructor. """ if len(args) == 1 and not kwargs and isinstance(arg...
[ "def", "add", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "len", "(", "args", ")", "==", "1", "and", "not", "kwargs", "and", "isinstance", "(", "args", "[", "0", "]", ",", "FeedEntry", ")", ":", "self", ".", "entries...
Add a new entry to the feed. This function can either be called with a :class:`FeedEntry` or some keyword and positional arguments that are forwarded to the :class:`FeedEntry` constructor.
[ "Add", "a", "new", "entry", "to", "the", "feed", ".", "This", "function", "can", "either", "be", "called", "with", "a", ":", "class", ":", "FeedEntry", "or", "some", "keyword", "and", "positional", "arguments", "that", "are", "forwarded", "to", "the", ":...
9b937ac86926a1aa0e14ae774d1cc303f46327d5
https://github.com/sramana/pyatom/blob/9b937ac86926a1aa0e14ae774d1cc303f46327d5/pyatom.py#L167-L177
train
sramana/pyatom
pyatom.py
AtomFeed.generate
def generate(self): """Return a generator that yields pieces of XML.""" # atom demands either an author element in every entry or a global one if not self.author: if False in map(lambda e: bool(e.author), self.entries): self.author = ({'name': u'unbekannter Autor'},) ...
python
def generate(self): """Return a generator that yields pieces of XML.""" # atom demands either an author element in every entry or a global one if not self.author: if False in map(lambda e: bool(e.author), self.entries): self.author = ({'name': u'unbekannter Autor'},) ...
[ "def", "generate", "(", "self", ")", ":", "# atom demands either an author element in every entry or a global one", "if", "not", "self", ".", "author", ":", "if", "False", "in", "map", "(", "lambda", "e", ":", "bool", "(", "e", ".", "author", ")", ",", "self",...
Return a generator that yields pieces of XML.
[ "Return", "a", "generator", "that", "yields", "pieces", "of", "XML", "." ]
9b937ac86926a1aa0e14ae774d1cc303f46327d5
https://github.com/sramana/pyatom/blob/9b937ac86926a1aa0e14ae774d1cc303f46327d5/pyatom.py#L186-L240
train
sramana/pyatom
pyatom.py
FeedEntry.generate
def generate(self): """Yields pieces of ATOM XML.""" base = '' if self.xml_base: base = ' xml:base="%s"' % escape(self.xml_base, True) yield u'<entry%s>\n' % base yield u' ' + _make_text_block('title', self.title, self.title_type) yield u' <id>%s</id>\n' % e...
python
def generate(self): """Yields pieces of ATOM XML.""" base = '' if self.xml_base: base = ' xml:base="%s"' % escape(self.xml_base, True) yield u'<entry%s>\n' % base yield u' ' + _make_text_block('title', self.title, self.title_type) yield u' <id>%s</id>\n' % e...
[ "def", "generate", "(", "self", ")", ":", "base", "=", "''", "if", "self", ".", "xml_base", ":", "base", "=", "' xml:base=\"%s\"'", "%", "escape", "(", "self", ".", "xml_base", ",", "True", ")", "yield", "u'<entry%s>\\n'", "%", "base", "yield", "u' '", ...
Yields pieces of ATOM XML.
[ "Yields", "pieces", "of", "ATOM", "XML", "." ]
9b937ac86926a1aa0e14ae774d1cc303f46327d5
https://github.com/sramana/pyatom/blob/9b937ac86926a1aa0e14ae774d1cc303f46327d5/pyatom.py#L337-L376
train
nitely/django-djconfig
djconfig/utils.py
override_djconfig
def override_djconfig(**new_cache_values): """ Temporarily override config values. This is similar to :py:func:`django.test.override_settings`,\ use it in testing. :param new_cache_values: Keyword arguments,\ the key should match one in the config,\ a new one is created otherwise,\ the...
python
def override_djconfig(**new_cache_values): """ Temporarily override config values. This is similar to :py:func:`django.test.override_settings`,\ use it in testing. :param new_cache_values: Keyword arguments,\ the key should match one in the config,\ a new one is created otherwise,\ the...
[ "def", "override_djconfig", "(", "*", "*", "new_cache_values", ")", ":", "def", "decorator", "(", "func", ")", ":", "@", "wraps", "(", "func", ")", "def", "func_wrapper", "(", "*", "args", ",", "*", "*", "kw", ")", ":", "old_cache_values", "=", "{", ...
Temporarily override config values. This is similar to :py:func:`django.test.override_settings`,\ use it in testing. :param new_cache_values: Keyword arguments,\ the key should match one in the config,\ a new one is created otherwise,\ the value is overridden within\ the decorated function
[ "Temporarily", "override", "config", "values", "." ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/utils.py#L17-L56
train
nitely/django-djconfig
djconfig/utils.py
serialize
def serialize(value, field): """ Form values serialization :param object value: A value to be serialized\ for saving it into the database and later\ loading it into the form as initial value """ assert isinstance(field, forms.Field) if isinstance(field, forms.ModelMultipleChoiceField): ...
python
def serialize(value, field): """ Form values serialization :param object value: A value to be serialized\ for saving it into the database and later\ loading it into the form as initial value """ assert isinstance(field, forms.Field) if isinstance(field, forms.ModelMultipleChoiceField): ...
[ "def", "serialize", "(", "value", ",", "field", ")", ":", "assert", "isinstance", "(", "field", ",", "forms", ".", "Field", ")", "if", "isinstance", "(", "field", ",", "forms", ".", "ModelMultipleChoiceField", ")", ":", "return", "json", ".", "dumps", "(...
Form values serialization :param object value: A value to be serialized\ for saving it into the database and later\ loading it into the form as initial value
[ "Form", "values", "serialization" ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/utils.py#L59-L73
train
nitely/django-djconfig
setup.py
get_version
def get_version(package): """Get version without importing the lib""" with io.open(os.path.join(BASE_DIR, package, '__init__.py'), encoding='utf-8') as fh: return [ l.split('=', 1)[1].strip().strip("'").strip('"') for l in fh.readlines() if '__version__' in l][0]
python
def get_version(package): """Get version without importing the lib""" with io.open(os.path.join(BASE_DIR, package, '__init__.py'), encoding='utf-8') as fh: return [ l.split('=', 1)[1].strip().strip("'").strip('"') for l in fh.readlines() if '__version__' in l][0]
[ "def", "get_version", "(", "package", ")", ":", "with", "io", ".", "open", "(", "os", ".", "path", ".", "join", "(", "BASE_DIR", ",", "package", ",", "'__init__.py'", ")", ",", "encoding", "=", "'utf-8'", ")", "as", "fh", ":", "return", "[", "l", "...
Get version without importing the lib
[ "Get", "version", "without", "importing", "the", "lib" ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/setup.py#L14-L20
train
nitely/django-djconfig
djconfig/conf.py
_check_backend
def _check_backend(): """ Check :py:class:`djconfig.middleware.DjConfigMiddleware`\ is registered into ``settings.MIDDLEWARE_CLASSES`` """ # Django 1.10 does not allow # both settings to be set middleware = set( getattr(settings, 'MIDDLEWARE', None) or getattr(settings, 'MIDD...
python
def _check_backend(): """ Check :py:class:`djconfig.middleware.DjConfigMiddleware`\ is registered into ``settings.MIDDLEWARE_CLASSES`` """ # Django 1.10 does not allow # both settings to be set middleware = set( getattr(settings, 'MIDDLEWARE', None) or getattr(settings, 'MIDD...
[ "def", "_check_backend", "(", ")", ":", "# Django 1.10 does not allow", "# both settings to be set", "middleware", "=", "set", "(", "getattr", "(", "settings", ",", "'MIDDLEWARE'", ",", "None", ")", "or", "getattr", "(", "settings", ",", "'MIDDLEWARE_CLASSES'", ",",...
Check :py:class:`djconfig.middleware.DjConfigMiddleware`\ is registered into ``settings.MIDDLEWARE_CLASSES``
[ "Check", ":", "py", ":", "class", ":", "djconfig", ".", "middleware", ".", "DjConfigMiddleware", "\\", "is", "registered", "into", "settings", ".", "MIDDLEWARE_CLASSES" ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/conf.py#L23-L45
train
nitely/django-djconfig
djconfig/conf.py
Config._register
def _register(self, form_class, check_middleware=True): """ Register a config form into the registry :param object form_class: The form class to register.\ Must be an instance of :py:class:`djconfig.forms.ConfigForm` :param bool check_middleware: Check\ :py:class:`djconf...
python
def _register(self, form_class, check_middleware=True): """ Register a config form into the registry :param object form_class: The form class to register.\ Must be an instance of :py:class:`djconfig.forms.ConfigForm` :param bool check_middleware: Check\ :py:class:`djconf...
[ "def", "_register", "(", "self", ",", "form_class", ",", "check_middleware", "=", "True", ")", ":", "if", "not", "issubclass", "(", "form_class", ",", "_ConfigFormBase", ")", ":", "raise", "ValueError", "(", "\"The form does not inherit from `forms.ConfigForm`\"", "...
Register a config form into the registry :param object form_class: The form class to register.\ Must be an instance of :py:class:`djconfig.forms.ConfigForm` :param bool check_middleware: Check\ :py:class:`djconfig.middleware.DjConfigMiddleware`\ is registered into ``settings.MID...
[ "Register", "a", "config", "form", "into", "the", "registry" ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/conf.py#L83-L100
train
nitely/django-djconfig
djconfig/conf.py
Config._reload
def _reload(self): """ Gets every registered form's field value.\ If a field name is found in the db, it will load it from there.\ Otherwise, the initial value from the field form is used """ ConfigModel = apps.get_model('djconfig.Config') cache = {} data ...
python
def _reload(self): """ Gets every registered form's field value.\ If a field name is found in the db, it will load it from there.\ Otherwise, the initial value from the field form is used """ ConfigModel = apps.get_model('djconfig.Config') cache = {} data ...
[ "def", "_reload", "(", "self", ")", ":", "ConfigModel", "=", "apps", ".", "get_model", "(", "'djconfig.Config'", ")", "cache", "=", "{", "}", "data", "=", "dict", "(", "ConfigModel", ".", "objects", ".", "all", "(", ")", ".", "values_list", "(", "'key'...
Gets every registered form's field value.\ If a field name is found in the db, it will load it from there.\ Otherwise, the initial value from the field form is used
[ "Gets", "every", "registered", "form", "s", "field", "value", ".", "\\", "If", "a", "field", "name", "is", "found", "in", "the", "db", "it", "will", "load", "it", "from", "there", ".", "\\", "Otherwise", "the", "initial", "value", "from", "the", "field...
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/conf.py#L102-L142
train
nitely/django-djconfig
djconfig/conf.py
Config._reload_maybe
def _reload_maybe(self): """ Reload the config if the config\ model has been updated. This is called\ once on every request by the middleware.\ Should not be called directly. """ ConfigModel = apps.get_model('djconfig.Config') data = dict( Con...
python
def _reload_maybe(self): """ Reload the config if the config\ model has been updated. This is called\ once on every request by the middleware.\ Should not be called directly. """ ConfigModel = apps.get_model('djconfig.Config') data = dict( Con...
[ "def", "_reload_maybe", "(", "self", ")", ":", "ConfigModel", "=", "apps", ".", "get_model", "(", "'djconfig.Config'", ")", "data", "=", "dict", "(", "ConfigModel", ".", "objects", ".", "filter", "(", "key", "=", "'_updated_at'", ")", ".", "values_list", "...
Reload the config if the config\ model has been updated. This is called\ once on every request by the middleware.\ Should not be called directly.
[ "Reload", "the", "config", "if", "the", "config", "\\", "model", "has", "been", "updated", ".", "This", "is", "called", "\\", "once", "on", "every", "request", "by", "the", "middleware", ".", "\\", "Should", "not", "be", "called", "directly", "." ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/conf.py#L144-L160
train
nitely/django-djconfig
djconfig/forms.py
ConfigForm.save
def save(self): """ Save the config with the cleaned data,\ update the last modified date so\ the config is reloaded on other process/nodes.\ Reload the config so it can be called right away. """ assert self.__class__ in conf.config._registry,\ '%(clas...
python
def save(self): """ Save the config with the cleaned data,\ update the last modified date so\ the config is reloaded on other process/nodes.\ Reload the config so it can be called right away. """ assert self.__class__ in conf.config._registry,\ '%(clas...
[ "def", "save", "(", "self", ")", ":", "assert", "self", ".", "__class__", "in", "conf", ".", "config", ".", "_registry", ",", "'%(class_name)s is not registered'", "%", "{", "'class_name'", ":", "self", ".", "__class__", ".", "__name__", "}", "ConfigModel", ...
Save the config with the cleaned data,\ update the last modified date so\ the config is reloaded on other process/nodes.\ Reload the config so it can be called right away.
[ "Save", "the", "config", "with", "the", "cleaned", "data", "\\", "update", "the", "last", "modified", "date", "so", "\\", "the", "config", "is", "reloaded", "on", "other", "process", "/", "nodes", ".", "\\", "Reload", "the", "config", "so", "it", "can", ...
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/forms.py#L36-L71
train
nitely/django-djconfig
djconfig/admin.py
register
def register(conf, conf_admin, **options): """ Register a new admin section. :param conf: A subclass of ``djconfig.admin.Config`` :param conf_admin: A subclass of ``djconfig.admin.ConfigAdmin`` :param options: Extra options passed to ``django.contrib.admin.site.register`` """ assert issubcl...
python
def register(conf, conf_admin, **options): """ Register a new admin section. :param conf: A subclass of ``djconfig.admin.Config`` :param conf_admin: A subclass of ``djconfig.admin.ConfigAdmin`` :param options: Extra options passed to ``django.contrib.admin.site.register`` """ assert issubcl...
[ "def", "register", "(", "conf", ",", "conf_admin", ",", "*", "*", "options", ")", ":", "assert", "issubclass", "(", "conf_admin", ",", "ConfigAdmin", ")", ",", "(", "'conf_admin is not a ConfigAdmin subclass'", ")", "assert", "issubclass", "(", "getattr", "(", ...
Register a new admin section. :param conf: A subclass of ``djconfig.admin.Config`` :param conf_admin: A subclass of ``djconfig.admin.ConfigAdmin`` :param options: Extra options passed to ``django.contrib.admin.site.register``
[ "Register", "a", "new", "admin", "section", "." ]
5e79a048ef5c9529075cad947b0c309115035d7e
https://github.com/nitely/django-djconfig/blob/5e79a048ef5c9529075cad947b0c309115035d7e/djconfig/admin.py#L130-L156
train
gamechanger/schemer
schemer/extension_types.py
Mixed
def Mixed(*types): """Mixed type, used to indicate a field in a schema can be one of many types. Use as a last resort only. The Mixed type can be used directly as a class to indicate any type is permitted for a given field: `"my_field": {"type": Mixed}` It can also be instantiated with list of s...
python
def Mixed(*types): """Mixed type, used to indicate a field in a schema can be one of many types. Use as a last resort only. The Mixed type can be used directly as a class to indicate any type is permitted for a given field: `"my_field": {"type": Mixed}` It can also be instantiated with list of s...
[ "def", "Mixed", "(", "*", "types", ")", ":", "if", "len", "(", "types", ")", "<", "2", ":", "raise", "ValueError", "(", "\"Mixed type requires at least 2 specific types\"", ")", "types", "=", "set", "(", "types", ")", "# dedupe", "class", "MixedType", "(", ...
Mixed type, used to indicate a field in a schema can be one of many types. Use as a last resort only. The Mixed type can be used directly as a class to indicate any type is permitted for a given field: `"my_field": {"type": Mixed}` It can also be instantiated with list of specific types the fiel...
[ "Mixed", "type", "used", "to", "indicate", "a", "field", "in", "a", "schema", "can", "be", "one", "of", "many", "types", ".", "Use", "as", "a", "last", "resort", "only", ".", "The", "Mixed", "type", "can", "be", "used", "directly", "as", "a", "class"...
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/extension_types.py#L1-L28
train
gamechanger/schemer
schemer/validators.py
one_of
def one_of(*args): """ Validates that a field value matches one of the values given to this validator. """ if len(args) == 1 and isinstance(args[0], list): items = args[0] else: items = list(args) def validate(value): if not value in items: return e("{} i...
python
def one_of(*args): """ Validates that a field value matches one of the values given to this validator. """ if len(args) == 1 and isinstance(args[0], list): items = args[0] else: items = list(args) def validate(value): if not value in items: return e("{} i...
[ "def", "one_of", "(", "*", "args", ")", ":", "if", "len", "(", "args", ")", "==", "1", "and", "isinstance", "(", "args", "[", "0", "]", ",", "list", ")", ":", "items", "=", "args", "[", "0", "]", "else", ":", "items", "=", "list", "(", "args"...
Validates that a field value matches one of the values given to this validator.
[ "Validates", "that", "a", "field", "value", "matches", "one", "of", "the", "values", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L8-L21
train
gamechanger/schemer
schemer/validators.py
gte
def gte(min_value): """ Validates that a field value is greater than or equal to the value given to this validator. """ def validate(value): if value < min_value: return e("{} is not greater than or equal to {}", value, min_value) return validate
python
def gte(min_value): """ Validates that a field value is greater than or equal to the value given to this validator. """ def validate(value): if value < min_value: return e("{} is not greater than or equal to {}", value, min_value) return validate
[ "def", "gte", "(", "min_value", ")", ":", "def", "validate", "(", "value", ")", ":", "if", "value", "<", "min_value", ":", "return", "e", "(", "\"{} is not greater than or equal to {}\"", ",", "value", ",", "min_value", ")", "return", "validate" ]
Validates that a field value is greater than or equal to the value given to this validator.
[ "Validates", "that", "a", "field", "value", "is", "greater", "than", "or", "equal", "to", "the", "value", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L24-L32
train
gamechanger/schemer
schemer/validators.py
lte
def lte(max_value): """ Validates that a field value is less than or equal to the value given to this validator. """ def validate(value): if value > max_value: return e("{} is not less than or equal to {}", value, max_value) return validate
python
def lte(max_value): """ Validates that a field value is less than or equal to the value given to this validator. """ def validate(value): if value > max_value: return e("{} is not less than or equal to {}", value, max_value) return validate
[ "def", "lte", "(", "max_value", ")", ":", "def", "validate", "(", "value", ")", ":", "if", "value", ">", "max_value", ":", "return", "e", "(", "\"{} is not less than or equal to {}\"", ",", "value", ",", "max_value", ")", "return", "validate" ]
Validates that a field value is less than or equal to the value given to this validator.
[ "Validates", "that", "a", "field", "value", "is", "less", "than", "or", "equal", "to", "the", "value", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L35-L43
train
gamechanger/schemer
schemer/validators.py
gt
def gt(gt_value): """ Validates that a field value is greater than the value given to this validator. """ def validate(value): if value <= gt_value: return e("{} is not greater than {}", value, gt_value) return validate
python
def gt(gt_value): """ Validates that a field value is greater than the value given to this validator. """ def validate(value): if value <= gt_value: return e("{} is not greater than {}", value, gt_value) return validate
[ "def", "gt", "(", "gt_value", ")", ":", "def", "validate", "(", "value", ")", ":", "if", "value", "<=", "gt_value", ":", "return", "e", "(", "\"{} is not greater than {}\"", ",", "value", ",", "gt_value", ")", "return", "validate" ]
Validates that a field value is greater than the value given to this validator.
[ "Validates", "that", "a", "field", "value", "is", "greater", "than", "the", "value", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L46-L54
train
gamechanger/schemer
schemer/validators.py
lt
def lt(lt_value): """ Validates that a field value is less than the value given to this validator. """ def validate(value): if value >= lt_value: return e("{} is not less than {}", value, lt_value) return validate
python
def lt(lt_value): """ Validates that a field value is less than the value given to this validator. """ def validate(value): if value >= lt_value: return e("{} is not less than {}", value, lt_value) return validate
[ "def", "lt", "(", "lt_value", ")", ":", "def", "validate", "(", "value", ")", ":", "if", "value", ">=", "lt_value", ":", "return", "e", "(", "\"{} is not less than {}\"", ",", "value", ",", "lt_value", ")", "return", "validate" ]
Validates that a field value is less than the value given to this validator.
[ "Validates", "that", "a", "field", "value", "is", "less", "than", "the", "value", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L57-L65
train
gamechanger/schemer
schemer/validators.py
between
def between(min_value, max_value): """ Validates that a field value is between the two values given to this validator. """ def validate(value): if value < min_value: return e("{} is not greater than or equal to {}", value, min_value) if value > max_value: ...
python
def between(min_value, max_value): """ Validates that a field value is between the two values given to this validator. """ def validate(value): if value < min_value: return e("{} is not greater than or equal to {}", value, min_value) if value > max_value: ...
[ "def", "between", "(", "min_value", ",", "max_value", ")", ":", "def", "validate", "(", "value", ")", ":", "if", "value", "<", "min_value", ":", "return", "e", "(", "\"{} is not greater than or equal to {}\"", ",", "value", ",", "min_value", ")", "if", "valu...
Validates that a field value is between the two values given to this validator.
[ "Validates", "that", "a", "field", "value", "is", "between", "the", "two", "values", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L68-L80
train
gamechanger/schemer
schemer/validators.py
length
def length(min=None, max=None): """ Validates that a field value's length is between the bounds given to this validator. """ def validate(value): if min and len(value) < min: return e("{} does not have a length of at least {}", value, min) if max and len(value) > max: ...
python
def length(min=None, max=None): """ Validates that a field value's length is between the bounds given to this validator. """ def validate(value): if min and len(value) < min: return e("{} does not have a length of at least {}", value, min) if max and len(value) > max: ...
[ "def", "length", "(", "min", "=", "None", ",", "max", "=", "None", ")", ":", "def", "validate", "(", "value", ")", ":", "if", "min", "and", "len", "(", "value", ")", "<", "min", ":", "return", "e", "(", "\"{} does not have a length of at least {}\"", "...
Validates that a field value's length is between the bounds given to this validator.
[ "Validates", "that", "a", "field", "value", "s", "length", "is", "between", "the", "bounds", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L83-L94
train
gamechanger/schemer
schemer/validators.py
match
def match(pattern): """ Validates that a field value matches the regex given to this validator. """ regex = re.compile(pattern) def validate(value): if not regex.match(value): return e("{} does not match the pattern {}", value, pattern) return validate
python
def match(pattern): """ Validates that a field value matches the regex given to this validator. """ regex = re.compile(pattern) def validate(value): if not regex.match(value): return e("{} does not match the pattern {}", value, pattern) return validate
[ "def", "match", "(", "pattern", ")", ":", "regex", "=", "re", ".", "compile", "(", "pattern", ")", "def", "validate", "(", "value", ")", ":", "if", "not", "regex", ".", "match", "(", "value", ")", ":", "return", "e", "(", "\"{} does not match the patte...
Validates that a field value matches the regex given to this validator.
[ "Validates", "that", "a", "field", "value", "matches", "the", "regex", "given", "to", "this", "validator", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L97-L106
train
gamechanger/schemer
schemer/validators.py
is_email
def is_email(): """ Validates that a fields value is a valid email address. """ email = ( ur'(?!^\.)' # No dot at start ur'(?!.*\.@)' # No dot before at sign ur'(?!.*@\.)' # No dot after at sign ur'(?!.*\.$)' # No dot at the end ur'(?!.*\.\.)' # No dou...
python
def is_email(): """ Validates that a fields value is a valid email address. """ email = ( ur'(?!^\.)' # No dot at start ur'(?!.*\.@)' # No dot before at sign ur'(?!.*@\.)' # No dot after at sign ur'(?!.*\.$)' # No dot at the end ur'(?!.*\.\.)' # No dou...
[ "def", "is_email", "(", ")", ":", "email", "=", "(", "ur'(?!^\\.)'", "# No dot at start", "ur'(?!.*\\.@)'", "# No dot before at sign", "ur'(?!.*@\\.)'", "# No dot after at sign", "ur'(?!.*\\.$)'", "# No dot at the end", "ur'(?!.*\\.\\.)'", "# No double dots anywhere", "ur'^\\S+'"...
Validates that a fields value is a valid email address.
[ "Validates", "that", "a", "fields", "value", "is", "a", "valid", "email", "address", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L108-L129
train
gamechanger/schemer
schemer/validators.py
is_url
def is_url(): """ Validates that a fields value is a valid URL. """ # Stolen from Django regex = re.compile( r'^(?:http|ftp)s?://' # http:// or https:// r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain... r'localhost|' #localhost......
python
def is_url(): """ Validates that a fields value is a valid URL. """ # Stolen from Django regex = re.compile( r'^(?:http|ftp)s?://' # http:// or https:// r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain... r'localhost|' #localhost......
[ "def", "is_url", "(", ")", ":", "# Stolen from Django", "regex", "=", "re", ".", "compile", "(", "r'^(?:http|ftp)s?://'", "# http:// or https://", "r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}\\.?)|'", "#domain...", "r'localhost|'", "#localhost.....
Validates that a fields value is a valid URL.
[ "Validates", "that", "a", "fields", "value", "is", "a", "valid", "URL", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L131-L147
train
gamechanger/schemer
schemer/validators.py
each_item
def each_item(*validators): """ A wrapper which applies the given validators to each item in a field value of type `list`. Example usage in a Schema: "my_list_field": {"type": Array(int), "validates": each_item(lte(10))} """ def validate(value): for item in value: for v...
python
def each_item(*validators): """ A wrapper which applies the given validators to each item in a field value of type `list`. Example usage in a Schema: "my_list_field": {"type": Array(int), "validates": each_item(lte(10))} """ def validate(value): for item in value: for v...
[ "def", "each_item", "(", "*", "validators", ")", ":", "def", "validate", "(", "value", ")", ":", "for", "item", "in", "value", ":", "for", "validator", "in", "validators", ":", "error", "=", "validator", "(", "item", ")", "if", "error", ":", "return", ...
A wrapper which applies the given validators to each item in a field value of type `list`. Example usage in a Schema: "my_list_field": {"type": Array(int), "validates": each_item(lte(10))}
[ "A", "wrapper", "which", "applies", "the", "given", "validators", "to", "each", "item", "in", "a", "field", "value", "of", "type", "list", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L150-L166
train
gamechanger/schemer
schemer/validators.py
distinct
def distinct(): """ Validates that all items in the given field list value are distinct, i.e. that the list contains no duplicates. """ def validate(value): for i, item in enumerate(value): if item in value[i+1:]: return e("{} is not a distinct set of values", val...
python
def distinct(): """ Validates that all items in the given field list value are distinct, i.e. that the list contains no duplicates. """ def validate(value): for i, item in enumerate(value): if item in value[i+1:]: return e("{} is not a distinct set of values", val...
[ "def", "distinct", "(", ")", ":", "def", "validate", "(", "value", ")", ":", "for", "i", ",", "item", "in", "enumerate", "(", "value", ")", ":", "if", "item", "in", "value", "[", "i", "+", "1", ":", "]", ":", "return", "e", "(", "\"{} is not a di...
Validates that all items in the given field list value are distinct, i.e. that the list contains no duplicates.
[ "Validates", "that", "all", "items", "in", "the", "given", "field", "list", "value", "are", "distinct", "i", ".", "e", ".", "that", "the", "list", "contains", "no", "duplicates", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/validators.py#L169-L178
train
gamechanger/schemer
schemer/__init__.py
Schema.apply_defaults
def apply_defaults(self, instance): """Applies the defaults described by the this schema to the given document instance as appropriate. Defaults are only applied to fields which are currently unset.""" for field, spec in self.doc_spec.iteritems(): field_type = spec['type'] ...
python
def apply_defaults(self, instance): """Applies the defaults described by the this schema to the given document instance as appropriate. Defaults are only applied to fields which are currently unset.""" for field, spec in self.doc_spec.iteritems(): field_type = spec['type'] ...
[ "def", "apply_defaults", "(", "self", ",", "instance", ")", ":", "for", "field", ",", "spec", "in", "self", ".", "doc_spec", ".", "iteritems", "(", ")", ":", "field_type", "=", "spec", "[", "'type'", "]", "if", "field", "not", "in", "instance", ":", ...
Applies the defaults described by the this schema to the given document instance as appropriate. Defaults are only applied to fields which are currently unset.
[ "Applies", "the", "defaults", "described", "by", "the", "this", "schema", "to", "the", "given", "document", "instance", "as", "appropriate", ".", "Defaults", "are", "only", "applied", "to", "fields", "which", "are", "currently", "unset", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L26-L49
train
gamechanger/schemer
schemer/__init__.py
Schema.validate
def validate(self, instance): """Validates the given document against this schema. Raises a ValidationException if there are any failures.""" errors = {} self._validate_instance(instance, errors) if len(errors) > 0: raise ValidationException(errors)
python
def validate(self, instance): """Validates the given document against this schema. Raises a ValidationException if there are any failures.""" errors = {} self._validate_instance(instance, errors) if len(errors) > 0: raise ValidationException(errors)
[ "def", "validate", "(", "self", ",", "instance", ")", ":", "errors", "=", "{", "}", "self", ".", "_validate_instance", "(", "instance", ",", "errors", ")", "if", "len", "(", "errors", ")", ">", "0", ":", "raise", "ValidationException", "(", "errors", "...
Validates the given document against this schema. Raises a ValidationException if there are any failures.
[ "Validates", "the", "given", "document", "against", "this", "schema", ".", "Raises", "a", "ValidationException", "if", "there", "are", "any", "failures", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L51-L58
train
gamechanger/schemer
schemer/__init__.py
Schema._verify
def _verify(self, path_prefix=None): """Verifies that this schema's doc spec is valid and makes sense.""" for field, spec in self.doc_spec.iteritems(): path = self._append_path(path_prefix, field) # Standard dict-based spec if isinstance(spec, dict): ...
python
def _verify(self, path_prefix=None): """Verifies that this schema's doc spec is valid and makes sense.""" for field, spec in self.doc_spec.iteritems(): path = self._append_path(path_prefix, field) # Standard dict-based spec if isinstance(spec, dict): ...
[ "def", "_verify", "(", "self", ",", "path_prefix", "=", "None", ")", ":", "for", "field", ",", "spec", "in", "self", ".", "doc_spec", ".", "iteritems", "(", ")", ":", "path", "=", "self", ".", "_append_path", "(", "path_prefix", ",", "field", ")", "#...
Verifies that this schema's doc spec is valid and makes sense.
[ "Verifies", "that", "this", "schema", "s", "doc", "spec", "is", "valid", "and", "makes", "sense", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L67-L76
train
gamechanger/schemer
schemer/__init__.py
Schema._verify_field_spec
def _verify_field_spec(self, spec, path): """Verifies a given field specification is valid, recursing into nested schemas if required.""" # Required should be a boolean if 'required' in spec and not isinstance(spec['required'], bool): raise SchemaFormatException("{} required declara...
python
def _verify_field_spec(self, spec, path): """Verifies a given field specification is valid, recursing into nested schemas if required.""" # Required should be a boolean if 'required' in spec and not isinstance(spec['required'], bool): raise SchemaFormatException("{} required declara...
[ "def", "_verify_field_spec", "(", "self", ",", "spec", ",", "path", ")", ":", "# Required should be a boolean", "if", "'required'", "in", "spec", "and", "not", "isinstance", "(", "spec", "[", "'required'", "]", ",", "bool", ")", ":", "raise", "SchemaFormatExce...
Verifies a given field specification is valid, recursing into nested schemas if required.
[ "Verifies", "a", "given", "field", "specification", "is", "valid", "recursing", "into", "nested", "schemas", "if", "required", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L79-L106
train
gamechanger/schemer
schemer/__init__.py
Schema._verify_type
def _verify_type(self, spec, path): """Verify that the 'type' in the spec is valid""" field_type = spec['type'] if isinstance(field_type, Schema): # Nested documents cannot have validation if not set(spec.keys()).issubset(set(['type', 'required', 'nullable', 'default']))...
python
def _verify_type(self, spec, path): """Verify that the 'type' in the spec is valid""" field_type = spec['type'] if isinstance(field_type, Schema): # Nested documents cannot have validation if not set(spec.keys()).issubset(set(['type', 'required', 'nullable', 'default']))...
[ "def", "_verify_type", "(", "self", ",", "spec", ",", "path", ")", ":", "field_type", "=", "spec", "[", "'type'", "]", "if", "isinstance", "(", "field_type", ",", "Schema", ")", ":", "# Nested documents cannot have validation", "if", "not", "set", "(", "spec...
Verify that the 'type' in the spec is valid
[ "Verify", "that", "the", "type", "in", "the", "spec", "is", "valid" ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L108-L123
train
gamechanger/schemer
schemer/__init__.py
Schema._verify_default
def _verify_default(self, spec, path): """Verifies that the default specified in the given spec is valid.""" field_type = spec['type'] default = spec['default'] # If it's a function there's nothing we can really do except assume its valid if callable(default): return...
python
def _verify_default(self, spec, path): """Verifies that the default specified in the given spec is valid.""" field_type = spec['type'] default = spec['default'] # If it's a function there's nothing we can really do except assume its valid if callable(default): return...
[ "def", "_verify_default", "(", "self", ",", "spec", ",", "path", ")", ":", "field_type", "=", "spec", "[", "'type'", "]", "default", "=", "spec", "[", "'default'", "]", "# If it's a function there's nothing we can really do except assume its valid", "if", "callable", ...
Verifies that the default specified in the given spec is valid.
[ "Verifies", "that", "the", "default", "specified", "in", "the", "given", "spec", "is", "valid", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L128-L156
train
gamechanger/schemer
schemer/__init__.py
Schema._verify_validates
def _verify_validates(self, spec, path): """Verify thats the 'validates' argument is valid.""" validates = spec['validates'] if isinstance(validates, list): for validator in validates: self._verify_validator(validator, path) else: self._verify_val...
python
def _verify_validates(self, spec, path): """Verify thats the 'validates' argument is valid.""" validates = spec['validates'] if isinstance(validates, list): for validator in validates: self._verify_validator(validator, path) else: self._verify_val...
[ "def", "_verify_validates", "(", "self", ",", "spec", ",", "path", ")", ":", "validates", "=", "spec", "[", "'validates'", "]", "if", "isinstance", "(", "validates", ",", "list", ")", ":", "for", "validator", "in", "validates", ":", "self", ".", "_verify...
Verify thats the 'validates' argument is valid.
[ "Verify", "thats", "the", "validates", "argument", "is", "valid", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L159-L167
train
gamechanger/schemer
schemer/__init__.py
Schema._verify_validator
def _verify_validator(self, validator, path): """Verifies that a given validator associated with the field at the given path is legitimate.""" # Validator should be a function if not callable(validator): raise SchemaFormatException("Invalid validations for {}", path) # Vali...
python
def _verify_validator(self, validator, path): """Verifies that a given validator associated with the field at the given path is legitimate.""" # Validator should be a function if not callable(validator): raise SchemaFormatException("Invalid validations for {}", path) # Vali...
[ "def", "_verify_validator", "(", "self", ",", "validator", ",", "path", ")", ":", "# Validator should be a function", "if", "not", "callable", "(", "validator", ")", ":", "raise", "SchemaFormatException", "(", "\"Invalid validations for {}\"", ",", "path", ")", "# V...
Verifies that a given validator associated with the field at the given path is legitimate.
[ "Verifies", "that", "a", "given", "validator", "associated", "with", "the", "field", "at", "the", "given", "path", "is", "legitimate", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L170-L180
train
gamechanger/schemer
schemer/__init__.py
Schema._validate_instance
def _validate_instance(self, instance, errors, path_prefix=''): """Validates that the given instance of a document conforms to the given schema's structure and validations. Any validation errors are added to the given errors collection. The caller should assume the instance is considered valid i...
python
def _validate_instance(self, instance, errors, path_prefix=''): """Validates that the given instance of a document conforms to the given schema's structure and validations. Any validation errors are added to the given errors collection. The caller should assume the instance is considered valid i...
[ "def", "_validate_instance", "(", "self", ",", "instance", ",", "errors", ",", "path_prefix", "=", "''", ")", ":", "if", "not", "isinstance", "(", "instance", ",", "dict", ")", ":", "errors", "[", "path_prefix", "]", "=", "\"Expected instance of dict to valida...
Validates that the given instance of a document conforms to the given schema's structure and validations. Any validation errors are added to the given errors collection. The caller should assume the instance is considered valid if the errors collection is empty when this method returns.
[ "Validates", "that", "the", "given", "instance", "of", "a", "document", "conforms", "to", "the", "given", "schema", "s", "structure", "and", "validations", ".", "Any", "validation", "errors", "are", "added", "to", "the", "given", "errors", "collection", ".", ...
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L183-L215
train
gamechanger/schemer
schemer/__init__.py
Schema._validate_value
def _validate_value(self, value, field_spec, path, errors): """Validates that the given field value is valid given the associated field spec and path. Any validation failures are added to the given errors collection.""" # Check if the value is None and add an error if the field is not n...
python
def _validate_value(self, value, field_spec, path, errors): """Validates that the given field value is valid given the associated field spec and path. Any validation failures are added to the given errors collection.""" # Check if the value is None and add an error if the field is not n...
[ "def", "_validate_value", "(", "self", ",", "value", ",", "field_spec", ",", "path", ",", "errors", ")", ":", "# Check if the value is None and add an error if the field is not nullable.", "# Note that for backward compatibility reasons, the default value of 'nullable'", "# is the in...
Validates that the given field value is valid given the associated field spec and path. Any validation failures are added to the given errors collection.
[ "Validates", "that", "the", "given", "field", "value", "is", "valid", "given", "the", "associated", "field", "spec", "and", "path", ".", "Any", "validation", "failures", "are", "added", "to", "the", "given", "errors", "collection", "." ]
1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee
https://github.com/gamechanger/schemer/blob/1d1dd7da433d3b84ce5a80ded5a84ab4a65825ee/schemer/__init__.py#L217-L274
train
GaretJax/lancet
lancet/settings.py
load_config
def load_config(path=None, defaults=None): """ Loads and parses an INI style configuration file using Python's built-in configparser module. If path is specified, load it. If ``defaults`` (a list of strings) is given, try to load each entry as a file, without throwing any error if the operation fail...
python
def load_config(path=None, defaults=None): """ Loads and parses an INI style configuration file using Python's built-in configparser module. If path is specified, load it. If ``defaults`` (a list of strings) is given, try to load each entry as a file, without throwing any error if the operation fail...
[ "def", "load_config", "(", "path", "=", "None", ",", "defaults", "=", "None", ")", ":", "if", "defaults", "is", "None", ":", "defaults", "=", "DEFAULT_FILES", "config", "=", "ConfigParser", "(", "allow_no_value", "=", "True", ")", "if", "defaults", ":", ...
Loads and parses an INI style configuration file using Python's built-in configparser module. If path is specified, load it. If ``defaults`` (a list of strings) is given, try to load each entry as a file, without throwing any error if the operation fails. If ``defaults`` is not given, the following loca...
[ "Loads", "and", "parses", "an", "INI", "style", "configuration", "file", "using", "Python", "s", "built", "-", "in", "configparser", "module", ".", "If", "path", "is", "specified", "load", "it", ".", "If", "defaults", "(", "a", "list", "of", "strings", "...
cf438c5c6166b18ee0dc5ffce55220793019bb95
https://github.com/GaretJax/lancet/blob/cf438c5c6166b18ee0dc5ffce55220793019bb95/lancet/settings.py#L37-L61
train
GaretJax/lancet
lancet/settings.py
as_dict
def as_dict(config): """ Converts a ConfigParser object into a dictionary. The resulting dictionary has sections as keys which point to a dict of the sections options as key => value pairs. """ settings = defaultdict(lambda: {}) for section in config.sections(): for key, val in conf...
python
def as_dict(config): """ Converts a ConfigParser object into a dictionary. The resulting dictionary has sections as keys which point to a dict of the sections options as key => value pairs. """ settings = defaultdict(lambda: {}) for section in config.sections(): for key, val in conf...
[ "def", "as_dict", "(", "config", ")", ":", "settings", "=", "defaultdict", "(", "lambda", ":", "{", "}", ")", "for", "section", "in", "config", ".", "sections", "(", ")", ":", "for", "key", ",", "val", "in", "config", ".", "items", "(", "section", ...
Converts a ConfigParser object into a dictionary. The resulting dictionary has sections as keys which point to a dict of the sections options as key => value pairs.
[ "Converts", "a", "ConfigParser", "object", "into", "a", "dictionary", "." ]
cf438c5c6166b18ee0dc5ffce55220793019bb95
https://github.com/GaretJax/lancet/blob/cf438c5c6166b18ee0dc5ffce55220793019bb95/lancet/settings.py#L85-L96
train