code
stringlengths
51
2.34k
sequence
stringlengths
1.16k
13.1k
docstring
stringlengths
11
171
def _generate_delete_sql(self, delete_keys): for key in delete_keys: app_label, sql_name = key old_node = self.from_sql_graph.nodes[key] operation = DeleteSQL(sql_name, old_node.reverse_sql, reverse_sql=old_node.sql) sql_deps = [n.key for n in self.from_sql_graph.node_map[key].children] sql_deps.append(key) self.add_sql_operation(app_label, sql_name, operation, sql_deps)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_delete_sql'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'delete_keys'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'delete_keys'}; {'id': '10', 'type': 'block', 'children': ['11', '17', '27', '42', '60', '67']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '16']}; {'id': '13', 'type': 'pattern_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sql_name'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'old_node'}; {'id': '20', 'type': 'subscript', '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': 'from_sql_graph'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'DeleteSQL'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sql_name'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'old_node'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'reverse_sql'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse_sql'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'old_node'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sql_deps'}; {'id': '45', 'type': 'list_comprehension', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '51', 'type': 'attribute', 'children': ['52', '59']}; {'id': '52', 'type': 'subscript', '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': 'from_sql_graph'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'node_map'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'children'}; {'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': 'sql_deps'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'add_sql_operation'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75', '76']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sql_name'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sql_deps'}
Generate forward delete operations for SQL items.
def endpoint_search(filter_fulltext, filter_owner_id, filter_scope): if filter_scope == "all" and not filter_fulltext: raise click.UsageError( "When searching all endpoints (--filter-scope=all, the default), " "a full-text search filter is required. Other scopes (e.g. " "--filter-scope=recently-used) may be used without specifying " "an additional filter." ) client = get_client() owner_id = filter_owner_id if owner_id: owner_id = maybe_lookup_identity_id(owner_id) search_iterator = client.endpoint_search( filter_fulltext=filter_fulltext, filter_scope=filter_scope, filter_owner_id=owner_id, ) formatted_print( search_iterator, fields=ENDPOINT_LIST_FIELDS, json_converter=iterable_response_to_dict, )
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'endpoint_search'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filter_fulltext'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter_owner_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter_scope'}; {'id': '7', 'type': 'block', 'children': ['8', '27', '33', '37', '47', '64']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '15']}; {'id': '9', 'type': 'boolean_operator', 'children': ['10', '13'], 'value': 'and'}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '=='}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'filter_scope'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"all"'}; {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'filter_fulltext'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'raise_statement', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'UsageError'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'concatenated_string', 'children': ['23', '24', '25', '26']}; {'id': '23', 'type': 'string', 'children': [], 'value': '"When searching all endpoints (--filter-scope=all, the default), "'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"a full-text search filter is required. Other scopes (e.g. "'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"--filter-scope=recently-used) may be used without specifying "'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"an additional filter."'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_client'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'owner_id'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'filter_owner_id'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'owner_id'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'owner_id'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'maybe_lookup_identity_id'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'owner_id'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'search_iterator'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'endpoint_search'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '58', '61']}; {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'filter_fulltext'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'filter_fulltext'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'filter_scope'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'filter_scope'}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'filter_owner_id'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'owner_id'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'formatted_print'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '69', '72']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'search_iterator'}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ENDPOINT_LIST_FIELDS'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'json_converter'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'iterable_response_to_dict'}
Executor for `globus endpoint search`
def _json_to_unicode(data): ret = {} for key, value in data.items(): if not isinstance(value, six.text_type): if isinstance(value, dict): ret[key] = _json_to_unicode(value) else: ret[key] = six.text_type(value).lower() else: ret[key] = value return ret
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_json_to_unicode'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '71']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '19']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '29', '63']}; {'id': '21', 'type': 'not_operator', 'children': ['22']}; {'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': 'value'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36', '46']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_json_to_unicode'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '53', 'type': 'call', 'children': ['54', '62']}; {'id': '54', 'type': 'attribute', 'children': ['55', '61']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'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': 'ret'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ret'}
Encode json values in unicode to match that of the API
def _is_replacement_allowed(self, s): if any(tag in s.parent_tags for tag in self.skipped_tags): return False if any(tag not in self.textflow_tags for tag in s.involved_tags): return False return True
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_is_replacement_allowed'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '41']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '21']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '10', 'type': 'generator_expression', 'children': ['11', '16']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'in'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'parent_tags'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'skipped_tags'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}; {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '38']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '27', 'type': 'generator_expression', 'children': ['28', '33']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'not in'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'textflow_tags'}; {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'involved_tags'}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'False', 'children': []}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'True', 'children': []}
Tests whether replacement is allowed on given piece of HTML text.
def unique_list(lst): uniq = [] for item in lst: if item not in uniq: uniq.append(item) return uniq
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique_list'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'lst'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '26']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'uniq'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'lst'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'not in'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'uniq'}; {'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': 'uniq'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'uniq'}
Make a list unique, retaining order of initial appearance.
def search_weekday(weekday, jd, direction, offset): return weekday_before(weekday, jd + (direction * offset))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_weekday'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'weekday'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'weekday_before'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'weekday'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '+'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '16', 'type': '()', 'children': ['17']}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '*'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'offset'}
Determine the Julian date for the next or previous weekday
def create_dcnm_in_nwk(self, tenant_id, fw_dict, is_fw_virt=False): tenant_name = fw_dict.get('tenant_name') ret = self._create_service_nwk(tenant_id, tenant_name, 'in') if ret: res = fw_const.DCNM_IN_NETWORK_CREATE_SUCCESS LOG.info("In Service network created for tenant %s", tenant_id) else: res = fw_const.DCNM_IN_NETWORK_CREATE_FAIL LOG.info("In Service network create failed for tenant %s", tenant_id) self.update_fw_db_result(tenant_id, dcnm_status=res) return ret
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_dcnm_in_nwk'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tenant_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fw_dict'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'is_fw_virt'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20', '31', '64', '74']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'tenant_name'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'fw_dict'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'tenant_name'"}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'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': '_create_service_nwk'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tenant_id'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tenant_name'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'in'"}; {'id': '31', 'type': 'if_statement', 'children': ['32', '33', '48']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '33', 'type': 'block', 'children': ['34', '40']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fw_const'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'DCNM_IN_NETWORK_CREATE_SUCCESS'}; {'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': 'LOG'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"In Service network created for tenant %s"'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tenant_id'}; {'id': '48', 'type': 'else_clause', 'children': ['49']}; {'id': '49', 'type': 'block', 'children': ['50', '56']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'fw_const'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'DCNM_IN_NETWORK_CREATE_FAIL'}; {'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': 'LOG'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"In Service network create failed for tenant %s"'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'tenant_id'}; {'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': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'update_fw_db_result'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tenant_id'}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dcnm_status'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ret'}
Create the DCNM In Network and store the result in DB.
def trigger(self, *args, **kargs): event = args[0] if isinstance(event, str) and ' ' in event: event = event.split(' ') if isinstance(event, list): for each in event: self.events[each].trigger(*args[1:], **kargs) else: self.events[event].trigger(*args[1:], **kargs)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'trigger'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'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': 'kargs'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '36']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '26']}; {'id': '17', 'type': 'boolean_operator', 'children': ['18', '23'], 'value': 'and'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42', '65']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'each'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '56']}; {'id': '49', 'type': 'attribute', 'children': ['50', '55']}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'each'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '63']}; {'id': '57', 'type': 'list_splat', 'children': ['58']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '60', 'type': 'slice', 'children': ['61', '62']}; {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'colon', 'children': []}; {'id': '63', 'type': 'dictionary_splat', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'kargs'}; {'id': '65', 'type': 'else_clause', 'children': ['66']}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '76']}; {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '83']}; {'id': '77', 'type': 'list_splat', 'children': ['78']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '80', 'type': 'slice', 'children': ['81', '82']}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'colon', 'children': []}; {'id': '83', 'type': 'dictionary_splat', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'kargs'}
Execute all event handlers with optional arguments for the observable.
def sam_parse_reply(line): parts = line.split(' ') opts = {k: v for (k, v) in split_kv(parts[2:])} return SAMReply(parts[0], opts)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sam_parse_reply'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '34']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '18', 'type': 'dictionary_comprehension', 'children': ['19', '22']}; {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '26']}; {'id': '23', 'type': 'tuple_pattern', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'split_kv'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '31', 'type': 'slice', 'children': ['32', '33']}; {'id': '32', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '33', 'type': 'colon', 'children': []}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'SAMReply'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'opts'}
parse a reply line into a dict
def hash_name(name, script_pubkey, register_addr=None): bin_name = b40_to_bin(name) name_and_pubkey = bin_name + unhexlify(script_pubkey) if register_addr is not None: name_and_pubkey += str(register_addr) return hex_hash160(name_and_pubkey)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hash_name'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'script_pubkey'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'register_addr'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '17', '26', '38']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bin_name'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'b40_to_bin'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'name_and_pubkey'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '+'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bin_name'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'unhexlify'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'script_pubkey'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is not'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'register_addr'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'augmented_assignment', 'children': ['33', '34'], 'value': '+='}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name_and_pubkey'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'register_addr'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'hex_hash160'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'name_and_pubkey'}
Generate the hash over a name and hex-string script pubkey
def _process_output(self, node, **kwargs): for n in node.nodes: self._process_node(n, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_output'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'for_statement', 'children': ['10', '11', '14']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_process_node'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '22', 'type': 'dictionary_splat', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
Processes an output node, which will contain things like `Name` and `TemplateData` nodes.
def _check_content(self, content_str): if self.do_content_check: space_ratio = float(content_str.count(' '))/len(content_str) if space_ratio > self.max_space_ratio: return "space-ratio: %f > %f" % (space_ratio, self.max_space_ratio) if len(content_str) > self.input_character_limit: return "too long: %d > %d" % (len(content_str), self.input_character_limit) return None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_content'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'content_str'}; {'id': '6', 'type': 'block', 'children': ['7', '65']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'do_content_check'}; {'id': '11', 'type': 'block', 'children': ['12', '29', '44']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'space_ratio'}; {'id': '15', 'type': 'binary_operator', 'children': ['16', '25'], 'value': '/'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'content_str'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'content_str'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '>'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'space_ratio'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'max_space_ratio'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"space-ratio: %f > %f"'}; {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'space_ratio'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'max_space_ratio'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '53']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '50'], 'value': '>'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'content_str'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'input_character_limit'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'return_statement', 'children': ['55']}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"too long: %d > %d"'}; {'id': '57', 'type': 'tuple', 'children': ['58', '62']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'content_str'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'input_character_limit'}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'None', 'children': []}
Check if the content is likely to be successfully read.
def _add_mxnet_ctc_loss(pred, seq_len, label): pred_ctc = mx.sym.Reshape(data=pred, shape=(-4, seq_len, -1, 0)) loss = mx.sym.contrib.ctc_loss(data=pred_ctc, label=label) ctc_loss = mx.sym.MakeLoss(loss) softmax_class = mx.symbol.SoftmaxActivation(data=pred) softmax_loss = mx.sym.MakeLoss(softmax_class) softmax_loss = mx.sym.BlockGrad(softmax_loss) return mx.sym.Group([softmax_loss, ctc_loss])
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_mxnet_ctc_loss'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pred'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'seq_len'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '7', 'type': 'block', 'children': ['8', '30', '48', '59', '72', '83', '94']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pred_ctc'}; {'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': 'mx'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Reshape'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '21']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pred'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '23', 'type': 'tuple', 'children': ['24', '26', '27', '29']}; {'id': '24', 'type': 'unary_operator', 'children': ['25'], 'value': '-'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'seq_len'}; {'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'loss'}; {'id': '33', 'type': 'call', 'children': ['34', '41']}; {'id': '34', 'type': 'attribute', 'children': ['35', '40']}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'mx'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'contrib'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ctc_loss'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pred_ctc'}; {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ctc_loss'}; {'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': 'mx'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'MakeLoss'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'loss'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'softmax_class'}; {'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': 'mx'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'symbol'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'SoftmaxActivation'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'pred'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'softmax_loss'}; {'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': 'mx'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'MakeLoss'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'softmax_class'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'softmax_loss'}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'mx'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'BlockGrad'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'softmax_loss'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'mx'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Group'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'list', 'children': ['103', '104'], 'value': '[softmax_loss, ctc_loss]'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'softmax_loss'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ctc_loss'}
Adds Symbol.WapCTC on top of pred symbol and returns the resulting symbol
def getavailable(self): from importlib import import_module available = [] for script in self.SCRIPTS: if have(script): available.append(script) for module in self.MODULES: try: import_module(module) available.append(module) except ImportError: pass return sorted(available)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getavailable'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '11', '15', '34', '58']}; {'id': '6', 'type': 'import_from_statement', 'children': ['7', '9']}; {'id': '7', 'type': 'dotted_name', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'importlib'}; {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'import_module'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'available'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'script'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'SCRIPTS'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'have'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'script'}; {'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': 'available'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'script'}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '39']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'MODULES'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'try_statement', 'children': ['41', '54']}; {'id': '41', 'type': 'block', 'children': ['42', '47']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'import_module'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'available'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '54', 'type': 'except_clause', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'pass_statement', 'children': []}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'available'}
Return a list of subtitle downloaders available.
def censor(self, input_text): bad_words = self.get_profane_words() res = input_text for word in bad_words: regex_string = r'{0}' if self._no_word_boundaries else r'\b{0}\b' regex_string = regex_string.format(word) regex = re.compile(regex_string, re.IGNORECASE) res = regex.sub(self._censor_char * len(word), res) return res
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'censor'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_text'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '19', '70']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'bad_words'}; {'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_profane_words'}; {'id': '14', 'type': 'argument_list', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'input_text'}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bad_words'}; {'id': '22', 'type': 'block', 'children': ['23', '32', '41', '53']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'regex_string'}; {'id': '26', 'type': 'conditional_expression', 'children': ['27', '28', '31'], 'value': 'if'}; {'id': '27', 'type': 'string', 'children': [], 'value': "r'{0}'"}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_no_word_boundaries'}; {'id': '31', 'type': 'string', 'children': [], 'value': "r'\\b{0}\\b'"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'regex_string'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'regex_string'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'regex_string'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '69']}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '*'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_censor_char'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'res'}
Returns input_text with any profane words censored.
def _current_user_manager(self, session=None): if session is None: session = db.session() try: user = g.user except Exception: return session.query(User).get(0) if sa.orm.object_session(user) is not session: return session.query(User).get(user.id) else: return user
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_current_user_manager'}; {'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': 'session'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '22', '45']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'session'}; {'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': 'session'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'try_statement', 'children': ['23', '30']}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '30', 'type': 'except_clause', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '43']}; {'id': '35', 'type': 'attribute', 'children': ['36', '42']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'User'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '56', '71']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '55'], 'value': 'is not'}; {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'orm'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'object_session'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '67']}; {'id': '59', 'type': 'attribute', 'children': ['60', '66']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'User'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'user'}
Return the current user, or SYSTEM user.
def _split_one_end(path): s = path.rsplit('/', 1) if len(s) == 1: return s[0], '' else: return tuple(s)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_split_one_end'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '5', 'type': 'block', 'children': ['6', '16']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '23', '30']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '22'], 'value': '=='}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}; {'id': '25', 'type': 'expression_list', 'children': ['26', '29']}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '29', 'type': 'string', 'children': [], 'value': "''"}; {'id': '30', 'type': 'else_clause', 'children': ['31']}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's'}
Utility function for splitting off the very end part of a path.
def body(self): for fp, need_close in self.files: try: name = os.path.basename(fp.name) except AttributeError: name = '' for chunk in self.gen_chunks(self.envelope.file_open(name)): yield chunk for chunk in self.file_chunks(fp): yield chunk for chunk in self.gen_chunks(self.envelope.file_close()): yield chunk if need_close: fp.close() for chunk in self.close(): yield chunk
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'body'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '94']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '10', '13']}; {'id': '7', 'type': 'pattern_list', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'need_close'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '13', 'type': 'block', 'children': ['14', '36', '55', '67', '85']}; {'id': '14', 'type': 'try_statement', 'children': ['15', '29']}; {'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': 'name'}; {'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': 'os'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '29', 'type': 'except_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'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': 'name'}; {'id': '35', 'type': 'string', 'children': [], 'value': "''"}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '51']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'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': 'gen_chunks'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'envelope'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'file_open'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'yield', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '63']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'file_chunks'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'yield', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '81']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'gen_chunks'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'envelope'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'file_close'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'yield', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '85', 'type': 'if_statement', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'need_close'}; {'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': 'fp'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '101']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '100', 'type': 'argument_list', 'children': []}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'yield', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'chunk'}
Yields the body of the buffered file.
def write(self, fptr): fptr.write(struct.pack('>I4s', 12, b'jP ')) fptr.write(struct.pack('>BBBB', *self.signature))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fptr'}; {'id': '6', 'type': 'block', 'children': ['7', '21']}; {'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': 'fptr'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'>I4s'"}; {'id': '19', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '20', 'type': 'string', 'children': [], 'value': "b'jP '"}; {'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': 'fptr'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'>BBBB'"}; {'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': 'signature'}
Write a JPEG 2000 Signature box to file.
def _compile_itemsort(): def is_extra(key_): return key_ is Extra def is_remove(key_): return isinstance(key_, Remove) def is_marker(key_): return isinstance(key_, Marker) def is_type(key_): return inspect.isclass(key_) def is_callable(key_): return callable(key_) priority = [(1, is_remove), (2, is_marker), (4, is_type), (3, is_callable), (5, is_extra)] def item_priority(item_): key_ = item_[0] for i, check_ in priority: if check_(key_): return i return 0 return item_priority
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_compile_itemsort'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '14', '25', '36', '48', '58', '77', '104']}; {'id': '5', 'type': 'function_definition', 'children': ['6', '7', '9']}; {'id': '6', 'type': 'function_name', 'children': [], 'value': 'is_extra'}; {'id': '7', 'type': 'parameters', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Extra'}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']}; {'id': '15', 'type': 'function_name', 'children': [], 'value': 'is_remove'}; {'id': '16', 'type': 'parameters', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Remove'}; {'id': '25', 'type': 'function_definition', 'children': ['26', '27', '29']}; {'id': '26', 'type': 'function_name', 'children': [], 'value': 'is_marker'}; {'id': '27', 'type': 'parameters', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'Marker'}; {'id': '36', 'type': 'function_definition', 'children': ['37', '38', '40']}; {'id': '37', 'type': 'function_name', 'children': [], 'value': 'is_type'}; {'id': '38', 'type': 'parameters', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isclass'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '48', 'type': 'function_definition', 'children': ['49', '50', '52']}; {'id': '49', 'type': 'function_name', 'children': [], 'value': 'is_callable'}; {'id': '50', 'type': 'parameters', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '61', 'type': 'list', 'children': ['62', '65', '68', '71', '74'], 'value': '[(1, is_remove),\n (2, is_marker),\n (4, is_type),\n (3, is_callable),\n (5, is_extra)]'}; {'id': '62', 'type': 'tuple', 'children': ['63', '64']}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'is_remove'}; {'id': '65', 'type': 'tuple', 'children': ['66', '67']}; {'id': '66', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'is_marker'}; {'id': '68', 'type': 'tuple', 'children': ['69', '70']}; {'id': '69', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'is_type'}; {'id': '71', 'type': 'tuple', 'children': ['72', '73']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'is_callable'}; {'id': '74', 'type': 'tuple', 'children': ['75', '76']}; {'id': '75', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'is_extra'}; {'id': '77', 'type': 'function_definition', 'children': ['78', '79', '81']}; {'id': '78', 'type': 'function_name', 'children': [], 'value': 'item_priority'}; {'id': '79', 'type': 'parameters', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'item_'}; {'id': '81', 'type': 'block', 'children': ['82', '88', '102']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'item_'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '92', '93']}; {'id': '89', 'type': 'pattern_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'check_'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'if_statement', 'children': ['95', '99']}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'check_'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}; {'id': '103', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'item_priority'}
return sort function of mappings
def _create(archive, compression, cmd, format, verbosity, filenames): if len(filenames) > 1: raise util.PatoolError('multi-file compression not supported in Python lzma') try: with lzma.LZMAFile(archive, mode='wb', **_get_lzma_options(format, preset=9)) as lzmafile: filename = filenames[0] with open(filename, 'rb') as srcfile: data = srcfile.read(READ_SIZE_BYTES) while data: lzmafile.write(data) data = srcfile.read(READ_SIZE_BYTES) except Exception as err: msg = "error creating %s: %s" % (archive, err) raise util.PatoolError(msg) return None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'compression'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'verbosity'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '10', 'type': 'block', 'children': ['11', '26', '119']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '18']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '17'], 'value': '>'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'PatoolError'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'multi-file compression not supported in Python lzma'"}; {'id': '26', 'type': 'try_statement', 'children': ['27', '98']}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'with_statement', 'children': ['29', '51']}; {'id': '29', 'type': 'with_clause', 'children': ['30']}; {'id': '30', 'type': 'with_item', 'children': ['31']}; {'id': '31', 'type': 'as_pattern', 'children': ['32', '49']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'lzma'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'LZMAFile'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '41']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '41', 'type': 'dictionary_splat', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_get_lzma_options'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'preset'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '49', 'type': 'as_pattern_target', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'lzmafile'}; {'id': '51', 'type': 'block', 'children': ['52', '58']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'with_statement', 'children': ['59', '69']}; {'id': '59', 'type': 'with_clause', 'children': ['60']}; {'id': '60', 'type': 'with_item', 'children': ['61']}; {'id': '61', 'type': 'as_pattern', 'children': ['62', '67']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '67', 'type': 'as_pattern_target', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'srcfile'}; {'id': '69', 'type': 'block', 'children': ['70', '79']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'srcfile'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'READ_SIZE_BYTES'}; {'id': '79', 'type': 'while_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '81', 'type': 'block', 'children': ['82', '89']}; {'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': 'lzmafile'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'srcfile'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'READ_SIZE_BYTES'}; {'id': '98', 'type': 'except_clause', 'children': ['99', '103']}; {'id': '99', 'type': 'as_pattern', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '101', 'type': 'as_pattern_target', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '103', 'type': 'block', 'children': ['104', '112']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '%'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"error creating %s: %s"'}; {'id': '109', 'type': 'tuple', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '112', 'type': 'raise_statement', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'PatoolError'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'None', 'children': []}
Create an LZMA or XZ archive with the lzma Python module.
def mkUTC(year, month, day, hour, min, sec): "similar to python's mktime but for utc" spec = [year, month, day, hour, min, sec] + [0, 0, 0] utc = time.mktime(spec) - time.timezone return utc
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mkUTC'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sec'}; {'id': '10', 'type': 'block', 'children': ['11', '13', '28', '41']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"similar to python\'s mktime but for utc"'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '24'], 'value': '+'}; {'id': '17', 'type': 'list', 'children': ['18', '19', '20', '21', '22', '23'], 'value': '[year, month, day, hour, min, sec]'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sec'}; {'id': '24', 'type': 'list', 'children': ['25', '26', '27'], 'value': '[0, 0, 0]'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'utc'}; {'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': 'time'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'mktime'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'utc'}
similar to python's mktime but for utc
def remove(self, transport): recipients = copy.copy(self.recipients) for address, recManager in recipients.items(): recManager.remove(transport) if not len(recManager.transports): del self.recipients[address]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'transport'}; {'id': '6', 'type': 'block', 'children': ['7', '18']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recipients'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'recipients'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '22', '27']}; {'id': '19', 'type': 'pattern_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'recManager'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'recipients'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'block', 'children': ['28', '35']}; {'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': 'recManager'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'transport'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '43']}; {'id': '36', 'type': 'not_operator', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'recManager'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'transports'}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'delete_statement', 'children': ['45']}; {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'recipients'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'address'}
removes a transport from all channels to which it belongs.
def project_inspect_template_path(cls, project, inspect_template): return google.api_core.path_template.expand( "projects/{project}/inspectTemplates/{inspect_template}", project=project, inspect_template=inspect_template, )
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'project_inspect_template_path'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'inspect_template'}; {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'return_statement', 'children': ['9']}; {'id': '9', 'type': 'call', 'children': ['10', '17']}; {'id': '10', 'type': 'attribute', 'children': ['11', '16']}; {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'google'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'api_core'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'path_template'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"projects/{project}/inspectTemplates/{inspect_template}"'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'inspect_template'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'inspect_template'}
Return a fully-qualified project_inspect_template string.
def get(self, key, subcommand="config:get"): cmd = ["heroku", subcommand, key, "--app", self.name] return self._result(cmd)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'subcommand'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"config:get"'}; {'id': '9', 'type': 'block', 'children': ['10', '21']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '13', 'type': 'list', 'children': ['14', '15', '16', '17', '18'], 'value': '["heroku", subcommand, key, "--app", self.name]'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"heroku"'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'subcommand'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '17', 'type': 'string', 'children': [], 'value': '"--app"'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'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': '_result'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'cmd'}
Get a app config value by name
def RemoveEventHandler(self, wb): from UcsBase import WriteUcsWarning if wb in self._wbs: self._remove_watch_block(wb) else: WriteUcsWarning("Event handler not found")
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'RemoveEventHandler'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'wb'}; {'id': '6', 'type': 'block', 'children': ['7', '12']}; {'id': '7', 'type': 'import_from_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'dotted_name', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'UcsBase'}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18', '26']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'in'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'wb'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_wbs'}; {'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': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_remove_watch_block'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'wb'}; {'id': '26', 'type': 'else_clause', 'children': ['27']}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"Event handler not found"'}
Removes an event handler.
def three_d_effect(img, **kwargs): w = kwargs.get('weight', 1) LOG.debug("Applying 3D effect with weight %.2f", w) kernel = np.array([[-w, 0, w], [-w, 1, w], [-w, 0, w]]) mode = kwargs.get('convolve_mode', 'same') def func(band_data, kernel=kernel, mode=mode, index=None): del index delay = dask.delayed(_three_d_effect_delayed)(band_data, kernel, mode) new_data = da.from_delayed(delay, shape=band_data.shape, dtype=band_data.dtype) return new_data return apply_enhancement(img.data, func, separate=True, pass_dask=True)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'three_d_effect'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '26', '50', '60', '111']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'weight'"}; {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'LOG'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"Applying 3D effect with weight %.2f"'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'list', 'children': ['35', '40', '45'], 'value': '[[-w, 0, w],\n [-w, 1, w],\n [-w, 0, w]]'}; {'id': '35', 'type': 'list', 'children': ['36', '38', '39'], 'value': '[-w, 0, w]'}; {'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '40', 'type': 'list', 'children': ['41', '43', '44'], 'value': '[-w, 1, w]'}; {'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '45', 'type': 'list', 'children': ['46', '48', '49'], 'value': '[-w, 0, w]'}; {'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'convolve_mode'"}; {'id': '59', 'type': 'string', 'children': [], 'value': "'same'"}; {'id': '60', 'type': 'function_definition', 'children': ['61', '62', '73']}; {'id': '61', 'type': 'function_name', 'children': [], 'value': 'func'}; {'id': '62', 'type': 'parameters', 'children': ['63', '64', '67', '70']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'band_data'}; {'id': '64', 'type': 'default_parameter', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '67', 'type': 'default_parameter', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '70', 'type': 'default_parameter', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '72', 'type': 'None', 'children': []}; {'id': '73', 'type': 'block', 'children': ['74', '76', '90', '109']}; {'id': '74', 'type': 'delete_statement', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'delay'}; {'id': '79', 'type': 'call', 'children': ['80', '86']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dask'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'delayed'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': '_three_d_effect_delayed'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'band_data'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'from_delayed'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99', '104']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'delay'}; {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'band_data'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'band_data'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '109', 'type': 'return_statement', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'apply_enhancement'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '118', '119', '122']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'separate'}; {'id': '121', 'type': 'True', 'children': []}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'pass_dask'}; {'id': '124', 'type': 'True', 'children': []}
Create 3D effect using convolution
def append_warning(self, msg): assert self.model is not None, "You must already have run make_model!" addendum = ('\t<span style="color:red;">(CAUTION: %s occurred when ' 'creating this page.)</span>' % msg) self.model = self.model.replace(self.title, self.title + addendum) return self.model
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_warning'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '23', '43']}; {'id': '7', 'type': 'assert_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': 'model'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'string', 'children': [], 'value': '"You must already have run make_model!"'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'addendum'}; {'id': '17', 'type': '()', 'children': ['18']}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '%'}; {'id': '19', 'type': 'concatenated_string', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': '\'\\t<span style="color:red;">(CAUTION: %s occurred when \''}; {'id': '21', 'type': 'string', 'children': [], 'value': "'creating this page.)</span>'"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'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': 'model'}; {'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': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '42'], 'value': '+'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'addendum'}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'model'}
Append a warning message to the model to expose issues.
def _start(self): self.start = time.time() self.result['start'] = str(datetime.datetime.now()) if not self.pause_type == 'prompt': print "(^C-c = continue early, ^C-a = abort)"
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_start'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '16', '33']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', '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': 'result'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '25', 'type': 'argument_list', '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': 'datetime'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'if_statement', 'children': ['34', '40']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pause_type'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'prompt'"}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'print_statement', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"(^C-c = continue early, ^C-a = abort)"'}
mark the time of execution for duration calculations later
def make_response(message, status_code, details=None): response_body = dict(message=message) if details: response_body['details'] = details response = jsonify(response_body) response.status_code = status_code return response
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_response'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '19', '28', '35', '41']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'response_body'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '19', 'type': 'if_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'response_body'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'details'"}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'details'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'jsonify'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'response_body'}; {'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': 'response'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'response'}
Make a jsonified response with specified message and status code.
def valid_modes(self): default_mode = (self.mode,) if self.mode is not None else None return getattr(self, '_valid_mode', default_mode)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'valid_modes'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '20']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'default_mode'}; {'id': '9', 'type': 'conditional_expression', 'children': ['10', '14', '19'], 'value': 'if'}; {'id': '10', 'type': 'tuple', 'children': ['11']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'is not'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'_valid_mode'"}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'default_mode'}
Valid modes of an open file
def streamify(self, state, frame): enc_tab = self._tables[1][:] untrail_len, untrail_code = enc_tab.pop(0) result = [] blocks = frame.split('\0') skip = False for i in range(len(blocks)): if skip: skip = False continue blk = blocks[i] while len(blk) >= untrail_len - 1: result.append(untrail_code + blk[:untrail_len - 1]) blk = blk[untrail_len - 1:] if (len(enc_tab) > 1 and i + 1 < len(blocks) and blocks[i + 1] == '' and len(blk) <= 30): tab = enc_tab[1] skip = True else: tab = enc_tab[0] result.append(tab[len(blk) + 1] + blk) return ''.join(result) + '\0'
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'streamify'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '7', 'type': 'block', 'children': ['8', '19', '30', '34', '43', '47', '173']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'enc_tab'}; {'id': '11', 'type': 'subscript', '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': '_tables'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '17', 'type': 'slice', 'children': ['18']}; {'id': '18', 'type': 'colon', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}; {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'untrail_len'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'untrail_code'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enc_tab'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'\\0'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '46', 'type': 'False', 'children': []}; {'id': '47', 'type': 'for_statement', 'children': ['48', '49', '56']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '56', 'type': 'block', 'children': ['57', '65', '71', '106', '157']}; {'id': '57', 'type': 'if_statement', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '59', 'type': 'block', 'children': ['60', '64']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'continue_statement', 'children': []}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '71', 'type': 'while_statement', 'children': ['72', '80']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': '>='}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '-'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'untrail_len'}; {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'block', 'children': ['81', '96']}; {'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': 'result'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'untrail_code'}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '91', 'type': 'slice', 'children': ['92', '93']}; {'id': '92', 'type': 'colon', 'children': []}; {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '-'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'untrail_len'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '101', 'type': 'slice', 'children': ['102', '105']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '-'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'untrail_len'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '105', 'type': 'colon', 'children': []}; {'id': '106', 'type': 'if_statement', 'children': ['107', '138', '149']}; {'id': '107', 'type': '()', 'children': ['108']}; {'id': '108', 'type': 'boolean_operator', 'children': ['109', '132'], 'value': 'and'}; {'id': '109', 'type': 'boolean_operator', 'children': ['110', '125'], 'value': 'and'}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '117'], 'value': 'and'}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '116'], 'value': '>'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'enc_tab'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '<'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '131'], 'value': '=='}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '+'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '131', 'type': 'string', 'children': [], 'value': "''"}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '137'], 'value': '<='}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '138', 'type': 'block', 'children': ['139', '145']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'enc_tab'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '148', 'type': 'True', 'children': []}; {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'enc_tab'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'binary_operator', 'children': ['164', '172'], 'value': '+'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '171'], 'value': '+'}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'blk'}; {'id': '173', 'type': 'return_statement', 'children': ['174']}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '181'], 'value': '+'}; {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'string', 'children': [], 'value': "''"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '181', 'type': 'string', 'children': [], 'value': "'\\0'"}
Prepare frame for output as a COBS-encoded stream.
def file_ns_handler(importer, path_item, packageName, module): subpath = os.path.join(path_item, packageName.split('.')[-1]) normalized = _normalize_cached(subpath) for item in module.__path__: if _normalize_cached(item) == normalized: break else: return subpath
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'file_ns_handler'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'importer'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path_item'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'packageName'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '8', 'type': 'block', 'children': ['9', '29', '36']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'subpath'}; {'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': 'os'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'path_item'}; {'id': '20', 'type': 'subscript', 'children': ['21', '27']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'packageName'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'normalized'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_normalize_cached'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'subpath'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '41', '51']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '__path__'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '49']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '=='}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '_normalize_cached'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'normalized'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'break_statement', 'children': []}; {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'subpath'}
Compute an ns-package subpath for a filesystem or zipfile importer
def ellipse(center,covariance_matrix,level=1, n=1000): U, s, rotation_matrix = N.linalg.svd(covariance_matrix) saxes = N.sqrt(s)*level u = N.linspace(0, 2*N.pi, n) data = N.column_stack((saxes[0]*N.cos(u), saxes[1]*N.sin(u))) return N.dot(data, rotation_matrix)+ center
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ellipse'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'covariance_matrix'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '12', 'type': 'block', 'children': ['13', '27', '38', '53', '82']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '19']}; {'id': '15', 'type': 'pattern_list', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'U'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'rotation_matrix'}; {'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': 'N'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'svd'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'covariance_matrix'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'saxes'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '37'], 'value': '*'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'linspace'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '52']}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '*'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'column_stack'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'tuple', 'children': ['62', '72']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '*'}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'saxes'}; {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cos'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '76'], 'value': '*'}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'saxes'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sin'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '82', 'type': 'return_statement', 'children': ['83']}; {'id': '83', 'type': 'binary_operator', 'children': ['84', '91'], 'value': '+'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'rotation_matrix'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'center'}
Returns error ellipse in slope-azimuth space
def _set_opt(config_dict, path, value): if value is None: return if '.' not in path: config_dict[path] = value return key, rest = path.split(".", 1) if key not in config_dict: config_dict[key] = {} _set_opt(config_dict[key], rest, value)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_opt'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config_dict'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '26', '38', '49']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'not in'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'block', 'children': ['19', '25']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'config_dict'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '25', 'type': 'return_statement', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not in'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'config_dict'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'config_dict'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'dictionary', 'children': []}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_set_opt'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56', '57']}; {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'config_dict'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'}
Set the value in the dictionary at the given path if the value is not None.
def _get_pq_array_construct(self): bus_no = integer.setResultsName("bus_no") s_rating = real.setResultsName("s_rating") v_rating = real.setResultsName("v_rating") p = real.setResultsName("p") q = real.setResultsName("q") v_max = Optional(real).setResultsName("v_max") v_min = Optional(real).setResultsName("v_min") z_conv = Optional(boolean).setResultsName("z_conv") status = Optional(boolean).setResultsName("status") pq_data = bus_no + s_rating + v_rating + p + q + v_max + \ v_min + z_conv + status + scolon pq_data.setParseAction(self.push_pq) pq_array = Literal("PQ.con") + "=" + "[" + "..." + \ ZeroOrMore(pq_data + Optional("]" + scolon)) return pq_array
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_pq_array_construct'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '24', '33', '42', '51', '63', '75', '87', '99', '122', '131', '157']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bus_no'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'integer'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"bus_no"'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 's_rating'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'string', 'children': [], 'value': '"s_rating"'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v_rating'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"v_rating"'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"p"'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"q"'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'v_max'}; {'id': '54', 'type': 'call', 'children': ['55', '61']}; {'id': '55', 'type': 'attribute', 'children': ['56', '60']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"v_max"'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'v_min'}; {'id': '66', 'type': 'call', 'children': ['67', '73']}; {'id': '67', 'type': 'attribute', 'children': ['68', '72']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"v_min"'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'z_conv'}; {'id': '78', 'type': 'call', 'children': ['79', '85']}; {'id': '79', 'type': 'attribute', 'children': ['80', '84']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'boolean'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"z_conv"'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '90', 'type': 'call', 'children': ['91', '97']}; {'id': '91', 'type': 'attribute', 'children': ['92', '96']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'boolean'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'setResultsName'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pq_data'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '121'], 'value': '+'}; {'id': '103', 'type': 'binary_operator', 'children': ['104', '120'], 'value': '+'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '119'], 'value': '+'}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '117', '118'], 'value': '+'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '116'], 'value': '+'}; {'id': '107', 'type': 'binary_operator', 'children': ['108', '115'], 'value': '+'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '114'], 'value': '+'}; {'id': '109', 'type': 'binary_operator', 'children': ['110', '113'], 'value': '+'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '+'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'bus_no'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 's_rating'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'v_rating'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'v_max'}; {'id': '117', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'v_min'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'z_conv'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'scolon'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pq_data'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'setParseAction'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'push_pq'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'pq_array'}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '145', '146'], 'value': '+'}; {'id': '135', 'type': 'binary_operator', 'children': ['136', '144'], 'value': '+'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '143'], 'value': '+'}; {'id': '137', 'type': 'binary_operator', 'children': ['138', '142'], 'value': '+'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'Literal'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'string', 'children': [], 'value': '"PQ.con"'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '143', 'type': 'string', 'children': [], 'value': '"["'}; {'id': '144', 'type': 'string', 'children': [], 'value': '"..."'}; {'id': '145', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ZeroOrMore'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '+'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'pq_data'}; {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '+'}; {'id': '155', 'type': 'string', 'children': [], 'value': '"]"'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'scolon'}; {'id': '157', 'type': 'return_statement', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'pq_array'}
Returns a construct for an array of PQ load data.
def from_genes(cls, genes: List[ExpGene]): data = [g.to_dict() for g in genes] index = [d.pop('ensembl_id') for d in data] table = cls(data, index=index) return table
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_genes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'genes'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'generic_type', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '10', 'type': 'type_parameter', 'children': ['11']}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ExpGene'}; {'id': '13', 'type': 'block', 'children': ['14', '26', '39', '49']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '17', 'type': 'list_comprehension', 'children': ['18', '23']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'genes'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '29', 'type': 'list_comprehension', 'children': ['30', '36']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'ensembl_id'"}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'table'}
Initialize instance using a list of `ExpGene` objects.
def _PartitionChunks(chunks): partitions = [[]] partition_size = 0 for chunk in chunks: cursize = len(chunk["blob_chunk"]) if (cursize + partition_size > BLOB_CHUNK_SIZE or len(partitions[-1]) >= CHUNKS_PER_INSERT): partitions.append([]) partition_size = 0 partitions[-1].append(chunk) partition_size += cursize return partitions
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_PartitionChunks'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '5', 'type': 'block', 'children': ['6', '11', '15', '71']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'partitions'}; {'id': '9', 'type': 'list', 'children': ['10'], 'value': '[[]]'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'partition_size'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '18', 'type': 'block', 'children': ['19', '28', '57', '67']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cursize'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"blob_chunk"'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '45']}; {'id': '29', 'type': '()', 'children': ['30']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '36'], 'value': 'or'}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': '>'}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '+'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cursize'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'partition_size'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'BLOB_CHUNK_SIZE'}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '44'], 'value': '>='}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'partitions'}; {'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'}; {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'CHUNKS_PER_INSERT'}; {'id': '45', 'type': 'block', 'children': ['46', '53']}; {'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': 'partitions'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'partition_size'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '65']}; {'id': '59', 'type': 'attribute', 'children': ['60', '64']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'partitions'}; {'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'augmented_assignment', 'children': ['69', '70'], 'value': '+='}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'partition_size'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cursize'}; {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'partitions'}
Groups chunks into partitions of size safe for a single INSERT.
def _check_directory_arguments(self): if not os.path.isdir(self.datapath): raise (NotADirectoryError('Directory does not exist: %s' % self.datapath)) if self.time_delay: if self.time_delay < 1: raise ValueError('Time step argument must be greater than 0, but gave: %i' % self.time_delay) if not isinstance(self.time_delay, int): raise ValueError('Time step argument must be an integer, but gave: %s' % str(self.time_delay))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_directory_arguments'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '29']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '18']}; {'id': '7', 'type': 'not_operator', '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': 'os'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'datapath'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': '()', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'NotADirectoryError'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'Directory does not exist: %s'"}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'datapath'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'time_delay'}; {'id': '33', 'type': 'block', 'children': ['34', '50']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '40']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '<'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'time_delay'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '%'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'Time step argument must be greater than 0, but gave: %i'"}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'time_delay'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '59']}; {'id': '51', 'type': 'not_operator', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'time_delay'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'raise_statement', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '%'}; {'id': '65', 'type': 'string', 'children': [], 'value': "'Time step argument must be an integer, but gave: %s'"}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'time_delay'}
Validates arguments for loading from directories, including static image and time series directories.
def printSegmentForCell(tm, cell): print "Segments for cell", cell, ":" for seg in tm.basalConnections._cells[cell]._segments: print " ", synapses = seg._synapses for s in synapses: print "%d:%g" %(s.presynapticCell,s.permanence), print
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'printSegmentForCell'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tm'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cell'}; {'id': '6', 'type': 'block', 'children': ['7', '11']}; {'id': '7', 'type': 'print_statement', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"Segments for cell"'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'cell'}; {'id': '10', 'type': 'string', 'children': [], 'value': '":"'}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '22']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '13', 'type': 'attribute', 'children': ['14', '21']}; {'id': '14', 'type': 'subscript', 'children': ['15', '20']}; {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tm'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'basalConnections'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_cells'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cell'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '_segments'}; {'id': '22', 'type': 'block', 'children': ['23', '25', '31', '45']}; {'id': '23', 'type': 'print_statement', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'synapses'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_synapses'}; {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'synapses'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'print_statement', 'children': ['36']}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '%'}; {'id': '37', 'type': 'string', 'children': [], 'value': '"%d:%g"'}; {'id': '38', 'type': 'tuple', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'presynapticCell'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'permanence'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'print'}
Print segment information for this cell
def load(self, file=None): "Read and decompress a compact script from the Pickler's file object." if file is None: file = self._file script_class = self.get_script_class() script = self._load(file, self._protocol, self._version) return script_class(script)
{'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': 'file'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '22', '30', '45']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': '"Read and decompress a compact script from the Pickler\'s file object."'}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '14', 'type': 'None', 'children': []}; {'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': 'file'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '_file'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'script_class'}; {'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': 'get_script_class'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'script'}; {'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': '_load'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_protocol'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_version'}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'script_class'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'script'}
Read and decompress a compact script from the Pickler's file object.
def overlap(self, other: 'Span'): return not ( other.column_end <= self.column_start or self.column_end <= other.column_start or other.row_end <= self.row_start or self.row_end <= other.row_start )
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'overlap'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'Span'"}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}; {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': '()', 'children': ['13']}; {'id': '13', 'type': 'boolean_operator', 'children': ['14', '37'], 'value': 'or'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '30'], 'value': 'or'}; {'id': '15', 'type': 'boolean_operator', 'children': ['16', '23'], 'value': 'or'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': '<='}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'column_end'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'column_start'}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '<='}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'column_end'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'column_start'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': '<='}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'row_end'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'row_start'}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '<='}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'row_end'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'row_start'}
Detect if two spans overlap.
def connect(self): self.client = smtplib.SMTP(self.options['server'], self.options['port'], local_hostname='local.domain', timeout=15)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'smtplib'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SMTP'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '21', '26', '29']}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'server'"}; {'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': 'options'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'port'"}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'local_hostname'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'local.domain'"}; {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '15'}
Connect to the SMTP server.
def find_free_port(): with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: sock.bind(('', 0)) return sock.getsockname()[1]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_free_port'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5']}; {'id': '5', 'type': 'with_statement', 'children': ['6', '25']}; {'id': '6', 'type': 'with_clause', 'children': ['7']}; {'id': '7', 'type': 'with_item', 'children': ['8']}; {'id': '8', 'type': 'as_pattern', 'children': ['9', '23']}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'closing'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'AF_INET'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'SOCK_STREAM'}; {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '25', 'type': 'block', 'children': ['26', '35']}; {'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': 'sock'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bind'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'tuple', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "''"}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'subscript', 'children': ['37', '42']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'getsockname'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}
Finds a free port.
def netmask(mask): if not isinstance(mask, string_types): return False octets = mask.split('.') if not len(octets) == 4: return False return ipv4_addr(mask) and octets == sorted(octets, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'netmask'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '5', 'type': 'block', 'children': ['6', '16', '25', '36']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}; {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}; {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'octets'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '25', 'type': 'if_statement', 'children': ['26', '33']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'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': 'octets'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'boolean_operator', 'children': ['38', '42'], 'value': 'and'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ipv4_addr'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'octets'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'octets'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '50', 'type': 'True', 'children': []}
Returns True if the value passed is a valid netmask, otherwise return False
def as_dict(self): d = {"ion": self.ion.as_dict(), "energy": self.energy, "name": self.name} return d
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'as_dict'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '29']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '9', 'type': 'dictionary', 'children': ['10', '19', '24']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}; {'id': '11', 'type': 'string', 'children': [], 'value': '"ion"'}; {'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': 'ion'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'as_dict'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': '"energy"'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'energy'}; {'id': '24', 'type': 'pair', 'children': ['25', '26']}; {'id': '25', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'd'}
Creates a dict of composition, energy, and ion name
def write(*args, **kwargs): debug = kwargs.pop("debug", None) warning = kwargs.pop("warning", None) if _logger: kwargs.pop("end", None) kwargs.pop("file", None) if debug: _logger.debug(*args, **kwargs) elif warning: _logger.warning(*args, **kwargs) else: _logger.info(*args, **kwargs) else: print(*args, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write'}; {'id': '3', 'type': 'parameters', 'children': ['4', '6']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'string', 'children': [], 'value': '"debug"'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': '"warning"'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'if_statement', 'children': ['30', '31', '86']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '31', 'type': 'block', 'children': ['32', '40', '48']}; {'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': 'kwargs'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"end"'}; {'id': '39', 'type': 'None', 'children': []}; {'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': 'kwargs'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"file"'}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'if_statement', 'children': ['49', '50', '61', '74']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '59']}; {'id': '57', 'type': 'list_splat', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '59', 'type': 'dictionary_splat', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '61', 'type': 'elif_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'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': '_logger'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '72']}; {'id': '70', 'type': 'list_splat', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '72', 'type': 'dictionary_splat', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '74', 'type': 'else_clause', 'children': ['75']}; {'id': '75', 'type': 'block', 'children': ['76']}; {'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': '_logger'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '84']}; {'id': '82', 'type': 'list_splat', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '84', 'type': 'dictionary_splat', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '86', 'type': 'else_clause', 'children': ['87']}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '91', 'type': 'argument_list', 'children': ['92', '94']}; {'id': '92', 'type': 'list_splat', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '94', 'type': 'dictionary_splat', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
Redirectable wrapper for print statements.
def traverse_levelorder(self, leaves=True, internal=True): for node in self.root.traverse_levelorder(leaves=leaves, internal=internal): yield node
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'traverse_levelorder'}; {'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': 'leaves'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'internal'}; {'id': '10', 'type': 'True', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '27']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '14', 'type': 'call', 'children': ['15', '20']}; {'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': 'root'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'traverse_levelorder'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'leaves'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'leaves'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'internal'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'internal'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'yield', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}
Perform a levelorder traversal of the ``Node`` objects in this ``Tree``
def expand(self, msgpos): MT = self._tree[msgpos] MT.expand(MT.root)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'expand'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'msgpos'}; {'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': 'MT'}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '_tree'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'msgpos'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'MT'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'MT'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'root'}
expand message at given position
def file_contents(file_name): curr_dir = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(curr_dir, file_name)) as the_file: contents = the_file.read() return contents
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'file_contents'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '5', 'type': 'block', 'children': ['6', '24', '51']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'curr_dir'}; {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'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': 'os'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '__file__'}; {'id': '24', 'type': 'with_statement', 'children': ['25', '42']}; {'id': '25', 'type': 'with_clause', 'children': ['26']}; {'id': '26', 'type': 'with_item', 'children': ['27']}; {'id': '27', 'type': 'as_pattern', 'children': ['28', '40']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'curr_dir'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '40', 'type': 'as_pattern_target', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'the_file'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'the_file'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '50', 'type': 'argument_list', 'children': []}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'contents'}
Given a file name to a valid file returns the file object.
def copy_w_id_suffix(elem, suffix="_copy"): mycopy = deepcopy(elem) for id_elem in mycopy.xpath('//*[@id]'): id_elem.set('id', id_elem.get('id') + suffix) return mycopy
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy_w_id_suffix'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '7', 'type': 'string', 'children': [], 'value': '"_copy"'}; {'id': '8', 'type': 'block', 'children': ['9', '16', '40']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'mycopy'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '24']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'id_elem'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mycopy'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'xpath'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'//*[@id]'"}; {'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': 'id_elem'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '39'], 'value': '+'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'id_elem'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mycopy'}
Make a deep copy of the provided tree, altering ids.
def click_table_printer(headers, _filter, data): _filter = [h.lower() for h in _filter] + [h.upper() for h in _filter] headers = [h for h in headers if not _filter or h in _filter] header_widths = [len(h) for h in headers] for row in data: for idx in range(len(headers)): if header_widths[idx] < len(str(row[idx])): header_widths[idx] = len(str(row[idx])) formatted_output_parts = ['{{:<{0}}}'.format(hw) for hw in header_widths] formatted_output = ' '.join(formatted_output_parts) click.echo(formatted_output.format(*[h.upper() for h in headers])) for row in data: click.echo(formatted_output.format(*row))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'click_table_printer'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '7', 'type': 'block', 'children': ['8', '30', '45', '56', '99', '112', '121', '142']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '11', 'type': 'binary_operator', 'children': ['12', '21'], 'value': '+'}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '18']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '21', 'type': 'list_comprehension', 'children': ['22', '27']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '33', 'type': 'list_comprehension', 'children': ['34', '35', '38']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '38', 'type': 'if_clause', 'children': ['39']}; {'id': '39', 'type': 'boolean_operator', 'children': ['40', '42'], 'value': 'or'}; {'id': '40', 'type': 'not_operator', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'header_widths'}; {'id': '48', 'type': 'list_comprehension', 'children': ['49', '53']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '59']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '69']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'if_statement', 'children': ['71', '84']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '<'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'header_widths'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'header_widths'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'formatted_output_parts'}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '109']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'string', 'children': [], 'value': "'{{:<{0}}}'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'hw'}; {'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'hw'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'header_widths'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'formatted_output'}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'formatted_output_parts'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'formatted_output'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'list_splat', 'children': ['133']}; {'id': '133', 'type': 'list_comprehension', 'children': ['134', '139']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '138', 'type': 'argument_list', 'children': []}; {'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '142', 'type': 'for_statement', 'children': ['143', '144', '145']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '145', 'type': 'block', 'children': ['146']}; {'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': 'click'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'formatted_output'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'list_splat', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'row'}
Generate space separated output for click commands.
def render_pulp_tag(self): if not self.dj.dock_json_has_plugin_conf('postbuild_plugins', 'pulp_tag'): return pulp_registry = self.spec.pulp_registry.value if pulp_registry: self.dj.dock_json_set_arg('postbuild_plugins', 'pulp_tag', 'pulp_registry_name', pulp_registry) if self.spec.pulp_secret.value is None: conf = self.dj.dock_json_get_plugin_conf('postbuild_plugins', 'pulp_tag') args = conf.get('args', {}) if 'username' not in args: raise OsbsValidationException("Pulp registry specified " "but no auth config") else: logger.info("removing pulp_tag from request, " "requires pulp_registry") self.dj.remove_plugin("postbuild_plugins", "pulp_tag")
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_pulp_tag'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '19', '29']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '17']}; {'id': '7', 'type': 'not_operator', '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': 'dj'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dock_json_has_plugin_conf'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'postbuild_plugins'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'pulp_tag'"}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pulp_registry'}; {'id': '22', 'type': 'attribute', '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': 'spec'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pulp_registry'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '31', '89']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pulp_registry'}; {'id': '31', 'type': 'block', 'children': ['32', '44']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'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': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dj'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dock_json_set_arg'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42', '43']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'postbuild_plugins'"}; {'id': '41', 'type': 'string', 'children': [], 'value': "'pulp_tag'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'pulp_registry_name'"}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pulp_registry'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '54']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '53'], 'value': 'is'}; {'id': '46', 'type': 'attribute', 'children': ['47', '52']}; {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pulp_secret'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55', '67', '77']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dj'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'dock_json_get_plugin_conf'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}; {'id': '65', 'type': 'string', 'children': [], 'value': "'postbuild_plugins'"}; {'id': '66', 'type': 'string', 'children': [], 'value': "'pulp_tag'"}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}; {'id': '75', 'type': 'string', 'children': [], 'value': "'args'"}; {'id': '76', 'type': 'dictionary', 'children': []}; {'id': '77', 'type': 'if_statement', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not in'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'username'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'OsbsValidationException'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'concatenated_string', 'children': ['87', '88']}; {'id': '87', 'type': 'string', 'children': [], 'value': '"Pulp registry specified "'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"but no auth config"'}; {'id': '89', 'type': 'else_clause', 'children': ['90']}; {'id': '90', 'type': 'block', 'children': ['91', '100']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'concatenated_string', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"removing pulp_tag from request, "'}; {'id': '99', 'type': 'string', 'children': [], 'value': '"requires pulp_registry"'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '107']}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'dj'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'remove_plugin'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"postbuild_plugins"'}; {'id': '109', 'type': 'string', 'children': [], 'value': '"pulp_tag"'}
Configure the pulp_tag plugin.
def collect(self): if boto is None: self.log.error("Unable to import boto python module") return {} for s3instance in self.config['s3']: self.log.info("S3: byte_unit: %s" % self.config['byte_unit']) aws_access = self.config['s3'][s3instance]['aws_access_key'] aws_secret = self.config['s3'][s3instance]['aws_secret_key'] for bucket_name in self.config['s3'][s3instance]['buckets']: bucket = self.getBucket(aws_access, aws_secret, bucket_name) total_size = self.getBucketSize(bucket) for byte_unit in self.config['byte_unit']: new_size = diamond.convertor.binary.convert( value=total_size, oldUnit='byte', newUnit=byte_unit ) self.publish("%s.size.%s" % (bucket_name, byte_unit), new_size)
{'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': 'boto'}; {'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 boto python module"'}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '29']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 's3instance'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'s3'"}; {'id': '29', 'type': 'block', 'children': ['30', '45', '57', '69']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '%'}; {'id': '39', 'type': 'string', 'children': [], 'value': '"S3: byte_unit: %s"'}; {'id': '40', 'type': 'subscript', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'byte_unit'"}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'aws_access'}; {'id': '48', 'type': 'subscript', 'children': ['49', '56']}; {'id': '49', 'type': 'subscript', 'children': ['50', '55']}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'s3'"}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 's3instance'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'aws_access_key'"}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'aws_secret'}; {'id': '60', 'type': 'subscript', 'children': ['61', '68']}; {'id': '61', 'type': 'subscript', 'children': ['62', '67']}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'s3'"}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 's3instance'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'aws_secret_key'"}; {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '80']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'bucket_name'}; {'id': '71', 'type': 'subscript', 'children': ['72', '79']}; {'id': '72', 'type': 'subscript', 'children': ['73', '78']}; {'id': '73', 'type': 'subscript', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '77', 'type': 'string', 'children': [], 'value': "'s3'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 's3instance'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'buckets'"}; {'id': '80', 'type': 'block', 'children': ['81', '92', '101']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'bucket'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'getBucket'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'aws_access'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'aws_secret'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'bucket_name'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'total_size'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'getBucketSize'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'bucket'}; {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '108']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'byte_unit'}; {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'byte_unit'"}; {'id': '108', 'type': 'block', 'children': ['109', '130']}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'new_size'}; {'id': '112', 'type': 'call', 'children': ['113', '120']}; {'id': '113', 'type': 'attribute', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'diamond'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'convertor'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'convert'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '124', '127']}; {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'total_size'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'oldUnit'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'byte'"}; {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'newUnit'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'byte_unit'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'publish'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '141']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '%'}; {'id': '137', 'type': 'string', 'children': [], 'value': '"%s.size.%s"'}; {'id': '138', 'type': 'tuple', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'bucket_name'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'byte_unit'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'new_size'}
Collect s3 bucket stats
def update(callback=None, path=None, method=Method.PUT, resource=None, tags=None, summary="Update specified resource.", middleware=None): def inner(c): op = ResourceOperation(c, path or PathParam('{key_field}'), method, resource, tags, summary, middleware) op.responses.add(Response(HTTPStatus.NO_CONTENT, "{name} has been updated.")) op.responses.add(Response(HTTPStatus.BAD_REQUEST, "Validation failed.", Error)) op.responses.add(Response(HTTPStatus.NOT_FOUND, "Not found", Error)) return op return inner(callback) if callback else inner
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '15', '18', '21', '24']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Method'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'PUT'}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '23', 'type': 'string', 'children': [], 'value': '"Update specified resource."'}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'middleware'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'block', 'children': ['28', '100']}; {'id': '28', 'type': 'function_definition', 'children': ['29', '30', '32']}; {'id': '29', 'type': 'function_name', 'children': [], 'value': 'inner'}; {'id': '30', 'type': 'parameters', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '32', 'type': 'block', 'children': ['33', '51', '66', '82', '98']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ResourceOperation'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '46', '47', '48', '49', '50']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '42'], 'value': 'or'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'PathParam'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'{key_field}'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'middleware'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'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': 'op'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'responses'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'Response'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'NO_CONTENT'}; {'id': '65', 'type': 'string', 'children': [], 'value': '"{name} has been updated."'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'responses'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Response'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '80', '81']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'BAD_REQUEST'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Validation failed."'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'responses'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'Response'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '96', '97']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'NOT_FOUND'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"Not found"'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'conditional_expression', 'children': ['102', '106', '107'], 'value': 'if'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'inner'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'inner'}
Decorator to configure an operation that updates a resource.
def convert_doc_to_text(filename: str = None, blob: bytes = None, config: TextProcessingConfig = _DEFAULT_CONFIG) -> str: antiword = tools['antiword'] if antiword: if filename: return get_cmd_output(antiword, '-w', str(config.width), filename) else: return get_cmd_output_from_stdin(blob, antiword, '-w', str(config.width), '-') else: raise AssertionError("No DOC-reading tool available")
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_doc_to_text'}; {'id': '3', 'type': 'parameters', 'children': ['4', '9', '14']}; {'id': '4', 'type': 'typed_default_parameter', 'children': ['5', '6', '8']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '18']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'TextProcessingConfig'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_DEFAULT_CONFIG'}; {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '21', 'type': 'block', 'children': ['22', '28']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'antiword'}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '27', 'type': 'string', 'children': [], 'value': "'antiword'"}; {'id': '28', 'type': 'if_statement', 'children': ['29', '30', '63']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'antiword'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'if_statement', 'children': ['32', '33', '47']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_cmd_output'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40', '46']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'antiword'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'-w'"}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_cmd_output_from_stdin'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56', '62']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'antiword'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'-w'"}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'string', 'children': [], 'value': '"No DOC-reading tool available"'}
Converts Microsoft Word DOC files to text.
def _addNoise(self, pattern, noiseLevel): if pattern is None: return None newBits = [] for bit in pattern: if random.random() < noiseLevel: newBits.append(random.randint(0, max(pattern))) else: newBits.append(bit) return set(newBits)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_addNoise'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'noiseLevel'}; {'id': '7', 'type': 'block', 'children': ['8', '15', '19', '57']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}; {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'newBits'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'if_statement', 'children': ['24', '31', '48']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '30'], 'value': '<'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'noiseLevel'}; {'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': 'newBits'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}; {'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': 'random'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'randint'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '48', 'type': 'else_clause', 'children': ['49']}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'newBits'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'newBits'}
Adds noise the given list of patterns and returns a list of noisy copies.
def pulp_repo_path(connection, repoid): dl_base = connection.base_url.replace('/pulp/api/v2', '/pulp/repos') _m = re.match('(.*)-(.*)', repoid) repo = _m.group(1) env = _m.group(2) return "%s/%s/%s" % (dl_base, env, repo)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pulp_repo_path'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repoid'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '29', '38', '47']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dl_base'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}; {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'string', 'children': [], 'value': "'/pulp/api/v2'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'/pulp/repos'"}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '_m'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'(.*)-(.*)'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'repoid'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_m'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': '_m'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'}; {'id': '49', 'type': 'string', 'children': [], 'value': '"%s/%s/%s"'}; {'id': '50', 'type': 'tuple', 'children': ['51', '52', '53']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dl_base'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'repo'}
Given a connection and a repoid, return the url of the repository
def reorder(self, dst_order, arr, src_order=None): if dst_order is None: dst_order = self.viewer.rgb_order if src_order is None: src_order = self.rgb_order if src_order != dst_order: arr = trcalc.reorder_image(dst_order, arr, src_order) return arr
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reorder'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dst_order'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'arr'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'src_order'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '24', '35', '51']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dst_order'}; {'id': '14', 'type': 'None', 'children': []}; {'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': 'dst_order'}; {'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': 'viewer'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'rgb_order'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'src_order'}; {'id': '27', 'type': 'None', 'children': []}; {'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': 'src_order'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rgb_order'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '!='}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'src_order'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dst_order'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'arr'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'trcalc'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reorder_image'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dst_order'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'arr'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'src_order'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'arr'}
Reorder the output array to match that needed by the viewer.
def log_accept(self, block_id, vtxindex, opcode, op_data): log.debug("ACCEPT op {} at ({}, {}) ({})".format(opcode, block_id, vtxindex, json.dumps(op_data, sort_keys=True)))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'log_accept'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'vtxindex'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'opcode'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'op_data'}; {'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': 'log'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"ACCEPT op {} at ({}, {}) ({})"'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23', '24']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'opcode'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'vtxindex'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'op_data'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '32', 'type': 'True', 'children': []}
Log an accepted operation
def remove_files_in_dir(dpath, fname_pattern_list='*', recursive=False, verbose=VERBOSE, dryrun=False, ignore_errors=False): if isinstance(fname_pattern_list, six.string_types): fname_pattern_list = [fname_pattern_list] if verbose > 2: print('[util_path] Removing files:') print(' * from dpath = %r ' % dpath) print(' * with patterns = %r' % fname_pattern_list) print(' * recursive = %r' % recursive) num_removed, num_matched = (0, 0) if not exists(dpath): msg = ('!!! dir = %r does not exist!' % dpath) if verbose: print(msg) warnings.warn(msg, category=UserWarning) for root, dname_list, fname_list in os.walk(dpath): for fname_pattern in fname_pattern_list: for fname in fnmatch.filter(fname_list, fname_pattern): num_matched += 1 num_removed += remove_file(join(root, fname), ignore_errors=ignore_errors, dryrun=dryrun, verbose=verbose > 5) if not recursive: break if verbose > 0: print('[util_path] ... Removed %d/%d files' % (num_removed, num_matched)) return True
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_files_in_dir'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dryrun'}; {'id': '16', 'type': 'False', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '35', '66', '74', '106', '163', '177']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '29']}; {'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': 'fname_pattern_list'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'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': 'fname_pattern_list'}; {'id': '33', 'type': 'list', 'children': ['34'], 'value': '[fname_pattern_list]'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '39', 'type': 'block', 'children': ['40', '45', '52', '59']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'[util_path] Removing files:'"}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '%'}; {'id': '50', 'type': 'string', 'children': [], 'value': "' * from dpath = %r '"}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'}; {'id': '57', 'type': 'string', 'children': [], 'value': "' * with patterns = %r'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'}; {'id': '64', 'type': 'string', 'children': [], 'value': "' * recursive = %r'"}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'pattern_list', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'num_removed'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'num_matched'}; {'id': '71', 'type': 'tuple', 'children': ['72', '73']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '80']}; {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '80', 'type': 'block', 'children': ['81', '88', '96']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '84', 'type': '()', 'children': ['85']}; {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'!!! dir = %r does not exist!'"}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'UserWarning'}; {'id': '106', 'type': 'for_statement', 'children': ['107', '111', '117']}; {'id': '107', 'type': 'pattern_list', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'dname_list'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'fname_list'}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '117', 'type': 'block', 'children': ['118', '158']}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '121']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fname_pattern'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '131']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'fname_list'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'fname_pattern'}; {'id': '131', 'type': 'block', 'children': ['132', '136']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'augmented_assignment', 'children': ['134', '135'], 'value': '+='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'num_matched'}; {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'num_removed'}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'remove_file'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '147', '150', '153']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'dryrun'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'dryrun'}; {'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '>'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '157', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '161']}; {'id': '159', 'type': 'not_operator', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'break_statement', 'children': []}; {'id': '163', 'type': 'if_statement', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '>'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'}; {'id': '173', 'type': 'string', 'children': [], 'value': "'[util_path] ... Removed %d/%d files'"}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'num_removed'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'num_matched'}; {'id': '177', 'type': 'return_statement', 'children': ['178']}; {'id': '178', 'type': 'True', 'children': []}
Removes files matching a pattern from a directory
def build_index(self, idx_name, _type='default'): "Build the index related to the `name`." indexes = {} has_non_string_values = False for key, item in self.data.items(): if idx_name in item: value = item[idx_name] if not isinstance(value, six.string_types): has_non_string_values = True if value not in indexes: indexes[value] = set([]) indexes[value].add(key) self.indexes[idx_name] = indexes if self._meta.lazy_indexes or has_non_string_values: _type = 'lazy' self.index_defs[idx_name] = {'type': _type}
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_index'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'idx_name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': '_type'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '9', 'type': 'block', 'children': ['10', '12', '16', '20', '80', '88', '101']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'string', 'children': [], 'value': '"Build the index related to the `name`."'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'has_non_string_values'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'for_statement', 'children': ['21', '24', '31']}; {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'item'}; {'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': 'data'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'idx_name'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '36', 'type': 'block', 'children': ['37', '43', '57', '71']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'idx_name'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '52']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'has_non_string_values'}; {'id': '56', 'type': 'True', 'children': []}; {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'not in'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '78']}; {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '87']}; {'id': '82', 'type': 'subscript', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'idx_name'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '96']}; {'id': '89', 'type': 'boolean_operator', 'children': ['90', '95'], 'value': 'or'}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'lazy_indexes'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'has_non_string_values'}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': '_type'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'lazy'"}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '108']}; {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'index_defs'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'idx_name'}; {'id': '108', 'type': 'dictionary', 'children': ['109']}; {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '_type'}
Build the index related to the `name`.
def short_token(): hash = hashlib.sha1(shortuuid.uuid()) hash.update(settings.SECRET_KEY) return hash.hexdigest()[::2]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'short_token'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '18', '27']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'hashlib'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sha1'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'shortuuid'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'SECRET_KEY'}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '34']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hexdigest'}; {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'slice', 'children': ['35', '36', '37']}; {'id': '35', 'type': 'colon', 'children': []}; {'id': '36', 'type': 'colon', 'children': []}; {'id': '37', 'type': 'integer', 'children': [], 'value': '2'}
Generate a hash that can be used as an application identifier
def _grouped_backends(cls, options, backend): "Group options by backend and filter out output group appropriately" if options is None: return [(backend or Store.current_backend, options)] dfltdict = defaultdict(dict) for spec, groups in options.items(): if 'output' not in groups.keys() or len(groups['output'])==0: dfltdict[backend or Store.current_backend][spec.strip()] = groups elif set(groups['output'].keys()) - set(['backend']): dfltdict[groups['output']['backend']][spec.strip()] = groups elif ['backend'] == list(groups['output'].keys()): filtered = {k:v for k,v in groups.items() if k != 'output'} dfltdict[groups['output']['backend']][spec.strip()] = filtered else: raise Exception('The output options group must have the backend keyword') return [(bk, bk_opts) for (bk, bk_opts) in dfltdict.items()]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_grouped_backends'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '7', 'type': 'block', 'children': ['8', '10', '24', '31', '167']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'string', 'children': [], 'value': '"Group options by backend and filter out output group appropriately"'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'list', 'children': ['17'], 'value': '[(backend or Store.current_backend, options)]'}; {'id': '17', 'type': 'tuple', 'children': ['18', '23']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '20'], 'value': 'or'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Store'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'current_backend'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dfltdict'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '31', 'type': 'for_statement', 'children': ['32', '35', '40']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'if_statement', 'children': ['42', '58', '75', '109', '160']}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '50'], 'value': 'or'}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not in'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '57'], 'value': '=='}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '74']}; {'id': '61', 'type': 'subscript', 'children': ['62', '69']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'dfltdict'}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '66'], 'value': 'or'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Store'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'current_backend'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '75', 'type': 'elif_clause', 'children': ['76', '92']}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '87'], 'value': '-'}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '86']}; {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '86', 'type': 'argument_list', 'children': []}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'list', 'children': ['91'], 'value': "['backend']"}; {'id': '91', 'type': 'string', 'children': [], 'value': "'backend'"}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '108']}; {'id': '95', 'type': 'subscript', 'children': ['96', '103']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dfltdict'}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'backend'"}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '109', 'type': 'elif_clause', 'children': ['110', '123']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '113'], 'value': '=='}; {'id': '111', 'type': 'list', 'children': ['112'], 'value': "['backend']"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'backend'"}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '122']}; {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '122', 'type': 'argument_list', 'children': []}; {'id': '123', 'type': 'block', 'children': ['124', '144']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'id': '127', 'type': 'dictionary_comprehension', 'children': ['128', '131', '140']}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '131', 'type': 'for_in_clause', 'children': ['132', '135']}; {'id': '132', 'type': 'pattern_list', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'if_clause', 'children': ['141']}; {'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '!='}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '143', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '159']}; {'id': '146', 'type': 'subscript', 'children': ['147', '154']}; {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'dfltdict'}; {'id': '149', 'type': 'subscript', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '153', 'type': 'string', 'children': [], 'value': "'backend'"}; {'id': '154', 'type': 'call', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '158', 'type': 'argument_list', 'children': []}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'id': '160', 'type': 'else_clause', 'children': ['161']}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'raise_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'string', 'children': [], 'value': "'The output options group must have the backend keyword'"}; {'id': '167', 'type': 'return_statement', 'children': ['168']}; {'id': '168', 'type': 'list_comprehension', 'children': ['169', '172']}; {'id': '169', 'type': 'tuple', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'bk'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'bk_opts'}; {'id': '172', 'type': 'for_in_clause', 'children': ['173', '176']}; {'id': '173', 'type': 'tuple_pattern', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'bk'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'bk_opts'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'dfltdict'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '180', 'type': 'argument_list', 'children': []}
Group options by backend and filter out output group appropriately
def __get_cycle(graph, ordering, parent_lookup): root_node = ordering[0] for i in range(2, len(ordering)): current_node = ordering[i] if graph.adjacent(current_node, root_node): path = [] while current_node != root_node: path.append(current_node) current_node = parent_lookup[current_node] path.append(root_node) path.reverse() return path
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__get_cycle'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'parent_lookup'}; {'id': '7', 'type': 'block', 'children': ['8', '14']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'root_node'}; {'id': '11', 'type': 'subscript', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '24']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'integer', 'children': [], 'value': '2'}; {'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': 'ordering'}; {'id': '24', 'type': 'block', 'children': ['25', '31']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '39']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'adjacent'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'root_node'}; {'id': '39', 'type': 'block', 'children': ['40', '44', '62', '69', '75']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '43', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '44', 'type': 'while_statement', 'children': ['45', '48']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '!='}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'root_node'}; {'id': '48', 'type': 'block', 'children': ['49', '56']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'parent_lookup'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'root_node'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '74', 'type': 'argument_list', 'children': []}; {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'}
Gets the main cycle of the dfs tree.
def _create_buffers(self): self.buffers = {} for step in self.graph.nodes(): num_buffers = 1 if isinstance(step, Reduction): num_buffers = len(step.parents) self.buffers[step] = Buffer(step.min_frames, step.left_context, step.right_context, num_buffers) return self.buffers
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_buffers'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '62']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'buffers'}; {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '21']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '14', 'type': 'call', 'children': ['15', '20']}; {'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': 'graph'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22', '26', '42']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'num_buffers'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}; {'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': 'step'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Reduction'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'num_buffers'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'parents'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '49']}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'buffers'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'Buffer'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '55', '58', '61']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'min_frames'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'left_context'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'right_context'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'num_buffers'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'buffers'}
Create a buffer for every step in the pipeline.
def __clean_tmp(sfn): if sfn.startswith(os.path.join(tempfile.gettempdir(), salt.utils.files.TEMPFILE_PREFIX)): all_roots = itertools.chain.from_iterable( six.itervalues(__opts__['file_roots'])) in_roots = any(sfn.startswith(root) for root in all_roots) if os.path.exists(sfn) and not in_roots: os.remove(sfn)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__clean_tmp'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sfn'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '31']}; {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sfn'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '11', 'type': 'argument_list', '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': 'os'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '24']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'gettempdir'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'attribute', 'children': ['25', '30']}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'salt'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'TEMPFILE_PREFIX'}; {'id': '31', 'type': 'block', 'children': ['32', '50', '65']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'all_roots'}; {'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': 'itertools'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'from_iterable'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'itervalues'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__opts__'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'file_roots'"}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'in_roots'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '55', 'type': 'generator_expression', 'children': ['56', '62']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sfn'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'all_roots'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '77']}; {'id': '66', 'type': 'boolean_operator', 'children': ['67', '75'], 'value': 'and'}; {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sfn'}; {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'in_roots'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sfn'}
Clean out a template temp file
def _get_value(self): if self._aux_variable: return self._aux_variable['law'](self._aux_variable['variable'].value) if self._transformation is None: return self._internal_value else: return self._transformation.backward(self._internal_value)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_value'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '26']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': '_aux_variable'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '18']}; {'id': '13', 'type': 'subscript', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_aux_variable'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'law'"}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'attribute', 'children': ['20', '25']}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_aux_variable'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'variable'"}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32', '37']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': 'is'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_transformation'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_internal_value'}; {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '46']}; {'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': '_transformation'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'backward'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': '_internal_value'}
Return current parameter value
def id_request(self): import inspect curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 2) _LOGGER.debug('caller name: %s', calframe[1][3]) msg = StandardSend(self.address, COMMAND_ID_REQUEST_0X10_0X00) self._plm.send_msg(msg)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'id_request'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '9', '17', '27', '39', '49']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}; {'id': '7', 'type': 'dotted_name', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'curframe'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'currentframe'}; {'id': '16', 'type': 'argument_list', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'calframe'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'getouterframes'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'curframe'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '2'}; {'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': '_LOGGER'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'caller name: %s'"}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'calframe'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'StandardSend'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'COMMAND_ID_REQUEST_0X10_0X00'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_plm'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'send_msg'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'msg'}
Request a device ID from a device.
def tmp_context(fn, mode="r"): with open(tmp_context_name(fn), mode) as f: return f.read()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tmp_context'}; {'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': 'mode'}; {'id': '7', 'type': 'string', 'children': [], 'value': '"r"'}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'with_statement', 'children': ['10', '23']}; {'id': '10', 'type': 'with_clause', 'children': ['11']}; {'id': '11', 'type': 'with_item', 'children': ['12']}; {'id': '12', 'type': 'as_pattern', 'children': ['13', '21']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '20']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tmp_context_name'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '21', 'type': 'as_pattern_target', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'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': 'f'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '29', 'type': 'argument_list', 'children': []}
Return content fo the `fn` from the temporary directory.
def clean_ns(tag): if '}' in tag: split = tag.split('}') return split[0].strip('{'), split[-1] return '', tag
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_ns'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '5', 'type': 'block', 'children': ['6', '34']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'in'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'}'"}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '10', 'type': 'block', 'children': ['11', '20']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'}'"}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'expression_list', 'children': ['22', '30']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'{'"}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'expression_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "''"}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'tag'}
Return a tag and its namespace separately.
def process_request(self, request_object): resources = (request_object.entity_cls.query .filter(**request_object.filters) .offset((request_object.page - 1) * request_object.per_page) .limit(request_object.per_page) .order_by(request_object.order_by) .all()) return ResponseSuccess(Status.SUCCESS, resources)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_request'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '6', 'type': 'block', 'children': ['7', '56']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '10', 'type': '()', 'children': ['11']}; {'id': '11', 'type': 'call', 'children': ['12', '55']}; {'id': '12', 'type': 'attribute', 'children': ['13', '54']}; {'id': '13', 'type': 'call', 'children': ['14', '50']}; {'id': '14', 'type': 'attribute', 'children': ['15', '49']}; {'id': '15', 'type': 'call', 'children': ['16', '45']}; {'id': '16', 'type': 'attribute', 'children': ['17', '44']}; {'id': '17', 'type': 'call', 'children': ['18', '33']}; {'id': '18', 'type': 'attribute', 'children': ['19', '32']}; {'id': '19', 'type': 'call', 'children': ['20', '27']}; {'id': '20', 'type': 'attribute', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'entity_cls'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'dictionary_splat', 'children': ['29']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '41'], 'value': '*'}; {'id': '35', 'type': '()', 'children': ['36']}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '40'], 'value': '-'}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'request_object'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ResponseSuccess'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Status'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'SUCCESS'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'resources'}
Return a list of resources
def _next_id(self): assert get_thread_ident() == self.ioloop_thread_id self._last_msg_id += 1 return str(self._last_msg_id)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_next_id'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '20']}; {'id': '6', 'type': 'assert_statement', 'children': ['7']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'get_thread_ident'}; {'id': '10', 'type': 'argument_list', 'children': []}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ioloop_thread_id'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'augmented_assignment', 'children': ['16', '19'], 'value': '+='}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_last_msg_id'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'return_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_last_msg_id'}
Return the next available message id.
def parse_cfg(self): self.cfgparser = ConfigParser() if not self.cfgparser.read(self.options.config): raise SystemExit('config file %s not found.'%self.options.config) projectDir = os.path.dirname(self.options.config) projectDir = os.path.abspath(projectDir) os.chdir(projectDir)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_cfg'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '40', '55', '66']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cfgparser'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ConfigParser'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '28']}; {'id': '15', 'type': 'not_operator', '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': 'cfgparser'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'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': 'options'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'SystemExit'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'config file %s not found.'"}; {'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': 'options'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'projectDir'}; {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'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': 'options'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'projectDir'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}; {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'projectDir'}; {'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': 'os'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'chdir'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'projectDir'}
parses the given config file for experiments.
def send_response(self, response): response_bytes = response.encode(config.CODEC) log.debug("About to send reponse: %r", response_bytes) self.socket.send(response_bytes)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_response'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '26']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'response_bytes'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'CODEC'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"About to send reponse: %r"'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'response_bytes'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'response_bytes'}
Send a unicode object as reply to the most recently-issued command
def make_gui(self): self.option_window = Toplevel() self.option_window.protocol("WM_DELETE_WINDOW", self.on_exit) self.canvas_frame = tk.Frame(self, height=500) self.option_frame = tk.Frame(self.option_window, height=300) self.canvas_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) self.option_frame.pack(side=tk.RIGHT, fill=None, expand=False) self.make_options_frame() self.make_canvas_frame() self.disable_singlecolor()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_gui'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '26', '40', '56', '77', '96', '102', '108']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'option_window'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Toplevel'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'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': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'option_window'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"WM_DELETE_WINDOW"'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'on_exit'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'canvas_frame'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tk'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'Frame'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'option_frame'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tk'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Frame'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'option_window'}; {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '300'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'canvas_frame'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '69', '74']}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'side'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'tk'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'LEFT'}; {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'fill'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'tk'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'BOTH'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '76', 'type': 'True', 'children': []}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}; {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'option_frame'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '90', '93']}; {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'side'}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'tk'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'RIGHT'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'fill'}; {'id': '92', 'type': 'None', 'children': []}; {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '95', 'type': 'False', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'make_options_frame'}; {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'make_canvas_frame'}; {'id': '107', 'type': 'argument_list', 'children': []}; {'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': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'disable_singlecolor'}; {'id': '113', 'type': 'argument_list', 'children': []}
Setups the general structure of the gui, the first function called
def _build_resource(self): resource = {"name": self.name} if self.dns_name is not None: resource["dnsName"] = self.dns_name if self.description is not None: resource["description"] = self.description if self.name_server_set is not None: resource["nameServerSet"] = self.name_server_set return resource
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_resource'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '30', '45', '60']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '9', 'type': 'dictionary', 'children': ['10']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}; {'id': '11', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': 'is not'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dns_name'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"dnsName"'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dns_name'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': 'is not'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '41', 'type': 'string', 'children': [], 'value': '"description"'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '51']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': 'is not'}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'name_server_set'}; {'id': '50', 'type': 'None', 'children': []}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'resource'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"nameServerSet"'}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'name_server_set'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'resource'}
Generate a resource for ``create`` or ``update``.
def _write_config(self, memory): memory.seek(0) memory.write(struct.pack("<II", self._simulator.length, self.output.routing_key)) memory.write(bitarray( self.stimulus.ljust(self._simulator.length, "0"), endian="little").tobytes())
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_write_config'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'memory'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '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': 'memory'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'memory'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'write'}; {'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': 'struct'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '31']}; {'id': '25', 'type': 'string', 'children': [], 'value': '"<II"'}; {'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': '_simulator'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'routing_key'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'memory'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '64']}; {'id': '43', 'type': 'attribute', 'children': ['44', '63']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'bitarray'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '60']}; {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'stimulus'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '59']}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_simulator'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '59', 'type': 'string', 'children': [], 'value': '"0"'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'endian'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"little"'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'tobytes'}; {'id': '64', 'type': 'argument_list', 'children': []}
Write the configuration for this stimulus to memory.
def packet_write(self): bytes_written = 0 if self.sock == NC.INVALID_SOCKET: return NC.ERR_NO_CONN, bytes_written while len(self.out_packet) > 0: pkt = self.out_packet[0] write_length, status = nyamuk_net.write(self.sock, pkt.payload) if write_length > 0: pkt.to_process -= write_length pkt.pos += write_length bytes_written += write_length if pkt.to_process > 0: return NC.ERR_SUCCESS, bytes_written else: if status == errno.EAGAIN or status == errno.EWOULDBLOCK: return NC.ERR_SUCCESS, bytes_written elif status == errno.ECONNRESET: return NC.ERR_CONN_LOST, bytes_written else: return NC.ERR_UNKNOWN, bytes_written del self.out_packet[0] self.last_msg_out = time.time() return NC.ERR_SUCCESS, bytes_written
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'packet_write'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '25', '151']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'if_statement', 'children': ['11', '18']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': '=='}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'INVALID_SOCKET'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'expression_list', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ERR_NO_CONN'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '25', 'type': 'while_statement', 'children': ['26', '34']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '33'], 'value': '>'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'out_packet'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'block', 'children': ['35', '43', '59', '135', '141']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'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': 'out_packet'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}; {'id': '45', 'type': 'pattern_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'write_length'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'nyamuk_net'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63', '93']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '>'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'write_length'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '63', 'type': 'block', 'children': ['64', '70', '76', '80']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'augmented_assignment', 'children': ['66', '69'], 'value': '-='}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'to_process'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'write_length'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'augmented_assignment', 'children': ['72', '75'], 'value': '+='}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'write_length'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'augmented_assignment', 'children': ['78', '79'], 'value': '+='}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'write_length'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '>'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'pkt'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'to_process'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'expression_list', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ERR_SUCCESS'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '93', 'type': 'else_clause', 'children': ['94']}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'if_statement', 'children': ['96', '107', '114', '127']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '102'], 'value': 'or'}; {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '=='}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'EAGAIN'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '=='}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'EWOULDBLOCK'}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}; {'id': '109', 'type': 'expression_list', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ERR_SUCCESS'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '114', 'type': 'elif_clause', 'children': ['115', '120']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ECONNRESET'}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'expression_list', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ERR_CONN_LOST'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'expression_list', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ERR_UNKNOWN'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}; {'id': '135', 'type': 'delete_statement', 'children': ['136']}; {'id': '136', 'type': 'subscript', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'out_packet'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'last_msg_out'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '150', 'type': 'argument_list', 'children': []}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'expression_list', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'NC'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ERR_SUCCESS'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'bytes_written'}
Write packet to network.
def touch_file(self, filename): path_to_file = self.__file_class__(os.path.join(self, filename)) path_to_file.touch() return path_to_file
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'touch_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '30']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'path_to_file'}; {'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': '__file_class__'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'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']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'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': 'path_to_file'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'touch'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'path_to_file'}
Touch a file in the directory
def lock_exists_in_either_channel_side( channel_state: NettingChannelState, secrethash: SecretHash, ) -> bool: lock = get_lock(channel_state.our_state, secrethash) if not lock: lock = get_lock(channel_state.partner_state, secrethash) return lock is not None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'lock_exists_in_either_channel_side'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'channel_state'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'NettingChannelState'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'secrethash'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SecretHash'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '14', 'type': 'block', 'children': ['15', '25', '39']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_lock'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'channel_state'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'our_state'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'secrethash'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'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': 'lock'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_lock'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'channel_state'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'partner_state'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'secrethash'}; {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is not'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '42', 'type': 'None', 'children': []}
Check if the lock with `secrethash` exists in either our state or the partner's state
async def server_stop(app, loop): em = Embed(color=0xe67e22) em.set_footer('Host: {}'.format(socket.gethostname())) em.description = '[INFO] Server Stopped' await app.webhook.send(embed=em) await app.session.close()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'server_stop'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '32', '38', '50']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'em'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Embed'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '15', 'type': 'integer', 'children': [], 'value': '0xe67e22'}; {'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': 'em'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'set_footer'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'Host: {}'"}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'gethostname'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'em'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '37', 'type': 'string', 'children': [], 'value': "'[INFO] Server Stopped'"}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'await', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '46']}; {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'webhook'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'embed'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'em'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'await', 'children': ['52']}; {'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': 'app'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '58', 'type': 'argument_list', 'children': []}
Sends a message to the webhook channel when server stops.
def connect(uri, factory=pymongo.MongoClient): warnings.warn( "do not use. Just call MongoClient directly.", DeprecationWarning) return factory(uri)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'factory'}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pymongo'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'MongoClient'}; {'id': '10', 'type': 'block', 'children': ['11', '19']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'string', 'children': [], 'value': '"do not use. Just call MongoClient directly."'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'factory'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'uri'}
Use the factory to establish a connection to uri.
def compute(self, xt1, yt1, xt, yt, theta1t1, theta2t1, theta1, theta2): dx = xt - xt1 dy = yt - yt1 if self.numPoints < self.maxPoints: self.dxValues[self.numPoints,0] = dx self.dxValues[self.numPoints,1] = dy self.thetaValues[self.numPoints,0] = theta1 self.thetaValues[self.numPoints,1] = theta2 self.numPoints += 1 elif self.numPoints == self.maxPoints: print >> sys.stderr,"Max points exceeded, analyzing ",self.maxPoints,"points only" self.numPoints += 1
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'xt1'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'yt1'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'xt'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'yt'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'theta1t1'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'theta2t1'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'theta1'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'theta2'}; {'id': '13', 'type': 'block', 'children': ['14', '20', '26']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '-'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'xt'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'xt1'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dy'}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '-'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'yt'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'yt1'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '34', '85']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '<'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'maxPoints'}; {'id': '34', 'type': 'block', 'children': ['35', '46', '57', '68', '79']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '45']}; {'id': '37', 'type': 'subscript', 'children': ['38', '41', '44']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dxValues'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '56']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52', '55']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dxValues'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dy'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '67']}; {'id': '59', 'type': 'subscript', 'children': ['60', '63', '66']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'thetaValues'}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'theta1'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '78']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74', '77']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'thetaValues'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'theta2'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'augmented_assignment', 'children': ['81', '84'], 'value': '+='}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '85', 'type': 'elif_clause', 'children': ['86', '93']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'maxPoints'}; {'id': '93', 'type': 'block', 'children': ['94', '104']}; {'id': '94', 'type': 'print_statement', 'children': ['95', '99', '100', '103']}; {'id': '95', 'type': 'chevron', 'children': ['96']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '99', 'type': 'string', 'children': [], 'value': '"Max points exceeded, analyzing "'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'maxPoints'}; {'id': '103', 'type': 'string', 'children': [], 'value': '"points only"'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'augmented_assignment', 'children': ['106', '109'], 'value': '+='}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'numPoints'}; {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}
Accumulate the various inputs.
def _build_all_dependencies(self): ret = {} for model, schema in six.iteritems(self._models()): dep_list = self._build_dependent_model_list(schema) ret[model] = dep_list return ret
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_all_dependencies'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '40']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '24']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'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': '_models'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '34']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dep_list'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': '_build_dependent_model_list'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dep_list'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ret'}
Helper function to build a map of model to their list of model reference dependencies
def search_related(self, request): logger.debug("Cache Search Request") if self.cache.is_empty() is True: logger.debug("Empty Cache") return None result = [] items = list(self.cache.cache.items()) for key, item in items: element = self.cache.get(item.key) logger.debug("Element : {elm}".format(elm=str(element))) if request.proxy_uri == element.uri: result.append(item) return result
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_related'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '34', '38', '53', '105']}; {'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': '"Cache Search Request"'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '24']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '23'], 'value': 'is'}; {'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': 'cache'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_empty'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '32']}; {'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': 'logger'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'string', 'children': [], 'value': '"Empty Cache"'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}; {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '52']}; {'id': '45', 'type': 'attribute', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'for_statement', 'children': ['54', '57', '58']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '58', 'type': 'block', 'children': ['59', '72', '89']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'element'}; {'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': 'cache'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'logger'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Element : {elm}"'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'elm'}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '97']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '=='}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'proxy_uri'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'result'}
extracting everything from the cache
def do_application_actions_plus(parser, token): nodelist = parser.parse(('end_application_actions',)) parser.delete_first_token() return ApplicationActionsPlus(nodelist)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_application_actions_plus'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '23']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'nodelist'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'tuple', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'end_application_actions'"}; {'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': 'parser'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'delete_first_token'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ApplicationActionsPlus'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'nodelist'}
Render actions available with extra text.
def func(self, p): self._set_stochastics(p) try: return -1. * self.logp except ZeroProbability: return Inf
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'func'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '6', 'type': 'block', 'children': ['7', '14']}; {'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': '_set_stochastics'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '14', 'type': 'try_statement', 'children': ['15', '23']}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '20'], 'value': '*'}; {'id': '18', 'type': 'unary_operator', 'children': ['19'], 'value': '-'}; {'id': '19', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'logp'}; {'id': '23', 'type': 'except_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ZeroProbability'}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Inf'}
The function that gets passed to the optimizers.
def from_ad_date(cls, date): functions.check_valid_ad_range(date) days = values.START_EN_DATE - date start_date = NepDate(values.START_NP_YEAR, 1, 1) return start_date + (date - values.START_EN_DATE)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_ad_date'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '22', '33']}; {'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': 'functions'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'check_valid_ad_range'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '21'], 'value': '-'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'START_EN_DATE'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'start_date'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'NepDate'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '31', '32']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'START_NP_YEAR'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '+'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'start_date'}; {'id': '36', 'type': '()', 'children': ['37']}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '-'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'START_EN_DATE'}
Gets a NepDate object from gregorian calendar date
def parse_array(raw_array): array_strip_brackets = raw_array.replace('{', '').replace('}', '') array_strip_spaces = array_strip_brackets.replace('"', '').replace(' ', '') return array_strip_spaces.split(',')
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_array'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'raw_array'}; {'id': '5', 'type': 'block', 'children': ['6', '22', '38']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'array_strip_brackets'}; {'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': 'raw_array'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'{'"}; {'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': "'}'"}; {'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': 'array_strip_spaces'}; {'id': '25', 'type': 'call', 'children': ['26', '35']}; {'id': '26', 'type': 'attribute', 'children': ['27', '34']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'array_strip_brackets'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '\'"\''}; {'id': '33', 'type': 'string', 'children': [], 'value': "''"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '37', 'type': 'string', 'children': [], 'value': "''"}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'array_strip_spaces'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'string', 'children': [], 'value': "','"}
Parse a WMIC array.
def list_fpgas(self): click.echo('\nSupported FPGAs:\n') FPGALIST_TPL = ('{fpga:30} {type:<5} {size:<5} {pack:<10}') terminal_width, _ = click.get_terminal_size() click.echo('-' * terminal_width) click.echo(FPGALIST_TPL.format( fpga=click.style('FPGA', fg='cyan'), type='Type', size='Size', pack='Pack')) click.echo('-' * terminal_width) for fpga in self.fpgas: click.echo(FPGALIST_TPL.format( fpga=click.style(fpga, fg='cyan'), type=self.fpgas.get(fpga).get('type'), size=self.fpgas.get(fpga).get('size'), pack=self.fpgas.get(fpga).get('pack')))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_fpgas'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '18', '28', '37', '68', '77']}; {'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': 'click'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'\\nSupported FPGAs:\\n'"}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'FPGALIST_TPL'}; {'id': '16', 'type': '()', 'children': ['17']}; {'id': '17', 'type': 'string', 'children': [], 'value': "'{fpga:30} {type:<5} {size:<5} {pack:<10}'"}; {'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': 'terminal_width'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_terminal_size'}; {'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': 'click'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '*'}; {'id': '35', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'terminal_width'}; {'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': 'click'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'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': 'FPGALIST_TPL'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '59', '62', '65']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': "'FPGA'"}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'fg'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'cyan'"}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '61', 'type': 'string', 'children': [], 'value': "'Type'"}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'Size'"}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'Pack'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '*'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'terminal_width'}; {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '82']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fpgas'}; {'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': 'click'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'FPGALIST_TPL'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '105', '120', '135']}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fg'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'cyan'"}; {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '107', 'type': 'call', 'children': ['108', '118']}; {'id': '108', 'type': 'attribute', 'children': ['109', '117']}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'fpgas'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '122', 'type': 'call', 'children': ['123', '133']}; {'id': '123', 'type': 'attribute', 'children': ['124', '132']}; {'id': '124', 'type': 'call', 'children': ['125', '130']}; {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'fpgas'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'size'"}; {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '137', 'type': 'call', 'children': ['138', '148']}; {'id': '138', 'type': 'attribute', 'children': ['139', '147']}; {'id': '139', 'type': 'call', 'children': ['140', '145']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'fpgas'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'fpga'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'string', 'children': [], 'value': "'pack'"}
Return a list with all the supported FPGAs
def execInspectorDialog(self): dialog = OpenInspectorDialog(self.argosApplication.inspectorRegistry, parent=self) dialog.setCurrentInspectorRegItem(self.inspectorRegItem) dialog.exec_() if dialog.result(): inspectorRegItem = dialog.getCurrentInspectorRegItem() if inspectorRegItem is not None: self.getInspectorActionById(inspectorRegItem.identifier).trigger()
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'execInspectorDialog'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '20', '29', '35']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dialog'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OpenInspectorDialog'}; {'id': '11', 'type': 'argument_list', 'children': ['12', '17']}; {'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': 'argosApplication'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'inspectorRegistry'}; {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'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': 'dialog'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'setCurrentInspectorRegItem'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'inspectorRegItem'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dialog'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'exec_'}; {'id': '34', 'type': 'argument_list', 'children': []}; {'id': '35', 'type': 'if_statement', 'children': ['36', '41']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dialog'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '40', 'type': 'argument_list', 'children': []}; {'id': '41', 'type': 'block', 'children': ['42', '50']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'inspectorRegItem'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'dialog'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'getCurrentInspectorRegItem'}; {'id': '49', 'type': 'argument_list', 'children': []}; {'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': 'inspectorRegItem'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '67']}; {'id': '57', 'type': 'attribute', 'children': ['58', '66']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'getInspectorActionById'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'inspectorRegItem'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'trigger'}; {'id': '67', 'type': 'argument_list', 'children': []}
Opens the inspector dialog box to let the user change the current inspector.
def select_template_name(template_name_list, using=None): if not isinstance(template_name_list, tuple): template_name_list = tuple(template_name_list) try: return _cached_name_lookups[template_name_list] except KeyError: for template_name in template_name_list: try: get_template(template_name, using=using) except TemplateDoesNotExist: continue else: template_name = six.text_type(template_name) _cached_name_lookups[template_name_list] = template_name return template_name return None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select_template_name'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'template_name_list'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'using'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '24']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}; {'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': 'template_name_list'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'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': 'template_name_list'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'template_name_list'}; {'id': '24', 'type': 'try_statement', 'children': ['25', '30']}; {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_cached_name_lookups'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'template_name_list'}; {'id': '30', 'type': 'except_clause', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '32', 'type': 'block', 'children': ['33', '70']}; {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'template_name_list'}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'try_statement', 'children': ['38', '47', '51']}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get_template'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'using'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'using'}; {'id': '47', 'type': 'except_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'TemplateDoesNotExist'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'continue_statement', 'children': []}; {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53', '62', '68']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': '_cached_name_lookups'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'template_name_list'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'template_name'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}; {'id': '71', 'type': 'None', 'children': []}
Given a list of template names, find the first one that exists.
def resolve_service_id(self, service_name=None, service_type=None): services = [s._info for s in self.api.services.list()] service_name = service_name.lower() for s in services: name = s['name'].lower() if service_type and service_name: if (service_name == name and service_type == s['type']): return s['id'] elif service_name and service_name == name: return s['id'] elif service_type and service_type == s['type']: return s['id'] return None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_service_id'}; {'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': 'service_name'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'service_type'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '30', '38', '97']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '15', 'type': 'list_comprehension', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_info'}; {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '21', 'type': 'call', 'children': ['22', '29']}; {'id': '22', 'type': 'attribute', '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': 'api'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '41', 'type': 'block', 'children': ['42', '52']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56', '73', '84']}; {'id': '53', 'type': 'boolean_operator', 'children': ['54', '55'], 'value': 'and'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'service_type'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'if_statement', 'children': ['58', '68']}; {'id': '58', 'type': '()', 'children': ['59']}; {'id': '59', 'type': 'boolean_operator', 'children': ['60', '63'], 'value': 'and'}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'service_type'}; {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '73', 'type': 'elif_clause', 'children': ['74', '79']}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '76'], 'value': 'and'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '84', 'type': 'elif_clause', 'children': ['85', '92']}; {'id': '85', 'type': 'boolean_operator', 'children': ['86', '87'], 'value': 'and'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'service_type'}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'service_type'}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'return_statement', 'children': ['94']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '97', 'type': 'return_statement', 'children': ['98']}; {'id': '98', 'type': 'None', 'children': []}
Find the service_id of a given service
def n_failed(self): return self._counters[JobStatus.failed] + self._counters[JobStatus.partial_failed]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'n_failed'}; {'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': 'binary_operator', 'children': ['8', '15'], 'value': '+'}; {'id': '8', 'type': 'subscript', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': '_counters'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'JobStatus'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '15', 'type': 'subscript', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_counters'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'JobStatus'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'partial_failed'}
Return the number of failed jobs
def run(self, cmd): cmd = ['git', '--git-dir=%s' % self.path] + cmd print("cmd list", cmd) print("cmd", ' '.join(cmd)) res = None try: res = subprocess.check_output(cmd) except BaseException: pass if res: try: res = res.decode() except UnicodeDecodeError: res = res.decode('utf-8') return res
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '25', '36', '40', '55', '80']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '10', 'type': 'binary_operator', 'children': ['11', '18'], 'value': '+'}; {'id': '11', 'type': 'list', 'children': ['12', '13'], 'value': "['git', '--git-dir=%s' % self.path]"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'git'"}; {'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '%'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'--git-dir=%s'"}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}; {'id': '23', 'type': 'string', 'children': [], 'value': '"cmd list"'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'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', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"cmd"'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'try_statement', 'children': ['41', '51']}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'check_output'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '51', 'type': 'except_clause', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'BaseException'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'pass_statement', 'children': []}; {'id': '55', 'type': 'if_statement', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'try_statement', 'children': ['59', '68']}; {'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': 'res'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'except_clause', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'res'}
Execute git command in bash
def aggregated_relevant_items(raw_df): df = ( raw_df[['idSegmento', 'idPlanilhaItens', 'VlUnitarioAprovado']] .groupby(by=['idSegmento', 'idPlanilhaItens']) .agg([np.mean, lambda x: np.std(x, ddof=0)]) ) df.columns = df.columns.droplevel(0) return ( df .rename(columns={'<lambda>': 'std'}) )
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'aggregated_relevant_items'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'raw_df'}; {'id': '5', 'type': 'block', 'children': ['6', '45', '58']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '9', 'type': '()', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '28']}; {'id': '11', 'type': 'attribute', 'children': ['12', '27']}; {'id': '12', 'type': 'call', 'children': ['13', '21']}; {'id': '13', 'type': 'attribute', 'children': ['14', '20']}; {'id': '14', 'type': 'subscript', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'raw_df'}; {'id': '16', 'type': 'list', 'children': ['17', '18', '19'], 'value': "['idSegmento', 'idPlanilhaItens', 'VlUnitarioAprovado']"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'idSegmento'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'idPlanilhaItens'"}; {'id': '19', 'type': 'string', 'children': [], 'value': "'VlUnitarioAprovado'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '24', 'type': 'list', 'children': ['25', '26'], 'value': "['idSegmento', 'idPlanilhaItens']"}; {'id': '25', 'type': 'string', 'children': [], 'value': "'idSegmento'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'idPlanilhaItens'"}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'agg'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'list', 'children': ['30', '33'], 'value': '[np.mean, lambda x: np.std(x, ddof=0)]'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '33', 'type': 'lambda', 'children': ['34', '36']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ddof'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'droplevel'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': '()', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'rename'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '67', 'type': 'dictionary', 'children': ['68']}; {'id': '68', 'type': 'pair', 'children': ['69', '70']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'<lambda>'"}; {'id': '70', 'type': 'string', 'children': [], 'value': "'std'"}
Aggragation for calculate mean and std.
def intersect_two(f1, f2, work_dir, data): bedtools = config_utils.get_program("bedtools", data, default="bedtools") f1_exists = f1 and utils.file_exists(f1) f2_exists = f2 and utils.file_exists(f2) if not f1_exists and not f2_exists: return None elif f1_exists and not f2_exists: return f1 elif f2_exists and not f1_exists: return f2 else: out_file = os.path.join(work_dir, "%s-merged.bed" % (utils.splitext_plus(os.path.basename(f1))[0])) if not utils.file_exists(out_file): with file_transaction(data, out_file) as tx_out_file: cmd = "{bedtools} intersect -a {f1} -b {f2} > {tx_out_file}" do.run(cmd.format(**locals()), "Intersect BED files", data) return out_file
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersect_two'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'f1'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'f2'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'work_dir'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '8', 'type': 'block', 'children': ['9', '22', '33', '44']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'bedtools'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'config_utils'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_program'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}; {'id': '17', 'type': 'string', 'children': [], 'value': '"bedtools"'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"bedtools"'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'f1_exists'}; {'id': '25', 'type': 'boolean_operator', 'children': ['26', '27'], 'value': 'and'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'f1'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'file_exists'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'f1'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'f2_exists'}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '38'], 'value': 'and'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'f2'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'file_exists'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'f2'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50', '53', '61', '69']}; {'id': '45', 'type': 'boolean_operator', 'children': ['46', '48'], 'value': 'and'}; {'id': '46', 'type': 'not_operator', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'f1_exists'}; {'id': '48', 'type': 'not_operator', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'f2_exists'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'None', 'children': []}; {'id': '53', 'type': 'elif_clause', 'children': ['54', '58']}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '56'], 'value': 'and'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'f1_exists'}; {'id': '56', 'type': 'not_operator', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'f2_exists'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'f1'}; {'id': '61', 'type': 'elif_clause', 'children': ['62', '66']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'and'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'f2_exists'}; {'id': '64', 'type': 'not_operator', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'f1_exists'}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'f2'}; {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71', '100', '142']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '74', 'type': 'call', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'work_dir'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '%'}; {'id': '83', 'type': 'string', 'children': [], 'value': '"%s-merged.bed"'}; {'id': '84', 'type': '()', 'children': ['85']}; {'id': '85', 'type': 'subscript', 'children': ['86', '99']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'splitext_plus'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'f1'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '108']}; {'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': 'utils'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'file_exists'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '108', 'type': 'block', 'children': ['109']}; {'id': '109', 'type': 'with_statement', 'children': ['110', '120']}; {'id': '110', 'type': 'with_clause', 'children': ['111']}; {'id': '111', 'type': 'with_item', 'children': ['112']}; {'id': '112', 'type': 'as_pattern', 'children': ['113', '118']}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'file_transaction'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '118', 'type': 'as_pattern_target', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tx_out_file'}; {'id': '120', 'type': 'block', 'children': ['121', '125']}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '124', 'type': 'string', 'children': [], 'value': '"{bedtools} intersect -a {f1} -b {f2} > {tx_out_file}"'}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'do'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '140', '141']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'dictionary_splat', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'string', 'children': [], 'value': '"Intersect BED files"'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'out_file'}
Intersect two regions, handling cases where either file is not present.
def similar_items(self, itemid, N=10): if itemid >= self.similarity.shape[0]: return [] return sorted(list(nonzeros(self.similarity, itemid)), key=lambda x: -x[1])[:N]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'similar_items'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'itemid'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '9', 'type': 'block', 'children': ['10', '23']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '20']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '>='}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'itemid'}; {'id': '13', 'type': 'subscript', 'children': ['14', '19']}; {'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': 'similarity'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'subscript', 'children': ['25', '47']}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '38']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'nonzeros'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'similarity'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'itemid'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '40', 'type': 'lambda', 'children': ['41', '43']}; {'id': '41', 'type': 'lambda_parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '43', 'type': 'unary_operator', 'children': ['44'], 'value': '-'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '47', 'type': 'slice', 'children': ['48', '49']}; {'id': '48', 'type': 'colon', 'children': []}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'N'}
Returns a list of the most similar other items
def _is_streaming_request(self): arg2 = self.argstreams[1] arg3 = self.argstreams[2] return not (isinstance(arg2, InMemStream) and isinstance(arg3, InMemStream) and ((arg2.auto_close and arg3.auto_close) or ( arg2.state == StreamState.completed and arg3.state == StreamState.completed)))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_is_streaming_request'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '22']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'arg2'}; {'id': '9', 'type': 'subscript', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'argstreams'}; {'id': '13', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'arg3'}; {'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': 'argstreams'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '22', 'type': 'return_statement', 'children': ['23']}; {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': '()', 'children': ['25']}; {'id': '25', 'type': 'boolean_operator', 'children': ['26', '37'], 'value': 'and'}; {'id': '26', 'type': 'boolean_operator', 'children': ['27', '32'], 'value': 'and'}; {'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': 'arg2'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'InMemStream'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'arg3'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'InMemStream'}; {'id': '37', 'type': '()', 'children': ['38']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '47'], 'value': 'or'}; {'id': '39', 'type': '()', 'children': ['40']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'and'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'arg2'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'auto_close'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'arg3'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'auto_close'}; {'id': '47', 'type': '()', 'children': ['48']}; {'id': '48', 'type': 'boolean_operator', 'children': ['49', '56'], 'value': 'and'}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '=='}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'arg2'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'StreamState'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'completed'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '60'], 'value': '=='}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'arg3'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'StreamState'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'completed'}
check request is stream request or not