sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_serve_runs; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:request; 6, block; 6, 7; 6, 99; 7, if_statement; 7, 8; 7, 11; 7, 39; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_db_connection_provider; 11, block; 11, 12; 11, 20; 11, 29; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:db; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_db_connection_provider; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:cursor; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:db; 26, identifier:execute; 27, argument_list; 27, 28; 28, string:'''
SELECT
run_name,
started_time IS NULL as started_time_nulls_last,
started_time
FROM Runs
ORDER BY started_time_nulls_last, started_time, run_name
'''; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:run_names; 32, list_comprehension; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:row; 35, integer:0; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:row; 38, identifier:cursor; 39, else_clause; 39, 40; 40, block; 40, 41; 40, 54; 40, 90; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:run_names; 44, call; 44, 45; 44, 46; 45, identifier:sorted; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_multiplexer; 52, identifier:Runs; 53, argument_list; 54, function_definition; 54, 55; 54, 56; 54, 58; 55, function_name:get_first_event_timestamp; 56, parameters; 56, 57; 57, identifier:run_name; 58, block; 58, 59; 59, try_statement; 59, 60; 59, 70; 60, block; 60, 61; 61, return_statement; 61, 62; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_multiplexer; 67, identifier:FirstEventTimestamp; 68, argument_list; 68, 69; 69, identifier:run_name; 70, except_clause; 70, 71; 70, 75; 71, as_pattern; 71, 72; 71, 73; 72, identifier:ValueError; 73, as_pattern_target; 73, 74; 74, identifier:e; 75, block; 75, 76; 75, 85; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:logger; 80, identifier:warn; 81, argument_list; 81, 82; 81, 83; 81, 84; 82, string:'Unable to get first event timestamp for run %s: %s'; 83, identifier:run_name; 84, identifier:e; 85, return_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:float; 88, argument_list; 88, 89; 89, string:'inf'; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:run_names; 94, identifier:sort; 95, argument_list; 95, 96; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:key; 98, identifier:get_first_event_timestamp; 99, return_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:http_util; 103, identifier:Respond; 104, argument_list; 104, 105; 104, 106; 104, 107; 105, identifier:request; 106, identifier:run_names; 107, string:'application/json' | def _serve_runs(self, request):
if self._db_connection_provider:
db = self._db_connection_provider()
cursor = db.execute('''
SELECT
run_name,
started_time IS NULL as started_time_nulls_last,
started_time
FROM Runs
ORDER BY started_time_nulls_last, started_time, run_name
''')
run_names = [row[0] for row in cursor]
else:
run_names = sorted(self._multiplexer.Runs())
def get_first_event_timestamp(run_name):
try:
return self._multiplexer.FirstEventTimestamp(run_name)
except ValueError as e:
logger.warn(
'Unable to get first event timestamp for run %s: %s', run_name, e)
return float('inf')
run_names.sort(key=get_first_event_timestamp)
return http_util.Respond(request, run_names, 'application/json') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_fetch_events_files_on_disk; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 21; 5, 36; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:all_files; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:tf; 14, identifier:io; 15, identifier:gfile; 16, identifier:listdir; 17, argument_list; 17, 18; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_events_directory; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:relevant_files; 24, list_comprehension; 24, 25; 24, 26; 24, 29; 25, identifier:file_name; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:file_name; 28, identifier:all_files; 29, if_clause; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:_DEBUGGER_EVENTS_FILE_NAME_REGEX; 33, identifier:match; 34, argument_list; 34, 35; 35, identifier:file_name; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:sorted; 39, argument_list; 39, 40; 39, 41; 40, identifier:relevant_files; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:key; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_obtain_file_index | def _fetch_events_files_on_disk(self):
all_files = tf.io.gfile.listdir(self._events_directory)
relevant_files = [
file_name for file_name in all_files
if _DEBUGGER_EVENTS_FILE_NAME_REGEX.match(file_name)
]
return sorted(relevant_files, key=self._obtain_file_index) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:Cleanse; 3, parameters; 3, 4; 3, 5; 4, identifier:obj; 5, default_parameter; 5, 6; 5, 7; 6, identifier:encoding; 7, string:'utf-8'; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 15; 9, 18; 9, 53; 9, 70; 9, 89; 9, 109; 9, 138; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:obj; 14, identifier:int; 15, block; 15, 16; 16, return_statement; 16, 17; 17, identifier:obj; 18, elif_clause; 18, 19; 18, 24; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:obj; 23, identifier:float; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 29; 25, 32; 25, 39; 25, 49; 26, comparison_operator:==; 26, 27; 26, 28; 27, identifier:obj; 28, identifier:_INFINITY; 29, block; 29, 30; 30, return_statement; 30, 31; 31, string:'Infinity'; 32, elif_clause; 32, 33; 32, 36; 33, comparison_operator:==; 33, 34; 33, 35; 34, identifier:obj; 35, identifier:_NEGATIVE_INFINITY; 36, block; 36, 37; 37, return_statement; 37, 38; 38, string:'-Infinity'; 39, elif_clause; 39, 40; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:math; 43, identifier:isnan; 44, argument_list; 44, 45; 45, identifier:obj; 46, block; 46, 47; 47, return_statement; 47, 48; 48, string:'NaN'; 49, else_clause; 49, 50; 50, block; 50, 51; 51, return_statement; 51, 52; 52, identifier:obj; 53, elif_clause; 53, 54; 53, 59; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:obj; 58, identifier:bytes; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:tf; 65, identifier:compat; 66, identifier:as_text; 67, argument_list; 67, 68; 67, 69; 68, identifier:obj; 69, identifier:encoding; 70, elif_clause; 70, 71; 70, 78; 71, call; 71, 72; 71, 73; 72, identifier:isinstance; 73, argument_list; 73, 74; 73, 75; 74, identifier:obj; 75, tuple; 75, 76; 75, 77; 76, identifier:list; 77, identifier:tuple; 78, block; 78, 79; 79, return_statement; 79, 80; 80, list_comprehension; 80, 81; 80, 86; 81, call; 81, 82; 81, 83; 82, identifier:Cleanse; 83, argument_list; 83, 84; 83, 85; 84, identifier:i; 85, identifier:encoding; 86, for_in_clause; 86, 87; 86, 88; 87, identifier:i; 88, identifier:obj; 89, elif_clause; 89, 90; 89, 95; 90, call; 90, 91; 90, 92; 91, identifier:isinstance; 92, argument_list; 92, 93; 92, 94; 93, identifier:obj; 94, identifier:set; 95, block; 95, 96; 96, return_statement; 96, 97; 97, list_comprehension; 97, 98; 97, 103; 98, call; 98, 99; 98, 100; 99, identifier:Cleanse; 100, argument_list; 100, 101; 100, 102; 101, identifier:i; 102, identifier:encoding; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:i; 105, call; 105, 106; 105, 107; 106, identifier:sorted; 107, argument_list; 107, 108; 108, identifier:obj; 109, elif_clause; 109, 110; 109, 115; 110, call; 110, 111; 110, 112; 111, identifier:isinstance; 112, argument_list; 112, 113; 112, 114; 113, identifier:obj; 114, identifier:dict; 115, block; 115, 116; 116, return_statement; 116, 117; 117, dictionary_comprehension; 117, 118; 117, 129; 118, pair; 118, 119; 118, 124; 119, call; 119, 120; 119, 121; 120, identifier:Cleanse; 121, argument_list; 121, 122; 121, 123; 122, identifier:k; 123, identifier:encoding; 124, call; 124, 125; 124, 126; 125, identifier:Cleanse; 126, argument_list; 126, 127; 126, 128; 127, identifier:v; 128, identifier:encoding; 129, for_in_clause; 129, 130; 129, 133; 130, pattern_list; 130, 131; 130, 132; 131, identifier:k; 132, identifier:v; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:obj; 136, identifier:items; 137, argument_list; 138, else_clause; 138, 139; 139, block; 139, 140; 140, return_statement; 140, 141; 141, identifier:obj | def Cleanse(obj, encoding='utf-8'):
if isinstance(obj, int):
return obj
elif isinstance(obj, float):
if obj == _INFINITY:
return 'Infinity'
elif obj == _NEGATIVE_INFINITY:
return '-Infinity'
elif math.isnan(obj):
return 'NaN'
else:
return obj
elif isinstance(obj, bytes):
return tf.compat.as_text(obj, encoding)
elif isinstance(obj, (list, tuple)):
return [Cleanse(i, encoding) for i in obj]
elif isinstance(obj, set):
return [Cleanse(i, encoding) for i in sorted(obj)]
elif isinstance(obj, dict):
return {Cleanse(k, encoding): Cleanse(v, encoding) for k, v in obj.items()}
else:
return obj |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:session_groups; 6, block; 6, 7; 6, 21; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:session_groups; 11, identifier:sort; 12, argument_list; 12, 13; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:key; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:operator; 18, identifier:attrgetter; 19, argument_list; 19, 20; 20, string:'name'; 21, for_statement; 21, 22; 21, 25; 21, 42; 22, pattern_list; 22, 23; 22, 24; 23, identifier:col_param; 24, identifier:extractor; 25, call; 25, 26; 25, 27; 26, identifier:reversed; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:list; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:zip; 33, argument_list; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_request; 38, identifier:col_params; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_extractors; 42, block; 42, 43; 42, 53; 43, if_statement; 43, 44; 43, 51; 44, comparison_operator:==; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:col_param; 47, identifier:order; 48, attribute; 48, 49; 48, 50; 49, identifier:api_pb2; 50, identifier:ORDER_UNSPECIFIED; 51, block; 51, 52; 52, continue_statement; 53, if_statement; 53, 54; 53, 61; 53, 80; 53, 109; 54, comparison_operator:==; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:col_param; 57, identifier:order; 58, attribute; 58, 59; 58, 60; 59, identifier:api_pb2; 60, identifier:ORDER_ASC; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:session_groups; 66, identifier:sort; 67, argument_list; 67, 68; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:key; 70, call; 70, 71; 70, 72; 71, identifier:_create_key_func; 72, argument_list; 72, 73; 72, 74; 73, identifier:extractor; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:none_is_largest; 76, not_operator; 76, 77; 77, attribute; 77, 78; 77, 79; 78, identifier:col_param; 79, identifier:missing_values_first; 80, elif_clause; 80, 81; 80, 88; 81, comparison_operator:==; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:col_param; 84, identifier:order; 85, attribute; 85, 86; 85, 87; 86, identifier:api_pb2; 87, identifier:ORDER_DESC; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:session_groups; 93, identifier:sort; 94, argument_list; 94, 95; 94, 106; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:key; 97, call; 97, 98; 97, 99; 98, identifier:_create_key_func; 99, argument_list; 99, 100; 99, 101; 100, identifier:extractor; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:none_is_largest; 103, attribute; 103, 104; 103, 105; 104, identifier:col_param; 105, identifier:missing_values_first; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:reverse; 108, True; 109, else_clause; 109, 110; 110, block; 110, 111; 111, raise_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:error; 115, identifier:HParamsError; 116, argument_list; 116, 117; 117, binary_operator:%; 117, 118; 117, 119; 118, string:'Unknown col_param.order given: %s'; 119, identifier:col_param | def _sort(self, session_groups):
session_groups.sort(key=operator.attrgetter('name'))
for col_param, extractor in reversed(list(zip(self._request.col_params,
self._extractors))):
if col_param.order == api_pb2.ORDER_UNSPECIFIED:
continue
if col_param.order == api_pb2.ORDER_ASC:
session_groups.sort(
key=_create_key_func(
extractor,
none_is_largest=not col_param.missing_values_first))
elif col_param.order == api_pb2.ORDER_DESC:
session_groups.sort(
key=_create_key_func(
extractor,
none_is_largest=col_param.missing_values_first),
reverse=True)
else:
raise error.HParamsError('Unknown col_param.order given: %s' %
col_param) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:search; 6, block; 6, 7; 6, 24; 7, if_statement; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_sort; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:search; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:search; 18, identifier:sort; 19, argument_list; 19, 20; 20, list_splat; 20, 21; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_sort; 24, return_statement; 24, 25; 25, identifier:search | def sort(self, search):
if self._sort:
search = search.sort(*self._sort)
return search |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:competitions_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:group; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:category; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_by; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:page; 16, integer:1; 17, default_parameter; 17, 18; 17, 19; 18, identifier:search; 19, None; 20, block; 20, 21; 20, 28; 20, 45; 20, 56; 20, 73; 20, 83; 20, 100; 20, 136; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:valid_groups; 24, list:['general', 'entered', 'inClass']; 24, 25; 24, 26; 24, 27; 25, string:'general'; 26, string:'entered'; 27, string:'inClass'; 28, if_statement; 28, 29; 28, 34; 29, boolean_operator:and; 29, 30; 29, 31; 30, identifier:group; 31, comparison_operator:not; 31, 32; 31, 33; 32, identifier:group; 33, identifier:valid_groups; 34, block; 34, 35; 35, raise_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:ValueError; 38, argument_list; 38, 39; 39, binary_operator:+; 39, 40; 39, 41; 40, string:'Invalid group specified. Valid options are '; 41, call; 41, 42; 41, 43; 42, identifier:str; 43, argument_list; 43, 44; 44, identifier:valid_groups; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:valid_categories; 48, list:[
'all', 'featured', 'research', 'recruitment', 'gettingStarted',
'masters', 'playground'
]; 48, 49; 48, 50; 48, 51; 48, 52; 48, 53; 48, 54; 48, 55; 49, string:'all'; 50, string:'featured'; 51, string:'research'; 52, string:'recruitment'; 53, string:'gettingStarted'; 54, string:'masters'; 55, string:'playground'; 56, if_statement; 56, 57; 56, 62; 57, boolean_operator:and; 57, 58; 57, 59; 58, identifier:category; 59, comparison_operator:not; 59, 60; 59, 61; 60, identifier:category; 61, identifier:valid_categories; 62, block; 62, 63; 63, raise_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:ValueError; 66, argument_list; 66, 67; 67, binary_operator:+; 67, 68; 67, 69; 68, string:'Invalid category specified. Valid options are '; 69, call; 69, 70; 69, 71; 70, identifier:str; 71, argument_list; 71, 72; 72, identifier:valid_categories; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:valid_sort_by; 76, list:[
'grouped', 'prize', 'earliestDeadline', 'latestDeadline',
'numberOfTeams', 'recentlyCreated'
]; 76, 77; 76, 78; 76, 79; 76, 80; 76, 81; 76, 82; 77, string:'grouped'; 78, string:'prize'; 79, string:'earliestDeadline'; 80, string:'latestDeadline'; 81, string:'numberOfTeams'; 82, string:'recentlyCreated'; 83, if_statement; 83, 84; 83, 89; 84, boolean_operator:and; 84, 85; 84, 86; 85, identifier:sort_by; 86, comparison_operator:not; 86, 87; 86, 88; 87, identifier:sort_by; 88, identifier:valid_sort_by; 89, block; 89, 90; 90, raise_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:ValueError; 93, argument_list; 93, 94; 94, binary_operator:+; 94, 95; 94, 96; 95, string:'Invalid sort_by specified. Valid options are '; 96, call; 96, 97; 96, 98; 97, identifier:str; 98, argument_list; 98, 99; 99, identifier:valid_sort_by; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:competitions_list_result; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:process_response; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:competitions_list_with_http_info; 112, argument_list; 112, 113; 112, 118; 112, 123; 112, 128; 112, 131; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:group; 115, boolean_operator:or; 115, 116; 115, 117; 116, identifier:group; 117, string:''; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:category; 120, boolean_operator:or; 120, 121; 120, 122; 121, identifier:category; 122, string:''; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:sort_by; 125, boolean_operator:or; 125, 126; 125, 127; 126, identifier:sort_by; 127, string:''; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:page; 130, identifier:page; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:search; 133, boolean_operator:or; 133, 134; 133, 135; 134, identifier:search; 135, string:''; 136, return_statement; 136, 137; 137, list_comprehension; 137, 138; 137, 142; 138, call; 138, 139; 138, 140; 139, identifier:Competition; 140, argument_list; 140, 141; 141, identifier:c; 142, for_in_clause; 142, 143; 142, 144; 143, identifier:c; 144, identifier:competitions_list_result | def competitions_list(self,
group=None,
category=None,
sort_by=None,
page=1,
search=None):
valid_groups = ['general', 'entered', 'inClass']
if group and group not in valid_groups:
raise ValueError('Invalid group specified. Valid options are ' +
str(valid_groups))
valid_categories = [
'all', 'featured', 'research', 'recruitment', 'gettingStarted',
'masters', 'playground'
]
if category and category not in valid_categories:
raise ValueError('Invalid category specified. Valid options are ' +
str(valid_categories))
valid_sort_by = [
'grouped', 'prize', 'earliestDeadline', 'latestDeadline',
'numberOfTeams', 'recentlyCreated'
]
if sort_by and sort_by not in valid_sort_by:
raise ValueError('Invalid sort_by specified. Valid options are ' +
str(valid_sort_by))
competitions_list_result = self.process_response(
self.competitions_list_with_http_info(
group=group or '',
category=category or '',
sort_by=sort_by or '',
page=page,
search=search or ''))
return [Competition(c) for c in competitions_list_result] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:competitions_list_cli; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:group; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:category; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort_by; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:page; 16, integer:1; 17, default_parameter; 17, 18; 17, 19; 18, identifier:search; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:csv_display; 22, False; 23, block; 23, 24; 23, 47; 23, 57; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:competitions; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:competitions_list; 31, argument_list; 31, 32; 31, 35; 31, 38; 31, 41; 31, 44; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:group; 34, identifier:group; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:category; 37, identifier:category; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:sort_by; 40, identifier:sort_by; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:page; 43, identifier:page; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:search; 46, identifier:search; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:fields; 50, list:[
'ref', 'deadline', 'category', 'reward', 'teamCount',
'userHasEntered'
]; 50, 51; 50, 52; 50, 53; 50, 54; 50, 55; 50, 56; 51, string:'ref'; 52, string:'deadline'; 53, string:'category'; 54, string:'reward'; 55, string:'teamCount'; 56, string:'userHasEntered'; 57, if_statement; 57, 58; 57, 59; 57, 81; 58, identifier:competitions; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 62; 60, 71; 61, identifier:csv_display; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:print_csv; 68, argument_list; 68, 69; 68, 70; 69, identifier:competitions; 70, identifier:fields; 71, else_clause; 71, 72; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:print_table; 78, argument_list; 78, 79; 78, 80; 79, identifier:competitions; 80, identifier:fields; 81, else_clause; 81, 82; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:print; 86, argument_list; 86, 87; 87, string:'No competitions found' | def competitions_list_cli(self,
group=None,
category=None,
sort_by=None,
page=1,
search=None,
csv_display=False):
competitions = self.competitions_list(
group=group,
category=category,
sort_by=sort_by,
page=page,
search=search)
fields = [
'ref', 'deadline', 'category', 'reward', 'teamCount',
'userHasEntered'
]
if competitions:
if csv_display:
self.print_csv(competitions, fields)
else:
self.print_table(competitions, fields)
else:
print('No competitions found') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:dataset_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_by; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:size; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:file_type; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:license_name; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:tag_ids; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:search; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:user; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:mine; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:page; 31, integer:1; 32, block; 32, 33; 32, 42; 32, 59; 32, 67; 32, 84; 32, 93; 32, 110; 32, 119; 32, 136; 32, 149; 32, 153; 32, 168; 32, 175; 32, 229; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:valid_sort_bys; 36, list:['hottest', 'votes', 'updated', 'active', 'published']; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 37, string:'hottest'; 38, string:'votes'; 39, string:'updated'; 40, string:'active'; 41, string:'published'; 42, if_statement; 42, 43; 42, 48; 43, boolean_operator:and; 43, 44; 43, 45; 44, identifier:sort_by; 45, comparison_operator:not; 45, 46; 45, 47; 46, identifier:sort_by; 47, identifier:valid_sort_bys; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:ValueError; 52, argument_list; 52, 53; 53, binary_operator:+; 53, 54; 53, 55; 54, string:'Invalid sort by specified. Valid options are '; 55, call; 55, 56; 55, 57; 56, identifier:str; 57, argument_list; 57, 58; 58, identifier:valid_sort_bys; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:valid_sizes; 62, list:['all', 'small', 'medium', 'large']; 62, 63; 62, 64; 62, 65; 62, 66; 63, string:'all'; 64, string:'small'; 65, string:'medium'; 66, string:'large'; 67, if_statement; 67, 68; 67, 73; 68, boolean_operator:and; 68, 69; 68, 70; 69, identifier:size; 70, comparison_operator:not; 70, 71; 70, 72; 71, identifier:size; 72, identifier:valid_sizes; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:ValueError; 77, argument_list; 77, 78; 78, binary_operator:+; 78, 79; 78, 80; 79, string:'Invalid size specified. Valid options are '; 80, call; 80, 81; 80, 82; 81, identifier:str; 82, argument_list; 82, 83; 83, identifier:valid_sizes; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:valid_file_types; 87, list:['all', 'csv', 'sqlite', 'json', 'bigQuery']; 87, 88; 87, 89; 87, 90; 87, 91; 87, 92; 88, string:'all'; 89, string:'csv'; 90, string:'sqlite'; 91, string:'json'; 92, string:'bigQuery'; 93, if_statement; 93, 94; 93, 99; 94, boolean_operator:and; 94, 95; 94, 96; 95, identifier:file_type; 96, comparison_operator:not; 96, 97; 96, 98; 97, identifier:file_type; 98, identifier:valid_file_types; 99, block; 99, 100; 100, raise_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:ValueError; 103, argument_list; 103, 104; 104, binary_operator:+; 104, 105; 104, 106; 105, string:'Invalid file type specified. Valid options are '; 106, call; 106, 107; 106, 108; 107, identifier:str; 108, argument_list; 108, 109; 109, identifier:valid_file_types; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:valid_license_names; 113, list:['all', 'cc', 'gpl', 'odb', 'other']; 113, 114; 113, 115; 113, 116; 113, 117; 113, 118; 114, string:'all'; 115, string:'cc'; 116, string:'gpl'; 117, string:'odb'; 118, string:'other'; 119, if_statement; 119, 120; 119, 125; 120, boolean_operator:and; 120, 121; 120, 122; 121, identifier:license_name; 122, comparison_operator:not; 122, 123; 122, 124; 123, identifier:license_name; 124, identifier:valid_license_names; 125, block; 125, 126; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:ValueError; 129, argument_list; 129, 130; 130, binary_operator:+; 130, 131; 130, 132; 131, string:'Invalid license specified. Valid options are '; 132, call; 132, 133; 132, 134; 133, identifier:str; 134, argument_list; 134, 135; 135, identifier:valid_license_names; 136, if_statement; 136, 137; 136, 143; 137, comparison_operator:<=; 137, 138; 137, 142; 138, call; 138, 139; 138, 140; 139, identifier:int; 140, argument_list; 140, 141; 141, identifier:page; 142, integer:0; 143, block; 143, 144; 144, raise_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:ValueError; 147, argument_list; 147, 148; 148, string:'Page number must be >= 1'; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:group; 152, string:'public'; 153, if_statement; 153, 154; 153, 155; 154, identifier:mine; 155, block; 155, 156; 155, 160; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:group; 159, string:'my'; 160, if_statement; 160, 161; 160, 162; 161, identifier:user; 162, block; 162, 163; 163, raise_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:ValueError; 166, argument_list; 166, 167; 167, string:'Cannot specify both mine and a user'; 168, if_statement; 168, 169; 168, 170; 169, identifier:user; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:group; 174, string:'user'; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:datasets_list_result; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:process_response; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:datasets_list_with_http_info; 187, argument_list; 187, 188; 187, 191; 187, 196; 187, 201; 187, 206; 187, 211; 187, 216; 187, 221; 187, 226; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:group; 190, identifier:group; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:sort_by; 193, boolean_operator:or; 193, 194; 193, 195; 194, identifier:sort_by; 195, string:'hottest'; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:size; 198, boolean_operator:or; 198, 199; 198, 200; 199, identifier:size; 200, string:'all'; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:filetype; 203, boolean_operator:or; 203, 204; 203, 205; 204, identifier:file_type; 205, string:'all'; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:license; 208, boolean_operator:or; 208, 209; 208, 210; 209, identifier:license_name; 210, string:'all'; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:tagids; 213, boolean_operator:or; 213, 214; 213, 215; 214, identifier:tag_ids; 215, string:''; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:search; 218, boolean_operator:or; 218, 219; 218, 220; 219, identifier:search; 220, string:''; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:user; 223, boolean_operator:or; 223, 224; 223, 225; 224, identifier:user; 225, string:''; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:page; 228, identifier:page; 229, return_statement; 229, 230; 230, list_comprehension; 230, 231; 230, 235; 231, call; 231, 232; 231, 233; 232, identifier:Dataset; 233, argument_list; 233, 234; 234, identifier:d; 235, for_in_clause; 235, 236; 235, 237; 236, identifier:d; 237, identifier:datasets_list_result | def dataset_list(self,
sort_by=None,
size=None,
file_type=None,
license_name=None,
tag_ids=None,
search=None,
user=None,
mine=False,
page=1):
valid_sort_bys = ['hottest', 'votes', 'updated', 'active', 'published']
if sort_by and sort_by not in valid_sort_bys:
raise ValueError('Invalid sort by specified. Valid options are ' +
str(valid_sort_bys))
valid_sizes = ['all', 'small', 'medium', 'large']
if size and size not in valid_sizes:
raise ValueError('Invalid size specified. Valid options are ' +
str(valid_sizes))
valid_file_types = ['all', 'csv', 'sqlite', 'json', 'bigQuery']
if file_type and file_type not in valid_file_types:
raise ValueError('Invalid file type specified. Valid options are '
+ str(valid_file_types))
valid_license_names = ['all', 'cc', 'gpl', 'odb', 'other']
if license_name and license_name not in valid_license_names:
raise ValueError('Invalid license specified. Valid options are ' +
str(valid_license_names))
if int(page) <= 0:
raise ValueError('Page number must be >= 1')
group = 'public'
if mine:
group = 'my'
if user:
raise ValueError('Cannot specify both mine and a user')
if user:
group = 'user'
datasets_list_result = self.process_response(
self.datasets_list_with_http_info(
group=group,
sort_by=sort_by or 'hottest',
size=size or 'all',
filetype=file_type or 'all',
license=license_name or 'all',
tagids=tag_ids or '',
search=search or '',
user=user or '',
page=page))
return [Dataset(d) for d in datasets_list_result] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 2, function_name:dataset_list_cli; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_by; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:size; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:file_type; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:license_name; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:tag_ids; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:search; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:user; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:mine; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:page; 31, integer:1; 32, default_parameter; 32, 33; 32, 34; 33, identifier:csv_display; 34, False; 35, block; 35, 36; 35, 53; 35, 62; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:datasets; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:dataset_list; 43, argument_list; 43, 44; 43, 45; 43, 46; 43, 47; 43, 48; 43, 49; 43, 50; 43, 51; 43, 52; 44, identifier:sort_by; 45, identifier:size; 46, identifier:file_type; 47, identifier:license_name; 48, identifier:tag_ids; 49, identifier:search; 50, identifier:user; 51, identifier:mine; 52, identifier:page; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:fields; 56, list:['ref', 'title', 'size', 'lastUpdated', 'downloadCount']; 56, 57; 56, 58; 56, 59; 56, 60; 56, 61; 57, string:'ref'; 58, string:'title'; 59, string:'size'; 60, string:'lastUpdated'; 61, string:'downloadCount'; 62, if_statement; 62, 63; 62, 64; 62, 86; 63, identifier:datasets; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 67; 65, 76; 66, identifier:csv_display; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:print_csv; 73, argument_list; 73, 74; 73, 75; 74, identifier:datasets; 75, identifier:fields; 76, else_clause; 76, 77; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:print_table; 83, argument_list; 83, 84; 83, 85; 84, identifier:datasets; 85, identifier:fields; 86, else_clause; 86, 87; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:print; 91, argument_list; 91, 92; 92, string:'No datasets found' | def dataset_list_cli(self,
sort_by=None,
size=None,
file_type=None,
license_name=None,
tag_ids=None,
search=None,
user=None,
mine=False,
page=1,
csv_display=False):
datasets = self.dataset_list(sort_by, size, file_type, license_name,
tag_ids, search, user, mine, page)
fields = ['ref', 'title', 'size', 'lastUpdated', 'downloadCount']
if datasets:
if csv_display:
self.print_csv(datasets, fields)
else:
self.print_table(datasets, fields)
else:
print('No datasets found') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 41; 2, function_name:kernels_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:page; 7, integer:1; 8, default_parameter; 8, 9; 8, 10; 9, identifier:page_size; 10, integer:20; 11, default_parameter; 11, 12; 11, 13; 12, identifier:dataset; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:competition; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:parent_kernel; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:search; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:mine; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:user; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:language; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:kernel_type; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:output_type; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:sort_by; 40, None; 41, block; 41, 42; 41, 55; 41, 62; 41, 72; 41, 81; 41, 90; 41, 107; 41, 114; 41, 131; 41, 138; 41, 155; 41, 168; 41, 185; 41, 199; 41, 206; 41, 213; 41, 217; 41, 224; 41, 291; 42, if_statement; 42, 43; 42, 49; 43, comparison_operator:<=; 43, 44; 43, 48; 44, call; 44, 45; 44, 46; 45, identifier:int; 46, argument_list; 46, 47; 47, identifier:page; 48, integer:0; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ValueError; 53, argument_list; 53, 54; 54, string:'Page number must be >= 1'; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:page_size; 58, call; 58, 59; 58, 60; 59, identifier:int; 60, argument_list; 60, 61; 61, identifier:page_size; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:<=; 63, 64; 63, 65; 64, identifier:page_size; 65, integer:0; 66, block; 66, 67; 67, raise_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:ValueError; 70, argument_list; 70, 71; 71, string:'Page size must be >= 1'; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:>; 73, 74; 73, 75; 74, identifier:page_size; 75, integer:100; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:page_size; 80, integer:100; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:valid_languages; 84, list:['all', 'python', 'r', 'sqlite', 'julia']; 84, 85; 84, 86; 84, 87; 84, 88; 84, 89; 85, string:'all'; 86, string:'python'; 87, string:'r'; 88, string:'sqlite'; 89, string:'julia'; 90, if_statement; 90, 91; 90, 96; 91, boolean_operator:and; 91, 92; 91, 93; 92, identifier:language; 93, comparison_operator:not; 93, 94; 93, 95; 94, identifier:language; 95, identifier:valid_languages; 96, block; 96, 97; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:ValueError; 100, argument_list; 100, 101; 101, binary_operator:+; 101, 102; 101, 103; 102, string:'Invalid language specified. Valid options are '; 103, call; 103, 104; 103, 105; 104, identifier:str; 105, argument_list; 105, 106; 106, identifier:valid_languages; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:valid_kernel_types; 110, list:['all', 'script', 'notebook']; 110, 111; 110, 112; 110, 113; 111, string:'all'; 112, string:'script'; 113, string:'notebook'; 114, if_statement; 114, 115; 114, 120; 115, boolean_operator:and; 115, 116; 115, 117; 116, identifier:kernel_type; 117, comparison_operator:not; 117, 118; 117, 119; 118, identifier:kernel_type; 119, identifier:valid_kernel_types; 120, block; 120, 121; 121, raise_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:ValueError; 124, argument_list; 124, 125; 125, binary_operator:+; 125, 126; 125, 127; 126, string:'Invalid kernel type specified. Valid options are '; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:valid_kernel_types; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:valid_output_types; 134, list:['all', 'visualization', 'data']; 134, 135; 134, 136; 134, 137; 135, string:'all'; 136, string:'visualization'; 137, string:'data'; 138, if_statement; 138, 139; 138, 144; 139, boolean_operator:and; 139, 140; 139, 141; 140, identifier:output_type; 141, comparison_operator:not; 141, 142; 141, 143; 142, identifier:output_type; 143, identifier:valid_output_types; 144, block; 144, 145; 145, raise_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:ValueError; 148, argument_list; 148, 149; 149, binary_operator:+; 149, 150; 149, 151; 150, string:'Invalid output type specified. Valid options are '; 151, call; 151, 152; 151, 153; 152, identifier:str; 153, argument_list; 153, 154; 154, identifier:valid_output_types; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:valid_sort_by; 158, list:[
'hotness', 'commentCount', 'dateCreated', 'dateRun', 'relevance',
'scoreAscending', 'scoreDescending', 'viewCount', 'voteCount'
]; 158, 159; 158, 160; 158, 161; 158, 162; 158, 163; 158, 164; 158, 165; 158, 166; 158, 167; 159, string:'hotness'; 160, string:'commentCount'; 161, string:'dateCreated'; 162, string:'dateRun'; 163, string:'relevance'; 164, string:'scoreAscending'; 165, string:'scoreDescending'; 166, string:'viewCount'; 167, string:'voteCount'; 168, if_statement; 168, 169; 168, 174; 169, boolean_operator:and; 169, 170; 169, 171; 170, identifier:sort_by; 171, comparison_operator:not; 171, 172; 171, 173; 172, identifier:sort_by; 173, identifier:valid_sort_by; 174, block; 174, 175; 175, raise_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:ValueError; 178, argument_list; 178, 179; 179, binary_operator:+; 179, 180; 179, 181; 180, string:'Invalid sort by type specified. Valid options are '; 181, call; 181, 182; 181, 183; 182, identifier:str; 183, argument_list; 183, 184; 184, identifier:valid_sort_by; 185, if_statement; 185, 186; 185, 193; 186, boolean_operator:and; 186, 187; 186, 190; 187, comparison_operator:==; 187, 188; 187, 189; 188, identifier:sort_by; 189, string:'relevance'; 190, comparison_operator:==; 190, 191; 190, 192; 191, identifier:search; 192, string:''; 193, block; 193, 194; 194, raise_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:ValueError; 197, argument_list; 197, 198; 198, string:'Cannot sort by relevance without a search term.'; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:validate_dataset_string; 204, argument_list; 204, 205; 205, identifier:dataset; 206, expression_statement; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:validate_kernel_string; 211, argument_list; 211, 212; 212, identifier:parent_kernel; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:group; 216, string:'everyone'; 217, if_statement; 217, 218; 217, 219; 218, identifier:mine; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:group; 223, string:'profile'; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:kernels_list_result; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:process_response; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:kernels_list_with_http_info; 236, argument_list; 236, 237; 236, 240; 236, 243; 236, 246; 236, 251; 236, 256; 236, 261; 236, 266; 236, 271; 236, 276; 236, 281; 236, 286; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:page; 239, identifier:page; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:page_size; 242, identifier:page_size; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:group; 245, identifier:group; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:user; 248, boolean_operator:or; 248, 249; 248, 250; 249, identifier:user; 250, string:''; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:language; 253, boolean_operator:or; 253, 254; 253, 255; 254, identifier:language; 255, string:'all'; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:kernel_type; 258, boolean_operator:or; 258, 259; 258, 260; 259, identifier:kernel_type; 260, string:'all'; 261, keyword_argument; 261, 262; 261, 263; 262, identifier:output_type; 263, boolean_operator:or; 263, 264; 263, 265; 264, identifier:output_type; 265, string:'all'; 266, keyword_argument; 266, 267; 266, 268; 267, identifier:sort_by; 268, boolean_operator:or; 268, 269; 268, 270; 269, identifier:sort_by; 270, string:'hotness'; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:dataset; 273, boolean_operator:or; 273, 274; 273, 275; 274, identifier:dataset; 275, string:''; 276, keyword_argument; 276, 277; 276, 278; 277, identifier:competition; 278, boolean_operator:or; 278, 279; 278, 280; 279, identifier:competition; 280, string:''; 281, keyword_argument; 281, 282; 281, 283; 282, identifier:parent_kernel; 283, boolean_operator:or; 283, 284; 283, 285; 284, identifier:parent_kernel; 285, string:''; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:search; 288, boolean_operator:or; 288, 289; 288, 290; 289, identifier:search; 290, string:''; 291, return_statement; 291, 292; 292, list_comprehension; 292, 293; 292, 297; 293, call; 293, 294; 293, 295; 294, identifier:Kernel; 295, argument_list; 295, 296; 296, identifier:k; 297, for_in_clause; 297, 298; 297, 299; 298, identifier:k; 299, identifier:kernels_list_result | def kernels_list(self,
page=1,
page_size=20,
dataset=None,
competition=None,
parent_kernel=None,
search=None,
mine=False,
user=None,
language=None,
kernel_type=None,
output_type=None,
sort_by=None):
if int(page) <= 0:
raise ValueError('Page number must be >= 1')
page_size = int(page_size)
if page_size <= 0:
raise ValueError('Page size must be >= 1')
if page_size > 100:
page_size = 100
valid_languages = ['all', 'python', 'r', 'sqlite', 'julia']
if language and language not in valid_languages:
raise ValueError('Invalid language specified. Valid options are ' +
str(valid_languages))
valid_kernel_types = ['all', 'script', 'notebook']
if kernel_type and kernel_type not in valid_kernel_types:
raise ValueError(
'Invalid kernel type specified. Valid options are ' +
str(valid_kernel_types))
valid_output_types = ['all', 'visualization', 'data']
if output_type and output_type not in valid_output_types:
raise ValueError(
'Invalid output type specified. Valid options are ' +
str(valid_output_types))
valid_sort_by = [
'hotness', 'commentCount', 'dateCreated', 'dateRun', 'relevance',
'scoreAscending', 'scoreDescending', 'viewCount', 'voteCount'
]
if sort_by and sort_by not in valid_sort_by:
raise ValueError(
'Invalid sort by type specified. Valid options are ' +
str(valid_sort_by))
if sort_by == 'relevance' and search == '':
raise ValueError('Cannot sort by relevance without a search term.')
self.validate_dataset_string(dataset)
self.validate_kernel_string(parent_kernel)
group = 'everyone'
if mine:
group = 'profile'
kernels_list_result = self.process_response(
self.kernels_list_with_http_info(
page=page,
page_size=page_size,
group=group,
user=user or '',
language=language or 'all',
kernel_type=kernel_type or 'all',
output_type=output_type or 'all',
sort_by=sort_by or 'hotness',
dataset=dataset or '',
competition=competition or '',
parent_kernel=parent_kernel or '',
search=search or ''))
return [Kernel(k) for k in kernels_list_result] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:_get_salt_params; 3, parameters; 4, block; 4, 5; 4, 7; 4, 15; 4, 23; 4, 27; 4, 189; 5, expression_statement; 5, 6; 6, string:'''
Try to get all sort of parameters for Server Density server info.
NOTE: Missing publicDNS and publicIPs parameters. There might be way of
getting them with salt-cloud.
'''; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:all_stats; 10, call; 10, 11; 10, 14; 11, subscript; 11, 12; 11, 13; 12, identifier:__salt__; 13, string:'status.all_status'; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:all_grains; 18, call; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:__salt__; 21, string:'grains.items'; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:params; 26, dictionary; 27, try_statement; 27, 28; 27, 185; 28, block; 28, 29; 28, 37; 28, 45; 28, 82; 28, 97; 28, 107; 28, 129; 28, 151; 28, 168; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:params; 33, string:'name'; 34, subscript; 34, 35; 34, 36; 35, identifier:all_grains; 36, string:'id'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:params; 41, string:'hostname'; 42, subscript; 42, 43; 42, 44; 43, identifier:all_grains; 44, string:'host'; 45, if_statement; 45, 46; 45, 51; 45, 62; 46, comparison_operator:==; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:all_grains; 49, string:'kernel'; 50, string:'Darwin'; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:sd_os; 55, dictionary; 55, 56; 55, 59; 56, pair; 56, 57; 56, 58; 57, string:'code'; 58, string:'mac'; 59, pair; 59, 60; 59, 61; 60, string:'name'; 61, string:'Mac'; 62, else_clause; 62, 63; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:sd_os; 67, dictionary; 67, 68; 67, 77; 68, pair; 68, 69; 68, 70; 69, string:'code'; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:all_grains; 74, string:'kernel'; 75, identifier:lower; 76, argument_list; 77, pair; 77, 78; 77, 79; 78, string:'name'; 79, subscript; 79, 80; 79, 81; 80, identifier:all_grains; 81, string:'kernel'; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:params; 86, string:'os'; 87, call; 87, 88; 87, 95; 88, attribute; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:salt; 92, identifier:utils; 93, identifier:json; 94, identifier:dumps; 95, argument_list; 95, 96; 96, identifier:sd_os; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:params; 101, string:'cpuCores'; 102, subscript; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:all_stats; 105, string:'cpuinfo'; 106, string:'cpu cores'; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:params; 111, string:'installedRAM'; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:six; 115, identifier:text_type; 116, argument_list; 116, 117; 117, binary_operator:/; 117, 118; 117, 128; 118, call; 118, 119; 118, 120; 119, identifier:int; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 127; 122, subscript; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:all_stats; 125, string:'meminfo'; 126, string:'MemTotal'; 127, string:'value'; 128, integer:1024; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:params; 133, string:'swapSpace'; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:six; 137, identifier:text_type; 138, argument_list; 138, 139; 139, binary_operator:/; 139, 140; 139, 150; 140, call; 140, 141; 140, 142; 141, identifier:int; 142, argument_list; 142, 143; 143, subscript; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:all_stats; 147, string:'meminfo'; 148, string:'SwapTotal'; 149, string:'value'; 150, integer:1024; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:params; 155, string:'privateIPs'; 156, call; 156, 157; 156, 164; 157, attribute; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:salt; 161, identifier:utils; 162, identifier:json; 163, identifier:dumps; 164, argument_list; 164, 165; 165, subscript; 165, 166; 165, 167; 166, identifier:all_grains; 167, string:'fqdn_ip4'; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:params; 172, string:'privateDNS'; 173, call; 173, 174; 173, 181; 174, attribute; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:salt; 178, identifier:utils; 179, identifier:json; 180, identifier:dumps; 181, argument_list; 181, 182; 182, subscript; 182, 183; 182, 184; 183, identifier:all_grains; 184, string:'fqdn'; 185, except_clause; 185, 186; 185, 187; 186, identifier:KeyError; 187, block; 187, 188; 188, pass_statement; 189, return_statement; 189, 190; 190, identifier:params | def _get_salt_params():
'''
Try to get all sort of parameters for Server Density server info.
NOTE: Missing publicDNS and publicIPs parameters. There might be way of
getting them with salt-cloud.
'''
all_stats = __salt__['status.all_status']()
all_grains = __salt__['grains.items']()
params = {}
try:
params['name'] = all_grains['id']
params['hostname'] = all_grains['host']
if all_grains['kernel'] == 'Darwin':
sd_os = {'code': 'mac', 'name': 'Mac'}
else:
sd_os = {'code': all_grains['kernel'].lower(), 'name': all_grains['kernel']}
params['os'] = salt.utils.json.dumps(sd_os)
params['cpuCores'] = all_stats['cpuinfo']['cpu cores']
params['installedRAM'] = six.text_type(int(all_stats['meminfo']['MemTotal']['value']) / 1024)
params['swapSpace'] = six.text_type(int(all_stats['meminfo']['SwapTotal']['value']) / 1024)
params['privateIPs'] = salt.utils.json.dumps(all_grains['fqdn_ip4'])
params['privateDNS'] = salt.utils.json.dumps(all_grains['fqdn'])
except KeyError:
pass
return params |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:zcard; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:key; 5, default_parameter; 5, 6; 5, 7; 6, identifier:host; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:port; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:db; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:password; 16, None; 17, block; 17, 18; 17, 20; 17, 30; 18, expression_statement; 18, 19; 19, string:'''
Get the length of a sorted set in Redis
CLI Example:
.. code-block:: bash
salt '*' redis.zcard foo_sorted
'''; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:server; 23, call; 23, 24; 23, 25; 24, identifier:_connect; 25, argument_list; 25, 26; 25, 27; 25, 28; 25, 29; 26, identifier:host; 27, identifier:port; 28, identifier:db; 29, identifier:password; 30, return_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:server; 34, identifier:zcard; 35, argument_list; 35, 36; 36, identifier:key | def zcard(key, host=None, port=None, db=None, password=None):
'''
Get the length of a sorted set in Redis
CLI Example:
.. code-block:: bash
salt '*' redis.zcard foo_sorted
'''
server = _connect(host, port, db, password)
return server.zcard(key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:zrange; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 4, identifier:key; 5, identifier:start; 6, identifier:stop; 7, default_parameter; 7, 8; 7, 9; 8, identifier:host; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:port; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:db; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:password; 18, None; 19, block; 19, 20; 19, 22; 19, 32; 20, expression_statement; 20, 21; 21, string:'''
Get a range of values from a sorted set in Redis by index
CLI Example:
.. code-block:: bash
salt '*' redis.zrange foo_sorted 0 10
'''; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:server; 25, call; 25, 26; 25, 27; 26, identifier:_connect; 27, argument_list; 27, 28; 27, 29; 27, 30; 27, 31; 28, identifier:host; 29, identifier:port; 30, identifier:db; 31, identifier:password; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:server; 36, identifier:zrange; 37, argument_list; 37, 38; 37, 39; 37, 40; 38, identifier:key; 39, identifier:start; 40, identifier:stop | def zrange(key, start, stop, host=None, port=None, db=None, password=None):
'''
Get a range of values from a sorted set in Redis by index
CLI Example:
.. code-block:: bash
salt '*' redis.zrange foo_sorted 0 10
'''
server = _connect(host, port, db, password)
return server.zrange(key, start, stop) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:get_list; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 4, default_parameter; 4, 5; 4, 6; 5, identifier:list_type; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:search_term; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:page; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:page_size; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:sort_by; 18, None; 19, block; 19, 20; 19, 22; 19, 35; 19, 66; 19, 101; 19, 112; 19, 144; 19, 178; 19, 191; 19, 198; 19, 209; 19, 213; 19, 238; 20, expression_statement; 20, 21; 21, string:'''
Returns a list of domains for the particular user as a list of objects
offset by ``page`` length of ``page_size``
list_type : ALL
One of ``ALL``, ``EXPIRING``, ``EXPIRED``
search_term
Keyword to look for on the domain list
page : 1
Number of result page to return
page_size : 20
Number of domains to be listed per page (minimum: ``10``, maximum:
``100``)
sort_by
One of ``NAME``, ``NAME_DESC``, ``EXPIREDATE``, ``EXPIREDATE_DESC``,
``CREATEDATE``, or ``CREATEDATE_DESC``
CLI Example:
.. code-block:: bash
salt 'my-minion' namecheap_domains.get_list
'''; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:opts; 25, call; 25, 26; 25, 33; 26, attribute; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:salt; 30, identifier:utils; 31, identifier:namecheap; 32, identifier:get_opts; 33, argument_list; 33, 34; 34, string:'namecheap.domains.getList'; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:list_type; 38, None; 39, block; 39, 40; 39, 60; 40, if_statement; 40, 41; 40, 47; 41, comparison_operator:not; 41, 42; 41, 43; 42, identifier:list_type; 43, list:['ALL', 'EXPIRING', 'EXPIRED']; 43, 44; 43, 45; 43, 46; 44, string:'ALL'; 45, string:'EXPIRING'; 46, string:'EXPIRED'; 47, block; 47, 48; 47, 55; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:log; 52, identifier:error; 53, argument_list; 53, 54; 54, string:'Invalid option for list_type'; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:Exception; 58, argument_list; 58, 59; 59, string:'Invalid option for list_type'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:opts; 64, string:'ListType'; 65, identifier:list_type; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:search_term; 69, None; 70, block; 70, 71; 70, 95; 71, if_statement; 71, 72; 71, 78; 72, comparison_operator:>; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, identifier:search_term; 77, integer:70; 78, block; 78, 79; 78, 86; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:log; 83, identifier:warning; 84, argument_list; 84, 85; 85, string:'search_term trimmed to first 70 characters'; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:search_term; 89, subscript; 89, 90; 89, 91; 90, identifier:search_term; 91, slice; 91, 92; 91, 93; 91, 94; 92, integer:0; 93, colon; 94, integer:70; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:opts; 99, string:'SearchTerm'; 100, identifier:search_term; 101, if_statement; 101, 102; 101, 105; 102, comparison_operator:is; 102, 103; 102, 104; 103, identifier:page; 104, None; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:opts; 110, string:'Page'; 111, identifier:page; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:page_size; 115, None; 116, block; 116, 117; 116, 138; 117, if_statement; 117, 118; 117, 125; 118, boolean_operator:or; 118, 119; 118, 122; 119, comparison_operator:>; 119, 120; 119, 121; 120, identifier:page_size; 121, integer:100; 122, comparison_operator:<; 122, 123; 122, 124; 123, identifier:page_size; 124, integer:10; 125, block; 125, 126; 125, 133; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:log; 130, identifier:error; 131, argument_list; 131, 132; 132, string:'Invalid option for page'; 133, raise_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:Exception; 136, argument_list; 136, 137; 137, string:'Invalid option for page'; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:opts; 142, string:'PageSize'; 143, identifier:page_size; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:is; 145, 146; 145, 147; 146, identifier:sort_by; 147, None; 148, block; 148, 149; 148, 172; 149, if_statement; 149, 150; 149, 159; 150, comparison_operator:not; 150, 151; 150, 152; 151, identifier:sort_by; 152, list:['NAME', 'NAME_DESC', 'EXPIREDATE', 'EXPIREDATE_DESC', 'CREATEDATE', 'CREATEDATE_DESC']; 152, 153; 152, 154; 152, 155; 152, 156; 152, 157; 152, 158; 153, string:'NAME'; 154, string:'NAME_DESC'; 155, string:'EXPIREDATE'; 156, string:'EXPIREDATE_DESC'; 157, string:'CREATEDATE'; 158, string:'CREATEDATE_DESC'; 159, block; 159, 160; 159, 167; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:log; 164, identifier:error; 165, argument_list; 165, 166; 166, string:'Invalid option for sort_by'; 167, raise_statement; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:Exception; 170, argument_list; 170, 171; 171, string:'Invalid option for sort_by'; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, subscript; 174, 175; 174, 176; 175, identifier:opts; 176, string:'SortBy'; 177, identifier:sort_by; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:response_xml; 181, call; 181, 182; 181, 189; 182, attribute; 182, 183; 182, 188; 183, attribute; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:salt; 186, identifier:utils; 187, identifier:namecheap; 188, identifier:get_request; 189, argument_list; 189, 190; 190, identifier:opts; 191, if_statement; 191, 192; 191, 195; 192, comparison_operator:is; 192, 193; 192, 194; 193, identifier:response_xml; 194, None; 195, block; 195, 196; 196, return_statement; 196, 197; 197, list:[]; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:domainresult; 201, subscript; 201, 202; 201, 208; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:response_xml; 205, identifier:getElementsByTagName; 206, argument_list; 206, 207; 207, string:"DomainGetListResult"; 208, integer:0; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:domains; 212, list:[]; 213, for_statement; 213, 214; 213, 215; 213, 221; 214, identifier:d; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:domainresult; 218, identifier:getElementsByTagName; 219, argument_list; 219, 220; 220, string:"Domain"; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:domains; 226, identifier:append; 227, argument_list; 227, 228; 228, call; 228, 229; 228, 236; 229, attribute; 229, 230; 229, 235; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:salt; 233, identifier:utils; 234, identifier:namecheap; 235, identifier:atts_to_dict; 236, argument_list; 236, 237; 237, identifier:d; 238, return_statement; 238, 239; 239, identifier:domains | def get_list(list_type=None,
search_term=None,
page=None,
page_size=None,
sort_by=None):
'''
Returns a list of domains for the particular user as a list of objects
offset by ``page`` length of ``page_size``
list_type : ALL
One of ``ALL``, ``EXPIRING``, ``EXPIRED``
search_term
Keyword to look for on the domain list
page : 1
Number of result page to return
page_size : 20
Number of domains to be listed per page (minimum: ``10``, maximum:
``100``)
sort_by
One of ``NAME``, ``NAME_DESC``, ``EXPIREDATE``, ``EXPIREDATE_DESC``,
``CREATEDATE``, or ``CREATEDATE_DESC``
CLI Example:
.. code-block:: bash
salt 'my-minion' namecheap_domains.get_list
'''
opts = salt.utils.namecheap.get_opts('namecheap.domains.getList')
if list_type is not None:
if list_type not in ['ALL', 'EXPIRING', 'EXPIRED']:
log.error('Invalid option for list_type')
raise Exception('Invalid option for list_type')
opts['ListType'] = list_type
if search_term is not None:
if len(search_term) > 70:
log.warning('search_term trimmed to first 70 characters')
search_term = search_term[0:70]
opts['SearchTerm'] = search_term
if page is not None:
opts['Page'] = page
if page_size is not None:
if page_size > 100 or page_size < 10:
log.error('Invalid option for page')
raise Exception('Invalid option for page')
opts['PageSize'] = page_size
if sort_by is not None:
if sort_by not in ['NAME', 'NAME_DESC', 'EXPIREDATE', 'EXPIREDATE_DESC', 'CREATEDATE', 'CREATEDATE_DESC']:
log.error('Invalid option for sort_by')
raise Exception('Invalid option for sort_by')
opts['SortBy'] = sort_by
response_xml = salt.utils.namecheap.get_request(opts)
if response_xml is None:
return []
domainresult = response_xml.getElementsByTagName("DomainGetListResult")[0]
domains = []
for d in domainresult.getElementsByTagName("Domain"):
domains.append(salt.utils.namecheap.atts_to_dict(d))
return domains |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort_policy; 3, parameters; 3, 4; 4, identifier:doc; 5, block; 5, 6; 5, 8; 5, 57; 6, expression_statement; 6, 7; 7, string:'''
List-type sub-items in policies don't happen to be order-sensitive, but
compare operations will render them unequal, leading to non-idempotent
state runs. We'll sort any list-type subitems before comparison to reduce
the likelihood of false negatives.
'''; 8, if_statement; 8, 9; 8, 14; 8, 27; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:doc; 13, identifier:list; 14, block; 14, 15; 15, return_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:sorted; 18, argument_list; 18, 19; 19, list_comprehension; 19, 20; 19, 24; 20, call; 20, 21; 20, 22; 21, identifier:_sort_policy; 22, argument_list; 22, 23; 23, identifier:i; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:i; 26, identifier:doc; 27, elif_clause; 27, 28; 27, 35; 28, call; 28, 29; 28, 30; 29, identifier:isinstance; 30, argument_list; 30, 31; 30, 32; 31, identifier:doc; 32, tuple; 32, 33; 32, 34; 33, identifier:dict; 34, identifier:OrderedDict; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:dict; 39, argument_list; 39, 40; 40, list_comprehension; 40, 41; 40, 47; 41, tuple; 41, 42; 41, 43; 42, identifier:k; 43, call; 43, 44; 43, 45; 44, identifier:_sort_policy; 45, argument_list; 45, 46; 46, identifier:v; 47, for_in_clause; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:k; 50, identifier:v; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:six; 54, identifier:iteritems; 55, argument_list; 55, 56; 56, identifier:doc; 57, return_statement; 57, 58; 58, identifier:doc | def _sort_policy(doc):
'''
List-type sub-items in policies don't happen to be order-sensitive, but
compare operations will render them unequal, leading to non-idempotent
state runs. We'll sort any list-type subitems before comparison to reduce
the likelihood of false negatives.
'''
if isinstance(doc, list):
return sorted([_sort_policy(i) for i in doc])
elif isinstance(doc, (dict, OrderedDict)):
return dict([(k, _sort_policy(v)) for k, v in six.iteritems(doc)])
return doc |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_resolve_datacenter; 3, parameters; 3, 4; 3, 5; 4, identifier:dc; 5, identifier:pillarenv; 6, block; 6, 7; 6, 9; 6, 17; 6, 40; 6, 51; 6, 59; 6, 82; 6, 133; 7, expression_statement; 7, 8; 8, string:'''
If ``dc`` is a string - return it as is.
If it's a dict then sort it in descending order by key length and try
to use keys as RegEx patterns to match against ``pillarenv``.
The value for matched pattern should be a string (that can use
``str.format`` syntax togetehr with captured variables from pattern)
pointing to targe data center to use.
If none patterns matched return ``None`` which meanse us datacenter of
conencted Consul agent.
'''; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:log; 13, identifier:debug; 14, argument_list; 14, 15; 14, 16; 15, string:'Resolving Consul datacenter based on: %s'; 16, identifier:dc; 17, try_statement; 17, 18; 17, 27; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:mappings; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:dc; 25, identifier:items; 26, argument_list; 27, except_clause; 27, 28; 27, 29; 28, identifier:AttributeError; 29, block; 29, 30; 29, 38; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:log; 34, identifier:debug; 35, argument_list; 35, 36; 35, 37; 36, string:'Using pre-defined DC: \'%s\''; 37, identifier:dc; 38, return_statement; 38, 39; 39, identifier:dc; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:log; 44, identifier:debug; 45, argument_list; 45, 46; 45, 47; 46, string:'Selecting DC based on pillarenv using %d pattern(s)'; 47, call; 47, 48; 47, 49; 48, identifier:len; 49, argument_list; 49, 50; 50, identifier:mappings; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:log; 55, identifier:debug; 56, argument_list; 56, 57; 56, 58; 57, string:'Pillarenv set to \'%s\''; 58, identifier:pillarenv; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:sorted_mappings; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 64, 66; 65, identifier:mappings; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:key; 68, lambda; 68, 69; 68, 71; 69, lambda_parameters; 69, 70; 70, identifier:m; 71, tuple; 71, 72; 71, 79; 72, unary_operator:-; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, subscript; 76, 77; 76, 78; 77, identifier:m; 78, integer:0; 79, subscript; 79, 80; 79, 81; 80, identifier:m; 81, integer:0; 82, for_statement; 82, 83; 82, 86; 82, 87; 83, pattern_list; 83, 84; 83, 85; 84, identifier:pattern; 85, identifier:target; 86, identifier:sorted_mappings; 87, block; 87, 88; 87, 98; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:match; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:re; 94, identifier:match; 95, argument_list; 95, 96; 95, 97; 96, identifier:pattern; 97, identifier:pillarenv; 98, if_statement; 98, 99; 98, 100; 99, identifier:match; 100, block; 100, 101; 100, 109; 100, 123; 100, 131; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:log; 105, identifier:debug; 106, argument_list; 106, 107; 106, 108; 107, string:'Matched pattern: \'%s\''; 108, identifier:pattern; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:result; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:target; 115, identifier:format; 116, argument_list; 116, 117; 117, dictionary_splat; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:match; 121, identifier:groupdict; 122, argument_list; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:log; 127, identifier:debug; 128, argument_list; 128, 129; 128, 130; 129, string:'Resolved datacenter: \'%s\''; 130, identifier:result; 131, return_statement; 131, 132; 132, identifier:result; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:log; 137, identifier:debug; 138, argument_list; 138, 139; 138, 140; 138, 141; 139, string:'None of following patterns matched pillarenv=%s: %s'; 140, identifier:pillarenv; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, string:', '; 144, identifier:join; 145, generator_expression; 145, 146; 145, 150; 146, call; 146, 147; 146, 148; 147, identifier:repr; 148, argument_list; 148, 149; 149, identifier:x; 150, for_in_clause; 150, 151; 150, 152; 151, identifier:x; 152, identifier:mappings | def _resolve_datacenter(dc, pillarenv):
'''
If ``dc`` is a string - return it as is.
If it's a dict then sort it in descending order by key length and try
to use keys as RegEx patterns to match against ``pillarenv``.
The value for matched pattern should be a string (that can use
``str.format`` syntax togetehr with captured variables from pattern)
pointing to targe data center to use.
If none patterns matched return ``None`` which meanse us datacenter of
conencted Consul agent.
'''
log.debug('Resolving Consul datacenter based on: %s', dc)
try:
mappings = dc.items()
except AttributeError:
log.debug('Using pre-defined DC: \'%s\'', dc)
return dc
log.debug('Selecting DC based on pillarenv using %d pattern(s)', len(mappings))
log.debug('Pillarenv set to \'%s\'', pillarenv)
sorted_mappings = sorted(mappings, key=lambda m: (-len(m[0]), m[0]))
for pattern, target in sorted_mappings:
match = re.match(pattern, pillarenv)
if match:
log.debug('Matched pattern: \'%s\'', pattern)
result = target.format(**match.groupdict())
log.debug('Resolved datacenter: \'%s\'', result)
return result
log.debug(
'None of following patterns matched pillarenv=%s: %s',
pillarenv, ', '.join(repr(x) for x in mappings)
) |
0, module; 0, 1; 1, ERROR; 1, 2; 1, 169; 1, 176; 2, function_definition; 2, 3; 2, 4; 2, 9; 3, function_name:read_conf; 4, parameters; 4, 5; 4, 6; 5, identifier:conf_file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:out_format; 8, string:'simple'; 9, block; 9, 10; 9, 12; 9, 16; 9, 20; 10, expression_statement; 10, 11; 11, string:'''
Read in an LXC configuration file. By default returns a simple, unsorted
dict, but can also return a more detailed structure including blank lines
and comments.
out_format:
set to 'simple' if you need the old and unsupported behavior.
This won't support the multiple lxc values (eg: multiple network nics)
CLI Examples:
.. code-block:: bash
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf out_format=commented
'''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ret_commented; 15, list:[]; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:ret_simple; 19, dictionary; 20, with_statement; 20, 21; 20, 37; 21, with_clause; 21, 22; 22, with_item; 22, 23; 23, as_pattern; 23, 24; 23, 35; 24, call; 24, 25; 24, 32; 25, attribute; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:salt; 29, identifier:utils; 30, identifier:files; 31, identifier:fopen; 32, argument_list; 32, 33; 32, 34; 33, identifier:conf_file; 34, string:'r'; 35, as_pattern_target; 35, 36; 36, identifier:fp_; 37, block; 37, 38; 38, for_statement; 38, 39; 38, 40; 38, 54; 38, 140; 39, identifier:line; 40, call; 40, 41; 40, 48; 41, attribute; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:salt; 45, identifier:utils; 46, identifier:data; 47, identifier:decode; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:fp_; 52, identifier:readlines; 53, argument_list; 54, ERROR; 54, 55; 54, 68; 54, 77; 54, 94; 54, 98; 54, 105; 54, 107; 54, 139; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:not; 56, 57; 56, 58; 57, string:'='; 58, identifier:line; 59, block; 59, 60; 59, 67; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:ret_commented; 64, identifier:append; 65, argument_list; 65, 66; 66, identifier:line; 67, continue_statement; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:comps; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:line; 74, identifier:split; 75, argument_list; 75, 76; 76, string:'='; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:value; 80, call; 80, 81; 80, 93; 81, attribute; 81, 82; 81, 92; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, string:'='; 85, identifier:join; 86, argument_list; 86, 87; 87, subscript; 87, 88; 87, 89; 88, identifier:comps; 89, slice; 89, 90; 89, 91; 90, integer:1; 91, colon; 92, identifier:strip; 93, argument_list; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:comment; 97, None; 98, attribute; 98, 99; 98, 104; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:value; 102, identifier:strip; 103, argument_list; 104, identifier:startswith; 105, ERROR; 105, 106; 106, string:'
vcomps = value.strip().split('; 107, keyword_argument; 107, 108; 107, 109; 107, 118; 108, identifier:value; 109, ERROR; 109, 110; 109, 117; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:vcomps; 114, integer:1; 115, identifier:strip; 116, argument_list; 117, identifier:comment; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:ret_commented; 121, identifier:append; 122, argument_list; 122, 123; 123, dictionary; 123, 124; 124, pair; 124, 125; 124, 132; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:comps; 129, integer:0; 130, identifier:strip; 131, argument_list; 132, dictionary; 132, 133; 132, 136; 133, pair; 133, 134; 133, 135; 134, string:'value'; 135, identifier:value; 136, pair; 136, 137; 136, 138; 137, string:'comment'; 138, identifier:comment; 139, identifier:else; 140, block; 140, 141; 140, 157; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:ret_commented; 145, identifier:append; 146, argument_list; 146, 147; 147, dictionary; 147, 148; 148, pair; 148, 149; 148, 156; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:comps; 153, integer:0; 154, identifier:strip; 155, argument_list; 156, identifier:value; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 168; 159, subscript; 159, 160; 159, 161; 160, identifier:ret_simple; 161, call; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:comps; 165, integer:0; 166, identifier:strip; 167, argument_list; 168, identifier:value; 169, if_statement; 169, 170; 169, 173; 170, comparison_operator:==; 170, 171; 170, 172; 171, identifier:out_format; 172, string:'simple'; 173, block; 173, 174; 174, return_statement; 174, 175; 175, identifier:ret_simple; 176, return_statement; 176, 177; 177, identifier:ret_commented | def read_conf(conf_file, out_format='simple'):
'''
Read in an LXC configuration file. By default returns a simple, unsorted
dict, but can also return a more detailed structure including blank lines
and comments.
out_format:
set to 'simple' if you need the old and unsupported behavior.
This won't support the multiple lxc values (eg: multiple network nics)
CLI Examples:
.. code-block:: bash
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf out_format=commented
'''
ret_commented = []
ret_simple = {}
with salt.utils.files.fopen(conf_file, 'r') as fp_:
for line in salt.utils.data.decode(fp_.readlines()):
if '=' not in line:
ret_commented.append(line)
continue
comps = line.split('=')
value = '='.join(comps[1:]).strip()
comment = None
if value.strip().startswith('
vcomps = value.strip().split('
value = vcomps[1].strip()
comment = '
ret_commented.append({comps[0].strip(): {
'value': value,
'comment': comment,
}})
else:
ret_commented.append({comps[0].strip(): value})
ret_simple[comps[0].strip()] = value
if out_format == 'simple':
return ret_simple
return ret_commented |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort_top_targets; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:top; 6, identifier:orders; 7, block; 7, 8; 7, 10; 7, 19; 7, 61; 8, expression_statement; 8, 9; 9, string:'''
Returns the sorted high data from the merged top files
'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sorted_top; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:collections; 16, identifier:defaultdict; 17, argument_list; 17, 18; 18, identifier:OrderedDict; 19, for_statement; 19, 20; 19, 23; 19, 29; 20, pattern_list; 20, 21; 20, 22; 21, identifier:saltenv; 22, identifier:targets; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:six; 26, identifier:iteritems; 27, argument_list; 27, 28; 28, identifier:top; 29, block; 29, 30; 29, 47; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:sorted_targets; 33, call; 33, 34; 33, 35; 34, identifier:sorted; 35, argument_list; 35, 36; 35, 37; 36, identifier:targets; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:target; 42, subscript; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:orders; 45, identifier:saltenv; 46, identifier:target; 47, for_statement; 47, 48; 47, 49; 47, 50; 48, identifier:target; 49, identifier:sorted_targets; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 58; 53, subscript; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:sorted_top; 56, identifier:saltenv; 57, identifier:target; 58, subscript; 58, 59; 58, 60; 59, identifier:targets; 60, identifier:target; 61, return_statement; 61, 62; 62, identifier:sorted_top | def sort_top_targets(self, top, orders):
'''
Returns the sorted high data from the merged top files
'''
sorted_top = collections.defaultdict(OrderedDict)
for saltenv, targets in six.iteritems(top):
sorted_targets = sorted(targets,
key=lambda target: orders[saltenv][target])
for target in sorted_targets:
sorted_top[saltenv][target] = targets[target]
return sorted_top |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 47; 2, function_name:subvolume_list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 3, 44; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:parent_id; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:absolute; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ogeneration; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:generation; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:subvolumes; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:uuid; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:parent_uuid; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:sent_subvolume_uuid; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:snapshots; 31, False; 32, default_parameter; 32, 33; 32, 34; 33, identifier:readonly; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:deleted; 37, False; 38, default_parameter; 38, 39; 38, 40; 39, identifier:generation_cmp; 40, None; 41, default_parameter; 41, 42; 41, 43; 42, identifier:ogeneration_cmp; 43, None; 44, default_parameter; 44, 45; 44, 46; 45, identifier:sort; 46, None; 47, block; 47, 48; 47, 50; 47, 65; 47, 95; 47, 114; 47, 121; 47, 158; 47, 174; 47, 186; 47, 198; 47, 218; 47, 225; 47, 234; 47, 245; 47, 259; 47, 263; 47, 318; 48, expression_statement; 48, 49; 49, string:'''
List the subvolumes present in the filesystem.
path
Mount point for the subvolume
parent_id
Print parent ID
absolute
Print all the subvolumes in the filesystem and distinguish
between absolute and relative path with respect to the given
<path>
ogeneration
Print the ogeneration of the subvolume
generation
Print the generation of the subvolume
subvolumes
Print only subvolumes below specified <path>
uuid
Print the UUID of the subvolume
parent_uuid
Print the parent uuid of subvolumes (and snapshots)
sent_subvolume_uuid
Print the UUID of the sent subvolume, where the subvolume is
the result of a receive operation
snapshots
Only snapshot subvolumes in the filesystem will be listed
readonly
Only readonly subvolumes in the filesystem will be listed
deleted
Only deleted subvolumens that are ye not cleaned
generation_cmp
List subvolumes in the filesystem that its generation is >=,
<= or = value. '+' means >= value, '-' means <= value, If
there is neither '+' nor '-', it means = value
ogeneration_cmp
List subvolumes in the filesystem that its ogeneration is >=,
<= or = value
sort
List subvolumes in order by specified items. Possible values:
* rootid
* gen
* ogen
* path
You can add '+' or '-' in front of each items, '+' means
ascending, '-' means descending. The default is ascending. You
can combite it in a list.
CLI Example:
.. code-block:: bash
salt '*' btrfs.subvolume_list /var/volumes/tmp
salt '*' btrfs.subvolume_list /var/volumes/tmp path=True
salt '*' btrfs.subvolume_list /var/volumes/tmp sort='[-rootid]'
'''; 50, if_statement; 50, 51; 50, 59; 51, boolean_operator:and; 51, 52; 51, 53; 52, identifier:sort; 53, comparison_operator:is; 53, 54; 53, 58; 54, call; 54, 55; 54, 56; 55, identifier:type; 56, argument_list; 56, 57; 57, identifier:sort; 58, identifier:list; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:CommandExecutionError; 63, argument_list; 63, 64; 64, string:'Sort parameter must be a list'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:valid_sorts; 68, list_comprehension; 68, 69; 68, 77; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:''; 72, identifier:join; 73, argument_list; 73, 74; 74, tuple; 74, 75; 74, 76; 75, identifier:order; 76, identifier:attrib; 77, for_in_clause; 77, 78; 77, 81; 78, pattern_list; 78, 79; 78, 80; 79, identifier:order; 80, identifier:attrib; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:itertools; 84, identifier:product; 85, argument_list; 85, 86; 85, 90; 86, tuple; 86, 87; 86, 88; 86, 89; 87, string:'-'; 88, string:''; 89, string:'+'; 90, tuple; 90, 91; 90, 92; 90, 93; 90, 94; 91, string:'rootid'; 92, string:'gen'; 93, string:'ogen'; 94, string:'path'; 95, if_statement; 95, 96; 95, 108; 96, boolean_operator:and; 96, 97; 96, 98; 97, identifier:sort; 98, not_operator; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:all; 101, generator_expression; 101, 102; 101, 105; 102, comparison_operator:in; 102, 103; 102, 104; 103, identifier:s; 104, identifier:valid_sorts; 105, for_in_clause; 105, 106; 105, 107; 106, identifier:s; 107, identifier:sort; 108, block; 108, 109; 109, raise_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:CommandExecutionError; 112, argument_list; 112, 113; 113, string:'Value for sort not recognized'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:cmd; 117, list:['btrfs', 'subvolume', 'list']; 117, 118; 117, 119; 117, 120; 118, string:'btrfs'; 119, string:'subvolume'; 120, string:'list'; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:params; 124, tuple; 124, 125; 124, 128; 124, 131; 124, 134; 124, 137; 124, 140; 124, 143; 124, 146; 124, 149; 124, 152; 124, 155; 125, tuple; 125, 126; 125, 127; 126, identifier:parent_id; 127, string:'-p'; 128, tuple; 128, 129; 128, 130; 129, identifier:absolute; 130, string:'-a'; 131, tuple; 131, 132; 131, 133; 132, identifier:ogeneration; 133, string:'-c'; 134, tuple; 134, 135; 134, 136; 135, identifier:generation; 136, string:'-g'; 137, tuple; 137, 138; 137, 139; 138, identifier:subvolumes; 139, string:'-o'; 140, tuple; 140, 141; 140, 142; 141, identifier:uuid; 142, string:'-u'; 143, tuple; 143, 144; 143, 145; 144, identifier:parent_uuid; 145, string:'-q'; 146, tuple; 146, 147; 146, 148; 147, identifier:sent_subvolume_uuid; 148, string:'-R'; 149, tuple; 149, 150; 149, 151; 150, identifier:snapshots; 151, string:'-s'; 152, tuple; 152, 153; 152, 154; 153, identifier:readonly; 154, string:'-r'; 155, tuple; 155, 156; 155, 157; 156, identifier:deleted; 157, string:'-d'; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:cmd; 162, identifier:extend; 163, generator_expression; 163, 164; 163, 167; 163, 170; 164, subscript; 164, 165; 164, 166; 165, identifier:p; 166, integer:1; 167, for_in_clause; 167, 168; 167, 169; 168, identifier:p; 169, identifier:params; 170, if_clause; 170, 171; 171, subscript; 171, 172; 171, 173; 172, identifier:p; 173, integer:0; 174, if_statement; 174, 175; 174, 176; 175, identifier:generation_cmp; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:cmd; 181, identifier:extend; 182, argument_list; 182, 183; 183, list:['-G', generation_cmp]; 183, 184; 183, 185; 184, string:'-G'; 185, identifier:generation_cmp; 186, if_statement; 186, 187; 186, 188; 187, identifier:ogeneration_cmp; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:cmd; 193, identifier:extend; 194, argument_list; 194, 195; 195, list:['-C', ogeneration_cmp]; 195, 196; 195, 197; 196, string:'-C'; 197, identifier:ogeneration_cmp; 198, if_statement; 198, 199; 198, 200; 199, identifier:sort; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:cmd; 205, identifier:append; 206, argument_list; 206, 207; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, string:'--sort={}'; 210, identifier:format; 211, argument_list; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, string:','; 215, identifier:join; 216, argument_list; 216, 217; 217, identifier:sort; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:cmd; 222, identifier:append; 223, argument_list; 223, 224; 224, identifier:path; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:res; 228, call; 228, 229; 228, 232; 229, subscript; 229, 230; 229, 231; 230, identifier:__salt__; 231, string:'cmd.run_all'; 232, argument_list; 232, 233; 233, identifier:cmd; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 243; 236, attribute; 236, 237; 236, 242; 237, attribute; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:salt; 240, identifier:utils; 241, identifier:fsutils; 242, identifier:_verify_run; 243, argument_list; 243, 244; 244, identifier:res; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:columns; 248, tuple; 248, 249; 248, 250; 248, 251; 248, 252; 248, 253; 248, 254; 248, 255; 248, 256; 248, 257; 248, 258; 249, string:'ID'; 250, string:'gen'; 251, string:'cgen'; 252, string:'parent'; 253, string:'top level'; 254, string:'otime'; 255, string:'parent_uuid'; 256, string:'received_uuid'; 257, string:'uuid'; 258, string:'path'; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:result; 262, list:[]; 263, for_statement; 263, 264; 263, 265; 263, 272; 264, identifier:line; 265, call; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, subscript; 267, 268; 267, 269; 268, identifier:res; 269, string:'stdout'; 270, identifier:splitlines; 271, argument_list; 272, block; 272, 273; 272, 277; 272, 307; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:table; 276, dictionary; 277, for_statement; 277, 278; 277, 279; 277, 280; 278, identifier:key; 279, identifier:columns; 280, block; 280, 281; 280, 294; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 286; 283, pattern_list; 283, 284; 283, 285; 284, identifier:value; 285, identifier:line; 286, call; 286, 287; 286, 288; 287, identifier:_pop; 288, argument_list; 288, 289; 288, 290; 288, 291; 289, identifier:line; 290, identifier:key; 291, comparison_operator:==; 291, 292; 291, 293; 292, identifier:key; 293, string:'path'; 294, if_statement; 294, 295; 294, 296; 295, identifier:value; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 306; 299, subscript; 299, 300; 299, 301; 300, identifier:table; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:key; 304, identifier:lower; 305, argument_list; 306, identifier:value; 307, if_statement; 307, 308; 307, 310; 308, not_operator; 308, 309; 309, identifier:line; 310, block; 310, 311; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:result; 315, identifier:append; 316, argument_list; 316, 317; 317, identifier:table; 318, return_statement; 318, 319; 319, identifier:result | def subvolume_list(path, parent_id=False, absolute=False,
ogeneration=False, generation=False,
subvolumes=False, uuid=False, parent_uuid=False,
sent_subvolume_uuid=False, snapshots=False,
readonly=False, deleted=False, generation_cmp=None,
ogeneration_cmp=None, sort=None):
'''
List the subvolumes present in the filesystem.
path
Mount point for the subvolume
parent_id
Print parent ID
absolute
Print all the subvolumes in the filesystem and distinguish
between absolute and relative path with respect to the given
<path>
ogeneration
Print the ogeneration of the subvolume
generation
Print the generation of the subvolume
subvolumes
Print only subvolumes below specified <path>
uuid
Print the UUID of the subvolume
parent_uuid
Print the parent uuid of subvolumes (and snapshots)
sent_subvolume_uuid
Print the UUID of the sent subvolume, where the subvolume is
the result of a receive operation
snapshots
Only snapshot subvolumes in the filesystem will be listed
readonly
Only readonly subvolumes in the filesystem will be listed
deleted
Only deleted subvolumens that are ye not cleaned
generation_cmp
List subvolumes in the filesystem that its generation is >=,
<= or = value. '+' means >= value, '-' means <= value, If
there is neither '+' nor '-', it means = value
ogeneration_cmp
List subvolumes in the filesystem that its ogeneration is >=,
<= or = value
sort
List subvolumes in order by specified items. Possible values:
* rootid
* gen
* ogen
* path
You can add '+' or '-' in front of each items, '+' means
ascending, '-' means descending. The default is ascending. You
can combite it in a list.
CLI Example:
.. code-block:: bash
salt '*' btrfs.subvolume_list /var/volumes/tmp
salt '*' btrfs.subvolume_list /var/volumes/tmp path=True
salt '*' btrfs.subvolume_list /var/volumes/tmp sort='[-rootid]'
'''
if sort and type(sort) is not list:
raise CommandExecutionError('Sort parameter must be a list')
valid_sorts = [
''.join((order, attrib)) for order, attrib in itertools.product(
('-', '', '+'), ('rootid', 'gen', 'ogen', 'path'))
]
if sort and not all(s in valid_sorts for s in sort):
raise CommandExecutionError('Value for sort not recognized')
cmd = ['btrfs', 'subvolume', 'list']
params = ((parent_id, '-p'),
(absolute, '-a'),
(ogeneration, '-c'),
(generation, '-g'),
(subvolumes, '-o'),
(uuid, '-u'),
(parent_uuid, '-q'),
(sent_subvolume_uuid, '-R'),
(snapshots, '-s'),
(readonly, '-r'),
(deleted, '-d'))
cmd.extend(p[1] for p in params if p[0])
if generation_cmp:
cmd.extend(['-G', generation_cmp])
if ogeneration_cmp:
cmd.extend(['-C', ogeneration_cmp])
if sort:
cmd.append('--sort={}'.format(','.join(sort)))
cmd.append(path)
res = __salt__['cmd.run_all'](cmd)
salt.utils.fsutils._verify_run(res)
columns = ('ID', 'gen', 'cgen', 'parent', 'top level', 'otime',
'parent_uuid', 'received_uuid', 'uuid', 'path')
result = []
for line in res['stdout'].splitlines():
table = {}
for key in columns:
value, line = _pop(line, key, key == 'path')
if value:
table[key.lower()] = value
if not line:
result.append(table)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:diff; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 14; 8, 24; 8, 28; 8, 237; 9, expression_statement; 9, 10; 10, string:'''
Return the DIFFERENCE of the result sets returned by each matching minion
pool
.. versionadded:: 2014.7.0
These pools are determined from the aggregated and sorted results of
a salt command.
This command displays the "diffs" as a series of 2-way differences --
namely the difference between the FIRST displayed minion pool
(according to sort order) and EACH SUBSEQUENT minion pool result set.
Differences are displayed according to the Python ``difflib.unified_diff()``
as in the case of the salt execution module ``file.get_diff``.
This command is submitted via a salt runner using the general form::
salt-run survey.diff [survey_sort=up/down] <target>
<salt-execution-module> <salt-execution-module parameters>
Optionally accept a ``survey_sort=`` parameter. Default:
``survey_sort=down``
CLI Example
.. code-block:: bash
salt-run survey.diff survey_sort=up "*" cp.get_file_str file:///etc/hosts
'''; 11, import_statement; 11, 12; 12, dotted_name; 12, 13; 13, identifier:difflib; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:bulk_ret; 17, call; 17, 18; 17, 19; 18, identifier:_get_pool_results; 19, argument_list; 19, 20; 19, 22; 20, list_splat; 20, 21; 21, identifier:args; 22, dictionary_splat; 22, 23; 23, identifier:kwargs; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:is_first_time; 27, True; 28, for_statement; 28, 29; 28, 30; 28, 31; 29, identifier:k; 30, identifier:bulk_ret; 31, block; 31, 32; 31, 39; 31, 46; 31, 53; 31, 70; 31, 100; 31, 116; 31, 121; 31, 134; 31, 146; 31, 163; 31, 173; 31, 190; 31, 194; 31, 228; 31, 233; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:print; 35, argument_list; 35, 36; 36, concatenated_string; 36, 37; 36, 38; 37, string:'minion pool :\n'; 38, string:'------------'; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:print; 42, argument_list; 42, 43; 43, subscript; 43, 44; 43, 45; 44, identifier:k; 45, string:'pool'; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:print; 49, argument_list; 49, 50; 50, concatenated_string; 50, 51; 50, 52; 51, string:'pool size :\n'; 52, string:'----------'; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:print; 56, argument_list; 56, 57; 57, binary_operator:+; 57, 58; 57, 59; 58, string:' '; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:six; 62, identifier:text_type; 63, argument_list; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, subscript; 67, 68; 67, 69; 68, identifier:k; 69, string:'pool'; 70, if_statement; 70, 71; 70, 72; 71, identifier:is_first_time; 72, block; 72, 73; 72, 77; 72, 84; 72, 95; 72, 99; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:is_first_time; 76, False; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:print; 80, argument_list; 80, 81; 81, concatenated_string; 81, 82; 81, 83; 82, string:'pool result :\n'; 83, string:'------------'; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:print; 87, argument_list; 87, 88; 88, binary_operator:+; 88, 89; 88, 90; 89, string:' '; 90, subscript; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:bulk_ret; 93, integer:0; 94, string:'result'; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:print; 98, argument_list; 99, continue_statement; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:outs; 103, call; 103, 104; 103, 108; 104, attribute; 104, 105; 104, 107; 105, parenthesized_expression; 105, 106; 106, string:'differences from "{0}" results :'; 107, identifier:format; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 115; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:bulk_ret; 113, integer:0; 114, string:'pool'; 115, integer:0; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:print; 119, argument_list; 119, 120; 120, identifier:outs; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:print; 124, argument_list; 124, 125; 125, binary_operator:*; 125, 126; 125, 127; 126, string:'-'; 127, parenthesized_expression; 127, 128; 128, binary_operator:-; 128, 129; 128, 133; 129, call; 129, 130; 129, 131; 130, identifier:len; 131, argument_list; 131, 132; 132, identifier:outs; 133, integer:1; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:from_result; 137, call; 137, 138; 137, 145; 138, attribute; 138, 139; 138, 144; 139, subscript; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:bulk_ret; 142, integer:0; 143, string:'result'; 144, identifier:splitlines; 145, argument_list; 146, for_statement; 146, 147; 146, 148; 146, 156; 147, identifier:i; 148, call; 148, 149; 148, 150; 149, identifier:range; 150, argument_list; 150, 151; 150, 152; 151, integer:0; 152, call; 152, 153; 152, 154; 153, identifier:len; 154, argument_list; 154, 155; 155, identifier:from_result; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, augmented_assignment:+=; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:from_result; 161, identifier:i; 162, string:'\n'; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:to_result; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:k; 170, string:'result'; 171, identifier:splitlines; 172, argument_list; 173, for_statement; 173, 174; 173, 175; 173, 183; 174, identifier:i; 175, call; 175, 176; 175, 177; 176, identifier:range; 177, argument_list; 177, 178; 177, 179; 178, integer:0; 179, call; 179, 180; 179, 181; 180, identifier:len; 181, argument_list; 181, 182; 182, identifier:to_result; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, augmented_assignment:+=; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:to_result; 188, identifier:i; 189, string:'\n'; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:outs; 193, string:''; 194, expression_statement; 194, 195; 195, augmented_assignment:+=; 195, 196; 195, 197; 196, identifier:outs; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, string:''; 200, identifier:join; 201, argument_list; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:difflib; 205, identifier:unified_diff; 206, argument_list; 206, 207; 206, 208; 206, 209; 206, 218; 206, 225; 207, identifier:from_result; 208, identifier:to_result; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:fromfile; 211, subscript; 211, 212; 211, 217; 212, subscript; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:bulk_ret; 215, integer:0; 216, string:'pool'; 217, integer:0; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:tofile; 220, subscript; 220, 221; 220, 224; 221, subscript; 221, 222; 221, 223; 222, identifier:k; 223, string:'pool'; 224, integer:0; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:n; 227, integer:0; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:print; 231, argument_list; 231, 232; 232, identifier:outs; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 236; 235, identifier:print; 236, argument_list; 237, return_statement; 237, 238; 238, identifier:bulk_ret | def diff(*args, **kwargs):
'''
Return the DIFFERENCE of the result sets returned by each matching minion
pool
.. versionadded:: 2014.7.0
These pools are determined from the aggregated and sorted results of
a salt command.
This command displays the "diffs" as a series of 2-way differences --
namely the difference between the FIRST displayed minion pool
(according to sort order) and EACH SUBSEQUENT minion pool result set.
Differences are displayed according to the Python ``difflib.unified_diff()``
as in the case of the salt execution module ``file.get_diff``.
This command is submitted via a salt runner using the general form::
salt-run survey.diff [survey_sort=up/down] <target>
<salt-execution-module> <salt-execution-module parameters>
Optionally accept a ``survey_sort=`` parameter. Default:
``survey_sort=down``
CLI Example
.. code-block:: bash
salt-run survey.diff survey_sort=up "*" cp.get_file_str file:///etc/hosts
'''
import difflib
bulk_ret = _get_pool_results(*args, **kwargs)
is_first_time = True
for k in bulk_ret:
print('minion pool :\n'
'------------')
print(k['pool'])
print('pool size :\n'
'----------')
print(' ' + six.text_type(len(k['pool'])))
if is_first_time:
is_first_time = False
print('pool result :\n'
'------------')
print(' ' + bulk_ret[0]['result'])
print()
continue
outs = ('differences from "{0}" results :').format(
bulk_ret[0]['pool'][0])
print(outs)
print('-' * (len(outs) - 1))
from_result = bulk_ret[0]['result'].splitlines()
for i in range(0, len(from_result)):
from_result[i] += '\n'
to_result = k['result'].splitlines()
for i in range(0, len(to_result)):
to_result[i] += '\n'
outs = ''
outs += ''.join(difflib.unified_diff(from_result,
to_result,
fromfile=bulk_ret[0]['pool'][0],
tofile=k['pool'][0],
n=0))
print(outs)
print()
return bulk_ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_get_pool_results; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 14; 8, 20; 8, 26; 8, 30; 8, 40; 8, 46; 8, 56; 8, 67; 8, 94; 8, 107; 8, 148; 8, 225; 8, 229; 8, 261; 9, expression_statement; 9, 10; 10, string:'''
A helper function which returns a dictionary of minion pools along with
their matching result sets.
Useful for developing other "survey style" functions.
Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for
specifying sort order.
Because the kwargs namespace of the "salt" and "survey" command are shared,
the name "survey_sort" was chosen to help avoid option conflicts.
'''; 11, import_statement; 11, 12; 12, dotted_name; 12, 13; 13, identifier:hashlib; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:tgt; 17, subscript; 17, 18; 17, 19; 18, identifier:args; 19, integer:0; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:cmd; 23, subscript; 23, 24; 23, 25; 24, identifier:args; 25, integer:1; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:ret; 29, dictionary; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:sort; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:kwargs; 36, identifier:pop; 37, argument_list; 37, 38; 37, 39; 38, string:'survey_sort'; 39, string:'down'; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:direction; 43, comparison_operator:!=; 43, 44; 43, 45; 44, identifier:sort; 45, string:'up'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:tgt_type; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:kwargs; 52, identifier:pop; 53, argument_list; 53, 54; 53, 55; 54, string:'tgt_type'; 55, string:'compound'; 56, if_statement; 56, 57; 56, 62; 57, comparison_operator:not; 57, 58; 57, 59; 58, identifier:tgt_type; 59, list:['compound', 'pcre']; 59, 60; 59, 61; 60, string:'compound'; 61, string:'pcre'; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:tgt_type; 66, string:'compound'; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:kwargs_passthru; 70, call; 70, 71; 70, 72; 71, identifier:dict; 72, generator_expression; 72, 73; 72, 78; 72, 86; 73, tuple; 73, 74; 73, 75; 74, identifier:k; 75, subscript; 75, 76; 75, 77; 76, identifier:kwargs; 77, identifier:k; 78, for_in_clause; 78, 79; 78, 80; 79, identifier:k; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:six; 83, identifier:iterkeys; 84, argument_list; 84, 85; 85, identifier:kwargs; 86, if_clause; 86, 87; 87, not_operator; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:k; 91, identifier:startswith; 92, argument_list; 92, 93; 93, string:'_'; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:client; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:salt; 101, identifier:client; 102, identifier:get_local_client; 103, argument_list; 103, 104; 104, subscript; 104, 105; 104, 106; 105, identifier:__opts__; 106, string:'conf_file'; 107, try_statement; 107, 108; 107, 135; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:minions; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:client; 115, identifier:cmd; 116, argument_list; 116, 117; 116, 118; 116, 119; 116, 124; 116, 129; 116, 132; 117, identifier:tgt; 118, identifier:cmd; 119, subscript; 119, 120; 119, 121; 120, identifier:args; 121, slice; 121, 122; 121, 123; 122, integer:2; 123, colon; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:timeout; 126, subscript; 126, 127; 126, 128; 127, identifier:__opts__; 128, string:'timeout'; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:tgt_type; 131, identifier:tgt_type; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:kwarg; 134, identifier:kwargs_passthru; 135, except_clause; 135, 136; 135, 140; 136, as_pattern; 136, 137; 136, 138; 137, identifier:SaltClientError; 138, as_pattern_target; 138, 139; 139, identifier:client_error; 140, block; 140, 141; 140, 146; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:print; 144, argument_list; 144, 145; 145, identifier:client_error; 146, return_statement; 146, 147; 147, identifier:ret; 148, for_statement; 148, 149; 148, 150; 148, 154; 149, identifier:minion; 150, call; 150, 151; 150, 152; 151, identifier:sorted; 152, argument_list; 152, 153; 153, identifier:minions; 154, block; 154, 155; 154, 180; 154, 214; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:digest; 158, call; 158, 159; 158, 179; 159, attribute; 159, 160; 159, 178; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:hashlib; 163, identifier:sha256; 164, argument_list; 164, 165; 165, call; 165, 166; 165, 176; 166, attribute; 166, 167; 166, 175; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:six; 170, identifier:text_type; 171, argument_list; 171, 172; 172, subscript; 172, 173; 172, 174; 173, identifier:minions; 174, identifier:minion; 175, identifier:encode; 176, argument_list; 176, 177; 177, identifier:__salt_system_encoding__; 178, identifier:hexdigest; 179, argument_list; 180, if_statement; 180, 181; 180, 184; 181, comparison_operator:not; 181, 182; 181, 183; 182, identifier:digest; 183, identifier:ret; 184, block; 184, 185; 184, 191; 184, 199; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:ret; 189, identifier:digest; 190, dictionary; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 198; 193, subscript; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:ret; 196, identifier:digest; 197, string:'pool'; 198, list:[]; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 206; 201, subscript; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:ret; 204, identifier:digest; 205, string:'result'; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:six; 209, identifier:text_type; 210, argument_list; 210, 211; 211, subscript; 211, 212; 211, 213; 212, identifier:minions; 213, identifier:minion; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 223; 216, attribute; 216, 217; 216, 222; 217, subscript; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:ret; 220, identifier:digest; 221, string:'pool'; 222, identifier:append; 223, argument_list; 223, 224; 224, identifier:minion; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:sorted_ret; 228, list:[]; 229, for_statement; 229, 230; 229, 231; 229, 251; 230, identifier:k; 231, call; 231, 232; 231, 233; 232, identifier:sorted; 233, argument_list; 233, 234; 233, 235; 233, 248; 234, identifier:ret; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:key; 237, lambda; 237, 238; 237, 240; 238, lambda_parameters; 238, 239; 239, identifier:k; 240, call; 240, 241; 240, 242; 241, identifier:len; 242, argument_list; 242, 243; 243, subscript; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:ret; 246, identifier:k; 247, string:'pool'; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:reverse; 250, identifier:direction; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:sorted_ret; 256, identifier:append; 257, argument_list; 257, 258; 258, subscript; 258, 259; 258, 260; 259, identifier:ret; 260, identifier:k; 261, return_statement; 261, 262; 262, identifier:sorted_ret | def _get_pool_results(*args, **kwargs):
'''
A helper function which returns a dictionary of minion pools along with
their matching result sets.
Useful for developing other "survey style" functions.
Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for
specifying sort order.
Because the kwargs namespace of the "salt" and "survey" command are shared,
the name "survey_sort" was chosen to help avoid option conflicts.
'''
import hashlib
tgt = args[0]
cmd = args[1]
ret = {}
sort = kwargs.pop('survey_sort', 'down')
direction = sort != 'up'
tgt_type = kwargs.pop('tgt_type', 'compound')
if tgt_type not in ['compound', 'pcre']:
tgt_type = 'compound'
kwargs_passthru = dict((k, kwargs[k]) for k in six.iterkeys(kwargs) if not k.startswith('_'))
client = salt.client.get_local_client(__opts__['conf_file'])
try:
minions = client.cmd(tgt, cmd, args[2:], timeout=__opts__['timeout'], tgt_type=tgt_type, kwarg=kwargs_passthru)
except SaltClientError as client_error:
print(client_error)
return ret
for minion in sorted(minions):
digest = hashlib.sha256(six.text_type(minions[minion]).encode(__salt_system_encoding__)).hexdigest()
if digest not in ret:
ret[digest] = {}
ret[digest]['pool'] = []
ret[digest]['result'] = six.text_type(minions[minion])
ret[digest]['pool'].append(minion)
sorted_ret = []
for k in sorted(ret, key=lambda k: len(ret[k]['pool']), reverse=direction):
sorted_ret.append(ret[k])
return sorted_ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:list_; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:name; 6, None; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 18; 9, 28; 9, 45; 9, 57; 9, 65; 9, 70; 9, 74; 9, 90; 9, 118; 9, 138; 9, 148; 9, 183; 9, 209; 9, 237; 9, 341; 10, expression_statement; 10, 11; 11, string:'''
Return a list of all datasets or a specified dataset on the system and the
values of their used, available, referenced, and mountpoint properties.
name : string
name of dataset, volume, or snapshot
recursive : boolean
recursively list children
depth : int
limit recursion to depth
properties : string
comma-separated list of properties to list, the name property will always be added
type : string
comma-separated list of types to display, where type is one of
filesystem, snapshot, volume, bookmark, or all.
sort : string
property to sort on (default = name)
order : string [ascending|descending]
sort order (default = ascending)
parsable : boolean
display numbers in parsable (exact) values
.. versionadded:: 2018.3.0
.. versionadded:: 2015.5.0
CLI Example:
.. code-block:: bash
salt '*' zfs.list
salt '*' zfs.list myzpool/mydataset [recursive=True|False]
salt '*' zfs.list myzpool/mydataset properties="sharenfs,mountpoint"
'''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ret; 15, call; 15, 16; 15, 17; 16, identifier:OrderedDict; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:properties; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:kwargs; 24, identifier:get; 25, argument_list; 25, 26; 25, 27; 26, string:'properties'; 27, string:'used,avail,refer,mountpoint'; 28, if_statement; 28, 29; 28, 35; 29, not_operator; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:isinstance; 32, argument_list; 32, 33; 32, 34; 33, identifier:properties; 34, identifier:list; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:properties; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:properties; 42, identifier:split; 43, argument_list; 43, 44; 44, string:','; 45, while_statement; 45, 46; 45, 49; 46, comparison_operator:in; 46, 47; 46, 48; 47, string:'name'; 48, identifier:properties; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:properties; 54, identifier:remove; 55, argument_list; 55, 56; 56, string:'name'; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:properties; 61, identifier:insert; 62, argument_list; 62, 63; 62, 64; 63, integer:0; 64, string:'name'; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:flags; 68, list:['-H']; 68, 69; 69, string:'-H'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:opts; 73, dictionary; 74, if_statement; 74, 75; 74, 82; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:kwargs; 78, identifier:get; 79, argument_list; 79, 80; 79, 81; 80, string:'recursive'; 81, False; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:flags; 87, identifier:append; 88, argument_list; 88, 89; 89, string:'-r'; 90, if_statement; 90, 91; 90, 106; 91, boolean_operator:and; 91, 92; 91, 99; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:kwargs; 95, identifier:get; 96, argument_list; 96, 97; 96, 98; 97, string:'recursive'; 98, False; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:kwargs; 102, identifier:get; 103, argument_list; 103, 104; 103, 105; 104, string:'depth'; 105, False; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:opts; 111, string:'-d'; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:kwargs; 115, identifier:get; 116, argument_list; 116, 117; 117, string:'depth'; 118, if_statement; 118, 119; 118, 126; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:kwargs; 122, identifier:get; 123, argument_list; 123, 124; 123, 125; 124, string:'type'; 125, False; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:opts; 131, string:'-t'; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:kwargs; 135, identifier:get; 136, argument_list; 136, 137; 137, string:'type'; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:kwargs_sort; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:kwargs; 144, identifier:get; 145, argument_list; 145, 146; 145, 147; 146, string:'sort'; 147, False; 148, if_statement; 148, 149; 148, 154; 149, boolean_operator:and; 149, 150; 149, 151; 150, identifier:kwargs_sort; 151, comparison_operator:in; 151, 152; 151, 153; 152, identifier:kwargs_sort; 153, identifier:properties; 154, block; 154, 155; 155, if_statement; 155, 156; 155, 168; 155, 175; 156, call; 156, 157; 156, 166; 157, attribute; 157, 158; 157, 165; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:kwargs; 161, identifier:get; 162, argument_list; 162, 163; 162, 164; 163, string:'order'; 164, string:'ascending'; 165, identifier:startswith; 166, argument_list; 166, 167; 167, string:'a'; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:opts; 173, string:'-s'; 174, identifier:kwargs_sort; 175, else_clause; 175, 176; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:opts; 181, string:'-S'; 182, identifier:kwargs_sort; 183, if_statement; 183, 184; 183, 189; 183, 201; 184, call; 184, 185; 184, 186; 185, identifier:isinstance; 186, argument_list; 186, 187; 186, 188; 187, identifier:properties; 188, identifier:list; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:opts; 194, string:'-o'; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, string:','; 198, identifier:join; 199, argument_list; 199, 200; 200, identifier:properties; 201, else_clause; 201, 202; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:opts; 207, string:'-o'; 208, identifier:properties; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:res; 212, call; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:__salt__; 215, string:'cmd.run_all'; 216, argument_list; 216, 217; 216, 234; 217, call; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:__utils__; 220, string:'zfs.zfs_command'; 221, argument_list; 221, 222; 221, 225; 221, 228; 221, 231; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:command; 224, string:'list'; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:flags; 227, identifier:flags; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:opts; 230, identifier:opts; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:target; 233, identifier:name; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:python_shell; 236, False; 237, if_statement; 237, 238; 237, 243; 237, 332; 238, comparison_operator:==; 238, 239; 238, 242; 239, subscript; 239, 240; 239, 241; 240, identifier:res; 241, string:'retcode'; 242, integer:0; 243, block; 243, 244; 244, for_statement; 244, 245; 244, 246; 244, 253; 245, identifier:ds; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:res; 250, string:'stdout'; 251, identifier:splitlines; 252, argument_list; 253, block; 253, 254; 253, 316; 253, 324; 254, if_statement; 254, 255; 254, 262; 254, 287; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:kwargs; 258, identifier:get; 259, argument_list; 259, 260; 259, 261; 260, string:'parsable'; 261, True; 262, block; 262, 263; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:ds_data; 266, call; 266, 267; 266, 270; 267, subscript; 267, 268; 267, 269; 268, identifier:__utils__; 269, string:'zfs.from_auto_dict'; 270, argument_list; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:OrderedDict; 273, argument_list; 273, 274; 274, call; 274, 275; 274, 276; 275, identifier:list; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 279; 278, identifier:zip; 279, argument_list; 279, 280; 279, 281; 280, identifier:properties; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:ds; 284, identifier:split; 285, argument_list; 285, 286; 286, string:"\t"; 287, else_clause; 287, 288; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:ds_data; 292, call; 292, 293; 292, 296; 293, subscript; 293, 294; 293, 295; 294, identifier:__utils__; 295, string:'zfs.to_auto_dict'; 296, argument_list; 296, 297; 296, 313; 297, call; 297, 298; 297, 299; 298, identifier:OrderedDict; 299, argument_list; 299, 300; 300, call; 300, 301; 300, 302; 301, identifier:list; 302, argument_list; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:zip; 305, argument_list; 305, 306; 305, 307; 306, identifier:properties; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:ds; 310, identifier:split; 311, argument_list; 311, 312; 312, string:"\t"; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:convert_to_human; 315, True; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 323; 318, subscript; 318, 319; 318, 320; 319, identifier:ret; 320, subscript; 320, 321; 320, 322; 321, identifier:ds_data; 322, string:'name'; 323, identifier:ds_data; 324, delete_statement; 324, 325; 325, subscript; 325, 326; 325, 331; 326, subscript; 326, 327; 326, 328; 327, identifier:ret; 328, subscript; 328, 329; 328, 330; 329, identifier:ds_data; 330, string:'name'; 331, string:'name'; 332, else_clause; 332, 333; 333, block; 333, 334; 334, return_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, subscript; 336, 337; 336, 338; 337, identifier:__utils__; 338, string:'zfs.parse_command_result'; 339, argument_list; 339, 340; 340, identifier:res; 341, return_statement; 341, 342; 342, identifier:ret | def list_(name=None, **kwargs):
'''
Return a list of all datasets or a specified dataset on the system and the
values of their used, available, referenced, and mountpoint properties.
name : string
name of dataset, volume, or snapshot
recursive : boolean
recursively list children
depth : int
limit recursion to depth
properties : string
comma-separated list of properties to list, the name property will always be added
type : string
comma-separated list of types to display, where type is one of
filesystem, snapshot, volume, bookmark, or all.
sort : string
property to sort on (default = name)
order : string [ascending|descending]
sort order (default = ascending)
parsable : boolean
display numbers in parsable (exact) values
.. versionadded:: 2018.3.0
.. versionadded:: 2015.5.0
CLI Example:
.. code-block:: bash
salt '*' zfs.list
salt '*' zfs.list myzpool/mydataset [recursive=True|False]
salt '*' zfs.list myzpool/mydataset properties="sharenfs,mountpoint"
'''
ret = OrderedDict()
properties = kwargs.get('properties', 'used,avail,refer,mountpoint')
if not isinstance(properties, list):
properties = properties.split(',')
while 'name' in properties:
properties.remove('name')
properties.insert(0, 'name')
flags = ['-H']
opts = {}
if kwargs.get('recursive', False):
flags.append('-r')
if kwargs.get('recursive', False) and kwargs.get('depth', False):
opts['-d'] = kwargs.get('depth')
if kwargs.get('type', False):
opts['-t'] = kwargs.get('type')
kwargs_sort = kwargs.get('sort', False)
if kwargs_sort and kwargs_sort in properties:
if kwargs.get('order', 'ascending').startswith('a'):
opts['-s'] = kwargs_sort
else:
opts['-S'] = kwargs_sort
if isinstance(properties, list):
opts['-o'] = ','.join(properties)
else:
opts['-o'] = properties
res = __salt__['cmd.run_all'](
__utils__['zfs.zfs_command'](
command='list',
flags=flags,
opts=opts,
target=name,
),
python_shell=False,
)
if res['retcode'] == 0:
for ds in res['stdout'].splitlines():
if kwargs.get('parsable', True):
ds_data = __utils__['zfs.from_auto_dict'](
OrderedDict(list(zip(properties, ds.split("\t")))),
)
else:
ds_data = __utils__['zfs.to_auto_dict'](
OrderedDict(list(zip(properties, ds.split("\t")))),
convert_to_human=True,
)
ret[ds_data['name']] = ds_data
del ret[ds_data['name']]['name']
else:
return __utils__['zfs.parse_command_result'](res)
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:list_users; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:order_by; 6, string:'id'; 7, block; 7, 8; 7, 10; 7, 14; 7, 28; 7, 37; 7, 45; 7, 114; 8, expression_statement; 8, 9; 9, string:'''
Show all users for this company.
CLI Example:
salt myminion bamboohr.list_users
By default, the return data will be keyed by ID. However, it can be ordered
by any other field. Keep in mind that if the field that is chosen contains
duplicate values (i.e., location is used, for a company which only has one
location), then each duplicate value will be overwritten by the previous.
Therefore, it is advisable to only sort by fields that are guaranteed to be
unique.
CLI Examples:
salt myminion bamboohr.list_users order_by=id
salt myminion bamboohr.list_users order_by=email
'''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:ret; 13, dictionary; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, pattern_list; 16, 17; 16, 18; 17, identifier:status; 18, identifier:result; 19, call; 19, 20; 19, 21; 20, identifier:_query; 21, argument_list; 21, 22; 21, 25; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:action; 24, string:'meta'; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:command; 27, string:'users'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:root; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:ET; 34, identifier:fromstring; 35, argument_list; 35, 36; 36, identifier:result; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:users; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:root; 43, identifier:getchildren; 44, argument_list; 45, for_statement; 45, 46; 45, 47; 45, 48; 46, identifier:user; 47, identifier:users; 48, block; 48, 49; 48, 53; 48, 57; 48, 88; 48, 106; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:user_id; 52, None; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:user_ret; 56, dictionary; 57, for_statement; 57, 58; 57, 59; 57, 64; 58, identifier:item; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:user; 62, identifier:items; 63, argument_list; 64, block; 64, 65; 64, 75; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 69; 68, identifier:user_ret; 69, subscript; 69, 70; 69, 71; 70, identifier:item; 71, integer:0; 72, subscript; 72, 73; 72, 74; 73, identifier:item; 74, integer:1; 75, if_statement; 75, 76; 75, 81; 76, comparison_operator:==; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:item; 79, integer:0; 80, string:'id'; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:user_id; 85, subscript; 85, 86; 85, 87; 86, identifier:item; 87, integer:1; 88, for_statement; 88, 89; 88, 90; 88, 95; 89, identifier:item; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:user; 93, identifier:getchildren; 94, argument_list; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 103; 98, subscript; 98, 99; 98, 100; 99, identifier:user_ret; 100, attribute; 100, 101; 100, 102; 101, identifier:item; 102, identifier:tag; 103, attribute; 103, 104; 103, 105; 104, identifier:item; 105, identifier:text; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 113; 108, subscript; 108, 109; 108, 110; 109, identifier:ret; 110, subscript; 110, 111; 110, 112; 111, identifier:user_ret; 112, identifier:order_by; 113, identifier:user_ret; 114, return_statement; 114, 115; 115, identifier:ret | def list_users(order_by='id'):
'''
Show all users for this company.
CLI Example:
salt myminion bamboohr.list_users
By default, the return data will be keyed by ID. However, it can be ordered
by any other field. Keep in mind that if the field that is chosen contains
duplicate values (i.e., location is used, for a company which only has one
location), then each duplicate value will be overwritten by the previous.
Therefore, it is advisable to only sort by fields that are guaranteed to be
unique.
CLI Examples:
salt myminion bamboohr.list_users order_by=id
salt myminion bamboohr.list_users order_by=email
'''
ret = {}
status, result = _query(action='meta', command='users')
root = ET.fromstring(result)
users = root.getchildren()
for user in users:
user_id = None
user_ret = {}
for item in user.items():
user_ret[item[0]] = item[1]
if item[0] == 'id':
user_id = item[1]
for item in user.getchildren():
user_ret[item.tag] = item.text
ret[user_ret[order_by]] = user_ret
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:key_value; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:minion_id; 5, identifier:pillar; 6, default_parameter; 6, 7; 6, 8; 7, identifier:pillar_key; 8, string:'redis_pillar'; 9, block; 9, 10; 9, 12; 9, 21; 9, 134; 10, expression_statement; 10, 11; 11, string:'''
Looks for key in redis matching minion_id, returns a structure based on the
data type of the redis key. String for string type, dict for hash type and
lists for lists, sets and sorted sets.
pillar_key
Pillar key to return data into
'''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:key_type; 15, call; 15, 16; 15, 19; 16, subscript; 16, 17; 16, 18; 17, identifier:__salt__; 18, string:'redis.key_type'; 19, argument_list; 19, 20; 20, identifier:minion_id; 21, if_statement; 21, 22; 21, 25; 21, 36; 21, 51; 21, 85; 21, 100; 22, comparison_operator:==; 22, 23; 22, 24; 23, identifier:key_type; 24, string:'string'; 25, block; 25, 26; 26, return_statement; 26, 27; 27, dictionary; 27, 28; 28, pair; 28, 29; 28, 30; 29, identifier:pillar_key; 30, call; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:__salt__; 33, string:'redis.get_key'; 34, argument_list; 34, 35; 35, identifier:minion_id; 36, elif_clause; 36, 37; 36, 40; 37, comparison_operator:==; 37, 38; 37, 39; 38, identifier:key_type; 39, string:'hash'; 40, block; 40, 41; 41, return_statement; 41, 42; 42, dictionary; 42, 43; 43, pair; 43, 44; 43, 45; 44, identifier:pillar_key; 45, call; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:__salt__; 48, string:'redis.hgetall'; 49, argument_list; 49, 50; 50, identifier:minion_id; 51, elif_clause; 51, 52; 51, 55; 52, comparison_operator:==; 52, 53; 52, 54; 53, identifier:key_type; 54, string:'list'; 55, block; 55, 56; 55, 65; 55, 71; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:list_size; 59, call; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:__salt__; 62, string:'redis.llen'; 63, argument_list; 63, 64; 64, identifier:minion_id; 65, if_statement; 65, 66; 65, 68; 66, not_operator; 66, 67; 67, identifier:list_size; 68, block; 68, 69; 69, return_statement; 69, 70; 70, dictionary; 71, return_statement; 71, 72; 72, dictionary; 72, 73; 73, pair; 73, 74; 73, 75; 74, identifier:pillar_key; 75, call; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:__salt__; 78, string:'redis.lrange'; 79, argument_list; 79, 80; 79, 81; 79, 82; 80, identifier:minion_id; 81, integer:0; 82, binary_operator:-; 82, 83; 82, 84; 83, identifier:list_size; 84, integer:1; 85, elif_clause; 85, 86; 85, 89; 86, comparison_operator:==; 86, 87; 86, 88; 87, identifier:key_type; 88, string:'set'; 89, block; 89, 90; 90, return_statement; 90, 91; 91, dictionary; 91, 92; 92, pair; 92, 93; 92, 94; 93, identifier:pillar_key; 94, call; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:__salt__; 97, string:'redis.smembers'; 98, argument_list; 98, 99; 99, identifier:minion_id; 100, elif_clause; 100, 101; 100, 104; 101, comparison_operator:==; 101, 102; 101, 103; 102, identifier:key_type; 103, string:'zset'; 104, block; 104, 105; 104, 114; 104, 120; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:set_size; 108, call; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:__salt__; 111, string:'redis.zcard'; 112, argument_list; 112, 113; 113, identifier:minion_id; 114, if_statement; 114, 115; 114, 117; 115, not_operator; 115, 116; 116, identifier:set_size; 117, block; 117, 118; 118, return_statement; 118, 119; 119, dictionary; 120, return_statement; 120, 121; 121, dictionary; 121, 122; 122, pair; 122, 123; 122, 124; 123, identifier:pillar_key; 124, call; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:__salt__; 127, string:'redis.zrange'; 128, argument_list; 128, 129; 128, 130; 128, 131; 129, identifier:minion_id; 130, integer:0; 131, binary_operator:-; 131, 132; 131, 133; 132, identifier:set_size; 133, integer:1; 134, return_statement; 134, 135; 135, dictionary | def key_value(minion_id,
pillar,
pillar_key='redis_pillar'):
'''
Looks for key in redis matching minion_id, returns a structure based on the
data type of the redis key. String for string type, dict for hash type and
lists for lists, sets and sorted sets.
pillar_key
Pillar key to return data into
'''
key_type = __salt__['redis.key_type'](minion_id)
if key_type == 'string':
return {pillar_key: __salt__['redis.get_key'](minion_id)}
elif key_type == 'hash':
return {pillar_key: __salt__['redis.hgetall'](minion_id)}
elif key_type == 'list':
list_size = __salt__['redis.llen'](minion_id)
if not list_size:
return {}
return {pillar_key: __salt__['redis.lrange'](minion_id, 0,
list_size - 1)}
elif key_type == 'set':
return {pillar_key: __salt__['redis.smembers'](minion_id)}
elif key_type == 'zset':
set_size = __salt__['redis.zcard'](minion_id)
if not set_size:
return {}
return {pillar_key: __salt__['redis.zrange'](minion_id, 0,
set_size - 1)}
return {} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_cmp_version; 3, parameters; 3, 4; 3, 5; 4, identifier:item1; 5, identifier:item2; 6, block; 6, 7; 6, 9; 6, 16; 6, 23; 6, 31; 6, 38; 7, expression_statement; 7, 8; 8, string:'''
Compare function for package version sorting
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:vers1; 12, call; 12, 13; 12, 14; 13, identifier:_LooseVersion; 14, argument_list; 14, 15; 15, identifier:item1; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:vers2; 19, call; 19, 20; 19, 21; 20, identifier:_LooseVersion; 21, argument_list; 21, 22; 22, identifier:item2; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:<; 24, 25; 24, 26; 25, identifier:vers1; 26, identifier:vers2; 27, block; 27, 28; 28, return_statement; 28, 29; 29, unary_operator:-; 29, 30; 30, integer:1; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:>; 32, 33; 32, 34; 33, identifier:vers1; 34, identifier:vers2; 35, block; 35, 36; 36, return_statement; 36, 37; 37, integer:1; 38, return_statement; 38, 39; 39, integer:0 | def _cmp_version(item1, item2):
'''
Compare function for package version sorting
'''
vers1 = _LooseVersion(item1)
vers2 = _LooseVersion(item2)
if vers1 < vers2:
return -1
if vers1 > vers2:
return 1
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:list_snapshots; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:config_path; 6, identifier:_DEFAULT_CONFIG_PATH; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sort_by_time; 9, False; 10, block; 10, 11; 10, 13; 10, 18; 10, 31; 10, 50; 10, 57; 10, 73; 10, 84; 11, expression_statement; 11, 12; 12, string:'''
Get a list of all the existing snapshots.
:param str config_path: The path to the configuration file for the aptly instance.
:param bool sort_by_time: Whether to sort by creation time instead of by name.
:return: A list of the snapshot names.
:rtype: list
CLI Example:
.. code-block:: bash
salt '*' aptly.list_snapshots
'''; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:_validate_config; 16, argument_list; 16, 17; 17, identifier:config_path; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:cmd; 21, list:['snapshot', 'list', '-config={}'.format(config_path), '-raw=true']; 21, 22; 21, 23; 21, 24; 21, 30; 22, string:'snapshot'; 23, string:'list'; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:'-config={}'; 27, identifier:format; 28, argument_list; 28, 29; 29, identifier:config_path; 30, string:'-raw=true'; 31, if_statement; 31, 32; 31, 33; 31, 41; 32, identifier:sort_by_time; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:cmd; 38, identifier:append; 39, argument_list; 39, 40; 40, string:'-sort=time'; 41, else_clause; 41, 42; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:cmd; 47, identifier:append; 48, argument_list; 48, 49; 49, string:'-sort=name'; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:cmd_ret; 53, call; 53, 54; 53, 55; 54, identifier:_cmd_run; 55, argument_list; 55, 56; 56, identifier:cmd; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:ret; 60, list_comprehension; 60, 61; 60, 66; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:line; 64, identifier:strip; 65, argument_list; 66, for_in_clause; 66, 67; 66, 68; 67, identifier:line; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:cmd_ret; 71, identifier:splitlines; 72, argument_list; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:log; 77, identifier:debug; 78, argument_list; 78, 79; 78, 80; 79, string:'Found snapshots: %s'; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:ret; 84, return_statement; 84, 85; 85, identifier:ret | def list_snapshots(config_path=_DEFAULT_CONFIG_PATH, sort_by_time=False):
'''
Get a list of all the existing snapshots.
:param str config_path: The path to the configuration file for the aptly instance.
:param bool sort_by_time: Whether to sort by creation time instead of by name.
:return: A list of the snapshot names.
:rtype: list
CLI Example:
.. code-block:: bash
salt '*' aptly.list_snapshots
'''
_validate_config(config_path)
cmd = ['snapshot', 'list', '-config={}'.format(config_path), '-raw=true']
if sort_by_time:
cmd.append('-sort=time')
else:
cmd.append('-sort=name')
cmd_ret = _cmd_run(cmd)
ret = [line.strip() for line in cmd_ret.splitlines()]
log.debug('Found snapshots: %s', len(ret))
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:render_value; 3, parameters; 3, 4; 4, identifier:value; 5, block; 5, 6; 6, if_statement; 6, 7; 6, 12; 6, 30; 6, 74; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:value; 11, identifier:list; 12, block; 12, 13; 13, return_statement; 13, 14; 14, binary_operator:+; 14, 15; 14, 29; 15, binary_operator:+; 15, 16; 15, 17; 16, string:'['; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, string:', '; 20, identifier:join; 21, generator_expression; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:render_value; 24, argument_list; 24, 25; 25, identifier:v; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:v; 28, identifier:value; 29, string:']'; 30, elif_clause; 30, 31; 30, 36; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 35; 34, identifier:value; 35, identifier:dict; 36, block; 36, 37; 37, return_statement; 37, 38; 38, parenthesized_expression; 38, 39; 39, binary_operator:+; 39, 40; 39, 73; 40, binary_operator:+; 40, 41; 40, 42; 41, string:'{'; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:', '; 45, identifier:join; 46, generator_expression; 46, 47; 46, 61; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:'{k!r}: {v}'; 50, identifier:format; 51, argument_list; 51, 52; 51, 55; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:k; 54, identifier:k; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:v; 57, call; 57, 58; 57, 59; 58, identifier:render_value; 59, argument_list; 59, 60; 60, identifier:v; 61, for_in_clause; 61, 62; 61, 65; 62, pattern_list; 62, 63; 62, 64; 63, identifier:k; 64, identifier:v; 65, call; 65, 66; 65, 67; 66, identifier:sorted; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:value; 71, identifier:items; 72, argument_list; 73, string:'}'; 74, else_clause; 74, 75; 75, block; 75, 76; 76, return_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:repr; 79, argument_list; 79, 80; 80, identifier:value | def render_value(value):
if isinstance(value, list):
return '[' + ', '.join(render_value(v) for v in value) + ']'
elif isinstance(value, dict):
return (
'{' +
', '.join('{k!r}: {v}'.format(
k=k, v=render_value(v)) for k, v in sorted(value.items())) +
'}')
else:
return repr(value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort_schema; 3, parameters; 3, 4; 4, identifier:schema; 5, block; 5, 6; 6, if_statement; 6, 7; 6, 12; 6, 69; 6, 117; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier:schema; 11, identifier:dict; 12, block; 12, 13; 13, for_statement; 13, 14; 13, 17; 13, 25; 14, pattern_list; 14, 15; 14, 16; 15, identifier:k; 16, identifier:v; 17, call; 17, 18; 17, 19; 18, identifier:sorted; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:schema; 23, identifier:items; 24, argument_list; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 32; 26, 44; 26, 62; 27, call; 27, 28; 27, 29; 28, identifier:isinstance; 29, argument_list; 29, 30; 29, 31; 30, identifier:v; 31, identifier:dict; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, yield; 34, 35; 35, expression_list; 35, 36; 35, 37; 36, identifier:k; 37, call; 37, 38; 37, 39; 38, identifier:OrderedDict; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:_sort_schema; 42, argument_list; 42, 43; 43, identifier:v; 44, elif_clause; 44, 45; 44, 50; 45, call; 45, 46; 45, 47; 46, identifier:isinstance; 47, argument_list; 47, 48; 47, 49; 48, identifier:v; 49, identifier:list; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, yield; 52, 53; 53, expression_list; 53, 54; 53, 55; 54, identifier:k; 55, call; 55, 56; 55, 57; 56, identifier:list; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:_sort_schema; 60, argument_list; 60, 61; 61, identifier:v; 62, else_clause; 62, 63; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, yield; 65, 66; 66, expression_list; 66, 67; 66, 68; 67, identifier:k; 68, identifier:v; 69, elif_clause; 69, 70; 69, 75; 70, call; 70, 71; 70, 72; 71, identifier:isinstance; 72, argument_list; 72, 73; 72, 74; 73, identifier:schema; 74, identifier:list; 75, block; 75, 76; 76, for_statement; 76, 77; 76, 78; 76, 79; 77, identifier:v; 78, identifier:schema; 79, block; 79, 80; 80, if_statement; 80, 81; 80, 86; 80, 96; 80, 112; 81, call; 81, 82; 81, 83; 82, identifier:isinstance; 83, argument_list; 83, 84; 83, 85; 84, identifier:v; 85, identifier:dict; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, yield; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:OrderedDict; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:_sort_schema; 94, argument_list; 94, 95; 95, identifier:v; 96, elif_clause; 96, 97; 96, 102; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:v; 101, identifier:list; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, yield; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:list; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:_sort_schema; 110, argument_list; 110, 111; 111, identifier:v; 112, else_clause; 112, 113; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, yield; 115, 116; 116, identifier:v; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, yield; 120, 121; 121, identifier:d | def _sort_schema(schema):
if isinstance(schema, dict):
for k, v in sorted(schema.items()):
if isinstance(v, dict):
yield k, OrderedDict(_sort_schema(v))
elif isinstance(v, list):
yield k, list(_sort_schema(v))
else:
yield k, v
elif isinstance(schema, list):
for v in schema:
if isinstance(v, dict):
yield OrderedDict(_sort_schema(v))
elif isinstance(v, list):
yield list(_sort_schema(v))
else:
yield v
else:
yield d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_sort_handlers; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:cls; 5, identifier:signals; 6, identifier:handlers; 7, identifier:configs; 8, block; 8, 9; 8, 78; 8, 87; 8, 94; 8, 144; 8, 180; 9, function_definition; 9, 10; 9, 11; 9, 14; 10, function_name:macro_precedence_sorter; 11, parameters; 11, 12; 11, 13; 12, identifier:flags; 13, identifier:hname; 14, block; 14, 15; 14, 21; 14, 29; 14, 50; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:data; 18, subscript; 18, 19; 18, 20; 19, identifier:configs; 20, identifier:hname; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:topdown_sort; 24, comparison_operator:in; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:SignalOptions; 27, identifier:SORT_TOPDOWN; 28, identifier:flags; 29, if_statement; 29, 30; 29, 31; 29, 42; 30, identifier:topdown_sort; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:level; 35, binary_operator:-; 35, 36; 35, 39; 36, binary_operator:-; 36, 37; 36, 38; 37, identifier:levels_count; 38, integer:1; 39, subscript; 39, 40; 39, 41; 40, identifier:data; 41, string:'level'; 42, else_clause; 42, 43; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:level; 47, subscript; 47, 48; 47, 49; 48, identifier:data; 49, string:'level'; 50, if_statement; 50, 51; 50, 54; 50, 61; 50, 71; 51, comparison_operator:in; 51, 52; 51, 53; 52, string:'begin'; 53, identifier:data; 54, block; 54, 55; 55, return_statement; 55, 56; 56, tuple; 56, 57; 56, 59; 56, 60; 57, unary_operator:-; 57, 58; 58, integer:1; 59, identifier:level; 60, identifier:hname; 61, elif_clause; 61, 62; 61, 65; 62, comparison_operator:in; 62, 63; 62, 64; 63, string:'end'; 64, identifier:data; 65, block; 65, 66; 66, return_statement; 66, 67; 67, tuple; 67, 68; 67, 69; 67, 70; 68, integer:1; 69, identifier:level; 70, identifier:hname; 71, else_clause; 71, 72; 72, block; 72, 73; 73, return_statement; 73, 74; 74, tuple; 74, 75; 74, 76; 74, 77; 75, integer:0; 76, identifier:level; 77, identifier:hname; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:levels_count; 81, call; 81, 82; 81, 83; 82, identifier:len; 83, argument_list; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:handlers; 86, identifier:maps; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:per_signal; 90, call; 90, 91; 90, 92; 91, identifier:defaultdict; 92, argument_list; 92, 93; 93, identifier:list; 94, for_statement; 94, 95; 94, 98; 94, 107; 95, pattern_list; 95, 96; 95, 97; 96, identifier:level; 97, identifier:m; 98, call; 98, 99; 98, 100; 99, identifier:enumerate; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:reversed; 103, argument_list; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:handlers; 106, identifier:maps; 107, block; 107, 108; 108, for_statement; 108, 109; 108, 112; 108, 117; 109, pattern_list; 109, 110; 109, 111; 110, identifier:hname; 111, identifier:sig_name; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:m; 115, identifier:items; 116, argument_list; 117, block; 117, 118; 117, 124; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:sig_handlers; 121, subscript; 121, 122; 121, 123; 122, identifier:per_signal; 123, identifier:sig_name; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:not; 125, 126; 125, 127; 126, identifier:hname; 127, identifier:sig_handlers; 128, block; 128, 129; 128, 137; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 136; 131, subscript; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:configs; 134, identifier:hname; 135, string:'level'; 136, identifier:level; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:sig_handlers; 141, identifier:append; 142, argument_list; 142, 143; 143, identifier:hname; 144, for_statement; 144, 145; 144, 148; 144, 153; 145, pattern_list; 145, 146; 145, 147; 146, identifier:sig_name; 147, identifier:sig_handlers; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:per_signal; 151, identifier:items; 152, argument_list; 153, block; 153, 154; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:in; 155, 156; 155, 157; 156, identifier:sig_name; 157, identifier:signals; 158, block; 158, 159; 158, 167; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:flags; 162, attribute; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:signals; 165, identifier:sig_name; 166, identifier:flags; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:sig_handlers; 171, identifier:sort; 172, argument_list; 172, 173; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:key; 175, call; 175, 176; 175, 177; 176, identifier:partial; 177, argument_list; 177, 178; 177, 179; 178, identifier:macro_precedence_sorter; 179, identifier:flags; 180, return_statement; 180, 181; 181, identifier:per_signal | def _sort_handlers(cls, signals, handlers, configs):
def macro_precedence_sorter(flags, hname):
data = configs[hname]
topdown_sort = SignalOptions.SORT_TOPDOWN in flags
if topdown_sort:
level = levels_count - 1 - data['level']
else:
level = data['level']
if 'begin' in data:
return (-1, level, hname)
elif 'end' in data:
return (1, level, hname)
else:
return (0, level, hname)
levels_count = len(handlers.maps)
per_signal = defaultdict(list)
for level, m in enumerate(reversed(handlers.maps)):
for hname, sig_name in m.items():
sig_handlers = per_signal[sig_name]
if hname not in sig_handlers:
configs[hname]['level'] = level
sig_handlers.append(hname)
for sig_name, sig_handlers in per_signal.items():
if sig_name in signals:
flags = signals[sig_name].flags
sig_handlers.sort(key=partial(macro_precedence_sorter,
flags))
return per_signal |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_radixPass; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:a; 5, identifier:b; 6, identifier:r; 7, identifier:n; 8, identifier:K; 9, block; 9, 10; 9, 24; 9, 41; 9, 45; 9, 70; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:c; 13, call; 13, 14; 13, 15; 14, identifier:_array; 15, argument_list; 15, 16; 15, 17; 16, string:"i"; 17, binary_operator:*; 17, 18; 17, 20; 18, list:[0]; 18, 19; 19, integer:0; 20, parenthesized_expression; 20, 21; 21, binary_operator:+; 21, 22; 21, 23; 22, identifier:K; 23, integer:1; 24, for_statement; 24, 25; 24, 26; 24, 30; 25, identifier:i; 26, call; 26, 27; 26, 28; 27, identifier:range; 28, argument_list; 28, 29; 29, identifier:n; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, augmented_assignment:+=; 32, 33; 32, 40; 33, subscript; 33, 34; 33, 35; 34, identifier:c; 35, subscript; 35, 36; 35, 37; 36, identifier:r; 37, subscript; 37, 38; 37, 39; 38, identifier:a; 39, identifier:i; 40, integer:1; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:sum; 44, integer:0; 45, for_statement; 45, 46; 45, 47; 45, 53; 46, identifier:i; 47, call; 47, 48; 47, 49; 48, identifier:range; 49, argument_list; 49, 50; 50, binary_operator:+; 50, 51; 50, 52; 51, identifier:K; 52, integer:1; 53, block; 53, 54; 53, 60; 53, 66; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:t; 57, subscript; 57, 58; 57, 59; 58, identifier:c; 59, identifier:i; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:c; 64, identifier:i; 65, identifier:sum; 66, expression_statement; 66, 67; 67, augmented_assignment:+=; 67, 68; 67, 69; 68, identifier:sum; 69, identifier:t; 70, for_statement; 70, 71; 70, 72; 70, 77; 71, identifier:a_i; 72, subscript; 72, 73; 72, 74; 73, identifier:a; 74, slice; 74, 75; 74, 76; 75, colon; 76, identifier:n; 77, block; 77, 78; 77, 88; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 87; 80, subscript; 80, 81; 80, 82; 81, identifier:b; 82, subscript; 82, 83; 82, 84; 83, identifier:c; 84, subscript; 84, 85; 84, 86; 85, identifier:r; 86, identifier:a_i; 87, identifier:a_i; 88, expression_statement; 88, 89; 89, augmented_assignment:+=; 89, 90; 89, 95; 90, subscript; 90, 91; 90, 92; 91, identifier:c; 92, subscript; 92, 93; 92, 94; 93, identifier:r; 94, identifier:a_i; 95, integer:1 | def _radixPass(a, b, r, n, K):
c = _array("i", [0] * (K + 1))
for i in range(n):
c[r[a[i]]] += 1
sum = 0
for i in range(K + 1):
t = c[i]
c[i] = sum
sum += t
for a_i in a[:n]:
b[c[r[a_i]]] = a_i
c[r[a_i]] += 1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:save_yaml; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:dictionary; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:pretty; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sortkeys; 11, False; 12, block; 12, 13; 12, 23; 13, if_statement; 13, 14; 13, 15; 14, identifier:sortkeys; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:dictionary; 19, call; 19, 20; 19, 21; 20, identifier:dict; 21, argument_list; 21, 22; 22, identifier:dictionary; 23, with_statement; 23, 24; 23, 34; 24, with_clause; 24, 25; 25, with_item; 25, 26; 26, as_pattern; 26, 27; 26, 32; 27, call; 27, 28; 27, 29; 28, identifier:open; 29, argument_list; 29, 30; 29, 31; 30, identifier:path; 31, string:'w'; 32, as_pattern_target; 32, 33; 33, identifier:f; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 37; 35, 46; 36, identifier:pretty; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:pyaml; 42, identifier:dump; 43, argument_list; 43, 44; 43, 45; 44, identifier:dictionary; 45, identifier:f; 46, else_clause; 46, 47; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:yaml; 52, identifier:dump; 53, argument_list; 53, 54; 53, 55; 53, 56; 53, 59; 54, identifier:dictionary; 55, identifier:f; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:default_flow_style; 58, None; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:Dumper; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:yamlloader; 64, identifier:ordereddict; 65, identifier:CDumper | def save_yaml(dictionary, path, pretty=False, sortkeys=False):
if sortkeys:
dictionary = dict(dictionary)
with open(path, 'w') as f:
if pretty:
pyaml.dump(dictionary, f)
else:
yaml.dump(dictionary, f, default_flow_style=None, Dumper=yamlloader.ordereddict.CDumper) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:save_json; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:dictionary; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:pretty; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sortkeys; 11, False; 12, block; 12, 13; 13, with_statement; 13, 14; 13, 24; 14, with_clause; 14, 15; 15, with_item; 15, 16; 16, as_pattern; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:open; 19, argument_list; 19, 20; 19, 21; 20, identifier:path; 21, string:'w'; 22, as_pattern_target; 22, 23; 23, identifier:f; 24, block; 24, 25; 24, 50; 25, if_statement; 25, 26; 25, 27; 25, 38; 26, identifier:pretty; 27, block; 27, 28; 27, 32; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:indent; 31, integer:2; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:separators; 35, tuple; 35, 36; 35, 37; 36, string:','; 37, string:': '; 38, else_clause; 38, 39; 39, block; 39, 40; 39, 44; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:indent; 43, None; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:separators; 47, tuple; 47, 48; 47, 49; 48, string:', '; 49, string:': '; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:json; 54, identifier:dump; 55, argument_list; 55, 56; 55, 57; 55, 58; 55, 61; 55, 64; 56, identifier:dictionary; 57, identifier:f; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:indent; 60, identifier:indent; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:sort_keys; 63, identifier:sortkeys; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:separators; 66, identifier:separators | def save_json(dictionary, path, pretty=False, sortkeys=False):
with open(path, 'w') as f:
if pretty:
indent = 2
separators = (',', ': ')
else:
indent = None
separators = (', ', ': ')
json.dump(dictionary, f, indent=indent, sort_keys=sortkeys, separators=separators) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:save_json; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:val; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pretty; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:encoder; 13, None; 14, block; 14, 15; 14, 24; 14, 72; 14, 97; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:encoder; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:encoder; 23, identifier:DateTimeEncoder; 24, if_statement; 24, 25; 24, 26; 24, 50; 25, identifier:pretty; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:data; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:json; 33, identifier:dumps; 34, argument_list; 34, 35; 34, 36; 34, 39; 34, 44; 34, 47; 35, identifier:val; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:indent; 38, integer:4; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:separators; 41, tuple; 41, 42; 41, 43; 42, string:','; 43, string:': '; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:sort_keys; 46, identifier:sort; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:cls; 49, identifier:encoder; 50, else_clause; 50, 51; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:data; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:json; 58, identifier:dumps; 59, argument_list; 59, 60; 59, 61; 59, 66; 59, 69; 60, identifier:val; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:separators; 63, tuple; 63, 64; 63, 65; 64, string:','; 65, string:':'; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:sort_keys; 68, identifier:sort; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:cls; 71, identifier:encoder; 72, if_statement; 72, 73; 72, 87; 73, boolean_operator:and; 73, 74; 73, 82; 74, not_operator; 74, 75; 75, comparison_operator:>; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:sys; 78, identifier:version_info; 79, tuple; 79, 80; 79, 81; 80, integer:3; 81, integer:0; 82, call; 82, 83; 82, 84; 83, identifier:isinstance; 84, argument_list; 84, 85; 84, 86; 85, identifier:data; 86, identifier:str; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:data; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:data; 94, identifier:decode; 95, argument_list; 95, 96; 96, string:"utf-8"; 97, return_statement; 97, 98; 98, identifier:data | def save_json(val, pretty=False, sort=True, encoder=None):
if encoder is None:
encoder = DateTimeEncoder
if pretty:
data = json.dumps(
val,
indent=4,
separators=(',', ': '),
sort_keys=sort,
cls=encoder
)
else:
data = json.dumps(
val,
separators=(',', ':'),
sort_keys=sort,
cls=encoder
)
if not sys.version_info > (3, 0) and isinstance(data, str):
data = data.decode("utf-8")
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:revdocs2reverts; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 3, 16; 4, identifier:rev_docs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:radius; 7, attribute; 7, 8; 7, 9; 8, identifier:defaults; 9, identifier:RADIUS; 10, default_parameter; 10, 11; 10, 12; 11, identifier:use_sha1; 12, False; 13, default_parameter; 13, 14; 13, 15; 14, identifier:resort; 15, False; 16, default_parameter; 16, 17; 16, 18; 17, identifier:verbose; 18, False; 19, block; 19, 20; 19, 36; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:page_rev_docs; 23, call; 23, 24; 23, 25; 24, identifier:groupby; 25, argument_list; 25, 26; 25, 27; 26, identifier:rev_docs; 27, lambda; 27, 28; 27, 30; 28, lambda_parameters; 28, 29; 29, identifier:rd; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:rd; 33, identifier:get; 34, argument_list; 34, 35; 35, string:'page'; 36, for_statement; 36, 37; 36, 40; 36, 41; 37, pattern_list; 37, 38; 37, 39; 38, identifier:page_doc; 39, identifier:rev_docs; 40, identifier:page_rev_docs; 41, block; 41, 42; 41, 69; 41, 117; 41, 126; 41, 261; 42, if_statement; 42, 43; 42, 44; 43, identifier:verbose; 44, block; 44, 45; 44, 61; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:sys; 50, identifier:stderr; 51, identifier:write; 52, argument_list; 52, 53; 53, binary_operator:+; 53, 54; 53, 60; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:page_doc; 57, identifier:get; 58, argument_list; 58, 59; 59, string:'title'; 60, string:": "; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:sys; 66, identifier:stderr; 67, identifier:flush; 68, argument_list; 69, if_statement; 69, 70; 69, 71; 70, identifier:resort; 71, block; 71, 72; 71, 92; 72, if_statement; 72, 73; 72, 74; 73, identifier:verbose; 74, block; 74, 75; 74, 84; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:sys; 80, identifier:stderr; 81, identifier:write; 82, argument_list; 82, 83; 83, string:"(sorting) "; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:sys; 89, identifier:stderr; 90, identifier:flush; 91, argument_list; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:rev_docs; 95, call; 95, 96; 95, 97; 96, identifier:sorted; 97, argument_list; 97, 98; 97, 99; 98, identifier:rev_docs; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:key; 101, lambda; 101, 102; 101, 104; 102, lambda_parameters; 102, 103; 103, identifier:r; 104, tuple; 104, 105; 104, 111; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:r; 108, identifier:get; 109, argument_list; 109, 110; 110, string:'timestamp'; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:r; 114, identifier:get; 115, argument_list; 115, 116; 116, string:'id'; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:detector; 120, call; 120, 121; 120, 122; 121, identifier:Detector; 122, argument_list; 122, 123; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:radius; 125, identifier:radius; 126, for_statement; 126, 127; 126, 128; 126, 129; 127, identifier:rev_doc; 128, identifier:rev_docs; 129, block; 129, 130; 129, 154; 129, 199; 129, 209; 130, if_statement; 130, 131; 130, 137; 131, boolean_operator:and; 131, 132; 131, 134; 132, not_operator; 132, 133; 133, identifier:use_sha1; 134, comparison_operator:not; 134, 135; 134, 136; 135, string:'text'; 136, identifier:rev_doc; 137, block; 137, 138; 137, 153; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:logger; 142, identifier:warn; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, string:"Skipping {0}: 'text' field not found in {0}"; 147, identifier:format; 148, argument_list; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:rev_doc; 151, string:'id'; 152, identifier:rev_doc; 153, continue_statement; 154, if_statement; 154, 155; 154, 156; 154, 170; 155, identifier:use_sha1; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:checksum; 160, boolean_operator:or; 160, 161; 160, 167; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:rev_doc; 164, identifier:get; 165, argument_list; 165, 166; 166, string:'sha1'; 167, call; 167, 168; 167, 169; 168, identifier:DummyChecksum; 169, argument_list; 170, elif_clause; 170, 171; 170, 174; 171, comparison_operator:in; 171, 172; 171, 173; 172, string:'text'; 173, identifier:rev_doc; 174, block; 174, 175; 174, 186; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:text_bytes; 178, call; 178, 179; 178, 180; 179, identifier:bytes; 180, argument_list; 180, 181; 180, 184; 180, 185; 181, subscript; 181, 182; 181, 183; 182, identifier:rev_doc; 183, string:'text'; 184, string:'utf8'; 185, string:'replace'; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:checksum; 189, call; 189, 190; 189, 198; 190, attribute; 190, 191; 190, 197; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:hashlib; 194, identifier:sha1; 195, argument_list; 195, 196; 196, identifier:text_bytes; 197, identifier:digest; 198, argument_list; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:revert; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:detector; 205, identifier:process; 206, argument_list; 206, 207; 206, 208; 207, identifier:checksum; 208, identifier:rev_doc; 209, if_statement; 209, 210; 209, 211; 209, 239; 210, identifier:revert; 211, block; 211, 212; 211, 219; 212, expression_statement; 212, 213; 213, yield; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:revert; 217, identifier:to_json; 218, argument_list; 219, if_statement; 219, 220; 219, 221; 220, identifier:verbose; 221, block; 221, 222; 221, 231; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 229; 224, attribute; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:sys; 227, identifier:stderr; 228, identifier:write; 229, argument_list; 229, 230; 230, string:"r"; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 238; 233, attribute; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:sys; 236, identifier:stderr; 237, identifier:flush; 238, argument_list; 239, else_clause; 239, 240; 240, block; 240, 241; 241, if_statement; 241, 242; 241, 243; 242, identifier:verbose; 243, block; 243, 244; 243, 253; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 251; 246, attribute; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:sys; 249, identifier:stderr; 250, identifier:write; 251, argument_list; 251, 252; 252, string:"."; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:sys; 258, identifier:stderr; 259, identifier:flush; 260, argument_list; 261, if_statement; 261, 262; 261, 263; 262, identifier:verbose; 263, block; 263, 264; 263, 273; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 271; 266, attribute; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:sys; 269, identifier:stderr; 270, identifier:write; 271, argument_list; 271, 272; 272, string:"\n"; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 280; 275, attribute; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:sys; 278, identifier:stderr; 279, identifier:flush; 280, argument_list | def revdocs2reverts(rev_docs, radius=defaults.RADIUS, use_sha1=False,
resort=False, verbose=False):
page_rev_docs = groupby(rev_docs, lambda rd: rd.get('page'))
for page_doc, rev_docs in page_rev_docs:
if verbose:
sys.stderr.write(page_doc.get('title') + ": ")
sys.stderr.flush()
if resort:
if verbose:
sys.stderr.write("(sorting) ")
sys.stderr.flush()
rev_docs = sorted(
rev_docs, key=lambda r: (r.get('timestamp'), r.get('id')))
detector = Detector(radius=radius)
for rev_doc in rev_docs:
if not use_sha1 and 'text' not in rev_doc:
logger.warn("Skipping {0}: 'text' field not found in {0}"
.format(rev_doc['id'], rev_doc))
continue
if use_sha1:
checksum = rev_doc.get('sha1') or DummyChecksum()
elif 'text' in rev_doc:
text_bytes = bytes(rev_doc['text'], 'utf8', 'replace')
checksum = hashlib.sha1(text_bytes).digest()
revert = detector.process(checksum, rev_doc)
if revert:
yield revert.to_json()
if verbose:
sys.stderr.write("r")
sys.stderr.flush()
else:
if verbose:
sys.stderr.write(".")
sys.stderr.flush()
if verbose:
sys.stderr.write("\n")
sys.stderr.flush() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:dsort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:fname; 5, identifier:order; 6, default_parameter; 6, 7; 6, 8; 7, identifier:has_header; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:frow; 11, integer:0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:ofname; 14, None; 15, block; 15, 16; 15, 18; 15, 27; 15, 42; 15, 49; 16, expression_statement; 16, 17; 17, identifier:r; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:ofname; 21, conditional_expression:if; 21, 22; 21, 23; 21, 26; 22, identifier:fname; 23, comparison_operator:is; 23, 24; 23, 25; 24, identifier:ofname; 25, None; 26, identifier:ofname; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:obj; 30, call; 30, 31; 30, 32; 31, identifier:CsvFile; 32, argument_list; 32, 33; 32, 36; 32, 39; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:fname; 35, identifier:fname; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:has_header; 38, identifier:has_header; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:frow; 41, identifier:frow; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:obj; 46, identifier:dsort; 47, argument_list; 47, 48; 48, identifier:order; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:obj; 53, identifier:write; 54, argument_list; 54, 55; 54, 58; 54, 61; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:fname; 57, identifier:ofname; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:header; 60, identifier:has_header; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:append; 63, False | def dsort(fname, order, has_header=True, frow=0, ofname=None):
r
ofname = fname if ofname is None else ofname
obj = CsvFile(fname=fname, has_header=has_header, frow=frow)
obj.dsort(order)
obj.write(fname=ofname, header=has_header, append=False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:dsort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:order; 6, block; 6, 7; 6, 9; 6, 21; 6, 40; 6, 60; 6, 64; 6, 111; 7, expression_statement; 7, 8; 8, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:order; 12, conditional_expression:if; 12, 13; 12, 14; 12, 19; 13, identifier:order; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:order; 18, identifier:list; 19, list:[order]; 19, 20; 20, identifier:order; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:norder; 24, list_comprehension; 24, 25; 24, 37; 25, conditional_expression:if; 25, 26; 25, 30; 25, 36; 26, dictionary; 26, 27; 27, pair; 27, 28; 27, 29; 28, identifier:item; 29, string:"A"; 30, not_operator; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:isinstance; 33, argument_list; 33, 34; 33, 35; 34, identifier:item; 35, identifier:dict; 36, identifier:item; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:item; 39, identifier:order; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:_in_header; 45, argument_list; 45, 46; 46, list_comprehension; 46, 47; 46, 57; 47, subscript; 47, 48; 47, 56; 48, call; 48, 49; 48, 50; 49, identifier:list; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:item; 54, identifier:keys; 55, argument_list; 56, integer:0; 57, for_in_clause; 57, 58; 57, 59; 58, identifier:item; 59, identifier:norder; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:clist; 63, list:[]; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:nitem; 66, identifier:norder; 67, block; 67, 68; 68, for_statement; 68, 69; 68, 72; 68, 77; 69, pattern_list; 69, 70; 69, 71; 70, identifier:key; 71, identifier:value; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:nitem; 75, identifier:items; 76, argument_list; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:clist; 82, identifier:append; 83, argument_list; 83, 84; 84, tuple; 84, 85; 84, 104; 85, conditional_expression:if; 85, 86; 85, 87; 85, 92; 86, identifier:key; 87, call; 87, 88; 87, 89; 88, identifier:isinstance; 89, argument_list; 89, 90; 89, 91; 90, identifier:key; 91, identifier:int; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_header_upper; 97, identifier:index; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:key; 102, identifier:upper; 103, argument_list; 104, comparison_operator:==; 104, 105; 104, 110; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:value; 108, identifier:upper; 109, argument_list; 110, string:"D"; 111, for_statement; 111, 112; 111, 115; 111, 119; 112, tuple_pattern; 112, 113; 112, 114; 113, identifier:cindex; 114, identifier:rvalue; 115, call; 115, 116; 115, 117; 116, identifier:reversed; 117, argument_list; 117, 118; 118, identifier:clist; 119, block; 119, 120; 119, 129; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:fpointer; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:operator; 126, identifier:itemgetter; 127, argument_list; 127, 128; 128, identifier:cindex; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:_data; 135, identifier:sort; 136, argument_list; 136, 137; 136, 140; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:key; 139, identifier:fpointer; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:reverse; 142, identifier:rvalue | def dsort(self, order):
r
order = order if isinstance(order, list) else [order]
norder = [{item: "A"} if not isinstance(item, dict) else item for item in order]
self._in_header([list(item.keys())[0] for item in norder])
clist = []
for nitem in norder:
for key, value in nitem.items():
clist.append(
(
key
if isinstance(key, int)
else self._header_upper.index(key.upper()),
value.upper() == "D",
)
)
for (cindex, rvalue) in reversed(clist):
fpointer = operator.itemgetter(cindex)
self._data.sort(key=fpointer, reverse=rvalue) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:get_points_and_weights; 3, parameters; 3, 4; 3, 17; 3, 21; 3, 24; 3, 27; 4, default_parameter; 4, 5; 4, 6; 5, identifier:w_func; 6, lambda; 6, 7; 6, 9; 7, lambda_parameters; 7, 8; 8, identifier:x; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:np; 12, identifier:ones; 13, argument_list; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:x; 16, identifier:shape; 17, default_parameter; 17, 18; 17, 19; 18, identifier:left; 19, unary_operator:-; 19, 20; 20, float:1.0; 21, default_parameter; 21, 22; 21, 23; 22, identifier:right; 23, float:1.0; 24, default_parameter; 24, 25; 24, 26; 25, identifier:num_points; 26, integer:5; 27, default_parameter; 27, 28; 27, 29; 28, identifier:n; 29, integer:4096; 30, block; 30, 31; 30, 43; 30, 67; 30, 76; 30, 87; 30, 91; 30, 100; 30, 109; 30, 122; 30, 134; 30, 147; 30, 155; 30, 161; 30, 177; 30, 183; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:dx; 34, binary_operator:/; 34, 35; 34, 42; 35, parenthesized_expression; 35, 36; 36, binary_operator:-; 36, 37; 36, 41; 37, call; 37, 38; 37, 39; 38, identifier:float; 39, argument_list; 39, 40; 40, identifier:right; 41, identifier:left; 42, identifier:n; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:z; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:np; 49, identifier:hstack; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:np; 54, identifier:linspace; 55, argument_list; 55, 56; 55, 61; 55, 66; 56, binary_operator:+; 56, 57; 56, 58; 57, identifier:left; 58, binary_operator:*; 58, 59; 58, 60; 59, float:0.5; 60, identifier:dx; 61, binary_operator:-; 61, 62; 61, 63; 62, identifier:right; 63, binary_operator:*; 63, 64; 63, 65; 64, float:0.5; 65, identifier:dx; 66, identifier:n; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:w; 70, binary_operator:*; 70, 71; 70, 72; 71, identifier:dx; 72, call; 72, 73; 72, 74; 73, identifier:w_func; 74, argument_list; 74, 75; 75, identifier:z; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, tuple_pattern; 78, 79; 78, 80; 79, identifier:a; 80, identifier:b; 81, call; 81, 82; 81, 83; 82, identifier:discrete_gautschi; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, identifier:z; 85, identifier:w; 86, identifier:num_points; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:alpha; 90, identifier:a; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:beta; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:np; 97, identifier:sqrt; 98, argument_list; 98, 99; 99, identifier:b; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:J; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:diag; 107, argument_list; 107, 108; 108, identifier:alpha; 109, expression_statement; 109, 110; 110, augmented_assignment:+=; 110, 111; 110, 112; 111, identifier:J; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:np; 115, identifier:diag; 116, argument_list; 116, 117; 116, 118; 117, identifier:beta; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:k; 120, unary_operator:-; 120, 121; 121, integer:1; 122, expression_statement; 122, 123; 123, augmented_assignment:+=; 123, 124; 123, 125; 124, identifier:J; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:np; 128, identifier:diag; 129, argument_list; 129, 130; 129, 131; 130, identifier:beta; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:k; 133, integer:1; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, tuple_pattern; 136, 137; 136, 138; 137, identifier:points; 138, identifier:v; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:np; 143, identifier:linalg; 144, identifier:eigh; 145, argument_list; 145, 146; 146, identifier:J; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:ind; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:points; 153, identifier:argsort; 154, argument_list; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:points; 158, subscript; 158, 159; 158, 160; 159, identifier:points; 160, identifier:ind; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:weights; 164, binary_operator:*; 164, 165; 164, 172; 165, binary_operator:**; 165, 166; 165, 171; 166, subscript; 166, 167; 166, 168; 166, 169; 167, identifier:v; 168, integer:0; 169, slice; 169, 170; 170, colon; 171, integer:2; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:w; 175, identifier:sum; 176, argument_list; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:weights; 180, subscript; 180, 181; 180, 182; 181, identifier:weights; 182, identifier:ind; 183, return_statement; 183, 184; 184, tuple; 184, 185; 184, 186; 185, identifier:points; 186, identifier:weights | def get_points_and_weights(w_func=lambda x : np.ones(x.shape),
left=-1.0, right=1.0, num_points=5, n=4096):
dx = (float(right)-left)/n
z = np.hstack(np.linspace(left+0.5*dx, right-0.5*dx, n))
w = dx*w_func(z)
(a, b) = discrete_gautschi(z, w, num_points)
alpha = a
beta = np.sqrt(b)
J = np.diag(alpha)
J += np.diag(beta, k=-1)
J += np.diag(beta, k=1)
(points,v) = np.linalg.eigh(J)
ind = points.argsort()
points = points[ind]
weights = v[0,:]**2 * w.sum()
weights = weights[ind]
return (points, weights) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:apply_to; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:x; 6, default_parameter; 6, 7; 6, 8; 7, identifier:columns; 8, False; 9, block; 9, 10; 9, 51; 10, if_statement; 10, 11; 10, 37; 11, boolean_operator:and; 11, 12; 11, 36; 12, boolean_operator:and; 12, 13; 12, 29; 13, boolean_operator:and; 13, 14; 13, 21; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:x; 18, attribute; 18, 19; 18, 20; 19, identifier:np; 20, identifier:ndarray; 21, comparison_operator:==; 21, 22; 21, 28; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:x; 27, identifier:shape; 28, integer:2; 29, comparison_operator:==; 29, 30; 29, 35; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:x; 33, identifier:shape; 34, integer:0; 35, integer:3; 36, identifier:columns; 37, block; 37, 38; 38, return_statement; 38, 39; 39, binary_operator:+; 39, 40; 39, 41; 40, identifier:x; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:t; 46, identifier:reshape; 47, argument_list; 47, 48; 48, tuple; 48, 49; 48, 50; 49, integer:3; 50, integer:1; 51, if_statement; 51, 52; 51, 88; 51, 95; 51, 116; 51, 134; 51, 151; 51, 160; 52, boolean_operator:and; 52, 53; 52, 86; 53, boolean_operator:and; 53, 54; 53, 61; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:x; 58, attribute; 58, 59; 58, 60; 59, identifier:np; 60, identifier:ndarray; 61, parenthesized_expression; 61, 62; 62, boolean_operator:or; 62, 63; 62, 69; 63, comparison_operator:==; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:x; 66, identifier:shape; 67, tuple; 67, 68; 68, integer:3; 69, parenthesized_expression; 69, 70; 70, boolean_operator:and; 70, 71; 70, 79; 71, comparison_operator:==; 71, 72; 71, 78; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:x; 77, identifier:shape; 78, integer:2; 79, comparison_operator:==; 79, 80; 79, 85; 80, subscript; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:x; 83, identifier:shape; 84, integer:1; 85, integer:3; 86, not_operator; 86, 87; 87, identifier:columns; 88, block; 88, 89; 89, return_statement; 89, 90; 90, binary_operator:+; 90, 91; 90, 92; 91, identifier:x; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:t; 95, elif_clause; 95, 96; 95, 101; 96, call; 96, 97; 96, 98; 97, identifier:isinstance; 98, argument_list; 98, 99; 98, 100; 99, identifier:x; 100, identifier:Complete; 101, block; 101, 102; 102, return_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:Complete; 105, argument_list; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:x; 108, identifier:r; 109, binary_operator:+; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:x; 112, identifier:t; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:t; 116, elif_clause; 116, 117; 116, 122; 117, call; 117, 118; 117, 119; 118, identifier:isinstance; 119, argument_list; 119, 120; 119, 121; 120, identifier:x; 121, identifier:Translation; 122, block; 122, 123; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:Translation; 126, argument_list; 126, 127; 127, binary_operator:+; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:x; 130, identifier:t; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:t; 134, elif_clause; 134, 135; 134, 140; 135, call; 135, 136; 135, 137; 136, identifier:isinstance; 137, argument_list; 137, 138; 137, 139; 138, identifier:x; 139, identifier:Rotation; 140, block; 140, 141; 141, return_statement; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:Complete; 144, argument_list; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:x; 147, identifier:r; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:t; 151, elif_clause; 151, 152; 151, 157; 152, call; 152, 153; 152, 154; 153, identifier:isinstance; 154, argument_list; 154, 155; 154, 156; 155, identifier:x; 156, identifier:UnitCell; 157, block; 157, 158; 158, return_statement; 158, 159; 159, identifier:x; 160, else_clause; 160, 161; 161, block; 161, 162; 162, raise_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:ValueError; 165, argument_list; 165, 166; 166, binary_operator:%; 166, 167; 166, 168; 167, string:"Can not apply this translation to %s"; 168, identifier:x | def apply_to(self, x, columns=False):
if isinstance(x, np.ndarray) and len(x.shape) == 2 and x.shape[0] == 3 and columns:
return x + self.t.reshape((3,1))
if isinstance(x, np.ndarray) and (x.shape == (3, ) or (len(x.shape) == 2 and x.shape[1] == 3)) and not columns:
return x + self.t
elif isinstance(x, Complete):
return Complete(x.r, x.t + self.t)
elif isinstance(x, Translation):
return Translation(x.t + self.t)
elif isinstance(x, Rotation):
return Complete(x.r, self.t)
elif isinstance(x, UnitCell):
return x
else:
raise ValueError("Can not apply this translation to %s" % x) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:apply_to; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:x; 6, default_parameter; 6, 7; 6, 8; 7, identifier:columns; 8, False; 9, block; 9, 10; 9, 48; 10, if_statement; 10, 11; 10, 37; 11, boolean_operator:and; 11, 12; 11, 36; 12, boolean_operator:and; 12, 13; 12, 29; 13, boolean_operator:and; 13, 14; 13, 21; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:x; 18, attribute; 18, 19; 18, 20; 19, identifier:np; 20, identifier:ndarray; 21, comparison_operator:==; 21, 22; 21, 28; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:x; 27, identifier:shape; 28, integer:2; 29, comparison_operator:==; 29, 30; 29, 35; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:x; 33, identifier:shape; 34, integer:0; 35, integer:3; 36, identifier:columns; 37, block; 37, 38; 38, return_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:np; 42, identifier:dot; 43, argument_list; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:r; 47, identifier:x; 48, if_statement; 48, 49; 48, 85; 48, 100; 48, 133; 48, 158; 48, 180; 48, 205; 49, boolean_operator:and; 49, 50; 49, 83; 50, boolean_operator:and; 50, 51; 50, 58; 51, call; 51, 52; 51, 53; 52, identifier:isinstance; 53, argument_list; 53, 54; 53, 55; 54, identifier:x; 55, attribute; 55, 56; 55, 57; 56, identifier:np; 57, identifier:ndarray; 58, parenthesized_expression; 58, 59; 59, boolean_operator:or; 59, 60; 59, 66; 60, comparison_operator:==; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:x; 63, identifier:shape; 64, tuple; 64, 65; 65, integer:3; 66, parenthesized_expression; 66, 67; 67, boolean_operator:and; 67, 68; 67, 76; 68, comparison_operator:==; 68, 69; 68, 75; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, attribute; 72, 73; 72, 74; 73, identifier:x; 74, identifier:shape; 75, integer:2; 76, comparison_operator:==; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:x; 80, identifier:shape; 81, integer:1; 82, integer:3; 83, not_operator; 83, 84; 84, identifier:columns; 85, block; 85, 86; 86, return_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:np; 90, identifier:dot; 91, argument_list; 91, 92; 91, 93; 92, identifier:x; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:r; 98, identifier:transpose; 99, argument_list; 100, elif_clause; 100, 101; 100, 106; 101, call; 101, 102; 101, 103; 102, identifier:isinstance; 103, argument_list; 103, 104; 103, 105; 104, identifier:x; 105, identifier:Complete; 106, block; 106, 107; 107, return_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:Complete; 110, argument_list; 110, 111; 110, 122; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:np; 114, identifier:dot; 115, argument_list; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:r; 119, attribute; 119, 120; 119, 121; 120, identifier:x; 121, identifier:r; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:np; 125, identifier:dot; 126, argument_list; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:r; 130, attribute; 130, 131; 130, 132; 131, identifier:x; 132, identifier:t; 133, elif_clause; 133, 134; 133, 139; 134, call; 134, 135; 134, 136; 135, identifier:isinstance; 136, argument_list; 136, 137; 136, 138; 137, identifier:x; 138, identifier:Translation; 139, block; 139, 140; 140, return_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:Complete; 143, argument_list; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:r; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:np; 150, identifier:dot; 151, argument_list; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:r; 155, attribute; 155, 156; 155, 157; 156, identifier:x; 157, identifier:t; 158, elif_clause; 158, 159; 158, 164; 159, call; 159, 160; 159, 161; 160, identifier:isinstance; 161, argument_list; 161, 162; 161, 163; 162, identifier:x; 163, identifier:Rotation; 164, block; 164, 165; 165, return_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:Rotation; 168, argument_list; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:np; 172, identifier:dot; 173, argument_list; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:r; 177, attribute; 177, 178; 177, 179; 178, identifier:x; 179, identifier:r; 180, elif_clause; 180, 181; 180, 186; 181, call; 181, 182; 181, 183; 182, identifier:isinstance; 183, argument_list; 183, 184; 183, 185; 184, identifier:x; 185, identifier:UnitCell; 186, block; 186, 187; 187, return_statement; 187, 188; 188, call; 188, 189; 188, 190; 189, identifier:UnitCell; 190, argument_list; 190, 191; 190, 202; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:np; 194, identifier:dot; 195, argument_list; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:r; 199, attribute; 199, 200; 199, 201; 200, identifier:x; 201, identifier:matrix; 202, attribute; 202, 203; 202, 204; 203, identifier:x; 204, identifier:active; 205, else_clause; 205, 206; 206, block; 206, 207; 207, raise_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:ValueError; 210, argument_list; 210, 211; 211, binary_operator:%; 211, 212; 211, 213; 212, string:"Can not apply this rotation to %s"; 213, identifier:x | def apply_to(self, x, columns=False):
if isinstance(x, np.ndarray) and len(x.shape) == 2 and x.shape[0] == 3 and columns:
return np.dot(self.r, x)
if isinstance(x, np.ndarray) and (x.shape == (3, ) or (len(x.shape) == 2 and x.shape[1] == 3)) and not columns:
return np.dot(x, self.r.transpose())
elif isinstance(x, Complete):
return Complete(np.dot(self.r, x.r), np.dot(self.r, x.t))
elif isinstance(x, Translation):
return Complete(self.r, np.dot(self.r, x.t))
elif isinstance(x, Rotation):
return Rotation(np.dot(self.r, x.r))
elif isinstance(x, UnitCell):
return UnitCell(np.dot(self.r, x.matrix), x.active)
else:
raise ValueError("Can not apply this rotation to %s" % x) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:canonical_order; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 46; 5, 99; 5, 108; 5, 142; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:starting_vertex; 9, subscript; 9, 10; 9, 44; 10, call; 10, 11; 10, 12; 11, identifier:max; 12, generator_expression; 12, 13; 12, 39; 13, tuple; 13, 14; 13, 23; 13, 29; 13, 38; 14, unary_operator:-; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:len; 17, argument_list; 17, 18; 18, subscript; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:equivalent_vertices; 22, identifier:vertex; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:get_vertex_string; 27, argument_list; 27, 28; 28, identifier:vertex; 29, call; 29, 30; 29, 37; 30, attribute; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:vertex_fingerprints; 35, identifier:vertex; 36, identifier:tobytes; 37, argument_list; 38, identifier:vertex; 39, for_in_clause; 39, 40; 39, 41; 40, identifier:vertex; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:central_vertices; 44, unary_operator:-; 44, 45; 45, integer:1; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:l; 49, list_comprehension; 49, 50; 49, 78; 49, 88; 50, list:[
-distance,
-len(self.equivalent_vertices[vertex]),
self.get_vertex_string(vertex),
self.vertex_fingerprints[vertex].tobytes(),
vertex
]; 50, 51; 50, 53; 50, 62; 50, 68; 50, 77; 51, unary_operator:-; 51, 52; 52, identifier:distance; 53, unary_operator:-; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:len; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:equivalent_vertices; 61, identifier:vertex; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:get_vertex_string; 66, argument_list; 66, 67; 67, identifier:vertex; 68, call; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:vertex_fingerprints; 74, identifier:vertex; 75, identifier:tobytes; 76, argument_list; 77, identifier:vertex; 78, for_in_clause; 78, 79; 78, 82; 79, pattern_list; 79, 80; 79, 81; 80, identifier:vertex; 81, identifier:distance; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:iter_breadth_first; 86, argument_list; 86, 87; 87, identifier:starting_vertex; 88, if_clause; 88, 89; 89, comparison_operator:>; 89, 90; 89, 98; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, subscript; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:neighbors; 97, identifier:vertex; 98, integer:0; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:l; 103, identifier:sort; 104, argument_list; 104, 105; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:reverse; 107, True; 108, for_statement; 108, 109; 108, 110; 108, 118; 109, identifier:i; 110, call; 110, 111; 110, 112; 111, identifier:range; 112, argument_list; 112, 113; 112, 114; 113, integer:1; 114, call; 114, 115; 114, 116; 115, identifier:len; 116, argument_list; 116, 117; 117, identifier:l; 118, block; 118, 119; 119, if_statement; 119, 120; 119, 139; 120, comparison_operator:==; 120, 121; 120, 129; 121, subscript; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:l; 124, identifier:i; 125, slice; 125, 126; 125, 127; 126, colon; 127, unary_operator:-; 127, 128; 128, integer:1; 129, subscript; 129, 130; 129, 135; 130, subscript; 130, 131; 130, 132; 131, identifier:l; 132, binary_operator:-; 132, 133; 132, 134; 133, identifier:i; 134, integer:1; 135, slice; 135, 136; 135, 137; 136, colon; 137, unary_operator:-; 137, 138; 138, integer:1; 139, block; 139, 140; 140, raise_statement; 140, 141; 141, identifier:NotImplementedError; 142, return_statement; 142, 143; 143, list_comprehension; 143, 144; 143, 148; 144, subscript; 144, 145; 144, 146; 145, identifier:record; 146, unary_operator:-; 146, 147; 147, integer:1; 148, for_in_clause; 148, 149; 148, 150; 149, identifier:record; 150, identifier:l | def canonical_order(self):
starting_vertex = max(
(
-len(self.equivalent_vertices[vertex]),
self.get_vertex_string(vertex),
self.vertex_fingerprints[vertex].tobytes(),
vertex
) for vertex in self.central_vertices
)[-1]
l = [
[
-distance,
-len(self.equivalent_vertices[vertex]),
self.get_vertex_string(vertex),
self.vertex_fingerprints[vertex].tobytes(),
vertex
] for vertex, distance in self.iter_breadth_first(starting_vertex)
if len(self.neighbors[vertex]) > 0
]
l.sort(reverse=True)
for i in range(1, len(l)):
if l[i][:-1] == l[i-1][:-1]:
raise NotImplementedError
return [record[-1] for record in l] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_subgraph; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:subvertices; 6, default_parameter; 6, 7; 6, 8; 7, identifier:normalize; 8, False; 9, block; 9, 10; 9, 261; 10, if_statement; 10, 11; 10, 12; 10, 192; 11, identifier:normalize; 12, block; 12, 13; 12, 30; 12, 34; 12, 38; 12, 97; 12, 110; 12, 131; 12, 141; 12, 151; 12, 164; 12, 178; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:revorder; 16, call; 16, 17; 16, 18; 17, identifier:dict; 18, generator_expression; 18, 19; 18, 22; 19, tuple; 19, 20; 19, 21; 20, identifier:j; 21, identifier:i; 22, for_in_clause; 22, 23; 22, 26; 23, pattern_list; 23, 24; 23, 25; 24, identifier:i; 25, identifier:j; 26, call; 26, 27; 26, 28; 27, identifier:enumerate; 28, argument_list; 28, 29; 29, identifier:subvertices; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:new_edges; 33, list:[]; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:old_edge_indexes; 37, list:[]; 38, for_statement; 38, 39; 38, 44; 38, 50; 39, pattern_list; 39, 40; 39, 41; 40, identifier:counter; 41, tuple_pattern; 41, 42; 41, 43; 42, identifier:i; 43, identifier:j; 44, call; 44, 45; 44, 46; 45, identifier:enumerate; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:edges; 50, block; 50, 51; 50, 60; 50, 66; 50, 75; 50, 81; 50, 90; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:new_i; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:revorder; 57, identifier:get; 58, argument_list; 58, 59; 59, identifier:i; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:new_i; 63, None; 64, block; 64, 65; 65, continue_statement; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:new_j; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:revorder; 72, identifier:get; 73, argument_list; 73, 74; 74, identifier:j; 75, if_statement; 75, 76; 75, 79; 76, comparison_operator:is; 76, 77; 76, 78; 77, identifier:new_j; 78, None; 79, block; 79, 80; 80, continue_statement; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:new_edges; 85, identifier:append; 86, argument_list; 86, 87; 87, tuple; 87, 88; 87, 89; 88, identifier:new_i; 89, identifier:new_j; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:old_edge_indexes; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:counter; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:order; 100, call; 100, 101; 100, 102; 101, identifier:list; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:range; 105, argument_list; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:len; 108, argument_list; 108, 109; 109, identifier:new_edges; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:order; 114, identifier:sort; 115, argument_list; 115, 116; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:key; 118, parenthesized_expression; 118, 119; 119, lambda; 119, 120; 119, 122; 120, lambda_parameters; 120, 121; 121, identifier:i; 122, call; 122, 123; 122, 124; 123, identifier:tuple; 124, argument_list; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:sorted; 127, argument_list; 127, 128; 128, subscript; 128, 129; 128, 130; 129, identifier:new_edges; 130, identifier:i; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:new_edges; 134, list_comprehension; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:new_edges; 137, identifier:i; 138, for_in_clause; 138, 139; 138, 140; 139, identifier:i; 140, identifier:order; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:old_edge_indexes; 144, list_comprehension; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:old_edge_indexes; 147, identifier:i; 148, for_in_clause; 148, 149; 148, 150; 149, identifier:i; 150, identifier:order; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:result; 154, call; 154, 155; 154, 156; 155, identifier:Graph; 156, argument_list; 156, 157; 156, 158; 157, identifier:new_edges; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:num_vertices; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:subvertices; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:result; 168, identifier:_old_vertex_indexes; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:np; 172, identifier:array; 173, argument_list; 173, 174; 173, 175; 174, identifier:subvertices; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:dtype; 177, identifier:int; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:result; 182, identifier:_old_edge_indexes; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:np; 186, identifier:array; 187, argument_list; 187, 188; 187, 189; 188, identifier:old_edge_indexes; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:dtype; 191, identifier:int; 192, else_clause; 192, 193; 193, block; 193, 194; 193, 201; 193, 231; 193, 245; 193, 255; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:subvertices; 197, call; 197, 198; 197, 199; 198, identifier:set; 199, argument_list; 199, 200; 200, identifier:subvertices; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:old_edge_indexes; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:np; 207, identifier:array; 208, argument_list; 208, 209; 208, 228; 209, list_comprehension; 209, 210; 209, 211; 209, 221; 210, identifier:i; 211, for_in_clause; 211, 212; 211, 215; 212, pattern_list; 212, 213; 212, 214; 213, identifier:i; 214, identifier:edge; 215, call; 215, 216; 215, 217; 216, identifier:enumerate; 217, argument_list; 217, 218; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:edges; 221, if_clause; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:edge; 225, identifier:issubset; 226, argument_list; 226, 227; 227, identifier:subvertices; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:dtype; 230, identifier:int; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:new_edges; 234, call; 234, 235; 234, 236; 235, identifier:tuple; 236, generator_expression; 236, 237; 236, 242; 237, subscript; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:edges; 241, identifier:i; 242, for_in_clause; 242, 243; 242, 244; 243, identifier:i; 244, identifier:old_edge_indexes; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:result; 248, call; 248, 249; 248, 250; 249, identifier:Graph; 250, argument_list; 250, 251; 250, 252; 251, identifier:new_edges; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:num_vertices; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:result; 259, identifier:_old_edge_indexes; 260, identifier:old_edge_indexes; 261, return_statement; 261, 262; 262, identifier:result | def get_subgraph(self, subvertices, normalize=False):
if normalize:
revorder = dict((j, i) for i, j in enumerate(subvertices))
new_edges = []
old_edge_indexes = []
for counter, (i, j) in enumerate(self.edges):
new_i = revorder.get(i)
if new_i is None:
continue
new_j = revorder.get(j)
if new_j is None:
continue
new_edges.append((new_i, new_j))
old_edge_indexes.append(counter)
order = list(range(len(new_edges)))
order.sort( key=(lambda i: tuple(sorted(new_edges[i]))) )
new_edges = [new_edges[i] for i in order]
old_edge_indexes = [old_edge_indexes[i] for i in order]
result = Graph(new_edges, num_vertices=len(subvertices))
result._old_vertex_indexes = np.array(subvertices, dtype=int)
result._old_edge_indexes = np.array(old_edge_indexes, dtype=int)
else:
subvertices = set(subvertices)
old_edge_indexes = np.array([
i for i, edge in enumerate(self.edges)
if edge.issubset(subvertices)
], dtype=int)
new_edges = tuple(self.edges[i] for i in old_edge_indexes)
result = Graph(new_edges, self.num_vertices)
result._old_edge_indexes = old_edge_indexes
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_closed_cycles; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 23; 5, 44; 5, 48; 5, 154; 5, 160; 5, 173; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:closed_cycles; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:todo; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:forward; 21, identifier:keys; 22, argument_list; 23, if_statement; 23, 24; 23, 36; 24, comparison_operator:!=; 24, 25; 24, 26; 25, identifier:todo; 26, call; 26, 27; 26, 28; 27, identifier:set; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:forward; 34, identifier:values; 35, argument_list; 36, block; 36, 37; 37, raise_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:GraphError; 40, argument_list; 40, 41; 41, concatenated_string; 41, 42; 41, 43; 42, string:"The subject and pattern graph must have the same "; 43, string:"numbering."; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:current_vertex; 47, None; 48, while_statement; 48, 49; 48, 55; 49, comparison_operator:>; 49, 50; 49, 54; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:todo; 54, integer:0; 55, block; 55, 56; 55, 82; 55, 89; 55, 98; 56, if_statement; 56, 57; 56, 60; 56, 73; 57, comparison_operator:==; 57, 58; 57, 59; 58, identifier:current_vertex; 59, None; 60, block; 60, 61; 60, 69; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:current_vertex; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:todo; 67, identifier:pop; 68, argument_list; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:current_cycle; 72, list:[]; 73, else_clause; 73, 74; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:todo; 79, identifier:discard; 80, argument_list; 80, 81; 81, identifier:current_vertex; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:current_cycle; 86, identifier:append; 87, argument_list; 87, 88; 88, identifier:current_vertex; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:next_vertex; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:get_destination; 96, argument_list; 96, 97; 97, identifier:current_vertex; 98, if_statement; 98, 99; 98, 104; 98, 148; 99, comparison_operator:==; 99, 100; 99, 101; 100, identifier:next_vertex; 101, subscript; 101, 102; 101, 103; 102, identifier:current_cycle; 103, integer:0; 104, block; 104, 105; 104, 144; 105, if_statement; 105, 106; 105, 112; 106, comparison_operator:>; 106, 107; 106, 111; 107, call; 107, 108; 107, 109; 108, identifier:len; 109, argument_list; 109, 110; 110, identifier:current_cycle; 111, integer:1; 112, block; 112, 113; 112, 122; 112, 137; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:pivot; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:np; 119, identifier:argmin; 120, argument_list; 120, 121; 121, identifier:current_cycle; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:current_cycle; 125, binary_operator:+; 125, 126; 125, 131; 125, 132; 126, subscript; 126, 127; 126, 128; 127, identifier:current_cycle; 128, slice; 128, 129; 128, 130; 129, identifier:pivot; 130, colon; 131, line_continuation:\; 132, subscript; 132, 133; 132, 134; 133, identifier:current_cycle; 134, slice; 134, 135; 134, 136; 135, colon; 136, identifier:pivot; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:closed_cycles; 141, identifier:append; 142, argument_list; 142, 143; 143, identifier:current_cycle; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:current_vertex; 147, None; 148, else_clause; 148, 149; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:current_vertex; 153, identifier:next_vertex; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:closed_cycles; 158, identifier:sort; 159, argument_list; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:closed_cycles; 163, call; 163, 164; 163, 165; 164, identifier:tuple; 165, generator_expression; 165, 166; 165, 170; 166, call; 166, 167; 166, 168; 167, identifier:tuple; 168, argument_list; 168, 169; 169, identifier:cycle; 170, for_in_clause; 170, 171; 170, 172; 171, identifier:cycle; 172, identifier:closed_cycles; 173, return_statement; 173, 174; 174, identifier:closed_cycles | def get_closed_cycles(self):
closed_cycles = []
todo = set(self.forward.keys())
if todo != set(self.forward.values()):
raise GraphError("The subject and pattern graph must have the same "
"numbering.")
current_vertex = None
while len(todo) > 0:
if current_vertex == None:
current_vertex = todo.pop()
current_cycle = []
else:
todo.discard(current_vertex)
current_cycle.append(current_vertex)
next_vertex = self.get_destination(current_vertex)
if next_vertex == current_cycle[0]:
if len(current_cycle) > 1:
pivot = np.argmin(current_cycle)
current_cycle = current_cycle[pivot:] + \
current_cycle[:pivot]
closed_cycles.append(current_cycle)
current_vertex = None
else:
current_vertex = next_vertex
closed_cycles.sort()
closed_cycles = tuple(tuple(cycle) for cycle in closed_cycles)
return closed_cycles |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted_exists; 3, parameters; 3, 4; 3, 5; 4, identifier:values; 5, identifier:x; 6, block; 6, 7; 6, 15; 6, 23; 6, 34; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:i; 10, call; 10, 11; 10, 12; 11, identifier:bisect_left; 12, argument_list; 12, 13; 12, 14; 13, identifier:values; 14, identifier:x; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:j; 18, call; 18, 19; 18, 20; 19, identifier:bisect_right; 20, argument_list; 20, 21; 20, 22; 21, identifier:values; 22, identifier:x; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:exists; 26, comparison_operator:in; 26, 27; 26, 28; 27, identifier:x; 28, subscript; 28, 29; 28, 30; 29, identifier:values; 30, slice; 30, 31; 30, 32; 30, 33; 31, identifier:i; 32, colon; 33, identifier:j; 34, return_statement; 34, 35; 35, expression_list; 35, 36; 35, 37; 36, identifier:exists; 37, identifier:i | def sorted_exists(values, x):
i = bisect_left(values, x)
j = bisect_right(values, x)
exists = x in values[i:j]
return exists, i |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted_index; 3, parameters; 3, 4; 3, 5; 4, identifier:values; 5, identifier:x; 6, block; 6, 7; 6, 15; 6, 23; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:i; 10, call; 10, 11; 10, 12; 11, identifier:bisect_left; 12, argument_list; 12, 13; 12, 14; 13, identifier:values; 14, identifier:x; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:j; 18, call; 18, 19; 18, 20; 19, identifier:bisect_right; 20, argument_list; 20, 21; 20, 22; 21, identifier:values; 22, identifier:x; 23, return_statement; 23, 24; 24, binary_operator:+; 24, 25; 24, 36; 25, call; 25, 26; 25, 34; 26, attribute; 26, 27; 26, 33; 27, subscript; 27, 28; 27, 29; 28, identifier:values; 29, slice; 29, 30; 29, 31; 29, 32; 30, identifier:i; 31, colon; 32, identifier:j; 33, identifier:index; 34, argument_list; 34, 35; 35, identifier:x; 36, identifier:i | def sorted_index(values, x):
i = bisect_left(values, x)
j = bisect_right(values, x)
return values[i:j].index(x) + i |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_index; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 15; 5, 45; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sort; 9, call; 9, 10; 9, 11; 10, identifier:sorted_list_indexes; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_index; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_index; 20, conditional_expression:if; 20, 21; 20, 33; 20, 36; 21, call; 21, 22; 21, 23; 22, identifier:blist; 23, argument_list; 23, 24; 24, list_comprehension; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_index; 29, identifier:x; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:x; 32, identifier:sort; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_blist; 36, list_comprehension; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_index; 41, identifier:x; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:x; 44, identifier:sort; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_data; 50, conditional_expression:if; 50, 51; 50, 63; 50, 66; 51, call; 51, 52; 51, 53; 52, identifier:blist; 53, argument_list; 53, 54; 54, list_comprehension; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_data; 59, identifier:x; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:x; 62, identifier:sort; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_blist; 66, list_comprehension; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_data; 71, identifier:x; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:x; 74, identifier:sort | def sort_index(self):
sort = sorted_list_indexes(self._index)
self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
self._data = blist([self._data[x] for x in sort]) if self._blist else [self._data[x] for x in sort] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_add_missing_rows; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:indexes; 6, block; 6, 7; 6, 21; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:new_indexes; 10, list_comprehension; 10, 11; 10, 12; 10, 15; 11, identifier:x; 12, for_in_clause; 12, 13; 12, 14; 13, identifier:x; 14, identifier:indexes; 15, if_clause; 15, 16; 16, comparison_operator:not; 16, 17; 16, 18; 17, identifier:x; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_index; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:x; 23, identifier:new_indexes; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_add_row; 30, argument_list; 30, 31; 31, identifier:x | def _add_missing_rows(self, indexes):
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._add_row(x) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_insert_missing_rows; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:indexes; 6, block; 6, 7; 6, 21; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:new_indexes; 10, list_comprehension; 10, 11; 10, 12; 10, 15; 11, identifier:x; 12, for_in_clause; 12, 13; 12, 14; 13, identifier:x; 14, identifier:indexes; 15, if_clause; 15, 16; 16, comparison_operator:not; 16, 17; 16, 18; 17, identifier:x; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_index; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:x; 23, identifier:new_indexes; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_insert_row; 30, argument_list; 30, 31; 30, 38; 31, call; 31, 32; 31, 33; 32, identifier:bisect_left; 33, argument_list; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_index; 37, identifier:x; 38, identifier:x | def _insert_missing_rows(self, indexes):
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._insert_row(bisect_left(self._index, x), x) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:append_row; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:index; 6, identifier:value; 7, block; 7, 8; 7, 20; 7, 29; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:in; 9, 10; 9, 11; 10, identifier:index; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_index; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:IndexError; 18, argument_list; 18, 19; 19, string:'index already in Series'; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_index; 26, identifier:append; 27, argument_list; 27, 28; 28, identifier:index; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_data; 35, identifier:append; 36, argument_list; 36, 37; 37, identifier:value | def append_row(self, index, value):
if index in self._index:
raise IndexError('index already in Series')
self._index.append(index)
self._data.append(value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:append_rows; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:indexes; 6, identifier:values; 7, block; 7, 8; 7, 24; 7, 32; 7, 51; 7, 60; 8, if_statement; 8, 9; 8, 18; 9, comparison_operator:!=; 9, 10; 9, 14; 10, call; 10, 11; 10, 12; 11, identifier:len; 12, argument_list; 12, 13; 13, identifier:values; 14, call; 14, 15; 14, 16; 15, identifier:len; 16, argument_list; 16, 17; 17, identifier:indexes; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:ValueError; 22, argument_list; 22, 23; 23, string:'length of values is not equal to length of indexes'; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:combined_index; 27, binary_operator:+; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_index; 31, identifier:indexes; 32, if_statement; 32, 33; 32, 45; 33, comparison_operator:!=; 33, 34; 33, 41; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:set; 39, argument_list; 39, 40; 40, identifier:combined_index; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:combined_index; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:IndexError; 49, argument_list; 49, 50; 50, string:'duplicate indexes in Series'; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_index; 57, identifier:extend; 58, argument_list; 58, 59; 59, identifier:indexes; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_data; 66, identifier:extend; 67, argument_list; 67, 68; 68, identifier:values | def append_rows(self, indexes, values):
if len(values) != len(indexes):
raise ValueError('length of values is not equal to length of indexes')
combined_index = self._index + indexes
if len(set(combined_index)) != len(combined_index):
raise IndexError('duplicate indexes in Series')
self._index.extend(indexes)
self._data.extend(values) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_sort_columns; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:columns_list; 6, block; 6, 7; 6, 41; 6, 56; 6, 86; 7, if_statement; 7, 8; 7, 35; 8, not_operator; 8, 9; 9, parenthesized_expression; 9, 10; 10, boolean_operator:and; 10, 11; 10, 23; 11, call; 11, 12; 11, 13; 12, identifier:all; 13, argument_list; 13, 14; 14, list_comprehension; 14, 15; 14, 18; 15, comparison_operator:in; 15, 16; 15, 17; 16, identifier:x; 17, identifier:columns_list; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:x; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_columns; 23, call; 23, 24; 23, 25; 24, identifier:all; 25, argument_list; 25, 26; 26, list_comprehension; 26, 27; 26, 32; 27, comparison_operator:in; 27, 28; 27, 29; 28, identifier:x; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_columns; 32, for_in_clause; 32, 33; 32, 34; 33, identifier:x; 34, identifier:columns_list; 35, block; 35, 36; 36, raise_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:ValueError; 39, argument_list; 39, 40; 40, string:'columns_list must be all in current columns, and all current columns must be in columns_list'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:new_sort; 44, list_comprehension; 44, 45; 44, 53; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_columns; 50, identifier:index; 51, argument_list; 51, 52; 52, identifier:x; 53, for_in_clause; 53, 54; 53, 55; 54, identifier:x; 55, identifier:columns_list; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_data; 61, conditional_expression:if; 61, 62; 61, 74; 61, 77; 62, call; 62, 63; 62, 64; 63, identifier:blist; 64, argument_list; 64, 65; 65, list_comprehension; 65, 66; 65, 71; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_data; 70, identifier:x; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:x; 73, identifier:new_sort; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_blist; 77, list_comprehension; 77, 78; 77, 83; 78, subscript; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_data; 82, identifier:x; 83, for_in_clause; 83, 84; 83, 85; 84, identifier:x; 85, identifier:new_sort; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:_columns; 91, conditional_expression:if; 91, 92; 91, 104; 91, 107; 91, 108; 92, call; 92, 93; 92, 94; 93, identifier:blist; 94, argument_list; 94, 95; 95, list_comprehension; 95, 96; 95, 101; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_columns; 100, identifier:x; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:x; 103, identifier:new_sort; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:_blist; 107, line_continuation:\; 108, list_comprehension; 108, 109; 108, 114; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_columns; 113, identifier:x; 114, for_in_clause; 114, 115; 114, 116; 115, identifier:x; 116, identifier:new_sort | def _sort_columns(self, columns_list):
if not (all([x in columns_list for x in self._columns]) and all([x in self._columns for x in columns_list])):
raise ValueError(
'columns_list must be all in current columns, and all current columns must be in columns_list')
new_sort = [self._columns.index(x) for x in columns_list]
self._data = blist([self._data[x] for x in new_sort]) if self._blist else [self._data[x] for x in new_sort]
self._columns = blist([self._columns[x] for x in new_sort]) if self._blist \
else [self._columns[x] for x in new_sort] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:append_row; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:index; 6, identifier:values; 7, default_parameter; 7, 8; 7, 9; 8, identifier:new_cols; 9, True; 10, block; 10, 11; 10, 23; 10, 44; 10, 53; 11, if_statement; 11, 12; 11, 17; 12, comparison_operator:in; 12, 13; 12, 14; 13, identifier:index; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_index; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:IndexError; 21, argument_list; 21, 22; 22, string:'index already in DataFrame'; 23, if_statement; 23, 24; 23, 25; 24, identifier:new_cols; 25, block; 25, 26; 26, for_statement; 26, 27; 26, 28; 26, 29; 27, identifier:col; 28, identifier:values; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 36; 31, comparison_operator:not; 31, 32; 31, 33; 32, identifier:col; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_columns; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_add_column; 42, argument_list; 42, 43; 43, identifier:col; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_index; 50, identifier:append; 51, argument_list; 51, 52; 52, identifier:index; 53, for_statement; 53, 54; 53, 57; 53, 63; 54, pattern_list; 54, 55; 54, 56; 55, identifier:c; 56, identifier:col; 57, call; 57, 58; 57, 59; 58, identifier:enumerate; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_columns; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 73; 66, attribute; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_data; 71, identifier:c; 72, identifier:append; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:values; 77, identifier:get; 78, argument_list; 78, 79; 78, 80; 79, identifier:col; 80, None | def append_row(self, index, values, new_cols=True):
if index in self._index:
raise IndexError('index already in DataFrame')
if new_cols:
for col in values:
if col not in self._columns:
self._add_column(col)
self._index.append(index)
for c, col in enumerate(self._columns):
self._data[c].append(values.get(col, None)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:append_rows; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:indexes; 6, identifier:values; 7, default_parameter; 7, 8; 7, 9; 8, identifier:new_cols; 9, True; 10, block; 10, 11; 10, 35; 10, 43; 10, 62; 10, 83; 10, 92; 10, 126; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:column; 13, identifier:values; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 27; 16, comparison_operator:>; 16, 17; 16, 23; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, subscript; 20, 21; 20, 22; 21, identifier:values; 22, identifier:column; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:indexes; 27, block; 27, 28; 28, raise_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:ValueError; 31, argument_list; 31, 32; 32, binary_operator:%; 32, 33; 32, 34; 33, string:'length of %s column in values is longer than indexes'; 34, identifier:column; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:combined_index; 38, binary_operator:+; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_index; 42, identifier:indexes; 43, if_statement; 43, 44; 43, 56; 44, comparison_operator:!=; 44, 45; 44, 52; 45, call; 45, 46; 45, 47; 46, identifier:len; 47, argument_list; 47, 48; 48, call; 48, 49; 48, 50; 49, identifier:set; 50, argument_list; 50, 51; 51, identifier:combined_index; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:combined_index; 56, block; 56, 57; 57, raise_statement; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:IndexError; 60, argument_list; 60, 61; 61, string:'duplicate indexes in DataFrames'; 62, if_statement; 62, 63; 62, 64; 63, identifier:new_cols; 64, block; 64, 65; 65, for_statement; 65, 66; 65, 67; 65, 68; 66, identifier:col; 67, identifier:values; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 75; 70, comparison_operator:not; 70, 71; 70, 72; 71, identifier:col; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:_columns; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_add_column; 81, argument_list; 81, 82; 82, identifier:col; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_index; 89, identifier:extend; 90, argument_list; 90, 91; 91, identifier:indexes; 92, for_statement; 92, 93; 92, 96; 92, 102; 93, pattern_list; 93, 94; 93, 95; 94, identifier:c; 95, identifier:col; 96, call; 96, 97; 96, 98; 97, identifier:enumerate; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:_columns; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 112; 105, attribute; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_data; 110, identifier:c; 111, identifier:extend; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:values; 116, identifier:get; 117, argument_list; 117, 118; 117, 119; 118, identifier:col; 119, binary_operator:*; 119, 120; 119, 122; 120, list:[None]; 120, 121; 121, None; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:indexes; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:_pad_data; 131, argument_list | def append_rows(self, indexes, values, new_cols=True):
for column in values:
if len(values[column]) > len(indexes):
raise ValueError('length of %s column in values is longer than indexes' % column)
combined_index = self._index + indexes
if len(set(combined_index)) != len(combined_index):
raise IndexError('duplicate indexes in DataFrames')
if new_cols:
for col in values:
if col not in self._columns:
self._add_column(col)
self._index.extend(indexes)
for c, col in enumerate(self._columns):
self._data[c].extend(values.get(col, [None] * len(indexes)))
self._pad_data() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_index; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 15; 5, 45; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sort; 9, call; 9, 10; 9, 11; 10, identifier:sorted_list_indexes; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_index; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_index; 20, conditional_expression:if; 20, 21; 20, 33; 20, 36; 21, call; 21, 22; 21, 23; 22, identifier:blist; 23, argument_list; 23, 24; 24, list_comprehension; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_index; 29, identifier:x; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:x; 32, identifier:sort; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_blist; 36, list_comprehension; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_index; 41, identifier:x; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:x; 44, identifier:sort; 45, for_statement; 45, 46; 45, 47; 45, 56; 46, identifier:c; 47, call; 47, 48; 47, 49; 48, identifier:range; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_data; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 64; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_data; 63, identifier:c; 64, conditional_expression:if; 64, 65; 64, 79; 64, 82; 65, call; 65, 66; 65, 67; 66, identifier:blist; 67, argument_list; 67, 68; 68, list_comprehension; 68, 69; 68, 76; 69, subscript; 69, 70; 69, 75; 70, subscript; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_data; 74, identifier:c; 75, identifier:i; 76, for_in_clause; 76, 77; 76, 78; 77, identifier:i; 78, identifier:sort; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_blist; 82, list_comprehension; 82, 83; 82, 90; 83, subscript; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_data; 88, identifier:c; 89, identifier:i; 90, for_in_clause; 90, 91; 90, 92; 91, identifier:i; 92, identifier:sort | def sort_index(self):
sort = sorted_list_indexes(self._index)
self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
for c in range(len(self._data)):
self._data[c] = blist([self._data[c][i] for i in sort]) if self._blist else [self._data[c][i] for i in sort] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:tags; 3, parameters; 4, block; 4, 5; 5, return_statement; 5, 6; 6, call; 6, 7; 6, 27; 7, attribute; 7, 8; 7, 26; 8, call; 8, 9; 8, 25; 9, attribute; 9, 10; 9, 24; 10, attribute; 10, 11; 10, 23; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:shell; 14, identifier:run; 15, argument_list; 15, 16; 15, 17; 15, 20; 16, string:'git tag --sort=v:refname'; 17, keyword_argument; 17, 18; 17, 19; 18, identifier:capture; 19, True; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:never_pretend; 22, True; 23, identifier:stdout; 24, identifier:strip; 25, argument_list; 26, identifier:splitlines; 27, argument_list | def tags():
return shell.run(
'git tag --sort=v:refname',
capture=True,
never_pretend=True
).stdout.strip().splitlines() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 90; 1, 92; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 15; 3, 20; 3, 25; 3, 30; 3, 35; 3, 40; 3, 45; 3, 50; 3, 55; 3, 60; 3, 65; 3, 70; 3, 75; 3, 80; 3, 85; 4, identifier:self; 5, typed_default_parameter; 5, 6; 5, 7; 5, 9; 6, identifier:token; 7, type; 7, 8; 8, identifier:dict; 9, None; 10, typed_default_parameter; 10, 11; 10, 12; 10, 14; 11, identifier:query; 12, type; 12, 13; 13, identifier:str; 14, string:""; 15, typed_default_parameter; 15, 16; 15, 17; 15, 19; 16, identifier:bbox; 17, type; 17, 18; 18, identifier:list; 19, None; 20, typed_default_parameter; 20, 21; 20, 22; 20, 24; 21, identifier:poly; 22, type; 22, 23; 23, identifier:str; 24, None; 25, typed_default_parameter; 25, 26; 25, 27; 25, 29; 26, identifier:georel; 27, type; 27, 28; 28, identifier:str; 29, None; 30, typed_default_parameter; 30, 31; 30, 32; 30, 34; 31, identifier:order_by; 32, type; 32, 33; 33, identifier:str; 34, string:"_created"; 35, typed_default_parameter; 35, 36; 35, 37; 35, 39; 36, identifier:order_dir; 37, type; 37, 38; 38, identifier:str; 39, string:"desc"; 40, typed_default_parameter; 40, 41; 40, 42; 40, 44; 41, identifier:page_size; 42, type; 42, 43; 43, identifier:int; 44, integer:100; 45, typed_default_parameter; 45, 46; 45, 47; 45, 49; 46, identifier:offset; 47, type; 47, 48; 48, identifier:int; 49, integer:0; 50, typed_default_parameter; 50, 51; 50, 52; 50, 54; 51, identifier:share; 52, type; 52, 53; 53, identifier:str; 54, None; 55, typed_default_parameter; 55, 56; 55, 57; 55, 59; 56, identifier:specific_md; 57, type; 57, 58; 58, identifier:list; 59, list:[]; 60, typed_default_parameter; 60, 61; 60, 62; 60, 64; 61, identifier:include; 62, type; 62, 63; 63, identifier:list; 64, list:[]; 65, typed_default_parameter; 65, 66; 65, 67; 65, 69; 66, identifier:whole_share; 67, type; 67, 68; 68, identifier:bool; 69, True; 70, typed_default_parameter; 70, 71; 70, 72; 70, 74; 71, identifier:check; 72, type; 72, 73; 73, identifier:bool; 74, True; 75, typed_default_parameter; 75, 76; 75, 77; 75, 79; 76, identifier:augment; 77, type; 77, 78; 78, identifier:bool; 79, False; 80, typed_default_parameter; 80, 81; 80, 82; 80, 84; 81, identifier:tags_as_dicts; 82, type; 82, 83; 83, identifier:bool; 84, False; 85, typed_default_parameter; 85, 86; 85, 87; 85, 89; 86, identifier:prot; 87, type; 87, 88; 88, identifier:str; 89, string:"https"; 90, type; 90, 91; 91, identifier:dict; 92, block; 92, 93; 92, 102; 92, 111; 92, 153; 92, 166; 92, 178; 92, 222; 92, 229; 92, 237; 92, 246; 92, 341; 92, 387; 92, 467; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:specific_md; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:checker; 99, identifier:_check_filter_specific_md; 100, argument_list; 100, 101; 101, identifier:specific_md; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:include; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:checker; 108, identifier:_check_filter_includes; 109, argument_list; 109, 110; 110, identifier:include; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:payload; 114, dictionary; 114, 115; 114, 118; 114, 121; 114, 126; 114, 129; 114, 132; 114, 135; 114, 138; 114, 141; 114, 144; 114, 147; 114, 150; 115, pair; 115, 116; 115, 117; 116, string:"_id"; 117, identifier:specific_md; 118, pair; 118, 119; 118, 120; 119, string:"_include"; 120, identifier:include; 121, pair; 121, 122; 121, 123; 122, string:"_lang"; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:lang; 126, pair; 126, 127; 126, 128; 127, string:"_limit"; 128, identifier:page_size; 129, pair; 129, 130; 129, 131; 130, string:"_offset"; 131, identifier:offset; 132, pair; 132, 133; 132, 134; 133, string:"box"; 134, identifier:bbox; 135, pair; 135, 136; 135, 137; 136, string:"geo"; 137, identifier:poly; 138, pair; 138, 139; 138, 140; 139, string:"rel"; 140, identifier:georel; 141, pair; 141, 142; 141, 143; 142, string:"ob"; 143, identifier:order_by; 144, pair; 144, 145; 144, 146; 145, string:"od"; 146, identifier:order_dir; 147, pair; 147, 148; 147, 149; 148, string:"q"; 149, identifier:query; 150, pair; 150, 151; 150, 152; 151, string:"s"; 152, identifier:share; 153, if_statement; 153, 154; 153, 155; 153, 163; 154, identifier:check; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:checker; 160, identifier:check_request_parameters; 161, argument_list; 161, 162; 162, identifier:payload; 163, else_clause; 163, 164; 164, block; 164, 165; 165, pass_statement; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:search_url; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, string:"{}://v1.{}.isogeo.com/resources/search"; 172, identifier:format; 173, argument_list; 173, 174; 173, 175; 174, identifier:prot; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:api_url; 178, try_statement; 178, 179; 178, 207; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:search_req; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:get; 187, argument_list; 187, 188; 187, 189; 187, 194; 187, 197; 187, 202; 188, identifier:search_url; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:headers; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:header; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:params; 196, identifier:payload; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:proxies; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:proxies; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:verify; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:ssl; 207, except_clause; 207, 208; 207, 212; 208, as_pattern; 208, 209; 208, 210; 209, identifier:Exception; 210, as_pattern_target; 210, 211; 211, identifier:e; 212, block; 212, 213; 212, 220; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:logging; 217, identifier:error; 218, argument_list; 218, 219; 219, identifier:e; 220, raise_statement; 220, 221; 221, identifier:Exception; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:checker; 226, identifier:check_api_response; 227, argument_list; 227, 228; 228, identifier:search_req; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:search_rez; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:search_req; 235, identifier:json; 236, argument_list; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:resources_count; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:search_rez; 243, identifier:get; 244, argument_list; 244, 245; 245, string:"total"; 246, if_statement; 246, 247; 246, 252; 246, 338; 247, boolean_operator:and; 247, 248; 247, 251; 248, comparison_operator:>; 248, 249; 248, 250; 249, identifier:resources_count; 250, identifier:page_size; 251, identifier:whole_share; 252, block; 252, 253; 252, 257; 252, 263; 252, 332; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:metadatas; 256, list:[]; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:payload; 261, string:"_limit"; 262, integer:100; 263, for_statement; 263, 264; 263, 265; 263, 280; 264, identifier:idx; 265, call; 265, 266; 265, 267; 266, identifier:range; 267, argument_list; 267, 268; 267, 269; 268, integer:0; 269, binary_operator:+; 269, 270; 269, 279; 270, call; 270, 271; 270, 272; 271, identifier:int; 272, argument_list; 272, 273; 273, call; 273, 274; 273, 275; 274, identifier:ceil; 275, argument_list; 275, 276; 276, binary_operator:/; 276, 277; 276, 278; 277, identifier:resources_count; 278, integer:100; 279, integer:1; 280, block; 280, 281; 280, 289; 280, 316; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 286; 283, subscript; 283, 284; 283, 285; 284, identifier:payload; 285, string:"_offset"; 286, binary_operator:*; 286, 287; 286, 288; 287, identifier:idx; 288, integer:100; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:search_req; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:get; 296, argument_list; 296, 297; 296, 298; 296, 303; 296, 306; 296, 311; 297, identifier:search_url; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:headers; 300, attribute; 300, 301; 300, 302; 301, identifier:self; 302, identifier:header; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:params; 305, identifier:payload; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:proxies; 308, attribute; 308, 309; 308, 310; 309, identifier:self; 310, identifier:proxies; 311, keyword_argument; 311, 312; 311, 313; 312, identifier:verify; 313, attribute; 313, 314; 313, 315; 314, identifier:self; 315, identifier:ssl; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:metadatas; 320, identifier:extend; 321, argument_list; 321, 322; 322, call; 322, 323; 322, 330; 323, attribute; 323, 324; 323, 329; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:search_req; 327, identifier:json; 328, argument_list; 329, identifier:get; 330, argument_list; 330, 331; 331, string:"results"; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 337; 334, subscript; 334, 335; 334, 336; 335, identifier:search_rez; 336, string:"results"; 337, identifier:metadatas; 338, else_clause; 338, 339; 339, block; 339, 340; 340, pass_statement; 341, if_statement; 341, 342; 341, 343; 341, 384; 342, identifier:augment; 343, block; 343, 344; 343, 356; 344, expression_statement; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:self; 348, identifier:add_tags_shares; 349, argument_list; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:search_rez; 353, identifier:get; 354, argument_list; 354, 355; 355, string:"tags"; 356, if_statement; 356, 357; 356, 358; 356, 371; 357, identifier:share; 358, block; 358, 359; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 369; 361, subscript; 361, 362; 361, 368; 362, call; 362, 363; 362, 366; 363, attribute; 363, 364; 363, 365; 364, identifier:search_rez; 365, identifier:get; 366, argument_list; 366, 367; 367, string:"query"; 368, string:"_shares"; 369, list:[share]; 369, 370; 370, identifier:share; 371, else_clause; 371, 372; 372, block; 372, 373; 373, expression_statement; 373, 374; 374, assignment; 374, 375; 374, 383; 375, subscript; 375, 376; 375, 382; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:search_rez; 379, identifier:get; 380, argument_list; 380, 381; 381, string:"query"; 382, string:"_shares"; 383, list:[]; 384, else_clause; 384, 385; 385, block; 385, 386; 386, pass_statement; 387, if_statement; 387, 388; 387, 389; 387, 464; 388, identifier:tags_as_dicts; 389, block; 389, 390; 389, 414; 389, 425; 389, 436; 389, 450; 390, expression_statement; 390, 391; 391, assignment; 391, 392; 391, 393; 392, identifier:new_tags; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:utils; 396, identifier:tags_to_dict; 397, argument_list; 397, 398; 397, 406; 398, keyword_argument; 398, 399; 398, 400; 399, identifier:tags; 400, call; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:search_rez; 403, identifier:get; 404, argument_list; 404, 405; 405, string:"tags"; 406, keyword_argument; 406, 407; 406, 408; 407, identifier:prev_query; 408, call; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:search_rez; 411, identifier:get; 412, argument_list; 412, 413; 413, string:"query"; 414, expression_statement; 414, 415; 415, call; 415, 416; 415, 424; 416, attribute; 416, 417; 416, 423; 417, call; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:search_rez; 420, identifier:get; 421, argument_list; 421, 422; 422, string:"tags"; 423, identifier:clear; 424, argument_list; 425, expression_statement; 425, 426; 426, call; 426, 427; 426, 435; 427, attribute; 427, 428; 427, 434; 428, call; 428, 429; 428, 432; 429, attribute; 429, 430; 429, 431; 430, identifier:search_rez; 431, identifier:get; 432, argument_list; 432, 433; 433, string:"query"; 434, identifier:clear; 435, argument_list; 436, expression_statement; 436, 437; 437, call; 437, 438; 437, 446; 438, attribute; 438, 439; 438, 445; 439, call; 439, 440; 439, 443; 440, attribute; 440, 441; 440, 442; 441, identifier:search_rez; 442, identifier:get; 443, argument_list; 443, 444; 444, string:"tags"; 445, identifier:update; 446, argument_list; 446, 447; 447, subscript; 447, 448; 447, 449; 448, identifier:new_tags; 449, integer:0; 450, expression_statement; 450, 451; 451, call; 451, 452; 451, 460; 452, attribute; 452, 453; 452, 459; 453, call; 453, 454; 453, 457; 454, attribute; 454, 455; 454, 456; 455, identifier:search_rez; 456, identifier:get; 457, argument_list; 457, 458; 458, string:"query"; 459, identifier:update; 460, argument_list; 460, 461; 461, subscript; 461, 462; 461, 463; 462, identifier:new_tags; 463, integer:1; 464, else_clause; 464, 465; 465, block; 465, 466; 466, pass_statement; 467, return_statement; 467, 468; 468, identifier:search_rez | def search(
self,
token: dict = None,
query: str = "",
bbox: list = None,
poly: str = None,
georel: str = None,
order_by: str = "_created",
order_dir: str = "desc",
page_size: int = 100,
offset: int = 0,
share: str = None,
specific_md: list = [],
include: list = [],
whole_share: bool = True,
check: bool = True,
augment: bool = False,
tags_as_dicts: bool = False,
prot: str = "https",
) -> dict:
specific_md = checker._check_filter_specific_md(specific_md)
include = checker._check_filter_includes(include)
payload = {
"_id": specific_md,
"_include": include,
"_lang": self.lang,
"_limit": page_size,
"_offset": offset,
"box": bbox,
"geo": poly,
"rel": georel,
"ob": order_by,
"od": order_dir,
"q": query,
"s": share,
}
if check:
checker.check_request_parameters(payload)
else:
pass
search_url = "{}://v1.{}.isogeo.com/resources/search".format(prot, self.api_url)
try:
search_req = self.get(
search_url,
headers=self.header,
params=payload,
proxies=self.proxies,
verify=self.ssl,
)
except Exception as e:
logging.error(e)
raise Exception
checker.check_api_response(search_req)
search_rez = search_req.json()
resources_count = search_rez.get("total")
if resources_count > page_size and whole_share:
metadatas = []
payload["_limit"] = 100
for idx in range(0, int(ceil(resources_count / 100)) + 1):
payload["_offset"] = idx * 100
search_req = self.get(
search_url,
headers=self.header,
params=payload,
proxies=self.proxies,
verify=self.ssl,
)
metadatas.extend(search_req.json().get("results"))
search_rez["results"] = metadatas
else:
pass
if augment:
self.add_tags_shares(search_rez.get("tags"))
if share:
search_rez.get("query")["_shares"] = [share]
else:
search_rez.get("query")["_shares"] = []
else:
pass
if tags_as_dicts:
new_tags = utils.tags_to_dict(
tags=search_rez.get("tags"), prev_query=search_rez.get("query")
)
search_rez.get("tags").clear()
search_rez.get("query").clear()
search_rez.get("tags").update(new_tags[0])
search_rez.get("query").update(new_tags[1])
else:
pass
return search_rez |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 60; 1, 62; 2, function_name:keywords; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 15; 3, 20; 3, 25; 3, 30; 3, 35; 3, 40; 3, 45; 3, 50; 3, 55; 4, identifier:self; 5, typed_default_parameter; 5, 6; 5, 7; 5, 9; 6, identifier:token; 7, type; 7, 8; 8, identifier:dict; 9, None; 10, typed_default_parameter; 10, 11; 10, 12; 10, 14; 11, identifier:thez_id; 12, type; 12, 13; 13, identifier:str; 14, string:"1616597fbc4348c8b11ef9d59cf594c8"; 15, typed_default_parameter; 15, 16; 15, 17; 15, 19; 16, identifier:query; 17, type; 17, 18; 18, identifier:str; 19, string:""; 20, typed_default_parameter; 20, 21; 20, 22; 20, 24; 21, identifier:offset; 22, type; 22, 23; 23, identifier:int; 24, integer:0; 25, typed_default_parameter; 25, 26; 25, 27; 25, 29; 26, identifier:order_by; 27, type; 27, 28; 28, identifier:str; 29, string:"text"; 30, typed_default_parameter; 30, 31; 30, 32; 30, 34; 31, identifier:order_dir; 32, type; 32, 33; 33, identifier:str; 34, string:"desc"; 35, typed_default_parameter; 35, 36; 35, 37; 35, 39; 36, identifier:page_size; 37, type; 37, 38; 38, identifier:int; 39, integer:20; 40, typed_default_parameter; 40, 41; 40, 42; 40, 44; 41, identifier:specific_md; 42, type; 42, 43; 43, identifier:list; 44, list:[]; 45, typed_default_parameter; 45, 46; 45, 47; 45, 49; 46, identifier:specific_tag; 47, type; 47, 48; 48, identifier:list; 49, list:[]; 50, typed_default_parameter; 50, 51; 50, 52; 50, 54; 51, identifier:include; 52, type; 52, 53; 53, identifier:list; 54, list:[]; 55, typed_default_parameter; 55, 56; 55, 57; 55, 59; 56, identifier:prot; 57, type; 57, 58; 58, identifier:str; 59, string:"https"; 60, type; 60, 61; 61, identifier:dict; 62, block; 62, 63; 62, 72; 62, 82; 62, 91; 62, 122; 62, 135; 62, 162; 62, 169; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:specific_md; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:checker; 69, identifier:_check_filter_specific_md; 70, argument_list; 70, 71; 71, identifier:specific_md; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:include; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:checker; 78, identifier:_check_filter_includes; 79, argument_list; 79, 80; 79, 81; 80, identifier:include; 81, string:"keyword"; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:specific_tag; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:checker; 88, identifier:_check_filter_specific_tag; 89, argument_list; 89, 90; 90, identifier:specific_tag; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:payload; 94, dictionary; 94, 95; 94, 98; 94, 101; 94, 104; 94, 107; 94, 110; 94, 113; 94, 116; 94, 119; 95, pair; 95, 96; 95, 97; 96, string:"_id"; 97, identifier:specific_md; 98, pair; 98, 99; 98, 100; 99, string:"_include"; 100, identifier:include; 101, pair; 101, 102; 101, 103; 102, string:"_limit"; 103, identifier:page_size; 104, pair; 104, 105; 104, 106; 105, string:"_offset"; 106, identifier:offset; 107, pair; 107, 108; 107, 109; 108, string:"_tag"; 109, identifier:specific_tag; 110, pair; 110, 111; 110, 112; 111, string:"tid"; 112, identifier:thez_id; 113, pair; 113, 114; 113, 115; 114, string:"ob"; 115, identifier:order_by; 116, pair; 116, 117; 116, 118; 117, string:"od"; 118, identifier:order_dir; 119, pair; 119, 120; 119, 121; 120, string:"q"; 121, identifier:query; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:keywords_url; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, string:"{}://v1.{}.isogeo.com/thesauri/{}/keywords/search"; 128, identifier:format; 129, argument_list; 129, 130; 129, 131; 129, 134; 130, identifier:prot; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:api_url; 134, identifier:thez_id; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:kwds_req; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:get; 142, argument_list; 142, 143; 142, 144; 142, 149; 142, 152; 142, 157; 143, identifier:keywords_url; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:headers; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:header; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:params; 151, identifier:payload; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:proxies; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:proxies; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:verify; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:ssl; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:checker; 166, identifier:check_api_response; 167, argument_list; 167, 168; 168, identifier:kwds_req; 169, return_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:kwds_req; 173, identifier:json; 174, argument_list | def keywords(
self,
token: dict = None,
thez_id: str = "1616597fbc4348c8b11ef9d59cf594c8",
query: str = "",
offset: int = 0,
order_by: str = "text",
order_dir: str = "desc",
page_size: int = 20,
specific_md: list = [],
specific_tag: list = [],
include: list = [],
prot: str = "https",
) -> dict:
specific_md = checker._check_filter_specific_md(specific_md)
include = checker._check_filter_includes(include, "keyword")
specific_tag = checker._check_filter_specific_tag(specific_tag)
payload = {
"_id": specific_md,
"_include": include,
"_limit": page_size,
"_offset": offset,
"_tag": specific_tag,
"tid": thez_id,
"ob": order_by,
"od": order_dir,
"q": query,
}
keywords_url = "{}://v1.{}.isogeo.com/thesauri/{}/keywords/search".format(
prot, self.api_url, thez_id
)
kwds_req = self.get(
keywords_url,
headers=self.header,
params=payload,
proxies=self.proxies,
verify=self.ssl,
)
checker.check_api_response(kwds_req)
return kwds_req.json() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_field_sort_name; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:name; 6, block; 6, 7; 6, 51; 7, if_statement; 7, 8; 7, 17; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 16; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:cls; 14, identifier:__dict__; 15, identifier:name; 16, identifier:DateItemField; 17, block; 17, 18; 17, 29; 17, 40; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:name; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:re; 24, identifier:sub; 25, argument_list; 25, 26; 25, 27; 25, 28; 26, string:'year'; 27, string:'date0'; 28, identifier:name; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:name; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:re; 35, identifier:sub; 36, argument_list; 36, 37; 36, 38; 36, 39; 37, string:'month'; 38, string:'date1'; 39, identifier:name; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:name; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:re; 46, identifier:sub; 47, argument_list; 47, 48; 47, 49; 47, 50; 48, string:'day'; 49, string:'date2'; 50, identifier:name; 51, return_statement; 51, 52; 52, identifier:name | def _field_sort_name(cls, name):
if isinstance(cls.__dict__[name], DateItemField):
name = re.sub('year', 'date0', name)
name = re.sub('month', 'date1', name)
name = re.sub('day', 'date2', name)
return name |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted_fields; 3, parameters; 3, 4; 4, identifier:cls; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 8; 6, 21; 7, identifier:property; 8, call; 8, 9; 8, 10; 9, identifier:sorted; 10, argument_list; 10, 11; 10, 16; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:cls; 14, identifier:fields; 15, argument_list; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:key; 18, attribute; 18, 19; 18, 20; 19, identifier:cls; 20, identifier:_field_sort_name; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, yield; 23, 24; 24, identifier:property | def sorted_fields(cls):
for property in sorted(cls.fields(), key=cls._field_sort_name):
yield property |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:set_vassals_wrapper_params; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wrapper; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:overrides; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:fallbacks; 13, None; 14, block; 14, 15; 14, 23; 14, 34; 14, 45; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_set; 20, argument_list; 20, 21; 20, 22; 21, string:'emperor-wrapper'; 22, identifier:wrapper; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_set; 28, argument_list; 28, 29; 28, 30; 28, 31; 29, string:'emperor-wrapper-override'; 30, identifier:overrides; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:multi; 33, True; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_set; 39, argument_list; 39, 40; 39, 41; 39, 42; 40, string:'emperor-wrapper-fallback'; 41, identifier:fallbacks; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:multi; 44, True; 45, return_statement; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_section | def set_vassals_wrapper_params(self, wrapper=None, overrides=None, fallbacks=None):
self._set('emperor-wrapper', wrapper)
self._set('emperor-wrapper-override', overrides, multi=True)
self._set('emperor-wrapper-fallback', fallbacks, multi=True)
return self._section |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_query_parameters_to_url; 3, parameters; 3, 4; 3, 5; 4, identifier:url; 5, identifier:query_parameters; 6, block; 6, 7; 6, 18; 6, 31; 6, 38; 6, 44; 6, 63; 6, 75; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:url_parts; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:urllib; 14, identifier:parse; 15, identifier:urlparse; 16, argument_list; 16, 17; 17, identifier:url; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:qs_args; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:urllib; 25, identifier:parse; 26, identifier:parse_qs; 27, argument_list; 27, 28; 28, subscript; 28, 29; 28, 30; 29, identifier:url_parts; 30, integer:4; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:qs_args; 35, identifier:update; 36, argument_list; 36, 37; 37, identifier:query_parameters; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:sorted_qs_args; 41, call; 41, 42; 41, 43; 42, identifier:OrderedDict; 43, argument_list; 44, for_statement; 44, 45; 44, 46; 44, 54; 45, identifier:k; 46, call; 46, 47; 46, 48; 47, identifier:sorted; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:qs_args; 52, identifier:keys; 53, argument_list; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:sorted_qs_args; 59, identifier:k; 60, subscript; 60, 61; 60, 62; 61, identifier:qs_args; 62, identifier:k; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:new_qs; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:urllib; 70, identifier:parse; 71, identifier:urlencode; 72, argument_list; 72, 73; 72, 74; 73, identifier:sorted_qs_args; 74, True; 75, return_statement; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:urllib; 80, identifier:parse; 81, identifier:urlunparse; 82, argument_list; 82, 83; 83, binary_operator:+; 83, 84; 83, 96; 84, binary_operator:+; 84, 85; 84, 94; 85, call; 85, 86; 85, 87; 86, identifier:list; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 90; 89, identifier:url_parts; 90, slice; 90, 91; 90, 92; 90, 93; 91, integer:0; 92, colon; 93, integer:4; 94, list:[new_qs]; 94, 95; 95, identifier:new_qs; 96, call; 96, 97; 96, 98; 97, identifier:list; 98, argument_list; 98, 99; 99, subscript; 99, 100; 99, 101; 100, identifier:url_parts; 101, slice; 101, 102; 101, 103; 102, integer:5; 103, colon | def add_query_parameters_to_url(url, query_parameters):
url_parts = urllib.parse.urlparse(url)
qs_args = urllib.parse.parse_qs(url_parts[4])
qs_args.update(query_parameters)
sorted_qs_args = OrderedDict()
for k in sorted(qs_args.keys()):
sorted_qs_args[k] = qs_args[k]
new_qs = urllib.parse.urlencode(sorted_qs_args, True)
return urllib.parse.urlunparse(list(url_parts[0:4]) + [new_qs] + list(url_parts[5:])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:merge; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:elements; 6, block; 6, 7; 6, 9; 6, 14; 6, 22; 6, 48; 7, expression_statement; 7, 8; 8, string:''' Merges all scraping results to a list sorted by frequency of occurrence. '''; 9, import_from_statement; 9, 10; 9, 12; 10, dotted_name; 10, 11; 11, identifier:collections; 12, dotted_name; 12, 13; 13, identifier:Counter; 14, import_from_statement; 14, 15; 14, 18; 14, 20; 15, dotted_name; 15, 16; 15, 17; 16, identifier:lltk; 17, identifier:utils; 18, dotted_name; 18, 19; 19, identifier:list2tuple; 20, dotted_name; 20, 21; 21, identifier:tuple2list; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:merged; 25, call; 25, 26; 25, 27; 26, identifier:tuple2list; 27, argument_list; 27, 28; 28, list_comprehension; 28, 29; 28, 30; 29, identifier:value; 30, for_in_clause; 30, 31; 30, 34; 31, pattern_list; 31, 32; 31, 33; 32, identifier:value; 33, identifier:count; 34, call; 34, 35; 34, 47; 35, attribute; 35, 36; 35, 46; 36, call; 36, 37; 36, 38; 37, identifier:Counter; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:list2tuple; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:list; 44, argument_list; 44, 45; 45, identifier:elements; 46, identifier:most_common; 47, argument_list; 48, return_statement; 48, 49; 49, identifier:merged | def merge(self, elements):
''' Merges all scraping results to a list sorted by frequency of occurrence. '''
from collections import Counter
from lltk.utils import list2tuple, tuple2list
merged = tuple2list([value for value, count in Counter(list2tuple(list(elements))).most_common()])
return merged |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:in1d_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:ar1; 5, identifier:ar2; 6, block; 6, 7; 6, 26; 6, 35; 6, 46; 7, if_statement; 7, 8; 7, 23; 8, boolean_operator:or; 8, 9; 8, 16; 9, comparison_operator:==; 9, 10; 9, 15; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:ar1; 13, identifier:shape; 14, integer:0; 15, integer:0; 16, comparison_operator:==; 16, 17; 16, 22; 17, subscript; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:ar2; 20, identifier:shape; 21, integer:0; 22, integer:0; 23, block; 23, 24; 24, return_statement; 24, 25; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:inds; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:ar2; 32, identifier:searchsorted; 33, argument_list; 33, 34; 34, identifier:ar1; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 45; 37, subscript; 37, 38; 37, 39; 38, identifier:inds; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:inds; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:ar2; 45, integer:0; 46, return_statement; 46, 47; 47, comparison_operator:==; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:ar2; 50, identifier:inds; 51, identifier:ar1 | def in1d_sorted(ar1, ar2):
if ar1.shape[0] == 0 or ar2.shape[0] == 0:
return []
inds = ar2.searchsorted(ar1)
inds[inds == len(ar2)] = 0
return ar2[inds] == ar1 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_parameter_value_from_file_names; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:files; 5, default_parameter; 5, 6; 5, 7; 6, identifier:parameters; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:unique; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, True; 14, block; 14, 15; 14, 39; 14, 47; 14, 54; 14, 66; 14, 75; 14, 83; 14, 87; 14, 193; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logging; 19, identifier:debug; 20, argument_list; 20, 21; 21, binary_operator:+; 21, 22; 21, 38; 22, binary_operator:+; 22, 23; 22, 31; 23, binary_operator:+; 23, 24; 23, 30; 24, binary_operator:+; 24, 25; 24, 26; 25, string:'Get the parameter: '; 26, call; 26, 27; 26, 28; 27, identifier:str; 28, argument_list; 28, 29; 29, identifier:parameters; 30, string:' values from the file names of '; 31, call; 31, 32; 31, 33; 32, identifier:str; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, identifier:files; 38, string:' files'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:files_dict; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:collections; 45, identifier:OrderedDict; 46, argument_list; 47, if_statement; 47, 48; 47, 51; 48, comparison_operator:is; 48, 49; 48, 50; 49, identifier:parameters; 50, None; 51, block; 51, 52; 52, return_statement; 52, 53; 53, identifier:files_dict; 54, if_statement; 54, 55; 54, 60; 55, call; 55, 56; 55, 57; 56, identifier:isinstance; 57, argument_list; 57, 58; 57, 59; 58, identifier:parameters; 59, identifier:basestring; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:parameters; 64, tuple; 64, 65; 65, identifier:parameters; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:search_string; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:'_'; 72, identifier:join; 73, argument_list; 73, 74; 74, identifier:parameters; 75, for_statement; 75, 76; 75, 77; 75, 78; 76, identifier:_; 77, identifier:parameters; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, augmented_assignment:+=; 80, 81; 80, 82; 81, identifier:search_string; 82, string:r'_(-?\d+)'; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:result; 86, dictionary; 87, for_statement; 87, 88; 87, 89; 87, 90; 88, identifier:one_file; 89, identifier:files; 90, block; 90, 91; 90, 101; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:parameter_values; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:re; 97, identifier:findall; 98, argument_list; 98, 99; 98, 100; 99, identifier:search_string; 100, identifier:one_file; 101, if_statement; 101, 102; 101, 103; 102, identifier:parameter_values; 103, block; 103, 104; 103, 130; 103, 142; 103, 155; 104, if_statement; 104, 105; 104, 112; 105, call; 105, 106; 105, 107; 106, identifier:isinstance; 107, argument_list; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:parameter_values; 110, integer:0; 111, identifier:tuple; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:parameter_values; 116, call; 116, 117; 116, 118; 117, identifier:list; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:reduce; 121, argument_list; 121, 122; 121, 129; 122, lambda; 122, 123; 122, 126; 123, lambda_parameters; 123, 124; 123, 125; 124, identifier:t1; 125, identifier:t2; 126, binary_operator:+; 126, 127; 126, 128; 127, identifier:t1; 128, identifier:t2; 129, identifier:parameter_values; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:parameter_values; 133, list_comprehension; 133, 134; 133, 139; 134, list:[int(i), ]; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:int; 137, argument_list; 137, 138; 138, identifier:i; 139, for_in_clause; 139, 140; 139, 141; 140, identifier:i; 141, identifier:parameter_values; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:files_dict; 146, identifier:one_file; 147, call; 147, 148; 147, 149; 148, identifier:dict; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:zip; 152, argument_list; 152, 153; 152, 154; 153, identifier:parameters; 154, identifier:parameter_values; 155, if_statement; 155, 156; 155, 157; 155, 183; 156, identifier:unique; 157, block; 157, 158; 158, for_statement; 158, 159; 158, 162; 158, 167; 159, pattern_list; 159, 160; 159, 161; 160, identifier:key; 161, identifier:value; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:files_dict; 165, identifier:items; 166, argument_list; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 176; 169, comparison_operator:not; 169, 170; 169, 171; 170, identifier:value; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:result; 174, identifier:values; 175, argument_list; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:result; 181, identifier:key; 182, identifier:value; 183, else_clause; 183, 184; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:result; 189, identifier:one_file; 190, subscript; 190, 191; 190, 192; 191, identifier:files_dict; 192, identifier:one_file; 193, return_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:collections; 197, identifier:OrderedDict; 198, argument_list; 198, 199; 199, conditional_expression:if; 199, 200; 199, 214; 199, 215; 200, call; 200, 201; 200, 202; 201, identifier:sorted; 202, argument_list; 202, 203; 202, 208; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:result; 206, identifier:iteritems; 207, argument_list; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:key; 210, call; 210, 211; 210, 212; 211, identifier:itemgetter; 212, argument_list; 212, 213; 213, integer:1; 214, identifier:sort; 215, identifier:files_dict | def get_parameter_value_from_file_names(files, parameters=None, unique=False, sort=True):
logging.debug('Get the parameter: ' + str(parameters) + ' values from the file names of ' + str(len(files)) + ' files')
files_dict = collections.OrderedDict()
if parameters is None:
return files_dict
if isinstance(parameters, basestring):
parameters = (parameters, )
search_string = '_'.join(parameters)
for _ in parameters:
search_string += r'_(-?\d+)'
result = {}
for one_file in files:
parameter_values = re.findall(search_string, one_file)
if parameter_values:
if isinstance(parameter_values[0], tuple):
parameter_values = list(reduce(lambda t1, t2: t1 + t2, parameter_values))
parameter_values = [[int(i), ] for i in parameter_values]
files_dict[one_file] = dict(zip(parameters, parameter_values))
if unique:
for key, value in files_dict.items():
if value not in result.values():
result[key] = value
else:
result[one_file] = files_dict[one_file]
return collections.OrderedDict(sorted(result.iteritems(), key=itemgetter(1)) if sort else files_dict) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:get_data_file_names_from_scan_base; 3, parameters; 3, 4; 3, 5; 3, 13; 3, 16; 4, identifier:scan_base; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filter_str; 7, list:['_analyzed.h5', '_interpreted.h5', '_cut.h5', '_result.h5', '_hists.h5']; 7, 8; 7, 9; 7, 10; 7, 11; 7, 12; 8, string:'_analyzed.h5'; 9, string:'_interpreted.h5'; 10, string:'_cut.h5'; 11, string:'_result.h5'; 12, string:'_hists.h5'; 13, default_parameter; 13, 14; 13, 15; 14, identifier:sort_by_time; 15, True; 16, default_parameter; 16, 17; 16, 18; 17, identifier:meta_data_v2; 18, True; 19, block; 19, 20; 19, 24; 19, 31; 19, 43; 19, 84; 19, 124; 19, 249; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:data_files; 23, list:[]; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:scan_base; 27, None; 28, block; 28, 29; 29, return_statement; 29, 30; 30, identifier:data_files; 31, if_statement; 31, 32; 31, 37; 32, call; 32, 33; 32, 34; 33, identifier:isinstance; 34, argument_list; 34, 35; 34, 36; 35, identifier:scan_base; 36, identifier:basestring; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:scan_base; 41, list:[scan_base]; 41, 42; 42, identifier:scan_base; 43, for_statement; 43, 44; 43, 45; 43, 46; 44, identifier:scan_base_str; 45, identifier:scan_base; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 60; 47, 68; 48, comparison_operator:==; 48, 49; 48, 50; 49, string:'.h5'; 50, subscript; 50, 51; 50, 59; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:os; 55, identifier:path; 56, identifier:splitext; 57, argument_list; 57, 58; 58, identifier:scan_base_str; 59, integer:1; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:data_files; 65, identifier:append; 66, argument_list; 66, 67; 67, identifier:scan_base_str; 68, else_clause; 68, 69; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:data_files; 74, identifier:extend; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:glob; 79, identifier:glob; 80, argument_list; 80, 81; 81, binary_operator:+; 81, 82; 81, 83; 82, identifier:scan_base_str; 83, string:'*.h5'; 84, if_statement; 84, 85; 84, 86; 85, identifier:filter_str; 86, block; 86, 87; 86, 99; 87, if_statement; 87, 88; 87, 93; 88, call; 88, 89; 88, 90; 89, identifier:isinstance; 90, argument_list; 90, 91; 90, 92; 91, identifier:filter_str; 92, identifier:basestring; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:filter_str; 97, list:[filter_str]; 97, 98; 98, identifier:filter_str; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:data_files; 102, call; 102, 103; 102, 104; 103, identifier:filter; 104, argument_list; 104, 105; 104, 123; 105, lambda; 105, 106; 105, 108; 106, lambda_parameters; 106, 107; 107, identifier:data_file; 108, not_operator; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:any; 111, argument_list; 111, 112; 112, list_comprehension; 112, 113; 112, 120; 113, parenthesized_expression; 113, 114; 114, conditional_expression:if; 114, 115; 114, 116; 114, 119; 115, True; 116, comparison_operator:in; 116, 117; 116, 118; 117, identifier:x; 118, identifier:data_file; 119, False; 120, for_in_clause; 120, 121; 120, 122; 121, identifier:x; 122, identifier:filter_str; 123, identifier:data_files; 124, if_statement; 124, 125; 124, 133; 125, boolean_operator:and; 125, 126; 125, 127; 126, identifier:sort_by_time; 127, comparison_operator:>; 127, 128; 127, 132; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, identifier:data_files; 132, integer:1; 133, block; 133, 134; 133, 138; 133, 231; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:f_list; 137, dictionary; 138, for_statement; 138, 139; 138, 140; 138, 141; 139, identifier:data_file; 140, identifier:data_files; 141, block; 141, 142; 142, with_statement; 142, 143; 142, 157; 143, with_clause; 143, 144; 144, with_item; 144, 145; 145, as_pattern; 145, 146; 145, 155; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:tb; 149, identifier:open_file; 150, argument_list; 150, 151; 150, 152; 151, identifier:data_file; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:mode; 154, string:"r"; 155, as_pattern_target; 155, 156; 156, identifier:h5_file; 157, block; 157, 158; 158, try_statement; 158, 159; 158, 168; 158, 184; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:meta_data; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:h5_file; 166, identifier:root; 167, identifier:meta_data; 168, except_clause; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:tb; 171, identifier:NoSuchNodeError; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:logging; 177, identifier:warning; 178, argument_list; 178, 179; 179, binary_operator:%; 179, 180; 179, 181; 180, string:"File %s is missing meta_data"; 181, attribute; 181, 182; 181, 183; 182, identifier:h5_file; 183, identifier:filename; 184, else_clause; 184, 185; 185, block; 185, 186; 186, try_statement; 186, 187; 186, 209; 186, 223; 187, block; 187, 188; 188, if_statement; 188, 189; 188, 190; 188, 199; 189, identifier:meta_data_v2; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:timestamp; 194, subscript; 194, 195; 194, 198; 195, subscript; 195, 196; 195, 197; 196, identifier:meta_data; 197, integer:0; 198, string:"timestamp_start"; 199, else_clause; 199, 200; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:timestamp; 204, subscript; 204, 205; 204, 208; 205, subscript; 205, 206; 205, 207; 206, identifier:meta_data; 207, integer:0; 208, string:"timestamp"; 209, except_clause; 209, 210; 209, 211; 210, identifier:IndexError; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:logging; 216, identifier:info; 217, argument_list; 217, 218; 218, binary_operator:%; 218, 219; 218, 220; 219, string:"File %s has empty meta_data"; 220, attribute; 220, 221; 220, 222; 221, identifier:h5_file; 222, identifier:filename; 223, else_clause; 223, 224; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:f_list; 229, identifier:data_file; 230, identifier:timestamp; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:data_files; 234, call; 234, 235; 234, 236; 235, identifier:list; 236, argument_list; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:sorted; 239, argument_list; 239, 240; 239, 241; 239, 246; 240, identifier:f_list; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:key; 243, attribute; 243, 244; 243, 245; 244, identifier:f_list; 245, identifier:__getitem__; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:reverse; 248, False; 249, return_statement; 249, 250; 250, identifier:data_files | def get_data_file_names_from_scan_base(scan_base, filter_str=['_analyzed.h5', '_interpreted.h5', '_cut.h5', '_result.h5', '_hists.h5'], sort_by_time=True, meta_data_v2=True):
data_files = []
if scan_base is None:
return data_files
if isinstance(scan_base, basestring):
scan_base = [scan_base]
for scan_base_str in scan_base:
if '.h5' == os.path.splitext(scan_base_str)[1]:
data_files.append(scan_base_str)
else:
data_files.extend(glob.glob(scan_base_str + '*.h5'))
if filter_str:
if isinstance(filter_str, basestring):
filter_str = [filter_str]
data_files = filter(lambda data_file: not any([(True if x in data_file else False) for x in filter_str]), data_files)
if sort_by_time and len(data_files) > 1:
f_list = {}
for data_file in data_files:
with tb.open_file(data_file, mode="r") as h5_file:
try:
meta_data = h5_file.root.meta_data
except tb.NoSuchNodeError:
logging.warning("File %s is missing meta_data" % h5_file.filename)
else:
try:
if meta_data_v2:
timestamp = meta_data[0]["timestamp_start"]
else:
timestamp = meta_data[0]["timestamp"]
except IndexError:
logging.info("File %s has empty meta_data" % h5_file.filename)
else:
f_list[data_file] = timestamp
data_files = list(sorted(f_list, key=f_list.__getitem__, reverse=False))
return data_files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_parameter_from_files; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:files; 5, default_parameter; 5, 6; 5, 7; 6, identifier:parameters; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:unique; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sort; 13, True; 14, block; 14, 15; 14, 17; 14, 41; 14, 49; 14, 61; 14, 73; 14, 87; 14, 376; 15, expression_statement; 15, 16; 16, string:''' Takes a list of files, searches for the parameter name in the file name and in the file.
Returns a ordered dict with the file name in the first dimension and the corresponding parameter values in the second.
If a scan parameter appears in the file name and in the file the first parameter setting has to be in the file name, otherwise a warning is shown.
The file names can be sorted by the first parameter value of each file.
Parameters
----------
files : string, list of strings
parameters : string, list of strings
unique : boolean
If set only one file per scan parameter value is used.
sort : boolean
Returns
-------
collections.OrderedDict
'''; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:logging; 21, identifier:debug; 22, argument_list; 22, 23; 23, binary_operator:+; 23, 24; 23, 40; 24, binary_operator:+; 24, 25; 24, 33; 25, binary_operator:+; 25, 26; 25, 32; 26, binary_operator:+; 26, 27; 26, 28; 27, string:'Get the parameter '; 28, call; 28, 29; 28, 30; 29, identifier:str; 30, argument_list; 30, 31; 31, identifier:parameters; 32, string:' values from '; 33, call; 33, 34; 33, 35; 34, identifier:str; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, identifier:files; 40, string:' files'; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:files_dict; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:collections; 47, identifier:OrderedDict; 48, argument_list; 49, if_statement; 49, 50; 49, 55; 50, call; 50, 51; 50, 52; 51, identifier:isinstance; 52, argument_list; 52, 53; 52, 54; 53, identifier:files; 54, identifier:basestring; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:files; 59, tuple; 59, 60; 60, identifier:files; 61, if_statement; 61, 62; 61, 67; 62, call; 62, 63; 62, 64; 63, identifier:isinstance; 64, argument_list; 64, 65; 64, 66; 65, identifier:parameters; 66, identifier:basestring; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:parameters; 71, tuple; 71, 72; 72, identifier:parameters; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:parameter_values_from_file_names_dict; 76, call; 76, 77; 76, 78; 77, identifier:get_parameter_value_from_file_names; 78, argument_list; 78, 79; 78, 80; 78, 81; 78, 84; 79, identifier:files; 80, identifier:parameters; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:unique; 83, identifier:unique; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:sort; 86, identifier:sort; 87, for_statement; 87, 88; 87, 89; 87, 90; 88, identifier:file_name; 89, identifier:files; 90, block; 90, 91; 91, with_statement; 91, 92; 91, 106; 92, with_clause; 92, 93; 93, with_item; 93, 94; 94, as_pattern; 94, 95; 94, 104; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:tb; 98, identifier:open_file; 99, argument_list; 99, 100; 99, 101; 100, identifier:file_name; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:mode; 103, string:"r"; 104, as_pattern_target; 104, 105; 105, identifier:in_file_h5; 106, block; 106, 107; 106, 115; 106, 218; 106, 300; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:scan_parameter_values; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:collections; 113, identifier:OrderedDict; 114, argument_list; 115, try_statement; 115, 116; 115, 167; 116, block; 116, 117; 116, 128; 116, 140; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:scan_parameters; 120, subscript; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:in_file_h5; 124, identifier:root; 125, identifier:scan_parameters; 126, slice; 126, 127; 127, colon; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:parameters; 131, None; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:parameters; 136, call; 136, 137; 136, 138; 137, identifier:get_scan_parameter_names; 138, argument_list; 138, 139; 139, identifier:scan_parameters; 140, for_statement; 140, 141; 140, 142; 140, 143; 141, identifier:parameter; 142, identifier:parameters; 143, block; 143, 144; 144, try_statement; 144, 145; 144, 163; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:scan_parameter_values; 150, identifier:parameter; 151, call; 151, 152; 151, 162; 152, attribute; 152, 153; 152, 161; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:np; 156, identifier:unique; 157, argument_list; 157, 158; 158, subscript; 158, 159; 158, 160; 159, identifier:scan_parameters; 160, identifier:parameter; 161, identifier:tolist; 162, argument_list; 163, except_clause; 163, 164; 163, 165; 164, identifier:ValueError; 165, block; 165, 166; 166, pass_statement; 167, except_clause; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:tb; 170, identifier:NoSuchNodeError; 171, block; 171, 172; 172, try_statement; 172, 173; 172, 212; 173, block; 173, 174; 173, 188; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:scan_parameters; 177, call; 177, 178; 177, 179; 178, identifier:get_scan_parameter; 179, argument_list; 179, 180; 180, subscript; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:in_file_h5; 184, identifier:root; 185, identifier:meta_data; 186, slice; 186, 187; 187, colon; 188, if_statement; 188, 189; 188, 190; 189, identifier:scan_parameters; 190, block; 190, 191; 191, try_statement; 191, 192; 191, 208; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:scan_parameter_values; 196, call; 196, 197; 196, 207; 197, attribute; 197, 198; 197, 206; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:np; 201, identifier:unique; 202, argument_list; 202, 203; 203, subscript; 203, 204; 203, 205; 204, identifier:scan_parameters; 205, identifier:parameters; 206, identifier:tolist; 207, argument_list; 208, except_clause; 208, 209; 208, 210; 209, identifier:ValueError; 210, block; 210, 211; 211, pass_statement; 212, except_clause; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:tb; 215, identifier:NoSuchNodeError; 216, block; 216, 217; 217, pass_statement; 218, if_statement; 218, 219; 218, 221; 218, 237; 219, not_operator; 219, 220; 220, identifier:scan_parameter_values; 221, block; 221, 222; 222, try_statement; 222, 223; 222, 230; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:scan_parameter_values; 227, subscript; 227, 228; 227, 229; 228, identifier:parameter_values_from_file_names_dict; 229, identifier:file_name; 230, except_clause; 230, 231; 230, 232; 231, identifier:KeyError; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:scan_parameter_values; 236, None; 237, else_clause; 237, 238; 238, block; 238, 239; 239, try_statement; 239, 240; 239, 288; 239, 292; 240, block; 240, 241; 241, for_statement; 241, 242; 241, 245; 241, 250; 242, pattern_list; 242, 243; 242, 244; 243, identifier:key; 244, identifier:value; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:scan_parameter_values; 248, identifier:items; 249, argument_list; 250, block; 250, 251; 251, if_statement; 251, 252; 251, 265; 252, boolean_operator:and; 252, 253; 252, 254; 253, identifier:value; 254, comparison_operator:!=; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:value; 257, integer:0; 258, subscript; 258, 259; 258, 264; 259, subscript; 259, 260; 259, 263; 260, subscript; 260, 261; 260, 262; 261, identifier:parameter_values_from_file_names_dict; 262, identifier:file_name; 263, identifier:key; 264, integer:0; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:logging; 270, identifier:warning; 271, argument_list; 271, 272; 271, 287; 272, binary_operator:+; 272, 273; 272, 286; 273, binary_operator:+; 273, 274; 273, 282; 274, binary_operator:+; 274, 275; 274, 281; 275, binary_operator:+; 275, 276; 275, 277; 276, string:'Parameter values in the file name and in the file differ. Take '; 277, call; 277, 278; 277, 279; 278, identifier:str; 279, argument_list; 279, 280; 280, identifier:key; 281, string:' parameters '; 282, call; 282, 283; 282, 284; 283, identifier:str; 284, argument_list; 284, 285; 285, identifier:value; 286, string:' found in %s.'; 287, identifier:file_name; 288, except_clause; 288, 289; 288, 290; 289, identifier:KeyError; 290, block; 290, 291; 291, pass_statement; 292, except_clause; 292, 293; 292, 294; 293, identifier:IndexError; 294, block; 294, 295; 295, raise_statement; 295, 296; 296, call; 296, 297; 296, 298; 297, identifier:IncompleteInputError; 298, argument_list; 298, 299; 299, string:'Something wrong check!'; 300, if_statement; 300, 301; 300, 306; 300, 368; 301, boolean_operator:and; 301, 302; 301, 303; 302, identifier:unique; 303, comparison_operator:is; 303, 304; 303, 305; 304, identifier:scan_parameter_values; 305, None; 306, block; 306, 307; 306, 311; 306, 348; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:existing; 310, False; 311, for_statement; 311, 312; 311, 313; 311, 314; 312, identifier:parameter; 313, identifier:scan_parameter_values; 314, block; 314, 315; 314, 329; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:all_par_values; 318, list_comprehension; 318, 319; 318, 322; 319, subscript; 319, 320; 319, 321; 320, identifier:values; 321, identifier:parameter; 322, for_in_clause; 322, 323; 322, 324; 323, identifier:values; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:files_dict; 327, identifier:values; 328, argument_list; 329, if_statement; 329, 330; 329, 342; 330, call; 330, 331; 330, 332; 331, identifier:any; 332, generator_expression; 332, 333; 332, 339; 333, comparison_operator:in; 333, 334; 333, 335; 334, identifier:x; 335, list:[scan_parameter_values[parameter]]; 335, 336; 336, subscript; 336, 337; 336, 338; 337, identifier:scan_parameter_values; 338, identifier:parameter; 339, for_in_clause; 339, 340; 339, 341; 340, identifier:x; 341, identifier:all_par_values; 342, block; 342, 343; 342, 347; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:existing; 346, True; 347, break_statement; 348, if_statement; 348, 349; 348, 351; 348, 358; 349, not_operator; 349, 350; 350, identifier:existing; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 357; 354, subscript; 354, 355; 354, 356; 355, identifier:files_dict; 356, identifier:file_name; 357, identifier:scan_parameter_values; 358, else_clause; 358, 359; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:logging; 364, identifier:warning; 365, argument_list; 365, 366; 365, 367; 366, string:'Scan parameter value(s) from %s exists already, do not add to result'; 367, identifier:file_name; 368, else_clause; 368, 369; 369, block; 369, 370; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 375; 372, subscript; 372, 373; 372, 374; 373, identifier:files_dict; 374, identifier:file_name; 375, identifier:scan_parameter_values; 376, return_statement; 376, 377; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:collections; 380, identifier:OrderedDict; 381, argument_list; 381, 382; 382, conditional_expression:if; 382, 383; 382, 397; 382, 398; 383, call; 383, 384; 383, 385; 384, identifier:sorted; 385, argument_list; 385, 386; 385, 391; 386, call; 386, 387; 386, 390; 387, attribute; 387, 388; 387, 389; 388, identifier:files_dict; 389, identifier:iteritems; 390, argument_list; 391, keyword_argument; 391, 392; 391, 393; 392, identifier:key; 393, call; 393, 394; 393, 395; 394, identifier:itemgetter; 395, argument_list; 395, 396; 396, integer:1; 397, identifier:sort; 398, identifier:files_dict | def get_parameter_from_files(files, parameters=None, unique=False, sort=True):
''' Takes a list of files, searches for the parameter name in the file name and in the file.
Returns a ordered dict with the file name in the first dimension and the corresponding parameter values in the second.
If a scan parameter appears in the file name and in the file the first parameter setting has to be in the file name, otherwise a warning is shown.
The file names can be sorted by the first parameter value of each file.
Parameters
----------
files : string, list of strings
parameters : string, list of strings
unique : boolean
If set only one file per scan parameter value is used.
sort : boolean
Returns
-------
collections.OrderedDict
'''
logging.debug('Get the parameter ' + str(parameters) + ' values from ' + str(len(files)) + ' files')
files_dict = collections.OrderedDict()
if isinstance(files, basestring):
files = (files, )
if isinstance(parameters, basestring):
parameters = (parameters, )
parameter_values_from_file_names_dict = get_parameter_value_from_file_names(files, parameters, unique=unique, sort=sort)
for file_name in files:
with tb.open_file(file_name, mode="r") as in_file_h5:
scan_parameter_values = collections.OrderedDict()
try:
scan_parameters = in_file_h5.root.scan_parameters[:]
if parameters is None:
parameters = get_scan_parameter_names(scan_parameters)
for parameter in parameters:
try:
scan_parameter_values[parameter] = np.unique(scan_parameters[parameter]).tolist()
except ValueError:
pass
except tb.NoSuchNodeError:
try:
scan_parameters = get_scan_parameter(in_file_h5.root.meta_data[:])
if scan_parameters:
try:
scan_parameter_values = np.unique(scan_parameters[parameters]).tolist()
except ValueError:
pass
except tb.NoSuchNodeError:
pass
if not scan_parameter_values:
try:
scan_parameter_values = parameter_values_from_file_names_dict[file_name]
except KeyError:
scan_parameter_values = None
else:
try:
for key, value in scan_parameter_values.items():
if value and value[0] != parameter_values_from_file_names_dict[file_name][key][0]:
logging.warning('Parameter values in the file name and in the file differ. Take ' + str(key) + ' parameters ' + str(value) + ' found in %s.', file_name)
except KeyError:
pass
except IndexError:
raise IncompleteInputError('Something wrong check!')
if unique and scan_parameter_values is not None:
existing = False
for parameter in scan_parameter_values:
all_par_values = [values[parameter] for values in files_dict.values()]
if any(x in [scan_parameter_values[parameter]] for x in all_par_values):
existing = True
break
if not existing:
files_dict[file_name] = scan_parameter_values
else:
logging.warning('Scan parameter value(s) from %s exists already, do not add to result', file_name)
else:
files_dict[file_name] = scan_parameter_values
return collections.OrderedDict(sorted(files_dict.iteritems(), key=itemgetter(1)) if sort else files_dict) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:reduce_sorted_to_intersect; 3, parameters; 3, 4; 3, 5; 4, identifier:ar1; 5, identifier:ar2; 6, block; 6, 7; 6, 20; 6, 33; 6, 40; 6, 46; 6, 53; 6, 59; 6, 82; 6, 93; 6, 104; 6, 115; 6, 126; 6, 135; 6, 144; 6, 165; 6, 186; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:ar1; 10, call; 10, 11; 10, 19; 11, attribute; 11, 12; 11, 18; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:asarray; 16, argument_list; 16, 17; 17, identifier:ar1; 18, identifier:ravel; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:ar2; 23, call; 23, 24; 23, 32; 24, attribute; 24, 25; 24, 31; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:asarray; 29, argument_list; 29, 30; 30, identifier:ar2; 31, identifier:ravel; 32, argument_list; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:ar1_biggest_value; 36, subscript; 36, 37; 36, 38; 37, identifier:ar1; 38, unary_operator:-; 38, 39; 39, integer:1; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ar1_smallest_value; 43, subscript; 43, 44; 43, 45; 44, identifier:ar1; 45, integer:0; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:ar2_biggest_value; 49, subscript; 49, 50; 49, 51; 50, identifier:ar2; 51, unary_operator:-; 51, 52; 52, integer:1; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:ar2_smallest_value; 56, subscript; 56, 57; 56, 58; 57, identifier:ar2; 58, integer:0; 59, if_statement; 59, 60; 59, 67; 60, boolean_operator:or; 60, 61; 60, 64; 61, comparison_operator:<; 61, 62; 61, 63; 62, identifier:ar1_biggest_value; 63, identifier:ar2_smallest_value; 64, comparison_operator:>; 64, 65; 64, 66; 65, identifier:ar1_smallest_value; 66, identifier:ar2_biggest_value; 67, block; 67, 68; 68, return_statement; 68, 69; 69, expression_list; 69, 70; 69, 76; 70, subscript; 70, 71; 70, 72; 71, identifier:ar1; 72, slice; 72, 73; 72, 74; 72, 75; 73, integer:0; 74, colon; 75, integer:0; 76, subscript; 76, 77; 76, 78; 77, identifier:ar2; 78, slice; 78, 79; 78, 80; 78, 81; 79, integer:0; 80, colon; 81, integer:0; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:min_index_ar1; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:argmin; 89, argument_list; 89, 90; 90, comparison_operator:<; 90, 91; 90, 92; 91, identifier:ar1; 92, identifier:ar2_smallest_value; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:max_index_ar1; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:np; 99, identifier:argmax; 100, argument_list; 100, 101; 101, comparison_operator:>; 101, 102; 101, 103; 102, identifier:ar1; 103, identifier:ar2_biggest_value; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:min_index_ar2; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:argmin; 111, argument_list; 111, 112; 112, comparison_operator:<; 112, 113; 112, 114; 113, identifier:ar2; 114, identifier:ar1_smallest_value; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:max_index_ar2; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:np; 121, identifier:argmax; 122, argument_list; 122, 123; 123, comparison_operator:>; 123, 124; 123, 125; 124, identifier:ar2; 125, identifier:ar1_biggest_value; 126, if_statement; 126, 127; 126, 130; 127, comparison_operator:<; 127, 128; 127, 129; 128, identifier:min_index_ar1; 129, integer:0; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:min_index_ar1; 134, integer:0; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:<; 136, 137; 136, 138; 137, identifier:min_index_ar2; 138, integer:0; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:min_index_ar2; 143, integer:0; 144, if_statement; 144, 145; 144, 156; 145, boolean_operator:or; 145, 146; 145, 149; 146, comparison_operator:==; 146, 147; 146, 148; 147, identifier:max_index_ar1; 148, integer:0; 149, comparison_operator:>; 149, 150; 149, 151; 150, identifier:max_index_ar1; 151, subscript; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:ar1; 154, identifier:shape; 155, integer:0; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:max_index_ar1; 160, subscript; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:ar1; 163, identifier:shape; 164, integer:0; 165, if_statement; 165, 166; 165, 177; 166, boolean_operator:or; 166, 167; 166, 170; 167, comparison_operator:==; 167, 168; 167, 169; 168, identifier:max_index_ar2; 169, integer:0; 170, comparison_operator:>; 170, 171; 170, 172; 171, identifier:max_index_ar2; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:ar2; 175, identifier:shape; 176, integer:0; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:max_index_ar2; 181, subscript; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:ar2; 184, identifier:shape; 185, integer:0; 186, return_statement; 186, 187; 187, expression_list; 187, 188; 187, 194; 188, subscript; 188, 189; 188, 190; 189, identifier:ar1; 190, slice; 190, 191; 190, 192; 190, 193; 191, identifier:min_index_ar1; 192, colon; 193, identifier:max_index_ar1; 194, subscript; 194, 195; 194, 196; 195, identifier:ar2; 196, slice; 196, 197; 196, 198; 196, 199; 197, identifier:min_index_ar2; 198, colon; 199, identifier:max_index_ar2 | def reduce_sorted_to_intersect(ar1, ar2):
ar1 = np.asarray(ar1).ravel()
ar2 = np.asarray(ar2).ravel()
ar1_biggest_value = ar1[-1]
ar1_smallest_value = ar1[0]
ar2_biggest_value = ar2[-1]
ar2_smallest_value = ar2[0]
if ar1_biggest_value < ar2_smallest_value or ar1_smallest_value > ar2_biggest_value:
return ar1[0:0], ar2[0:0]
min_index_ar1 = np.argmin(ar1 < ar2_smallest_value)
max_index_ar1 = np.argmax(ar1 > ar2_biggest_value)
min_index_ar2 = np.argmin(ar2 < ar1_smallest_value)
max_index_ar2 = np.argmax(ar2 > ar1_biggest_value)
if min_index_ar1 < 0:
min_index_ar1 = 0
if min_index_ar2 < 0:
min_index_ar2 = 0
if max_index_ar1 == 0 or max_index_ar1 > ar1.shape[0]:
max_index_ar1 = ar1.shape[0]
if max_index_ar2 == 0 or max_index_ar2 > ar2.shape[0]:
max_index_ar2 = ar2.shape[0]
return ar1[min_index_ar1:max_index_ar1], ar2[min_index_ar2:max_index_ar2] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:get_hits_in_events; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:hits_array; 5, identifier:events; 6, default_parameter; 6, 7; 6, 8; 7, identifier:assume_sorted; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:condition; 11, None; 12, block; 12, 13; 12, 15; 12, 27; 12, 58; 12, 158; 13, expression_statement; 13, 14; 14, string:'''Selects the hits that occurred in events and optional selection criterion.
If a event range can be defined use the get_data_in_event_range function. It is much faster.
Parameters
----------
hits_array : numpy.array
events : array
assume_sorted : bool
Is true if the events to select are sorted from low to high value. Increases speed by 35%.
condition : string
A condition that is applied to the hits in numexpr. Only if the expression evaluates to True the hit is taken.
Returns
-------
numpy.array
hit array with the hits in events.
'''; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logging; 19, identifier:debug; 20, argument_list; 20, 21; 21, binary_operator:%; 21, 22; 21, 23; 22, string:"Calculate hits that exists in the given %d events."; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:events; 27, if_statement; 27, 28; 27, 29; 28, identifier:assume_sorted; 29, block; 29, 30; 29, 42; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, pattern_list; 32, 33; 32, 34; 33, identifier:events; 34, identifier:_; 35, call; 35, 36; 35, 37; 36, identifier:reduce_sorted_to_intersect; 37, argument_list; 37, 38; 37, 39; 38, identifier:events; 39, subscript; 39, 40; 39, 41; 40, identifier:hits_array; 41, string:'event_number'; 42, if_statement; 42, 43; 42, 50; 43, comparison_operator:==; 43, 44; 43, 49; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:events; 47, identifier:shape; 48, integer:0; 49, integer:0; 50, block; 50, 51; 51, return_statement; 51, 52; 52, subscript; 52, 53; 52, 54; 53, identifier:hits_array; 54, slice; 54, 55; 54, 56; 54, 57; 55, integer:0; 56, colon; 57, integer:0; 58, try_statement; 58, 59; 58, 146; 59, block; 59, 60; 59, 96; 60, if_statement; 60, 61; 60, 62; 60, 75; 61, identifier:assume_sorted; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:selection; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:analysis_utils; 69, identifier:in1d_events; 70, argument_list; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:hits_array; 73, string:'event_number'; 74, identifier:events; 75, else_clause; 75, 76; 76, block; 76, 77; 76, 84; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:logging; 81, identifier:warning; 82, argument_list; 82, 83; 83, string:'Events are usually sorted. Are you sure you want this?'; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:selection; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:np; 90, identifier:in1d; 91, argument_list; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:hits_array; 94, string:'event_number'; 95, identifier:events; 96, if_statement; 96, 97; 96, 100; 96, 107; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:condition; 99, None; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:hits_in_events; 104, subscript; 104, 105; 104, 106; 105, identifier:hits_array; 106, identifier:selection; 107, else_clause; 107, 108; 108, block; 108, 109; 108, 133; 109, for_statement; 109, 110; 109, 111; 109, 121; 110, identifier:variable; 111, call; 111, 112; 111, 113; 112, identifier:set; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:re; 117, identifier:findall; 118, argument_list; 118, 119; 118, 120; 119, string:r'[a-zA-Z_]+'; 120, identifier:condition; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:exec; 125, argument_list; 125, 126; 126, binary_operator:+; 126, 127; 126, 132; 127, binary_operator:+; 127, 128; 127, 131; 128, binary_operator:+; 128, 129; 128, 130; 129, identifier:variable; 130, string:' = hits_array[\''; 131, identifier:variable; 132, string:'\']'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:hits_in_events; 136, subscript; 136, 137; 136, 138; 137, identifier:hits_array; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:ne; 141, identifier:evaluate; 142, argument_list; 142, 143; 143, binary_operator:+; 143, 144; 143, 145; 144, identifier:condition; 145, string:' & selection'; 146, except_clause; 146, 147; 146, 148; 147, identifier:MemoryError; 148, block; 148, 149; 148, 156; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:logging; 153, identifier:error; 154, argument_list; 154, 155; 155, string:'There are too many hits to do in RAM operations. Consider decreasing chunk size and use the write_hits_in_events function instead.'; 156, raise_statement; 156, 157; 157, identifier:MemoryError; 158, return_statement; 158, 159; 159, identifier:hits_in_events | def get_hits_in_events(hits_array, events, assume_sorted=True, condition=None):
'''Selects the hits that occurred in events and optional selection criterion.
If a event range can be defined use the get_data_in_event_range function. It is much faster.
Parameters
----------
hits_array : numpy.array
events : array
assume_sorted : bool
Is true if the events to select are sorted from low to high value. Increases speed by 35%.
condition : string
A condition that is applied to the hits in numexpr. Only if the expression evaluates to True the hit is taken.
Returns
-------
numpy.array
hit array with the hits in events.
'''
logging.debug("Calculate hits that exists in the given %d events." % len(events))
if assume_sorted:
events, _ = reduce_sorted_to_intersect(events, hits_array['event_number'])
if events.shape[0] == 0:
return hits_array[0:0]
try:
if assume_sorted:
selection = analysis_utils.in1d_events(hits_array['event_number'], events)
else:
logging.warning('Events are usually sorted. Are you sure you want this?')
selection = np.in1d(hits_array['event_number'], events)
if condition is None:
hits_in_events = hits_array[selection]
else:
for variable in set(re.findall(r'[a-zA-Z_]+', condition)):
exec(variable + ' = hits_array[\'' + variable + '\']')
hits_in_events = hits_array[ne.evaluate(condition + ' & selection')]
except MemoryError:
logging.error('There are too many hits to do in RAM operations. Consider decreasing chunk size and use the write_hits_in_events function instead.')
raise MemoryError
return hits_in_events |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:natsorted; 3, parameters; 3, 4; 3, 5; 4, identifier:seq; 5, default_parameter; 5, 6; 5, 7; 6, identifier:cmp; 7, identifier:natcmp; 8, block; 8, 9; 8, 11; 8, 14; 8, 23; 8, 29; 9, expression_statement; 9, 10; 10, string:"Returns a copy of seq, sorted by natural string sort."; 11, import_statement; 11, 12; 12, dotted_name; 12, 13; 13, identifier:copy; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:temp; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:copy; 20, identifier:copy; 21, argument_list; 21, 22; 22, identifier:seq; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:natsort; 26, argument_list; 26, 27; 26, 28; 27, identifier:temp; 28, identifier:cmp; 29, return_statement; 29, 30; 30, identifier:temp | def natsorted(seq, cmp=natcmp):
"Returns a copy of seq, sorted by natural string sort."
import copy
temp = copy.copy(seq)
natsort(temp, cmp)
return temp |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort2groups; 3, parameters; 3, 4; 3, 5; 4, identifier:array; 5, default_parameter; 5, 6; 5, 7; 6, identifier:gpat; 7, list:['_R1','_R2']; 7, 8; 7, 9; 8, string:'_R1'; 9, string:'_R2'; 10, block; 10, 11; 10, 22; 10, 26; 10, 62; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:groups; 14, list_comprehension; 14, 15; 14, 19; 15, call; 15, 16; 15, 17; 16, identifier:REGroup; 17, argument_list; 17, 18; 18, identifier:gp; 19, for_in_clause; 19, 20; 19, 21; 20, identifier:gp; 21, identifier:gpat; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:unmatched; 25, list:[]; 26, for_statement; 26, 27; 26, 28; 26, 29; 27, identifier:item; 28, identifier:array; 29, block; 29, 30; 29, 34; 29, 51; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:matched; 33, False; 34, for_statement; 34, 35; 34, 36; 34, 37; 35, identifier:m; 36, identifier:groups; 37, block; 37, 38; 38, if_statement; 38, 39; 38, 45; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:m; 42, identifier:match; 43, argument_list; 43, 44; 44, identifier:item; 45, block; 45, 46; 45, 50; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:matched; 49, True; 50, break_statement; 51, if_statement; 51, 52; 51, 54; 52, not_operator; 52, 53; 53, identifier:matched; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:unmatched; 59, identifier:append; 60, argument_list; 60, 61; 61, identifier:item; 62, return_statement; 62, 63; 63, expression_list; 63, 64; 63, 74; 64, list_comprehension; 64, 65; 64, 71; 65, call; 65, 66; 65, 67; 66, identifier:sorted; 67, argument_list; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:m; 70, identifier:list; 71, for_in_clause; 71, 72; 71, 73; 72, identifier:m; 73, identifier:groups; 74, call; 74, 75; 74, 76; 75, identifier:sorted; 76, argument_list; 76, 77; 77, identifier:unmatched | def sort2groups(array, gpat=['_R1','_R2']):
groups = [REGroup(gp) for gp in gpat]
unmatched = []
for item in array:
matched = False
for m in groups:
if m.match(item):
matched = True
break
if not matched: unmatched.append(item)
return [sorted(m.list) for m in groups], sorted(unmatched) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_and_distribute; 3, parameters; 3, 4; 3, 5; 4, identifier:array; 5, default_parameter; 5, 6; 5, 7; 6, identifier:splits; 7, integer:2; 8, block; 8, 9; 8, 24; 8, 37; 8, 44; 8, 69; 8, 77; 8, 111; 9, if_statement; 9, 10; 9, 18; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:array; 15, tuple; 15, 16; 15, 17; 16, identifier:list; 17, identifier:tuple; 18, block; 18, 19; 19, raise_statement; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:TypeError; 22, argument_list; 22, 23; 23, string:"array must be a list"; 24, if_statement; 24, 25; 24, 31; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 30; 29, identifier:splits; 30, identifier:int; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:TypeError; 35, argument_list; 35, 36; 36, string:"splits must be an integer"; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:remaining; 40, call; 40, 41; 40, 42; 41, identifier:sorted; 42, argument_list; 42, 43; 43, identifier:array; 44, if_statement; 44, 45; 44, 52; 44, 60; 45, comparison_operator:<; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:sys; 48, identifier:version_info; 49, tuple; 49, 50; 49, 51; 50, integer:3; 51, integer:0; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:myrange; 56, call; 56, 57; 56, 58; 57, identifier:xrange; 58, argument_list; 58, 59; 59, identifier:splits; 60, else_clause; 60, 61; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:myrange; 65, call; 65, 66; 65, 67; 66, identifier:range; 67, argument_list; 67, 68; 68, identifier:splits; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:groups; 72, list_comprehension; 72, 73; 72, 74; 73, list:[]; 74, for_in_clause; 74, 75; 74, 76; 75, identifier:i; 76, identifier:myrange; 77, while_statement; 77, 78; 77, 84; 78, comparison_operator:>; 78, 79; 78, 83; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:remaining; 83, integer:0; 84, block; 84, 85; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:i; 87, identifier:myrange; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 96; 90, comparison_operator:>; 90, 91; 90, 95; 91, call; 91, 92; 91, 93; 92, identifier:len; 93, argument_list; 93, 94; 94, identifier:remaining; 95, integer:0; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:groups; 102, identifier:i; 103, identifier:append; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:remaining; 108, identifier:pop; 109, argument_list; 109, 110; 110, integer:0; 111, return_statement; 111, 112; 112, identifier:groups | def sort_and_distribute(array, splits=2):
if not isinstance(array, (list,tuple)): raise TypeError("array must be a list")
if not isinstance(splits, int): raise TypeError("splits must be an integer")
remaining = sorted(array)
if sys.version_info < (3, 0):
myrange = xrange(splits)
else:
myrange = range(splits)
groups = [[] for i in myrange]
while len(remaining) > 0:
for i in myrange:
if len(remaining) > 0: groups[i].append(remaining.pop(0))
return groups |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 9; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:section; 7, type; 7, 8; 8, identifier:int; 9, default_parameter; 9, 10; 9, 11; 10, identifier:order; 11, None; 12, block; 12, 13; 12, 21; 12, 29; 12, 35; 12, 80; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:attr; 16, subscript; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:header; 20, identifier:section; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, pattern_list; 23, 24; 23, 25; 24, identifier:old_i; 25, identifier:old_sort; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:sort_state; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:beginResetModel; 34, argument_list; 35, if_statement; 35, 36; 35, 39; 35, 60; 36, comparison_operator:==; 36, 37; 36, 38; 37, identifier:section; 38, identifier:old_i; 39, block; 39, 40; 39, 51; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:collection; 46, identifier:sort; 47, argument_list; 47, 48; 47, 49; 48, identifier:attr; 49, not_operator; 49, 50; 50, identifier:old_sort; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:sort_state; 56, tuple; 56, 57; 56, 58; 57, identifier:section; 58, not_operator; 58, 59; 59, identifier:old_sort; 60, else_clause; 60, 61; 61, block; 61, 62; 61, 72; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:collection; 68, identifier:sort; 69, argument_list; 69, 70; 69, 71; 70, identifier:attr; 71, True; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:sort_state; 77, tuple; 77, 78; 77, 79; 78, identifier:section; 79, True; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:endResetModel; 85, argument_list | def sort(self, section: int, order=None):
attr = self.header[section]
old_i, old_sort = self.sort_state
self.beginResetModel()
if section == old_i:
self.collection.sort(attr, not old_sort)
self.sort_state = (section, not old_sort)
else:
self.collection.sort(attr, True)
self.sort_state = (section, True)
self.endResetModel() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:set_collection; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:collection; 6, block; 6, 7; 6, 13; 6, 19; 6, 28; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:beginResetModel; 12, argument_list; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:collection; 18, identifier:collection; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:sort_state; 24, tuple; 24, 25; 24, 27; 25, unary_operator:-; 25, 26; 26, integer:1; 27, False; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:endResetModel; 33, argument_list | def set_collection(self, collection):
self.beginResetModel()
self.collection = collection
self.sort_state = (-1, False)
self.endResetModel() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:copy; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:items; 7, None; 8, block; 8, 9; 9, return_statement; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:NGram; 12, argument_list; 12, 13; 12, 19; 12, 22; 12, 25; 12, 28; 12, 31; 12, 34; 13, conditional_expression:if; 13, 14; 13, 15; 13, 18; 14, identifier:items; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:items; 17, None; 18, identifier:self; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:threshold; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:warp; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_key; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:N; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_pad_len; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_pad_char | def copy(self, items=None):
return NGram(items if items is not None else self,
self.threshold, self.warp, self._key,
self.N, self._pad_len, self._pad_char) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:items_sharing_ngrams; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:query; 6, block; 6, 7; 6, 11; 6, 15; 6, 89; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:shared; 10, dictionary; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:remaining; 14, dictionary; 15, for_statement; 15, 16; 15, 17; 15, 23; 16, identifier:ngram; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:split; 21, argument_list; 21, 22; 22, identifier:query; 23, block; 23, 24; 24, try_statement; 24, 25; 24, 85; 25, block; 25, 26; 26, for_statement; 26, 27; 26, 30; 26, 39; 27, pattern_list; 27, 28; 27, 29; 28, identifier:match; 29, identifier:count; 30, call; 30, 31; 30, 38; 31, attribute; 31, 32; 31, 37; 32, subscript; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_grams; 36, identifier:ngram; 37, identifier:items; 38, argument_list; 39, block; 39, 40; 39, 54; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 51; 42, attribute; 42, 43; 42, 50; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:remaining; 46, identifier:setdefault; 47, argument_list; 47, 48; 47, 49; 48, identifier:ngram; 49, dictionary; 50, identifier:setdefault; 51, argument_list; 51, 52; 51, 53; 52, identifier:match; 53, identifier:count; 54, if_statement; 54, 55; 54, 62; 55, comparison_operator:>; 55, 56; 55, 61; 56, subscript; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:remaining; 59, identifier:ngram; 60, identifier:match; 61, integer:0; 62, block; 62, 63; 62, 71; 62, 79; 63, expression_statement; 63, 64; 64, augmented_assignment:-=; 64, 65; 64, 70; 65, subscript; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:remaining; 68, identifier:ngram; 69, identifier:match; 70, integer:1; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:shared; 75, identifier:setdefault; 76, argument_list; 76, 77; 76, 78; 77, identifier:match; 78, integer:0; 79, expression_statement; 79, 80; 80, augmented_assignment:+=; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:shared; 83, identifier:match; 84, integer:1; 85, except_clause; 85, 86; 85, 87; 86, identifier:KeyError; 87, block; 87, 88; 88, pass_statement; 89, return_statement; 89, 90; 90, identifier:shared | def items_sharing_ngrams(self, query):
shared = {}
remaining = {}
for ngram in self.split(query):
try:
for match, count in self._grams[ngram].items():
remaining.setdefault(ngram, {}).setdefault(match, count)
if remaining[ngram][match] > 0:
remaining[ngram][match] -= 1
shared.setdefault(match, 0)
shared[match] += 1
except KeyError:
pass
return shared |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:searchitem; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:item; 6, default_parameter; 6, 7; 6, 8; 7, identifier:threshold; 8, None; 9, block; 9, 10; 10, return_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:search; 15, argument_list; 15, 16; 15, 22; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:key; 20, argument_list; 20, 21; 21, identifier:item; 22, identifier:threshold | def searchitem(self, item, threshold=None):
return self.search(self.key(item), threshold) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:query; 6, default_parameter; 6, 7; 6, 8; 7, identifier:threshold; 8, None; 9, block; 9, 10; 9, 21; 9, 25; 9, 97; 9, 114; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:threshold; 13, conditional_expression:if; 13, 14; 13, 15; 13, 18; 14, identifier:threshold; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:threshold; 17, None; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:threshold; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:results; 24, list:[]; 25, for_statement; 25, 26; 25, 29; 25, 39; 26, pattern_list; 26, 27; 26, 28; 27, identifier:match; 28, identifier:samegrams; 29, call; 29, 30; 29, 38; 30, attribute; 30, 31; 30, 37; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:items_sharing_ngrams; 35, argument_list; 35, 36; 36, identifier:query; 37, identifier:items; 38, argument_list; 39, block; 39, 40; 39, 70; 39, 83; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:allgrams; 43, parenthesized_expression; 43, 44; 44, binary_operator:+; 44, 45; 44, 69; 45, binary_operator:-; 45, 46; 45, 68; 46, binary_operator:-; 46, 47; 46, 62; 47, binary_operator:+; 47, 48; 47, 57; 48, call; 48, 49; 48, 50; 49, identifier:len; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:pad; 55, argument_list; 55, 56; 56, identifier:query; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:length; 61, identifier:match; 62, parenthesized_expression; 62, 63; 63, binary_operator:*; 63, 64; 63, 65; 64, integer:2; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:N; 68, identifier:samegrams; 69, integer:2; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:similarity; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:ngram_similarity; 77, argument_list; 77, 78; 77, 79; 77, 80; 78, identifier:samegrams; 79, identifier:allgrams; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:warp; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:>=; 84, 85; 84, 86; 85, identifier:similarity; 86, identifier:threshold; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:results; 92, identifier:append; 93, argument_list; 93, 94; 94, tuple; 94, 95; 94, 96; 95, identifier:match; 96, identifier:similarity; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:results; 101, identifier:sort; 102, argument_list; 102, 103; 102, 111; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:key; 105, lambda; 105, 106; 105, 108; 106, lambda_parameters; 106, 107; 107, identifier:x; 108, subscript; 108, 109; 108, 110; 109, identifier:x; 110, integer:1; 111, keyword_argument; 111, 112; 111, 113; 112, identifier:reverse; 113, True; 114, return_statement; 114, 115; 115, identifier:results | def search(self, query, threshold=None):
threshold = threshold if threshold is not None else self.threshold
results = []
for match, samegrams in self.items_sharing_ngrams(query).items():
allgrams = (len(self.pad(query))
+ self.length[match] - (2 * self.N) - samegrams + 2)
similarity = self.ngram_similarity(samegrams, allgrams, self.warp)
if similarity >= threshold:
results.append((match, similarity))
results.sort(key=lambda x: x[1], reverse=True)
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:clear; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 22; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 15; 8, attribute; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:super; 11, argument_list; 11, 12; 11, 13; 12, identifier:NGram; 13, identifier:self; 14, identifier:clear; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_grams; 21, dictionary; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:length; 27, dictionary | def clear(self):
super(NGram, self).clear()
self._grams = {}
self.length = {} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:union; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:others; 7, block; 7, 8; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:copy; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 22; 15, attribute; 15, 16; 15, 21; 16, call; 16, 17; 16, 18; 17, identifier:super; 18, argument_list; 18, 19; 18, 20; 19, identifier:NGram; 20, identifier:self; 21, identifier:union; 22, argument_list; 22, 23; 23, list_splat; 23, 24; 24, identifier:others | def union(self, *others):
return self.copy(super(NGram, self).union(*others)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:symmetric_difference; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 7, return_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:copy; 12, argument_list; 12, 13; 13, call; 13, 14; 13, 21; 14, attribute; 14, 15; 14, 20; 15, call; 15, 16; 15, 17; 16, identifier:super; 17, argument_list; 17, 18; 17, 19; 18, identifier:NGram; 19, identifier:self; 20, identifier:symmetric_difference; 21, argument_list; 21, 22; 22, identifier:other | def symmetric_difference(self, other):
return self.copy(super(NGram, self).symmetric_difference(other)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:symmetric_difference_update; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 20; 6, 27; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:intersection; 10, call; 10, 11; 10, 18; 11, attribute; 11, 12; 11, 17; 12, call; 12, 13; 12, 14; 13, identifier:super; 14, argument_list; 14, 15; 14, 16; 15, identifier:NGram; 16, identifier:self; 17, identifier:intersection; 18, argument_list; 18, 19; 19, identifier:other; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:update; 25, argument_list; 25, 26; 26, identifier:other; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:difference_update; 32, argument_list; 32, 33; 33, identifier:intersection | def symmetric_difference_update(self, other):
intersection = super(NGram, self).intersection(other)
self.update(other)
self.difference_update(intersection) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:download; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 4, identifier:directory; 5, default_parameter; 5, 6; 5, 7; 6, identifier:master_token; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:member; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:access_token; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:source; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:project_data; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:max_size; 22, string:'128m'; 23, default_parameter; 23, 24; 23, 25; 24, identifier:verbose; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:debug; 28, False; 29, default_parameter; 29, 30; 29, 31; 30, identifier:memberlist; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:excludelist; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:id_filename; 37, False; 38, block; 38, 39; 38, 45; 38, 63; 38, 70; 38, 77; 38, 96; 38, 109; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:set_log_level; 42, argument_list; 42, 43; 42, 44; 43, identifier:debug; 44, identifier:verbose; 45, if_statement; 45, 46; 45, 55; 46, boolean_operator:and; 46, 47; 46, 51; 47, parenthesized_expression; 47, 48; 48, boolean_operator:or; 48, 49; 48, 50; 49, identifier:memberlist; 50, identifier:excludelist; 51, parenthesized_expression; 51, 52; 52, boolean_operator:or; 52, 53; 52, 54; 53, identifier:member; 54, identifier:access_token; 55, block; 55, 56; 56, raise_statement; 56, 57; 57, call; 57, 58; 57, 59; 58, identifier:UsageError; 59, argument_list; 59, 60; 60, concatenated_string; 60, 61; 60, 62; 61, string:'Please do not provide a memberlist or excludelist '; 62, string:'when retrieving data for a single member.'; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:memberlist; 66, call; 66, 67; 66, 68; 67, identifier:read_id_list; 68, argument_list; 68, 69; 69, identifier:memberlist; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:excludelist; 73, call; 73, 74; 73, 75; 74, identifier:read_id_list; 75, argument_list; 75, 76; 76, identifier:excludelist; 77, if_statement; 77, 78; 77, 88; 78, boolean_operator:or; 78, 79; 78, 84; 79, not_operator; 79, 80; 80, parenthesized_expression; 80, 81; 81, boolean_operator:or; 81, 82; 81, 83; 82, identifier:master_token; 83, identifier:access_token; 84, parenthesized_expression; 84, 85; 85, boolean_operator:and; 85, 86; 85, 87; 86, identifier:master_token; 87, identifier:access_token; 88, block; 88, 89; 89, raise_statement; 89, 90; 90, call; 90, 91; 90, 92; 91, identifier:UsageError; 92, argument_list; 92, 93; 93, concatenated_string; 93, 94; 93, 95; 94, string:'Please specify either a master access token (-T), '; 95, string:'or an OAuth2 user access token (-t).'; 96, if_statement; 96, 97; 96, 101; 97, parenthesized_expression; 97, 98; 98, boolean_operator:and; 98, 99; 98, 100; 99, identifier:source; 100, identifier:project_data; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:UsageError; 105, argument_list; 105, 106; 106, concatenated_string; 106, 107; 106, 108; 107, string:"It doesn't make sense to use both 'source' and"; 108, string:"'project-data' options!"; 109, if_statement; 109, 110; 109, 111; 109, 205; 110, identifier:master_token; 111, block; 111, 112; 111, 121; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:project; 115, call; 115, 116; 115, 117; 116, identifier:OHProject; 117, argument_list; 117, 118; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:master_access_token; 120, identifier:master_token; 121, if_statement; 121, 122; 121, 123; 121, 176; 122, identifier:member; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 126; 124, 149; 125, identifier:project_data; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:project; 131, identifier:download_member_project_data; 132, argument_list; 132, 133; 132, 140; 132, 143; 132, 146; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:member_data; 135, subscript; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:project; 138, identifier:project_data; 139, identifier:member; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:target_member_dir; 142, identifier:directory; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:max_size; 145, identifier:max_size; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:id_filename; 148, identifier:id_filename; 149, else_clause; 149, 150; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:project; 155, identifier:download_member_shared; 156, argument_list; 156, 157; 156, 164; 156, 167; 156, 170; 156, 173; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:member_data; 159, subscript; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:project; 162, identifier:project_data; 163, identifier:member; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:target_member_dir; 166, identifier:directory; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:source; 169, identifier:source; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:max_size; 172, identifier:max_size; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:id_filename; 175, identifier:id_filename; 176, else_clause; 176, 177; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:project; 182, identifier:download_all; 183, argument_list; 183, 184; 183, 187; 183, 190; 183, 193; 183, 196; 183, 199; 183, 202; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:target_dir; 186, identifier:directory; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:source; 189, identifier:source; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:max_size; 192, identifier:max_size; 193, keyword_argument; 193, 194; 193, 195; 194, identifier:memberlist; 195, identifier:memberlist; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:excludelist; 198, identifier:excludelist; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:project_data; 201, identifier:project_data; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:id_filename; 204, identifier:id_filename; 205, else_clause; 205, 206; 206, block; 206, 207; 206, 217; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:member_data; 210, call; 210, 211; 210, 212; 211, identifier:exchange_oauth2_member; 212, argument_list; 212, 213; 212, 214; 213, identifier:access_token; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:all_files; 216, True; 217, if_statement; 217, 218; 217, 219; 217, 238; 218, identifier:project_data; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:OHProject; 224, identifier:download_member_project_data; 225, argument_list; 225, 226; 225, 229; 225, 232; 225, 235; 226, keyword_argument; 226, 227; 226, 228; 227, identifier:member_data; 228, identifier:member_data; 229, keyword_argument; 229, 230; 229, 231; 230, identifier:target_member_dir; 231, identifier:directory; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:max_size; 234, identifier:max_size; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:id_filename; 237, identifier:id_filename; 238, else_clause; 238, 239; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:OHProject; 244, identifier:download_member_shared; 245, argument_list; 245, 246; 245, 249; 245, 252; 245, 255; 245, 258; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:member_data; 248, identifier:member_data; 249, keyword_argument; 249, 250; 249, 251; 250, identifier:target_member_dir; 251, identifier:directory; 252, keyword_argument; 252, 253; 252, 254; 253, identifier:source; 254, identifier:source; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:max_size; 257, identifier:max_size; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:id_filename; 260, identifier:id_filename | def download(directory, master_token=None, member=None, access_token=None,
source=None, project_data=False, max_size='128m', verbose=False,
debug=False, memberlist=None, excludelist=None,
id_filename=False):
set_log_level(debug, verbose)
if (memberlist or excludelist) and (member or access_token):
raise UsageError('Please do not provide a memberlist or excludelist '
'when retrieving data for a single member.')
memberlist = read_id_list(memberlist)
excludelist = read_id_list(excludelist)
if not (master_token or access_token) or (master_token and access_token):
raise UsageError('Please specify either a master access token (-T), '
'or an OAuth2 user access token (-t).')
if (source and project_data):
raise UsageError("It doesn't make sense to use both 'source' and"
"'project-data' options!")
if master_token:
project = OHProject(master_access_token=master_token)
if member:
if project_data:
project.download_member_project_data(
member_data=project.project_data[member],
target_member_dir=directory,
max_size=max_size,
id_filename=id_filename)
else:
project.download_member_shared(
member_data=project.project_data[member],
target_member_dir=directory,
source=source,
max_size=max_size,
id_filename=id_filename)
else:
project.download_all(target_dir=directory,
source=source,
max_size=max_size,
memberlist=memberlist,
excludelist=excludelist,
project_data=project_data,
id_filename=id_filename)
else:
member_data = exchange_oauth2_member(access_token, all_files=True)
if project_data:
OHProject.download_member_project_data(member_data=member_data,
target_member_dir=directory,
max_size=max_size,
id_filename=id_filename)
else:
OHProject.download_member_shared(member_data=member_data,
target_member_dir=directory,
source=source,
max_size=max_size,
id_filename=id_filename) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:columns; 7, dictionary_splat_pattern; 7, 8; 8, identifier:options; 9, block; 9, 10; 9, 22; 9, 116; 9, 129; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sorts; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:meta; 18, identifier:setdefault; 19, argument_list; 19, 20; 19, 21; 20, string:'sort'; 21, list:[]; 22, for_statement; 22, 23; 22, 24; 22, 25; 23, identifier:column; 24, identifier:columns; 25, block; 25, 26; 25, 94; 25, 107; 26, if_statement; 26, 27; 26, 32; 26, 39; 26, 82; 27, call; 27, 28; 27, 29; 28, identifier:isinstance; 29, argument_list; 29, 30; 29, 31; 30, identifier:column; 31, identifier:Column; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:identifier; 36, attribute; 36, 37; 36, 38; 37, identifier:column; 38, identifier:id; 39, elif_clause; 39, 40; 39, 47; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 44; 43, identifier:column; 44, attribute; 44, 45; 44, 46; 45, identifier:utils; 46, identifier:basestring; 47, block; 47, 48; 47, 65; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:descending; 51, boolean_operator:or; 51, 52; 51, 58; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:column; 55, identifier:startswith; 56, argument_list; 56, 57; 57, string:'-'; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:options; 61, identifier:get; 62, argument_list; 62, 63; 62, 64; 63, string:'descending'; 64, False; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:identifier; 68, attribute; 68, 69; 68, 81; 69, subscript; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:api; 74, identifier:columns; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:column; 78, identifier:lstrip; 79, argument_list; 79, 80; 80, string:'-'; 81, identifier:id; 82, else_clause; 82, 83; 83, block; 83, 84; 84, raise_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:ValueError; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, string:"Can only sort on columns or column strings. Received: {}"; 91, identifier:format; 92, argument_list; 92, 93; 93, identifier:column; 94, if_statement; 94, 95; 94, 96; 94, 101; 95, identifier:descending; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:sign; 100, string:'-'; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:sign; 106, string:''; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:sorts; 111, identifier:append; 112, argument_list; 112, 113; 113, binary_operator:+; 113, 114; 113, 115; 114, identifier:sign; 115, identifier:identifier; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:raw; 122, string:'sort'; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, string:","; 126, identifier:join; 127, argument_list; 127, 128; 128, identifier:sorts; 129, return_statement; 129, 130; 130, identifier:self | def sort(self, *columns, **options):
sorts = self.meta.setdefault('sort', [])
for column in columns:
if isinstance(column, Column):
identifier = column.id
elif isinstance(column, utils.basestring):
descending = column.startswith('-') or options.get('descending', False)
identifier = self.api.columns[column.lstrip('-')].id
else:
raise ValueError("Can only sort on columns or column strings. Received: {}".format(column))
if descending:
sign = '-'
else:
sign = ''
sorts.append(sign + identifier)
self.raw['sort'] = ",".join(sorts)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:getList; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:aspList; 6, block; 6, 7; 6, 23; 6, 39; 6, 55; 6, 63; 6, 78; 6, 86; 6, 102; 6, 118; 6, 128; 6, 132; 6, 204; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:objects; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_elements; 14, argument_list; 14, 15; 14, 18; 14, 21; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:SIG_OBJECTS; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:N; 21, list:[0]; 21, 22; 22, integer:0; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:houses; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_elements; 30, argument_list; 30, 31; 30, 34; 30, 37; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:SIG_HOUSES; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:N; 37, list:[0]; 37, 38; 38, integer:0; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:angles; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_elements; 46, argument_list; 46, 47; 46, 50; 46, 53; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:SIG_ANGLES; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:N; 53, list:[0]; 53, 54; 54, integer:0; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:significators; 58, binary_operator:+; 58, 59; 58, 62; 59, binary_operator:+; 59, 60; 59, 61; 60, identifier:objects; 61, identifier:houses; 62, identifier:angles; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:objects; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_elements; 70, argument_list; 70, 71; 70, 74; 70, 77; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:SIG_OBJECTS; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:N; 77, identifier:aspList; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:terms; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:_terms; 85, argument_list; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:antiscias; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_elements; 93, argument_list; 93, 94; 93, 97; 93, 100; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:SIG_OBJECTS; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:A; 100, list:[0]; 100, 101; 101, integer:0; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:cantiscias; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:_elements; 109, argument_list; 109, 110; 109, 113; 109, 116; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:SIG_OBJECTS; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:C; 116, list:[0]; 116, 117; 117, integer:0; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:promissors; 121, binary_operator:+; 121, 122; 121, 127; 122, binary_operator:+; 122, 123; 122, 126; 123, binary_operator:+; 123, 124; 123, 125; 124, identifier:objects; 125, identifier:terms; 126, identifier:antiscias; 127, identifier:cantiscias; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:res; 131, list:[]; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:prom; 134, identifier:promissors; 135, block; 135, 136; 136, for_statement; 136, 137; 136, 138; 136, 139; 137, identifier:sig; 138, identifier:significators; 139, block; 139, 140; 139, 151; 139, 161; 140, if_statement; 140, 141; 140, 149; 141, parenthesized_expression; 141, 142; 142, comparison_operator:==; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:prom; 145, string:'id'; 146, subscript; 146, 147; 146, 148; 147, identifier:sig; 148, string:'id'; 149, block; 149, 150; 150, continue_statement; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:arcs; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:_arc; 158, argument_list; 158, 159; 158, 160; 159, identifier:prom; 160, identifier:sig; 161, for_statement; 161, 162; 161, 165; 161, 172; 162, tuple_pattern; 162, 163; 162, 164; 163, identifier:x; 164, identifier:y; 165, list:[('arcm', 'M'), ('arcz', 'Z')]; 165, 166; 165, 169; 166, tuple; 166, 167; 166, 168; 167, string:'arcm'; 168, string:'M'; 169, tuple; 169, 170; 169, 171; 170, string:'arcz'; 171, string:'Z'; 172, block; 172, 173; 172, 179; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:arc; 176, subscript; 176, 177; 176, 178; 177, identifier:arcs; 178, identifier:x; 179, if_statement; 179, 180; 179, 186; 180, comparison_operator:<; 180, 181; 180, 182; 180, 183; 181, integer:0; 182, identifier:arc; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:MAX_ARC; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:res; 191, identifier:append; 192, argument_list; 192, 193; 193, list:[
arcs[x],
prom['id'],
sig['id'],
y,
]; 193, 194; 193, 197; 193, 200; 193, 203; 194, subscript; 194, 195; 194, 196; 195, identifier:arcs; 196, identifier:x; 197, subscript; 197, 198; 197, 199; 198, identifier:prom; 199, string:'id'; 200, subscript; 200, 201; 200, 202; 201, identifier:sig; 202, string:'id'; 203, identifier:y; 204, return_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:sorted; 207, argument_list; 207, 208; 208, identifier:res | def getList(self, aspList):
objects = self._elements(self.SIG_OBJECTS, self.N, [0])
houses = self._elements(self.SIG_HOUSES, self.N, [0])
angles = self._elements(self.SIG_ANGLES, self.N, [0])
significators = objects + houses + angles
objects = self._elements(self.SIG_OBJECTS, self.N, aspList)
terms = self._terms()
antiscias = self._elements(self.SIG_OBJECTS, self.A, [0])
cantiscias = self._elements(self.SIG_OBJECTS, self.C, [0])
promissors = objects + terms + antiscias + cantiscias
res = []
for prom in promissors:
for sig in significators:
if (prom['id'] == sig['id']):
continue
arcs = self._arc(prom, sig)
for (x,y) in [('arcm', 'M'), ('arcz', 'Z')]:
arc = arcs[x]
if 0 < arc < self.MAX_ARC:
res.append([
arcs[x],
prom['id'],
sig['id'],
y,
])
return sorted(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:knt2mlt; 3, parameters; 3, 4; 4, identifier:t; 5, block; 5, 6; 5, 15; 5, 27; 5, 31; 5, 35; 5, 76; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:t; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:np; 12, identifier:atleast_1d; 13, argument_list; 13, 14; 14, identifier:t; 15, if_statement; 15, 16; 15, 21; 16, comparison_operator:>; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:t; 19, identifier:ndim; 20, integer:1; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ValueError; 25, argument_list; 25, 26; 26, string:"t must be a list or a rank-1 array"; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:out; 30, list:[]; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:e; 34, None; 35, for_statement; 35, 36; 35, 37; 35, 45; 36, identifier:k; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 40, subscript; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:t; 43, identifier:shape; 44, integer:0; 45, block; 45, 46; 45, 69; 46, if_statement; 46, 47; 46, 52; 46, 63; 47, comparison_operator:!=; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:t; 50, identifier:k; 51, identifier:e; 52, block; 52, 53; 52, 59; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:e; 56, subscript; 56, 57; 56, 58; 57, identifier:t; 58, identifier:k; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:count; 62, integer:0; 63, else_clause; 63, 64; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, augmented_assignment:+=; 66, 67; 66, 68; 67, identifier:count; 68, integer:1; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:out; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:count; 76, return_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:np; 80, identifier:array; 81, argument_list; 81, 82; 82, identifier:out | def knt2mlt(t):
t = np.atleast_1d(t)
if t.ndim > 1:
raise ValueError("t must be a list or a rank-1 array")
out = []
e = None
for k in range(t.shape[0]):
if t[k] != e:
e = t[k]
count = 0
else:
count += 1
out.append(count)
return np.array( out ) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:get_gallery; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:section; 7, string:'hot'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort; 10, string:'viral'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:window; 13, string:'day'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:show_viral; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:limit; 19, None; 20, block; 20, 21; 20, 41; 20, 53; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:url; 24, parenthesized_expression; 24, 25; 25, binary_operator:+; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_base_url; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, concatenated_string; 31, 32; 31, 33; 32, string:"/3/gallery/{}/{}/{}/{}?showViral="; 33, string:"{}"; 34, identifier:format; 35, argument_list; 35, 36; 35, 37; 35, 38; 35, 39; 35, 40; 36, identifier:section; 37, identifier:sort; 38, identifier:window; 39, string:'{}'; 40, identifier:show_viral; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:resp; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_send_request; 48, argument_list; 48, 49; 48, 50; 49, identifier:url; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:limit; 52, identifier:limit; 53, return_statement; 53, 54; 54, list_comprehension; 54, 55; 54, 60; 55, call; 55, 56; 55, 57; 56, identifier:_get_album_or_image; 57, argument_list; 57, 58; 57, 59; 58, identifier:thing; 59, identifier:self; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:thing; 62, identifier:resp | def get_gallery(self, section='hot', sort='viral', window='day',
show_viral=True, limit=None):
url = (self._base_url + "/3/gallery/{}/{}/{}/{}?showViral="
"{}".format(section, sort, window, '{}', show_viral))
resp = self._send_request(url, limit=limit)
return [_get_album_or_image(thing, self) for thing in resp] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:find_neighbors; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:neighbors; 5, identifier:coords; 6, identifier:I; 7, identifier:source_files; 8, identifier:f; 9, identifier:sides; 10, block; 10, 11; 10, 85; 11, for_statement; 11, 12; 11, 15; 11, 19; 12, pattern_list; 12, 13; 12, 14; 13, identifier:i; 14, identifier:c1; 15, call; 15, 16; 15, 17; 16, identifier:enumerate; 17, argument_list; 17, 18; 18, identifier:coords; 19, block; 19, 20; 19, 28; 19, 40; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:me; 23, subscript; 23, 24; 23, 25; 24, identifier:source_files; 25, subscript; 25, 26; 25, 27; 26, identifier:I; 27, identifier:i; 28, if_statement; 28, 29; 28, 38; 29, comparison_operator:!=; 29, 30; 29, 37; 30, subscript; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:neighbors; 33, identifier:me; 34, subscript; 34, 35; 34, 36; 35, identifier:sides; 36, integer:0; 37, string:''; 38, block; 38, 39; 39, continue_statement; 40, for_statement; 40, 41; 40, 44; 40, 48; 41, pattern_list; 41, 42; 41, 43; 42, identifier:j; 43, identifier:c2; 44, call; 44, 45; 44, 46; 45, identifier:enumerate; 46, argument_list; 46, 47; 47, identifier:coords; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 55; 50, call; 50, 51; 50, 52; 51, identifier:f; 52, argument_list; 52, 53; 52, 54; 53, identifier:c1; 54, identifier:c2; 55, block; 55, 56; 55, 64; 55, 74; 55, 84; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:neigh; 59, subscript; 59, 60; 59, 61; 60, identifier:source_files; 61, subscript; 61, 62; 61, 63; 62, identifier:I; 63, identifier:j; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 73; 66, subscript; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:neighbors; 69, identifier:me; 70, subscript; 70, 71; 70, 72; 71, identifier:sides; 72, integer:0; 73, identifier:neigh; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 83; 76, subscript; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:neighbors; 79, identifier:neigh; 80, subscript; 80, 81; 80, 82; 81, identifier:sides; 82, integer:1; 83, identifier:me; 84, break_statement; 85, return_statement; 85, 86; 86, identifier:neighbors | def find_neighbors(neighbors, coords, I, source_files, f, sides):
for i, c1 in enumerate(coords):
me = source_files[I[i]]
if neighbors[me][sides[0]] != '':
continue
for j, c2 in enumerate(coords):
if f(c1, c2):
neigh = source_files[I[j]]
neighbors[me][sides[0]] = neigh
neighbors[neigh][sides[1]] = me
break
return neighbors |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sortrows; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:i; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:index_out; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:recurse; 13, True; 14, block; 14, 15; 14, 28; 14, 36; 14, 139; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:I; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:np; 21, identifier:argsort; 22, argument_list; 22, 23; 23, subscript; 23, 24; 23, 25; 23, 27; 24, identifier:a; 25, slice; 25, 26; 26, colon; 27, identifier:i; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:a; 31, subscript; 31, 32; 31, 33; 31, 34; 32, identifier:a; 33, identifier:I; 34, slice; 34, 35; 35, colon; 36, if_statement; 36, 37; 36, 50; 37, binary_operator:&; 37, 38; 37, 39; 38, identifier:recurse; 39, parenthesized_expression; 39, 40; 40, comparison_operator:>; 40, 41; 40, 47; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, subscript; 44, 45; 44, 46; 45, identifier:a; 46, integer:0; 47, binary_operator:+; 47, 48; 47, 49; 48, identifier:i; 49, integer:1; 50, block; 50, 51; 51, for_statement; 51, 52; 51, 53; 51, 63; 52, identifier:b; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:np; 56, identifier:unique; 57, argument_list; 57, 58; 58, subscript; 58, 59; 58, 60; 58, 62; 59, identifier:a; 60, slice; 60, 61; 61, colon; 62, identifier:i; 63, block; 63, 64; 63, 74; 63, 94; 63, 122; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:ids; 67, comparison_operator:==; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 70; 68, 72; 69, identifier:a; 70, slice; 70, 71; 71, colon; 72, identifier:i; 73, identifier:b; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:colids; 77, binary_operator:+; 77, 78; 77, 82; 78, call; 78, 79; 78, 80; 79, identifier:range; 80, argument_list; 80, 81; 81, identifier:i; 82, call; 82, 83; 82, 84; 83, identifier:range; 84, argument_list; 84, 85; 84, 88; 85, binary_operator:+; 85, 86; 85, 87; 86, identifier:i; 87, integer:1; 88, call; 88, 89; 88, 90; 89, identifier:len; 90, argument_list; 90, 91; 91, subscript; 91, 92; 91, 93; 92, identifier:a; 93, integer:0; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 107; 96, pattern_list; 96, 97; 96, 106; 97, subscript; 97, 98; 97, 99; 98, identifier:a; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:np; 102, identifier:ix_; 103, argument_list; 103, 104; 103, 105; 104, identifier:ids; 105, identifier:colids; 106, identifier:I2; 107, call; 107, 108; 107, 109; 108, identifier:sortrows; 109, argument_list; 109, 110; 109, 119; 109, 120; 109, 121; 110, subscript; 110, 111; 110, 112; 111, identifier:a; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:np; 115, identifier:ix_; 116, argument_list; 116, 117; 116, 118; 117, identifier:ids; 118, identifier:colids; 119, integer:0; 120, True; 121, True; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:I; 126, identifier:ids; 127, subscript; 127, 128; 127, 129; 128, identifier:I; 129, subscript; 129, 130; 129, 138; 130, subscript; 130, 131; 130, 137; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:np; 134, identifier:nonzero; 135, argument_list; 135, 136; 136, identifier:ids; 137, integer:0; 138, identifier:I2; 139, if_statement; 139, 140; 139, 141; 139, 146; 140, identifier:index_out; 141, block; 141, 142; 142, return_statement; 142, 143; 143, expression_list; 143, 144; 143, 145; 144, identifier:a; 145, identifier:I; 146, else_clause; 146, 147; 147, block; 147, 148; 148, return_statement; 148, 149; 149, identifier:a | def sortrows(a, i=0, index_out=False, recurse=True):
I = np.argsort(a[:, i])
a = a[I, :]
if recurse & (len(a[0]) > i + 1):
for b in np.unique(a[:, i]):
ids = a[:, i] == b
colids = range(i) + range(i+1, len(a[0]))
a[np.ix_(ids, colids)], I2 = sortrows(a[np.ix_(ids, colids)],
0, True, True)
I[ids] = I[np.nonzero(ids)[0][I2]]
if index_out:
return a, I
else:
return a |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:my_notes; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:start_index; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:limit; 10, integer:100; 11, default_parameter; 11, 12; 11, 13; 12, identifier:get_all; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort_by; 16, string:'loanId'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sort_dir; 19, string:'asc'; 20, block; 20, 21; 20, 25; 20, 38; 20, 146; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:index; 24, identifier:start_index; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:notes; 28, dictionary; 28, 29; 28, 32; 28, 35; 29, pair; 29, 30; 29, 31; 30, string:'loans'; 31, list:[]; 32, pair; 32, 33; 32, 34; 33, string:'total'; 34, integer:0; 35, pair; 35, 36; 35, 37; 36, string:'result'; 37, string:'success'; 38, while_statement; 38, 39; 38, 40; 39, True; 40, block; 40, 41; 40, 60; 40, 74; 40, 82; 40, 123; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:payload; 44, dictionary; 44, 45; 44, 48; 44, 51; 44, 54; 44, 57; 45, pair; 45, 46; 45, 47; 46, string:'sortBy'; 47, identifier:sort_by; 48, pair; 48, 49; 48, 50; 49, string:'dir'; 50, identifier:sort_dir; 51, pair; 51, 52; 51, 53; 52, string:'startindex'; 53, identifier:index; 54, pair; 54, 55; 54, 56; 55, string:'pagesize'; 56, identifier:limit; 57, pair; 57, 58; 57, 59; 58, string:'namespace'; 59, string:'/account'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:response; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:session; 68, identifier:post; 69, argument_list; 69, 70; 69, 71; 70, string:'/account/loansAj.action'; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:data; 73, identifier:payload; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:json_response; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:response; 80, identifier:json; 81, argument_list; 82, if_statement; 82, 83; 82, 91; 82, 112; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:session; 88, identifier:json_success; 89, argument_list; 89, 90; 90, identifier:json_response; 91, block; 91, 92; 91, 102; 92, expression_statement; 92, 93; 93, augmented_assignment:+=; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:notes; 96, string:'loans'; 97, subscript; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:json_response; 100, string:'searchresult'; 101, string:'loans'; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:notes; 106, string:'total'; 107, subscript; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:json_response; 110, string:'searchresult'; 111, string:'totalRecords'; 112, else_clause; 112, 113; 113, block; 113, 114; 113, 122; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:notes; 118, string:'result'; 119, subscript; 119, 120; 119, 121; 120, identifier:json_response; 121, string:'result'; 122, break_statement; 123, if_statement; 123, 124; 123, 138; 123, 143; 124, boolean_operator:and; 124, 125; 124, 128; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:get_all; 127, True; 128, comparison_operator:<; 128, 129; 128, 135; 129, call; 129, 130; 129, 131; 130, identifier:len; 131, argument_list; 131, 132; 132, subscript; 132, 133; 132, 134; 133, identifier:notes; 134, string:'loans'; 135, subscript; 135, 136; 135, 137; 136, identifier:notes; 137, string:'total'; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, augmented_assignment:+=; 140, 141; 140, 142; 141, identifier:index; 142, identifier:limit; 143, else_clause; 143, 144; 144, block; 144, 145; 145, break_statement; 146, return_statement; 146, 147; 147, identifier:notes | def my_notes(self, start_index=0, limit=100, get_all=False, sort_by='loanId', sort_dir='asc'):
index = start_index
notes = {
'loans': [],
'total': 0,
'result': 'success'
}
while True:
payload = {
'sortBy': sort_by,
'dir': sort_dir,
'startindex': index,
'pagesize': limit,
'namespace': '/account'
}
response = self.session.post('/account/loansAj.action', data=payload)
json_response = response.json()
if self.session.json_success(json_response):
notes['loans'] += json_response['searchresult']['loans']
notes['total'] = json_response['searchresult']['totalRecords']
else:
notes['result'] = json_response['result']
break
if get_all is True and len(notes['loans']) < notes['total']:
index += limit
else:
break
return notes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:blacken; 3, parameters; 3, 4; 4, identifier:c; 5, block; 5, 6; 5, 35; 5, 53; 5, 63; 5, 75; 6, if_statement; 6, 7; 6, 14; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:PYTHON; 11, identifier:startswith; 12, argument_list; 12, 13; 13, string:"3.6"; 14, block; 14, 15; 14, 24; 14, 34; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:msg; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, string:"Not blackening, since Python {} != Python 3.6"; 21, identifier:format; 22, argument_list; 22, 23; 23, identifier:PYTHON; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:print; 27, argument_list; 27, 28; 27, 29; 28, identifier:msg; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:file; 31, attribute; 31, 32; 31, 33; 32, identifier:sys; 33, identifier:stderr; 34, return_statement; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:config; 38, call; 38, 39; 38, 50; 39, attribute; 39, 40; 39, 49; 40, call; 40, 41; 40, 46; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:c; 44, identifier:config; 45, identifier:get; 46, argument_list; 46, 47; 46, 48; 47, string:"travis"; 48, dictionary; 49, identifier:get; 50, argument_list; 50, 51; 50, 52; 51, string:"black"; 52, dictionary; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:version; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:config; 59, identifier:get; 60, argument_list; 60, 61; 60, 62; 61, string:"version"; 62, string:"18.5b0"; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:c; 67, identifier:run; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, string:"pip install black=={}"; 72, identifier:format; 73, argument_list; 73, 74; 74, identifier:version; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:checks; 79, identifier:blacken; 80, argument_list; 80, 81; 80, 82; 80, 85; 81, identifier:c; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:check; 84, True; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:diff; 87, True | def blacken(c):
if not PYTHON.startswith("3.6"):
msg = "Not blackening, since Python {} != Python 3.6".format(PYTHON)
print(msg, file=sys.stderr)
return
config = c.config.get("travis", {}).get("black", {})
version = config.get("version", "18.5b0")
c.run("pip install black=={}".format(version))
checks.blacken(c, check=True, diff=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_versions_from_changelog; 3, parameters; 3, 4; 4, identifier:changelog; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:versions; 9, list_comprehension; 9, 10; 9, 14; 9, 17; 10, call; 10, 11; 10, 12; 11, identifier:Version; 12, argument_list; 12, 13; 13, identifier:x; 14, for_in_clause; 14, 15; 14, 16; 15, identifier:x; 16, identifier:changelog; 17, if_clause; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:BUGFIX_RELEASE_RE; 21, identifier:match; 22, argument_list; 22, 23; 23, identifier:x; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, identifier:versions | def _versions_from_changelog(changelog):
versions = [Version(x) for x in changelog if BUGFIX_RELEASE_RE.match(x)]
return sorted(versions) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_tags; 3, parameters; 3, 4; 4, identifier:c; 5, block; 5, 6; 5, 10; 5, 49; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:tags_; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 32; 11, identifier:tagstr; 12, call; 12, 13; 12, 30; 13, attribute; 13, 14; 13, 29; 14, call; 14, 15; 14, 28; 15, attribute; 15, 16; 15, 27; 16, attribute; 16, 17; 16, 26; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:c; 20, identifier:run; 21, argument_list; 21, 22; 21, 23; 22, string:"git tag"; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:hide; 25, True; 26, identifier:stdout; 27, identifier:strip; 28, argument_list; 29, identifier:split; 30, argument_list; 30, 31; 31, string:"\n"; 32, block; 32, 33; 33, try_statement; 33, 34; 33, 45; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:tags_; 39, identifier:append; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:Version; 43, argument_list; 43, 44; 44, identifier:tagstr; 45, except_clause; 45, 46; 45, 47; 46, identifier:ValueError; 47, block; 47, 48; 48, pass_statement; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:sorted; 52, argument_list; 52, 53; 53, identifier:tags_ | def _get_tags(c):
tags_ = []
for tagstr in c.run("git tag", hide=True).stdout.strip().split("\n"):
try:
tags_.append(Version(tagstr))
except ValueError:
pass
return sorted(tags_) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sortForSameExpTime; 3, parameters; 3, 4; 3, 5; 4, identifier:expTimes; 5, identifier:img_paths; 6, block; 6, 7; 6, 9; 6, 13; 6, 43; 6, 57; 7, expression_statement; 7, 8; 8, string:'''
return image paths sorted for same exposure time
'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:d; 12, dictionary; 13, for_statement; 13, 14; 13, 17; 13, 22; 14, pattern_list; 14, 15; 14, 16; 15, identifier:e; 16, identifier:i; 17, call; 17, 18; 17, 19; 18, identifier:zip; 19, argument_list; 19, 20; 19, 21; 20, identifier:expTimes; 21, identifier:img_paths; 22, block; 22, 23; 22, 34; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:not; 24, 25; 24, 26; 25, identifier:e; 26, identifier:d; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:d; 32, identifier:e; 33, list:[]; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:d; 39, identifier:e; 40, identifier:append; 41, argument_list; 41, 42; 42, identifier:i; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:d; 46, call; 46, 47; 46, 48; 47, identifier:OrderedDict; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:sorted; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:d; 55, identifier:items; 56, argument_list; 57, return_statement; 57, 58; 58, expression_list; 58, 59; 58, 67; 59, call; 59, 60; 59, 61; 60, identifier:list; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:d; 65, identifier:keys; 66, argument_list; 67, call; 67, 68; 67, 69; 68, identifier:list; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:d; 73, identifier:values; 74, argument_list | def sortForSameExpTime(expTimes, img_paths):
'''
return image paths sorted for same exposure time
'''
d = {}
for e, i in zip(expTimes, img_paths):
if e not in d:
d[e] = []
d[e].append(i)
d = OrderedDict(sorted(d.items()))
return list(d.keys()), list(d.values()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:actionnames; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 53; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:actions; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 22; 11, identifier:service_name; 12, call; 12, 13; 12, 14; 13, identifier:sorted; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:services; 20, identifier:keys; 21, argument_list; 22, block; 22, 23; 22, 37; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:action_names; 26, call; 26, 27; 26, 36; 27, attribute; 27, 28; 27, 35; 28, attribute; 28, 29; 28, 34; 29, subscript; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:services; 33, identifier:service_name; 34, identifier:actions; 35, identifier:keys; 36, argument_list; 37, for_statement; 37, 38; 37, 39; 37, 43; 38, identifier:action_name; 39, call; 39, 40; 39, 41; 40, identifier:sorted; 41, argument_list; 41, 42; 42, identifier:action_names; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:actions; 48, identifier:append; 49, argument_list; 49, 50; 50, tuple; 50, 51; 50, 52; 51, identifier:service_name; 52, identifier:action_name; 53, return_statement; 53, 54; 54, identifier:actions | def actionnames(self):
actions = []
for service_name in sorted(self.services.keys()):
action_names = self.services[service_name].actions.keys()
for action_name in sorted(action_names):
actions.append((service_name, action_name))
return actions |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:lookup_field_orderable; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:field; 6, block; 6, 7; 7, try_statement; 7, 8; 7, 22; 8, block; 8, 9; 8, 20; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 18; 11, attribute; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:model; 16, identifier:_meta; 17, identifier:get_field_by_name; 18, argument_list; 18, 19; 19, identifier:field; 20, return_statement; 20, 21; 21, True; 22, except_clause; 22, 23; 22, 24; 23, identifier:Exception; 24, block; 24, 25; 25, return_statement; 25, 26; 26, False | def lookup_field_orderable(self, field):
try:
self.model._meta.get_field_by_name(field)
return True
except Exception:
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:run; 3, parameters; 3, 4; 3, 5; 4, identifier:files; 5, identifier:temp_folder; 6, block; 6, 7; 6, 17; 6, 24; 7, try_statement; 7, 8; 7, 12; 8, block; 8, 9; 9, import_statement; 9, 10; 10, dotted_name; 10, 11; 11, identifier:isort; 12, except_clause; 12, 13; 12, 14; 13, identifier:ImportError; 14, block; 14, 15; 15, return_statement; 15, 16; 16, identifier:NO_ISORT_MSG; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:py_files; 20, call; 20, 21; 20, 22; 21, identifier:filter_python_files; 22, argument_list; 22, 23; 23, identifier:files; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 42; 26, attribute; 26, 27; 26, 41; 27, call; 27, 28; 27, 29; 28, identifier:bash; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:'isort -df --quiet {0}'; 33, identifier:format; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:' '; 38, identifier:join; 39, argument_list; 39, 40; 40, identifier:py_files; 41, identifier:value; 42, argument_list | def run(files, temp_folder):
try:
import isort
except ImportError:
return NO_ISORT_MSG
py_files = filter_python_files(files)
return bash('isort -df --quiet {0}'.format(' '.join(py_files))).value() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:keys; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 11, 33; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ks; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 27; 17, 30; 18, call; 18, 19; 18, 20; 19, identifier:list; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:dict; 24, identifier:keys; 25, argument_list; 25, 26; 26, identifier:self; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:key; 29, identifier:key; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:reverse; 32, identifier:reverse; 33, return_statement; 33, 34; 34, identifier:ks | def keys(self, key=None, reverse=False):
ks = sorted(list(dict.keys(self)), key=key, reverse=reverse)
return ks |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:lazy_map; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:data_processor; 5, identifier:data_generator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n_cpus; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:stepsize; 11, None; 12, block; 12, 13; 12, 40; 12, 49; 12, 53; 12, 98; 13, if_statement; 13, 14; 13, 16; 13, 25; 14, not_operator; 14, 15; 15, identifier:n_cpus; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:n_cpus; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:mp; 23, identifier:cpu_count; 24, argument_list; 25, elif_clause; 25, 26; 25, 29; 26, comparison_operator:<; 26, 27; 26, 28; 27, identifier:n_cpus; 28, integer:0; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:n_cpus; 33, binary_operator:-; 33, 34; 33, 39; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:mp; 37, identifier:cpu_count; 38, argument_list; 39, identifier:n_cpus; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:stepsize; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:stepsize; 48, identifier:n_cpus; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:results; 52, list:[]; 53, with_statement; 53, 54; 53, 67; 54, with_clause; 54, 55; 55, with_item; 55, 56; 56, as_pattern; 56, 57; 56, 65; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:mp; 60, identifier:Pool; 61, argument_list; 61, 62; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:processes; 64, identifier:n_cpus; 65, as_pattern_target; 65, 66; 66, identifier:p; 67, block; 67, 68; 68, while_statement; 68, 69; 68, 70; 69, True; 70, block; 70, 71; 70, 85; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:r; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:p; 77, identifier:map; 78, argument_list; 78, 79; 78, 80; 79, identifier:data_processor; 80, call; 80, 81; 80, 82; 81, identifier:islice; 82, argument_list; 82, 83; 82, 84; 83, identifier:data_generator; 84, identifier:stepsize; 85, if_statement; 85, 86; 85, 87; 85, 95; 86, identifier:r; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:results; 92, identifier:extend; 93, argument_list; 93, 94; 94, identifier:r; 95, else_clause; 95, 96; 96, block; 96, 97; 97, break_statement; 98, return_statement; 98, 99; 99, identifier:results | def lazy_map(data_processor, data_generator, n_cpus=1, stepsize=None):
if not n_cpus:
n_cpus = mp.cpu_count()
elif n_cpus < 0:
n_cpus = mp.cpu_count() - n_cpus
if stepsize is None:
stepsize = n_cpus
results = []
with mp.Pool(processes=n_cpus) as p:
while True:
r = p.map(data_processor, islice(data_generator, stepsize))
if r:
results.extend(r)
else:
break
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:lazy_imap; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:data_processor; 5, identifier:data_generator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:n_cpus; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:stepsize; 11, None; 12, block; 12, 13; 12, 40; 12, 49; 13, if_statement; 13, 14; 13, 16; 13, 25; 14, not_operator; 14, 15; 15, identifier:n_cpus; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:n_cpus; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:mp; 23, identifier:cpu_count; 24, argument_list; 25, elif_clause; 25, 26; 25, 29; 26, comparison_operator:<; 26, 27; 26, 28; 27, identifier:n_cpus; 28, integer:0; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:n_cpus; 33, binary_operator:-; 33, 34; 33, 39; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:mp; 37, identifier:cpu_count; 38, argument_list; 39, identifier:n_cpus; 40, if_statement; 40, 41; 40, 44; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:stepsize; 43, None; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:stepsize; 48, identifier:n_cpus; 49, with_statement; 49, 50; 49, 63; 50, with_clause; 50, 51; 51, with_item; 51, 52; 52, as_pattern; 52, 53; 52, 61; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:mp; 56, identifier:Pool; 57, argument_list; 57, 58; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:processes; 60, identifier:n_cpus; 61, as_pattern_target; 61, 62; 62, identifier:p; 63, block; 63, 64; 64, while_statement; 64, 65; 64, 66; 65, True; 66, block; 66, 67; 66, 81; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:r; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:p; 73, identifier:map; 74, argument_list; 74, 75; 74, 76; 75, identifier:data_processor; 76, call; 76, 77; 76, 78; 77, identifier:islice; 78, argument_list; 78, 79; 78, 80; 79, identifier:data_generator; 80, identifier:stepsize; 81, if_statement; 81, 82; 81, 83; 81, 87; 82, identifier:r; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, yield; 85, 86; 86, identifier:r; 87, else_clause; 87, 88; 88, block; 88, 89; 89, break_statement | def lazy_imap(data_processor, data_generator, n_cpus=1, stepsize=None):
if not n_cpus:
n_cpus = mp.cpu_count()
elif n_cpus < 0:
n_cpus = mp.cpu_count() - n_cpus
if stepsize is None:
stepsize = n_cpus
with mp.Pool(processes=n_cpus) as p:
while True:
r = p.map(data_processor, islice(data_generator, stepsize))
if r:
yield r
else:
break |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_dummy_thread; 3, parameters; 3, 4; 3, 5; 4, identifier:nsamples; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 18; 7, 28; 7, 41; 7, 51; 7, 64; 7, 78; 7, 133; 7, 147; 7, 166; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:seed; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:kwargs; 14, identifier:pop; 15, argument_list; 15, 16; 15, 17; 16, string:'seed'; 17, False; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:ndim; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:kwargs; 24, identifier:pop; 25, argument_list; 25, 26; 25, 27; 26, string:'ndim'; 27, integer:2; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:logl_start; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:kwargs; 34, identifier:pop; 35, argument_list; 35, 36; 35, 37; 36, string:'logl_start'; 37, unary_operator:-; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:np; 40, identifier:inf; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:logl_range; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:kwargs; 47, identifier:pop; 48, argument_list; 48, 49; 48, 50; 49, string:'logl_range'; 50, integer:1; 51, if_statement; 51, 52; 51, 53; 52, identifier:kwargs; 53, block; 53, 54; 54, raise_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:TypeError; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:'Unexpected **kwargs: {0}'; 61, identifier:format; 62, argument_list; 62, 63; 63, identifier:kwargs; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:is; 65, 66; 65, 67; 66, identifier:seed; 67, False; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:random; 75, identifier:seed; 76, argument_list; 76, 77; 77, identifier:seed; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:thread; 81, dictionary; 81, 82; 81, 99; 81, 108; 81, 120; 82, pair; 82, 83; 82, 84; 83, string:'logl'; 84, binary_operator:*; 84, 85; 84, 98; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:sort; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:np; 94, identifier:random; 95, identifier:random; 96, argument_list; 96, 97; 97, identifier:nsamples; 98, identifier:logl_range; 99, pair; 99, 100; 99, 101; 100, string:'nlive_array'; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:np; 104, identifier:full; 105, argument_list; 105, 106; 105, 107; 106, identifier:nsamples; 107, float:1.; 108, pair; 108, 109; 108, 110; 109, string:'theta'; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:np; 114, identifier:random; 115, identifier:random; 116, argument_list; 116, 117; 117, tuple; 117, 118; 117, 119; 118, identifier:nsamples; 119, identifier:ndim; 120, pair; 120, 121; 120, 122; 121, string:'thread_labels'; 122, call; 122, 123; 122, 131; 123, attribute; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:np; 127, identifier:zeros; 128, argument_list; 128, 129; 129, identifier:nsamples; 130, identifier:astype; 131, argument_list; 131, 132; 132, identifier:int; 133, if_statement; 133, 134; 133, 140; 134, comparison_operator:!=; 134, 135; 134, 136; 135, identifier:logl_start; 136, unary_operator:-; 136, 137; 137, attribute; 137, 138; 137, 139; 138, identifier:np; 139, identifier:inf; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, augmented_assignment:+=; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:thread; 145, string:'logl'; 146, identifier:logl_start; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:thread; 151, string:'thread_min_max'; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:np; 155, identifier:asarray; 156, argument_list; 156, 157; 157, list:[[logl_start, thread['logl'][-1]]]; 157, 158; 158, list:[logl_start, thread['logl'][-1]]; 158, 159; 158, 160; 159, identifier:logl_start; 160, subscript; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:thread; 163, string:'logl'; 164, unary_operator:-; 164, 165; 165, integer:1; 166, return_statement; 166, 167; 167, identifier:thread | def get_dummy_thread(nsamples, **kwargs):
seed = kwargs.pop('seed', False)
ndim = kwargs.pop('ndim', 2)
logl_start = kwargs.pop('logl_start', -np.inf)
logl_range = kwargs.pop('logl_range', 1)
if kwargs:
raise TypeError('Unexpected **kwargs: {0}'.format(kwargs))
if seed is not False:
np.random.seed(seed)
thread = {'logl': np.sort(np.random.random(nsamples)) * logl_range,
'nlive_array': np.full(nsamples, 1.),
'theta': np.random.random((nsamples, ndim)),
'thread_labels': np.zeros(nsamples).astype(int)}
if logl_start != -np.inf:
thread['logl'] += logl_start
thread['thread_min_max'] = np.asarray([[logl_start, thread['logl'][-1]]])
return thread |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_dummy_run; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:nthread; 5, identifier:nsamples; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 19; 8, 29; 8, 42; 8, 52; 8, 65; 8, 69; 8, 83; 8, 87; 8, 116; 8, 133; 8, 156; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:seed; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:kwargs; 15, identifier:pop; 16, argument_list; 16, 17; 16, 18; 17, string:'seed'; 18, False; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:ndim; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:kwargs; 25, identifier:pop; 26, argument_list; 26, 27; 26, 28; 27, string:'ndim'; 28, integer:2; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:logl_start; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:kwargs; 35, identifier:pop; 36, argument_list; 36, 37; 36, 38; 37, string:'logl_start'; 38, unary_operator:-; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:np; 41, identifier:inf; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:logl_range; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:kwargs; 48, identifier:pop; 49, argument_list; 49, 50; 49, 51; 50, string:'logl_range'; 51, integer:1; 52, if_statement; 52, 53; 52, 54; 53, identifier:kwargs; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:TypeError; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, string:'Unexpected **kwargs: {0}'; 62, identifier:format; 63, argument_list; 63, 64; 64, identifier:kwargs; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:threads; 68, list:[]; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:seed; 72, False; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:np; 79, identifier:random; 80, identifier:seed; 81, argument_list; 81, 82; 82, identifier:seed; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:threads; 86, list:[]; 87, for_statement; 87, 88; 87, 89; 87, 93; 88, identifier:_; 89, call; 89, 90; 89, 91; 90, identifier:range; 91, argument_list; 91, 92; 92, identifier:nthread; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:threads; 98, identifier:append; 99, argument_list; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:get_dummy_thread; 102, argument_list; 102, 103; 102, 104; 102, 107; 102, 110; 102, 113; 103, identifier:nsamples; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:ndim; 106, identifier:ndim; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:seed; 109, False; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:logl_start; 112, identifier:logl_start; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:logl_range; 115, identifier:logl_range; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:threads; 119, call; 119, 120; 119, 121; 120, identifier:sorted; 121, argument_list; 121, 122; 121, 123; 122, identifier:threads; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:key; 125, lambda; 125, 126; 125, 128; 126, lambda_parameters; 126, 127; 127, identifier:th; 128, subscript; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:th; 131, string:'logl'; 132, integer:0; 133, for_statement; 133, 134; 133, 137; 133, 141; 134, pattern_list; 134, 135; 134, 136; 135, identifier:i; 136, identifier:_; 137, call; 137, 138; 137, 139; 138, identifier:enumerate; 139, argument_list; 139, 140; 140, identifier:threads; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:threads; 147, identifier:i; 148, string:'thread_labels'; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:np; 152, identifier:full; 153, argument_list; 153, 154; 153, 155; 154, identifier:nsamples; 155, identifier:i; 156, return_statement; 156, 157; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:nestcheck; 161, identifier:ns_run_utils; 162, identifier:combine_threads; 163, argument_list; 163, 164; 164, identifier:threads | def get_dummy_run(nthread, nsamples, **kwargs):
seed = kwargs.pop('seed', False)
ndim = kwargs.pop('ndim', 2)
logl_start = kwargs.pop('logl_start', -np.inf)
logl_range = kwargs.pop('logl_range', 1)
if kwargs:
raise TypeError('Unexpected **kwargs: {0}'.format(kwargs))
threads = []
if seed is not False:
np.random.seed(seed)
threads = []
for _ in range(nthread):
threads.append(get_dummy_thread(
nsamples, ndim=ndim, seed=False, logl_start=logl_start,
logl_range=logl_range))
threads = sorted(threads, key=lambda th: th['logl'][0])
for i, _ in enumerate(threads):
threads[i]['thread_labels'] = np.full(nsamples, i)
return nestcheck.ns_run_utils.combine_threads(threads) |
Subsets and Splits