code
stringlengths 51
2.34k
| sequence
stringlengths 1.16k
13.1k
| docstring
stringlengths 11
171
|
|---|---|---|
def _no_spelling_errors(relative_path, contents, linter_options):
block_regexps = linter_options.get("block_regexps", None)
chunks, shadow = spellcheckable_and_shadow_contents(contents,
block_regexps)
cache = linter_options.get("spellcheck_cache", None)
user_words, valid_words = valid_words_dictionary_helper.create(cache)
technical_words = _create_technical_words_dictionary(cache,
relative_path,
user_words,
shadow)
if linter_options.get("log_technical_terms_to"):
linter_options["log_technical_terms_to"].put(technical_words.words())
return [e for e in _find_spelling_errors_in_chunks(chunks,
contents,
valid_words,
technical_words,
user_words) if e]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_no_spelling_errors'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'relative_path'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'linter_options'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '28', '38', '49', '59', '80']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'block_regexps'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'linter_options'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"block_regexps"'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'shadow'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'spellcheckable_and_shadow_contents'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'block_regexps'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'linter_options'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"spellcheck_cache"'}; {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'user_words'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'valid_words'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'valid_words_dictionary_helper'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'technical_words'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '_create_technical_words_dictionary'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57', '58']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'relative_path'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'user_words'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'shadow'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '66']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'linter_options'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'string', 'children': [], 'value': '"log_technical_terms_to"'}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '74']}; {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'linter_options'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"log_technical_terms_to"'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'technical_words'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'list_comprehension', 'children': ['82', '83', '93']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_find_spelling_errors_in_chunks'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89', '90', '91', '92']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'valid_words'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'technical_words'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'user_words'}; {'id': '93', 'type': 'if_clause', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'e'}
|
No spelling errors in strings, comments or anything of the like.
|
def clear(self, *resource_types):
resource_types = resource_types or tuple(self.__caches.keys())
for cls in resource_types:
self.__caches[cls].clear()
del self.__caches[cls]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clear'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'resource_types'}; {'id': '7', 'type': 'block', 'children': ['8', '23']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'resource_types'}; {'id': '11', 'type': 'boolean_operator', 'children': ['12', '13'], 'value': 'or'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'resource_types'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}; {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__caches'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'resource_types'}; {'id': '26', 'type': 'block', 'children': ['27', '37']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '36']}; {'id': '29', 'type': 'attribute', 'children': ['30', '35']}; {'id': '30', 'type': 'subscript', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '__caches'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'clear'}; {'id': '36', 'type': 'argument_list', 'children': []}; {'id': '37', 'type': 'delete_statement', 'children': ['38']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '__caches'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cls'}
|
Clear cache for each provided APIResource class, or all resources if no classes are provided
|
def _load_from_geo_ref(self, dsid):
file_handlers = self._get_file_handlers(dsid)
if not file_handlers:
return None
fns = []
for fh in file_handlers:
base_dir = os.path.dirname(fh.filename)
try:
fn = fh['/attr/N_GEO_Ref'][:46] + '*.h5'
fns.extend(glob(os.path.join(base_dir, fn)))
if fn[:5] == 'GIMGO':
fn = 'GITCO' + fn[5:]
elif fn[:5] == 'GMODO':
fn = 'GMTCO' + fn[5:]
else:
continue
fns.extend(glob(os.path.join(base_dir, fn)))
except KeyError:
LOG.debug("Could not load geo-reference information from {}".format(fh.filename))
return fns
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_load_from_geo_ref'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dsid'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '22', '26', '151']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'file_handlers'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '_get_file_handlers'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dsid'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '19']}; {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'file_handlers'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'file_handlers'}; {'id': '29', 'type': 'block', 'children': ['30', '43']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '43', 'type': 'try_statement', 'children': ['44', '134']}; {'id': '44', 'type': 'block', 'children': ['45', '57', '75', '116']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '56'], 'value': '+'}; {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'/attr/N_GEO_Ref'"}; {'id': '53', 'type': 'slice', 'children': ['54', '55']}; {'id': '54', 'type': 'colon', 'children': []}; {'id': '55', 'type': 'integer', 'children': [], 'value': '46'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'*.h5'"}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '75', 'type': 'if_statement', 'children': ['76', '83', '94', '113']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '82'], 'value': '=='}; {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '79', 'type': 'slice', 'children': ['80', '81']}; {'id': '80', 'type': 'colon', 'children': []}; {'id': '81', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'GIMGO'"}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'GITCO'"}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '91', 'type': 'slice', 'children': ['92', '93']}; {'id': '92', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '93', 'type': 'colon', 'children': []}; {'id': '94', 'type': 'elif_clause', 'children': ['95', '102']}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '101'], 'value': '=='}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '98', 'type': 'slice', 'children': ['99', '100']}; {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'GMODO'"}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'GMTCO'"}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '110', 'type': 'slice', 'children': ['111', '112']}; {'id': '111', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '112', 'type': 'colon', 'children': []}; {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'continue_statement', 'children': []}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '131']}; {'id': '126', 'type': 'attribute', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '134', 'type': 'except_clause', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'LOG'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'string', 'children': [], 'value': '"Could not load geo-reference information from {}"'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'fns'}
|
Load filenames from the N_GEO_Ref attribute of a dataset's file.
|
def input(self, request, tag):
subform = self.parameter.form.asSubForm(self.parameter.name)
subform.setFragmentParent(self)
return tag[subform]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'input'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '7', 'type': 'block', 'children': ['8', '25', '32']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'subform'}; {'id': '11', 'type': 'call', 'children': ['12', '19']}; {'id': '12', 'type': 'attribute', 'children': ['13', '18']}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'asSubForm'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'subform'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'setFragmentParent'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'subform'}
|
Add the wrapped form, as a subform, as a child of the given tag.
|
def surface2image(surface):
global g_lock
with g_lock:
img_io = io.BytesIO()
surface.write_to_png(img_io)
img_io.seek(0)
img = PIL.Image.open(img_io)
img.load()
if "A" not in img.getbands():
return img
img_no_alpha = PIL.Image.new("RGB", img.size, (255, 255, 255))
img_no_alpha.paste(img, mask=img.split()[3])
return img_no_alpha
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'surface2image'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'surface'}; {'id': '5', 'type': 'block', 'children': ['6', '8']}; {'id': '6', 'type': 'global_statement', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'g_lock'}; {'id': '8', 'type': 'with_statement', 'children': ['9', '12']}; {'id': '9', 'type': 'with_clause', 'children': ['10']}; {'id': '10', 'type': 'with_item', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'g_lock'}; {'id': '12', 'type': 'block', 'children': ['13', '21', '28', '35', '46', '52', '63', '81', '97']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'img_io'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'BytesIO'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'surface'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'write_to_png'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'img_io'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'img_io'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'PIL'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Image'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'img_io'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'if_statement', 'children': ['53', '60']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'not in'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"A"'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'getbands'}; {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'img_no_alpha'}; {'id': '66', 'type': 'call', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'PIL'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Image'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '77']}; {'id': '73', 'type': 'string', 'children': [], 'value': '"RGB"'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '77', 'type': 'tuple', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'img_no_alpha'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'paste'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '90', 'type': 'subscript', 'children': ['91', '96']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '97', 'type': 'return_statement', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'img_no_alpha'}
|
Convert a cairo surface into a PIL image
|
def print_runs(query):
if query is None:
return
for tup in query:
print(("{0} @ {1} - {2} id: {3} group: {4}".format(
tup.end, tup.experiment_name, tup.project_name,
tup.experiment_group, tup.run_group)))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_runs'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '5', 'type': 'block', 'children': ['6', '12']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': '()', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': '"{0} @ {1} - {2} id: {3} group: {4}"'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '29', '32', '35', '38']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'experiment_name'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'project_name'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'experiment_group'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'run_group'}
|
Print all rows in this result query.
|
def ports(self) -> dict:
return {
param: self[param].raw
for param in self
if param.startswith(IOPORT)
}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ports'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}; {'id': '9', 'type': 'dictionary_comprehension', 'children': ['10', '17', '20']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'raw'}; {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'if_clause', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'IOPORT'}
|
Create a smaller dictionary containing all ports.
|
def component_div(vec1, vec2):
new_vec = Vector2()
new_vec.X = vec1.X / vec2.X
new_vec.Y = vec1.Y / vec2.Y
return new_vec
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'component_div'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vec1'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '25', '37']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'new_vec'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Vector2'}; {'id': '12', 'type': 'argument_list', 'children': []}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'new_vec'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '/'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'vec1'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'new_vec'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '34'], 'value': '/'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'vec1'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'new_vec'}
|
Divide the components of the vectors and return the result.
|
def _update_feature_log_prob(self, alpha):
smoothed_fc = self.feature_count_ + alpha
smoothed_cc = self.class_count_ + alpha * 2
self.feature_log_prob_ = (np.log(smoothed_fc) -
np.log(smoothed_cc.reshape(-1, 1)))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_feature_log_prob'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '25']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'smoothed_fc'}; {'id': '10', 'type': 'binary_operator', 'children': ['11', '14'], 'value': '+'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'feature_count_'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'smoothed_cc'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '+'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'class_count_'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '*'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'feature_log_prob_'}; {'id': '30', 'type': '()', 'children': ['31']}; {'id': '31', 'type': 'binary_operator', 'children': ['32', '38'], 'value': '-'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'smoothed_fc'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'smoothed_cc'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '50']}; {'id': '48', 'type': 'unary_operator', 'children': ['49'], 'value': '-'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}
|
Apply smoothing to raw counts and recompute log probabilities
|
def _find_subnets(subnet_name=None, vpc_id=None, cidr=None, tags=None, conn=None):
if not any([subnet_name, tags, cidr]):
raise SaltInvocationError('At least one of the following must be '
'specified: subnet_name, cidr or tags.')
filter_parameters = {'filters': {}}
if cidr:
filter_parameters['filters']['cidr'] = cidr
if subnet_name:
filter_parameters['filters']['tag:Name'] = subnet_name
if vpc_id:
filter_parameters['filters']['VpcId'] = vpc_id
if tags:
for tag_name, tag_value in six.iteritems(tags):
filter_parameters['filters']['tag:{0}'.format(tag_name)] = tag_value
subnets = conn.get_all_subnets(**filter_parameters)
log.debug('The filters criteria %s matched the following subnets: %s',
filter_parameters, subnets)
if subnets:
return [subnet.id for subnet in subnets]
else:
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_subnets'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'subnet_name'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'vpc_id'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'cidr'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20', '37', '44', '55', '66', '77', '104', '114', '123']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '29']}; {'id': '21', 'type': 'not_operator', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'list', 'children': ['26', '27', '28'], 'value': '[subnet_name, tags, cidr]'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'subnet_name'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'cidr'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'raise_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'SaltInvocationError'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'concatenated_string', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'At least one of the following must be '"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'specified: subnet_name, cidr or tags.'"}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '40', 'type': 'dictionary', 'children': ['41']}; {'id': '41', 'type': 'pair', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'filters'"}; {'id': '43', 'type': 'dictionary', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cidr'}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '54']}; {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'filters'"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'cidr'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'cidr'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'subnet_name'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '65']}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'filters'"}; {'id': '64', 'type': 'string', 'children': [], 'value': "'tag:Name'"}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'subnet_name'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'vpc_id'}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '76']}; {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'filters'"}; {'id': '75', 'type': 'string', 'children': [], 'value': "'VpcId'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'vpc_id'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'for_statement', 'children': ['81', '84', '90']}; {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'tag_name'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tag_value'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '103']}; {'id': '93', 'type': 'subscript', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'filters'"}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'string', 'children': [], 'value': "'tag:{0}'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'tag_name'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'tag_value'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'subnets'}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'get_all_subnets'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'dictionary_splat', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'The filters criteria %s matched the following subnets: %s'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'filter_parameters'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'subnets'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '125', '134']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'subnets'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'return_statement', 'children': ['127']}; {'id': '127', 'type': 'list_comprehension', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'subnet'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'subnet'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'subnets'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'return_statement', 'children': ['137']}; {'id': '137', 'type': 'False', 'children': []}
|
Given subnet properties, find and return matching subnet ids
|
def globalsfilter(input_dict, check_all=False, filters=None,
exclude_private=None, exclude_capitalized=None,
exclude_uppercase=None, exclude_unsupported=None,
excluded_names=None):
output_dict = {}
for key, value in list(input_dict.items()):
excluded = (exclude_private and key.startswith('_')) or \
(exclude_capitalized and key[0].isupper()) or \
(exclude_uppercase and key.isupper()
and len(key) > 1 and not key[1:].isdigit()) or \
(key in excluded_names) or \
(exclude_unsupported and \
not is_supported(value, check_all=check_all,
filters=filters))
if not excluded:
output_dict[key] = value
return output_dict
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'globalsfilter'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_dict'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'check_all'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'exclude_private'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude_capitalized'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exclude_uppercase'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'exclude_unsupported'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'excluded_names'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '31', '129']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'output_dict'}; {'id': '30', 'type': 'dictionary', 'children': []}; {'id': '31', 'type': 'for_statement', 'children': ['32', '35', '43']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'input_dict'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'block', 'children': ['44', '119']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'excluded'}; {'id': '47', 'type': 'boolean_operator', 'children': ['48', '103', '104'], 'value': 'or'}; {'id': '48', 'type': 'boolean_operator', 'children': ['49', '98', '99'], 'value': 'or'}; {'id': '49', 'type': 'boolean_operator', 'children': ['50', '71', '72'], 'value': 'or'}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '60', '61'], 'value': 'or'}; {'id': '51', 'type': '()', 'children': ['52']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'exclude_private'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '60', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '61', 'type': '()', 'children': ['62']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'and'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'exclude_capitalized'}; {'id': '64', 'type': 'call', 'children': ['65', '70']}; {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '72', 'type': '()', 'children': ['73']}; {'id': '73', 'type': 'boolean_operator', 'children': ['74', '88'], 'value': 'and'}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '82'], 'value': 'and'}; {'id': '75', 'type': 'boolean_operator', 'children': ['76', '77'], 'value': 'and'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'exclude_uppercase'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '87'], 'value': '>'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'not_operator', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '97']}; {'id': '90', 'type': 'attribute', 'children': ['91', '96']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '95', 'type': 'colon', 'children': []}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '99', 'type': '()', 'children': ['100']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'in'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'excluded_names'}; {'id': '103', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '104', 'type': '()', 'children': ['105']}; {'id': '105', 'type': 'boolean_operator', 'children': ['106', '107', '108'], 'value': 'and'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'exclude_unsupported'}; {'id': '107', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '108', 'type': 'not_operator', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'is_supported'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '113', '116']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'check_all'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'check_all'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '119', 'type': 'if_statement', 'children': ['120', '122']}; {'id': '120', 'type': 'not_operator', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'excluded'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '128']}; {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'output_dict'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'output_dict'}
|
Keep only objects that can be pickled
|
def read_values(target_usage):
all_devices = hid.HidDeviceFilter().get_devices()
if not all_devices:
print("Can't find any non system HID device connected")
else:
usage_found = False
for device in all_devices:
try:
device.open()
for report in device.find_feature_reports():
if target_usage in report:
report.get()
print("The value:", list(report[target_usage]))
print("All the report: {0}".format(report.get_raw_data()))
usage_found = True
finally:
device.close()
if not usage_found:
print("The target device was found, but the requested usage does not exist!\n")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_values'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'target_usage'}; {'id': '5', 'type': 'block', 'children': ['6', '18']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_devices'}; {'id': '9', 'type': 'call', 'children': ['10', '17']}; {'id': '10', 'type': 'attribute', 'children': ['11', '16']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'hid'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'HidDeviceFilter'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_devices'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '21', '27']}; {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'all_devices'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"Can\'t find any non system HID device connected"'}; {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29', '33', '101']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'usage_found'}; {'id': '32', 'type': 'False', 'children': []}; {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'all_devices'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'try_statement', 'children': ['38', '93']}; {'id': '38', 'type': 'block', 'children': ['39', '45']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '52']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'find_feature_reports'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'target_usage'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '57', 'type': 'block', 'children': ['58', '64', '75', '89']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"The value:"'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'target_usage'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'string', 'children': [], 'value': '"All the report: {0}"'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_raw_data'}; {'id': '88', 'type': 'argument_list', 'children': []}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'usage_found'}; {'id': '92', 'type': 'True', 'children': []}; {'id': '93', 'type': 'finally_clause', 'children': ['94']}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '100', 'type': 'argument_list', 'children': []}; {'id': '101', 'type': 'if_statement', 'children': ['102', '104']}; {'id': '102', 'type': 'not_operator', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'usage_found'}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'string', 'children': [], 'value': '"The target device was found, but the requested usage does not exist!\\n"'}
|
read feature report values
|
def add_hbar_widget(self, ref, x=1, y=1, length=10):
if ref not in self.widgets:
widget = widgets.HBarWidget(screen=self, ref=ref, x=x, y=y, length=length)
self.widgets[ref] = widget
return self.widgets[ref]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_hbar_widget'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'not in'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'widgets'}; {'id': '22', 'type': 'block', 'children': ['23', '46', '54']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'widgets'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'HBarWidget'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '34', '37', '40', '43']}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'screen'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'widgets'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'widgets'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ref'}
|
Add Horizontal Bar Widget
|
def logged_delete(self, user):
self.delete()
entry = ChangeLogEntry({
'type': 'DELETED',
'documents': [self],
'user': user
})
entry.insert()
return entry
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'logged_delete'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '30', '36']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '12', 'type': 'argument_list', 'children': []}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ChangeLogEntry'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'dictionary', 'children': ['20', '23', '27']}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}; {'id': '21', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'DELETED'"}; {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'documents'"}; {'id': '25', 'type': 'list', 'children': ['26'], 'value': '[self]'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'pair', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'user'"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'entry'}
|
Delete the document and log the event in the change log
|
def pad_block(block, block_size):
unique_vals, unique_counts = np.unique(block, return_counts=True)
most_frequent_value = unique_vals[np.argmax(unique_counts)]
return np.pad(block,
tuple((0, desired_size - actual_size)
for desired_size, actual_size
in zip(block_size, block.shape)),
mode="constant", constant_values=most_frequent_value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pad_block'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '32']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'unique_vals'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'unique_counts'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'return_counts'}; {'id': '20', 'type': 'True', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'most_frequent_value'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unique_vals'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'argmax'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'unique_counts'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pad'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '58', '61']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '41', 'type': 'generator_expression', 'children': ['42', '47']}; {'id': '42', 'type': 'tuple', 'children': ['43', '44']}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '-'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'desired_size'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'actual_size'}; {'id': '47', 'type': 'for_in_clause', 'children': ['48', '51']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'desired_size'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'actual_size'}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"constant"'}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'constant_values'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'most_frequent_value'}
|
Pad a block to block_size with its most frequent value
|
def omerc2cf(area):
proj_dict = area.proj_dict
args = dict(azimuth_of_central_line=proj_dict.get('alpha'),
latitude_of_projection_origin=proj_dict.get('lat_0'),
longitude_of_projection_origin=proj_dict.get('lonc'),
grid_mapping_name='oblique_mercator',
reference_ellipsoid_name=proj_dict.get('ellps', 'WGS84'),
false_easting=0.,
false_northing=0.
)
if "no_rot" in proj_dict:
args['no_rotation'] = 1
if "gamma" in proj_dict:
args['gamma'] = proj_dict['gamma']
return args
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'omerc2cf'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'area'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '60', '71', '84']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'area'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '26', '34', '42', '45', '54', '57']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'azimuth_of_central_line'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'alpha'"}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'latitude_of_projection_origin'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'lat_0'"}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'longitude_of_projection_origin'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'lonc'"}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'grid_mapping_name'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'oblique_mercator'"}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reference_ellipsoid_name'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'ellps'"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'WGS84'"}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'false_easting'}; {'id': '56', 'type': 'float', 'children': [], 'value': '0.'}; {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'false_northing'}; {'id': '59', 'type': 'float', 'children': [], 'value': '0.'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"no_rot"'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'no_rotation'"}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '71', 'type': 'if_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'}; {'id': '73', 'type': 'string', 'children': [], 'value': '"gamma"'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '81']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'gamma'"}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'proj_dict'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'gamma'"}; {'id': '84', 'type': 'return_statement', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'}
|
Return the cf grid mapping for the omerc projection.
|
def update_project_template(push):
import ballet.update
import ballet.util.log
ballet.util.log.enable(level='INFO',
format=ballet.util.log.SIMPLE_LOG_FORMAT,
echo=False)
ballet.update.update_project_template(push=push)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_project_template'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '15', '40']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}; {'id': '7', 'type': 'dotted_name', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ballet'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '10', 'type': 'import_statement', 'children': ['11']}; {'id': '11', 'type': 'dotted_name', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ballet'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '24']}; {'id': '17', 'type': 'attribute', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ballet'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'enable'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '28', '37']}; {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '27', 'type': 'string', 'children': [], 'value': "'INFO'"}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '30', 'type': 'attribute', 'children': ['31', '36']}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ballet'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'SIMPLE_LOG_FORMAT'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '39', 'type': 'False', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ballet'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'update_project_template'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'push'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'push'}
|
Update an existing ballet project from the upstream template
|
def write_to(output, txt):
if (isinstance(txt, six.binary_type) or six.PY3 and isinstance(output, StringIO)) or isinstance(output, TextIOWrapper):
output.write(txt)
else:
output.write(txt.encode("utf-8", "replace"))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_to'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'txt'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '32', '40']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '27'], 'value': 'or'}; {'id': '9', 'type': '()', 'children': ['10']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '18'], 'value': 'or'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'txt'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'binary_type'}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'PY3'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'StringIO'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'TextIOWrapper'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'txt'}; {'id': '40', 'type': 'else_clause', 'children': ['41']}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'txt'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': '"utf-8"'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"replace"'}
|
Write some text to some output
|
def _get_variant_regions(items):
return list(filter(lambda x: x is not None,
[tz.get_in(("config", "algorithm", "variant_regions"), data)
for data in items
if tz.get_in(["config", "algorithm", "coverage_interval"], data) != "genome"]))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_variant_regions'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '19']}; {'id': '13', 'type': 'lambda', 'children': ['14', '16']}; {'id': '14', 'type': 'lambda_parameters', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is not'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'list_comprehension', 'children': ['20', '30', '33']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_in'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '29']}; {'id': '25', 'type': 'tuple', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"config"'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"algorithm"'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"variant_regions"'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '33', 'type': 'if_clause', 'children': ['34']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '45'], 'value': '!='}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_in'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '44']}; {'id': '40', 'type': 'list', 'children': ['41', '42', '43'], 'value': '["config", "algorithm", "coverage_interval"]'}; {'id': '41', 'type': 'string', 'children': [], 'value': '"config"'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"algorithm"'}; {'id': '43', 'type': 'string', 'children': [], 'value': '"coverage_interval"'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '45', 'type': 'string', 'children': [], 'value': '"genome"'}
|
Retrieve variant regions defined in any of the input items.
|
def _eq(field, value, document):
try:
return document.get(field, None) == value
except TypeError:
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_eq'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'try_statement', 'children': ['9', '20']}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '19'], 'value': '=='}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '20', 'type': 'except_clause', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'False', 'children': []}
|
Returns True if the value of a document field is equal to a given value
|
def list_security_groups(self, retrieve_all=True, **_params):
return self.list('security_groups', self.security_groups_path,
retrieve_all, **_params)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_security_groups'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'retrieve_all'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': '_params'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '21', '22']}; {'id': '17', 'type': 'string', 'children': [], 'value': "'security_groups'"}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'security_groups_path'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'retrieve_all'}; {'id': '22', 'type': 'dictionary_splat', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_params'}
|
Fetches a list of all security groups for a project.
|
def fetch(bank, key, cachedir):
inkey = False
key_file = os.path.join(cachedir, os.path.normpath(bank), '{0}.p'.format(key))
if not os.path.isfile(key_file):
key_file = os.path.join(cachedir, os.path.normpath(bank) + '.p')
inkey = True
if not os.path.isfile(key_file):
log.debug('Cache file "%s" does not exist', key_file)
return {}
try:
with salt.utils.files.fopen(key_file, 'rb') as fh_:
if inkey:
return __context__['serial'].load(fh_)[key]
else:
return __context__['serial'].load(fh_)
except IOError as exc:
raise SaltCacheError(
'There was an error reading the cache file "{0}": {1}'.format(
key_file, exc
)
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fetch'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bank'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cachedir'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '37', '73', '94']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'inkey'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23', '31']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'cachedir'}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bank'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'{0}.p'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '47']}; {'id': '38', 'type': 'not_operator', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '47', 'type': 'block', 'children': ['48', '69']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cachedir'}; {'id': '59', 'type': 'binary_operator', 'children': ['60', '68'], 'value': '+'}; {'id': '60', 'type': 'call', 'children': ['61', '66']}; {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'bank'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'.p'"}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'inkey'}; {'id': '72', 'type': 'True', 'children': []}; {'id': '73', 'type': 'if_statement', 'children': ['74', '83']}; {'id': '74', 'type': 'not_operator', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '83', 'type': 'block', 'children': ['84', '92']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': '\'Cache file "%s" does not exist\''}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}; {'id': '93', 'type': 'dictionary', 'children': []}; {'id': '94', 'type': 'try_statement', 'children': ['95', '139']}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'with_statement', 'children': ['97', '113']}; {'id': '97', 'type': 'with_clause', 'children': ['98']}; {'id': '98', 'type': 'with_item', 'children': ['99']}; {'id': '99', 'type': 'as_pattern', 'children': ['100', '111']}; {'id': '100', 'type': 'call', 'children': ['101', '108']}; {'id': '101', 'type': 'attribute', 'children': ['102', '107']}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'fopen'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '111', 'type': 'as_pattern_target', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'fh_'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116', '128']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'inkey'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'return_statement', 'children': ['118']}; {'id': '118', 'type': 'subscript', 'children': ['119', '127']}; {'id': '119', 'type': 'call', 'children': ['120', '125']}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': '__context__'}; {'id': '123', 'type': 'string', 'children': [], 'value': "'serial'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fh_'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'else_clause', 'children': ['129']}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'return_statement', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '137']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}; {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '__context__'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'serial'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'fh_'}; {'id': '139', 'type': 'except_clause', 'children': ['140', '144']}; {'id': '140', 'type': 'as_pattern', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '142', 'type': 'as_pattern_target', 'children': ['143']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'raise_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'SaltCacheError'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'string', 'children': [], 'value': '\'There was an error reading the cache file "{0}": {1}\''}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'key_file'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'exc'}
|
Fetch information from a file.
|
def bind(self, container):
def clone(prototype):
if prototype.is_bound():
raise RuntimeError('Cannot `bind` a bound extension.')
cls = type(prototype)
args, kwargs = prototype.__params
instance = cls(*args, **kwargs)
instance.container = weakref.proxy(container)
return instance
instance = clone(self)
for name, ext in inspect.getmembers(self, is_extension):
setattr(instance, name, ext.bind(container))
return instance
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bind'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '6', 'type': 'block', 'children': ['7', '62', '69', '93']}; {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'clone'}; {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'prototype'}; {'id': '11', 'type': 'block', 'children': ['12', '24', '31', '39', '49', '60']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'prototype'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'is_bound'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'Cannot `bind` a bound extension.'"}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'prototype'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'prototype'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '__params'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '47']}; {'id': '45', 'type': 'list_splat', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '47', 'type': 'dictionary_splat', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'weakref'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'proxy'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'clone'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'for_statement', 'children': ['70', '73', '80']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'getmembers'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'is_extension'}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'bind'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '93', 'type': 'return_statement', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'instance'}
|
Get an instance of this Extension to bind to `container`.
|
def _create_default_tiles(self):
for value, background, text in self.DEFAULT_TILES:
self.tiles[value] = self._make_tile(value, background, text)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_default_tiles'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '11', '14']}; {'id': '7', 'type': 'pattern_list', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'background'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_TILES'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '22']}; {'id': '17', 'type': 'subscript', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'tiles'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_make_tile'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'background'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'text'}
|
Create all default tiles, as defined above.
|
def tech_requirement(self) -> Optional[UnitTypeId]:
if self._proto.tech_requirement == 0:
return None
if self._proto.tech_requirement not in self._game_data.units:
return None
return UnitTypeId(self._proto.tech_requirement)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tech_requirement'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'generic_type', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '8', 'type': 'type_parameter', 'children': ['9']}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'UnitTypeId'}; {'id': '11', 'type': 'block', 'children': ['12', '23', '38']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '20']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '19'], 'value': '=='}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_proto'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tech_requirement'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'if_statement', 'children': ['24', '35']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '30'], 'value': 'not in'}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_proto'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tech_requirement'}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_game_data'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'UnitTypeId'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '_proto'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tech_requirement'}
|
Tech-building requirement of buildings - may work for units but unreliably
|
def _init_idxs_float(self, usr_hdrs):
self.idxs_float = [
Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.float_hdrs]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_init_idxs_float'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'usr_hdrs'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'idxs_float'}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '14', '25']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Idx'}; {'id': '14', 'type': 'for_in_clause', 'children': ['15', '18']}; {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Hdr'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Idx'}; {'id': '18', 'type': 'call', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hdr2idx'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'if_clause', 'children': ['26']}; {'id': '26', 'type': 'boolean_operator', 'children': ['27', '30'], 'value': 'and'}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Hdr'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'usr_hdrs'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'in'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Hdr'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'float_hdrs'}
|
List of indexes whose values will be floats.
|
def _jws_header(keyid, algorithm):
data = {
'typ': 'JWT',
'alg': algorithm.name,
'kid': keyid
}
datajson = json.dumps(data, sort_keys=True).encode('utf8')
return base64url_encode(datajson)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_jws_header'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'keyid'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'algorithm'}; {'id': '6', 'type': 'block', 'children': ['7', '22', '39']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '10', 'type': 'dictionary', 'children': ['11', '14', '19']}; {'id': '11', 'type': 'pair', 'children': ['12', '13']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'typ'"}; {'id': '13', 'type': 'string', 'children': [], 'value': "'JWT'"}; {'id': '14', 'type': 'pair', 'children': ['15', '16']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'alg'"}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'algorithm'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'kid'"}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keyid'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'datajson'}; {'id': '25', 'type': 'call', 'children': ['26', '37']}; {'id': '26', 'type': 'attribute', 'children': ['27', '36']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '35', 'type': 'True', 'children': []}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'utf8'"}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'base64url_encode'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'datajson'}
|
Produce a base64-encoded JWS header.
|
def bdd(*keywords):
settings = _personal_settings().data
_storybook().with_params(
**{"python version": settings["params"]["python version"]}
).only_uninherited().shortcut(*keywords).play()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bdd'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '6', 'type': 'block', 'children': ['7', '15']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_personal_settings'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '45']}; {'id': '17', 'type': 'attribute', 'children': ['18', '44']}; {'id': '18', 'type': 'call', 'children': ['19', '41']}; {'id': '19', 'type': 'attribute', 'children': ['20', '40']}; {'id': '20', 'type': 'call', 'children': ['21', '39']}; {'id': '21', 'type': 'attribute', 'children': ['22', '38']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_storybook'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'with_params'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'dictionary_splat', 'children': ['30']}; {'id': '30', 'type': 'dictionary', 'children': ['31']}; {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"python version"'}; {'id': '33', 'type': 'subscript', 'children': ['34', '37']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"params"'}; {'id': '37', 'type': 'string', 'children': [], 'value': '"python version"'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'only_uninherited'}; {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'shortcut'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'list_splat', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'play'}; {'id': '45', 'type': 'argument_list', 'children': []}
|
Run tests matching keywords.
|
def proxy_it(request, port):
websocket_proxy = request.registry.settings.get("pyramid_notebook.websocket_proxy", "")
if websocket_proxy.strip():
r = DottedNameResolver()
websocket_proxy = r.maybe_resolve(websocket_proxy)
if "upgrade" in request.headers.get("connection", "").lower():
if websocket_proxy:
return websocket_proxy(request, port)
else:
raise RuntimeError("Websocket proxy support is not configured.")
proxy_app = WSGIProxyApplication(port)
return request.get_response(proxy_app)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'proxy_it'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '43', '76', '83']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'websocket_proxy'}; {'id': '10', 'type': 'call', 'children': ['11', '18']}; {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'registry'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': '"pyramid_notebook.websocket_proxy"'}; {'id': '20', 'type': 'string', 'children': [], 'value': '""'}; {'id': '21', 'type': 'if_statement', 'children': ['22', '27']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'websocket_proxy'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'block', 'children': ['28', '34']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'DottedNameResolver'}; {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'websocket_proxy'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'maybe_resolve'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'websocket_proxy'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '59']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'in'}; {'id': '45', 'type': 'string', 'children': [], 'value': '"upgrade"'}; {'id': '46', 'type': 'call', 'children': ['47', '58']}; {'id': '47', 'type': 'attribute', 'children': ['48', '57']}; {'id': '48', 'type': 'call', 'children': ['49', '54']}; {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"connection"'}; {'id': '56', 'type': 'string', 'children': [], 'value': '""'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '62', '69']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'websocket_proxy'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'websocket_proxy'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'raise_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'string', 'children': [], 'value': '"Websocket proxy support is not configured."'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'proxy_app'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'WSGIProxyApplication'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_response'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'proxy_app'}
|
Proxy HTTP request to upstream IPython Notebook Tornado server.
|
def startLoop():
def _ipython_loop_asyncio(kernel):
loop = asyncio.get_event_loop()
def kernel_handler():
kernel.do_one_iteration()
loop.call_later(kernel._poll_interval, kernel_handler)
loop.call_soon(kernel_handler)
try:
if not loop.is_running():
loop.run_forever()
finally:
if not loop.is_running():
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()
patchAsyncio()
loop = asyncio.get_event_loop()
if not loop.is_running():
from ipykernel.eventloops import register_integration, enable_gui
register_integration('asyncio')(_ipython_loop_asyncio)
enable_gui('asyncio')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'startLoop'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '88', '92', '100']}; {'id': '5', 'type': 'function_definition', 'children': ['6', '7', '9']}; {'id': '6', 'type': 'function_name', 'children': [], 'value': '_ipython_loop_asyncio'}; {'id': '7', 'type': 'parameters', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '9', 'type': 'block', 'children': ['10', '18', '38', '45']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'asyncio'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_event_loop'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'function_definition', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'function_name', 'children': [], 'value': 'kernel_handler'}; {'id': '20', 'type': 'parameters', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22', '28']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'do_one_iteration'}; {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'call_later'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_poll_interval'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kernel_handler'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'call_soon'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kernel_handler'}; {'id': '45', 'type': 'try_statement', 'children': ['46', '61']}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'if_statement', 'children': ['48', '54']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_running'}; {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'run_forever'}; {'id': '60', 'type': 'argument_list', 'children': []}; {'id': '61', 'type': 'finally_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'if_statement', 'children': ['64', '70']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'is_running'}; {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71', '82']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'run_until_complete'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'shutdown_asyncgens'}; {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '87', 'type': 'argument_list', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'patchAsyncio'}; {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'asyncio'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get_event_loop'}; {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'if_statement', 'children': ['101', '107']}; {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'is_running'}; {'id': '106', 'type': 'argument_list', 'children': []}; {'id': '107', 'type': 'block', 'children': ['108', '116', '124']}; {'id': '108', 'type': 'import_from_statement', 'children': ['109', '112', '114']}; {'id': '109', 'type': 'dotted_name', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ipykernel'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'eventloops'}; {'id': '112', 'type': 'dotted_name', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'register_integration'}; {'id': '114', 'type': 'dotted_name', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'enable_gui'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '122']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'register_integration'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'string', 'children': [], 'value': "'asyncio'"}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': '_ipython_loop_asyncio'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'enable_gui'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'asyncio'"}
|
Use nested asyncio event loop for Jupyter notebooks.
|
def remove_object(self, key):
state = self.state
for layer in state.layers:
state.layers[layer].pop(key, None)
state.need_redraw = True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_object'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '31']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '18']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '28']}; {'id': '21', 'type': 'attribute', 'children': ['22', '27']}; {'id': '22', 'type': 'subscript', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'need_redraw'}; {'id': '36', 'type': 'True', 'children': []}
|
remove an object by key from all layers
|
def text(self, string, x, y, color, *,
font_name="font5x8.bin"):
if not self._font or self._font.font_name != font_name:
self._font = BitmapFont()
w = self._font.font_width
for i, char in enumerate(string):
self._font.draw_char(char,
x + (i * (w + 1)),
y, self, color)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'text'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '9', 'type': 'keyword_separator', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'font_name'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"font5x8.bin"'}; {'id': '13', 'type': 'block', 'children': ['14', '36', '44']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '27']}; {'id': '15', 'type': 'boolean_operator', 'children': ['16', '20'], 'value': 'or'}; {'id': '16', 'type': 'not_operator', 'children': ['17']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_font'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '26'], 'value': '!='}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_font'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'font_name'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'font_name'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_font'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'BitmapFont'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_font'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'font_width'}; {'id': '44', 'type': 'for_statement', 'children': ['45', '48', '52']}; {'id': '45', 'type': 'pattern_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '60']}; {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_font'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'draw_char'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62', '71', '72', '73']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '64', 'type': '()', 'children': ['65']}; {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '*'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '67', 'type': '()', 'children': ['68']}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'color'}
|
text is not yet implemented
|
def center(self):
bounds = self.bounds
x = (bounds[1] + bounds[0])/2
y = (bounds[3] + bounds[2])/2
z = (bounds[5] + bounds[4])/2
return [x, y, z]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'center'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '25', '38', '51']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '24'], 'value': '/'}; {'id': '16', 'type': '()', 'children': ['17']}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '21'], 'value': '+'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '37'], 'value': '/'}; {'id': '29', 'type': '()', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '34'], 'value': '+'}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '41', 'type': 'binary_operator', 'children': ['42', '50'], 'value': '/'}; {'id': '42', 'type': '()', 'children': ['43']}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '47'], 'value': '+'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'list', 'children': ['53', '54', '55'], 'value': '[x, y, z]'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'z'}
|
Center of the bounding box around all data present in the scene
|
def update(self, automation):
self._automation.update(
{k: automation[k] for k in automation if self._automation.get(k)})
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'automation'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '14']}; {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_automation'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'dictionary_comprehension', 'children': ['16', '21', '24']}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'automation'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'automation'}; {'id': '24', 'type': 'if_clause', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_automation'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'}
|
Update the internal automation json.
|
def best(self):
return pd.Series(
{
"name": self.best_dist.name,
"params": self.best_param,
"sse": self.best_sse,
}
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'best'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'dictionary', 'children': ['13', '20', '25']}; {'id': '13', 'type': 'pair', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'best_dist'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}; {'id': '21', 'type': 'string', 'children': [], 'value': '"params"'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'best_param'}; {'id': '25', 'type': 'pair', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"sse"'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'best_sse'}
|
The resulting best-fit distribution, its parameters, and SSE.
|
def _get_at_from_session(self):
try:
return self.request.session['oauth_%s_access_token'
% get_token_prefix(
self.request_token_url)]
except KeyError:
raise OAuthError(
_('No access token saved for "%s".')
% get_token_prefix(self.request_token_url))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_at_from_session'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '23']}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}; {'id': '9', 'type': 'subscript', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '%'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'oauth_%s_access_token'"}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_token_prefix'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'request_token_url'}; {'id': '23', 'type': 'except_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'raise_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'OAuthError'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '35'], 'value': '%'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': '\'No access token saved for "%s".\''}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_token_prefix'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'request_token_url'}
|
Get the saved access token for private resources from the session.
|
async def destroy(self, container = None):
if container is None:
container = RoutineContainer(self.scheduler)
if self.queue is not None:
await container.syscall_noreturn(syscall_removequeue(self.scheduler.queue, self.queue))
self.queue = None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'destroy'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'RoutineContainer'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'scheduler'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '29']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': 'is not'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30', '48']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'await', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'syscall_noreturn'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'syscall_removequeue'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'scheduler'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '53', 'type': 'None', 'children': []}
|
Destroy the created subqueue to change the behavior back to Lock
|
def timedelta_seconds(timedelta):
return (timedelta.total_seconds() if hasattr(timedelta, "total_seconds")
else timedelta.days * 24 * 3600 + timedelta.seconds +
timedelta.microseconds / 1000000.)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'timedelta_seconds'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}; {'id': '7', 'type': '()', 'children': ['8']}; {'id': '8', 'type': 'conditional_expression', 'children': ['9', '14', '19'], 'value': 'if'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"total_seconds"'}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '31'], 'value': '+'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '28'], 'value': '+'}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '27'], 'value': '*'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '26'], 'value': '*'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '24'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '3600'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'seconds'}; {'id': '31', 'type': 'binary_operator', 'children': ['32', '35'], 'value': '/'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'microseconds'}; {'id': '35', 'type': 'float', 'children': [], 'value': '1000000.'}
|
Returns the total timedelta duration in seconds.
|
def scorable_block_completion(sender, **kwargs):
if not waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
return
course_key = CourseKey.from_string(kwargs['course_id'])
block_key = UsageKey.from_string(kwargs['usage_id'])
block_cls = XBlock.load_class(block_key.block_type)
if XBlockCompletionMode.get_mode(block_cls) != XBlockCompletionMode.COMPLETABLE:
return
if getattr(block_cls, 'has_custom_completion', False):
return
user = User.objects.get(id=kwargs['user_id'])
if kwargs.get('score_deleted'):
completion = 0.0
else:
completion = 1.0
if not kwargs.get('grader_response'):
BlockCompletion.objects.submit_completion(
user=user,
course_key=course_key,
block_key=block_key,
completion=completion,
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scorable_block_completion'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sender'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '24', '35', '46', '57', '70', '79', '94', '112']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '22']}; {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '18']}; {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'waffle'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'waffle'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'is_enabled'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'waffle'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ENABLE_COMPLETION_TRACKING'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'return_statement', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'course_key'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'CourseKey'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'course_id'"}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'block_key'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'UsageKey'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '45', 'type': 'string', 'children': [], 'value': "'usage_id'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'block_cls'}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'XBlock'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'load_class'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'block_key'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'block_type'}; {'id': '57', 'type': 'if_statement', 'children': ['58', '68']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '65'], 'value': '!='}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'XBlockCompletionMode'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_mode'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'block_cls'}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'XBlockCompletionMode'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'COMPLETABLE'}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'return_statement', 'children': []}; {'id': '70', 'type': 'if_statement', 'children': ['71', '77']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'block_cls'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'has_custom_completion'"}; {'id': '76', 'type': 'False', 'children': []}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': []}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}; {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'User'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '93', 'type': 'string', 'children': [], 'value': "'user_id'"}; {'id': '94', 'type': 'if_statement', 'children': ['95', '101', '106']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'score_deleted'"}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'completion'}; {'id': '105', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'completion'}; {'id': '111', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '120']}; {'id': '113', 'type': 'not_operator', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'grader_response'"}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}; {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'BlockCompletion'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'submit_completion'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '132', '135', '138']}; {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'course_key'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'course_key'}; {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'block_key'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'block_key'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'completion'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'completion'}
|
When a problem is scored, submit a new BlockCompletion for that block.
|
def create_logger(self):
name = "bors"
if hasattr(self, "name"):
name = self.name
self.log = logging.getLogger(name)
try:
lvl = self.conf.get_log_level()
except AttributeError:
lvl = self.context.get("log_level", None)
self.log.setLevel(getattr(logging, lvl, logging.INFO))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_logger'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '23', '34', '61']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '9', 'type': 'string', 'children': [], 'value': '"bors"'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '34', 'type': 'try_statement', 'children': ['35', '46']}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_log_level'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'except_clause', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '52', 'type': 'call', 'children': ['53', '58']}; {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': '"log_level"'}; {'id': '60', 'type': 'None', 'children': []}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '68']}; {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '73', '74']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'INFO'}
|
Generates a logger instance from the singleton
|
def events_list(self):
evt = []
evt.extend(events.NEPALI_EVENTS[self.month, self.day])
evt.extend(events.ENGLISH_EVENTS[self.en_date.month, self.en_date.day])
return evt
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'events_list'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '26', '46']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'evt'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'evt'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'subscript', 'children': ['17', '20', '23']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'NEPALI_EVENTS'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'evt'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'subscript', 'children': ['33', '36', '41']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ENGLISH_EVENTS'}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'en_date'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'en_date'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'evt'}
|
Returns the events today
|
def handle_m2m_user(self, sender, instance, **kwargs):
self.handle_save(instance.user.__class__, instance.user)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_m2m_user'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sender'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'handle_save'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'user'}
|
Handle many to many relationships for user field
|
def quit(self):
response = self.run() == Gtk.ResponseType.YES
self.destroy()
return response
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'quit'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '20', '26']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '15'], 'value': '=='}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Gtk'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ResponseType'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'YES'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'destroy'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'response'}
|
Run the "are you sure" dialog for quitting Guake
|
def pass_verbosity(f):
def new_func(*args, **kwargs):
kwargs['verbosity'] = click.get_current_context().verbosity
return f(*args, **kwargs)
return update_wrapper(new_func, f)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pass_verbosity'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '5', 'type': 'block', 'children': ['6', '34']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '13']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'new_func'}; {'id': '8', 'type': 'parameters', 'children': ['9', '11']}; {'id': '9', 'type': 'list_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '13', 'type': 'block', 'children': ['14', '26']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '19']}; {'id': '16', 'type': 'subscript', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'verbosity'"}; {'id': '19', 'type': 'attribute', 'children': ['20', '25']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_current_context'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'verbosity'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '32']}; {'id': '30', 'type': 'list_splat', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '32', 'type': 'dictionary_splat', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'update_wrapper'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'new_func'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'f'}
|
Marks a callback as wanting to receive the verbosity as a keyword argument.
|
def _populateComboBoxes(self, row):
logger.debug("_populateComboBoxes")
for comboBox in self._comboBoxes:
comboBox.clear()
if not self.rtiIsSliceable:
for comboBoxNr, comboBox in enumerate(self._comboBoxes):
comboBox.addItem('', userData=None)
comboBox.setEnabled(False)
return
nDims = self._rti.nDims
nCombos = len(self._comboBoxes)
for comboBoxNr, comboBox in enumerate(self._comboBoxes):
comboBox.addItem(FAKE_DIM_NAME, userData = FAKE_DIM_OFFSET + comboBoxNr)
for dimNr in range(nDims):
comboBox.addItem(self._rti.dimensionNames[dimNr], userData=dimNr)
if nDims >= nCombos:
curIdx = nDims + 1 - nCombos + comboBoxNr
else:
curIdx = comboBoxNr + 1 if comboBoxNr < nDims else 0
assert 0 <= curIdx <= nDims + 1, \
"curIdx should be <= {}, got {}".format(nDims + 1, curIdx)
comboBox.setCurrentIndex(curIdx)
comboBox.setEnabled(True)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_populateComboBoxes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '26', '61', '69', '78']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'string', 'children': [], 'value': '"_populateComboBoxes"'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '19']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_comboBoxes'}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'clear'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '31']}; {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'rtiIsSliceable'}; {'id': '31', 'type': 'block', 'children': ['32', '60']}; {'id': '32', 'type': 'for_statement', 'children': ['33', '36', '42']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'comboBoxNr'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_comboBoxes'}; {'id': '42', 'type': 'block', 'children': ['43', '53']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'addItem'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'string', 'children': [], 'value': "''"}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'userData'}; {'id': '52', 'type': 'None', 'children': []}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'False', 'children': []}; {'id': '60', 'type': 'return_statement', 'children': []}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_rti'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'nCombos'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': '_comboBoxes'}; {'id': '78', 'type': 'for_statement', 'children': ['79', '82', '88']}; {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'comboBoxNr'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': '_comboBoxes'}; {'id': '88', 'type': 'block', 'children': ['89', '101', '124', '152', '168', '175']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'addItem'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'FAKE_DIM_NAME'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'userData'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '+'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'FAKE_DIM_OFFSET'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'comboBoxNr'}; {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '107']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dimNr'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'addItem'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '121']}; {'id': '114', 'type': 'subscript', 'children': ['115', '120']}; {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_rti'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dimensionNames'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'dimNr'}; {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'userData'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'dimNr'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128', '139']}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '>='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'nCombos'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'curIdx'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '138'], 'value': '+'}; {'id': '133', 'type': 'binary_operator', 'children': ['134', '137'], 'value': '-'}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'nCombos'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'comboBoxNr'}; {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'curIdx'}; {'id': '144', 'type': 'conditional_expression', 'children': ['145', '148', '151'], 'value': 'if'}; {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'comboBoxNr'}; {'id': '147', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '<'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'comboBoxNr'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '151', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '152', 'type': 'assert_statement', 'children': ['153', '159']}; {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155', '156'], 'value': '<='}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'curIdx'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '+'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'string', 'children': [], 'value': '"curIdx should be <= {}, got {}"'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '167']}; {'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '+'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'nDims'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'curIdx'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'setCurrentIndex'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'curIdx'}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'comboBox'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'True', 'children': []}
|
Populates the combo boxes with values of the repo tree item
|
def _get_localized_field_checks(self):
localized_fields_checks = []
for localized_field in self.instance.localized_fields:
if self.cleaned_data.get(localized_field) is None:
continue
f = getattr(self.instance.__class__, localized_field, None)
if f and f.unique:
if f.unique:
local_name = get_real_fieldname(localized_field, self.language)
localized_fields_checks.append((localized_field, local_name))
return localized_fields_checks
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_localized_field_checks'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '75']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'localized_fields_checks'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'localized_field'}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'localized_fields'}; {'id': '17', 'type': 'block', 'children': ['18', '31', '44']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '29']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '28'], 'value': 'is'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'localized_field'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'continue_statement', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '42', '43']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'localized_field'}; {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}; {'id': '45', 'type': 'boolean_operator', 'children': ['46', '47'], 'value': 'and'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '55', 'type': 'block', 'children': ['56', '66']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'local_name'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_real_fieldname'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'localized_field'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'language'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'localized_fields_checks'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'tuple', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'localized_field'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'local_name'}; {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'localized_fields_checks'}
|
Get the checks we must perform for the localized fields.
|
def problem_serializing(value, e=None):
from mo_logs import Log
try:
typename = type(value).__name__
except Exception:
typename = "<error getting name>"
try:
rep = text_type(repr(value))
except Exception as _:
rep = None
if rep == None:
Log.error(
"Problem turning value of type {{type}} to json",
type=typename,
cause=e
)
else:
Log.error(
"Problem turning value ({{value}}) of type {{type}} to json",
value=rep,
type=typename,
cause=e
)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'problem_serializing'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '14', '32', '54']}; {'id': '9', 'type': 'import_from_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'mo_logs'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Log'}; {'id': '14', 'type': 'try_statement', 'children': ['15', '25']}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '19', 'type': 'attribute', 'children': ['20', '24']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '25', 'type': 'except_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '31', 'type': 'string', 'children': [], 'value': '"<error getting name>"'}; {'id': '32', 'type': 'try_statement', 'children': ['33', '44']}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '44', 'type': 'except_clause', 'children': ['45', '49']}; {'id': '45', 'type': 'as_pattern', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '47', 'type': 'as_pattern_target', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58', '72']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'Log'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '69']}; {'id': '65', 'type': 'string', 'children': [], 'value': '"Problem turning value of type {{type}} to json"'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Log'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '84', '87']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Problem turning value ({{value}}) of type {{type}} to json"'}; {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cause'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'e'}
|
THROW ERROR ABOUT SERIALIZING
|
def _deserialize(cls, key, value, fields):
converter = cls._get_converter_for_field(key, None, fields)
return converter.deserialize(value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_deserialize'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '8', 'type': 'block', 'children': ['9', '20']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_get_converter_for_field'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'deserialize'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'value'}
|
Marshal incoming data into Python objects.
|
def _transform_i(self, x, i):
x = self._shift_or_mirror_into_invertible_i(x, i)
lb = self._lb[self._index(i)]
ub = self._ub[self._index(i)]
al = self._al[self._index(i)]
au = self._au[self._index(i)]
if x < lb + al:
return lb + (x - (lb - al))**2 / 4 / al
elif x < ub - au:
return x
elif x < ub + 3 * au:
return ub - (x - (ub + au))**2 / 4 / au
else:
assert False
return ub + au - (x - (ub + au))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_transform_i'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '31', '44', '57', '70']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_shift_or_mirror_into_invertible_i'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'lb'}; {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_lb'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_ub'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'al'}; {'id': '47', 'type': 'subscript', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_al'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'au'}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': '_au'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '76', '93', '102', '127']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '<'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'lb'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'al'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '+'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'lb'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '92'], 'value': '/'}; {'id': '81', 'type': 'binary_operator', 'children': ['82', '91'], 'value': '/'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '90'], 'value': '**'}; {'id': '83', 'type': '()', 'children': ['84']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '-'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '86', 'type': '()', 'children': ['87']}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '-'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'lb'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'al'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '91', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'al'}; {'id': '93', 'type': 'elif_clause', 'children': ['94', '99']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '<'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '-'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'au'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '102', 'type': 'elif_clause', 'children': ['103', '110']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '<'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '*'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'au'}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '-'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '126'], 'value': '/'}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '125'], 'value': '/'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '124'], 'value': '**'}; {'id': '117', 'type': '()', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '-'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '120', 'type': '()', 'children': ['121']}; {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'au'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'au'}; {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129', '131']}; {'id': '129', 'type': 'assert_statement', 'children': ['130']}; {'id': '130', 'type': 'False', 'children': []}; {'id': '131', 'type': 'return_statement', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '-'}; {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'au'}; {'id': '136', 'type': '()', 'children': ['137']}; {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '-'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '139', 'type': '()', 'children': ['140']}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '+'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ub'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'au'}
|
return transform of x in component i
|
def atlas_peer_set_zonefile_inventory( peer_hostport, peer_inv, peer_table=None ):
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
ptbl[peer_hostport]['zonefile_inv'] = peer_inv
return peer_inv
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'atlas_peer_set_zonefile_inventory'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'peer_hostport'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'peer_inv'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'peer_table'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '40']}; {'id': '10', 'type': 'with_statement', 'children': ['11', '20']}; {'id': '11', 'type': 'with_clause', 'children': ['12']}; {'id': '12', 'type': 'with_item', 'children': ['13']}; {'id': '13', 'type': 'as_pattern', 'children': ['14', '18']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'AtlasPeerTableLocked'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'peer_table'}; {'id': '18', 'type': 'as_pattern_target', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ptbl'}; {'id': '20', 'type': 'block', 'children': ['21', '32']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '29']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'not in'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'peer_hostport'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ptbl'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '39']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ptbl'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'peer_hostport'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'zonefile_inv'"}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'peer_inv'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'peer_inv'}
|
Set this peer's zonefile inventory
|
def reportTime(t, options, field=None):
if options.pretty:
return prettyTime(t, field=field)
else:
if field is not None:
return "%*.2f" % (field, t)
else:
return "%.2f" % t
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reportTime'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14', '23']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pretty'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'prettyTime'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '23', 'type': 'else_clause', 'children': ['24']}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '36']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is not'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '%'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"%*.2f"'}; {'id': '33', 'type': 'tuple', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '36', 'type': 'else_clause', 'children': ['37']}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"%.2f"'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 't'}
|
Given t seconds, report back the correct format as string.
|
def nodes_aws(c_obj):
aws_nodes = []
try:
aws_nodes = c_obj.list_nodes()
except BaseHTTPError as e:
abort_err("\r HTTP Error with AWS: {}".format(e))
aws_nodes = adj_nodes_aws(aws_nodes)
return aws_nodes
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nodes_aws'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'c_obj'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '36', '43']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'aws_nodes'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'try_statement', 'children': ['11', '20']}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'aws_nodes'}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'c_obj'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'list_nodes'}; {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'except_clause', 'children': ['21', '25']}; {'id': '21', 'type': 'as_pattern', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'BaseHTTPError'}; {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'abort_err'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"\\r HTTP Error with AWS: {}"'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'aws_nodes'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'adj_nodes_aws'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'aws_nodes'}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'aws_nodes'}
|
Get node objects from AWS.
|
def select_observations(self, name):
return [n for n in self.get_obs_nodes() if n.obsname==name]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select_observations'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'list_comprehension', 'children': ['9', '10', '17']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '10', 'type': 'for_in_clause', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_obs_nodes'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'if_clause', 'children': ['18']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'obsname'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}
|
Returns nodes whose instrument-band matches 'name'
|
def unhandled(self, key):
self.key = key
self.size = self.tui.get_cols_rows()
if self.search is True:
if self.enter is False and self.no_matches is False:
if len(key) == 1 and key.isprintable():
self.search_string += key
self._search()
elif self.enter is True and not self.search_string:
self.search = False
self.enter = False
return
if not self.urls and key not in "Qq":
return
if self.help_menu is False:
try:
self.keys[key]()
except KeyError:
pass
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unhandled'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '25', '96', '107']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '18', 'type': 'call', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tui'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_cols_rows'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': 'is'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '30', 'type': 'True', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32', '95']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '44', '71']}; {'id': '33', 'type': 'boolean_operator', 'children': ['34', '39'], 'value': 'and'}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': 'is'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'enter'}; {'id': '38', 'type': 'False', 'children': []}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'no_matches'}; {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '65']}; {'id': '45', 'type': 'if_statement', 'children': ['46', '58']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '53'], 'value': 'and'}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '52'], 'value': '=='}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'isprintable'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'augmented_assignment', 'children': ['61', '64'], 'value': '+='}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'search_string'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': '_search'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'elif_clause', 'children': ['72', '82']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '78'], 'value': 'and'}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '77'], 'value': 'is'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'enter'}; {'id': '77', 'type': 'True', 'children': []}; {'id': '78', 'type': 'not_operator', 'children': ['79']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'search_string'}; {'id': '82', 'type': 'block', 'children': ['83', '89']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '88', 'type': 'False', 'children': []}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'enter'}; {'id': '94', 'type': 'False', 'children': []}; {'id': '95', 'type': 'return_statement', 'children': []}; {'id': '96', 'type': 'if_statement', 'children': ['97', '105']}; {'id': '97', 'type': 'boolean_operator', 'children': ['98', '102'], 'value': 'and'}; {'id': '98', 'type': 'not_operator', 'children': ['99']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'urls'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'not in'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '104', 'type': 'string', 'children': [], 'value': '"Qq"'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'return_statement', 'children': []}; {'id': '107', 'type': 'if_statement', 'children': ['108', '113']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '112'], 'value': 'is'}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'help_menu'}; {'id': '112', 'type': 'False', 'children': []}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'try_statement', 'children': ['115', '124']}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '123']}; {'id': '118', 'type': 'subscript', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'except_clause', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'pass_statement', 'children': []}
|
Handle other keyboard actions not handled by the ListBox widget.
|
def exponential_backoff(fn, sleeptime_s_max=30 * 60):
sleeptime_ms = 500
while True:
if fn():
return True
else:
print('Sleeping {} ms'.format(sleeptime_ms))
time.sleep(sleeptime_ms / 1000.0)
sleeptime_ms *= 2
if sleeptime_ms / 1000.0 > sleeptime_s_max:
return False
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'exponential_backoff'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sleeptime_s_max'}; {'id': '7', 'type': 'binary_operator', 'children': ['8', '9'], 'value': '*'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '60'}; {'id': '10', 'type': 'block', 'children': ['11', '15']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sleeptime_ms'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '15', 'type': 'while_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'True', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18', '50']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22', '25']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'True', 'children': []}; {'id': '25', 'type': 'else_clause', 'children': ['26']}; {'id': '26', 'type': 'block', 'children': ['27', '37', '46']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'Sleeping {} ms'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sleeptime_ms'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '/'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sleeptime_ms'}; {'id': '45', 'type': 'float', 'children': [], 'value': '1000.0'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '*='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sleeptime_ms'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '56']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '>'}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '/'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sleeptime_ms'}; {'id': '54', 'type': 'float', 'children': [], 'value': '1000.0'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sleeptime_s_max'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'False', 'children': []}
|
Calls `fn` until it returns True, with an exponentially increasing wait time between calls
|
def create_turtle(self, id, shape, model_init, color_init):
assert id not in self.id_to_shape
data = self._create_turtle(id, shape, model_init, color_init)
self.id_to_shape[id] = shape
return data
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_turtle'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'model_init'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'color_init'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '28', '36']}; {'id': '10', 'type': 'assert_statement', 'children': ['11']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'not in'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'id_to_shape'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_create_turtle'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26', '27']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'model_init'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'color_init'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '35']}; {'id': '30', 'type': 'subscript', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'id_to_shape'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}
|
Create a slice of memory for turtle data storage
|
def _filter_disabled_regions(contents):
contents = list(contents)
in_backticks = False
contents_len = len(contents)
index = 0
while index < contents_len:
character = contents[index]
if character == "`":
if ((index + 2) < contents_len and
"".join(contents[index:index + 3]) == "```"):
in_backticks = not in_backticks
index += 3
continue
if in_backticks:
contents[index] = " "
index += 1
return "".join(contents)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_filter_disabled_regions'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '17', '24', '28', '92']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'in_backticks'}; {'id': '16', 'type': 'False', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'contents_len'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'while_statement', 'children': ['29', '32']}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '<'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'contents_len'}; {'id': '32', 'type': 'block', 'children': ['33', '39', '79', '88']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '39', 'type': 'if_statement', 'children': ['40', '43']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"`"'}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '68']}; {'id': '45', 'type': '()', 'children': ['46']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '53'], 'value': 'and'}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '52'], 'value': '<'}; {'id': '48', 'type': '()', 'children': ['49']}; {'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'contents_len'}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '67'], 'value': '=='}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': '""'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '61', 'type': 'slice', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '63', 'type': 'colon', 'children': []}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '67', 'type': 'string', 'children': [], 'value': '"```"'}; {'id': '68', 'type': 'block', 'children': ['69', '74', '78']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'in_backticks'}; {'id': '72', 'type': 'not_operator', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'in_backticks'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'augmented_assignment', 'children': ['76', '77'], 'value': '+='}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '78', 'type': 'continue_statement', 'children': []}; {'id': '79', 'type': 'if_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'in_backticks'}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '87', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '91', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'string', 'children': [], 'value': '""'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'contents'}
|
Filter regions that are contained in back-ticks.
|
def collect(self):
if redis is None:
self.log.error('Unable to import module redis')
return {}
for nick in self.instances.keys():
(host, port, unix_socket, auth) = self.instances[nick]
self.collect_instance(nick, host, int(port), unix_socket, auth)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '22']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'redis'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '18']}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'Unable to import module redis'"}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '31']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'nick'}; {'id': '24', 'type': 'call', 'children': ['25', '30']}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'instances'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32', '44']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '39']}; {'id': '34', 'type': 'tuple_pattern', 'children': ['35', '36', '37', '38']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'unix_socket'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '39', 'type': 'subscript', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'instances'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'nick'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'collect_instance'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '56', '57']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'nick'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'unix_socket'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'auth'}
|
Collect the stats from the redis instance and publish them.
|
def numericise_all(input, empty2zero=False, default_blank="", allow_underscores_in_numeric_literals=False):
return [numericise(s, empty2zero, default_blank, allow_underscores_in_numeric_literals) for s in input]
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'numericise_all'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'empty2zero'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'default_blank'}; {'id': '10', 'type': 'string', 'children': [], 'value': '""'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'allow_underscores_in_numeric_literals'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '24']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'numericise'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '23']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'empty2zero'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'default_blank'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'allow_underscores_in_numeric_literals'}; {'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'input'}
|
Returns a list of numericised values from strings
|
def make_patch(self):
path = [self.arcs[0].start_point()]
for a in self.arcs:
if a.direction:
vertices = Path.arc(a.from_angle, a.to_angle).vertices
else:
vertices = Path.arc(a.to_angle, a.from_angle).vertices
vertices = vertices[np.arange(len(vertices) - 1, -1, -1)]
vertices = vertices * a.radius + a.center
path = path + list(vertices[1:])
codes = [1] + [4] * (len(path) - 1)
return PathPatch(Path(path, codes))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_patch'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '19', '109', '125']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '9', 'type': 'list', 'children': ['10'], 'value': '[self.arcs[0].start_point()]'}; {'id': '10', 'type': 'call', 'children': ['11', '18']}; {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'subscript', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'arcs'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'start_point'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'arcs'}; {'id': '24', 'type': 'block', 'children': ['25', '84', '96']}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '46']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '33', 'type': 'attribute', 'children': ['34', '45']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Path'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'arc'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'from_angle'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'to_angle'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}; {'id': '47', 'type': 'block', 'children': ['48', '64']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '51', 'type': 'attribute', 'children': ['52', '63']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'Path'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'arc'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'to_angle'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'from_angle'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '80', '82']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '79'], 'value': '-'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'}; {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '93'], 'value': '+'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '*'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '106', 'type': 'slice', 'children': ['107', '108']}; {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'colon', 'children': []}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '115'], 'value': '+'}; {'id': '113', 'type': 'list', 'children': ['114'], 'value': '[1]'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '118'], 'value': '*'}; {'id': '116', 'type': 'list', 'children': ['117'], 'value': '[4]'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '118', 'type': '()', 'children': ['119']}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '124'], 'value': '-'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'PathPatch'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'Path'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'codes'}
|
Retuns a matplotlib PathPatch representing the current region.
|
def parse_stations(html):
html = html.replace('SLs.sls=', '').replace(';SLs.showSuggestion();', '')
html = json.loads(html)
return html['suggestions']
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_stations'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'html'}; {'id': '5', 'type': 'block', 'children': ['6', '22', '31']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'html'}; {'id': '9', 'type': 'call', 'children': ['10', '19']}; {'id': '10', 'type': 'attribute', 'children': ['11', '18']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'html'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'SLs.sls='"}; {'id': '17', 'type': 'string', 'children': [], 'value': "''"}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "';SLs.showSuggestion();'"}; {'id': '21', 'type': 'string', 'children': [], 'value': "''"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'html'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'html'}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'html'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'suggestions'"}
|
Strips JS code, loads JSON
|
def setPriority(self, queue, priority):
q = self.queueindex[queue]
self.queues[q[0]].removeSubQueue(q[1])
newPriority = self.queues.setdefault(priority, CBQueue.MultiQueue(self, priority))
q[0] = priority
newPriority.addSubQueue(q[1])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setPriority'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '7', 'type': 'block', 'children': ['8', '16', '31', '49', '55']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '11', 'type': 'subscript', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'queueindex'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '27']}; {'id': '18', 'type': 'attribute', 'children': ['19', '26']}; {'id': '19', 'type': 'subscript', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'queues'}; {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'removeSubQueue'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'newPriority'}; {'id': '34', 'type': 'call', 'children': ['35', '40']}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'queues'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'CBQueue'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'MultiQueue'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'newPriority'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'addSubQueue'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}
|
Set priority of a sub-queue
|
def _render(item: ConfigItem, indent: str = "") -> str:
optional = item.default_value != _NO_DEFAULT
if is_configurable(item.annotation):
rendered_annotation = f"{item.annotation} (configurable)"
else:
rendered_annotation = str(item.annotation)
rendered_item = "".join([
indent,
"// " if optional else "",
f'"{item.name}": ',
rendered_annotation,
f" (default: {item.default_value} )" if optional else "",
f" // {item.comment}" if item.comment else "",
"\n"
])
return rendered_item
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_render'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ConfigItem'}; {'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '12', 'type': 'string', 'children': [], 'value': '""'}; {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '15', 'type': 'block', 'children': ['16', '24', '47', '74']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'optional'}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '!='}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'default_value'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_NO_DEFAULT'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '31', '36']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'is_configurable'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rendered_annotation'}; {'id': '35', 'type': 'string', 'children': [], 'value': 'f"{item.annotation} (configurable)"'}; {'id': '36', 'type': 'else_clause', 'children': ['37']}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rendered_annotation'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'annotation'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'rendered_item'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': '""'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'list', 'children': ['56', '57', '61', '62', '63', '67', '73'], 'value': '[\n indent,\n "// " if optional else "",\n f\'"{item.name}": \',\n rendered_annotation,\n f" (default: {item.default_value} )" if optional else "",\n f" // {item.comment}" if item.comment else "",\n "\\n"\n ]'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '57', 'type': 'conditional_expression', 'children': ['58', '59', '60'], 'value': 'if'}; {'id': '58', 'type': 'string', 'children': [], 'value': '"// "'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'optional'}; {'id': '60', 'type': 'string', 'children': [], 'value': '""'}; {'id': '61', 'type': 'string', 'children': [], 'value': 'f\'"{item.name}": \''}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rendered_annotation'}; {'id': '63', 'type': 'conditional_expression', 'children': ['64', '65', '66'], 'value': 'if'}; {'id': '64', 'type': 'string', 'children': [], 'value': 'f" (default: {item.default_value} )"'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'optional'}; {'id': '66', 'type': 'string', 'children': [], 'value': '""'}; {'id': '67', 'type': 'conditional_expression', 'children': ['68', '69', '72'], 'value': 'if'}; {'id': '68', 'type': 'string', 'children': [], 'value': 'f" // {item.comment}"'}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '72', 'type': 'string', 'children': [], 'value': '""'}; {'id': '73', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'rendered_item'}
|
Render a single config item, with the provided indent
|
def sorted_filetype_items(self):
processed_types = []
file_type_items = deque(self.config['file_types'].items())
while len(file_type_items):
filetype, filetype_info = file_type_items.popleft()
requirements = filetype_info.get('requires')
if requirements is not None:
missing = [req for req in requirements
if req not in processed_types]
if missing:
file_type_items.append((filetype, filetype_info))
continue
processed_types.append(filetype)
yield filetype, filetype_info
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_filetype_items'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '25']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'processed_types'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'file_type_items'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'deque'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '24']}; {'id': '17', 'type': 'attribute', 'children': ['18', '23']}; {'id': '18', 'type': 'subscript', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'file_types'"}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'while_statement', 'children': ['26', '30']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'file_type_items'}; {'id': '30', 'type': 'block', 'children': ['31', '41', '50', '80', '87']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}; {'id': '33', 'type': 'pattern_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'filetype'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'filetype_info'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'file_type_items'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'popleft'}; {'id': '40', 'type': 'argument_list', 'children': []}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'filetype_info'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'requires'"}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is not'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55', '67']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'id': '58', 'type': 'list_comprehension', 'children': ['59', '60', '63']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '63', 'type': 'if_clause', 'children': ['64']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not in'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'processed_types'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'id': '69', 'type': 'block', 'children': ['70', '79']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'file_type_items'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'tuple', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'filetype'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'filetype_info'}; {'id': '79', 'type': 'continue_statement', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'processed_types'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'filetype'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'yield', 'children': ['89']}; {'id': '89', 'type': 'expression_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'filetype'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'filetype_info'}
|
Sort the instance's filetypes in using order.
|
def init(cls, *args, **kwargs):
instance = cls()
instance._values.update(dict(*args, **kwargs))
return instance
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'init'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '31']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '_values'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '29']}; {'id': '27', 'type': 'list_splat', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '29', 'type': 'dictionary_splat', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'instance'}
|
Initialize the config like as you would a regular dict.
|
def copy(self):
c = matrix()
c.tt = self.tt.copy()
c.n = self.n.copy()
c.m = self.m.copy()
return c
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '24', '36', '48']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '11', 'type': 'argument_list', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'tt'}; {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tt'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'return_statement', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'c'}
|
Creates a copy of the TT-matrix
|
def calculate_grid(self):
if self.grid is None:
self.grid = self.get_wellseries(self.get_grid())
if self.grid_transposed is None:
self.grid_transposed = self.get_wellseries(
self.transpose(
self.get_grid()))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'calculate_grid'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '28']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_wellseries'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_grid'}; {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '34']}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': 'is'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'grid_transposed'}; {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'grid_transposed'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_wellseries'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'transpose'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_grid'}; {'id': '54', 'type': 'argument_list', 'children': []}
|
Calculates and stores grid structure
|
def compute(self, write_to_tar=True):
data = self._get_all_data(self.start_date, self.end_date)
logging.info('Computing timeseries for {0} -- '
'{1}.'.format(self.start_date, self.end_date))
full, full_dt = self._compute_full_ts(data)
full_out = self._full_to_yearly_ts(full, full_dt)
reduced = self._apply_all_time_reductions(full_out)
logging.info("Writing desired gridded outputs to disk.")
for dtype_time, data in reduced.items():
data = _add_metadata_as_attrs(data, self.var.units,
self.var.description,
self.dtype_out_vert)
self.save(data, dtype_time, dtype_out_vert=self.dtype_out_vert,
save_files=True, write_to_tar=write_to_tar)
return self
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'write_to_tar'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23', '42', '53', '63', '72', '79', '128']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': '_get_all_data'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'start_date'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'end_date'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'Computing timeseries for {0} -- '"}; {'id': '33', 'type': 'string', 'children': [], 'value': "'{1}.'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'start_date'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'end_date'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'pattern_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'full_dt'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_compute_full_ts'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'full_out'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_full_to_yearly_ts'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'full_dt'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'reduced'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': '_apply_all_time_reductions'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'full_out'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"Writing desired gridded outputs to disk."'}; {'id': '79', 'type': 'for_statement', 'children': ['80', '83', '88']}; {'id': '80', 'type': 'pattern_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dtype_time'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'reduced'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '87', 'type': 'argument_list', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89', '109']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': '_add_metadata_as_attrs'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '101', '106']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'dtype_out_vert'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116', '117', '122', '125']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dtype_time'}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dtype_out_vert'}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'dtype_out_vert'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'save_files'}; {'id': '124', 'type': 'True', 'children': []}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'write_to_tar'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'write_to_tar'}; {'id': '128', 'type': 'return_statement', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}
|
Perform all desired calculations on the data and save externally.
|
def unsubscribe(self, topic):
if self.sock == NC.INVALID_SOCKET:
return NC.ERR_NO_CONN
self.logger.info("UNSUBSCRIBE: %s", topic)
return self.send_unsubscribe(False, [utf8encode(topic)])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unsubscribe'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '30']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '=='}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'INVALID_SOCKET'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ERR_NO_CONN'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"UNSUBSCRIBE: %s"'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'send_unsubscribe'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'False', 'children': []}; {'id': '37', 'type': 'list', 'children': ['38'], 'value': '[utf8encode(topic)]'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'utf8encode'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'topic'}
|
Unsubscribe to some topic.
|
def run_after_async(seconds, func, *args, **kwargs):
t = Timer(seconds, func, args, kwargs)
t.daemon = True
t.start()
return t
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_after_async'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seconds'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '21', '27', '33']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Timer'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '20']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'seconds'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'daemon'}; {'id': '26', 'type': 'True', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 't'}
|
Run the function after seconds asynchronously.
|
async def log_source(self, **params):
if params.get("message"):
params = json.loads(params.get("message", "{}"))
if not params:
return {"error":400, "reason":"Missed required fields"}
database = client[settings.DBNAME]
source_collection = database[settings.SOURCE]
await source_collection.update({"public_key":params.get("public_key")},
{"$addToSet":{"source":params.get("source")}},
upsert=True)
return {"result": "ok"}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'log_source'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '7', 'type': 'block', 'children': ['8', '31', '43', '51', '59', '90']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '15']}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"message"'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"message"'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"{}"'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '34']}; {'id': '32', 'type': 'not_operator', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'dictionary', 'children': ['37', '40']}; {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '400'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"reason"'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"Missed required fields"'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'DBNAME'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'source_collection'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'SOURCE'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'await', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'source_collection'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '75', '87']}; {'id': '66', 'type': 'dictionary', 'children': ['67']}; {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"public_key"'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"public_key"'}; {'id': '75', 'type': 'dictionary', 'children': ['76']}; {'id': '76', 'type': 'pair', 'children': ['77', '78']}; {'id': '77', 'type': 'string', 'children': [], 'value': '"$addToSet"'}; {'id': '78', 'type': 'dictionary', 'children': ['79']}; {'id': '79', 'type': 'pair', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"source"'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"source"'}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'upsert'}; {'id': '89', 'type': 'True', 'children': []}; {'id': '90', 'type': 'return_statement', 'children': ['91']}; {'id': '91', 'type': 'dictionary', 'children': ['92']}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': '"result"'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"ok"'}
|
Logging users request sources
|
def primal_name(func, wrt):
if not isinstance(func, types.FunctionType):
raise TypeError(func)
varnames = six.get_function_code(func).co_varnames
return PRIMAL_NAME.format(func.__name__, ''.join(varnames[i] for i in wrt))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'primal_name'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'wrt'}; {'id': '6', 'type': 'block', 'children': ['7', '22', '33']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '16']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'FunctionType'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'raise_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'varnames'}; {'id': '25', 'type': 'attribute', 'children': ['26', '32']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_function_code'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'co_varnames'}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'PRIMAL_NAME'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "''"}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '46', 'type': 'generator_expression', 'children': ['47', '50']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'varnames'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'wrt'}
|
Name for the primal of a function.
|
def _clean_args(sys_argv, args):
base = [x for x in sys_argv if
x.startswith("-") or not args.datadir == os.path.abspath(os.path.expanduser(x))]
base = [x for x in base if x not in set(["--minimize-disk"])]
if "--nodata" in base:
base.remove("--nodata")
else:
base.append("--data")
return base
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_clean_args'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sys_argv'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'block', 'children': ['7', '43', '59', '80']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '12', '15']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sys_argv'}; {'id': '15', 'type': 'if_clause', 'children': ['16']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '23'], 'value': 'or'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '=='}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'datadir'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}; {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '48', '51']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '51', 'type': 'if_clause', 'children': ['52']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'not in'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'list', 'children': ['58'], 'value': '["--minimize-disk"]'}; {'id': '58', 'type': 'string', 'children': [], 'value': '"--minimize-disk"'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63', '71']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}; {'id': '61', 'type': 'string', 'children': [], 'value': '"--nodata"'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"--nodata"'}; {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'string', 'children': [], 'value': '"--data"'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'base'}
|
Remove data directory from arguments to pass to upgrade function.
|
def rmrf(items, verbose=True):
"Silently remove a list of directories or files"
if isinstance(items, str):
items = [items]
for item in items:
if verbose:
print("Removing {}".format(item))
shutil.rmtree(item, ignore_errors=True)
try:
os.remove(item)
except FileNotFoundError:
pass
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rmrf'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '23']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': '"Silently remove a list of directories or files"'}; {'id': '11', 'type': 'if_statement', 'children': ['12', '17']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '21', 'type': 'list', 'children': ['22'], 'value': '[items]'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '26', 'type': 'block', 'children': ['27', '40', '50']}; {'id': '27', 'type': 'if_statement', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"Removing {}"'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '49', 'type': 'True', 'children': []}; {'id': '50', 'type': 'try_statement', 'children': ['51', '59']}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '59', 'type': 'except_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'pass_statement', 'children': []}
|
Silently remove a list of directories or files
|
def draw(self):
self.context.set_line_cap(cairo.LINE_CAP_SQUARE)
self.context.save()
self.context.rectangle(*self.rect)
self.context.clip()
cell_borders = CellBorders(self.cell_attributes, self.key, self.rect)
borders = list(cell_borders.gen_all())
borders.sort(key=attrgetter('width', 'color'))
for border in borders:
border.draw(self.context)
self.context.restore()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '17', '25', '37', '45', '60', '71', '84', '97']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'set_line_cap'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'cairo'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'LINE_CAP_SQUARE'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '24']}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '32']}; {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'rectangle'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'list_splat', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '44']}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'clip'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cell_borders'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'CellBorders'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54', '57']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cell_attributes'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'borders'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cell_borders'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'gen_all'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'borders'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'attrgetter'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'width'"}; {'id': '83', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'border'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'borders'}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'border'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'draw'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '104']}; {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'restore'}; {'id': '104', 'type': 'argument_list', 'children': []}
|
Draws cell border to context
|
def ls(obj=None):
if obj is None:
import builtins
all = builtins.__dict__.copy()
all.update(globals())
objlst = sorted(conf.layers, key=lambda x:x.__name__)
for o in objlst:
print("%-10s : %s" %(o.__name__,o.name))
else:
if isinstance(obj, type) and issubclass(obj, Packet):
for f in obj.fields_desc:
print("%-10s : %-20s = (%s)" % (f.name, f.__class__.__name__, repr(f.default)))
elif isinstance(obj, Packet):
for f in obj.fields_desc:
print("%-10s : %-20s = %-15s (%s)" % (f.name, f.__class__.__name__, repr(getattr(obj,f.name)), repr(f.default)))
if not isinstance(obj.payload, NoPayload):
print("--")
ls(obj.payload)
else:
print("Not a packet class. Type 'ls()' to list packet classes.")
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ls'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '69']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '16', '26', '35', '52']}; {'id': '13', 'type': 'import_statement', 'children': ['14']}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'builtins'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'builtins'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'globals'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'objlst'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'lambda', 'children': ['47', '49']}; {'id': '47', 'type': 'lambda_parameters', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'objlst'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '%'}; {'id': '61', 'type': 'string', 'children': [], 'value': '"%-10s : %s"'}; {'id': '62', 'type': 'tuple', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'if_statement', 'children': ['72', '83', '111', '177']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '78'], 'value': 'and'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'Packet'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '89']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'fields_desc'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'}; {'id': '95', 'type': 'string', 'children': [], 'value': '"%-10s : %-20s = (%s)"'}; {'id': '96', 'type': 'tuple', 'children': ['97', '100', '105']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '111', 'type': 'elif_clause', 'children': ['112', '117']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'Packet'}; {'id': '117', 'type': 'block', 'children': ['118', '155']}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '123']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'fields_desc'}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'}; {'id': '129', 'type': 'string', 'children': [], 'value': '"%-10s : %-20s = %-15s (%s)"'}; {'id': '130', 'type': 'tuple', 'children': ['131', '134', '139', '149']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '155', 'type': 'if_statement', 'children': ['156', '164']}; {'id': '156', 'type': 'not_operator', 'children': ['157']}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'NoPayload'}; {'id': '164', 'type': 'block', 'children': ['165', '170']}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}; {'id': '169', 'type': 'string', 'children': [], 'value': '"--"'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ls'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179']}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'string', 'children': [], 'value': '"Not a packet class. Type \'ls()\' to list packet classes."'}
|
List available layers, or infos on a given layer
|
def generate_sample_json():
check = EpubCheck(samples.EPUB3_VALID)
with open(samples.RESULT_VALID, 'wb') as jsonfile:
jsonfile.write(check._stdout)
check = EpubCheck(samples.EPUB3_INVALID)
with open(samples.RESULT_INVALID, 'wb') as jsonfile:
jsonfile.write(check._stdout)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_sample_json'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '14', '37', '46']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'EpubCheck'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'EPUB3_VALID'}; {'id': '14', 'type': 'with_statement', 'children': ['15', '27']}; {'id': '15', 'type': 'with_clause', 'children': ['16']}; {'id': '16', 'type': 'with_item', 'children': ['17']}; {'id': '17', 'type': 'as_pattern', 'children': ['18', '25']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'RESULT_VALID'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '25', 'type': 'as_pattern_target', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'jsonfile'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'jsonfile'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_stdout'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'EpubCheck'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'EPUB3_INVALID'}; {'id': '46', 'type': 'with_statement', 'children': ['47', '59']}; {'id': '47', 'type': 'with_clause', 'children': ['48']}; {'id': '48', 'type': 'with_item', 'children': ['49']}; {'id': '49', 'type': 'as_pattern', 'children': ['50', '57']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'RESULT_INVALID'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '57', 'type': 'as_pattern_target', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'jsonfile'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'jsonfile'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_stdout'}
|
Generate sample json data for testing
|
def plot_cable_length(stats, plotpath):
f, axarr = plt.subplots(2, 2, sharex=True)
stats.hist(column=['Length of MV overhead lines'], bins=5, alpha=0.5, ax=axarr[0, 0])
stats.hist(column=['Length of MV underground cables'], bins=5, alpha=0.5, ax=axarr[0, 1])
stats.hist(column=['Length of LV overhead lines'], bins=5, alpha=0.5, ax=axarr[1, 0])
stats.hist(column=['Length of LV underground cables'], bins=5, alpha=0.5, ax=axarr[1, 1])
plt.savefig(os.path.join(plotpath,
'Histogram_cable_line_length.pdf'))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_cable_length'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'plotpath'}; {'id': '6', 'type': 'block', 'children': ['7', '22', '44', '66', '88', '110']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}; {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'axarr'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'subplots'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}; {'id': '17', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sharex'}; {'id': '21', 'type': 'True', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '32', '35', '38']}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '30', 'type': 'list', 'children': ['31'], 'value': "['Length of MV overhead lines']"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'Length of MV overhead lines'"}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '37', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '40', 'type': 'subscript', 'children': ['41', '42', '43']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'axarr'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '54', '57', '60']}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '52', 'type': 'list', 'children': ['53'], 'value': "['Length of MV underground cables']"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'Length of MV underground cables'"}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '59', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64', '65']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'axarr'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '76', '79', '82']}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '74', 'type': 'list', 'children': ['75'], 'value': "['Length of LV overhead lines']"}; {'id': '75', 'type': 'string', 'children': [], 'value': "'Length of LV overhead lines'"}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '81', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'axarr'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '98', '101', '104']}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '96', 'type': 'list', 'children': ['97'], 'value': "['Length of LV underground cables']"}; {'id': '97', 'type': 'string', 'children': [], 'value': "'Length of LV underground cables'"}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '103', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108', '109']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'axarr'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'savefig'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '122']}; {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'plotpath'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'Histogram_cable_line_length.pdf'"}
|
Cable length per MV grid district
|
def _structure_union(self, obj, union):
union_params = union.__args__
if NoneType in union_params:
if obj is None:
return None
if len(union_params) == 2:
other = (
union_params[0]
if union_params[1] is NoneType
else union_params[1]
)
return self._structure_func.dispatch(other)(obj, other)
handler = self._union_registry.get(union)
if handler is not None:
return handler(obj, union)
cl = self._dis_func_cache(union)(obj)
return self._structure_func.dispatch(cl)(obj, cl)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_structure_union'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '63', '74', '85', '97']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'union_params'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '__args__'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'NoneType'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'union_params'}; {'id': '18', 'type': 'block', 'children': ['19', '26']}; {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '33']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '=='}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'union_params'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '33', 'type': 'block', 'children': ['34', '50']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '37', 'type': '()', 'children': ['38']}; {'id': '38', 'type': 'conditional_expression', 'children': ['39', '42', '47'], 'value': 'if'}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'union_params'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'is'}; {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'union_params'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'NoneType'}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'union_params'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'return_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '60']}; {'id': '52', 'type': 'call', 'children': ['53', '58']}; {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_structure_func'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dispatch'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '66', 'type': 'call', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_union_registry'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is not'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'cl'}; {'id': '88', 'type': 'call', 'children': ['89', '95']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_dis_func_cache'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '97', 'type': 'return_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '107']}; {'id': '99', 'type': 'call', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': '_structure_func'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dispatch'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cl'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cl'}
|
Deal with converting a union.
|
def collect_ansible_classes():
def trace_calls(frame, event, arg):
if event != 'call':
return
try:
_locals = inspect.getargvalues(frame).locals
if 'self' not in _locals:
return
_class = _locals['self'].__class__
_class_repr = repr(_class)
if 'ansible' not in _class_repr:
return
ANSIBLE_CLASSES[_class] = True
except (AttributeError, TypeError):
pass
print "Gathering classes"
sys.settrace(trace_calls)
main()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect_ansible_classes'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '70', '72', '79']}; {'id': '5', 'type': 'function_definition', 'children': ['6', '7', '11']}; {'id': '6', 'type': 'function_name', 'children': [], 'value': 'trace_calls'}; {'id': '7', 'type': 'parameters', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '11', 'type': 'block', 'children': ['12', '18']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': '!='}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '15', 'type': 'string', 'children': [], 'value': "'call'"}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': []}; {'id': '18', 'type': 'try_statement', 'children': ['19', '64']}; {'id': '19', 'type': 'block', 'children': ['20', '31', '37', '45', '52', '58']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_locals'}; {'id': '23', 'type': 'attribute', 'children': ['24', '30']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'getargvalues'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'not in'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'self'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_locals'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': []}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_locals'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'self'"}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': '_class_repr'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'not in'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'ansible'"}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_class_repr'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'return_statement', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ANSIBLE_CLASSES'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '63', 'type': 'True', 'children': []}; {'id': '64', 'type': 'except_clause', 'children': ['65', '68']}; {'id': '65', 'type': 'tuple', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'pass_statement', 'children': []}; {'id': '70', 'type': 'print_statement', 'children': ['71']}; {'id': '71', 'type': 'string', 'children': [], 'value': '"Gathering classes"'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'settrace'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'trace_calls'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'main'}; {'id': '82', 'type': 'argument_list', 'children': []}
|
Run playbook and collect classes of ansible that are run.
|
def _or_query(self, term_list, field, field_type):
term_list = [self._term_query(term, field, field_type) for term in term_list]
return xapian.Query(xapian.Query.OP_OR, term_list)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_or_query'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'term_list'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'field_type'}; {'id': '8', 'type': 'block', 'children': ['9', '24']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'term_list'}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '21']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_term_query'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'field_type'}; {'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'term_list'}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'xapian'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Query'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'xapian'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Query'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'OP_OR'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'term_list'}
|
Joins each item of term_list decorated by _term_query with an OR.
|
def _merge_lib_dict(d1, d2):
for required, requirings in d2.items():
if required in d1:
d1[required].update(requirings)
else:
d1[required] = requirings
return None
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_merge_lib_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'd2'}; {'id': '6', 'type': 'block', 'children': ['7', '39']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '11', '16']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'required'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'requirings'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'd2'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21', '31']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'required'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'required'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'requirings'}; {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'required'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'requirings'}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'None', 'children': []}
|
Merges lib_dict `d2` into lib_dict `d1`
|
def provides_defaults_for(self, rule: 'Rule', **values: Any) -> bool:
defaults_match = all(
values[key] == self.defaults[key] for key in self.defaults if key in values
)
return self != rule and bool(self.defaults) and defaults_match
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'provides_defaults_for'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'Rule'"}; {'id': '9', 'type': 'typed_parameter', 'children': ['10', '12']}; {'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '16', 'type': 'block', 'children': ['17', '41']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'defaults_match'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '22', 'type': 'generator_expression', 'children': ['23', '32', '37']}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '37', 'type': 'if_clause', 'children': ['38']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'in'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '53'], 'value': 'and'}; {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '!='}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'defaults_match'}
|
Returns true if this rule provides defaults for the argument and values.
|
def home(self):
self.command(c.LCD_RETURNHOME)
self._cursor_pos = (0, 0)
c.msleep(2)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'home'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '23']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'LCD_RETURNHOME'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_cursor_pos'}; {'id': '20', 'type': 'tuple', 'children': ['21', '22']}; {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'msleep'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'integer', 'children': [], 'value': '2'}
|
Set cursor to initial position and reset any shifting.
|
def on_episode_end(self, episode, logs={}):
for callback in self.callbacks:
if callable(getattr(callback, 'on_episode_end', None)):
callback.on_episode_end(episode, logs=logs)
else:
callback.on_epoch_end(episode, logs=logs)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'on_episode_end'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'episode'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '8', 'type': 'dictionary', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'callbacks'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '26', '37']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'on_episode_end'"}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'on_episode_end'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'episode'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'on_epoch_end'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'episode'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'logs'}
|
Called at end of each episode for each callback in callbackList
|
def _load(self, keyframe=True):
if self._cached:
return
pages = self.pages
if not pages:
return
if not self._indexed:
self._seek(-1)
if not self._cache:
return
fh = self.parent.filehandle
if keyframe is not None:
keyframe = self._keyframe
for i, page in enumerate(pages):
if isinstance(page, inttypes):
fh.seek(page)
page = self._tiffpage(self.parent, index=i, keyframe=keyframe)
pages[i] = page
self._cached = True
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_load'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'keyframe'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '15', '21', '26', '40', '47', '55', '66', '112']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_cached'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '21', 'type': 'if_statement', 'children': ['22', '24']}; {'id': '22', 'type': 'not_operator', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '31']}; {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_indexed'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_seek'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '45']}; {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_cache'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'return_statement', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filehandle'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is not'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'keyframe'}; {'id': '58', 'type': 'None', 'children': []}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'keyframe'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': '_keyframe'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '70', '74']}; {'id': '67', 'type': 'pattern_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'inttypes'}; {'id': '81', 'type': 'block', 'children': ['82', '89', '106']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': '_tiffpage'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '100', '103']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'keyframe'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'keyframe'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '111']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'pages'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_cached'}; {'id': '117', 'type': 'True', 'children': []}
|
Read all remaining pages from file.
|
def query_jobs_schedule(repo_name, revision, auth):
url = "%s/%s/rev/%s?format=json" % (SELF_SERVE, repo_name, revision)
LOG.debug("About to fetch %s" % url)
req = requests.get(url, auth=auth, timeout=TCP_TIMEOUT)
if req.status_code not in [200]:
return []
return req.json()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query_jobs_schedule'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '26', '41', '51']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '11', 'type': 'binary_operator', 'children': ['12', '13'], 'value': '%'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"%s/%s/rev/%s?format=json"'}; {'id': '13', 'type': 'tuple', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SELF_SERVE'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'LOG'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '%'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"About to fetch %s"'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '38']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'TCP_TIMEOUT'}; {'id': '41', 'type': 'if_statement', 'children': ['42', '48']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'not in'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '46', 'type': 'list', 'children': ['47'], 'value': '[200]'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '56', 'type': 'argument_list', 'children': []}
|
Query Buildapi for jobs.
|
def toggle_highlighting(self, state):
if self.editor is not None:
if state:
self.highlight_matches()
else:
self.clear_matches()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'toggle_highlighting'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'is not'}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'editor'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '16', '23']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'highlight_matches'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'else_clause', 'children': ['24']}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'clear_matches'}; {'id': '30', 'type': 'argument_list', 'children': []}
|
Toggle the 'highlight all results' feature
|
def setup(cfg):
this_module = sys.modules[__name__]
for name, value in cfg.items():
if hasattr(this_module, name):
setattr(this_module, name, value)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '5', 'type': 'block', 'children': ['6', '14']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'this_module'}; {'id': '9', 'type': 'subscript', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '23']}; {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'this_module'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'this_module'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}
|
set up the global configuration from an object
|
def edit(self):
if platform.system().lower() == 'windows':
os.startfile(str(self.config_file))
else:
if platform.system().lower() == 'darwin':
call = 'open'
else:
call = 'xdg-open'
subprocess.call([call, self.config_file])
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'edit'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '18', '31']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '17'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '16']}; {'id': '9', 'type': 'attribute', 'children': ['10', '15']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'string', 'children': [], 'value': "'windows'"}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'startfile'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33', '56']}; {'id': '33', 'type': 'if_statement', 'children': ['34', '45', '50']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '44'], 'value': '=='}; {'id': '35', 'type': 'call', 'children': ['36', '43']}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'string', 'children': [], 'value': "'darwin'"}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'open'"}; {'id': '50', 'type': 'else_clause', 'children': ['51']}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'xdg-open'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'list', 'children': ['63', '64'], 'value': '[call, self.config_file]'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'config_file'}
|
Edit file with default os application.
|
def save_model(model, output_file):
if not output_file:
return
with open(output_file, 'wb') as f:
pickle.dump(model, f)
print("Saved model to file '{}'.".format(output_file))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_model'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_file'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '32']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'output_file'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': []}; {'id': '12', 'type': 'with_statement', 'children': ['13', '23']}; {'id': '13', 'type': 'with_clause', 'children': ['14']}; {'id': '14', 'type': 'with_item', 'children': ['15']}; {'id': '15', 'type': 'as_pattern', 'children': ['16', '21']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'output_file'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '21', 'type': 'as_pattern_target', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Saved model to file \'{}\'."'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'output_file'}
|
Save model to output_file, if given
|
def fit_transform(self, input, **fit_kwargs):
self.fit(input, **fit_kwargs)
X = self.transform(input)
return X
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit_transform'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fit_kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '27']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'fit'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '16', 'type': 'dictionary_splat', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fit_kwargs'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'transform'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'X'}
|
Execute fit and transform in sequence.
|
def _dhash(self, params):
m = hashlib.new('md5')
m.update(self.hash.encode('utf-8'))
for key in sorted(params.keys()):
h_string = ('%s-%s' % (key, params[key])).encode('utf-8')
m.update(h_string)
return m.hexdigest()
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_dhash'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '30', '64']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hashlib'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'md5'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '40']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41', '57']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'h_string'}; {'id': '44', 'type': 'call', 'children': ['45', '55']}; {'id': '45', 'type': 'attribute', 'children': ['46', '54']}; {'id': '46', 'type': '()', 'children': ['47']}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'%s-%s'"}; {'id': '49', 'type': 'tuple', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'h_string'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'hexdigest'}; {'id': '69', 'type': 'argument_list', 'children': []}
|
Generate hash of the dictionary object.
|
def _get_files_modified():
cmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"
_, files_modified, _ = run(cmd)
extensions = [re.escape(ext) for ext in list(SUPPORTED_FILES) + [".rst"]]
test = "(?:{0})$".format("|".join(extensions))
return list(filter(lambda f: re.search(test, f), files_modified))
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_files_modified'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '9', '19', '38', '52']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"'}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '15']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'files_modified'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'extensions'}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '29']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'escape'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '31', 'type': 'binary_operator', 'children': ['32', '36'], 'value': '+'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_FILES'}; {'id': '36', 'type': 'list', 'children': ['37'], 'value': '[".rst"]'}; {'id': '37', 'type': 'string', 'children': [], 'value': '".rst"'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'string', 'children': [], 'value': '"(?:{0})$"'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"|"'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'extensions'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '69']}; {'id': '59', 'type': 'lambda', 'children': ['60', '62']}; {'id': '60', 'type': 'lambda_parameters', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'files_modified'}
|
Get the list of modified files that are Python or Jinja2.
|
def delete_collection(db_name, collection_name, host='localhost', port=27017):
client = MongoClient("mongodb://%s:%d" % (host, port))
client[db_name].drop_collection(collection_name)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete_collection'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection_name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'localhost'"}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '27017'}; {'id': '12', 'type': 'block', 'children': ['13', '24']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'MongoClient'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"mongodb://%s:%d"'}; {'id': '21', 'type': 'tuple', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'drop_collection'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'collection_name'}
|
Almost exclusively for testing.
|
def field_function(self, type_code, func_name):
assert func_name in ('to_json', 'from_json')
name = "field_%s_%s" % (type_code.lower(), func_name)
return getattr(self, name)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'field_function'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'type_code'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '26']}; {'id': '8', 'type': 'assert_statement', 'children': ['9']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'id': '11', 'type': 'tuple', 'children': ['12', '13']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'to_json'"}; {'id': '13', 'type': 'string', 'children': [], 'value': "'from_json'"}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"field_%s_%s"'}; {'id': '19', 'type': 'tuple', 'children': ['20', '25']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'type_code'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'func_name'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'}
|
Return the field function.
|
def debug_complete():
if not 'uniqueId' in request.args:
raise ExperimentError('improper_inputs')
else:
unique_id = request.args['uniqueId']
mode = request.args['mode']
try:
user = Participant.query.\
filter(Participant.uniqueid == unique_id).one()
user.status = COMPLETED
user.endhit = datetime.datetime.now()
db_session.add(user)
db_session.commit()
except:
raise ExperimentError('error_setting_worker_complete')
else:
if (mode == 'sandbox' or mode == 'live'):
return render_template('closepopup.html')
else:
return render_template('complete.html')
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'debug_complete'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5']}; {'id': '5', 'type': 'if_statement', 'children': ['6', '12', '18']}; {'id': '6', 'type': 'not_operator', 'children': ['7']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'in'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'uniqueId'"}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'raise_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ExperimentError'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'string', 'children': [], 'value': "'improper_inputs'"}; {'id': '18', 'type': 'else_clause', 'children': ['19']}; {'id': '19', 'type': 'block', 'children': ['20', '28', '36']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'unique_id'}; {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '27', 'type': 'string', 'children': [], 'value': "'uniqueId'"}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '35', 'type': 'string', 'children': [], 'value': "'mode'"}; {'id': '36', 'type': 'try_statement', 'children': ['37', '89', '96']}; {'id': '37', 'type': 'block', 'children': ['38', '58', '64', '76', '83']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '41', 'type': 'call', 'children': ['42', '57']}; {'id': '42', 'type': 'attribute', 'children': ['43', '56']}; {'id': '43', 'type': 'call', 'children': ['44', '50']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48', '49']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'Participant'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '48', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'Participant'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'uniqueid'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'unique_id'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'one'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'COMPLETED'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'endhit'}; {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'db_session'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'db_session'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '88', 'type': 'argument_list', 'children': []}; {'id': '89', 'type': 'except_clause', 'children': ['90']}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ExperimentError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'string', 'children': [], 'value': "'error_setting_worker_complete'"}; {'id': '96', 'type': 'else_clause', 'children': ['97']}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '107', '113']}; {'id': '99', 'type': '()', 'children': ['100']}; {'id': '100', 'type': 'boolean_operator', 'children': ['101', '104'], 'value': 'or'}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '103', 'type': 'string', 'children': [], 'value': "'sandbox'"}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'live'"}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'render_template'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'closepopup.html'"}; {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'render_template'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'complete.html'"}
|
Debugging route for complete.
|
def process_temperature_sensors(helper, session):
snmp_result_temp_sensor_names = helper.walk_snmp_values(
session, helper,
DEVICE_TEMPERATURE_OIDS['oid_temperature_probe_location'], "temperature sensors")
snmp_result_temp_sensor_states = helper.walk_snmp_values(
session, helper,
DEVICE_TEMPERATURE_OIDS['oid_temperature_probe_status'], "temperature sensors")
snmp_result_temp_sensor_values = helper.walk_snmp_values(
session, helper,
DEVICE_TEMPERATURE_OIDS['oid_temperature_probe_reading'], "temperature sensors")
for i, _result in enumerate(snmp_result_temp_sensor_states):
helper.update_status(
helper, probe_check(snmp_result_temp_sensor_names[i],
snmp_result_temp_sensor_states[i], "Temperature sensor"))
if i < len(snmp_result_temp_sensor_values):
helper.add_metric(label=snmp_result_temp_sensor_names[i] + " -Celsius-",
value=float(snmp_result_temp_sensor_values[i]) / 10)
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_temperature_sensors'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '35', '49']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_names'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'walk_snmp_values'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17', '20']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '17', 'type': 'subscript', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'DEVICE_TEMPERATURE_OIDS'}; {'id': '19', 'type': 'string', 'children': [], 'value': "'oid_temperature_probe_location'"}; {'id': '20', 'type': 'string', 'children': [], 'value': '"temperature sensors"'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_states'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'walk_snmp_values'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31', '34']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'DEVICE_TEMPERATURE_OIDS'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'oid_temperature_probe_status'"}; {'id': '34', 'type': 'string', 'children': [], 'value': '"temperature sensors"'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_values'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'walk_snmp_values'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45', '48']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'DEVICE_TEMPERATURE_OIDS'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'oid_temperature_probe_reading'"}; {'id': '48', 'type': 'string', 'children': [], 'value': '"temperature sensors"'}; {'id': '49', 'type': 'for_statement', 'children': ['50', '53', '57']}; {'id': '50', 'type': 'pattern_list', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_result'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_states'}; {'id': '57', 'type': 'block', 'children': ['58', '75']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'update_status'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'probe_check'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '71', '74']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_names'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_states'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '74', 'type': 'string', 'children': [], 'value': '"Temperature sensor"'}; {'id': '75', 'type': 'if_statement', 'children': ['76', '82']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '<'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_values'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'add_metric'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '96']}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '91', 'type': 'binary_operator', 'children': ['92', '95'], 'value': '+'}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_names'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '95', 'type': 'string', 'children': [], 'value': '" -Celsius-"'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '105'], 'value': '/'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'snmp_result_temp_sensor_values'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '105', 'type': 'integer', 'children': [], 'value': '10'}
|
process the temperature sensors
|
def _set_overlay_verify(name, overlay_path, config_path):
global DEBUG
if os.path.exists(config_path):
print("Config path already exists! Not moving forward")
print("config_path: {0}".format(config_path))
return -1
os.makedirs(config_path)
with open(config_path + "/dtbo", 'wb') as outfile:
with open(overlay_path, 'rb') as infile:
shutil.copyfileobj(infile, outfile)
time.sleep(0.2)
if name == "CUST":
return 0
elif name == "PWM0":
if os.path.exists(PWMSYSFSPATH):
if DEBUG:
print("PWM IS LOADED!")
return 0
else:
if DEBUG:
print("ERROR LOAIDNG PWM0")
return 1
elif name == "SPI2":
if os.listdir(SPI2SYSFSPATH) != "":
if DEBUG:
print("SPI2 IS LOADED!")
return 0
else:
if DEBUG:
print("ERROR LOADING SPI2")
return 0
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_overlay_verify'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'overlay_path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '7', 'type': 'block', 'children': ['8', '10', '38', '45', '79', '86']}; {'id': '8', 'type': 'global_statement', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '19']}; {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '19', 'type': 'block', 'children': ['20', '25', '35']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"Config path already exists! Not moving forward"'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'string', 'children': [], 'value': '"config_path: {0}"'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '45', 'type': 'with_statement', 'children': ['46', '58']}; {'id': '46', 'type': 'with_clause', 'children': ['47']}; {'id': '47', 'type': 'with_item', 'children': ['48']}; {'id': '48', 'type': 'as_pattern', 'children': ['49', '56']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '55']}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '+'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'config_path'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"/dtbo"'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '56', 'type': 'as_pattern_target', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'with_statement', 'children': ['60', '70']}; {'id': '60', 'type': 'with_clause', 'children': ['61']}; {'id': '61', 'type': 'with_item', 'children': ['62']}; {'id': '62', 'type': 'as_pattern', 'children': ['63', '68']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'overlay_path'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '68', 'type': 'as_pattern_target', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'copyfileobj'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'infile'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'outfile'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'float', 'children': [], 'value': '0.2'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90', '93', '130']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '89', 'type': 'string', 'children': [], 'value': '"CUST"'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'return_statement', 'children': ['92']}; {'id': '92', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '93', 'type': 'elif_clause', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"PWM0"'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '107', '118']}; {'id': '99', 'type': 'call', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'PWMSYSFSPATH'}; {'id': '107', 'type': 'block', 'children': ['108', '116']}; {'id': '108', 'type': 'if_statement', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'string', 'children': [], 'value': '"PWM IS LOADED!"'}; {'id': '116', 'type': 'return_statement', 'children': ['117']}; {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'else_clause', 'children': ['119']}; {'id': '119', 'type': 'block', 'children': ['120', '128']}; {'id': '120', 'type': 'if_statement', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'string', 'children': [], 'value': '"ERROR LOAIDNG PWM0"'}; {'id': '128', 'type': 'return_statement', 'children': ['129']}; {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'elif_clause', 'children': ['131', '134']}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '=='}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '133', 'type': 'string', 'children': [], 'value': '"SPI2"'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'if_statement', 'children': ['136', '144', '155']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '143'], 'value': '!='}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'SPI2SYSFSPATH'}; {'id': '143', 'type': 'string', 'children': [], 'value': '""'}; {'id': '144', 'type': 'block', 'children': ['145', '153']}; {'id': '145', 'type': 'if_statement', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'string', 'children': [], 'value': '"SPI2 IS LOADED!"'}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '155', 'type': 'else_clause', 'children': ['156']}; {'id': '156', 'type': 'block', 'children': ['157', '165']}; {'id': '157', 'type': 'if_statement', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'string', 'children': [], 'value': '"ERROR LOADING SPI2"'}; {'id': '165', 'type': 'return_statement', 'children': ['166']}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}
|
_set_overlay_verify - Function to load the overlay and verify it was setup properly
|
def to_json(df, columns, confidence={}):
records = []
display_cols = list(columns.keys())
if not display_cols:
display_cols = list(df.columns)
bounds = {}
for c in confidence:
bounds[c] = {
"min": df[confidence[c]["lower"]].min(),
"max": df[confidence[c]["upper"]].max(),
"lower": confidence[c]["lower"],
"upper": confidence[c]["upper"]
}
labels = {}
for c in display_cols:
if "label" in columns[c]:
labels[c] = columns[c]["label"]
else:
labels[c] = c
for i, row in df.iterrows():
row_ = DataTable.format_row(row, bounds, columns)
records.append({labels[c]: row_[c] for c in display_cols})
return {
"data": records,
"columns": [{"data": labels[c]} for c in display_cols]
}
|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'confidence'}; {'id': '8', 'type': 'dictionary', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '14', '25', '38', '42', '92', '96', '125', '163']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'display_cols'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'if_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'display_cols'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'display_cols'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'confidence'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '51', 'type': 'dictionary', 'children': ['52', '65', '78', '85']}; {'id': '52', 'type': 'pair', 'children': ['53', '54']}; {'id': '53', 'type': 'string', 'children': [], 'value': '"min"'}; {'id': '54', 'type': 'call', 'children': ['55', '64']}; {'id': '55', 'type': 'attribute', 'children': ['56', '63']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '58', 'type': 'subscript', 'children': ['59', '62']}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'confidence'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"lower"'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '64', 'type': 'argument_list', 'children': []}; {'id': '65', 'type': 'pair', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': '"max"'}; {'id': '67', 'type': 'call', 'children': ['68', '77']}; {'id': '68', 'type': 'attribute', 'children': ['69', '76']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'confidence'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '75', 'type': 'string', 'children': [], 'value': '"upper"'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': '"lower"'}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'confidence'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '84', 'type': 'string', 'children': [], 'value': '"lower"'}; {'id': '85', 'type': 'pair', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"upper"'}; {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'confidence'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '91', 'type': 'string', 'children': [], 'value': '"upper"'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '95', 'type': 'dictionary', 'children': []}; {'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'display_cols'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '106', '117']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'in'}; {'id': '102', 'type': 'string', 'children': [], 'value': '"label"'}; {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '112']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '112', 'type': 'subscript', 'children': ['113', '116']}; {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"label"'}; {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '124']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '125', 'type': 'for_statement', 'children': ['126', '129', '134']}; {'id': '126', 'type': 'pattern_list', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'iterrows'}; {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135', '146']}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'row_'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'DataTable'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'format_row'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144', '145']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'dictionary_comprehension', 'children': ['153', '160']}; {'id': '153', 'type': 'pair', 'children': ['154', '157']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'row_'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'display_cols'}; {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'dictionary', 'children': ['165', '168']}; {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"data"'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '168', 'type': 'pair', 'children': ['169', '170']}; {'id': '169', 'type': 'string', 'children': [], 'value': '"columns"'}; {'id': '170', 'type': 'list_comprehension', 'children': ['171', '177']}; {'id': '171', 'type': 'dictionary', 'children': ['172']}; {'id': '172', 'type': 'pair', 'children': ['173', '174']}; {'id': '173', 'type': 'string', 'children': [], 'value': '"data"'}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'display_cols'}
|
Transforms dataframe to properly formatted json response
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.