repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
christian-oudard/htmltreediff
htmltreediff/util.py
remove_comments
def remove_comments(xml): """ Remove comments, as they can break the xml parser. See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ). >>> remove_comments('<!-- -->') '' >>> remove_comments('<!--\\n-->') '' >>> remove_comments('<p>stuff<!-- \\n -->stuff</p...
python
def remove_comments(xml): """ Remove comments, as they can break the xml parser. See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ). >>> remove_comments('<!-- -->') '' >>> remove_comments('<!--\\n-->') '' >>> remove_comments('<p>stuff<!-- \\n -->stuff</p...
[ "def", "remove_comments", "(", "xml", ")", ":", "regex", "=", "re", ".", "compile", "(", "r'<!--.*?-->'", ",", "re", ".", "DOTALL", ")", "return", "regex", ".", "sub", "(", "''", ",", "xml", ")" ]
Remove comments, as they can break the xml parser. See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ). >>> remove_comments('<!-- -->') '' >>> remove_comments('<!--\\n-->') '' >>> remove_comments('<p>stuff<!-- \\n -->stuff</p>') '<p>stuffstuff</p>'
[ "Remove", "comments", "as", "they", "can", "break", "the", "xml", "parser", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L74-L88
christian-oudard/htmltreediff
htmltreediff/util.py
remove_newlines
def remove_newlines(xml): r"""Remove newlines in the xml. If the newline separates words in text, then replace with a space instead. >>> remove_newlines('<p>para one</p>\n<p>para two</p>') '<p>para one</p><p>para two</p>' >>> remove_newlines('<p>line one\nline two</p>') '<p>line one line two</...
python
def remove_newlines(xml): r"""Remove newlines in the xml. If the newline separates words in text, then replace with a space instead. >>> remove_newlines('<p>para one</p>\n<p>para two</p>') '<p>para one</p><p>para two</p>' >>> remove_newlines('<p>line one\nline two</p>') '<p>line one line two</...
[ "def", "remove_newlines", "(", "xml", ")", ":", "# Normalize newlines.", "xml", "=", "xml", ".", "replace", "(", "'\\r\\n'", ",", "'\\n'", ")", "xml", "=", "xml", ".", "replace", "(", "'\\r'", ",", "'\\n'", ")", "# Remove newlines that don't separate text. The r...
r"""Remove newlines in the xml. If the newline separates words in text, then replace with a space instead. >>> remove_newlines('<p>para one</p>\n<p>para two</p>') '<p>para one</p><p>para two</p>' >>> remove_newlines('<p>line one\nline two</p>') '<p>line one line two</p>' >>> remove_newlines('o...
[ "r", "Remove", "newlines", "in", "the", "xml", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L90-L110
christian-oudard/htmltreediff
htmltreediff/util.py
remove_insignificant_text_nodes
def remove_insignificant_text_nodes(dom): """ For html elements that should not have text nodes inside them, remove all whitespace. For elements that may have text, collapse multiple spaces to a single space. """ nodes_to_remove = [] for node in walk_dom(dom): if is_text(node): ...
python
def remove_insignificant_text_nodes(dom): """ For html elements that should not have text nodes inside them, remove all whitespace. For elements that may have text, collapse multiple spaces to a single space. """ nodes_to_remove = [] for node in walk_dom(dom): if is_text(node): ...
[ "def", "remove_insignificant_text_nodes", "(", "dom", ")", ":", "nodes_to_remove", "=", "[", "]", "for", "node", "in", "walk_dom", "(", "dom", ")", ":", "if", "is_text", "(", "node", ")", ":", "text", "=", "node", ".", "nodeValue", "if", "node", ".", "...
For html elements that should not have text nodes inside them, remove all whitespace. For elements that may have text, collapse multiple spaces to a single space.
[ "For", "html", "elements", "that", "should", "not", "have", "text", "nodes", "inside", "them", "remove", "all", "whitespace", ".", "For", "elements", "that", "may", "have", "text", "collapse", "multiple", "spaces", "to", "a", "single", "space", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L229-L244
christian-oudard/htmltreediff
htmltreediff/util.py
get_child
def get_child(parent, child_index): """ Get the child at the given index, or return None if it doesn't exist. """ if child_index < 0 or child_index >= len(parent.childNodes): return None return parent.childNodes[child_index]
python
def get_child(parent, child_index): """ Get the child at the given index, or return None if it doesn't exist. """ if child_index < 0 or child_index >= len(parent.childNodes): return None return parent.childNodes[child_index]
[ "def", "get_child", "(", "parent", ",", "child_index", ")", ":", "if", "child_index", "<", "0", "or", "child_index", ">=", "len", "(", "parent", ".", "childNodes", ")", ":", "return", "None", "return", "parent", ".", "childNodes", "[", "child_index", "]" ]
Get the child at the given index, or return None if it doesn't exist.
[ "Get", "the", "child", "at", "the", "given", "index", "or", "return", "None", "if", "it", "doesn", "t", "exist", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L253-L259
christian-oudard/htmltreediff
htmltreediff/util.py
get_location
def get_location(dom, location): """ Get the node at the specified location in the dom. Location is a sequence of child indices, starting at the children of the root element. If there is no node at this location, raise a ValueError. """ node = dom.documentElement for i in location: n...
python
def get_location(dom, location): """ Get the node at the specified location in the dom. Location is a sequence of child indices, starting at the children of the root element. If there is no node at this location, raise a ValueError. """ node = dom.documentElement for i in location: n...
[ "def", "get_location", "(", "dom", ",", "location", ")", ":", "node", "=", "dom", ".", "documentElement", "for", "i", "in", "location", ":", "node", "=", "get_child", "(", "node", ",", "i", ")", "if", "not", "node", ":", "raise", "ValueError", "(", "...
Get the node at the specified location in the dom. Location is a sequence of child indices, starting at the children of the root element. If there is no node at this location, raise a ValueError.
[ "Get", "the", "node", "at", "the", "specified", "location", "in", "the", "dom", ".", "Location", "is", "a", "sequence", "of", "child", "indices", "starting", "at", "the", "children", "of", "the", "root", "element", ".", "If", "there", "is", "no", "node",...
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L261-L272
christian-oudard/htmltreediff
htmltreediff/util.py
check_text_similarity
def check_text_similarity(a_dom, b_dom, cutoff): """Check whether two dom trees have similar text or not.""" a_words = list(tree_words(a_dom)) b_words = list(tree_words(b_dom)) sm = WordMatcher(a=a_words, b=b_words) if sm.text_ratio() >= cutoff: return True return False
python
def check_text_similarity(a_dom, b_dom, cutoff): """Check whether two dom trees have similar text or not.""" a_words = list(tree_words(a_dom)) b_words = list(tree_words(b_dom)) sm = WordMatcher(a=a_words, b=b_words) if sm.text_ratio() >= cutoff: return True return False
[ "def", "check_text_similarity", "(", "a_dom", ",", "b_dom", ",", "cutoff", ")", ":", "a_words", "=", "list", "(", "tree_words", "(", "a_dom", ")", ")", "b_words", "=", "list", "(", "tree_words", "(", "b_dom", ")", ")", "sm", "=", "WordMatcher", "(", "a...
Check whether two dom trees have similar text or not.
[ "Check", "whether", "two", "dom", "trees", "have", "similar", "text", "or", "not", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L295-L303
christian-oudard/htmltreediff
htmltreediff/util.py
tree_words
def tree_words(node): """Return all the significant text below the given node as a list of words. >>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>'))) ['one', 'two', 'three', 'four'] """ for word in split_text(tree_text(node)): word = word.strip() if ...
python
def tree_words(node): """Return all the significant text below the given node as a list of words. >>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>'))) ['one', 'two', 'three', 'four'] """ for word in split_text(tree_text(node)): word = word.strip() if ...
[ "def", "tree_words", "(", "node", ")", ":", "for", "word", "in", "split_text", "(", "tree_text", "(", "node", ")", ")", ":", "word", "=", "word", ".", "strip", "(", ")", "if", "word", ":", "yield", "word" ]
Return all the significant text below the given node as a list of words. >>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>'))) ['one', 'two', 'three', 'four']
[ "Return", "all", "the", "significant", "text", "below", "the", "given", "node", "as", "a", "list", "of", "words", ".", ">>>", "list", "(", "tree_words", "(", "parse_minidom", "(", "<h1", ">", "one<", "/", "h1", ">", "two", "<div", ">", "three<em", ">",...
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L305-L313
christian-oudard/htmltreediff
htmltreediff/util.py
tree_text
def tree_text(node): """ >>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>')) 'one two three four' """ text = [] for descendant in walk_dom(node): if is_text(descendant): text.append(descendant.nodeValue) return ' '.join(text)
python
def tree_text(node): """ >>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>')) 'one two three four' """ text = [] for descendant in walk_dom(node): if is_text(descendant): text.append(descendant.nodeValue) return ' '.join(text)
[ "def", "tree_text", "(", "node", ")", ":", "text", "=", "[", "]", "for", "descendant", "in", "walk_dom", "(", "node", ")", ":", "if", "is_text", "(", "descendant", ")", ":", "text", ".", "append", "(", "descendant", ".", "nodeValue", ")", "return", "...
>>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>')) 'one two three four'
[ ">>>", "tree_text", "(", "parse_minidom", "(", "<h1", ">", "one<", "/", "h1", ">", "two<div", ">", "three<em", ">", "four<", "/", "em", ">", "<", "/", "div", ">", "))", "one", "two", "three", "four" ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L315-L324
christian-oudard/htmltreediff
htmltreediff/util.py
insert_or_append
def insert_or_append(parent, node, next_sibling): """ Insert the node before next_sibling. If next_sibling is None, append the node last instead. """ # simple insert if next_sibling: parent.insertBefore(node, next_sibling) else: parent.appendChild(node)
python
def insert_or_append(parent, node, next_sibling): """ Insert the node before next_sibling. If next_sibling is None, append the node last instead. """ # simple insert if next_sibling: parent.insertBefore(node, next_sibling) else: parent.appendChild(node)
[ "def", "insert_or_append", "(", "parent", ",", "node", ",", "next_sibling", ")", ":", "# simple insert", "if", "next_sibling", ":", "parent", ".", "insertBefore", "(", "node", ",", "next_sibling", ")", "else", ":", "parent", ".", "appendChild", "(", "node", ...
Insert the node before next_sibling. If next_sibling is None, append the node last instead.
[ "Insert", "the", "node", "before", "next_sibling", ".", "If", "next_sibling", "is", "None", "append", "the", "node", "last", "instead", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L339-L347
christian-oudard/htmltreediff
htmltreediff/util.py
wrap
def wrap(node, tag): """Wrap the given tag around a node.""" wrap_node = node.ownerDocument.createElement(tag) parent = node.parentNode if parent: parent.replaceChild(wrap_node, node) wrap_node.appendChild(node) return wrap_node
python
def wrap(node, tag): """Wrap the given tag around a node.""" wrap_node = node.ownerDocument.createElement(tag) parent = node.parentNode if parent: parent.replaceChild(wrap_node, node) wrap_node.appendChild(node) return wrap_node
[ "def", "wrap", "(", "node", ",", "tag", ")", ":", "wrap_node", "=", "node", ".", "ownerDocument", ".", "createElement", "(", "tag", ")", "parent", "=", "node", ".", "parentNode", "if", "parent", ":", "parent", ".", "replaceChild", "(", "wrap_node", ",", ...
Wrap the given tag around a node.
[ "Wrap", "the", "given", "tag", "around", "a", "node", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L349-L356
christian-oudard/htmltreediff
htmltreediff/util.py
wrap_inner
def wrap_inner(node, tag): """Wrap the given tag around the contents of a node.""" children = list(node.childNodes) wrap_node = node.ownerDocument.createElement(tag) for c in children: wrap_node.appendChild(c) node.appendChild(wrap_node)
python
def wrap_inner(node, tag): """Wrap the given tag around the contents of a node.""" children = list(node.childNodes) wrap_node = node.ownerDocument.createElement(tag) for c in children: wrap_node.appendChild(c) node.appendChild(wrap_node)
[ "def", "wrap_inner", "(", "node", ",", "tag", ")", ":", "children", "=", "list", "(", "node", ".", "childNodes", ")", "wrap_node", "=", "node", ".", "ownerDocument", ".", "createElement", "(", "tag", ")", "for", "c", "in", "children", ":", "wrap_node", ...
Wrap the given tag around the contents of a node.
[ "Wrap", "the", "given", "tag", "around", "the", "contents", "of", "a", "node", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L358-L364
christian-oudard/htmltreediff
htmltreediff/util.py
unwrap
def unwrap(node): """Remove a node, replacing it with its children.""" for child in list(node.childNodes): node.parentNode.insertBefore(child, node) remove_node(node)
python
def unwrap(node): """Remove a node, replacing it with its children.""" for child in list(node.childNodes): node.parentNode.insertBefore(child, node) remove_node(node)
[ "def", "unwrap", "(", "node", ")", ":", "for", "child", "in", "list", "(", "node", ".", "childNodes", ")", ":", "node", ".", "parentNode", ".", "insertBefore", "(", "child", ",", "node", ")", "remove_node", "(", "node", ")" ]
Remove a node, replacing it with its children.
[ "Remove", "a", "node", "replacing", "it", "with", "its", "children", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L366-L370
christian-oudard/htmltreediff
htmltreediff/text.py
full_split
def full_split(text, regex): """ Split the text by the regex, keeping all parts. The parts should re-join back into the original text. >>> list(full_split('word', re.compile('&.*?'))) ['word'] """ while text: m = regex.search(text) if not m: yield text ...
python
def full_split(text, regex): """ Split the text by the regex, keeping all parts. The parts should re-join back into the original text. >>> list(full_split('word', re.compile('&.*?'))) ['word'] """ while text: m = regex.search(text) if not m: yield text ...
[ "def", "full_split", "(", "text", ",", "regex", ")", ":", "while", "text", ":", "m", "=", "regex", ".", "search", "(", "text", ")", "if", "not", "m", ":", "yield", "text", "break", "left", "=", "text", "[", ":", "m", ".", "start", "(", ")", "]"...
Split the text by the regex, keeping all parts. The parts should re-join back into the original text. >>> list(full_split('word', re.compile('&.*?'))) ['word']
[ "Split", "the", "text", "by", "the", "regex", "keeping", "all", "parts", ".", "The", "parts", "should", "re", "-", "join", "back", "into", "the", "original", "text", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L4-L24
christian-oudard/htmltreediff
htmltreediff/text.py
multi_split
def multi_split(text, regexes): """ Split the text by the given regexes, in priority order. Make sure that the regex is parenthesized so that matches are returned in re.split(). Splitting on a single regex works like normal split. >>> '|'.join(multi_split('one two three', [r'\w+'])) 'one| ...
python
def multi_split(text, regexes): """ Split the text by the given regexes, in priority order. Make sure that the regex is parenthesized so that matches are returned in re.split(). Splitting on a single regex works like normal split. >>> '|'.join(multi_split('one two three', [r'\w+'])) 'one| ...
[ "def", "multi_split", "(", "text", ",", "regexes", ")", ":", "def", "make_regex", "(", "s", ")", ":", "return", "re", ".", "compile", "(", "s", ")", "if", "isinstance", "(", "s", ",", "basestring", ")", "else", "s", "regexes", "=", "[", "make_regex",...
Split the text by the given regexes, in priority order. Make sure that the regex is parenthesized so that matches are returned in re.split(). Splitting on a single regex works like normal split. >>> '|'.join(multi_split('one two three', [r'\w+'])) 'one| |two| |three' Splitting on digits first...
[ "Split", "the", "text", "by", "the", "given", "regexes", "in", "priority", "order", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L26-L69
christian-oudard/htmltreediff
htmltreediff/text.py
WordMatcher.text_ratio
def text_ratio(self): """Return a measure of the sequences' word similarity (float in [0,1]). Each word has weight equal to its length for this measure >>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same >>> '%.3f' % m.ratio() # normal ratio fails ...
python
def text_ratio(self): """Return a measure of the sequences' word similarity (float in [0,1]). Each word has weight equal to its length for this measure >>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same >>> '%.3f' % m.ratio() # normal ratio fails ...
[ "def", "text_ratio", "(", "self", ")", ":", "return", "_calculate_ratio", "(", "self", ".", "match_length", "(", ")", ",", "self", ".", "_text_length", "(", "self", ".", "a", ")", "+", "self", ".", "_text_length", "(", "self", ".", "b", ")", ",", ")"...
Return a measure of the sequences' word similarity (float in [0,1]). Each word has weight equal to its length for this measure >>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same >>> '%.3f' % m.ratio() # normal ratio fails '0.500' >>> '%.3f...
[ "Return", "a", "measure", "of", "the", "sequences", "word", "similarity", "(", "float", "in", "[", "0", "1", "]", ")", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L124-L138
christian-oudard/htmltreediff
htmltreediff/text.py
WordMatcher.match_length
def match_length(self): """ Find the total length of all words that match between the two sequences.""" length = 0 for match in self.get_matching_blocks(): a, b, size = match length += self._text_length(self.a[a:a+size]) return length
python
def match_length(self): """ Find the total length of all words that match between the two sequences.""" length = 0 for match in self.get_matching_blocks(): a, b, size = match length += self._text_length(self.a[a:a+size]) return length
[ "def", "match_length", "(", "self", ")", ":", "length", "=", "0", "for", "match", "in", "self", ".", "get_matching_blocks", "(", ")", ":", "a", ",", "b", ",", "size", "=", "match", "length", "+=", "self", ".", "_text_length", "(", "self", ".", "a", ...
Find the total length of all words that match between the two sequences.
[ "Find", "the", "total", "length", "of", "all", "words", "that", "match", "between", "the", "two", "sequences", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L140-L146
christian-oudard/htmltreediff
htmltreediff/edit_script_runner.py
EditScriptRunner.run_edit_script
def run_edit_script(self): """ Run an xml edit script, and return the new html produced. """ for action, location, properties in self.edit_script: if action == 'delete': node = get_location(self.dom, location) self.action_delete(node) ...
python
def run_edit_script(self): """ Run an xml edit script, and return the new html produced. """ for action, location, properties in self.edit_script: if action == 'delete': node = get_location(self.dom, location) self.action_delete(node) ...
[ "def", "run_edit_script", "(", "self", ")", ":", "for", "action", ",", "location", ",", "properties", "in", "self", ".", "edit_script", ":", "if", "action", "==", "'delete'", ":", "node", "=", "get_location", "(", "self", ".", "dom", ",", "location", ")"...
Run an xml edit script, and return the new html produced.
[ "Run", "an", "xml", "edit", "script", "and", "return", "the", "new", "html", "produced", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/edit_script_runner.py#L48-L60
christian-oudard/htmltreediff
htmltreediff/changes.py
add_changes_markup
def add_changes_markup(dom, ins_nodes, del_nodes): """ Add <ins> and <del> tags to the dom to show changes. """ # add markup for inserted and deleted sections for node in reversed(del_nodes): # diff algorithm deletes nodes in reverse order, so un-reverse the # order for this iteratio...
python
def add_changes_markup(dom, ins_nodes, del_nodes): """ Add <ins> and <del> tags to the dom to show changes. """ # add markup for inserted and deleted sections for node in reversed(del_nodes): # diff algorithm deletes nodes in reverse order, so un-reverse the # order for this iteratio...
[ "def", "add_changes_markup", "(", "dom", ",", "ins_nodes", ",", "del_nodes", ")", ":", "# add markup for inserted and deleted sections", "for", "node", "in", "reversed", "(", "del_nodes", ")", ":", "# diff algorithm deletes nodes in reverse order, so un-reverse the", "# order...
Add <ins> and <del> tags to the dom to show changes.
[ "Add", "<ins", ">", "and", "<del", ">", "tags", "to", "the", "dom", "to", "show", "changes", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L48-L65
christian-oudard/htmltreediff
htmltreediff/changes.py
remove_nesting
def remove_nesting(dom, tag_name): """ Unwrap items in the node list that have ancestors with the same tag. """ for node in dom.getElementsByTagName(tag_name): for ancestor in ancestors(node): if ancestor is node: continue if ancestor is dom.documentElemen...
python
def remove_nesting(dom, tag_name): """ Unwrap items in the node list that have ancestors with the same tag. """ for node in dom.getElementsByTagName(tag_name): for ancestor in ancestors(node): if ancestor is node: continue if ancestor is dom.documentElemen...
[ "def", "remove_nesting", "(", "dom", ",", "tag_name", ")", ":", "for", "node", "in", "dom", ".", "getElementsByTagName", "(", "tag_name", ")", ":", "for", "ancestor", "in", "ancestors", "(", "node", ")", ":", "if", "ancestor", "is", "node", ":", "continu...
Unwrap items in the node list that have ancestors with the same tag.
[ "Unwrap", "items", "in", "the", "node", "list", "that", "have", "ancestors", "with", "the", "same", "tag", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L67-L79
christian-oudard/htmltreediff
htmltreediff/changes.py
sort_nodes
def sort_nodes(dom, cmp_func): """ Sort the nodes of the dom in-place, based on a comparison function. """ dom.normalize() for node in list(walk_dom(dom, elements_only=True)): prev_sib = node.previousSibling while prev_sib and cmp_func(prev_sib, node) == 1: node.parentNod...
python
def sort_nodes(dom, cmp_func): """ Sort the nodes of the dom in-place, based on a comparison function. """ dom.normalize() for node in list(walk_dom(dom, elements_only=True)): prev_sib = node.previousSibling while prev_sib and cmp_func(prev_sib, node) == 1: node.parentNod...
[ "def", "sort_nodes", "(", "dom", ",", "cmp_func", ")", ":", "dom", ".", "normalize", "(", ")", "for", "node", "in", "list", "(", "walk_dom", "(", "dom", ",", "elements_only", "=", "True", ")", ")", ":", "prev_sib", "=", "node", ".", "previousSibling", ...
Sort the nodes of the dom in-place, based on a comparison function.
[ "Sort", "the", "nodes", "of", "the", "dom", "in", "-", "place", "based", "on", "a", "comparison", "function", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L81-L90
christian-oudard/htmltreediff
htmltreediff/changes.py
merge_adjacent
def merge_adjacent(dom, tag_name): """ Merge all adjacent tags with the specified tag name. Return the number of merges performed. """ for node in dom.getElementsByTagName(tag_name): prev_sib = node.previousSibling if prev_sib and prev_sib.nodeName == node.tagName: for ch...
python
def merge_adjacent(dom, tag_name): """ Merge all adjacent tags with the specified tag name. Return the number of merges performed. """ for node in dom.getElementsByTagName(tag_name): prev_sib = node.previousSibling if prev_sib and prev_sib.nodeName == node.tagName: for ch...
[ "def", "merge_adjacent", "(", "dom", ",", "tag_name", ")", ":", "for", "node", "in", "dom", ".", "getElementsByTagName", "(", "tag_name", ")", ":", "prev_sib", "=", "node", ".", "previousSibling", "if", "prev_sib", "and", "prev_sib", ".", "nodeName", "==", ...
Merge all adjacent tags with the specified tag name. Return the number of merges performed.
[ "Merge", "all", "adjacent", "tags", "with", "the", "specified", "tag", "name", ".", "Return", "the", "number", "of", "merges", "performed", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L104-L114
christian-oudard/htmltreediff
htmltreediff/changes.py
distribute
def distribute(node): """ Wrap a copy of the given element around the contents of each of its children, removing the node in the process. """ children = list(c for c in node.childNodes if is_element(c)) unwrap(node) tag_name = node.tagName for c in children: wrap_inner(c, tag_nam...
python
def distribute(node): """ Wrap a copy of the given element around the contents of each of its children, removing the node in the process. """ children = list(c for c in node.childNodes if is_element(c)) unwrap(node) tag_name = node.tagName for c in children: wrap_inner(c, tag_nam...
[ "def", "distribute", "(", "node", ")", ":", "children", "=", "list", "(", "c", "for", "c", "in", "node", ".", "childNodes", "if", "is_element", "(", "c", ")", ")", "unwrap", "(", "node", ")", "tag_name", "=", "node", ".", "tagName", "for", "c", "in...
Wrap a copy of the given element around the contents of each of its children, removing the node in the process.
[ "Wrap", "a", "copy", "of", "the", "given", "element", "around", "the", "contents", "of", "each", "of", "its", "children", "removing", "the", "node", "in", "the", "process", "." ]
train
https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L116-L125
arteria/django-background-image
background_image/models.py
SingletonModel.save
def save(self, *args, **kwargs): """ Save object to the database. Removes all other entries if there are any. """ self.__class__.objects.exclude(id=self.id).delete() super(SingletonModel, self).save(*args, **kwargs)
python
def save(self, *args, **kwargs): """ Save object to the database. Removes all other entries if there are any. """ self.__class__.objects.exclude(id=self.id).delete() super(SingletonModel, self).save(*args, **kwargs)
[ "def", "save", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "__class__", ".", "objects", ".", "exclude", "(", "id", "=", "self", ".", "id", ")", ".", "delete", "(", ")", "super", "(", "SingletonModel", ",", "self...
Save object to the database. Removes all other entries if there are any.
[ "Save", "object", "to", "the", "database", ".", "Removes", "all", "other", "entries", "if", "there", "are", "any", "." ]
train
https://github.com/arteria/django-background-image/blob/30d2c80512bfde0aaf927bde84a50a20e089cd9c/background_image/models.py#L22-L28
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_magicc_region_to_openscm_region_mapping
def get_magicc_region_to_openscm_region_mapping(inverse=False): """Get the mappings from MAGICC to OpenSCM regions. This is not a pure inverse of the other way around. For example, we never provide "GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also have "World". Fortunat...
python
def get_magicc_region_to_openscm_region_mapping(inverse=False): """Get the mappings from MAGICC to OpenSCM regions. This is not a pure inverse of the other way around. For example, we never provide "GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also have "World". Fortunat...
[ "def", "get_magicc_region_to_openscm_region_mapping", "(", "inverse", "=", "False", ")", ":", "def", "get_openscm_replacement", "(", "in_region", ")", ":", "world", "=", "\"World\"", "if", "in_region", "in", "(", "\"WORLD\"", ",", "\"GLOBAL\"", ")", ":", "return",...
Get the mappings from MAGICC to OpenSCM regions. This is not a pure inverse of the other way around. For example, we never provide "GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also have "World". Fortunately MAGICC doesn't ever read the name "GLOBAL" so this shouldn't ma...
[ "Get", "the", "mappings", "from", "MAGICC", "to", "OpenSCM", "regions", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L80-L158
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_magicc_to_openscm_regions
def convert_magicc_to_openscm_regions(regions, inverse=False): """ Convert MAGICC regions to OpenSCM regions Parameters ---------- regions : list_like, str Regions to convert inverse : bool If True, convert the other way i.e. convert OpenSCM regions to MAGICC7 regions ...
python
def convert_magicc_to_openscm_regions(regions, inverse=False): """ Convert MAGICC regions to OpenSCM regions Parameters ---------- regions : list_like, str Regions to convert inverse : bool If True, convert the other way i.e. convert OpenSCM regions to MAGICC7 regions ...
[ "def", "convert_magicc_to_openscm_regions", "(", "regions", ",", "inverse", "=", "False", ")", ":", "if", "isinstance", "(", "regions", ",", "(", "list", ",", "pd", ".", "Index", ")", ")", ":", "return", "[", "_apply_convert_magicc_to_openscm_regions", "(", "r...
Convert MAGICC regions to OpenSCM regions Parameters ---------- regions : list_like, str Regions to convert inverse : bool If True, convert the other way i.e. convert OpenSCM regions to MAGICC7 regions Returns ------- ``type(regions)`` Set of converted regi...
[ "Convert", "MAGICC", "regions", "to", "OpenSCM", "regions" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L188-L209
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_magicc7_to_openscm_variable_mapping
def get_magicc7_to_openscm_variable_mapping(inverse=False): """Get the mappings from MAGICC7 to OpenSCM variables. Parameters ---------- inverse : bool If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings Returns ------- dict Dictionary of mappings """ ...
python
def get_magicc7_to_openscm_variable_mapping(inverse=False): """Get the mappings from MAGICC7 to OpenSCM variables. Parameters ---------- inverse : bool If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings Returns ------- dict Dictionary of mappings """ ...
[ "def", "get_magicc7_to_openscm_variable_mapping", "(", "inverse", "=", "False", ")", ":", "def", "get_openscm_replacement", "(", "in_var", ")", ":", "if", "in_var", ".", "endswith", "(", "\"_INVERSE_EMIS\"", ")", ":", "prefix", "=", "\"Inverse Emissions\"", "elif", ...
Get the mappings from MAGICC7 to OpenSCM variables. Parameters ---------- inverse : bool If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings Returns ------- dict Dictionary of mappings
[ "Get", "the", "mappings", "from", "MAGICC7", "to", "OpenSCM", "variables", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L212-L369
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_magicc7_to_openscm_variables
def convert_magicc7_to_openscm_variables(variables, inverse=False): """ Convert MAGICC7 variables to OpenSCM variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert OpenSCM variables to MAGICC7 ...
python
def convert_magicc7_to_openscm_variables(variables, inverse=False): """ Convert MAGICC7 variables to OpenSCM variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert OpenSCM variables to MAGICC7 ...
[ "def", "convert_magicc7_to_openscm_variables", "(", "variables", ",", "inverse", "=", "False", ")", ":", "if", "isinstance", "(", "variables", ",", "(", "list", ",", "pd", ".", "Index", ")", ")", ":", "return", "[", "_apply_convert_magicc7_to_openscm_variables", ...
Convert MAGICC7 variables to OpenSCM variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert OpenSCM variables to MAGICC7 variables Returns ------- ``type(variables)`` Set of...
[ "Convert", "MAGICC7", "variables", "to", "OpenSCM", "variables" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L400-L423
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_magicc6_to_magicc7_variable_mapping
def get_magicc6_to_magicc7_variable_mapping(inverse=False): """Get the mappings from MAGICC6 to MAGICC7 variables. Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and "HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in MAGICC7 maps back to "HFC4310". ...
python
def get_magicc6_to_magicc7_variable_mapping(inverse=False): """Get the mappings from MAGICC6 to MAGICC7 variables. Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and "HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in MAGICC7 maps back to "HFC4310". ...
[ "def", "get_magicc6_to_magicc7_variable_mapping", "(", "inverse", "=", "False", ")", ":", "# we generate the mapping dynamically, the first name in the list", "# is the one which will be used for inverse mappings", "magicc6_simple_mapping_vars", "=", "[", "\"KYOTO-CO2EQ\"", ",", "\"CO2...
Get the mappings from MAGICC6 to MAGICC7 variables. Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and "HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in MAGICC7 maps back to "HFC4310". Note that HFC-245fa was mistakenly labelled as HFC-245ca in MAGI...
[ "Get", "the", "mappings", "from", "MAGICC6", "to", "MAGICC7", "variables", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L426-L562
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_magicc6_to_magicc7_variables
def convert_magicc6_to_magicc7_variables(variables, inverse=False): """ Convert MAGICC6 variables to MAGICC7 variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6 ...
python
def convert_magicc6_to_magicc7_variables(variables, inverse=False): """ Convert MAGICC6 variables to MAGICC7 variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6 ...
[ "def", "convert_magicc6_to_magicc7_variables", "(", "variables", ",", "inverse", "=", "False", ")", ":", "if", "isinstance", "(", "variables", ",", "(", "list", ",", "pd", ".", "Index", ")", ")", ":", "return", "[", "_apply_convert_magicc6_to_magicc7_variables", ...
Convert MAGICC6 variables to MAGICC7 variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6 variables Raises ------ ValueError If you try to con...
[ "Convert", "MAGICC6", "variables", "to", "MAGICC7", "variables" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L604-L636
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_pint_to_fortran_safe_units_mapping
def get_pint_to_fortran_safe_units_mapping(inverse=False): """Get the mappings from Pint to Fortran safe units. Fortran can't handle special characters like "^" or "/" in names, but we need these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt CO2 / yr" but we don't want thes...
python
def get_pint_to_fortran_safe_units_mapping(inverse=False): """Get the mappings from Pint to Fortran safe units. Fortran can't handle special characters like "^" or "/" in names, but we need these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt CO2 / yr" but we don't want thes...
[ "def", "get_pint_to_fortran_safe_units_mapping", "(", "inverse", "=", "False", ")", ":", "replacements", "=", "{", "\"^\"", ":", "\"super\"", ",", "\"/\"", ":", "\"per\"", ",", "\" \"", ":", "\"\"", "}", "if", "inverse", ":", "replacements", "=", "{", "v", ...
Get the mappings from Pint to Fortran safe units. Fortran can't handle special characters like "^" or "/" in names, but we need these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt CO2 / yr" but we don't want these in the input files as Fortran is likely to think the whitesp...
[ "Get", "the", "mappings", "from", "Pint", "to", "Fortran", "safe", "units", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L639-L664
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_pint_to_fortran_safe_units
def convert_pint_to_fortran_safe_units(units, inverse=False): """ Convert Pint units to Fortran safe units Parameters ---------- units : list_like, str Units to convert inverse : bool If True, convert the other way i.e. convert Fortran safe units to Pint units Returns ...
python
def convert_pint_to_fortran_safe_units(units, inverse=False): """ Convert Pint units to Fortran safe units Parameters ---------- units : list_like, str Units to convert inverse : bool If True, convert the other way i.e. convert Fortran safe units to Pint units Returns ...
[ "def", "convert_pint_to_fortran_safe_units", "(", "units", ",", "inverse", "=", "False", ")", ":", "if", "inverse", ":", "return", "apply_string_substitutions", "(", "units", ",", "FORTRAN_SAFE_TO_PINT_UNITS_MAPPING", ")", "else", ":", "return", "apply_string_substituti...
Convert Pint units to Fortran safe units Parameters ---------- units : list_like, str Units to convert inverse : bool If True, convert the other way i.e. convert Fortran safe units to Pint units Returns ------- ``type(units)`` Set of converted units
[ "Convert", "Pint", "units", "to", "Fortran", "safe", "units" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L678-L698
productml/blurr
blurr/core/field.py
Field.run_evaluate
def run_evaluate(self) -> None: """ Overrides the base evaluation to set the value to the evaluation result of the value expression in the schema """ result = None self.eval_error = False if self._needs_evaluation: result = self._schema.value.evaluate(...
python
def run_evaluate(self) -> None: """ Overrides the base evaluation to set the value to the evaluation result of the value expression in the schema """ result = None self.eval_error = False if self._needs_evaluation: result = self._schema.value.evaluate(...
[ "def", "run_evaluate", "(", "self", ")", "->", "None", ":", "result", "=", "None", "self", ".", "eval_error", "=", "False", "if", "self", ".", "_needs_evaluation", ":", "result", "=", "self", ".", "_schema", ".", "value", ".", "evaluate", "(", "self", ...
Overrides the base evaluation to set the value to the evaluation result of the value expression in the schema
[ "Overrides", "the", "base", "evaluation", "to", "set", "the", "value", "to", "the", "evaluation", "result", "of", "the", "value", "expression", "in", "the", "schema" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field.py#L90-L124
productml/blurr
blurr/core/field_complex.py
Map.set
def set(self, key: Any, value: Any) -> None: """ Sets the value of a key to a supplied value """ if key is not None: self[key] = value
python
def set(self, key: Any, value: Any) -> None: """ Sets the value of a key to a supplied value """ if key is not None: self[key] = value
[ "def", "set", "(", "self", ",", "key", ":", "Any", ",", "value", ":", "Any", ")", "->", "None", ":", "if", "key", "is", "not", "None", ":", "self", "[", "key", "]", "=", "value" ]
Sets the value of a key to a supplied value
[ "Sets", "the", "value", "of", "a", "key", "to", "a", "supplied", "value" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L11-L14
productml/blurr
blurr/core/field_complex.py
Map.increment
def increment(self, key: Any, by: int = 1) -> None: """ Increments the value set against a key. If the key is not present, 0 is assumed as the initial state """ if key is not None: self[key] = self.get(key, 0) + by
python
def increment(self, key: Any, by: int = 1) -> None: """ Increments the value set against a key. If the key is not present, 0 is assumed as the initial state """ if key is not None: self[key] = self.get(key, 0) + by
[ "def", "increment", "(", "self", ",", "key", ":", "Any", ",", "by", ":", "int", "=", "1", ")", "->", "None", ":", "if", "key", "is", "not", "None", ":", "self", "[", "key", "]", "=", "self", ".", "get", "(", "key", ",", "0", ")", "+", "by" ...
Increments the value set against a key. If the key is not present, 0 is assumed as the initial state
[ "Increments", "the", "value", "set", "against", "a", "key", ".", "If", "the", "key", "is", "not", "present", "0", "is", "assumed", "as", "the", "initial", "state" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L16-L19
productml/blurr
blurr/core/field_complex.py
List.insert
def insert(self, index: int, obj: Any) -> None: """ Inserts an item to the list as long as it is not None """ if obj is not None: super().insert(index, obj)
python
def insert(self, index: int, obj: Any) -> None: """ Inserts an item to the list as long as it is not None """ if obj is not None: super().insert(index, obj)
[ "def", "insert", "(", "self", ",", "index", ":", "int", ",", "obj", ":", "Any", ")", "->", "None", ":", "if", "obj", "is", "not", "None", ":", "super", "(", ")", ".", "insert", "(", "index", ",", "obj", ")" ]
Inserts an item to the list as long as it is not None
[ "Inserts", "an", "item", "to", "the", "list", "as", "long", "as", "it", "is", "not", "None" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L42-L45
openclimatedata/pymagicc
pymagicc/io.py
get_dattype_regionmode
def get_dattype_regionmode(regions, scen7=False): """ Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set. In all MAGICC input files, there are two flags: THISFILE_DATTYPE and THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This function maps the ...
python
def get_dattype_regionmode(regions, scen7=False): """ Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set. In all MAGICC input files, there are two flags: THISFILE_DATTYPE and THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This function maps the ...
[ "def", "get_dattype_regionmode", "(", "regions", ",", "scen7", "=", "False", ")", ":", "dattype_flag", "=", "\"THISFILE_DATTYPE\"", "regionmode_flag", "=", "\"THISFILE_REGIONMODE\"", "region_dattype_row", "=", "_get_dattype_regionmode_regions_row", "(", "regions", ",", "s...
Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set. In all MAGICC input files, there are two flags: THISFILE_DATTYPE and THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This function maps the regions which are in a given file to the value of these flags ...
[ "Get", "the", "THISFILE_DATTYPE", "and", "THISFILE_REGIONMODE", "flags", "for", "a", "given", "region", "set", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1131-L1165
openclimatedata/pymagicc
pymagicc/io.py
get_region_order
def get_region_order(regions, scen7=False): """ Get the region order expected by MAGICC. Parameters ---------- regions : list_like The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for. scen7 : bool, optional Whether the file we are getting the flags for is a SC...
python
def get_region_order(regions, scen7=False): """ Get the region order expected by MAGICC. Parameters ---------- regions : list_like The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for. scen7 : bool, optional Whether the file we are getting the flags for is a SC...
[ "def", "get_region_order", "(", "regions", ",", "scen7", "=", "False", ")", ":", "region_dattype_row", "=", "_get_dattype_regionmode_regions_row", "(", "regions", ",", "scen7", "=", "scen7", ")", "region_order", "=", "DATTYPE_REGIONMODE_REGIONS", "[", "\"regions\"", ...
Get the region order expected by MAGICC. Parameters ---------- regions : list_like The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for. scen7 : bool, optional Whether the file we are getting the flags for is a SCEN7 file or not. Returns ------- list ...
[ "Get", "the", "region", "order", "expected", "by", "MAGICC", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1168-L1188
openclimatedata/pymagicc
pymagicc/io.py
get_special_scen_code
def get_special_scen_code(regions, emissions): """ Get special code for MAGICC6 SCEN files. At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions data is being provided for. The second digit, the 'sce...
python
def get_special_scen_code(regions, emissions): """ Get special code for MAGICC6 SCEN files. At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions data is being provided for. The second digit, the 'sce...
[ "def", "get_special_scen_code", "(", "regions", ",", "emissions", ")", ":", "if", "sorted", "(", "set", "(", "PART_OF_SCENFILE_WITH_EMISSIONS_CODE_0", ")", ")", "==", "sorted", "(", "set", "(", "emissions", ")", ")", ":", "scenfile_emissions_code", "=", "0", "...
Get special code for MAGICC6 SCEN files. At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions data is being provided for. The second digit, the 'scenfile_emissions_code', tells MAGICC which gases are in ...
[ "Get", "special", "code", "for", "MAGICC6", "SCEN", "files", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1796-L1852
openclimatedata/pymagicc
pymagicc/io.py
determine_tool
def determine_tool(filepath, tool_to_get): """ Determine the tool to use for reading/writing. The function uses an internally defined set of mappings between filepaths, regular expresions and readers/writers to work out which tool to use for a given task, given the filepath. It is intended for...
python
def determine_tool(filepath, tool_to_get): """ Determine the tool to use for reading/writing. The function uses an internally defined set of mappings between filepaths, regular expresions and readers/writers to work out which tool to use for a given task, given the filepath. It is intended for...
[ "def", "determine_tool", "(", "filepath", ",", "tool_to_get", ")", ":", "file_regexp_reader_writer", "=", "{", "\"SCEN\"", ":", "{", "\"regexp\"", ":", "r\"^.*\\.SCEN$\"", ",", "\"reader\"", ":", "_ScenReader", ",", "\"writer\"", ":", "_ScenWriter", "}", ",", "\...
Determine the tool to use for reading/writing. The function uses an internally defined set of mappings between filepaths, regular expresions and readers/writers to work out which tool to use for a given task, given the filepath. It is intended for internal use only, but is public because of its im...
[ "Determine", "the", "tool", "to", "use", "for", "reading", "/", "writing", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2021-L2163
openclimatedata/pymagicc
pymagicc/io.py
pull_cfg_from_parameters_out
def pull_cfg_from_parameters_out(parameters_out, namelist_to_read="nml_allcfgs"): """Pull out a single config set from a parameters_out namelist. This function returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``parame...
python
def pull_cfg_from_parameters_out(parameters_out, namelist_to_read="nml_allcfgs"): """Pull out a single config set from a parameters_out namelist. This function returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``parame...
[ "def", "pull_cfg_from_parameters_out", "(", "parameters_out", ",", "namelist_to_read", "=", "\"nml_allcfgs\"", ")", ":", "single_cfg", "=", "Namelist", "(", "{", "namelist_to_read", ":", "{", "}", "}", ")", "for", "key", ",", "value", "in", "parameters_out", "["...
Pull out a single config set from a parameters_out namelist. This function returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``parameters_out``. Parameters ---------- parameters_out : dict, f90nml.Namelist ...
[ "Pull", "out", "a", "single", "config", "set", "from", "a", "parameters_out", "namelist", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2196-L2246
openclimatedata/pymagicc
pymagicc/io.py
pull_cfg_from_parameters_out_file
def pull_cfg_from_parameters_out_file( parameters_out_file, namelist_to_read="nml_allcfgs" ): """Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file. This function reads in the ``PARAMETERS.OUT`` file and returns a single file with the config that needs to be passed to MAGICC in order to...
python
def pull_cfg_from_parameters_out_file( parameters_out_file, namelist_to_read="nml_allcfgs" ): """Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file. This function reads in the ``PARAMETERS.OUT`` file and returns a single file with the config that needs to be passed to MAGICC in order to...
[ "def", "pull_cfg_from_parameters_out_file", "(", "parameters_out_file", ",", "namelist_to_read", "=", "\"nml_allcfgs\"", ")", ":", "parameters_out", "=", "read_cfg_file", "(", "parameters_out_file", ")", "return", "pull_cfg_from_parameters_out", "(", "parameters_out", ",", ...
Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file. This function reads in the ``PARAMETERS.OUT`` file and returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``PARAMETERS.OUT``. Parameters ---------...
[ "Pull", "out", "a", "single", "config", "set", "from", "a", "MAGICC", "PARAMETERS", ".", "OUT", "file", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2249-L2279
openclimatedata/pymagicc
pymagicc/io.py
get_generic_rcp_name
def get_generic_rcp_name(inname): """Convert an RCP name into the generic Pymagicc RCP name The conversion is case insensitive. Parameters ---------- inname : str The name for which to get the generic Pymagicc RCP name Returns ------- str The generic Pymagicc RCP name ...
python
def get_generic_rcp_name(inname): """Convert an RCP name into the generic Pymagicc RCP name The conversion is case insensitive. Parameters ---------- inname : str The name for which to get the generic Pymagicc RCP name Returns ------- str The generic Pymagicc RCP name ...
[ "def", "get_generic_rcp_name", "(", "inname", ")", ":", "# TODO: move into OpenSCM", "mapping", "=", "{", "\"rcp26\"", ":", "\"rcp26\"", ",", "\"rcp3pd\"", ":", "\"rcp26\"", ",", "\"rcp45\"", ":", "\"rcp45\"", ",", "\"rcp6\"", ":", "\"rcp60\"", ",", "\"rcp60\"", ...
Convert an RCP name into the generic Pymagicc RCP name The conversion is case insensitive. Parameters ---------- inname : str The name for which to get the generic Pymagicc RCP name Returns ------- str The generic Pymagicc RCP name Examples -------- >>> get_ge...
[ "Convert", "an", "RCP", "name", "into", "the", "generic", "Pymagicc", "RCP", "name" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2282-L2315
openclimatedata/pymagicc
pymagicc/io.py
join_timeseries
def join_timeseries(base, overwrite, join_linear=None): """Join two sets of timeseries Parameters ---------- base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Base timeseries to use. If a filepath, the data will first be loaded from disk. overwrite : :obj:`MAGICCData`, :obj:`pd.DataF...
python
def join_timeseries(base, overwrite, join_linear=None): """Join two sets of timeseries Parameters ---------- base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Base timeseries to use. If a filepath, the data will first be loaded from disk. overwrite : :obj:`MAGICCData`, :obj:`pd.DataF...
[ "def", "join_timeseries", "(", "base", ",", "overwrite", ",", "join_linear", "=", "None", ")", ":", "if", "join_linear", "is", "not", "None", ":", "if", "len", "(", "join_linear", ")", "!=", "2", ":", "raise", "ValueError", "(", "\"join_linear must have a le...
Join two sets of timeseries Parameters ---------- base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Base timeseries to use. If a filepath, the data will first be loaded from disk. overwrite : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Timeseries to join onto base. Any point...
[ "Join", "two", "sets", "of", "timeseries" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2320-L2363
openclimatedata/pymagicc
pymagicc/io.py
read_scen_file
def read_scen_file( filepath, columns={ "model": ["unspecified"], "scenario": ["unspecified"], "climate_model": ["unspecified"], }, **kwargs ): """ Read a MAGICC .SCEN file. Parameters ---------- filepath : str Filepath of the .SCEN file to read ...
python
def read_scen_file( filepath, columns={ "model": ["unspecified"], "scenario": ["unspecified"], "climate_model": ["unspecified"], }, **kwargs ): """ Read a MAGICC .SCEN file. Parameters ---------- filepath : str Filepath of the .SCEN file to read ...
[ "def", "read_scen_file", "(", "filepath", ",", "columns", "=", "{", "\"model\"", ":", "[", "\"unspecified\"", "]", ",", "\"scenario\"", ":", "[", "\"unspecified\"", "]", ",", "\"climate_model\"", ":", "[", "\"unspecified\"", "]", ",", "}", ",", "*", "*", "...
Read a MAGICC .SCEN file. Parameters ---------- filepath : str Filepath of the .SCEN file to read columns : dict Passed to ``__init__`` method of MAGICCData. See ``MAGICCData.__init__`` for details. kwargs Passed to ``__init__`` method of MAGICCData. See ``...
[ "Read", "a", "MAGICC", ".", "SCEN", "file", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2431-L2463
openclimatedata/pymagicc
pymagicc/io.py
_get_openscm_var_from_filepath
def _get_openscm_var_from_filepath(filepath): """ Determine the OpenSCM variable from a filepath. Uses MAGICC's internal, implicit, filenaming conventions. Parameters ---------- filepath : str Filepath from which to determine the OpenSCM variable. Returns ------- str ...
python
def _get_openscm_var_from_filepath(filepath): """ Determine the OpenSCM variable from a filepath. Uses MAGICC's internal, implicit, filenaming conventions. Parameters ---------- filepath : str Filepath from which to determine the OpenSCM variable. Returns ------- str ...
[ "def", "_get_openscm_var_from_filepath", "(", "filepath", ")", ":", "reader", "=", "determine_tool", "(", "filepath", ",", "\"reader\"", ")", "(", "filepath", ")", "openscm_var", "=", "convert_magicc7_to_openscm_variables", "(", "convert_magicc6_to_magicc7_variables", "("...
Determine the OpenSCM variable from a filepath. Uses MAGICC's internal, implicit, filenaming conventions. Parameters ---------- filepath : str Filepath from which to determine the OpenSCM variable. Returns ------- str The OpenSCM variable implied by the filepath.
[ "Determine", "the", "OpenSCM", "variable", "from", "a", "filepath", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2466-L2487
openclimatedata/pymagicc
pymagicc/io.py
_Reader._find_nml
def _find_nml(self): """ Find the start and end of the embedded namelist. Returns ------- (int, int) start and end index for the namelist """ nml_start = None nml_end = None for i in range(len(self.lines)): if self.lines[i]...
python
def _find_nml(self): """ Find the start and end of the embedded namelist. Returns ------- (int, int) start and end index for the namelist """ nml_start = None nml_end = None for i in range(len(self.lines)): if self.lines[i]...
[ "def", "_find_nml", "(", "self", ")", ":", "nml_start", "=", "None", "nml_end", "=", "None", "for", "i", "in", "range", "(", "len", "(", "self", ".", "lines", ")", ")", ":", "if", "self", ".", "lines", "[", "i", "]", ".", "strip", "(", ")", "."...
Find the start and end of the embedded namelist. Returns ------- (int, int) start and end index for the namelist
[ "Find", "the", "start", "and", "end", "of", "the", "embedded", "namelist", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L143-L163
openclimatedata/pymagicc
pymagicc/io.py
_Reader.process_data
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file. Parameters ---------- stream : Streamlike object A Streamlike object (nominally StringIO) containing the table to be extracted metadata : dict ...
python
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file. Parameters ---------- stream : Streamlike object A Streamlike object (nominally StringIO) containing the table to be extracted metadata : dict ...
[ "def", "process_data", "(", "self", ",", "stream", ",", "metadata", ")", ":", "ch", ",", "metadata", "=", "self", ".", "_get_column_headers_and_update_metadata", "(", "stream", ",", "metadata", ")", "df", "=", "self", ".", "_convert_data_block_and_headers_to_df", ...
Extract the tabulated data from the input file. Parameters ---------- stream : Streamlike object A Streamlike object (nominally StringIO) containing the table to be extracted metadata : dict Metadata read in from the header and the namelist R...
[ "Extract", "the", "tabulated", "data", "from", "the", "input", "file", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L200-L222
openclimatedata/pymagicc
pymagicc/io.py
_Reader._convert_data_block_and_headers_to_df
def _convert_data_block_and_headers_to_df(self, stream): """ stream : Streamlike object A Streamlike object (nominally StringIO) containing the data to be extracted ch : dict Column headers to use for the output pd.DataFrame Returns ------- ...
python
def _convert_data_block_and_headers_to_df(self, stream): """ stream : Streamlike object A Streamlike object (nominally StringIO) containing the data to be extracted ch : dict Column headers to use for the output pd.DataFrame Returns ------- ...
[ "def", "_convert_data_block_and_headers_to_df", "(", "self", ",", "stream", ")", ":", "df", "=", "pd", ".", "read_csv", "(", "stream", ",", "skip_blank_lines", "=", "True", ",", "delim_whitespace", "=", "True", ",", "header", "=", "None", ",", "index_col", "...
stream : Streamlike object A Streamlike object (nominally StringIO) containing the data to be extracted ch : dict Column headers to use for the output pd.DataFrame Returns ------- :obj:`pd.DataFrame` Dataframe with processed datablock
[ "stream", ":", "Streamlike", "object", "A", "Streamlike", "object", "(", "nominally", "StringIO", ")", "containing", "the", "data", "to", "be", "extracted" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L224-L252
openclimatedata/pymagicc
pymagicc/io.py
_Reader._get_variable_from_filepath
def _get_variable_from_filepath(self): """ Determine the file variable from the filepath. Returns ------- str Best guess of variable name from the filepath """ try: return self.regexp_capture_variable.search(self.filepath).group(1) ...
python
def _get_variable_from_filepath(self): """ Determine the file variable from the filepath. Returns ------- str Best guess of variable name from the filepath """ try: return self.regexp_capture_variable.search(self.filepath).group(1) ...
[ "def", "_get_variable_from_filepath", "(", "self", ")", ":", "try", ":", "return", "self", ".", "regexp_capture_variable", ".", "search", "(", "self", ".", "filepath", ")", ".", "group", "(", "1", ")", "except", "AttributeError", ":", "self", ".", "_raise_ca...
Determine the file variable from the filepath. Returns ------- str Best guess of variable name from the filepath
[ "Determine", "the", "file", "variable", "from", "the", "filepath", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L359-L371
openclimatedata/pymagicc
pymagicc/io.py
_Reader.process_header
def process_header(self, header): """ Parse the header for additional metadata. Parameters ---------- header : str All the lines in the header. Returns ------- dict The metadata in the header. """ metadata = {} ...
python
def process_header(self, header): """ Parse the header for additional metadata. Parameters ---------- header : str All the lines in the header. Returns ------- dict The metadata in the header. """ metadata = {} ...
[ "def", "process_header", "(", "self", ",", "header", ")", ":", "metadata", "=", "{", "}", "for", "line", "in", "header", ".", "split", "(", "\"\\n\"", ")", ":", "line", "=", "line", ".", "strip", "(", ")", "for", "tag", "in", "self", ".", "header_t...
Parse the header for additional metadata. Parameters ---------- header : str All the lines in the header. Returns ------- dict The metadata in the header.
[ "Parse", "the", "header", "for", "additional", "metadata", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L383-L405
openclimatedata/pymagicc
pymagicc/io.py
_Reader._read_data_header_line
def _read_data_header_line(self, stream, expected_header): """Read a data header line, ensuring that it starts with the expected header Parameters ---------- stream : :obj:`StreamIO` Stream object containing the text to read expected_header : str, list of strs ...
python
def _read_data_header_line(self, stream, expected_header): """Read a data header line, ensuring that it starts with the expected header Parameters ---------- stream : :obj:`StreamIO` Stream object containing the text to read expected_header : str, list of strs ...
[ "def", "_read_data_header_line", "(", "self", ",", "stream", ",", "expected_header", ")", ":", "pos", "=", "stream", ".", "tell", "(", ")", "expected_header", "=", "(", "[", "expected_header", "]", "if", "isinstance", "(", "expected_header", ",", "str", ")",...
Read a data header line, ensuring that it starts with the expected header Parameters ---------- stream : :obj:`StreamIO` Stream object containing the text to read expected_header : str, list of strs Expected header of the data header line
[ "Read", "a", "data", "header", "line", "ensuring", "that", "it", "starts", "with", "the", "expected", "header" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L407-L434
openclimatedata/pymagicc
pymagicc/io.py
_BinData.read_chunk
def read_chunk(self, t): """ Read out the next chunk of memory Values in fortran binary streams begin and end with the number of bytes :param t: Data type (same format as used by struct). :return: Numpy array if the variable is an array, otherwise a scalar. """ s...
python
def read_chunk(self, t): """ Read out the next chunk of memory Values in fortran binary streams begin and end with the number of bytes :param t: Data type (same format as used by struct). :return: Numpy array if the variable is an array, otherwise a scalar. """ s...
[ "def", "read_chunk", "(", "self", ",", "t", ")", ":", "size", "=", "self", ".", "data", "[", "self", ".", "pos", ":", "self", ".", "pos", "+", "4", "]", ".", "cast", "(", "\"i\"", ")", "[", "0", "]", "d", "=", "self", ".", "data", "[", "sel...
Read out the next chunk of memory Values in fortran binary streams begin and end with the number of bytes :param t: Data type (same format as used by struct). :return: Numpy array if the variable is an array, otherwise a scalar.
[ "Read", "out", "the", "next", "chunk", "of", "memory" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1017-L1039
openclimatedata/pymagicc
pymagicc/io.py
_BinaryOutReader.process_data
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file # Arguments stream (Streamlike object): A Streamlike object (nominally StringIO) containing the table to be extracted metadata (dict): metadata read in from the header and th...
python
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file # Arguments stream (Streamlike object): A Streamlike object (nominally StringIO) containing the table to be extracted metadata (dict): metadata read in from the header and th...
[ "def", "process_data", "(", "self", ",", "stream", ",", "metadata", ")", ":", "index", "=", "np", ".", "arange", "(", "metadata", "[", "\"firstyear\"", "]", ",", "metadata", "[", "\"lastyear\"", "]", "+", "1", ")", "# The first variable is the global values", ...
Extract the tabulated data from the input file # Arguments stream (Streamlike object): A Streamlike object (nominally StringIO) containing the table to be extracted metadata (dict): metadata read in from the header and the namelist # Returns df (pandas.DataFrame): c...
[ "Extract", "the", "tabulated", "data", "from", "the", "input", "file" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1055-L1108
openclimatedata/pymagicc
pymagicc/io.py
_BinaryOutReader.process_header
def process_header(self, data): """ Reads the first part of the file to get some essential metadata # Returns return (dict): the metadata in the header """ metadata = { "datacolumns": data.read_chunk("I"), "firstyear": data.read_chunk("I"), ...
python
def process_header(self, data): """ Reads the first part of the file to get some essential metadata # Returns return (dict): the metadata in the header """ metadata = { "datacolumns": data.read_chunk("I"), "firstyear": data.read_chunk("I"), ...
[ "def", "process_header", "(", "self", ",", "data", ")", ":", "metadata", "=", "{", "\"datacolumns\"", ":", "data", ".", "read_chunk", "(", "\"I\"", ")", ",", "\"firstyear\"", ":", "data", ".", "read_chunk", "(", "\"I\"", ")", ",", "\"lastyear\"", ":", "d...
Reads the first part of the file to get some essential metadata # Returns return (dict): the metadata in the header
[ "Reads", "the", "first", "part", "of", "the", "file", "to", "get", "some", "essential", "metadata" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1110-L1128
openclimatedata/pymagicc
pymagicc/io.py
_Writer.write
def write(self, magicc_input, filepath): """ Write a MAGICC input file from df and metadata Parameters ---------- magicc_input : :obj:`pymagicc.io.MAGICCData` MAGICCData object which holds the data to write filepath : str Filepath of the file to ...
python
def write(self, magicc_input, filepath): """ Write a MAGICC input file from df and metadata Parameters ---------- magicc_input : :obj:`pymagicc.io.MAGICCData` MAGICCData object which holds the data to write filepath : str Filepath of the file to ...
[ "def", "write", "(", "self", ",", "magicc_input", ",", "filepath", ")", ":", "self", ".", "_filepath", "=", "filepath", "# TODO: make copy attribute for MAGICCData", "self", ".", "minput", "=", "deepcopy", "(", "magicc_input", ")", "self", ".", "data_block", "="...
Write a MAGICC input file from df and metadata Parameters ---------- magicc_input : :obj:`pymagicc.io.MAGICCData` MAGICCData object which holds the data to write filepath : str Filepath of the file to write to.
[ "Write", "a", "MAGICC", "input", "file", "from", "df", "and", "metadata" ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1240-L1267
openclimatedata/pymagicc
pymagicc/io.py
MAGICCData.append
def append(self, other, inplace=False, **kwargs): """ Append any input which can be converted to MAGICCData to self. Parameters ---------- other : MAGICCData, pd.DataFrame, pd.Series, str Source of data to append. inplace : bool If True, append `...
python
def append(self, other, inplace=False, **kwargs): """ Append any input which can be converted to MAGICCData to self. Parameters ---------- other : MAGICCData, pd.DataFrame, pd.Series, str Source of data to append. inplace : bool If True, append `...
[ "def", "append", "(", "self", ",", "other", ",", "inplace", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "other", ",", "MAGICCData", ")", ":", "other", "=", "MAGICCData", "(", "other", ",", "*", "*", "kwargs", ")...
Append any input which can be converted to MAGICCData to self. Parameters ---------- other : MAGICCData, pd.DataFrame, pd.Series, str Source of data to append. inplace : bool If True, append ``other`` inplace, otherwise return a new ``MAGICCData`` in...
[ "Append", "any", "input", "which", "can", "be", "converted", "to", "MAGICCData", "to", "self", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1973-L2001
openclimatedata/pymagicc
pymagicc/io.py
MAGICCData.write
def write(self, filepath, magicc_version): """ Write an input file to disk. Parameters ---------- filepath : str Filepath of the file to write. magicc_version : int The MAGICC version for which we want to write files. MAGICC7 and MAGICC6 ...
python
def write(self, filepath, magicc_version): """ Write an input file to disk. Parameters ---------- filepath : str Filepath of the file to write. magicc_version : int The MAGICC version for which we want to write files. MAGICC7 and MAGICC6 ...
[ "def", "write", "(", "self", ",", "filepath", ",", "magicc_version", ")", ":", "writer", "=", "determine_tool", "(", "filepath", ",", "\"writer\"", ")", "(", "magicc_version", "=", "magicc_version", ")", "writer", ".", "write", "(", "self", ",", "filepath", ...
Write an input file to disk. Parameters ---------- filepath : str Filepath of the file to write. magicc_version : int The MAGICC version for which we want to write files. MAGICC7 and MAGICC6 namelists are incompatible hence we need to know which one ...
[ "Write", "an", "input", "file", "to", "disk", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2003-L2018
productml/blurr
blurr/core/validator.py
validate_python_identifier_attributes
def validate_python_identifier_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[InvalidIdentifierError]: """ Validates a set of attributes as identifiers in a spec """ errors: List[InvalidIdentifierError] = [] checks: List[Tuple...
python
def validate_python_identifier_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[InvalidIdentifierError]: """ Validates a set of attributes as identifiers in a spec """ errors: List[InvalidIdentifierError] = [] checks: List[Tuple...
[ "def", "validate_python_identifier_attributes", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "*", "attributes", ":", "str", ")", "->", "List", "[", "InvalidIdentifierError", "]", ":", "errors", ":", "Li...
Validates a set of attributes as identifiers in a spec
[ "Validates", "a", "set", "of", "attributes", "as", "identifiers", "in", "a", "spec" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L11-L32
productml/blurr
blurr/core/validator.py
validate_required_attributes
def validate_required_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[RequiredAttributeError]: """ Validates to ensure that a set of attributes are present in spec """ return [ RequiredAttributeError(fully_qualified_name, spec, attri...
python
def validate_required_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[RequiredAttributeError]: """ Validates to ensure that a set of attributes are present in spec """ return [ RequiredAttributeError(fully_qualified_name, spec, attri...
[ "def", "validate_required_attributes", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "*", "attributes", ":", "str", ")", "->", "List", "[", "RequiredAttributeError", "]", ":", "return", "[", "RequiredAtt...
Validates to ensure that a set of attributes are present in spec
[ "Validates", "to", "ensure", "that", "a", "set", "of", "attributes", "are", "present", "in", "spec" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L35-L42
productml/blurr
blurr/core/validator.py
validate_empty_attributes
def validate_empty_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[EmptyAttributeError]: """ Validates to ensure that a set of attributes do not contain empty values """ return [ EmptyAttributeError(fully_qualified_name, spec, attribute...
python
def validate_empty_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[EmptyAttributeError]: """ Validates to ensure that a set of attributes do not contain empty values """ return [ EmptyAttributeError(fully_qualified_name, spec, attribute...
[ "def", "validate_empty_attributes", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "*", "attributes", ":", "str", ")", "->", "List", "[", "EmptyAttributeError", "]", ":", "return", "[", "EmptyAttributeErr...
Validates to ensure that a set of attributes do not contain empty values
[ "Validates", "to", "ensure", "that", "a", "set", "of", "attributes", "do", "not", "contain", "empty", "values" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L45-L52
productml/blurr
blurr/core/validator.py
validate_number_attribute
def validate_number_attribute( fully_qualified_name: str, spec: Dict[str, Any], attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] = None) -> Optional[InvalidNumberError]: ...
python
def validate_number_attribute( fully_qualified_name: str, spec: Dict[str, Any], attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] = None) -> Optional[InvalidNumberError]: ...
[ "def", "validate_number_attribute", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "attribute", ":", "str", ",", "value_type", ":", "Union", "[", "Type", "[", "int", "]", ",", "Type", "[", "float", ...
Validates to ensure that the value is a number of the specified type, and lies with the specified range
[ "Validates", "to", "ensure", "that", "the", "value", "is", "a", "number", "of", "the", "specified", "type", "and", "lies", "with", "the", "specified", "range" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L55-L73
productml/blurr
blurr/core/validator.py
validate_enum_attribute
def validate_enum_attribute(fully_qualified_name: str, spec: Dict[str, Any], attribute: str, candidates: Set[Union[str, int, float]]) -> Optional[InvalidValueError]: """ Validates to ensure that the value of an attribute lies within an allowed set of candidates """ if attribute not ...
python
def validate_enum_attribute(fully_qualified_name: str, spec: Dict[str, Any], attribute: str, candidates: Set[Union[str, int, float]]) -> Optional[InvalidValueError]: """ Validates to ensure that the value of an attribute lies within an allowed set of candidates """ if attribute not ...
[ "def", "validate_enum_attribute", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "attribute", ":", "str", ",", "candidates", ":", "Set", "[", "Union", "[", "str", ",", "int", ",", "float", "]", "]",...
Validates to ensure that the value of an attribute lies within an allowed set of candidates
[ "Validates", "to", "ensure", "that", "the", "value", "of", "an", "attribute", "lies", "within", "an", "allowed", "set", "of", "candidates" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L76-L84
productml/blurr
blurr/core/store_key.py
Key.parse
def parse(key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[3]: key_type = KeyType.TIMESTAMP return Key(key_type, parts[0], parts[1], parts[2].split(Key.DIMENSION...
python
def parse(key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[3]: key_type = KeyType.TIMESTAMP return Key(key_type, parts[0], parts[1], parts[2].split(Key.DIMENSION...
[ "def", "parse", "(", "key_string", ":", "str", ")", "->", "'Key'", ":", "parts", "=", "key_string", ".", "split", "(", "Key", ".", "PARTITION", ")", "key_type", "=", "KeyType", ".", "DIMENSION", "if", "parts", "[", "3", "]", ":", "key_type", "=", "Ke...
Parses a flat key string and returns a key
[ "Parses", "a", "flat", "key", "string", "and", "returns", "a", "key" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store_key.py#L62-L70
productml/blurr
blurr/core/store_key.py
Key.parse_sort_key
def parse_sort_key(identity: str, sort_key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = sort_key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[2]: key_type = KeyType.TIMESTAMP return Key(key_type, identity, part...
python
def parse_sort_key(identity: str, sort_key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = sort_key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[2]: key_type = KeyType.TIMESTAMP return Key(key_type, identity, part...
[ "def", "parse_sort_key", "(", "identity", ":", "str", ",", "sort_key_string", ":", "str", ")", "->", "'Key'", ":", "parts", "=", "sort_key_string", ".", "split", "(", "Key", ".", "PARTITION", ")", "key_type", "=", "KeyType", ".", "DIMENSION", "if", "parts"...
Parses a flat key string and returns a key
[ "Parses", "a", "flat", "key", "string", "and", "returns", "a", "key" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store_key.py#L73-L81
productml/blurr
blurr/core/store_key.py
Key.starts_with
def starts_with(self, other: 'Key') -> bool: """ Checks if this key starts with the other key provided. Returns False if key_type, identity or group are different. For `KeyType.TIMESTAMP` returns True. For `KeyType.DIMENSION` does prefix match between the two dimensions property....
python
def starts_with(self, other: 'Key') -> bool: """ Checks if this key starts with the other key provided. Returns False if key_type, identity or group are different. For `KeyType.TIMESTAMP` returns True. For `KeyType.DIMENSION` does prefix match between the two dimensions property....
[ "def", "starts_with", "(", "self", ",", "other", ":", "'Key'", ")", "->", "bool", ":", "if", "(", "self", ".", "key_type", ",", "self", ".", "identity", ",", "self", ".", "group", ")", "!=", "(", "other", ".", "key_type", ",", "other", ".", "identi...
Checks if this key starts with the other key provided. Returns False if key_type, identity or group are different. For `KeyType.TIMESTAMP` returns True. For `KeyType.DIMENSION` does prefix match between the two dimensions property.
[ "Checks", "if", "this", "key", "starts", "with", "the", "other", "key", "provided", ".", "Returns", "False", "if", "key_type", "identity", "or", "group", "are", "different", ".", "For", "KeyType", ".", "TIMESTAMP", "returns", "True", ".", "For", "KeyType", ...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store_key.py#L141-L156
productml/blurr
blurr/core/aggregate_identity.py
IdentityAggregate._evaluate_dimension_fields
def _evaluate_dimension_fields(self) -> bool: """ Evaluates the dimension fields. Returns False if any of the fields could not be evaluated. """ for _, item in self._dimension_fields.items(): item.run_evaluate() if item.eval_error: return False ...
python
def _evaluate_dimension_fields(self) -> bool: """ Evaluates the dimension fields. Returns False if any of the fields could not be evaluated. """ for _, item in self._dimension_fields.items(): item.run_evaluate() if item.eval_error: return False ...
[ "def", "_evaluate_dimension_fields", "(", "self", ")", "->", "bool", ":", "for", "_", ",", "item", "in", "self", ".", "_dimension_fields", ".", "items", "(", ")", ":", "item", ".", "run_evaluate", "(", ")", "if", "item", ".", "eval_error", ":", "return",...
Evaluates the dimension fields. Returns False if any of the fields could not be evaluated.
[ "Evaluates", "the", "dimension", "fields", ".", "Returns", "False", "if", "any", "of", "the", "fields", "could", "not", "be", "evaluated", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_identity.py#L85-L93
productml/blurr
blurr/core/aggregate_identity.py
IdentityAggregate._compare_dimensions_to_fields
def _compare_dimensions_to_fields(self) -> bool: """ Compares the dimension field values to the value in regular fields.""" for name, item in self._dimension_fields.items(): if item.value != self._nested_items[name].value: return False return True
python
def _compare_dimensions_to_fields(self) -> bool: """ Compares the dimension field values to the value in regular fields.""" for name, item in self._dimension_fields.items(): if item.value != self._nested_items[name].value: return False return True
[ "def", "_compare_dimensions_to_fields", "(", "self", ")", "->", "bool", ":", "for", "name", ",", "item", "in", "self", ".", "_dimension_fields", ".", "items", "(", ")", ":", "if", "item", ".", "value", "!=", "self", ".", "_nested_items", "[", "name", "]"...
Compares the dimension field values to the value in regular fields.
[ "Compares", "the", "dimension", "field", "values", "to", "the", "value", "in", "regular", "fields", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_identity.py#L95-L100
productml/blurr
blurr/core/aggregate_identity.py
IdentityAggregate._key
def _key(self): """ Generates the Key object based on dimension fields. """ return Key(self._schema.key_type, self._identity, self._name, [str(item.value) for item in self._dimension_fields.values()])
python
def _key(self): """ Generates the Key object based on dimension fields. """ return Key(self._schema.key_type, self._identity, self._name, [str(item.value) for item in self._dimension_fields.values()])
[ "def", "_key", "(", "self", ")", ":", "return", "Key", "(", "self", ".", "_schema", ".", "key_type", ",", "self", ".", "_identity", ",", "self", ".", "_name", ",", "[", "str", "(", "item", ".", "value", ")", "for", "item", "in", "self", ".", "_di...
Generates the Key object based on dimension fields.
[ "Generates", "the", "Key", "object", "based", "on", "dimension", "fields", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_identity.py#L103-L106
openclimatedata/pymagicc
pymagicc/__init__.py
run
def run(scenario, magicc_version=6, **kwargs): """ Run a MAGICC scenario and return output data and (optionally) config parameters. As a reminder, putting ``out_parameters=1`` will cause MAGICC to write out its parameters into ``out/PARAMETERS.OUT`` and they will then be read into ``output.metadata...
python
def run(scenario, magicc_version=6, **kwargs): """ Run a MAGICC scenario and return output data and (optionally) config parameters. As a reminder, putting ``out_parameters=1`` will cause MAGICC to write out its parameters into ``out/PARAMETERS.OUT`` and they will then be read into ``output.metadata...
[ "def", "run", "(", "scenario", ",", "magicc_version", "=", "6", ",", "*", "*", "kwargs", ")", ":", "if", "magicc_version", "==", "6", ":", "magicc_cls", "=", "MAGICC6", "elif", "magicc_version", "==", "7", ":", "magicc_cls", "=", "MAGICC7", "else", ":", ...
Run a MAGICC scenario and return output data and (optionally) config parameters. As a reminder, putting ``out_parameters=1`` will cause MAGICC to write out its parameters into ``out/PARAMETERS.OUT`` and they will then be read into ``output.metadata["parameters"]`` where ``output`` is the returned object. ...
[ "Run", "a", "MAGICC", "scenario", "and", "return", "output", "data", "and", "(", "optionally", ")", "config", "parameters", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/__init__.py#L37-L77
productml/blurr
blurr/core/transformer_window.py
WindowTransformer.run_evaluate
def run_evaluate(self, block: TimeAggregate) -> bool: """ Evaluates the anchor condition against the specified block. :param block: Block to run the anchor condition against. :return: True, if the anchor condition is met, otherwise, False. """ if self._anchor.evaluate_anc...
python
def run_evaluate(self, block: TimeAggregate) -> bool: """ Evaluates the anchor condition against the specified block. :param block: Block to run the anchor condition against. :return: True, if the anchor condition is met, otherwise, False. """ if self._anchor.evaluate_anc...
[ "def", "run_evaluate", "(", "self", ",", "block", ":", "TimeAggregate", ")", "->", "bool", ":", "if", "self", ".", "_anchor", ".", "evaluate_anchor", "(", "block", ",", "self", ".", "_evaluation_context", ")", ":", "try", ":", "self", ".", "run_reset", "...
Evaluates the anchor condition against the specified block. :param block: Block to run the anchor condition against. :return: True, if the anchor condition is met, otherwise, False.
[ "Evaluates", "the", "anchor", "condition", "against", "the", "specified", "block", ".", ":", "param", "block", ":", "Block", "to", "run", "the", "anchor", "condition", "against", ".", ":", "return", ":", "True", "if", "the", "anchor", "condition", "is", "m...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/transformer_window.py#L51-L68
productml/blurr
blurr/core/aggregate_time.py
TimeAggregateSchema.extend_schema_spec
def extend_schema_spec(self) -> None: """ Injects the block start and end times """ super().extend_schema_spec() if self.ATTRIBUTE_FIELDS in self._spec: # Add new fields to the schema spec. Since `_identity` is added by the super, new elements are added after predefined_...
python
def extend_schema_spec(self) -> None: """ Injects the block start and end times """ super().extend_schema_spec() if self.ATTRIBUTE_FIELDS in self._spec: # Add new fields to the schema spec. Since `_identity` is added by the super, new elements are added after predefined_...
[ "def", "extend_schema_spec", "(", "self", ")", "->", "None", ":", "super", "(", ")", ".", "extend_schema_spec", "(", ")", "if", "self", ".", "ATTRIBUTE_FIELDS", "in", "self", ".", "_spec", ":", "# Add new fields to the schema spec. Since `_identity` is added by the su...
Injects the block start and end times
[ "Injects", "the", "block", "start", "and", "end", "times" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_time.py#L12-L23
productml/blurr
blurr/core/aggregate_time.py
TimeAggregateSchema._build_time_fields_spec
def _build_time_fields_spec(name_in_context: str) -> List[Dict[str, Any]]: """ Constructs the spec for predefined fields that are to be included in the master spec prior to schema load :param name_in_context: Name of the current object in the context :return: """ return [...
python
def _build_time_fields_spec(name_in_context: str) -> List[Dict[str, Any]]: """ Constructs the spec for predefined fields that are to be included in the master spec prior to schema load :param name_in_context: Name of the current object in the context :return: """ return [...
[ "def", "_build_time_fields_spec", "(", "name_in_context", ":", "str", ")", "->", "List", "[", "Dict", "[", "str", ",", "Any", "]", "]", ":", "return", "[", "{", "'Name'", ":", "'_start_time'", ",", "'Type'", ":", "Type", ".", "DATETIME", ",", "'Value'", ...
Constructs the spec for predefined fields that are to be included in the master spec prior to schema load :param name_in_context: Name of the current object in the context :return:
[ "Constructs", "the", "spec", "for", "predefined", "fields", "that", "are", "to", "be", "included", "in", "the", "master", "spec", "prior", "to", "schema", "load", ":", "param", "name_in_context", ":", "Name", "of", "the", "current", "object", "in", "the", ...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_time.py#L26-L49
openclimatedata/pymagicc
pymagicc/utils.py
apply_string_substitutions
def apply_string_substitutions( inputs, substitutions, inverse=False, case_insensitive=False, unused_substitutions="ignore", ): """Apply a number of substitutions to a string(s). The substitutions are applied effectively all at once. This means that conflicting substitutions don't inter...
python
def apply_string_substitutions( inputs, substitutions, inverse=False, case_insensitive=False, unused_substitutions="ignore", ): """Apply a number of substitutions to a string(s). The substitutions are applied effectively all at once. This means that conflicting substitutions don't inter...
[ "def", "apply_string_substitutions", "(", "inputs", ",", "substitutions", ",", "inverse", "=", "False", ",", "case_insensitive", "=", "False", ",", "unused_substitutions", "=", "\"ignore\"", ",", ")", ":", "if", "inverse", ":", "substitutions", "=", "{", "v", ...
Apply a number of substitutions to a string(s). The substitutions are applied effectively all at once. This means that conflicting substitutions don't interact. Where substitutions are conflicting, the one which is longer takes precedance. This is confusing so we recommend that you look at the examples...
[ "Apply", "a", "number", "of", "substitutions", "to", "a", "string", "(", "s", ")", "." ]
train
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/utils.py#L82-L188
productml/blurr
blurr/core/store.py
Store.get_range
def get_range(self, base_key: Key, start_time: datetime, end_time: datetime = None, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. :param base_k...
python
def get_range(self, base_key: Key, start_time: datetime, end_time: datetime = None, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. :param base_k...
[ "def", "get_range", "(", "self", ",", "base_key", ":", "Key", ",", "start_time", ":", "datetime", ",", "end_time", ":", "datetime", "=", "None", ",", "count", ":", "int", "=", "0", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ...
Returns the list of items from the store based on the given time range or count. :param base_key: Items which don't start with the base_key are filtered out. :param start_time: Start time to for the range query :param end_time: End time of the range query. If None count is used. :param c...
[ "Returns", "the", "list", "of", "items", "from", "the", "store", "based", "on", "the", "given", "time", "range", "or", "count", ".", ":", "param", "base_key", ":", "Items", "which", "don", "t", "start", "with", "the", "base_key", "are", "filtered", "out"...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L30-L60
productml/blurr
blurr/core/store.py
Store._get_range_timestamp_key
def _get_range_timestamp_key(self, start: Key, end: Key, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. This is used when the key being used is a TIMESTAMP key. """ r...
python
def _get_range_timestamp_key(self, start: Key, end: Key, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. This is used when the key being used is a TIMESTAMP key. """ r...
[ "def", "_get_range_timestamp_key", "(", "self", ",", "start", ":", "Key", ",", "end", ":", "Key", ",", "count", ":", "int", "=", "0", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ":", "raise", "NotImplementedError", "(", ")" ]
Returns the list of items from the store based on the given time range or count. This is used when the key being used is a TIMESTAMP key.
[ "Returns", "the", "list", "of", "items", "from", "the", "store", "based", "on", "the", "given", "time", "range", "or", "count", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L63-L70
productml/blurr
blurr/core/store.py
Store._get_range_dimension_key
def _get_range_dimension_key(self, base_key: Key, start_time: datetime, end_time: datetime, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the...
python
def _get_range_dimension_key(self, base_key: Key, start_time: datetime, end_time: datetime, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the...
[ "def", "_get_range_dimension_key", "(", "self", ",", "base_key", ":", "Key", ",", "start_time", ":", "datetime", ",", "end_time", ":", "datetime", ",", "count", ":", "int", "=", "0", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ...
Returns the list of items from the store based on the given time range or count. This is used when the key being used is a DIMENSION key.
[ "Returns", "the", "list", "of", "items", "from", "the", "store", "based", "on", "the", "given", "time", "range", "or", "count", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L79-L89
productml/blurr
blurr/core/store.py
Store._restrict_items_to_count
def _restrict_items_to_count(items: List[Tuple[Key, Any]], count: int) -> List[Tuple[Key, Any]]: """ Restricts items to count number if len(items) is larger than abs(count). This function assumes that items is sorted by time. :param items: The items to restrict. :param count: Th...
python
def _restrict_items_to_count(items: List[Tuple[Key, Any]], count: int) -> List[Tuple[Key, Any]]: """ Restricts items to count number if len(items) is larger than abs(count). This function assumes that items is sorted by time. :param items: The items to restrict. :param count: Th...
[ "def", "_restrict_items_to_count", "(", "items", ":", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ",", "count", ":", "int", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ":", "if", "abs", "(", "count", ")", ">", ...
Restricts items to count number if len(items) is larger than abs(count). This function assumes that items is sorted by time. :param items: The items to restrict. :param count: The number of items returned.
[ "Restricts", "items", "to", "count", "number", "if", "len", "(", "items", ")", "is", "larger", "than", "abs", "(", "count", ")", ".", "This", "function", "assumes", "that", "items", "is", "sorted", "by", "time", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L92-L106
productml/blurr
blurr/core/base.py
BaseSchema.build_expression
def build_expression(self, attribute: str) -> Optional[Expression]: """ Builds an expression object. Adds an error if expression creation has errors. """ expression_string = self._spec.get(attribute, None) if expression_string: try: return Expression(str(expression_...
python
def build_expression(self, attribute: str) -> Optional[Expression]: """ Builds an expression object. Adds an error if expression creation has errors. """ expression_string = self._spec.get(attribute, None) if expression_string: try: return Expression(str(expression_...
[ "def", "build_expression", "(", "self", ",", "attribute", ":", "str", ")", "->", "Optional", "[", "Expression", "]", ":", "expression_string", "=", "self", ".", "_spec", ".", "get", "(", "attribute", ",", "None", ")", "if", "expression_string", ":", "try",...
Builds an expression object. Adds an error if expression creation has errors.
[ "Builds", "an", "expression", "object", ".", "Adds", "an", "error", "if", "expression", "creation", "has", "errors", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L41-L52
productml/blurr
blurr/core/base.py
BaseSchema.add_errors
def add_errors(self, *errors: Union[BaseSchemaError, List[BaseSchemaError]]) -> None: """ Adds errors to the error repository in schema loader """ self.schema_loader.add_errors(*errors)
python
def add_errors(self, *errors: Union[BaseSchemaError, List[BaseSchemaError]]) -> None: """ Adds errors to the error repository in schema loader """ self.schema_loader.add_errors(*errors)
[ "def", "add_errors", "(", "self", ",", "*", "errors", ":", "Union", "[", "BaseSchemaError", ",", "List", "[", "BaseSchemaError", "]", "]", ")", "->", "None", ":", "self", ".", "schema_loader", ".", "add_errors", "(", "*", "errors", ")" ]
Adds errors to the error repository in schema loader
[ "Adds", "errors", "to", "the", "error", "repository", "in", "schema", "loader" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L54-L56
productml/blurr
blurr/core/base.py
BaseSchema.validate_required_attributes
def validate_required_attributes(self, *attributes: str) -> None: """ Validates that the schema contains a series of required attributes """ self.add_errors( validate_required_attributes(self.fully_qualified_name, self._spec, *attributes))
python
def validate_required_attributes(self, *attributes: str) -> None: """ Validates that the schema contains a series of required attributes """ self.add_errors( validate_required_attributes(self.fully_qualified_name, self._spec, *attributes))
[ "def", "validate_required_attributes", "(", "self", ",", "*", "attributes", ":", "str", ")", "->", "None", ":", "self", ".", "add_errors", "(", "validate_required_attributes", "(", "self", ".", "fully_qualified_name", ",", "self", ".", "_spec", ",", "*", "attr...
Validates that the schema contains a series of required attributes
[ "Validates", "that", "the", "schema", "contains", "a", "series", "of", "required", "attributes" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L63-L66
productml/blurr
blurr/core/base.py
BaseSchema.validate_number_attribute
def validate_number_attribute(self, attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] =...
python
def validate_number_attribute(self, attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] =...
[ "def", "validate_number_attribute", "(", "self", ",", "attribute", ":", "str", ",", "value_type", ":", "Union", "[", "Type", "[", "int", "]", ",", "Type", "[", "float", "]", "]", "=", "int", ",", "minimum", ":", "Optional", "[", "Union", "[", "int", ...
Validates that the attribute contains a numeric value within boundaries if specified
[ "Validates", "that", "the", "attribute", "contains", "a", "numeric", "value", "within", "boundaries", "if", "specified" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L68-L76
productml/blurr
blurr/core/base.py
BaseSchema.validate_enum_attribute
def validate_enum_attribute(self, attribute: str, candidates: Set[Union[str, int, float]]) -> None: """ Validates that the attribute value is among the candidates """ self.add_errors( validate_enum_attribute(self.fully_qualified_name, self._spec, attribute, ca...
python
def validate_enum_attribute(self, attribute: str, candidates: Set[Union[str, int, float]]) -> None: """ Validates that the attribute value is among the candidates """ self.add_errors( validate_enum_attribute(self.fully_qualified_name, self._spec, attribute, ca...
[ "def", "validate_enum_attribute", "(", "self", ",", "attribute", ":", "str", ",", "candidates", ":", "Set", "[", "Union", "[", "str", ",", "int", ",", "float", "]", "]", ")", "->", "None", ":", "self", ".", "add_errors", "(", "validate_enum_attribute", "...
Validates that the attribute value is among the candidates
[ "Validates", "that", "the", "attribute", "value", "is", "among", "the", "candidates" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L78-L82
productml/blurr
blurr/core/base.py
BaseSchema.validate_schema_spec
def validate_schema_spec(self) -> None: """ Contains the validation routines that are to be executed as part of initialization by subclasses. When this method is being extended, the first line should always be: ```super().validate_schema_spec()``` """ self.add_errors( validate_empty_...
python
def validate_schema_spec(self) -> None: """ Contains the validation routines that are to be executed as part of initialization by subclasses. When this method is being extended, the first line should always be: ```super().validate_schema_spec()``` """ self.add_errors( validate_empty_...
[ "def", "validate_schema_spec", "(", "self", ")", "->", "None", ":", "self", ".", "add_errors", "(", "validate_empty_attributes", "(", "self", ".", "fully_qualified_name", ",", "self", ".", "_spec", ",", "*", "self", ".", "_spec", ".", "keys", "(", ")", ")"...
Contains the validation routines that are to be executed as part of initialization by subclasses. When this method is being extended, the first line should always be: ```super().validate_schema_spec()```
[ "Contains", "the", "validation", "routines", "that", "are", "to", "be", "executed", "as", "part", "of", "initialization", "by", "subclasses", ".", "When", "this", "method", "is", "being", "extended", "the", "first", "line", "should", "always", "be", ":", "su...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L84-L91
productml/blurr
blurr/core/base.py
BaseItem._needs_evaluation
def _needs_evaluation(self) -> bool: """ Returns True when: 1. Where clause is not specified 2. Where WHERE clause is specified and it evaluates to True Returns false if a where clause is specified and it evaluates to False """ return self._schema.when is ...
python
def _needs_evaluation(self) -> bool: """ Returns True when: 1. Where clause is not specified 2. Where WHERE clause is specified and it evaluates to True Returns false if a where clause is specified and it evaluates to False """ return self._schema.when is ...
[ "def", "_needs_evaluation", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_schema", ".", "when", "is", "None", "or", "self", ".", "_schema", ".", "when", ".", "evaluate", "(", "self", ".", "_evaluation_context", ")" ]
Returns True when: 1. Where clause is not specified 2. Where WHERE clause is specified and it evaluates to True Returns false if a where clause is specified and it evaluates to False
[ "Returns", "True", "when", ":", "1", ".", "Where", "clause", "is", "not", "specified", "2", ".", "Where", "WHERE", "clause", "is", "specified", "and", "it", "evaluates", "to", "True", "Returns", "false", "if", "a", "where", "clause", "is", "specified", "...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L147-L154
productml/blurr
blurr/core/base.py
BaseItemCollection.run_evaluate
def run_evaluate(self, *args, **kwargs) -> None: """ Evaluates the current item :returns An evaluation result object containing the result, or reasons why evaluation failed """ if self._needs_evaluation: for _, item in self._nested_items.items(): ...
python
def run_evaluate(self, *args, **kwargs) -> None: """ Evaluates the current item :returns An evaluation result object containing the result, or reasons why evaluation failed """ if self._needs_evaluation: for _, item in self._nested_items.items(): ...
[ "def", "run_evaluate", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "self", ".", "_needs_evaluation", ":", "for", "_", ",", "item", "in", "self", ".", "_nested_items", ".", "items", "(", ")", ":", "item", "....
Evaluates the current item :returns An evaluation result object containing the result, or reasons why evaluation failed
[ "Evaluates", "the", "current", "item", ":", "returns", "An", "evaluation", "result", "object", "containing", "the", "result", "or", "reasons", "why", "evaluation", "failed" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L208-L216
productml/blurr
blurr/core/base.py
BaseItemCollection._snapshot
def _snapshot(self) -> Dict[str, Any]: """ Implements snapshot for collections by recursively invoking snapshot of all child items """ try: return {name: item._snapshot for name, item in self._nested_items.items()} except Exception as e: raise SnapshotErro...
python
def _snapshot(self) -> Dict[str, Any]: """ Implements snapshot for collections by recursively invoking snapshot of all child items """ try: return {name: item._snapshot for name, item in self._nested_items.items()} except Exception as e: raise SnapshotErro...
[ "def", "_snapshot", "(", "self", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "try", ":", "return", "{", "name", ":", "item", ".", "_snapshot", "for", "name", ",", "item", "in", "self", ".", "_nested_items", ".", "items", "(", ")", "}", "...
Implements snapshot for collections by recursively invoking snapshot of all child items
[ "Implements", "snapshot", "for", "collections", "by", "recursively", "invoking", "snapshot", "of", "all", "child", "items" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L219-L226
productml/blurr
blurr/core/base.py
BaseItemCollection.run_restore
def run_restore(self, snapshot: Dict[Union[str, Key], Any]) -> 'BaseItemCollection': """ Restores the state of a collection from a snapshot """ try: for name, snap in snapshot.items(): if isinstance(name, Key): self._nested_items[name.grou...
python
def run_restore(self, snapshot: Dict[Union[str, Key], Any]) -> 'BaseItemCollection': """ Restores the state of a collection from a snapshot """ try: for name, snap in snapshot.items(): if isinstance(name, Key): self._nested_items[name.grou...
[ "def", "run_restore", "(", "self", ",", "snapshot", ":", "Dict", "[", "Union", "[", "str", ",", "Key", "]", ",", "Any", "]", ")", "->", "'BaseItemCollection'", ":", "try", ":", "for", "name", ",", "snap", "in", "snapshot", ".", "items", "(", ")", "...
Restores the state of a collection from a snapshot
[ "Restores", "the", "state", "of", "a", "collection", "from", "a", "snapshot" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L228-L242
productml/blurr
blurr/core/aggregate_window.py
WindowAggregate._prepare_window
def _prepare_window(self, start_time: datetime) -> None: """ Prepares window if any is specified. :param start_time: The anchor block start_time from where the window should be generated. """ # evaluate window first which sets the correct window in the store store...
python
def _prepare_window(self, start_time: datetime) -> None: """ Prepares window if any is specified. :param start_time: The anchor block start_time from where the window should be generated. """ # evaluate window first which sets the correct window in the store store...
[ "def", "_prepare_window", "(", "self", ",", "start_time", ":", "datetime", ")", "->", "None", ":", "# evaluate window first which sets the correct window in the store", "store", "=", "self", ".", "_schema", ".", "schema_loader", ".", "get_store", "(", "self", ".", "...
Prepares window if any is specified. :param start_time: The anchor block start_time from where the window should be generated.
[ "Prepares", "window", "if", "any", "is", "specified", ".", ":", "param", "start_time", ":", "The", "anchor", "block", "start_time", "from", "where", "the", "window", "should", "be", "generated", "." ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_window.py#L60-L82
productml/blurr
blurr/core/aggregate_window.py
WindowAggregate._get_end_time
def _get_end_time(self, start_time: datetime) -> datetime: """ Generates the end time to be used for the store range query. :param start_time: Start time to use as an offset to calculate the end time based on the window type in the schema. :return: """ if Type.is_...
python
def _get_end_time(self, start_time: datetime) -> datetime: """ Generates the end time to be used for the store range query. :param start_time: Start time to use as an offset to calculate the end time based on the window type in the schema. :return: """ if Type.is_...
[ "def", "_get_end_time", "(", "self", ",", "start_time", ":", "datetime", ")", "->", "datetime", ":", "if", "Type", ".", "is_type_equal", "(", "self", ".", "_schema", ".", "window_type", ",", "Type", ".", "DAY", ")", ":", "return", "start_time", "+", "tim...
Generates the end time to be used for the store range query. :param start_time: Start time to use as an offset to calculate the end time based on the window type in the schema. :return:
[ "Generates", "the", "end", "time", "to", "be", "used", "for", "the", "store", "range", "query", ".", ":", "param", "start_time", ":", "Start", "time", "to", "use", "as", "an", "offset", "to", "calculate", "the", "end", "time", "based", "on", "the", "wi...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_window.py#L100-L110
productml/blurr
blurr/core/aggregate_window.py
WindowAggregate._load_blocks
def _load_blocks(self, blocks: List[Tuple[Key, Any]]) -> List[TimeAggregate]: """ Converts [(Key, block)] to [BlockAggregate] :param blocks: List of (Key, block) blocks. :return: List of BlockAggregate """ return [ TypeLoader.load_item(self._schema.source.type...
python
def _load_blocks(self, blocks: List[Tuple[Key, Any]]) -> List[TimeAggregate]: """ Converts [(Key, block)] to [BlockAggregate] :param blocks: List of (Key, block) blocks. :return: List of BlockAggregate """ return [ TypeLoader.load_item(self._schema.source.type...
[ "def", "_load_blocks", "(", "self", ",", "blocks", ":", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ")", "->", "List", "[", "TimeAggregate", "]", ":", "return", "[", "TypeLoader", ".", "load_item", "(", "self", ".", "_schema", ".", "sourc...
Converts [(Key, block)] to [BlockAggregate] :param blocks: List of (Key, block) blocks. :return: List of BlockAggregate
[ "Converts", "[", "(", "Key", "block", ")", "]", "to", "[", "BlockAggregate", "]", ":", "param", "blocks", ":", "List", "of", "(", "Key", "block", ")", "blocks", ".", ":", "return", ":", "List", "of", "BlockAggregate" ]
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_window.py#L112-L122
productml/blurr
blurr/runner/runner.py
Runner.execute_per_identity_records
def execute_per_identity_records( self, identity: str, records: List[TimeAndRecord], old_state: Optional[Dict[Key, Any]] = None) -> Tuple[str, Tuple[Dict, List]]: """ Executes the streaming and window BTS on the given records. An option old state can provi...
python
def execute_per_identity_records( self, identity: str, records: List[TimeAndRecord], old_state: Optional[Dict[Key, Any]] = None) -> Tuple[str, Tuple[Dict, List]]: """ Executes the streaming and window BTS on the given records. An option old state can provi...
[ "def", "execute_per_identity_records", "(", "self", ",", "identity", ":", "str", ",", "records", ":", "List", "[", "TimeAndRecord", "]", ",", "old_state", ":", "Optional", "[", "Dict", "[", "Key", ",", "Any", "]", "]", "=", "None", ")", "->", "Tuple", ...
Executes the streaming and window BTS on the given records. An option old state can provided which initializes the state for execution. This is useful for batch execution where the previous state is written out to storage and can be loaded for the next batch run. :param identity: Identity of th...
[ "Executes", "the", "streaming", "and", "window", "BTS", "on", "the", "given", "records", ".", "An", "option", "old", "state", "can", "provided", "which", "initializes", "the", "state", "for", "execution", ".", "This", "is", "useful", "for", "batch", "executi...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/runner/runner.py#L55-L80
productml/blurr
blurr/runner/runner.py
Runner.get_per_identity_records
def get_per_identity_records(self, events: Iterable, data_processor: DataProcessor ) -> Generator[Tuple[str, TimeAndRecord], None, None]: """ Uses the given iteratable events and the data processor convert the event into a list of Records along with its identity ...
python
def get_per_identity_records(self, events: Iterable, data_processor: DataProcessor ) -> Generator[Tuple[str, TimeAndRecord], None, None]: """ Uses the given iteratable events and the data processor convert the event into a list of Records along with its identity ...
[ "def", "get_per_identity_records", "(", "self", ",", "events", ":", "Iterable", ",", "data_processor", ":", "DataProcessor", ")", "->", "Generator", "[", "Tuple", "[", "str", ",", "TimeAndRecord", "]", ",", "None", ",", "None", "]", ":", "schema_loader", "="...
Uses the given iteratable events and the data processor convert the event into a list of Records along with its identity and time. :param events: iteratable events. :param data_processor: DataProcessor to process each event in events. :return: yields Tuple[Identity, TimeAndRecord] for al...
[ "Uses", "the", "given", "iteratable", "events", "and", "the", "data", "processor", "convert", "the", "event", "into", "a", "list", "of", "Records", "along", "with", "its", "identity", "and", "time", ".", ":", "param", "events", ":", "iteratable", "events", ...
train
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/runner/runner.py#L82-L105
svinota/mdns
mdns/zeroconf.py
DNSEntry.to_string
def to_string(self, hdr, other): """String representation with additional information""" result = "%s[%s,%s" % ( hdr, self.get_type(self.type), self.get_clazz(self.clazz)) if self.unique: result += "-unique," else: result += "," result += s...
python
def to_string(self, hdr, other): """String representation with additional information""" result = "%s[%s,%s" % ( hdr, self.get_type(self.type), self.get_clazz(self.clazz)) if self.unique: result += "-unique," else: result += "," result += s...
[ "def", "to_string", "(", "self", ",", "hdr", ",", "other", ")", ":", "result", "=", "\"%s[%s,%s\"", "%", "(", "hdr", ",", "self", ".", "get_type", "(", "self", ".", "type", ")", ",", "self", ".", "get_clazz", "(", "self", ".", "clazz", ")", ")", ...
String representation with additional information
[ "String", "representation", "with", "additional", "information" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L342-L355
svinota/mdns
mdns/zeroconf.py
DNSQuestion.answered_by
def answered_by(self, rec): """Returns true if the question is answered by the record""" return self.clazz == rec.clazz and \ (self.type == rec.type or self.type == _TYPE_ANY) and \ self.name == rec.name
python
def answered_by(self, rec): """Returns true if the question is answered by the record""" return self.clazz == rec.clazz and \ (self.type == rec.type or self.type == _TYPE_ANY) and \ self.name == rec.name
[ "def", "answered_by", "(", "self", ",", "rec", ")", ":", "return", "self", ".", "clazz", "==", "rec", ".", "clazz", "and", "(", "self", ".", "type", "==", "rec", ".", "type", "or", "self", ".", "type", "==", "_TYPE_ANY", ")", "and", "self", ".", ...
Returns true if the question is answered by the record
[ "Returns", "true", "if", "the", "question", "is", "answered", "by", "the", "record" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L370-L374
svinota/mdns
mdns/zeroconf.py
DNSRecord.reset_ttl
def reset_ttl(self, other): """Sets this record's TTL and created time to that of another record.""" self.created = other.created self.ttl = other.ttl
python
def reset_ttl(self, other): """Sets this record's TTL and created time to that of another record.""" self.created = other.created self.ttl = other.ttl
[ "def", "reset_ttl", "(", "self", ",", "other", ")", ":", "self", ".", "created", "=", "other", ".", "created", "self", ".", "ttl", "=", "other", ".", "ttl" ]
Sets this record's TTL and created time to that of another record.
[ "Sets", "this", "record", "s", "TTL", "and", "created", "time", "to", "that", "of", "another", "record", "." ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L425-L429
svinota/mdns
mdns/zeroconf.py
DNSRecord.to_string
def to_string(self, other): """String representation with addtional information""" arg = "%s/%s,%s" % ( self.ttl, self.get_remaining_ttl(current_time_millis()), other) return DNSEntry.to_string(self, "record", arg)
python
def to_string(self, other): """String representation with addtional information""" arg = "%s/%s,%s" % ( self.ttl, self.get_remaining_ttl(current_time_millis()), other) return DNSEntry.to_string(self, "record", arg)
[ "def", "to_string", "(", "self", ",", "other", ")", ":", "arg", "=", "\"%s/%s,%s\"", "%", "(", "self", ".", "ttl", ",", "self", ".", "get_remaining_ttl", "(", "current_time_millis", "(", ")", ")", ",", "other", ")", "return", "DNSEntry", ".", "to_string"...
String representation with addtional information
[ "String", "representation", "with", "addtional", "information" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L435-L439
svinota/mdns
mdns/zeroconf.py
DNSAddress.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.address, len(self.address))
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.address, len(self.address))
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_string", "(", "self", ".", "address", ",", "len", "(", "self", ".", "address", ")", ")" ]
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L528-L530
svinota/mdns
mdns/zeroconf.py
DNSHinfo.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.cpu, len(self.cpu)) out.write_string(self.os, len(self.os))
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.cpu, len(self.cpu)) out.write_string(self.os, len(self.os))
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_string", "(", "self", ".", "cpu", ",", "len", "(", "self", ".", "cpu", ")", ")", "out", ".", "write_string", "(", "self", ".", "os", ",", "len", "(", "self", ".", "os", ")", ...
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L568-L571
svinota/mdns
mdns/zeroconf.py
DNSText.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.text, len(self.text))
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.text, len(self.text))
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_string", "(", "self", ".", "text", ",", "len", "(", "self", ".", "text", ")", ")" ]
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L620-L622
svinota/mdns
mdns/zeroconf.py
DNSText.set_property
def set_property(self, key, value): """ Update only one property in the dict """ self.properties[key] = value self.sync_properties()
python
def set_property(self, key, value): """ Update only one property in the dict """ self.properties[key] = value self.sync_properties()
[ "def", "set_property", "(", "self", ",", "key", ",", "value", ")", ":", "self", ".", "properties", "[", "key", "]", "=", "value", "self", ".", "sync_properties", "(", ")" ]
Update only one property in the dict
[ "Update", "only", "one", "property", "in", "the", "dict" ]
train
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L624-L629