sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:register; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:func; 6, identifier:order; 7, block; 7, 8; 7, 16; 7, 28; 7, 44; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:token; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:Token; 15, argument_list; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_filter_order; 22, identifier:append; 23, argument_list; 23, 24; 24, tuple; 24, 25; 24, 26; 24, 27; 25, identifier:order; 26, identifier:token; 27, identifier:func; 28, expression_statement; 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:_filter_order; 34, identifier:sort; 35, argument_list; 35, 36; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:key; 38, lambda; 38, 39; 38, 41; 39, lambda_parameters; 39, 40; 40, identifier:x; 41, subscript; 41, 42; 41, 43; 42, identifier:x; 43, integer:0; 44, return_statement; 44, 45; 45, identifier:token | def register(self, func, order):
token = self.Token()
self._filter_order.append((order, token, func))
self._filter_order.sort(key=lambda x: x[0])
return token |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_features; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:jid; 6, block; 6, 7; 6, 19; 6, 25; 6, 49; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:response; 10, yield; 10, 11; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_disco; 16, identifier:query_info; 17, argument_list; 17, 18; 18, identifier:jid; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:result; 22, call; 22, 23; 22, 24; 23, identifier:set; 24, argument_list; 25, for_statement; 25, 26; 25, 27; 25, 30; 26, identifier:feature; 27, attribute; 27, 28; 27, 29; 28, identifier:response; 29, identifier:features; 30, block; 30, 31; 31, try_statement; 31, 32; 31, 45; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:result; 37, identifier:add; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:pubsub_xso; 42, identifier:Feature; 43, argument_list; 43, 44; 44, identifier:feature; 45, except_clause; 45, 46; 45, 47; 46, identifier:ValueError; 47, block; 47, 48; 48, continue_statement; 49, return_statement; 49, 50; 50, identifier:result | def get_features(self, jid):
response = yield from self._disco.query_info(jid)
result = set()
for feature in response.features:
try:
result.add(pubsub_xso.Feature(feature))
except ValueError:
continue
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:intersect; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:other; 6, block; 6, 7; 6, 19; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:loc; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:locate_keys; 14, argument_list; 14, 15; 14, 16; 15, identifier:other; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:strict; 18, False; 19, return_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:compress; 24, argument_list; 24, 25; 24, 26; 25, identifier:loc; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:axis; 28, integer:0 | def intersect(self, other):
loc = self.locate_keys(other, strict=False)
return self.compress(loc, axis=0) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:locate_intersection_ranges; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:starts; 6, identifier:stops; 7, block; 7, 8; 7, 16; 7, 24; 7, 30; 7, 40; 7, 53; 7, 59; 7, 75; 7, 98; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:starts; 11, call; 11, 12; 11, 13; 12, identifier:asarray_ndim; 13, argument_list; 13, 14; 13, 15; 14, identifier:starts; 15, integer:1; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:stops; 19, call; 19, 20; 19, 21; 20, identifier:asarray_ndim; 21, argument_list; 21, 22; 21, 23; 22, identifier:stops; 23, integer:1; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:check_dim0_aligned; 27, argument_list; 27, 28; 27, 29; 28, identifier:starts; 29, identifier:stops; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:start_indices; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:searchsorted; 37, argument_list; 37, 38; 37, 39; 38, identifier:self; 39, identifier:starts; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:stop_indices; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:searchsorted; 47, argument_list; 47, 48; 47, 49; 47, 50; 48, identifier:self; 49, identifier:stops; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:side; 52, string:'right'; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:loc_ranges; 56, comparison_operator:<; 56, 57; 56, 58; 57, identifier:start_indices; 58, identifier:stop_indices; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:loc; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:np; 65, identifier:zeros; 66, argument_list; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:shape; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:dtype; 72, attribute; 72, 73; 72, 74; 73, identifier:np; 74, identifier:bool; 75, for_statement; 75, 76; 75, 79; 75, 88; 76, pattern_list; 76, 77; 76, 78; 77, identifier:i; 78, identifier:j; 79, call; 79, 80; 79, 81; 80, identifier:zip; 81, argument_list; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:start_indices; 84, identifier:loc_ranges; 85, subscript; 85, 86; 85, 87; 86, identifier:stop_indices; 87, identifier:loc_ranges; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 97; 91, subscript; 91, 92; 91, 93; 92, identifier:loc; 93, slice; 93, 94; 93, 95; 93, 96; 94, identifier:i; 95, colon; 96, identifier:j; 97, True; 98, return_statement; 98, 99; 99, expression_list; 99, 100; 99, 101; 100, identifier:loc; 101, identifier:loc_ranges | def locate_intersection_ranges(self, starts, stops):
starts = asarray_ndim(starts, 1)
stops = asarray_ndim(stops, 1)
check_dim0_aligned(starts, stops)
start_indices = np.searchsorted(self, starts)
stop_indices = np.searchsorted(self, stops, side='right')
loc_ranges = start_indices < stop_indices
loc = np.zeros(self.shape, dtype=np.bool)
for i, j in zip(start_indices[loc_ranges], stop_indices[loc_ranges]):
loc[i:j] = True
return loc, loc_ranges |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:locate_ranges; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:starts; 6, identifier:stops; 7, default_parameter; 7, 8; 7, 9; 8, identifier:strict; 9, True; 10, block; 10, 11; 10, 23; 10, 46; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, pattern_list; 13, 14; 13, 15; 14, identifier:loc; 15, identifier:found; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:locate_intersection_ranges; 20, argument_list; 20, 21; 20, 22; 21, identifier:starts; 22, identifier:stops; 23, if_statement; 23, 24; 23, 33; 24, boolean_operator:and; 24, 25; 24, 26; 25, identifier:strict; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:np; 29, identifier:any; 30, argument_list; 30, 31; 31, unary_operator:~; 31, 32; 32, identifier:found; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:KeyError; 37, argument_list; 37, 38; 37, 42; 38, subscript; 38, 39; 38, 40; 39, identifier:starts; 40, unary_operator:~; 40, 41; 41, identifier:found; 42, subscript; 42, 43; 42, 44; 43, identifier:stops; 44, unary_operator:~; 44, 45; 45, identifier:found; 46, return_statement; 46, 47; 47, identifier:loc | def locate_ranges(self, starts, stops, strict=True):
loc, found = self.locate_intersection_ranges(starts, stops)
if strict and np.any(~found):
raise KeyError(starts[~found], stops[~found])
return loc |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:intersect_ranges; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:starts; 6, identifier:stops; 7, block; 7, 8; 7, 21; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:loc; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:locate_ranges; 15, argument_list; 15, 16; 15, 17; 15, 18; 16, identifier:starts; 17, identifier:stops; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:strict; 20, False; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:compress; 26, argument_list; 26, 27; 26, 28; 27, identifier:loc; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:axis; 30, integer:0 | def intersect_ranges(self, starts, stops):
loc = self.locate_ranges(starts, stops, strict=False)
return self.compress(loc, axis=0) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:from_gff3; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 15; 3, 19; 3, 22; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:attributes; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:region; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:score_fill; 13, unary_operator:-; 13, 14; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:phase_fill; 17, unary_operator:-; 17, 18; 18, integer:1; 19, default_parameter; 19, 20; 19, 21; 20, identifier:attributes_fill; 21, string:'.'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:dtype; 24, None; 25, block; 25, 26; 25, 51; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:a; 29, call; 29, 30; 29, 31; 30, identifier:gff3_to_recarray; 31, argument_list; 31, 32; 31, 33; 31, 36; 31, 39; 31, 42; 31, 45; 31, 48; 32, identifier:path; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:attributes; 35, identifier:attributes; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:region; 38, identifier:region; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:score_fill; 41, identifier:score_fill; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:phase_fill; 44, identifier:phase_fill; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:attributes_fill; 47, identifier:attributes_fill; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:dtype; 50, identifier:dtype; 51, if_statement; 51, 52; 51, 55; 51, 58; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:a; 54, None; 55, block; 55, 56; 56, return_statement; 56, 57; 57, None; 58, else_clause; 58, 59; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:FeatureTable; 63, argument_list; 63, 64; 63, 65; 64, identifier:a; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:copy; 67, False | def from_gff3(path, attributes=None, region=None, score_fill=-1, phase_fill=-1,
attributes_fill='.', dtype=None):
a = gff3_to_recarray(path, attributes=attributes, region=region,
score_fill=score_fill, phase_fill=phase_fill,
attributes_fill=attributes_fill, dtype=dtype)
if a is None:
return None
else:
return FeatureTable(a, copy=False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:iter_gff3; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 15; 3, 19; 3, 22; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:attributes; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:region; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:score_fill; 13, unary_operator:-; 13, 14; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:phase_fill; 17, unary_operator:-; 17, 18; 18, integer:1; 19, default_parameter; 19, 20; 19, 21; 20, identifier:attributes_fill; 21, string:'.'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:tabix; 24, string:'tabix'; 25, block; 25, 26; 25, 75; 25, 142; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:attributes; 29, None; 30, block; 30, 31; 30, 38; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:attributes; 34, call; 34, 35; 34, 36; 35, identifier:list; 36, argument_list; 36, 37; 37, identifier:attributes; 38, if_statement; 38, 39; 38, 46; 38, 63; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 43; 42, identifier:attributes_fill; 43, tuple; 43, 44; 43, 45; 44, identifier:list; 45, identifier:tuple; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 57; 48, comparison_operator:!=; 48, 49; 48, 53; 49, call; 49, 50; 49, 51; 50, identifier:len; 51, argument_list; 51, 52; 52, identifier:attributes; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:attributes_fill; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ValueError; 61, argument_list; 61, 62; 62, string:'number of fills does not match attributes'; 63, else_clause; 63, 64; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:attributes_fill; 68, binary_operator:*; 68, 69; 68, 71; 69, list:[attributes_fill]; 69, 70; 70, identifier:attributes_fill; 71, call; 71, 72; 71, 73; 72, identifier:len; 73, argument_list; 73, 74; 74, identifier:attributes; 75, if_statement; 75, 76; 75, 79; 75, 103; 75, 130; 76, comparison_operator:is; 76, 77; 76, 78; 77, identifier:region; 78, None; 79, block; 79, 80; 79, 87; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:cmd; 83, list:[tabix, path, region]; 83, 84; 83, 85; 83, 86; 84, identifier:tabix; 85, identifier:path; 86, identifier:region; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:buffer; 90, attribute; 90, 91; 90, 102; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:subprocess; 94, identifier:Popen; 95, argument_list; 95, 96; 95, 97; 96, identifier:cmd; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:stdout; 99, attribute; 99, 100; 99, 101; 100, identifier:subprocess; 101, identifier:PIPE; 102, identifier:stdout; 103, elif_clause; 103, 104; 103, 117; 104, boolean_operator:or; 104, 105; 104, 111; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:path; 108, identifier:endswith; 109, argument_list; 109, 110; 110, string:'.gz'; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:path; 114, identifier:endswith; 115, argument_list; 115, 116; 116, string:'.bgz'; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:buffer; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:gzip; 124, identifier:open; 125, argument_list; 125, 126; 125, 127; 126, identifier:path; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:mode; 129, string:'rb'; 130, else_clause; 130, 131; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:buffer; 135, call; 135, 136; 135, 137; 136, identifier:open; 137, argument_list; 137, 138; 137, 139; 138, identifier:path; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:mode; 141, string:'rb'; 142, try_statement; 142, 143; 142, 338; 143, block; 143, 144; 144, for_statement; 144, 145; 144, 146; 144, 147; 145, identifier:line; 146, identifier:buffer; 147, block; 147, 148; 147, 156; 148, if_statement; 148, 149; 148, 154; 149, comparison_operator:==; 149, 150; 149, 153; 150, subscript; 150, 151; 150, 152; 151, identifier:line; 152, integer:0; 153, string:b'>'; 154, block; 154, 155; 155, return_statement; 156, if_statement; 156, 157; 156, 170; 156, 177; 157, comparison_operator:==; 157, 158; 157, 161; 157, 164; 158, subscript; 158, 159; 158, 160; 159, identifier:line; 160, integer:0; 161, ERROR; 161, 162; 161, 163; 162, identifier:continue; 163, identifier:vals; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:line; 167, identifier:split; 168, argument_list; 168, 169; 169, string:b'\t'; 170, ERROR; 170, 171; 171, comparison_operator:==; 171, 172; 171, 176; 172, call; 172, 173; 172, 174; 173, identifier:len; 174, argument_list; 174, 175; 175, identifier:vals; 176, integer:9; 177, block; 177, 178; 177, 191; 177, 198; 177, 205; 177, 223; 177, 241; 177, 285; 177, 297; 177, 335; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 190; 180, pattern_list; 180, 181; 180, 182; 180, 183; 180, 184; 180, 185; 180, 186; 180, 187; 180, 188; 180, 189; 181, identifier:fseqid; 182, identifier:fsource; 183, identifier:ftype; 184, identifier:fstart; 185, identifier:fend; 186, identifier:fscore; 187, identifier:fstrand; 188, identifier:fphase; 189, identifier:fattrs; 190, identifier:vals; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:fstart; 194, call; 194, 195; 194, 196; 195, identifier:int; 196, argument_list; 196, 197; 197, identifier:fstart; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:fend; 201, call; 201, 202; 201, 203; 202, identifier:int; 203, argument_list; 203, 204; 204, identifier:fend; 205, if_statement; 205, 206; 205, 209; 205, 214; 206, comparison_operator:==; 206, 207; 206, 208; 207, identifier:fscore; 208, string:b'.'; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:fscore; 213, identifier:score_fill; 214, else_clause; 214, 215; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:fscore; 219, call; 219, 220; 219, 221; 220, identifier:float; 221, argument_list; 221, 222; 222, identifier:fscore; 223, if_statement; 223, 224; 223, 227; 223, 232; 224, comparison_operator:==; 224, 225; 224, 226; 225, identifier:fphase; 226, string:b'.'; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:fphase; 231, identifier:phase_fill; 232, else_clause; 232, 233; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:fphase; 237, call; 237, 238; 237, 239; 238, identifier:int; 239, argument_list; 239, 240; 240, identifier:fphase; 241, if_statement; 241, 242; 241, 244; 242, not_operator; 242, 243; 243, identifier:PY2; 244, block; 244, 245; 244, 253; 244, 261; 244, 269; 244, 277; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:fseqid; 248, call; 248, 249; 248, 250; 249, identifier:str; 250, argument_list; 250, 251; 250, 252; 251, identifier:fseqid; 252, string:'ascii'; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:fsource; 256, call; 256, 257; 256, 258; 257, identifier:str; 258, argument_list; 258, 259; 258, 260; 259, identifier:fsource; 260, string:'ascii'; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:ftype; 264, call; 264, 265; 264, 266; 265, identifier:str; 266, argument_list; 266, 267; 266, 268; 267, identifier:ftype; 268, string:'ascii'; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:fstrand; 272, call; 272, 273; 272, 274; 273, identifier:str; 274, argument_list; 274, 275; 274, 276; 275, identifier:fstrand; 276, string:'ascii'; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:fattrs; 280, call; 280, 281; 280, 282; 281, identifier:str; 282, argument_list; 282, 283; 282, 284; 283, identifier:fattrs; 284, string:'ascii'; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:rec; 288, tuple; 288, 289; 288, 290; 288, 291; 288, 292; 288, 293; 288, 294; 288, 295; 288, 296; 289, identifier:fseqid; 290, identifier:fsource; 291, identifier:ftype; 292, identifier:fstart; 293, identifier:fend; 294, identifier:fscore; 295, identifier:fstrand; 296, identifier:fphase; 297, if_statement; 297, 298; 297, 301; 298, comparison_operator:is; 298, 299; 298, 300; 299, identifier:attributes; 300, None; 301, block; 301, 302; 301, 309; 301, 331; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:dattrs; 305, call; 305, 306; 305, 307; 306, identifier:gff3_parse_attributes; 307, argument_list; 307, 308; 308, identifier:fattrs; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:vattrs; 312, call; 312, 313; 312, 314; 313, identifier:tuple; 314, generator_expression; 314, 315; 314, 322; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:dattrs; 318, identifier:get; 319, argument_list; 319, 320; 319, 321; 320, identifier:k; 321, identifier:f; 322, for_in_clause; 322, 323; 322, 326; 323, pattern_list; 323, 324; 323, 325; 324, identifier:k; 325, identifier:f; 326, call; 326, 327; 326, 328; 327, identifier:zip; 328, argument_list; 328, 329; 328, 330; 329, identifier:attributes; 330, identifier:attributes_fill; 331, expression_statement; 331, 332; 332, augmented_assignment:+=; 332, 333; 332, 334; 333, identifier:rec; 334, identifier:vattrs; 335, expression_statement; 335, 336; 336, yield; 336, 337; 337, identifier:rec; 338, finally_clause; 338, 339; 339, block; 339, 340; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:buffer; 344, identifier:close; 345, argument_list | def iter_gff3(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix'):
if attributes is not None:
attributes = list(attributes)
if isinstance(attributes_fill, (list, tuple)):
if len(attributes) != len(attributes_fill):
raise ValueError('number of fills does not match attributes')
else:
attributes_fill = [attributes_fill] * len(attributes)
if region is not None:
cmd = [tabix, path, region]
buffer = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout
elif path.endswith('.gz') or path.endswith('.bgz'):
buffer = gzip.open(path, mode='rb')
else:
buffer = open(path, mode='rb')
try:
for line in buffer:
if line[0] == b'>':
return
if line[0] == b'
continue
vals = line.split(b'\t')
if len(vals) == 9:
fseqid, fsource, ftype, fstart, fend, fscore, fstrand, fphase, fattrs = vals
fstart = int(fstart)
fend = int(fend)
if fscore == b'.':
fscore = score_fill
else:
fscore = float(fscore)
if fphase == b'.':
fphase = phase_fill
else:
fphase = int(fphase)
if not PY2:
fseqid = str(fseqid, 'ascii')
fsource = str(fsource, 'ascii')
ftype = str(ftype, 'ascii')
fstrand = str(fstrand, 'ascii')
fattrs = str(fattrs, 'ascii')
rec = (fseqid, fsource, ftype, fstart, fend, fscore, fstrand, fphase)
if attributes is not None:
dattrs = gff3_parse_attributes(fattrs)
vattrs = tuple(
dattrs.get(k, f)
for k, f in zip(attributes, attributes_fill)
)
rec += vattrs
yield rec
finally:
buffer.close() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:gff3_to_recarray; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 15; 3, 19; 3, 22; 3, 25; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:attributes; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:region; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:score_fill; 13, unary_operator:-; 13, 14; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:phase_fill; 17, unary_operator:-; 17, 18; 18, integer:1; 19, default_parameter; 19, 20; 19, 21; 20, identifier:attributes_fill; 21, string:'.'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:tabix; 24, string:'tabix'; 25, default_parameter; 25, 26; 25, 27; 26, identifier:dtype; 27, None; 28, block; 28, 29; 28, 57; 28, 63; 28, 112; 28, 126; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:recs; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:iter_gff3; 37, argument_list; 37, 38; 37, 39; 37, 42; 37, 45; 37, 48; 37, 51; 37, 54; 38, identifier:path; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:attributes; 41, identifier:attributes; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:region; 44, identifier:region; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:score_fill; 47, identifier:score_fill; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:phase_fill; 50, identifier:phase_fill; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:attributes_fill; 53, identifier:attributes_fill; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:tabix; 56, identifier:tabix; 57, if_statement; 57, 58; 57, 60; 58, not_operator; 58, 59; 59, identifier:recs; 60, block; 60, 61; 61, return_statement; 61, 62; 62, None; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:dtype; 66, None; 67, block; 67, 68; 67, 96; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:dtype; 71, list:[('seqid', object),
('source', object),
('type', object),
('start', int),
('end', int),
('score', float),
('strand', object),
('phase', int)]; 71, 72; 71, 75; 71, 78; 71, 81; 71, 84; 71, 87; 71, 90; 71, 93; 72, tuple; 72, 73; 72, 74; 73, string:'seqid'; 74, identifier:object; 75, tuple; 75, 76; 75, 77; 76, string:'source'; 77, identifier:object; 78, tuple; 78, 79; 78, 80; 79, string:'type'; 80, identifier:object; 81, tuple; 81, 82; 81, 83; 82, string:'start'; 83, identifier:int; 84, tuple; 84, 85; 84, 86; 85, string:'end'; 86, identifier:int; 87, tuple; 87, 88; 87, 89; 88, string:'score'; 89, identifier:float; 90, tuple; 90, 91; 90, 92; 91, string:'strand'; 92, identifier:object; 93, tuple; 93, 94; 93, 95; 94, string:'phase'; 95, identifier:int; 96, if_statement; 96, 97; 96, 98; 97, identifier:attributes; 98, block; 98, 99; 99, for_statement; 99, 100; 99, 101; 99, 102; 100, identifier:n; 101, identifier:attributes; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:dtype; 107, identifier:append; 108, argument_list; 108, 109; 109, tuple; 109, 110; 109, 111; 110, identifier:n; 111, identifier:object; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:a; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:np; 119, identifier:rec; 120, identifier:fromrecords; 121, argument_list; 121, 122; 121, 123; 122, identifier:recs; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:dtype; 125, identifier:dtype; 126, return_statement; 126, 127; 127, identifier:a | def gff3_to_recarray(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix', dtype=None):
recs = list(iter_gff3(path, attributes=attributes, region=region,
score_fill=score_fill, phase_fill=phase_fill,
attributes_fill=attributes_fill, tabix=tabix))
if not recs:
return None
if dtype is None:
dtype = [('seqid', object),
('source', object),
('type', object),
('start', int),
('end', int),
('score', float),
('strand', object),
('phase', int)]
if attributes:
for n in attributes:
dtype.append((n, object))
a = np.rec.fromrecords(recs, dtype=dtype)
return a |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:gff3_to_dataframe; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 15; 3, 19; 3, 22; 3, 25; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:attributes; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:region; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:score_fill; 13, unary_operator:-; 13, 14; 14, integer:1; 15, default_parameter; 15, 16; 15, 17; 16, identifier:phase_fill; 17, unary_operator:-; 17, 18; 18, integer:1; 19, default_parameter; 19, 20; 19, 21; 20, identifier:attributes_fill; 21, string:'.'; 22, default_parameter; 22, 23; 22, 24; 23, identifier:tabix; 24, string:'tabix'; 25, dictionary_splat_pattern; 25, 26; 26, identifier:kwargs; 27, block; 27, 28; 27, 31; 27, 59; 27, 71; 27, 81; 27, 97; 28, import_statement; 28, 29; 29, dotted_name; 29, 30; 30, identifier:pandas; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:recs; 34, call; 34, 35; 34, 36; 35, identifier:list; 36, argument_list; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:iter_gff3; 39, argument_list; 39, 40; 39, 41; 39, 44; 39, 47; 39, 50; 39, 53; 39, 56; 40, identifier:path; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:attributes; 43, identifier:attributes; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:region; 46, identifier:region; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:score_fill; 49, identifier:score_fill; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:phase_fill; 52, identifier:phase_fill; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:attributes_fill; 55, identifier:attributes_fill; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:tabix; 58, identifier:tabix; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:columns; 62, list:['seqid', 'source', 'type', 'start', 'end', 'score', 'strand', 'phase']; 62, 63; 62, 64; 62, 65; 62, 66; 62, 67; 62, 68; 62, 69; 62, 70; 63, string:'seqid'; 64, string:'source'; 65, string:'type'; 66, string:'start'; 67, string:'end'; 68, string:'score'; 69, string:'strand'; 70, string:'phase'; 71, if_statement; 71, 72; 71, 73; 72, identifier:attributes; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, augmented_assignment:+=; 75, 76; 75, 77; 76, identifier:columns; 77, call; 77, 78; 77, 79; 78, identifier:list; 79, argument_list; 79, 80; 80, identifier:attributes; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:df; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:pandas; 88, identifier:DataFrame; 89, identifier:from_records; 90, argument_list; 90, 91; 90, 92; 90, 95; 91, identifier:recs; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:columns; 94, identifier:columns; 95, dictionary_splat; 95, 96; 96, identifier:kwargs; 97, return_statement; 97, 98; 98, identifier:df | def gff3_to_dataframe(path, attributes=None, region=None, score_fill=-1,
phase_fill=-1, attributes_fill='.', tabix='tabix', **kwargs):
import pandas
recs = list(iter_gff3(path, attributes=attributes, region=region,
score_fill=score_fill, phase_fill=phase_fill,
attributes_fill=attributes_fill, tabix=tabix))
columns = ['seqid', 'source', 'type', 'start', 'end', 'score', 'strand', 'phase']
if attributes:
columns += list(attributes)
df = pandas.DataFrame.from_records(recs, columns=columns, **kwargs)
return df |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:voight_painting; 3, parameters; 3, 4; 4, identifier:h; 5, block; 5, 6; 5, 21; 5, 35; 5, 49; 5, 57; 5, 70; 5, 85; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:h; 9, call; 9, 10; 9, 11; 10, identifier:HaplotypeArray; 11, argument_list; 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:h; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:copy; 20, False; 21, if_statement; 21, 22; 21, 29; 22, comparison_operator:>; 22, 23; 22, 28; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:h; 26, identifier:max; 27, argument_list; 28, integer:1; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:NotImplementedError; 33, argument_list; 33, 34; 34, string:'only biallelic variants are supported'; 35, if_statement; 35, 36; 35, 43; 36, comparison_operator:<; 36, 37; 36, 42; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:h; 40, identifier:min; 41, argument_list; 42, integer:0; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:NotImplementedError; 47, argument_list; 47, 48; 48, string:'missing calls are not supported'; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:indices; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:h; 55, identifier:prefix_argsort; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:h; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:np; 63, identifier:take; 64, argument_list; 64, 65; 64, 66; 64, 67; 65, identifier:h; 66, identifier:indices; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:axis; 69, integer:1; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:painting; 73, call; 73, 74; 73, 75; 74, identifier:paint_shared_prefixes; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:memoryview_safe; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:np; 82, identifier:asarray; 83, argument_list; 83, 84; 84, identifier:h; 85, return_statement; 85, 86; 86, expression_list; 86, 87; 86, 88; 87, identifier:painting; 88, identifier:indices | def voight_painting(h):
h = HaplotypeArray(np.asarray(h), copy=False)
if h.max() > 1:
raise NotImplementedError('only biallelic variants are supported')
if h.min() < 0:
raise NotImplementedError('missing calls are not supported')
indices = h.prefix_argsort()
h = np.take(h, indices, axis=1)
painting = paint_shared_prefixes(memoryview_safe(np.asarray(h)))
return painting, indices |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_model_perms; 3, parameters; 3, 4; 4, identifier:model; 5, block; 5, 6; 5, 14; 5, 22; 5, 34; 5, 50; 5, 68; 6, import_from_statement; 6, 7; 6, 12; 7, dotted_name; 7, 8; 7, 9; 7, 10; 7, 11; 8, identifier:django; 9, identifier:contrib; 10, identifier:auth; 11, identifier:models; 12, dotted_name; 12, 13; 13, identifier:Permission; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:app_label; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:model; 20, identifier:_meta; 21, identifier:app_label; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:model_name; 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:model; 30, identifier:_meta; 31, identifier:object_name; 32, identifier:lower; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:qs; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:Permission; 41, identifier:objects; 42, identifier:filter; 43, argument_list; 43, 44; 43, 47; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:content_type__app_label; 46, identifier:app_label; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:content_type__model; 49, identifier:model_name; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:perms; 53, generator_expression; 53, 54; 53, 61; 54, binary_operator:%; 54, 55; 54, 56; 55, string:'%s.%s'; 56, tuple; 56, 57; 56, 58; 57, identifier:app_label; 58, attribute; 58, 59; 58, 60; 59, identifier:p; 60, identifier:codename; 61, for_in_clause; 61, 62; 61, 63; 62, identifier:p; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:qs; 66, identifier:iterator; 67, argument_list; 68, return_statement; 68, 69; 69, call; 69, 70; 69, 71; 70, identifier:set; 71, argument_list; 71, 72; 72, identifier:perms | def get_model_perms(model):
from django.contrib.auth.models import Permission
app_label = model._meta.app_label
model_name = model._meta.object_name.lower()
qs = Permission.objects.filter(content_type__app_label=app_label,
content_type__model=model_name)
perms = ('%s.%s' % (app_label, p.codename) for p in qs.iterator())
return set(perms) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sort_trigger_set; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:triggers; 5, default_parameter; 5, 6; 5, 7; 6, identifier:exclude_previous; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:say; 10, None; 11, block; 11, 12; 11, 24; 11, 28; 11, 163; 11, 185; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:say; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:say; 20, lambda; 20, 21; 20, 23; 21, lambda_parameters; 21, 22; 22, identifier:x; 23, identifier:x; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:trigger_object_list; 27, list:[]; 28, for_statement; 28, 29; 28, 32; 28, 36; 29, pattern_list; 29, 30; 29, 31; 30, identifier:index; 31, identifier:trig; 32, call; 32, 33; 32, 34; 33, identifier:enumerate; 34, argument_list; 34, 35; 35, identifier:triggers; 36, block; 36, 37; 36, 47; 36, 53; 36, 71; 36, 86; 36, 98; 36, 150; 37, if_statement; 37, 38; 37, 45; 38, boolean_operator:and; 38, 39; 38, 40; 39, identifier:exclude_previous; 40, subscript; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:trig; 43, integer:1; 44, string:"previous"; 45, block; 45, 46; 46, continue_statement; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:pattern; 50, subscript; 50, 51; 50, 52; 51, identifier:trig; 52, integer:0; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, pattern_list; 55, 56; 55, 57; 56, identifier:match; 57, identifier:weight; 58, expression_list; 58, 59; 58, 70; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:re; 62, identifier:search; 63, argument_list; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:RE; 66, identifier:weight; 67, subscript; 67, 68; 67, 69; 68, identifier:trig; 69, integer:0; 70, integer:0; 71, if_statement; 71, 72; 71, 73; 72, identifier:match; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:weight; 77, call; 77, 78; 77, 79; 78, identifier:int; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:match; 83, identifier:group; 84, argument_list; 84, 85; 85, integer:1; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:match; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:re; 92, identifier:search; 93, argument_list; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:RE; 96, identifier:inherit; 97, identifier:pattern; 98, if_statement; 98, 99; 98, 100; 98, 142; 99, identifier:match; 100, block; 100, 101; 100, 113; 100, 123; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:inherit; 104, call; 104, 105; 104, 106; 105, identifier:int; 106, argument_list; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:match; 110, identifier:group; 111, argument_list; 111, 112; 112, integer:1; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:say; 116, argument_list; 116, 117; 117, binary_operator:+; 117, 118; 117, 119; 118, string:"\t\t\tTrigger belongs to a topic which inherits other topics: level="; 119, call; 119, 120; 119, 121; 120, identifier:str; 121, argument_list; 121, 122; 122, identifier:inherit; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:triggers; 128, identifier:index; 129, integer:0; 130, assignment; 130, 131; 130, 132; 131, identifier:pattern; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:re; 135, identifier:sub; 136, argument_list; 136, 137; 136, 140; 136, 141; 137, attribute; 137, 138; 137, 139; 138, identifier:RE; 139, identifier:inherit; 140, string:""; 141, identifier:pattern; 142, else_clause; 142, 143; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:inherit; 147, attribute; 147, 148; 147, 149; 148, identifier:sys; 149, identifier:maxsize; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:trigger_object_list; 154, identifier:append; 155, argument_list; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:TriggerObj; 158, argument_list; 158, 159; 158, 160; 158, 161; 158, 162; 159, identifier:pattern; 160, identifier:index; 161, identifier:weight; 162, identifier:inherit; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:sorted_list; 166, call; 166, 167; 166, 168; 167, identifier:sorted; 168, argument_list; 168, 169; 168, 170; 169, identifier:trigger_object_list; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:key; 172, call; 172, 173; 172, 174; 173, identifier:attrgetter; 174, argument_list; 174, 175; 174, 176; 174, 177; 174, 178; 174, 179; 174, 180; 174, 181; 174, 182; 174, 183; 174, 184; 175, string:'weight'; 176, string:'inherit'; 177, string:'is_empty'; 178, string:'star'; 179, string:'pound'; 180, string:'under'; 181, string:'option'; 182, string:'wordcount'; 183, string:'len'; 184, string:'alphabet'; 185, return_statement; 185, 186; 186, list_comprehension; 186, 187; 186, 192; 187, subscript; 187, 188; 187, 189; 188, identifier:triggers; 189, attribute; 189, 190; 189, 191; 190, identifier:item; 191, identifier:index; 192, for_in_clause; 192, 193; 192, 194; 193, identifier:item; 194, identifier:sorted_list | def sort_trigger_set(triggers, exclude_previous=True, say=None):
if say is None:
say = lambda x: x
trigger_object_list = []
for index, trig in enumerate(triggers):
if exclude_previous and trig[1]["previous"]:
continue
pattern = trig[0]
match, weight = re.search(RE.weight, trig[0]), 0
if match:
weight = int(match.group(1))
match = re.search(RE.inherit, pattern)
if match:
inherit = int(match.group(1))
say("\t\t\tTrigger belongs to a topic which inherits other topics: level=" + str(inherit))
triggers[index][0] = pattern = re.sub(RE.inherit, "", pattern)
else:
inherit = sys.maxsize
trigger_object_list.append(TriggerObj(pattern, index, weight, inherit))
sorted_list = sorted(trigger_object_list,
key=attrgetter('weight', 'inherit', 'is_empty', 'star', 'pound',
'under', 'option', 'wordcount', 'len', 'alphabet'))
return [triggers[item.index] for item in sorted_list] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_list; 3, parameters; 3, 4; 4, identifier:items; 5, block; 5, 6; 5, 10; 5, 26; 5, 62; 5, 66; 5, 102; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:track; 9, dictionary; 10, function_definition; 10, 11; 10, 12; 10, 15; 11, function_name:by_length; 12, parameters; 12, 13; 12, 14; 13, identifier:word1; 14, identifier:word2; 15, block; 15, 16; 16, return_statement; 16, 17; 17, binary_operator:-; 17, 18; 17, 22; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, identifier:word2; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, identifier:word1; 26, for_statement; 26, 27; 26, 28; 26, 29; 27, identifier:item; 28, identifier:items; 29, block; 29, 30; 29, 42; 29, 53; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:cword; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:utils; 36, identifier:word_count; 37, argument_list; 37, 38; 37, 39; 38, identifier:item; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:all; 41, True; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:not; 43, 44; 43, 45; 44, identifier:cword; 45, identifier:track; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:track; 51, identifier:cword; 52, list:[]; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:track; 58, identifier:cword; 59, identifier:append; 60, argument_list; 60, 61; 61, identifier:item; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:output; 65, list:[]; 66, for_statement; 66, 67; 66, 68; 66, 79; 67, identifier:count; 68, call; 68, 69; 68, 70; 69, identifier:sorted; 70, argument_list; 70, 71; 70, 76; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:track; 74, identifier:keys; 75, argument_list; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:reverse; 78, True; 79, block; 79, 80; 79, 95; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:sort; 83, call; 83, 84; 83, 85; 84, identifier:sorted; 85, argument_list; 85, 86; 85, 89; 85, 92; 86, subscript; 86, 87; 86, 88; 87, identifier:track; 88, identifier:count; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:key; 91, identifier:len; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:reverse; 94, True; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:output; 99, identifier:extend; 100, argument_list; 100, 101; 101, identifier:sort; 102, return_statement; 102, 103; 103, identifier:output | def sort_list(items):
track = {}
def by_length(word1, word2):
return len(word2) - len(word1)
for item in items:
cword = utils.word_count(item, all=True)
if cword not in track:
track[cword] = []
track[cword].append(item)
output = []
for count in sorted(track.keys(), reverse=True):
sort = sorted(track[count], key=len, reverse=True)
output.extend(sort)
return output |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_replies; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:thats; 7, False; 8, block; 8, 9; 8, 17; 8, 25; 8, 32; 8, 111; 8, 127; 8, 148; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 16; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_sorted; 15, string:"topics"; 16, dictionary; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 24; 19, subscript; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_sorted; 23, string:"thats"; 24, dictionary; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_say; 30, argument_list; 30, 31; 31, string:"Sorting triggers..."; 32, for_statement; 32, 33; 32, 34; 32, 41; 33, identifier:topic; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_topics; 39, identifier:keys; 40, argument_list; 41, block; 41, 42; 41, 51; 41, 62; 41, 81; 41, 92; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_say; 47, argument_list; 47, 48; 48, binary_operator:+; 48, 49; 48, 50; 49, string:"Analyzing topic "; 50, identifier:topic; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:alltrig; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:inherit_utils; 57, identifier:get_topic_triggers; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, identifier:self; 60, identifier:topic; 61, False; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 71; 64, subscript; 64, 65; 64, 70; 65, subscript; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_sorted; 69, string:"topics"; 70, identifier:topic; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:sorting; 74, identifier:sort_trigger_set; 75, argument_list; 75, 76; 75, 77; 75, 78; 76, identifier:alltrig; 77, True; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_say; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:that_triggers; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:inherit_utils; 87, identifier:get_topic_triggers; 88, argument_list; 88, 89; 88, 90; 88, 91; 89, identifier:self; 90, identifier:topic; 91, True; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 101; 94, subscript; 94, 95; 94, 100; 95, subscript; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:_sorted; 99, string:"thats"; 100, identifier:topic; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:sorting; 104, identifier:sort_trigger_set; 105, argument_list; 105, 106; 105, 107; 105, 108; 106, identifier:that_triggers; 107, False; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:_say; 111, if_statement; 111, 112; 111, 118; 112, not_operator; 112, 113; 113, comparison_operator:in; 113, 114; 113, 115; 114, string:"lists"; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:_sorted; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_sorted; 125, string:"lists"; 126, dictionary; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 136; 129, subscript; 129, 130; 129, 135; 130, subscript; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:_sorted; 134, string:"lists"; 135, string:"sub"; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:sorting; 139, identifier:sort_list; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:_sub; 146, identifier:keys; 147, argument_list; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 157; 150, subscript; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_sorted; 155, string:"lists"; 156, string:"person"; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:sorting; 160, identifier:sort_list; 161, argument_list; 161, 162; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:_person; 167, identifier:keys; 168, argument_list | def sort_replies(self, thats=False):
self._sorted["topics"] = {}
self._sorted["thats"] = {}
self._say("Sorting triggers...")
for topic in self._topics.keys():
self._say("Analyzing topic " + topic)
alltrig = inherit_utils.get_topic_triggers(self, topic, False)
self._sorted["topics"][topic] = sorting.sort_trigger_set(alltrig, True, self._say)
that_triggers = inherit_utils.get_topic_triggers(self, topic, True)
self._sorted["thats"][topic] = sorting.sort_trigger_set(that_triggers, False, self._say)
if not "lists" in self._sorted:
self._sorted["lists"] = {}
self._sorted["lists"]["sub"] = sorting.sort_list(self._sub.keys())
self._sorted["lists"]["person"] = sorting.sort_list(self._person.keys()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:all; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 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:per_page; 10, integer:10; 11, default_parameter; 11, 12; 11, 13; 12, identifier:order_by; 13, string:"latest"; 14, block; 14, 15; 15, return_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_all; 20, argument_list; 20, 21; 20, 22; 20, 25; 20, 28; 21, string:"/photos"; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:page; 24, identifier:page; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:per_page; 27, identifier:per_page; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:order_by; 30, identifier:order_by | def all(self, page=1, per_page=10, order_by="latest"):
return self._all("/photos", page=page, per_page=per_page, order_by=order_by) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:photos; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:username; 6, default_parameter; 6, 7; 6, 8; 7, identifier:page; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:per_page; 11, integer:10; 12, default_parameter; 12, 13; 12, 14; 13, identifier:order_by; 14, string:"latest"; 15, block; 15, 16; 15, 27; 15, 46; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:url; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, string:"/users/{username}/photos"; 22, identifier:format; 23, argument_list; 23, 24; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:username; 26, identifier:username; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:result; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_photos; 34, argument_list; 34, 35; 34, 36; 34, 37; 34, 40; 34, 43; 35, identifier:url; 36, identifier:username; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:page; 39, identifier:page; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:per_page; 42, identifier:per_page; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:order_by; 45, identifier:order_by; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:PhotoModel; 50, identifier:parse_list; 51, argument_list; 51, 52; 52, identifier:result | def photos(self, username, page=1, per_page=10, order_by="latest"):
url = "/users/{username}/photos".format(username=username)
result = self._photos(url, username, page=page, per_page=per_page, order_by=order_by)
return PhotoModel.parse_list(result) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:callable; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:nans; 7, False; 8, block; 8, 9; 8, 23; 8, 123; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:jitfunc; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:nb; 15, identifier:njit; 16, argument_list; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:func; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:nogil; 22, True; 23, function_definition; 23, 24; 23, 25; 23, 30; 24, function_name:_loop; 25, parameters; 25, 26; 25, 27; 25, 28; 25, 29; 26, identifier:sortidx; 27, identifier:group_idx; 28, identifier:a; 29, identifier:ret; 30, block; 30, 31; 30, 38; 30, 44; 30, 50; 30, 57; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:size; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, identifier:ret; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:group_idx_srt; 41, subscript; 41, 42; 41, 43; 42, identifier:group_idx; 43, identifier:sortidx; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:a_srt; 47, subscript; 47, 48; 47, 49; 48, identifier:a; 49, identifier:sortidx; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:indices; 53, call; 53, 54; 53, 55; 54, identifier:step_indices; 55, argument_list; 55, 56; 56, identifier:group_idx_srt; 57, for_statement; 57, 58; 57, 59; 57, 68; 58, identifier:i; 59, call; 59, 60; 59, 61; 60, identifier:range; 61, argument_list; 61, 62; 62, binary_operator:-; 62, 63; 62, 67; 63, call; 63, 64; 63, 65; 64, identifier:len; 65, argument_list; 65, 66; 66, identifier:indices; 67, integer:1; 68, block; 68, 69; 68, 83; 68, 89; 68, 99; 68, 109; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, pattern_list; 71, 72; 71, 73; 72, identifier:start_idx; 73, identifier:stop_idx; 74, expression_list; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:indices; 77, identifier:i; 78, subscript; 78, 79; 78, 80; 79, identifier:indices; 80, binary_operator:+; 80, 81; 80, 82; 81, identifier:i; 82, integer:1; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:ri; 86, subscript; 86, 87; 86, 88; 87, identifier:group_idx_srt; 88, identifier:start_idx; 89, if_statement; 89, 90; 89, 93; 90, comparison_operator:<; 90, 91; 90, 92; 91, identifier:ri; 92, integer:0; 93, block; 93, 94; 94, raise_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:ValueError; 97, argument_list; 97, 98; 98, string:"negative indices not supported"; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:>=; 100, 101; 100, 102; 101, identifier:ri; 102, identifier:size; 103, block; 103, 104; 104, raise_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:ValueError; 107, argument_list; 107, 108; 108, string:"one or more indices in group_idx are too large"; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:ret; 113, identifier:ri; 114, call; 114, 115; 114, 116; 115, identifier:jitfunc; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:a_srt; 119, slice; 119, 120; 119, 121; 119, 122; 120, identifier:start_idx; 121, colon; 122, identifier:stop_idx; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:nb; 127, identifier:njit; 128, argument_list; 128, 129; 128, 130; 129, identifier:_loop; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:nogil; 132, True | def callable(self, nans=False):
jitfunc = nb.njit(self.func, nogil=True)
def _loop(sortidx, group_idx, a, ret):
size = len(ret)
group_idx_srt = group_idx[sortidx]
a_srt = a[sortidx]
indices = step_indices(group_idx_srt)
for i in range(len(indices) - 1):
start_idx, stop_idx = indices[i], indices[i + 1]
ri = group_idx_srt[start_idx]
if ri < 0:
raise ValueError("negative indices not supported")
if ri >= size:
raise ValueError("one or more indices in group_idx are too large")
ret[ri] = jitfunc(a_srt[start_idx:stop_idx])
return nb.njit(_loop, nogil=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:scores2recos; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:scores; 6, identifier:candidates; 7, default_parameter; 7, 8; 7, 9; 8, identifier:rev; 9, False; 10, block; 10, 11; 10, 20; 10, 33; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:sorted_indices; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:np; 17, identifier:argsort; 18, argument_list; 18, 19; 19, identifier:scores; 20, if_statement; 20, 21; 20, 22; 21, identifier:rev; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:sorted_indices; 26, subscript; 26, 27; 26, 28; 27, identifier:sorted_indices; 28, slice; 28, 29; 28, 30; 28, 31; 29, colon; 30, colon; 31, unary_operator:-; 31, 32; 32, integer:1; 33, return_statement; 33, 34; 34, expression_list; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:candidates; 37, identifier:sorted_indices; 38, subscript; 38, 39; 38, 40; 39, identifier:scores; 40, identifier:sorted_indices | def scores2recos(self, scores, candidates, rev=False):
sorted_indices = np.argsort(scores)
if rev:
sorted_indices = sorted_indices[::-1]
return candidates[sorted_indices], scores[sorted_indices] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 1, 28; 2, function_name:commutative_sequence_variable_partition_iter; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:values; 6, type; 6, 7; 7, identifier:Multiset; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:variables; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:List; 13, type_parameter; 13, 14; 14, type; 14, 15; 15, identifier:VariableWithCount; 16, type; 16, 17; 17, generic_type; 17, 18; 17, 19; 18, identifier:Iterator; 19, type_parameter; 19, 20; 20, type; 20, 21; 21, generic_type; 21, 22; 21, 23; 22, identifier:Dict; 23, type_parameter; 23, 24; 23, 26; 24, type; 24, 25; 25, identifier:str; 26, type; 26, 27; 27, identifier:Multiset; 28, block; 28, 29; 28, 47; 28, 51; 28, 73; 28, 89; 29, if_statement; 29, 30; 29, 36; 30, comparison_operator:==; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:len; 33, argument_list; 33, 34; 34, identifier:variables; 35, integer:1; 36, block; 36, 37; 36, 46; 37, expression_statement; 37, 38; 38, yield; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:_commutative_single_variable_partiton_iter; 41, argument_list; 41, 42; 41, 43; 42, identifier:values; 43, subscript; 43, 44; 43, 45; 44, identifier:variables; 45, integer:0; 46, return_statement; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:generators; 50, list:[]; 51, for_statement; 51, 52; 51, 55; 51, 60; 52, pattern_list; 52, 53; 52, 54; 53, identifier:value; 54, identifier:count; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:values; 58, identifier:items; 59, argument_list; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:generators; 65, identifier:append; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:_make_variable_generator_factory; 69, argument_list; 69, 70; 69, 71; 69, 72; 70, identifier:value; 71, identifier:count; 72, identifier:variables; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:initial; 76, call; 76, 77; 76, 78; 77, identifier:dict; 78, generator_expression; 78, 79; 78, 86; 79, tuple; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:var; 82, identifier:name; 83, call; 83, 84; 83, 85; 84, identifier:Multiset; 85, argument_list; 86, for_in_clause; 86, 87; 86, 88; 87, identifier:var; 88, identifier:variables; 89, for_statement; 89, 90; 89, 91; 89, 97; 90, identifier:subst; 91, call; 91, 92; 91, 93; 92, identifier:generator_chain; 93, argument_list; 93, 94; 93, 95; 94, identifier:initial; 95, list_splat; 95, 96; 96, identifier:generators; 97, block; 97, 98; 97, 102; 97, 153; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:valid; 101, True; 102, for_statement; 102, 103; 102, 104; 102, 105; 103, identifier:var; 104, identifier:variables; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 123; 106, 134; 107, boolean_operator:and; 107, 108; 107, 113; 108, comparison_operator:is; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:var; 111, identifier:default; 112, None; 113, comparison_operator:==; 113, 114; 113, 122; 114, call; 114, 115; 114, 116; 115, identifier:len; 116, argument_list; 116, 117; 117, subscript; 117, 118; 117, 119; 118, identifier:subst; 119, attribute; 119, 120; 119, 121; 120, identifier:var; 121, identifier:name; 122, integer:0; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 131; 126, subscript; 126, 127; 126, 128; 127, identifier:subst; 128, attribute; 128, 129; 128, 130; 129, identifier:var; 130, identifier:name; 131, attribute; 131, 132; 131, 133; 132, identifier:var; 133, identifier:default; 134, elif_clause; 134, 135; 134, 147; 135, comparison_operator:<; 135, 136; 135, 144; 136, call; 136, 137; 136, 138; 137, identifier:len; 138, argument_list; 138, 139; 139, subscript; 139, 140; 139, 141; 140, identifier:subst; 141, attribute; 141, 142; 141, 143; 142, identifier:var; 143, identifier:name; 144, attribute; 144, 145; 144, 146; 145, identifier:var; 146, identifier:minimum; 147, block; 147, 148; 147, 152; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:valid; 151, False; 152, break_statement; 153, if_statement; 153, 154; 153, 155; 154, identifier:valid; 155, block; 155, 156; 155, 165; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:in; 157, 158; 157, 159; 158, None; 159, identifier:subst; 160, block; 160, 161; 161, delete_statement; 161, 162; 162, subscript; 162, 163; 162, 164; 163, identifier:subst; 164, None; 165, expression_statement; 165, 166; 166, yield; 166, 167; 167, identifier:subst | def commutative_sequence_variable_partition_iter(values: Multiset, variables: List[VariableWithCount]
) -> Iterator[Dict[str, Multiset]]:
if len(variables) == 1:
yield from _commutative_single_variable_partiton_iter(values, variables[0])
return
generators = []
for value, count in values.items():
generators.append(_make_variable_generator_factory(value, count, variables))
initial = dict((var.name, Multiset()) for var in variables)
for subst in generator_chain(initial, *generators):
valid = True
for var in variables:
if var.default is not None and len(subst[var.name]) == 0:
subst[var.name] = var.default
elif len(subst[var.name]) < var.minimum:
valid = False
break
if valid:
if None in subst:
del subst[None]
yield subst |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:iter_cookie_browse_sorting; 3, parameters; 3, 4; 4, identifier:cookies; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, string:'''
Get sorting-cookie from cookies dictionary.
:yields: tuple of path and sorting property
:ytype: 2-tuple of strings
'''; 8, try_statement; 8, 9; 8, 51; 9, block; 9, 10; 9, 25; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:data; 13, call; 13, 14; 13, 23; 14, attribute; 14, 15; 14, 22; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:cookies; 18, identifier:get; 19, argument_list; 19, 20; 19, 21; 20, string:'browse-sorting'; 21, string:'e30='; 22, identifier:encode; 23, argument_list; 23, 24; 24, string:'ascii'; 25, for_statement; 25, 26; 25, 29; 25, 45; 26, pattern_list; 26, 27; 26, 28; 27, identifier:path; 28, identifier:prop; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:json; 32, identifier:loads; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 43; 35, attribute; 35, 36; 35, 42; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:base64; 39, identifier:b64decode; 40, argument_list; 40, 41; 41, identifier:data; 42, identifier:decode; 43, argument_list; 43, 44; 44, string:'utf-8'; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, yield; 47, 48; 48, expression_list; 48, 49; 48, 50; 49, identifier:path; 50, identifier:prop; 51, except_clause; 51, 52; 51, 59; 52, as_pattern; 52, 53; 52, 57; 53, tuple; 53, 54; 53, 55; 53, 56; 54, identifier:ValueError; 55, identifier:TypeError; 56, identifier:KeyError; 57, as_pattern_target; 57, 58; 58, identifier:e; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:logger; 64, identifier:exception; 65, argument_list; 65, 66; 66, identifier:e | def iter_cookie_browse_sorting(cookies):
'''
Get sorting-cookie from cookies dictionary.
:yields: tuple of path and sorting property
:ytype: 2-tuple of strings
'''
try:
data = cookies.get('browse-sorting', 'e30=').encode('ascii')
for path, prop in json.loads(base64.b64decode(data).decode('utf-8')):
yield path, prop
except (ValueError, TypeError, KeyError) as e:
logger.exception(e) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_cookie_browse_sorting; 3, parameters; 3, 4; 3, 5; 4, identifier:path; 5, identifier:default; 6, block; 6, 7; 6, 9; 6, 30; 7, expression_statement; 7, 8; 8, string:'''
Get sorting-cookie data for path of current request.
:returns: sorting property
:rtype: string
'''; 9, if_statement; 9, 10; 9, 11; 10, identifier:request; 11, block; 11, 12; 12, for_statement; 12, 13; 12, 16; 12, 22; 13, pattern_list; 13, 14; 13, 15; 14, identifier:cpath; 15, identifier:cprop; 16, call; 16, 17; 16, 18; 17, identifier:iter_cookie_browse_sorting; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:request; 21, identifier:cookies; 22, block; 22, 23; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:==; 24, 25; 24, 26; 25, identifier:path; 26, identifier:cpath; 27, block; 27, 28; 28, return_statement; 28, 29; 29, identifier:cprop; 30, return_statement; 30, 31; 31, identifier:default | def get_cookie_browse_sorting(path, default):
'''
Get sorting-cookie data for path of current request.
:returns: sorting property
:rtype: string
'''
if request:
for cpath, cprop in iter_cookie_browse_sorting(request.cookies):
if path == cpath:
return cprop
return default |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:integral; 3, parameters; 3, 4; 3, 5; 4, identifier:requestContext; 5, identifier:seriesList; 6, block; 6, 7; 6, 11; 6, 90; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:results; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:series; 13, identifier:seriesList; 14, block; 14, 15; 14, 19; 14, 23; 14, 52; 14, 60; 14, 77; 14, 83; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:newValues; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:current; 22, float:0.0; 23, for_statement; 23, 24; 23, 25; 23, 26; 24, identifier:val; 25, identifier:series; 26, block; 26, 27; 27, if_statement; 27, 28; 27, 31; 27, 39; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:val; 30, None; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:newValues; 36, identifier:append; 37, argument_list; 37, 38; 38, None; 39, else_clause; 39, 40; 40, block; 40, 41; 40, 45; 41, expression_statement; 41, 42; 42, augmented_assignment:+=; 42, 43; 42, 44; 43, identifier:current; 44, identifier:val; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:newValues; 49, identifier:append; 50, argument_list; 50, 51; 51, identifier:current; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:newName; 55, binary_operator:%; 55, 56; 55, 57; 56, string:"integral(%s)"; 57, attribute; 57, 58; 57, 59; 58, identifier:series; 59, identifier:name; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:newSeries; 63, call; 63, 64; 63, 65; 64, identifier:TimeSeries; 65, argument_list; 65, 66; 65, 67; 65, 70; 65, 73; 65, 76; 66, identifier:newName; 67, attribute; 67, 68; 67, 69; 68, identifier:series; 69, identifier:start; 70, attribute; 70, 71; 70, 72; 71, identifier:series; 72, identifier:end; 73, attribute; 73, 74; 73, 75; 74, identifier:series; 75, identifier:step; 76, identifier:newValues; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:newSeries; 81, identifier:pathExpression; 82, identifier:newName; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:results; 87, identifier:append; 88, argument_list; 88, 89; 89, identifier:newSeries; 90, return_statement; 90, 91; 91, identifier:results | def integral(requestContext, seriesList):
results = []
for series in seriesList:
newValues = []
current = 0.0
for val in series:
if val is None:
newValues.append(None)
else:
current += val
newValues.append(current)
newName = "integral(%s)" % series.name
newSeries = TimeSeries(newName, series.start, series.end, series.step,
newValues)
newSeries.pathExpression = newName
results.append(newSeries)
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:map_metabolite2kegg; 3, parameters; 3, 4; 4, identifier:metabolite; 5, block; 5, 6; 5, 16; 5, 27; 5, 43; 5, 78; 5, 88; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:logger; 10, identifier:debug; 11, argument_list; 11, 12; 11, 13; 12, string:"Looking for KEGG compound identifier for %s."; 13, attribute; 13, 14; 13, 15; 14, identifier:metabolite; 15, identifier:id; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:kegg_annotation; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:metabolite; 23, identifier:annotation; 24, identifier:get; 25, argument_list; 25, 26; 26, string:"kegg.compound"; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:kegg_annotation; 30, None; 31, block; 31, 32; 31, 42; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:logger; 36, identifier:warning; 37, argument_list; 37, 38; 37, 39; 38, string:"No kegg.compound annotation for metabolite %s."; 39, attribute; 39, 40; 39, 41; 40, identifier:metabolite; 41, identifier:id; 42, return_statement; 43, if_statement; 43, 44; 43, 57; 43, 60; 44, boolean_operator:and; 44, 45; 44, 50; 44, 51; 45, call; 45, 46; 45, 47; 46, identifier:isinstance; 47, argument_list; 47, 48; 47, 49; 48, identifier:kegg_annotation; 49, identifier:string_types; 50, line_continuation:\; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:kegg_annotation; 54, identifier:startswith; 55, argument_list; 55, 56; 56, string:"C"; 57, block; 57, 58; 58, return_statement; 58, 59; 59, identifier:kegg_annotation; 60, elif_clause; 60, 61; 60, 66; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:kegg_annotation; 65, identifier:Iterable; 66, block; 66, 67; 67, try_statement; 67, 68; 67, 74; 68, block; 68, 69; 69, return_statement; 69, 70; 70, call; 70, 71; 70, 72; 71, identifier:get_smallest_compound_id; 72, argument_list; 72, 73; 73, identifier:kegg_annotation; 74, except_clause; 74, 75; 74, 76; 75, identifier:ValueError; 76, block; 76, 77; 77, return_statement; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:logger; 82, identifier:warning; 83, argument_list; 83, 84; 83, 85; 84, string:"No matching kegg.compound annotation for metabolite %s."; 85, attribute; 85, 86; 85, 87; 86, identifier:metabolite; 87, identifier:id; 88, return_statement | def map_metabolite2kegg(metabolite):
logger.debug("Looking for KEGG compound identifier for %s.", metabolite.id)
kegg_annotation = metabolite.annotation.get("kegg.compound")
if kegg_annotation is None:
logger.warning("No kegg.compound annotation for metabolite %s.",
metabolite.id)
return
if isinstance(kegg_annotation, string_types) and \
kegg_annotation.startswith("C"):
return kegg_annotation
elif isinstance(kegg_annotation, Iterable):
try:
return get_smallest_compound_id(kegg_annotation)
except ValueError:
return
logger.warning(
"No matching kegg.compound annotation for metabolite %s.",
metabolite.id
)
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:preProcessForComparison; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:results; 5, identifier:target_size; 6, identifier:size_tolerance_prct; 7, block; 7, 8; 7, 12; 7, 53; 7, 71; 7, 75; 7, 136; 7, 148; 7, 172; 7, 377; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:reference; 11, None; 12, for_statement; 12, 13; 12, 14; 12, 15; 13, identifier:result; 14, identifier:results; 15, block; 15, 16; 16, if_statement; 16, 17; 16, 24; 17, comparison_operator:is; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:result; 20, identifier:source_quality; 21, attribute; 21, 22; 21, 23; 22, identifier:CoverSourceQuality; 23, identifier:REFERENCE; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 48; 26, parenthesized_expression; 26, 27; 27, boolean_operator:or; 27, 28; 27, 32; 28, parenthesized_expression; 28, 29; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:reference; 31, None; 32, parenthesized_expression; 32, 33; 33, comparison_operator:>; 33, 34; 33, 47; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:CoverSourceResult; 37, identifier:compare; 38, argument_list; 38, 39; 38, 40; 38, 41; 38, 44; 39, identifier:result; 40, identifier:reference; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:target_size; 43, identifier:target_size; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:size_tolerance_prct; 46, identifier:size_tolerance_prct; 47, integer:0; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:reference; 52, identifier:result; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:results; 56, call; 56, 57; 56, 58; 57, identifier:list; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:itertools; 62, identifier:filterfalse; 63, argument_list; 63, 64; 63, 70; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:operator; 67, identifier:attrgetter; 68, argument_list; 68, 69; 69, string:"is_only_reference"; 70, identifier:results; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:no_dup_results; 74, list:[]; 75, for_statement; 75, 76; 75, 77; 75, 78; 76, identifier:result; 77, identifier:results; 78, block; 78, 79; 78, 83; 78, 125; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:is_dup; 82, False; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:result_comp; 85, identifier:results; 86, block; 86, 87; 87, if_statement; 87, 88; 87, 119; 88, parenthesized_expression; 88, 89; 89, boolean_operator:and; 89, 90; 89, 103; 90, boolean_operator:and; 90, 91; 90, 95; 91, parenthesized_expression; 91, 92; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:result_comp; 94, identifier:result; 95, parenthesized_expression; 95, 96; 96, comparison_operator:==; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:result_comp; 99, identifier:urls; 100, attribute; 100, 101; 100, 102; 101, identifier:result; 102, identifier:urls; 103, parenthesized_expression; 103, 104; 104, comparison_operator:<; 104, 105; 104, 118; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:__class__; 108, identifier:compare; 109, argument_list; 109, 110; 109, 111; 109, 112; 109, 115; 110, identifier:result; 111, identifier:result_comp; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:target_size; 114, identifier:target_size; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:size_tolerance_prct; 117, identifier:size_tolerance_prct; 118, integer:0; 119, block; 119, 120; 119, 124; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:is_dup; 123, True; 124, break_statement; 125, if_statement; 125, 126; 125, 128; 126, not_operator; 126, 127; 127, identifier:is_dup; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:no_dup_results; 133, identifier:append; 134, argument_list; 134, 135; 135, identifier:result; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:dup_count; 139, binary_operator:-; 139, 140; 139, 144; 140, call; 140, 141; 140, 142; 141, identifier:len; 142, argument_list; 142, 143; 143, identifier:results; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:no_dup_results; 148, if_statement; 148, 149; 148, 152; 149, comparison_operator:>; 149, 150; 149, 151; 150, identifier:dup_count; 151, integer:0; 152, block; 152, 153; 152, 168; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 163; 155, attribute; 155, 156; 155, 162; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:logging; 159, identifier:getLogger; 160, argument_list; 160, 161; 161, string:"Cover"; 162, identifier:info; 163, argument_list; 163, 164; 164, binary_operator:%; 164, 165; 164, 166; 165, string:"Removed %u duplicate results"; 166, parenthesized_expression; 166, 167; 167, identifier:dup_count; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:results; 171, identifier:no_dup_results; 172, if_statement; 172, 173; 172, 176; 172, 363; 173, comparison_operator:is; 173, 174; 173, 175; 174, identifier:reference; 175, None; 176, block; 176, 177; 176, 192; 176, 198; 176, 202; 176, 230; 176, 264; 176, 275; 176, 285; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 187; 179, attribute; 179, 180; 179, 186; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:logging; 183, identifier:getLogger; 184, argument_list; 184, 185; 185, string:"Cover"; 186, identifier:info; 187, argument_list; 187, 188; 188, binary_operator:%; 188, 189; 188, 190; 189, string:"Reference is: %s"; 190, parenthesized_expression; 190, 191; 191, identifier:reference; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:reference; 196, identifier:is_similar_to_reference; 197, True; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:futures; 201, list:[]; 202, for_statement; 202, 203; 202, 204; 202, 205; 203, identifier:result; 204, identifier:results; 205, block; 205, 206; 205, 214; 205, 223; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:coroutine; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:result; 212, identifier:updateSignature; 213, argument_list; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:future; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:asyncio; 220, identifier:ensure_future; 221, argument_list; 221, 222; 222, identifier:coroutine; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:futures; 227, identifier:append; 228, argument_list; 228, 229; 229, identifier:future; 230, if_statement; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:reference; 233, identifier:is_only_reference; 234, block; 234, 235; 234, 240; 234, 248; 234, 257; 235, assert_statement; 235, 236; 236, parenthesized_expression; 236, 237; 237, comparison_operator:not; 237, 238; 237, 239; 238, identifier:reference; 239, identifier:results; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:coroutine; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:reference; 246, identifier:updateSignature; 247, argument_list; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:future; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:asyncio; 254, identifier:ensure_future; 255, argument_list; 255, 256; 256, identifier:coroutine; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:futures; 261, identifier:append; 262, argument_list; 262, 263; 263, identifier:future; 264, if_statement; 264, 265; 264, 266; 265, identifier:futures; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, await; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:asyncio; 272, identifier:wait; 273, argument_list; 273, 274; 274, identifier:futures; 275, for_statement; 275, 276; 275, 277; 275, 278; 276, identifier:future; 277, identifier:futures; 278, block; 278, 279; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:future; 283, identifier:result; 284, argument_list; 285, for_statement; 285, 286; 285, 287; 285, 288; 286, identifier:result; 287, identifier:results; 288, block; 288, 289; 289, if_statement; 289, 290; 289, 309; 290, parenthesized_expression; 290, 291; 291, boolean_operator:and; 291, 292; 291, 303; 292, boolean_operator:and; 292, 293; 292, 297; 293, parenthesized_expression; 293, 294; 294, comparison_operator:is; 294, 295; 294, 296; 295, identifier:result; 296, identifier:reference; 297, parenthesized_expression; 297, 298; 298, comparison_operator:is; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:result; 301, identifier:thumbnail_sig; 302, None; 303, parenthesized_expression; 303, 304; 304, comparison_operator:is; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:reference; 307, identifier:thumbnail_sig; 308, None; 309, block; 309, 310; 309, 326; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:result; 314, identifier:is_similar_to_reference; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:__class__; 318, identifier:areImageSigsSimilar; 319, argument_list; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:result; 322, identifier:thumbnail_sig; 323, attribute; 323, 324; 323, 325; 324, identifier:reference; 325, identifier:thumbnail_sig; 326, if_statement; 326, 327; 326, 330; 326, 346; 327, attribute; 327, 328; 327, 329; 328, identifier:result; 329, identifier:is_similar_to_reference; 330, block; 330, 331; 331, expression_statement; 331, 332; 332, call; 332, 333; 332, 341; 333, attribute; 333, 334; 333, 340; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:logging; 337, identifier:getLogger; 338, argument_list; 338, 339; 339, string:"Cover"; 340, identifier:debug; 341, argument_list; 341, 342; 342, binary_operator:%; 342, 343; 342, 344; 343, string:"%s is similar to reference"; 344, parenthesized_expression; 344, 345; 345, identifier:result; 346, else_clause; 346, 347; 347, block; 347, 348; 348, expression_statement; 348, 349; 349, call; 349, 350; 349, 358; 350, attribute; 350, 351; 350, 357; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:logging; 354, identifier:getLogger; 355, argument_list; 355, 356; 356, string:"Cover"; 357, identifier:debug; 358, argument_list; 358, 359; 359, binary_operator:%; 359, 360; 359, 361; 360, string:"%s is NOT similar to reference"; 361, parenthesized_expression; 361, 362; 362, identifier:result; 363, else_clause; 363, 364; 364, block; 364, 365; 365, expression_statement; 365, 366; 366, call; 366, 367; 366, 375; 367, attribute; 367, 368; 367, 374; 368, call; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:logging; 371, identifier:getLogger; 372, argument_list; 372, 373; 373, string:"Cover"; 374, identifier:warning; 375, argument_list; 375, 376; 376, string:"No reference result found"; 377, return_statement; 377, 378; 378, identifier:results | async def preProcessForComparison(results, target_size, size_tolerance_prct):
reference = None
for result in results:
if result.source_quality is CoverSourceQuality.REFERENCE:
if ((reference is None) or
(CoverSourceResult.compare(result,
reference,
target_size=target_size,
size_tolerance_prct=size_tolerance_prct) > 0)):
reference = result
results = list(itertools.filterfalse(operator.attrgetter("is_only_reference"), results))
no_dup_results = []
for result in results:
is_dup = False
for result_comp in results:
if ((result_comp is not result) and
(result_comp.urls == result.urls) and
(__class__.compare(result,
result_comp,
target_size=target_size,
size_tolerance_prct=size_tolerance_prct) < 0)):
is_dup = True
break
if not is_dup:
no_dup_results.append(result)
dup_count = len(results) - len(no_dup_results)
if dup_count > 0:
logging.getLogger("Cover").info("Removed %u duplicate results" % (dup_count))
results = no_dup_results
if reference is not None:
logging.getLogger("Cover").info("Reference is: %s" % (reference))
reference.is_similar_to_reference = True
futures = []
for result in results:
coroutine = result.updateSignature()
future = asyncio.ensure_future(coroutine)
futures.append(future)
if reference.is_only_reference:
assert(reference not in results)
coroutine = reference.updateSignature()
future = asyncio.ensure_future(coroutine)
futures.append(future)
if futures:
await asyncio.wait(futures)
for future in futures:
future.result()
for result in results:
if ((result is not reference) and
(result.thumbnail_sig is not None) and
(reference.thumbnail_sig is not None)):
result.is_similar_to_reference = __class__.areImageSigsSimilar(result.thumbnail_sig,
reference.thumbnail_sig)
if result.is_similar_to_reference:
logging.getLogger("Cover").debug("%s is similar to reference" % (result))
else:
logging.getLogger("Cover").debug("%s is NOT similar to reference" % (result))
else:
logging.getLogger("Cover").warning("No reference result found")
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:order; 7, string:"asc"; 8, block; 8, 9; 8, 15; 8, 56; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:__prepare; 14, argument_list; 15, if_statement; 15, 16; 15, 23; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_json_data; 22, identifier:list; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 28; 24, 40; 25, comparison_operator:==; 25, 26; 25, 27; 26, identifier:order; 27, string:"asc"; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_json_data; 34, call; 34, 35; 34, 36; 35, identifier:sorted; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_json_data; 40, else_clause; 40, 41; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_json_data; 47, call; 47, 48; 47, 49; 48, identifier:sorted; 49, argument_list; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:_json_data; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:reverse; 55, True; 56, return_statement; 56, 57; 57, identifier:self | def sort(self, order="asc"):
self.__prepare()
if isinstance(self._json_data, list):
if order == "asc":
self._json_data = sorted(self._json_data)
else:
self._json_data = sorted(self._json_data, reverse=True)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_by; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:property; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, string:"asc"; 9, block; 9, 10; 9, 16; 9, 79; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:__prepare; 15, argument_list; 16, if_statement; 16, 17; 16, 24; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_json_data; 23, identifier:list; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 29; 25, 52; 26, comparison_operator:==; 26, 27; 26, 28; 27, identifier:order; 28, string:"asc"; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_json_data; 35, call; 35, 36; 35, 37; 36, identifier:sorted; 37, argument_list; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_json_data; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:key; 43, lambda; 43, 44; 43, 46; 44, lambda_parameters; 44, 45; 45, identifier:x; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:x; 49, identifier:get; 50, argument_list; 50, 51; 51, identifier:property; 52, else_clause; 52, 53; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_json_data; 59, call; 59, 60; 59, 61; 60, identifier:sorted; 61, argument_list; 61, 62; 61, 65; 61, 76; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_json_data; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:key; 67, lambda; 67, 68; 67, 70; 68, lambda_parameters; 68, 69; 69, identifier:x; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:x; 73, identifier:get; 74, argument_list; 74, 75; 75, identifier:property; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:reverse; 78, True; 79, return_statement; 79, 80; 80, identifier:self | def sort_by(self, property, order="asc"):
self.__prepare()
if isinstance(self._json_data, list):
if order == "asc":
self._json_data = sorted(
self._json_data,
key=lambda x: x.get(property)
)
else:
self._json_data = sorted(
self._json_data,
key=lambda x: x.get(property),
reverse=True
)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:dic; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:seps; 8, identifier:PATH_SEPS; 9, default_parameter; 9, 10; 9, 11; 10, identifier:idx_reg; 11, identifier:_JSNP_GET_ARRAY_IDX_REG; 12, block; 12, 13; 12, 28; 12, 36; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:items; 16, list_comprehension; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:_jsnp_unescape; 19, argument_list; 19, 20; 20, identifier:p; 21, for_in_clause; 21, 22; 21, 23; 22, identifier:p; 23, call; 23, 24; 23, 25; 24, identifier:_split_path; 25, argument_list; 25, 26; 25, 27; 26, identifier:path; 27, identifier:seps; 28, if_statement; 28, 29; 28, 31; 29, not_operator; 29, 30; 30, identifier:items; 31, block; 31, 32; 32, return_statement; 32, 33; 33, tuple; 33, 34; 33, 35; 34, identifier:dic; 35, string:''; 36, try_statement; 36, 37; 36, 115; 37, block; 37, 38; 37, 54; 37, 72; 37, 93; 38, if_statement; 38, 39; 38, 45; 39, comparison_operator:==; 39, 40; 39, 44; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:items; 44, integer:1; 45, block; 45, 46; 46, return_statement; 46, 47; 47, tuple; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 50; 49, identifier:dic; 50, subscript; 50, 51; 50, 52; 51, identifier:items; 52, integer:0; 53, string:''; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:prnt; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:functools; 60, identifier:reduce; 61, argument_list; 61, 62; 61, 65; 61, 71; 62, attribute; 62, 63; 62, 64; 63, identifier:operator; 64, identifier:getitem; 65, subscript; 65, 66; 65, 67; 66, identifier:items; 67, slice; 67, 68; 67, 69; 68, colon; 69, unary_operator:-; 69, 70; 70, integer:1; 71, identifier:dic; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:arr; 75, boolean_operator:and; 75, 76; 75, 84; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:anyconfig; 80, identifier:utils; 81, identifier:is_list_like; 82, argument_list; 82, 83; 83, identifier:prnt; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:idx_reg; 87, identifier:match; 88, argument_list; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:items; 91, unary_operator:-; 91, 92; 92, integer:1; 93, return_statement; 93, 94; 94, conditional_expression:if; 94, 95; 94, 106; 94, 107; 95, tuple; 95, 96; 95, 105; 96, subscript; 96, 97; 96, 98; 97, identifier:prnt; 98, call; 98, 99; 98, 100; 99, identifier:int; 100, argument_list; 100, 101; 101, subscript; 101, 102; 101, 103; 102, identifier:items; 103, unary_operator:-; 103, 104; 104, integer:1; 105, string:''; 106, identifier:arr; 107, tuple; 107, 108; 107, 114; 108, subscript; 108, 109; 108, 110; 109, identifier:prnt; 110, subscript; 110, 111; 110, 112; 111, identifier:items; 112, unary_operator:-; 112, 113; 113, integer:1; 114, string:''; 115, except_clause; 115, 116; 115, 123; 116, as_pattern; 116, 117; 116, 121; 117, tuple; 117, 118; 117, 119; 117, 120; 118, identifier:TypeError; 119, identifier:KeyError; 120, identifier:IndexError; 121, as_pattern_target; 121, 122; 122, identifier:exc; 123, block; 123, 124; 124, return_statement; 124, 125; 125, tuple; 125, 126; 125, 127; 126, None; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:exc | def get(dic, path, seps=PATH_SEPS, idx_reg=_JSNP_GET_ARRAY_IDX_REG):
items = [_jsnp_unescape(p) for p in _split_path(path, seps)]
if not items:
return (dic, '')
try:
if len(items) == 1:
return (dic[items[0]], '')
prnt = functools.reduce(operator.getitem, items[:-1], dic)
arr = anyconfig.utils.is_list_like(prnt) and idx_reg.match(items[-1])
return (prnt[int(items[-1])], '') if arr else (prnt[items[-1]], '')
except (TypeError, KeyError, IndexError) as exc:
return (None, str(exc)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:groupby; 3, parameters; 3, 4; 3, 5; 4, identifier:itr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_fn; 7, None; 8, block; 8, 9; 9, return_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:itertools; 13, identifier:groupby; 14, argument_list; 14, 15; 14, 22; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 19; 18, identifier:itr; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:key; 21, identifier:key_fn; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:key; 24, identifier:key_fn | def groupby(itr, key_fn=None):
return itertools.groupby(sorted(itr, key=key_fn), key=key_fn) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:open; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:mode; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ac_parser; 10, None; 11, dictionary_splat_pattern; 11, 12; 12, identifier:options; 13, block; 13, 14; 13, 24; 13, 45; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:psr; 17, call; 17, 18; 17, 19; 18, identifier:find; 19, argument_list; 19, 20; 19, 21; 20, identifier:path; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:forced_type; 23, identifier:ac_parser; 24, if_statement; 24, 25; 24, 35; 25, boolean_operator:and; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:mode; 28, None; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:mode; 32, identifier:startswith; 33, argument_list; 33, 34; 34, string:'w'; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:psr; 40, identifier:wopen; 41, argument_list; 41, 42; 41, 43; 42, identifier:path; 43, dictionary_splat; 43, 44; 44, identifier:options; 45, return_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:psr; 49, identifier:ropen; 50, argument_list; 50, 51; 50, 52; 51, identifier:path; 52, dictionary_splat; 52, 53; 53, identifier:options | def open(path, mode=None, ac_parser=None, **options):
psr = find(path, forced_type=ac_parser)
if mode is not None and mode.startswith('w'):
return psr.wopen(path, **options)
return psr.ropen(path, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:single_load; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:input_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ac_parser; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ac_template; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ac_context; 13, None; 14, dictionary_splat_pattern; 14, 15; 15, identifier:options; 16, block; 16, 17; 16, 19; 16, 37; 16, 51; 16, 61; 17, expression_statement; 17, 18; 18, identifier:r; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:cnf; 22, call; 22, 23; 22, 24; 23, identifier:_single_load; 24, argument_list; 24, 25; 24, 26; 24, 29; 24, 32; 24, 35; 25, identifier:input_; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:ac_parser; 28, identifier:ac_parser; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:ac_template; 31, identifier:ac_template; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:ac_context; 34, identifier:ac_context; 35, dictionary_splat; 35, 36; 36, identifier:options; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:schema; 40, call; 40, 41; 40, 42; 41, identifier:_maybe_schema; 42, argument_list; 42, 43; 42, 46; 42, 49; 43, keyword_argument; 43, 44; 43, 45; 44, identifier:ac_template; 45, identifier:ac_template; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:ac_context; 48, identifier:ac_context; 49, dictionary_splat; 49, 50; 50, identifier:options; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:cnf; 54, call; 54, 55; 54, 56; 55, identifier:_try_validate; 56, argument_list; 56, 57; 56, 58; 56, 59; 57, identifier:cnf; 58, identifier:schema; 59, dictionary_splat; 59, 60; 60, identifier:options; 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:anyconfig; 66, identifier:query; 67, identifier:query; 68, argument_list; 68, 69; 68, 70; 69, identifier:cnf; 70, dictionary_splat; 70, 71; 71, identifier:options | def single_load(input_, ac_parser=None, ac_template=False,
ac_context=None, **options):
r
cnf = _single_load(input_, ac_parser=ac_parser, ac_template=ac_template,
ac_context=ac_context, **options)
schema = _maybe_schema(ac_template=ac_template, ac_context=ac_context,
**options)
cnf = _try_validate(cnf, schema, **options)
return anyconfig.query.query(cnf, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:multi_load; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:inputs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ac_parser; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ac_template; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ac_context; 13, None; 14, dictionary_splat_pattern; 14, 15; 15, identifier:options; 16, block; 16, 17; 16, 19; 16, 35; 16, 49; 16, 55; 16, 69; 16, 91; 16, 95; 16, 147; 16, 163; 16, 173; 17, expression_statement; 17, 18; 18, identifier:r; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:marker; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:options; 25, identifier:setdefault; 26, argument_list; 26, 27; 26, 28; 27, string:"ac_marker"; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:options; 31, identifier:get; 32, argument_list; 32, 33; 32, 34; 33, string:"marker"; 34, string:'*'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:schema; 38, call; 38, 39; 38, 40; 39, identifier:_maybe_schema; 40, argument_list; 40, 41; 40, 44; 40, 47; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:ac_template; 43, identifier:ac_template; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:ac_context; 46, identifier:ac_context; 47, dictionary_splat; 47, 48; 48, identifier:options; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:options; 53, string:"ac_schema"; 54, None; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:paths; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:anyconfig; 62, identifier:utils; 63, identifier:expand_paths; 64, argument_list; 64, 65; 64, 66; 65, identifier:inputs; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:marker; 68, identifier:marker; 69, if_statement; 69, 70; 69, 78; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:anyconfig; 74, identifier:utils; 75, identifier:are_same_file_types; 76, argument_list; 76, 77; 77, identifier:paths; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:ac_parser; 82, call; 82, 83; 82, 84; 83, identifier:find; 84, argument_list; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:paths; 87, integer:0; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:forced_type; 90, identifier:ac_parser; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:cnf; 94, identifier:ac_context; 95, for_statement; 95, 96; 95, 97; 95, 98; 96, identifier:path; 97, identifier:paths; 98, block; 98, 99; 98, 107; 98, 125; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:opts; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:options; 105, identifier:copy; 106, argument_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:cups; 110, call; 110, 111; 110, 112; 111, identifier:_single_load; 112, argument_list; 112, 113; 112, 114; 112, 117; 112, 120; 112, 123; 113, identifier:path; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:ac_parser; 116, identifier:ac_parser; 117, keyword_argument; 117, 118; 117, 119; 118, identifier:ac_template; 119, identifier:ac_template; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:ac_context; 122, identifier:cnf; 123, dictionary_splat; 123, 124; 124, identifier:opts; 125, if_statement; 125, 126; 125, 127; 126, identifier:cups; 127, block; 127, 128; 128, if_statement; 128, 129; 128, 132; 128, 137; 129, comparison_operator:is; 129, 130; 129, 131; 130, identifier:cnf; 131, None; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:cnf; 136, identifier:cups; 137, else_clause; 137, 138; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:merge; 142, argument_list; 142, 143; 142, 144; 142, 145; 143, identifier:cnf; 144, identifier:cups; 145, dictionary_splat; 145, 146; 146, identifier:options; 147, if_statement; 147, 148; 147, 151; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:cnf; 150, None; 151, block; 151, 152; 152, return_statement; 152, 153; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:anyconfig; 157, identifier:dicts; 158, identifier:convert_to; 159, argument_list; 159, 160; 159, 161; 160, dictionary; 161, dictionary_splat; 161, 162; 162, identifier:options; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:cnf; 166, call; 166, 167; 166, 168; 167, identifier:_try_validate; 168, argument_list; 168, 169; 168, 170; 168, 171; 169, identifier:cnf; 170, identifier:schema; 171, dictionary_splat; 171, 172; 172, identifier:options; 173, return_statement; 173, 174; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:anyconfig; 178, identifier:query; 179, identifier:query; 180, argument_list; 180, 181; 180, 182; 181, identifier:cnf; 182, dictionary_splat; 182, 183; 183, identifier:options | def multi_load(inputs, ac_parser=None, ac_template=False, ac_context=None,
**options):
r
marker = options.setdefault("ac_marker", options.get("marker", '*'))
schema = _maybe_schema(ac_template=ac_template, ac_context=ac_context,
**options)
options["ac_schema"] = None
paths = anyconfig.utils.expand_paths(inputs, marker=marker)
if anyconfig.utils.are_same_file_types(paths):
ac_parser = find(paths[0], forced_type=ac_parser)
cnf = ac_context
for path in paths:
opts = options.copy()
cups = _single_load(path, ac_parser=ac_parser,
ac_template=ac_template, ac_context=cnf, **opts)
if cups:
if cnf is None:
cnf = cups
else:
merge(cnf, cups, **options)
if cnf is None:
return anyconfig.dicts.convert_to({}, **options)
cnf = _try_validate(cnf, schema, **options)
return anyconfig.query.query(cnf, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:load; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:path_specs; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ac_parser; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:ac_dict; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:ac_template; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:ac_context; 16, None; 17, dictionary_splat_pattern; 17, 18; 18, identifier:options; 19, block; 19, 20; 19, 22; 19, 38; 19, 68; 19, 87; 20, expression_statement; 20, 21; 21, identifier:r; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:marker; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:options; 28, identifier:setdefault; 29, argument_list; 29, 30; 29, 31; 30, string:"ac_marker"; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:options; 34, identifier:get; 35, argument_list; 35, 36; 35, 37; 36, string:"marker"; 37, string:'*'; 38, if_statement; 38, 39; 38, 48; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:anyconfig; 43, identifier:utils; 44, identifier:is_path_like_object; 45, argument_list; 45, 46; 45, 47; 46, identifier:path_specs; 47, identifier:marker; 48, block; 48, 49; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:single_load; 52, argument_list; 52, 53; 52, 54; 52, 57; 52, 60; 52, 63; 52, 66; 53, identifier:path_specs; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:ac_parser; 56, identifier:ac_parser; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:ac_dict; 59, identifier:ac_dict; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:ac_template; 62, identifier:ac_template; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:ac_context; 65, identifier:ac_context; 66, dictionary_splat; 66, 67; 67, identifier:options; 68, if_statement; 68, 69; 68, 79; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:anyconfig; 74, identifier:utils; 75, identifier:is_paths; 76, argument_list; 76, 77; 76, 78; 77, identifier:path_specs; 78, identifier:marker; 79, block; 79, 80; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:ValueError; 83, argument_list; 83, 84; 84, binary_operator:%; 84, 85; 84, 86; 85, string:"Possible invalid input %r"; 86, identifier:path_specs; 87, return_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:multi_load; 90, argument_list; 90, 91; 90, 92; 90, 95; 90, 98; 90, 101; 90, 104; 91, identifier:path_specs; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:ac_parser; 94, identifier:ac_parser; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:ac_dict; 97, identifier:ac_dict; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:ac_template; 100, identifier:ac_template; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:ac_context; 103, identifier:ac_context; 104, dictionary_splat; 104, 105; 105, identifier:options | def load(path_specs, ac_parser=None, ac_dict=None, ac_template=False,
ac_context=None, **options):
r
marker = options.setdefault("ac_marker", options.get("marker", '*'))
if anyconfig.utils.is_path_like_object(path_specs, marker):
return single_load(path_specs, ac_parser=ac_parser, ac_dict=ac_dict,
ac_template=ac_template, ac_context=ac_context,
**options)
if not anyconfig.utils.is_paths(path_specs, marker):
raise ValueError("Possible invalid input %r" % path_specs)
return multi_load(path_specs, ac_parser=ac_parser, ac_dict=ac_dict,
ac_template=ac_template, ac_context=ac_context,
**options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:dump; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:data; 5, identifier:out; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ac_parser; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:options; 11, block; 11, 12; 11, 23; 11, 33; 11, 43; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ioi; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:anyconfig; 19, identifier:ioinfo; 20, identifier:make; 21, argument_list; 21, 22; 22, identifier:out; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:psr; 26, call; 26, 27; 26, 28; 27, identifier:find; 28, argument_list; 28, 29; 28, 30; 29, identifier:ioi; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:forced_type; 32, identifier:ac_parser; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:LOGGER; 37, identifier:info; 38, argument_list; 38, 39; 38, 40; 39, string:"Dumping: %s"; 40, attribute; 40, 41; 40, 42; 41, identifier:ioi; 42, identifier:path; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:psr; 47, identifier:dump; 48, argument_list; 48, 49; 48, 50; 48, 51; 49, identifier:data; 50, identifier:ioi; 51, dictionary_splat; 51, 52; 52, identifier:options | def dump(data, out, ac_parser=None, **options):
ioi = anyconfig.ioinfo.make(out)
psr = find(ioi, forced_type=ac_parser)
LOGGER.info("Dumping: %s", ioi.path)
psr.dump(data, ioi, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:dumps; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ac_parser; 7, None; 8, dictionary_splat_pattern; 8, 9; 9, identifier:options; 10, block; 10, 11; 10, 21; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:psr; 14, call; 14, 15; 14, 16; 15, identifier:find; 16, argument_list; 16, 17; 16, 18; 17, None; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:forced_type; 20, identifier:ac_parser; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:psr; 25, identifier:dumps; 26, argument_list; 26, 27; 26, 28; 27, identifier:data; 28, dictionary_splat; 28, 29; 29, identifier:options | def dumps(data, ac_parser=None, **options):
psr = find(None, forced_type=ac_parser)
return psr.dumps(data, **options) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 1, 16; 2, function_name:sort_response; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:response; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Dict; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13; 13, identifier:Any; 14, type; 14, 15; 15, identifier:OrderedDict; 16, block; 16, 17; 16, 25; 16, 32; 16, 59; 16, 95; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:root_order; 20, list:["jsonrpc", "result", "error", "id"]; 20, 21; 20, 22; 20, 23; 20, 24; 21, string:"jsonrpc"; 22, string:"result"; 23, string:"error"; 24, string:"id"; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:error_order; 28, list:["code", "message", "data"]; 28, 29; 28, 30; 28, 31; 29, string:"code"; 30, string:"message"; 31, string:"data"; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:req; 35, call; 35, 36; 35, 37; 36, identifier:OrderedDict; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:sorted; 40, argument_list; 40, 41; 40, 46; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:response; 44, identifier:items; 45, argument_list; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:key; 48, lambda; 48, 49; 48, 51; 49, lambda_parameters; 49, 50; 50, identifier:k; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:root_order; 54, identifier:index; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:k; 58, integer:0; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:in; 60, 61; 60, 62; 61, string:"error"; 62, identifier:response; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:req; 68, string:"error"; 69, call; 69, 70; 69, 71; 70, identifier:OrderedDict; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:sorted; 74, argument_list; 74, 75; 74, 82; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:response; 79, string:"error"; 80, identifier:items; 81, argument_list; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:key; 84, lambda; 84, 85; 84, 87; 85, lambda_parameters; 85, 86; 86, identifier:k; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:error_order; 90, identifier:index; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, identifier:k; 94, integer:0; 95, return_statement; 95, 96; 96, identifier:req | def sort_response(response: Dict[str, Any]) -> OrderedDict:
root_order = ["jsonrpc", "result", "error", "id"]
error_order = ["code", "message", "data"]
req = OrderedDict(sorted(response.items(), key=lambda k: root_order.index(k[0])))
if "error" in response:
req["error"] = OrderedDict(
sorted(response["error"].items(), key=lambda k: error_order.index(k[0]))
)
return req |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 1, 16; 2, function_name:sort_request; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:request; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Dict; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13; 13, identifier:Any; 14, type; 14, 15; 15, identifier:OrderedDict; 16, block; 16, 17; 16, 25; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:sort_order; 20, list:["jsonrpc", "method", "params", "id"]; 20, 21; 20, 22; 20, 23; 20, 24; 21, string:"jsonrpc"; 22, string:"method"; 23, string:"params"; 24, string:"id"; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:OrderedDict; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:sorted; 31, argument_list; 31, 32; 31, 37; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:request; 35, identifier:items; 36, argument_list; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:k; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:sort_order; 45, identifier:index; 46, argument_list; 46, 47; 47, subscript; 47, 48; 47, 49; 48, identifier:k; 49, integer:0 | def sort_request(request: Dict[str, Any]) -> OrderedDict:
sort_order = ["jsonrpc", "method", "params", "id"]
return OrderedDict(sorted(request.items(), key=lambda k: sort_order.index(k[0]))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:dump; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:obj; 5, identifier:fp; 6, default_parameter; 6, 7; 6, 8; 7, identifier:container_count; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort_keys; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:no_float32; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:default; 17, None; 18, block; 18, 19; 18, 33; 18, 39; 19, if_statement; 19, 20; 19, 27; 20, not_operator; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:callable; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:fp; 26, identifier:write; 27, block; 27, 28; 28, raise_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:TypeError; 31, argument_list; 31, 32; 32, string:'fp.write not callable'; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:fp_write; 36, attribute; 36, 37; 36, 38; 37, identifier:fp; 38, identifier:write; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:__encode_value; 42, argument_list; 42, 43; 42, 44; 42, 45; 42, 46; 42, 47; 42, 48; 42, 49; 43, identifier:fp_write; 44, identifier:obj; 45, dictionary; 46, identifier:container_count; 47, identifier:sort_keys; 48, identifier:no_float32; 49, identifier:default | def dump(obj, fp, container_count=False, sort_keys=False, no_float32=True, default=None):
if not callable(fp.write):
raise TypeError('fp.write not callable')
fp_write = fp.write
__encode_value(fp_write, obj, {}, container_count, sort_keys, no_float32, default) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:torrents; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:filters; 7, block; 7, 8; 7, 12; 7, 37; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:params; 11, dictionary; 12, for_statement; 12, 13; 12, 16; 12, 21; 13, pattern_list; 13, 14; 13, 15; 14, identifier:name; 15, identifier:value; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:filters; 19, identifier:items; 20, argument_list; 21, block; 21, 22; 21, 31; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:name; 25, conditional_expression:if; 25, 26; 25, 27; 25, 30; 26, string:'filter'; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:name; 29, string:'status'; 30, identifier:name; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:params; 35, identifier:name; 36, identifier:value; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_get; 42, argument_list; 42, 43; 42, 44; 43, string:'query/torrents'; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:params; 46, identifier:params | def torrents(self, **filters):
params = {}
for name, value in filters.items():
name = 'filter' if name == 'status' else name
params[name] = value
return self._get('query/torrents', params=params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_global_color_table; 3, parameters; 3, 4; 4, identifier:colors; 5, block; 5, 6; 5, 24; 5, 43; 5, 55; 5, 69; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:global_color_table; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, string:b''; 12, identifier:join; 13, generator_expression; 13, 14; 13, 17; 14, subscript; 14, 15; 14, 16; 15, identifier:c; 16, integer:0; 17, for_in_clause; 17, 18; 17, 19; 18, identifier:c; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:colors; 22, identifier:most_common; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:full_table_size; 27, binary_operator:**; 27, 28; 27, 29; 28, integer:2; 29, parenthesized_expression; 29, 30; 30, binary_operator:+; 30, 31; 30, 32; 31, integer:1; 32, call; 32, 33; 32, 34; 33, identifier:int; 34, argument_list; 34, 35; 34, 42; 35, call; 35, 36; 35, 37; 36, identifier:get_color_table_size; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, identifier:colors; 42, integer:2; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:repeats; 46, binary_operator:*; 46, 47; 46, 48; 47, integer:3; 48, parenthesized_expression; 48, 49; 49, binary_operator:-; 49, 50; 49, 51; 50, identifier:full_table_size; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:colors; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:zeros; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:struct; 61, identifier:pack; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, string:'<{}x'; 66, identifier:format; 67, argument_list; 67, 68; 68, identifier:repeats; 69, return_statement; 69, 70; 70, binary_operator:+; 70, 71; 70, 72; 71, identifier:global_color_table; 72, identifier:zeros | def _get_global_color_table(colors):
global_color_table = b''.join(c[0] for c in colors.most_common())
full_table_size = 2**(1+int(get_color_table_size(len(colors)), 2))
repeats = 3 * (full_table_size - len(colors))
zeros = struct.pack('<{}x'.format(repeats))
return global_color_table + zeros |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:good_sequences_to_track; 3, parameters; 3, 4; 3, 5; 4, identifier:flow; 5, default_parameter; 5, 6; 5, 7; 6, identifier:motion_threshold; 7, float:1.0; 8, block; 8, 9; 8, 13; 8, 17; 8, 64; 8, 95; 8, 135; 8, 166; 8, 170; 8, 174; 8, 295; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:endpoints; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:in_low; 16, False; 17, for_statement; 17, 18; 17, 21; 17, 25; 18, pattern_list; 18, 19; 18, 20; 19, identifier:i; 20, identifier:val; 21, call; 21, 22; 21, 23; 22, identifier:enumerate; 23, argument_list; 23, 24; 24, identifier:flow; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 30; 26, 46; 27, comparison_operator:<; 27, 28; 27, 29; 28, identifier:val; 29, identifier:motion_threshold; 30, block; 30, 31; 31, if_statement; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:in_low; 34, block; 34, 35; 34, 42; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:endpoints; 39, identifier:append; 40, argument_list; 40, 41; 41, identifier:i; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:in_low; 45, True; 46, else_clause; 46, 47; 47, block; 47, 48; 47, 60; 48, if_statement; 48, 49; 48, 50; 49, identifier:in_low; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:endpoints; 55, identifier:append; 56, argument_list; 56, 57; 57, binary_operator:-; 57, 58; 57, 59; 58, identifier:i; 59, integer:1; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:in_low; 63, False; 64, function_definition; 64, 65; 64, 66; 64, 68; 65, function_name:mean_score_func; 66, parameters; 66, 67; 67, identifier:m; 68, block; 68, 69; 68, 73; 68, 77; 68, 86; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:mu; 72, integer:15; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:sigma; 76, integer:8; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:top_val; 80, call; 80, 81; 80, 82; 81, identifier:normpdf; 82, argument_list; 82, 83; 82, 84; 82, 85; 83, identifier:mu; 84, identifier:mu; 85, identifier:sigma; 86, return_statement; 86, 87; 87, binary_operator:/; 87, 88; 87, 94; 88, call; 88, 89; 88, 90; 89, identifier:normpdf; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:m; 92, identifier:mu; 93, identifier:sigma; 94, identifier:top_val; 95, function_definition; 95, 96; 95, 97; 95, 99; 96, function_name:max_score_func; 97, parameters; 97, 98; 98, identifier:m; 99, block; 99, 100; 99, 104; 99, 108; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:mu; 103, integer:40; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:sigma; 107, integer:8; 108, if_statement; 108, 109; 108, 112; 108, 115; 109, comparison_operator:<=; 109, 110; 109, 111; 110, identifier:m; 111, identifier:mu; 112, block; 112, 113; 113, return_statement; 113, 114; 114, float:1.; 115, else_clause; 115, 116; 116, block; 116, 117; 116, 126; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:top_val; 120, call; 120, 121; 120, 122; 121, identifier:normpdf; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:mu; 124, identifier:mu; 125, identifier:sigma; 126, return_statement; 126, 127; 127, binary_operator:/; 127, 128; 127, 134; 128, call; 128, 129; 128, 130; 129, identifier:normpdf; 130, argument_list; 130, 131; 130, 132; 130, 133; 131, identifier:m; 132, identifier:mu; 133, identifier:sigma; 134, identifier:top_val; 135, function_definition; 135, 136; 135, 137; 135, 139; 136, function_name:length_score_func; 137, parameters; 137, 138; 138, identifier:l; 139, block; 139, 140; 139, 144; 139, 148; 139, 157; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:mu; 143, integer:30; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:sigma; 147, integer:10; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:top_val; 151, call; 151, 152; 151, 153; 152, identifier:normpdf; 153, argument_list; 153, 154; 153, 155; 153, 156; 154, identifier:mu; 155, identifier:mu; 156, identifier:sigma; 157, return_statement; 157, 158; 158, binary_operator:/; 158, 159; 158, 165; 159, call; 159, 160; 159, 161; 160, identifier:normpdf; 161, argument_list; 161, 162; 161, 163; 161, 164; 162, identifier:l; 163, identifier:mu; 164, identifier:sigma; 165, identifier:top_val; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:min_length; 169, integer:5; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:sequences; 173, list:[]; 174, for_statement; 174, 175; 174, 178; 174, 187; 175, pattern_list; 175, 176; 175, 177; 176, identifier:k; 177, identifier:i; 178, call; 178, 179; 178, 180; 179, identifier:enumerate; 180, argument_list; 180, 181; 181, subscript; 181, 182; 181, 183; 182, identifier:endpoints; 183, slice; 183, 184; 183, 185; 184, colon; 185, unary_operator:-; 185, 186; 186, integer:1; 187, block; 187, 188; 188, for_statement; 188, 189; 188, 190; 188, 197; 189, identifier:j; 190, subscript; 190, 191; 190, 192; 191, identifier:endpoints; 192, slice; 192, 193; 192, 196; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:k; 195, integer:1; 196, colon; 197, block; 197, 198; 197, 204; 197, 210; 197, 221; 197, 233; 197, 245; 197, 252; 197, 266; 197, 277; 197, 285; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:length; 201, binary_operator:-; 201, 202; 201, 203; 202, identifier:j; 203, identifier:i; 204, if_statement; 204, 205; 204, 208; 205, comparison_operator:<; 205, 206; 205, 207; 206, identifier:length; 207, identifier:min_length; 208, block; 208, 209; 209, continue_statement; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:seq; 213, subscript; 213, 214; 213, 215; 214, identifier:flow; 215, slice; 215, 216; 215, 217; 215, 218; 216, identifier:i; 217, colon; 218, binary_operator:+; 218, 219; 218, 220; 219, identifier:j; 220, integer:1; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:m_score; 224, call; 224, 225; 224, 226; 225, identifier:mean_score_func; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:np; 230, identifier:mean; 231, argument_list; 231, 232; 232, identifier:seq; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:mx_score; 236, call; 236, 237; 236, 238; 237, identifier:max_score_func; 238, argument_list; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:np; 242, identifier:max; 243, argument_list; 243, 244; 244, identifier:seq; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:l_score; 248, call; 248, 249; 248, 250; 249, identifier:length_score_func; 250, argument_list; 250, 251; 251, identifier:length; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:logger; 256, identifier:debug; 257, argument_list; 257, 258; 258, binary_operator:%; 258, 259; 258, 260; 259, string:"%d, %d scores: (mean=%.5f, max=%.5f, length=%.5f)"; 260, tuple; 260, 261; 260, 262; 260, 263; 260, 264; 260, 265; 261, identifier:i; 262, identifier:j; 263, identifier:m_score; 264, identifier:mx_score; 265, identifier:l_score; 266, if_statement; 266, 267; 266, 275; 267, comparison_operator:<; 267, 268; 267, 274; 268, call; 268, 269; 268, 270; 269, identifier:min; 270, argument_list; 270, 271; 270, 272; 270, 273; 271, identifier:m_score; 272, identifier:mx_score; 273, identifier:l_score; 274, float:0.2; 275, block; 275, 276; 276, continue_statement; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:score; 280, binary_operator:+; 280, 281; 280, 284; 281, binary_operator:+; 281, 282; 281, 283; 282, identifier:m_score; 283, identifier:mx_score; 284, identifier:l_score; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:sequences; 289, identifier:append; 290, argument_list; 290, 291; 291, tuple; 291, 292; 291, 293; 291, 294; 292, identifier:i; 293, identifier:j; 294, identifier:score; 295, return_statement; 295, 296; 296, call; 296, 297; 296, 298; 297, identifier:sorted; 298, argument_list; 298, 299; 298, 300; 298, 308; 299, identifier:sequences; 300, keyword_argument; 300, 301; 300, 302; 301, identifier:key; 302, lambda; 302, 303; 302, 305; 303, lambda_parameters; 303, 304; 304, identifier:x; 305, subscript; 305, 306; 305, 307; 306, identifier:x; 307, integer:2; 308, keyword_argument; 308, 309; 308, 310; 309, identifier:reverse; 310, True | def good_sequences_to_track(flow, motion_threshold=1.0):
endpoints = []
in_low = False
for i, val in enumerate(flow):
if val < motion_threshold:
if not in_low:
endpoints.append(i)
in_low = True
else:
if in_low:
endpoints.append(i-1)
in_low = False
def mean_score_func(m):
mu = 15
sigma = 8
top_val = normpdf(mu, mu, sigma)
return normpdf(m, mu, sigma) / top_val
def max_score_func(m):
mu = 40
sigma = 8
if m <= mu:
return 1.
else:
top_val = normpdf(mu, mu, sigma)
return normpdf(m, mu, sigma) / top_val
def length_score_func(l):
mu = 30
sigma = 10
top_val = normpdf(mu, mu, sigma)
return normpdf(l, mu, sigma) / top_val
min_length = 5
sequences = []
for k, i in enumerate(endpoints[:-1]):
for j in endpoints[k+1:]:
length = j - i
if length < min_length:
continue
seq = flow[i:j+1]
m_score = mean_score_func(np.mean(seq))
mx_score = max_score_func(np.max(seq))
l_score = length_score_func(length)
logger.debug("%d, %d scores: (mean=%.5f, max=%.5f, length=%.5f)" % (i,j,m_score, mx_score, l_score))
if min(m_score, mx_score, l_score) < 0.2:
continue
score = m_score + mx_score + l_score
sequences.append((i, j, score))
return sorted(sequences, key=lambda x: x[2], reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_generate_comparator; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:field_names; 6, block; 6, 7; 6, 14; 6, 24; 6, 57; 6, 71; 6, 153; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:field_names; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, identifier:field_names; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:reverses; 17, binary_operator:*; 17, 18; 17, 20; 18, list:[1]; 18, 19; 19, integer:1; 20, call; 20, 21; 20, 22; 21, identifier:len; 22, argument_list; 22, 23; 23, identifier:field_names; 24, for_statement; 24, 25; 24, 28; 24, 32; 25, pattern_list; 25, 26; 25, 27; 26, identifier:i; 27, identifier:field_name; 28, call; 28, 29; 28, 30; 29, identifier:enumerate; 30, argument_list; 30, 31; 31, identifier:field_names; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 39; 34, comparison_operator:==; 34, 35; 34, 38; 35, subscript; 35, 36; 35, 37; 36, identifier:field_name; 37, integer:0; 38, string:'-'; 39, block; 39, 40; 39, 47; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:reverses; 44, identifier:i; 45, unary_operator:-; 45, 46; 46, integer:1; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:field_names; 51, identifier:i; 52, subscript; 52, 53; 52, 54; 53, identifier:field_name; 54, slice; 54, 55; 54, 56; 55, integer:1; 56, colon; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:field_names; 60, list_comprehension; 60, 61; 60, 68; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:f; 64, identifier:replace; 65, argument_list; 65, 66; 65, 67; 66, identifier:LOOKUP_SEP; 67, string:'.'; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:f; 70, identifier:field_names; 71, function_definition; 71, 72; 71, 73; 71, 76; 72, function_name:comparator; 73, parameters; 73, 74; 73, 75; 74, identifier:i1; 75, identifier:i2; 76, block; 76, 77; 76, 88; 76, 99; 76, 119; 76, 137; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:v1; 80, call; 80, 81; 80, 86; 81, call; 81, 82; 81, 83; 82, identifier:attrgetter; 83, argument_list; 83, 84; 84, list_splat; 84, 85; 85, identifier:field_names; 86, argument_list; 86, 87; 87, identifier:i1; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:v2; 91, call; 91, 92; 91, 97; 92, call; 92, 93; 92, 94; 93, identifier:attrgetter; 94, argument_list; 94, 95; 95, list_splat; 95, 96; 96, identifier:field_names; 97, argument_list; 97, 98; 98, identifier:i2; 99, if_statement; 99, 100; 99, 106; 100, comparison_operator:==; 100, 101; 100, 105; 101, call; 101, 102; 101, 103; 102, identifier:len; 103, argument_list; 103, 104; 104, identifier:field_names; 105, integer:1; 106, block; 106, 107; 107, return_statement; 107, 108; 108, binary_operator:*; 108, 109; 108, 116; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:cls; 112, identifier:_cmp; 113, argument_list; 113, 114; 113, 115; 114, identifier:v1; 115, identifier:v2; 116, subscript; 116, 117; 116, 118; 117, identifier:reverses; 118, integer:0; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:order; 122, call; 122, 123; 122, 124; 123, identifier:multiply_iterables; 124, argument_list; 124, 125; 124, 136; 125, call; 125, 126; 125, 127; 126, identifier:list; 127, argument_list; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:map; 130, argument_list; 130, 131; 130, 134; 130, 135; 131, attribute; 131, 132; 131, 133; 132, identifier:cls; 133, identifier:_cmp; 134, identifier:v1; 135, identifier:v2; 136, identifier:reverses; 137, try_statement; 137, 138; 137, 148; 138, block; 138, 139; 139, return_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:next; 142, argument_list; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:dropwhile; 145, argument_list; 145, 146; 145, 147; 146, identifier:__not__; 147, identifier:order; 148, except_clause; 148, 149; 148, 150; 149, identifier:StopIteration; 150, block; 150, 151; 151, return_statement; 151, 152; 152, integer:0; 153, return_statement; 153, 154; 154, identifier:comparator | def _generate_comparator(cls, field_names):
field_names = list(field_names)
reverses = [1] * len(field_names)
for i, field_name in enumerate(field_names):
if field_name[0] == '-':
reverses[i] = -1
field_names[i] = field_name[1:]
field_names = [f.replace(LOOKUP_SEP, '.') for f in field_names]
def comparator(i1, i2):
v1 = attrgetter(*field_names)(i1)
v2 = attrgetter(*field_names)(i2)
if len(field_names) == 1:
return cls._cmp(v1, v2) * reverses[0]
order = multiply_iterables(list(map(cls._cmp, v1, v2)), reverses)
try:
return next(dropwhile(__not__, order))
except StopIteration:
return 0
return comparator |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_segment_points; 3, parameters; 3, 4; 3, 5; 4, identifier:Aps; 5, identifier:Bps; 6, block; 6, 7; 6, 11; 6, 15; 6, 24; 6, 148; 6, 168; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:mid; 10, list:[]; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:j; 14, integer:0; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:mid; 19, identifier:append; 20, argument_list; 20, 21; 21, subscript; 21, 22; 21, 23; 22, identifier:Aps; 23, integer:0; 24, for_statement; 24, 25; 24, 26; 24, 35; 25, identifier:i; 26, call; 26, 27; 26, 28; 27, identifier:range; 28, argument_list; 28, 29; 29, binary_operator:-; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:len; 32, argument_list; 32, 33; 33, identifier:Aps; 34, integer:1; 35, block; 35, 36; 35, 50; 35, 137; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:dist; 39, call; 39, 40; 39, 41; 40, identifier:distance_tt_point; 41, argument_list; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:Aps; 44, identifier:i; 45, subscript; 45, 46; 45, 47; 46, identifier:Aps; 47, binary_operator:+; 47, 48; 47, 49; 48, identifier:i; 49, integer:1; 50, for_statement; 50, 51; 50, 52; 50, 60; 51, identifier:m; 52, call; 52, 53; 52, 54; 53, identifier:range; 54, argument_list; 54, 55; 54, 56; 55, identifier:j; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, identifier:Bps; 60, block; 60, 61; 60, 73; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:distm; 64, call; 64, 65; 64, 66; 65, identifier:distance_tt_point; 66, argument_list; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:Aps; 69, identifier:i; 70, subscript; 70, 71; 70, 72; 71, identifier:Bps; 72, identifier:m; 73, if_statement; 73, 74; 73, 77; 74, comparison_operator:>; 74, 75; 74, 76; 75, identifier:dist; 76, identifier:distm; 77, block; 77, 78; 77, 116; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:direction; 81, call; 81, 82; 81, 83; 82, identifier:dot; 83, argument_list; 83, 84; 83, 106; 84, call; 84, 85; 84, 86; 85, identifier:normalize; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 89; 88, identifier:line; 89, argument_list; 89, 90; 89, 97; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:Aps; 94, identifier:i; 95, identifier:gen2arr; 96, argument_list; 97, call; 97, 98; 97, 105; 98, attribute; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 101; 100, identifier:Aps; 101, binary_operator:+; 101, 102; 101, 103; 102, identifier:i; 103, integer:1; 104, identifier:gen2arr; 105, argument_list; 106, call; 106, 107; 106, 108; 107, identifier:normalize; 108, argument_list; 108, 109; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:Bps; 113, identifier:m; 114, identifier:gen2arr; 115, argument_list; 116, if_statement; 116, 117; 116, 120; 117, comparison_operator:>; 117, 118; 117, 119; 118, identifier:direction; 119, integer:0; 120, block; 120, 121; 120, 127; 120, 136; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:j; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:m; 126, integer:1; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:mid; 131, identifier:append; 132, argument_list; 132, 133; 133, subscript; 133, 134; 133, 135; 134, identifier:Bps; 135, identifier:m; 136, break_statement; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:mid; 141, identifier:append; 142, argument_list; 142, 143; 143, subscript; 143, 144; 143, 145; 144, identifier:Aps; 145, binary_operator:+; 145, 146; 145, 147; 146, identifier:i; 147, integer:1; 148, for_statement; 148, 149; 148, 150; 148, 158; 149, identifier:m; 150, call; 150, 151; 150, 152; 151, identifier:range; 152, argument_list; 152, 153; 152, 154; 153, identifier:j; 154, call; 154, 155; 154, 156; 155, identifier:len; 156, argument_list; 156, 157; 157, identifier:Bps; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:mid; 163, identifier:append; 164, argument_list; 164, 165; 165, subscript; 165, 166; 165, 167; 166, identifier:Bps; 167, identifier:m; 168, return_statement; 168, 169; 169, identifier:mid | def sort_segment_points(Aps, Bps):
mid = []
j = 0
mid.append(Aps[0])
for i in range(len(Aps)-1):
dist = distance_tt_point(Aps[i], Aps[i+1])
for m in range(j, len(Bps)):
distm = distance_tt_point(Aps[i], Bps[m])
if dist > distm:
direction = dot(normalize(line(Aps[i].gen2arr(), Aps[i+1].gen2arr())), normalize(Bps[m].gen2arr()))
if direction > 0:
j = m + 1
mid.append(Bps[m])
break
mid.append(Aps[i+1])
for m in range(j, len(Bps)):
mid.append(Bps[m])
return mid |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 43; 2, function_name:works; 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; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:query; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:filter; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:offset; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:limit; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:sample; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:sort; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:order; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:facet; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:select; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:cursor; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:cursor_max; 40, integer:5000; 41, dictionary_splat_pattern; 41, 42; 42, identifier:kwargs; 43, block; 43, 44; 43, 46; 44, expression_statement; 44, 45; 45, string:'''
Search Crossref works
:param ids: [Array] DOIs (digital object identifier) or other identifiers
:param query: [String] A query string
:param filter: [Hash] Filter options. See examples for usage.
Accepts a dict, with filter names and their values. For repeating filter names
pass in a list of the values to that filter name, e.g.,
`{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`.
See https://github.com/CrossRef/rest-api-doc
for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`
and :func:`~habanero.Crossref.filter_details`
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relavant when searching with specific dois.
Default: 20. Max: 1000
:param sample: [Fixnum] Number of random results to return. when you use the sample parameter,
the limit and offset parameters are ignored. Max: 100
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`.
See Facets_ for options.
:param select: [String/list(Strings)] Crossref metadata records can be
quite large. Sometimes you just want a few elements from the schema. You can "select"
a subset of elements to return. This can make your API calls much more efficient. Not
clear yet which fields are allowed here.
:param cursor: [String] Cursor character string to do deep paging. Default is None.
Pass in '*' to start deep paging. Any combination of query, filters and facets may be
used with deep paging cursors. While rows may be specified along with cursor, offset
and sample cannot be used.
See https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md
:param cursor_max: [Fixnum] Max records to retrieve. Only used when cursor param used. Because
deep paging can result in continuous requests until all are retrieved, use this
parameter to set a maximum number of records. Of course, if there are less records
found than this value, you will get only those found.
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.works()
cr.works(ids = '10.1371/journal.pone.0033693')
dois = ['10.1371/journal.pone.0033693', ]
cr.works(ids = dois)
x = cr.works(query = "ecology")
x['status']
x['message-type']
x['message-version']
x['message']
x['message']['total-results']
x['message']['items-per-page']
x['message']['query']
x['message']['items']
x = cr.works(filter = {'has_full_text': True})
x
x = cr.works(filter = {'has_full_text': True})
[ z['DOI'] for z in x['message']['items'] ]
[ {"doi": z['DOI'], "url": z['URL']} for z in x['message']['items'] ]
for i in x['message']['items']:
print i['DOI']
cr.works(filter = {'has_full_text': True})
cr.works(filter = {'has_funder': True, 'has_full_text': True})
cr.works(filter = {'award_number': 'CBET-0756451', 'award_funder': '10.13039/100000001'})
x = cr.works(filter = {'award_funder': ['10.13039/100004440', '10.13039/100000861']}, limit = 100)
map(lambda z:z['funder'][0]['DOI'], x['message']['items'])
cr.works(query = "widget", cursor = "*", cursor_max = 100)
res = cr.works(query = "octopus", cursor = "*", limit = 500)
sum([ len(z['message']['items']) for z in res ])
res = cr.works(query = "extravagant", cursor = "*", limit = 50, cursor_max = 500)
sum([ len(z['message']['items']) for z in res ])
res = cr.works(query = "widget", cursor = "*", cursor_max = 100)
sum([ len(z['message']['items']) for z in res ])
res = cr.works(query = "ecology", cursor = "*", cursor_max = 10000, limit = 1000)
sum([ len(z['message']['items']) for z in res ])
items = [ z['message']['items'] for z in res ]
items = [ item for sublist in items for item in sublist ]
[ z['DOI'] for z in items ][0:50]
res = cr.works(query = "ecology", query_author = 'carl boettiger')
[ x['author'][0]['family'] for x in res['message']['items'] ]
cr.works(query = "ecology", select = "DOI,title")
cr.works(query = "ecology", select = ["DOI","title"])
'''; 46, if_statement; 46, 47; 46, 54; 46, 82; 47, comparison_operator:!=; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:ids; 51, identifier:__class__; 52, identifier:__name__; 53, string:'NoneType'; 54, block; 54, 55; 55, return_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:request; 58, argument_list; 58, 59; 58, 62; 58, 65; 58, 66; 58, 67; 58, 68; 58, 69; 58, 70; 58, 71; 58, 72; 58, 73; 58, 74; 58, 75; 58, 76; 58, 77; 58, 78; 58, 79; 58, 80; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:mailto; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:base_url; 65, string:"/works/"; 66, identifier:ids; 67, identifier:query; 68, identifier:filter; 69, identifier:offset; 70, identifier:limit; 71, identifier:sample; 72, identifier:sort; 73, identifier:order; 74, identifier:facet; 75, identifier:select; 76, None; 77, None; 78, None; 79, None; 80, dictionary_splat; 80, 81; 81, identifier:kwargs; 82, else_clause; 82, 83; 83, block; 83, 84; 84, return_statement; 84, 85; 85, call; 85, 86; 85, 112; 86, attribute; 86, 87; 86, 111; 87, call; 87, 88; 87, 89; 88, identifier:Request; 89, argument_list; 89, 90; 89, 93; 89, 96; 89, 97; 89, 98; 89, 99; 89, 100; 89, 101; 89, 102; 89, 103; 89, 104; 89, 105; 89, 106; 89, 107; 89, 108; 89, 109; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:mailto; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:base_url; 96, string:"/works/"; 97, identifier:query; 98, identifier:filter; 99, identifier:offset; 100, identifier:limit; 101, identifier:sample; 102, identifier:sort; 103, identifier:order; 104, identifier:facet; 105, identifier:select; 106, identifier:cursor; 107, identifier:cursor_max; 108, None; 109, dictionary_splat; 109, 110; 110, identifier:kwargs; 111, identifier:do_request; 112, argument_list | def works(self, ids = None, query = None, filter = None, offset = None,
limit = None, sample = None, sort = None,
order = None, facet = None, select = None, cursor = None,
cursor_max = 5000, **kwargs):
'''
Search Crossref works
:param ids: [Array] DOIs (digital object identifier) or other identifiers
:param query: [String] A query string
:param filter: [Hash] Filter options. See examples for usage.
Accepts a dict, with filter names and their values. For repeating filter names
pass in a list of the values to that filter name, e.g.,
`{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`.
See https://github.com/CrossRef/rest-api-doc
for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`
and :func:`~habanero.Crossref.filter_details`
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relavant when searching with specific dois.
Default: 20. Max: 1000
:param sample: [Fixnum] Number of random results to return. when you use the sample parameter,
the limit and offset parameters are ignored. Max: 100
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`.
See Facets_ for options.
:param select: [String/list(Strings)] Crossref metadata records can be
quite large. Sometimes you just want a few elements from the schema. You can "select"
a subset of elements to return. This can make your API calls much more efficient. Not
clear yet which fields are allowed here.
:param cursor: [String] Cursor character string to do deep paging. Default is None.
Pass in '*' to start deep paging. Any combination of query, filters and facets may be
used with deep paging cursors. While rows may be specified along with cursor, offset
and sample cannot be used.
See https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md
:param cursor_max: [Fixnum] Max records to retrieve. Only used when cursor param used. Because
deep paging can result in continuous requests until all are retrieved, use this
parameter to set a maximum number of records. Of course, if there are less records
found than this value, you will get only those found.
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.works()
cr.works(ids = '10.1371/journal.pone.0033693')
dois = ['10.1371/journal.pone.0033693', ]
cr.works(ids = dois)
x = cr.works(query = "ecology")
x['status']
x['message-type']
x['message-version']
x['message']
x['message']['total-results']
x['message']['items-per-page']
x['message']['query']
x['message']['items']
x = cr.works(filter = {'has_full_text': True})
x
x = cr.works(filter = {'has_full_text': True})
[ z['DOI'] for z in x['message']['items'] ]
[ {"doi": z['DOI'], "url": z['URL']} for z in x['message']['items'] ]
for i in x['message']['items']:
print i['DOI']
cr.works(filter = {'has_full_text': True})
cr.works(filter = {'has_funder': True, 'has_full_text': True})
cr.works(filter = {'award_number': 'CBET-0756451', 'award_funder': '10.13039/100000001'})
x = cr.works(filter = {'award_funder': ['10.13039/100004440', '10.13039/100000861']}, limit = 100)
map(lambda z:z['funder'][0]['DOI'], x['message']['items'])
cr.works(query = "widget", cursor = "*", cursor_max = 100)
res = cr.works(query = "octopus", cursor = "*", limit = 500)
sum([ len(z['message']['items']) for z in res ])
res = cr.works(query = "extravagant", cursor = "*", limit = 50, cursor_max = 500)
sum([ len(z['message']['items']) for z in res ])
res = cr.works(query = "widget", cursor = "*", cursor_max = 100)
sum([ len(z['message']['items']) for z in res ])
res = cr.works(query = "ecology", cursor = "*", cursor_max = 10000, limit = 1000)
sum([ len(z['message']['items']) for z in res ])
items = [ z['message']['items'] for z in res ]
items = [ item for sublist in items for item in sublist ]
[ z['DOI'] for z in items ][0:50]
res = cr.works(query = "ecology", query_author = 'carl boettiger')
[ x['author'][0]['family'] for x in res['message']['items'] ]
cr.works(query = "ecology", select = "DOI,title")
cr.works(query = "ecology", select = ["DOI","title"])
'''
if ids.__class__.__name__ != 'NoneType':
return request(self.mailto, self.base_url, "/works/", ids,
query, filter, offset, limit, sample, sort,
order, facet, select, None, None, None, None, **kwargs)
else:
return Request(self.mailto, self.base_url, "/works/",
query, filter, offset, limit, sample, sort,
order, facet, select, cursor, cursor_max, None, **kwargs).do_request() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 43; 2, function_name:prefixes; 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; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:filter; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:offset; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:limit; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sample; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:sort; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:order; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:facet; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:works; 31, False; 32, default_parameter; 32, 33; 32, 34; 33, identifier:select; 34, None; 35, default_parameter; 35, 36; 35, 37; 36, identifier:cursor; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:cursor_max; 40, integer:5000; 41, dictionary_splat_pattern; 41, 42; 42, identifier:kwargs; 43, block; 43, 44; 43, 46; 43, 53; 44, expression_statement; 44, 45; 45, string:'''
Search Crossref prefixes
:param ids: [Array] DOIs (digital object identifier) or other identifiers
:param filter: [Hash] Filter options. See examples for usage.
Accepts a dict, with filter names and their values. For repeating filter names
pass in a list of the values to that filter name, e.g.,
`{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`.
See https://github.com/CrossRef/rest-api-doc
for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`
and :func:`~habanero.Crossref.filter_details`
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000
:param sample: [Fixnum] Number of random results to return. when you use the sample parameter,
the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`
See Facets_ for options.
:param select: [String/list(Strings)] Crossref metadata records can be
quite large. Sometimes you just want a few elements from the schema. You can "select"
a subset of elements to return. This can make your API calls much more efficient. Not
clear yet which fields are allowed here.
:param works: [Boolean] If true, works returned as well. Default: false
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.prefixes(ids = "10.1016")
cr.prefixes(ids = ['10.1016','10.1371','10.1023','10.4176','10.1093'])
cr.prefixes(ids = "10.1016", works = True)
cr.prefixes(ids = "10.1016", works = True, limit = 3)
cr.prefixes(ids = "10.1016", works = True, sort = "relevance", order = "asc")
res = cr.prefixes(ids = "10.1016", works = True, cursor = "*", limit = 200)
sum([ len(z['message']['items']) for z in res ])
items = [ z['message']['items'] for z in res ]
items = [ item for sublist in items for item in sublist ]
[ z['DOI'] for z in items ][0:50]
res = cr.prefixes(ids = "10.1371", works = True, query_editor = 'cooper', filter = {'type': 'journal-article'})
eds = [ x.get('editor') for x in res['message']['items'] ]
[ z for z in eds if z is not None ]
'''; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:check_kwargs; 49, argument_list; 49, 50; 49, 52; 50, list:["query"]; 50, 51; 51, string:"query"; 52, identifier:kwargs; 53, return_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:request; 56, argument_list; 56, 57; 56, 60; 56, 63; 56, 64; 56, 65; 56, 68; 56, 71; 56, 74; 56, 77; 56, 80; 56, 83; 56, 86; 56, 89; 56, 92; 56, 95; 56, 98; 56, 101; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:mailto; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:base_url; 63, string:"/prefixes/"; 64, identifier:ids; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:query; 67, None; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:filter; 70, identifier:filter; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:offset; 73, identifier:offset; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:limit; 76, identifier:limit; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:sample; 79, identifier:sample; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:sort; 82, identifier:sort; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:order; 85, identifier:order; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:facet; 88, identifier:facet; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:select; 91, identifier:select; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:works; 94, identifier:works; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:cursor; 97, identifier:cursor; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:cursor_max; 100, identifier:cursor_max; 101, dictionary_splat; 101, 102; 102, identifier:kwargs | def prefixes(self, ids = None, filter = None, offset = None,
limit = None, sample = None, sort = None,
order = None, facet = None, works = False, select = None,
cursor = None, cursor_max = 5000, **kwargs):
'''
Search Crossref prefixes
:param ids: [Array] DOIs (digital object identifier) or other identifiers
:param filter: [Hash] Filter options. See examples for usage.
Accepts a dict, with filter names and their values. For repeating filter names
pass in a list of the values to that filter name, e.g.,
`{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`.
See https://github.com/CrossRef/rest-api-doc
for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`
and :func:`~habanero.Crossref.filter_details`
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000
:param sample: [Fixnum] Number of random results to return. when you use the sample parameter,
the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`
See Facets_ for options.
:param select: [String/list(Strings)] Crossref metadata records can be
quite large. Sometimes you just want a few elements from the schema. You can "select"
a subset of elements to return. This can make your API calls much more efficient. Not
clear yet which fields are allowed here.
:param works: [Boolean] If true, works returned as well. Default: false
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.prefixes(ids = "10.1016")
cr.prefixes(ids = ['10.1016','10.1371','10.1023','10.4176','10.1093'])
cr.prefixes(ids = "10.1016", works = True)
cr.prefixes(ids = "10.1016", works = True, limit = 3)
cr.prefixes(ids = "10.1016", works = True, sort = "relevance", order = "asc")
res = cr.prefixes(ids = "10.1016", works = True, cursor = "*", limit = 200)
sum([ len(z['message']['items']) for z in res ])
items = [ z['message']['items'] for z in res ]
items = [ item for sublist in items for item in sublist ]
[ z['DOI'] for z in items ][0:50]
res = cr.prefixes(ids = "10.1371", works = True, query_editor = 'cooper', filter = {'type': 'journal-article'})
eds = [ x.get('editor') for x in res['message']['items'] ]
[ z for z in eds if z is not None ]
'''
check_kwargs(["query"], kwargs)
return request(self.mailto, self.base_url, "/prefixes/", ids,
query = None, filter = filter, offset = offset, limit = limit,
sample = sample, sort = sort, order = order, facet = facet,
select = select, works = works, cursor = cursor, cursor_max = cursor_max,
**kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 46; 2, function_name:types; 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:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ids; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:query; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:filter; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:offset; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:limit; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:sample; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:sort; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:order; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:facet; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:works; 34, False; 35, default_parameter; 35, 36; 35, 37; 36, identifier:select; 37, None; 38, default_parameter; 38, 39; 38, 40; 39, identifier:cursor; 40, None; 41, default_parameter; 41, 42; 41, 43; 42, identifier:cursor_max; 43, integer:5000; 44, dictionary_splat_pattern; 44, 45; 45, identifier:kwargs; 46, block; 46, 47; 46, 49; 47, expression_statement; 47, 48; 48, string:'''
Search Crossref types
:param ids: [Array] Type identifier, e.g., journal
:param query: [String] A query string
:param filter: [Hash] Filter options. See examples for usage.
Accepts a dict, with filter names and their values. For repeating filter names
pass in a list of the values to that filter name, e.g.,
`{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`.
See https://github.com/CrossRef/rest-api-doc
for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`
and :func:`~habanero.Crossref.filter_details`
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000
:param sample: [Fixnum] Number of random results to return. when you use the sample parameter,
the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`
See Facets_ for options.
:param select: [String/list(Strings)] Crossref metadata records can be
quite large. Sometimes you just want a few elements from the schema. You can "select"
a subset of elements to return. This can make your API calls much more efficient. Not
clear yet which fields are allowed here.
:param works: [Boolean] If true, works returned as well. Default: false
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.types()
cr.types(ids = "journal")
cr.types(ids = "journal-article")
cr.types(ids = "journal", works = True)
res = cr.types(ids = "journal-article", works = True, query_title = 'gender', rows = 100)
[ x.get('title') for x in res['message']['items'] ]
'''; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:request; 52, argument_list; 52, 53; 52, 56; 52, 59; 52, 60; 52, 61; 52, 62; 52, 63; 52, 64; 52, 65; 52, 66; 52, 67; 52, 68; 52, 69; 52, 70; 52, 71; 52, 72; 52, 73; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:mailto; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:base_url; 59, string:"/types/"; 60, identifier:ids; 61, identifier:query; 62, identifier:filter; 63, identifier:offset; 64, identifier:limit; 65, identifier:sample; 66, identifier:sort; 67, identifier:order; 68, identifier:facet; 69, identifier:select; 70, identifier:works; 71, identifier:cursor; 72, identifier:cursor_max; 73, dictionary_splat; 73, 74; 74, identifier:kwargs | def types(self, ids = None, query = None, filter = None, offset = None,
limit = None, sample = None, sort = None,
order = None, facet = None, works = False, select = None,
cursor = None, cursor_max = 5000, **kwargs):
'''
Search Crossref types
:param ids: [Array] Type identifier, e.g., journal
:param query: [String] A query string
:param filter: [Hash] Filter options. See examples for usage.
Accepts a dict, with filter names and their values. For repeating filter names
pass in a list of the values to that filter name, e.g.,
`{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`.
See https://github.com/CrossRef/rest-api-doc
for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`
and :func:`~habanero.Crossref.filter_details`
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000
:param sample: [Fixnum] Number of random results to return. when you use the sample parameter,
the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`
See Facets_ for options.
:param select: [String/list(Strings)] Crossref metadata records can be
quite large. Sometimes you just want a few elements from the schema. You can "select"
a subset of elements to return. This can make your API calls much more efficient. Not
clear yet which fields are allowed here.
:param works: [Boolean] If true, works returned as well. Default: false
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.types()
cr.types(ids = "journal")
cr.types(ids = "journal-article")
cr.types(ids = "journal", works = True)
res = cr.types(ids = "journal-article", works = True, query_title = 'gender', rows = 100)
[ x.get('title') for x in res['message']['items'] ]
'''
return request(self.mailto, self.base_url, "/types/", ids,
query, filter, offset, limit, sample, sort,
order, facet, select, works, cursor, cursor_max, **kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:licenses; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:query; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:offset; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:limit; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sample; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:sort; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:order; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:facet; 25, None; 26, dictionary_splat_pattern; 26, 27; 27, identifier:kwargs; 28, block; 28, 29; 28, 31; 28, 40; 28, 68; 29, expression_statement; 29, 30; 30, string:'''
Search Crossref licenses
:param query: [String] A query string
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`
See Facets_ for options.
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.licenses()
cr.licenses(query = "creative")
'''; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:check_kwargs; 34, argument_list; 34, 35; 34, 39; 35, list:["ids", "filter", "works"]; 35, 36; 35, 37; 35, 38; 36, string:"ids"; 37, string:"filter"; 38, string:"works"; 39, identifier:kwargs; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:res; 43, call; 43, 44; 43, 45; 44, identifier:request; 45, argument_list; 45, 46; 45, 49; 45, 52; 45, 53; 45, 54; 45, 55; 45, 56; 45, 57; 45, 58; 45, 59; 45, 60; 45, 61; 45, 62; 45, 63; 45, 64; 45, 65; 45, 66; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:mailto; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:base_url; 52, string:"/licenses/"; 53, None; 54, identifier:query; 55, None; 56, identifier:offset; 57, identifier:limit; 58, None; 59, identifier:sort; 60, identifier:order; 61, identifier:facet; 62, None; 63, None; 64, None; 65, None; 66, dictionary_splat; 66, 67; 67, identifier:kwargs; 68, return_statement; 68, 69; 69, identifier:res | def licenses(self, query = None, offset = None,
limit = None, sample = None, sort = None,
order = None, facet = None, **kwargs):
'''
Search Crossref licenses
:param query: [String] A query string
:param offset: [Fixnum] Number of record to start at, from 1 to 10000
:param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000
:param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort
order will be by the relevance score. If no query is included, then the sort order
will be by DOI update date. See sorting_ for possible values.
:param order: [String] Sort order, one of 'asc' or 'desc'
:param facet: [Boolean/String] Set to `true` to include facet results (default: false).
Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`
See Facets_ for options.
:param kwargs: additional named arguments passed on to `requests.get`, e.g., field
queries (see examples and FieldQueries_)
:return: A dict
Usage::
from habanero import Crossref
cr = Crossref()
cr.licenses()
cr.licenses(query = "creative")
'''
check_kwargs(["ids", "filter", "works"], kwargs)
res = request(self.mailto, self.base_url, "/licenses/", None,
query, None, offset, limit, None, sort,
order, facet, None, None, None, None, **kwargs)
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_graph_component; 3, parameters; 3, 4; 4, identifier:graph; 5, block; 5, 6; 5, 20; 5, 30; 5, 40; 5, 55; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:components; 9, call; 9, 10; 9, 11; 10, identifier:map; 11, argument_list; 11, 12; 11, 19; 12, call; 12, 13; 12, 14; 13, identifier:partial; 14, argument_list; 14, 15; 14, 16; 15, identifier:_visit; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:graph; 18, identifier:graph; 19, identifier:graph; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:node_component; 23, call; 23, 24; 23, 25; 24, identifier:dict; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:_gen_node_component; 28, argument_list; 28, 29; 29, identifier:components; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:graph_component; 33, dictionary_comprehension; 33, 34; 33, 37; 34, pair; 34, 35; 34, 36; 35, identifier:component; 36, list:[]; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:component; 39, identifier:components; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:graph_component; 44, identifier:update; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:dict; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:_gen_graph_component; 51, argument_list; 51, 52; 51, 53; 51, 54; 52, identifier:graph; 53, identifier:node_component; 54, identifier:_gen_graph_value; 55, return_statement; 55, 56; 56, identifier:graph_component | def get_graph_component(graph):
components = map(partial(_visit, graph=graph), graph)
node_component = dict(_gen_node_component(components))
graph_component = {component: [] for component in components}
graph_component.update(
dict(_gen_graph_component(graph, node_component, _gen_graph_value)))
return graph_component |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:pipe_fetchdata; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:context; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:_INPUT; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:conf; 12, None; 13, dictionary_splat_pattern; 13, 14; 14, identifier:kwargs; 15, block; 15, 16; 15, 30; 15, 40; 15, 48; 15, 58; 15, 67; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:funcs; 19, call; 19, 20; 19, 21; 20, identifier:get_splits; 21, argument_list; 21, 22; 21, 23; 21, 24; 22, None; 23, identifier:conf; 24, dictionary_splat; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:cdicts; 27, argument_list; 27, 28; 27, 29; 28, identifier:opts; 29, identifier:kwargs; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:parsed; 33, call; 33, 34; 33, 35; 34, identifier:get_parsed; 35, argument_list; 35, 36; 35, 37; 36, identifier:_INPUT; 37, subscript; 37, 38; 37, 39; 38, identifier:funcs; 39, integer:0; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:results; 43, call; 43, 44; 43, 45; 44, identifier:starmap; 45, argument_list; 45, 46; 45, 47; 46, identifier:parse_result; 47, identifier:parsed; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:items; 51, call; 51, 52; 51, 53; 52, identifier:imap; 53, argument_list; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:utils; 56, identifier:gen_items; 57, identifier:results; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:_OUTPUT; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:utils; 64, identifier:multiplex; 65, argument_list; 65, 66; 66, identifier:items; 67, return_statement; 67, 68; 68, identifier:_OUTPUT | def pipe_fetchdata(context=None, _INPUT=None, conf=None, **kwargs):
funcs = get_splits(None, conf, **cdicts(opts, kwargs))
parsed = get_parsed(_INPUT, funcs[0])
results = starmap(parse_result, parsed)
items = imap(utils.gen_items, results)
_OUTPUT = utils.multiplex(items)
return _OUTPUT |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:pipe_sort; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:context; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:_INPUT; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:conf; 12, None; 13, dictionary_splat_pattern; 13, 14; 14, identifier:kwargs; 15, block; 15, 16; 15, 26; 15, 37; 15, 52; 15, 63; 15, 77; 15, 85; 15, 106; 15, 114; 15, 124; 15, 140; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:test; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:kwargs; 22, identifier:pop; 23, argument_list; 23, 24; 23, 25; 24, string:'pass_if'; 25, None; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:_pass; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:utils; 32, identifier:get_pass; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:test; 36, identifier:test; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:key_defs; 40, call; 40, 41; 40, 42; 41, identifier:imap; 42, argument_list; 42, 43; 42, 44; 43, identifier:DotDict; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:utils; 47, identifier:listize; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:conf; 51, string:'KEY'; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:get_value; 55, call; 55, 56; 55, 57; 56, identifier:partial; 57, argument_list; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:utils; 60, identifier:get_value; 61, dictionary_splat; 61, 62; 62, identifier:kwargs; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:parse_conf; 66, call; 66, 67; 66, 68; 67, identifier:partial; 68, argument_list; 68, 69; 68, 72; 68, 75; 69, attribute; 69, 70; 69, 71; 70, identifier:utils; 71, identifier:parse_conf; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:parse_func; 74, identifier:get_value; 75, dictionary_splat; 75, 76; 76, identifier:kwargs; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:keys; 80, call; 80, 81; 80, 82; 81, identifier:imap; 82, argument_list; 82, 83; 82, 84; 83, identifier:parse_conf; 84, identifier:key_defs; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:order; 88, generator_expression; 88, 89; 88, 103; 89, binary_operator:%; 89, 90; 89, 91; 90, string:'%s%s'; 91, tuple; 91, 92; 91, 100; 92, conditional_expression:if; 92, 93; 92, 94; 92, 99; 93, string:'-'; 94, comparison_operator:==; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:k; 97, identifier:dir; 98, string:'DESC'; 99, string:''; 100, attribute; 100, 101; 100, 102; 101, identifier:k; 102, identifier:field; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:k; 105, identifier:keys; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:comparers; 109, call; 109, 110; 109, 111; 110, identifier:map; 111, argument_list; 111, 112; 111, 113; 112, identifier:get_comparer; 113, identifier:order; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:cmp_func; 117, call; 117, 118; 117, 119; 118, identifier:partial; 119, argument_list; 119, 120; 119, 121; 120, identifier:multikeysort; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:comparers; 123, identifier:comparers; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:_OUTPUT; 127, conditional_expression:if; 127, 128; 127, 129; 127, 130; 128, identifier:_INPUT; 129, identifier:_pass; 130, call; 130, 131; 130, 132; 131, identifier:iter; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:sorted; 135, argument_list; 135, 136; 135, 137; 136, identifier:_INPUT; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:cmp; 139, identifier:cmp_func; 140, return_statement; 140, 141; 141, identifier:_OUTPUT | def pipe_sort(context=None, _INPUT=None, conf=None, **kwargs):
test = kwargs.pop('pass_if', None)
_pass = utils.get_pass(test=test)
key_defs = imap(DotDict, utils.listize(conf['KEY']))
get_value = partial(utils.get_value, **kwargs)
parse_conf = partial(utils.parse_conf, parse_func=get_value, **kwargs)
keys = imap(parse_conf, key_defs)
order = ('%s%s' % ('-' if k.dir == 'DESC' else '', k.field) for k in keys)
comparers = map(get_comparer, order)
cmp_func = partial(multikeysort, comparers=comparers)
_OUTPUT = _INPUT if _pass else iter(sorted(_INPUT, cmp=cmp_func))
return _OUTPUT |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:asyncPipeStringtokenizer; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:context; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:_INPUT; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:conf; 12, None; 13, dictionary_splat_pattern; 13, 14; 14, identifier:kwargs; 15, block; 15, 16; 15, 34; 15, 49; 15, 61; 15, 74; 15, 83; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 21; 18, subscript; 18, 19; 18, 20; 19, identifier:conf; 20, string:'delimiter'; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:conf; 24, identifier:pop; 25, argument_list; 25, 26; 25, 27; 26, string:'to-str'; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:dict; 30, identifier:get; 31, argument_list; 31, 32; 31, 33; 32, identifier:conf; 33, string:'delimiter'; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:splits; 37, yield; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:asyncGetSplits; 40, argument_list; 40, 41; 40, 42; 40, 43; 41, identifier:_INPUT; 42, identifier:conf; 43, dictionary_splat; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:cdicts; 46, argument_list; 46, 47; 46, 48; 47, identifier:opts; 48, identifier:kwargs; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:parsed; 52, yield; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:asyncDispatch; 55, argument_list; 55, 56; 55, 57; 56, identifier:splits; 57, list_splat; 57, 58; 58, call; 58, 59; 58, 60; 59, identifier:get_async_dispatch_funcs; 60, argument_list; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:items; 64, yield; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:asyncStarMap; 67, argument_list; 67, 68; 67, 73; 68, call; 68, 69; 68, 70; 69, identifier:partial; 70, argument_list; 70, 71; 70, 72; 71, identifier:maybeDeferred; 72, identifier:parse_result; 73, identifier:parsed; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:_OUTPUT; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:utils; 80, identifier:multiplex; 81, argument_list; 81, 82; 82, identifier:items; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:returnValue; 86, argument_list; 86, 87; 87, identifier:_OUTPUT | def asyncPipeStringtokenizer(context=None, _INPUT=None, conf=None, **kwargs):
conf['delimiter'] = conf.pop('to-str', dict.get(conf, 'delimiter'))
splits = yield asyncGetSplits(_INPUT, conf, **cdicts(opts, kwargs))
parsed = yield asyncDispatch(splits, *get_async_dispatch_funcs())
items = yield asyncStarMap(partial(maybeDeferred, parse_result), parsed)
_OUTPUT = utils.multiplex(items)
returnValue(_OUTPUT) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:alphabeta; 3, parameters; 3, 4; 3, 5; 3, 17; 4, identifier:game; 5, default_parameter; 5, 6; 5, 7; 6, identifier:alpha_beta; 7, tuple; 7, 8; 7, 13; 8, unary_operator:-; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:float; 11, argument_list; 11, 12; 12, string:'inf'; 13, call; 13, 14; 13, 15; 14, identifier:float; 15, argument_list; 15, 16; 16, string:'inf'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:player; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:dominoes; 22, identifier:players; 23, identifier:identity; 24, block; 24, 25; 24, 27; 24, 42; 24, 114; 24, 176; 25, expression_statement; 25, 26; 26, string:'''
Runs minimax search with alpha-beta pruning on the provided game.
:param Game game: game to search
:param tuple alpha_beta: a tuple of two floats that indicate
the initial values of alpha and beta,
respectively. The default is (-inf, inf).
:param callable player: player used to sort moves to be explored.
Ordering better moves first may significantly
reduce the amount of moves that need to be
explored. The identity player is the default.
'''; 27, if_statement; 27, 28; 27, 33; 28, comparison_operator:is; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:game; 31, identifier:result; 32, None; 33, block; 33, 34; 34, return_statement; 34, 35; 35, expression_list; 35, 36; 35, 37; 36, list:[]; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:game; 40, identifier:result; 41, identifier:points; 42, if_statement; 42, 43; 42, 48; 42, 80; 43, binary_operator:%; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:game; 46, identifier:turn; 47, integer:2; 48, block; 48, 49; 48, 56; 48, 62; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:best_value; 52, call; 52, 53; 52, 54; 53, identifier:float; 54, argument_list; 54, 55; 55, string:'inf'; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:op; 59, attribute; 59, 60; 59, 61; 60, identifier:operator; 61, identifier:lt; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:update; 65, lambda; 65, 66; 65, 69; 66, lambda_parameters; 66, 67; 66, 68; 67, identifier:ab; 68, identifier:v; 69, tuple; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:ab; 72, integer:0; 73, call; 73, 74; 73, 75; 74, identifier:min; 75, argument_list; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:ab; 78, integer:1; 79, identifier:v; 80, else_clause; 80, 81; 81, block; 81, 82; 81, 90; 81, 96; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:best_value; 85, unary_operator:-; 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, assignment; 91, 92; 91, 93; 92, identifier:op; 93, attribute; 93, 94; 93, 95; 94, identifier:operator; 95, identifier:gt; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:update; 99, lambda; 99, 100; 99, 103; 100, lambda_parameters; 100, 101; 100, 102; 101, identifier:ab; 102, identifier:v; 103, tuple; 103, 104; 103, 111; 104, call; 104, 105; 104, 106; 105, identifier:max; 106, argument_list; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:ab; 109, integer:0; 110, identifier:v; 111, subscript; 111, 112; 111, 113; 112, identifier:ab; 113, integer:1; 114, for_statement; 114, 115; 114, 118; 114, 123; 115, pattern_list; 115, 116; 115, 117; 116, identifier:move; 117, identifier:new_game; 118, call; 118, 119; 118, 120; 119, identifier:make_moves; 120, argument_list; 120, 121; 120, 122; 121, identifier:game; 122, identifier:player; 123, block; 123, 124; 123, 135; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, pattern_list; 126, 127; 126, 128; 127, identifier:moves; 128, identifier:value; 129, call; 129, 130; 129, 131; 130, identifier:alphabeta; 131, argument_list; 131, 132; 131, 133; 131, 134; 132, identifier:new_game; 133, identifier:alpha_beta; 134, identifier:player; 135, if_statement; 135, 136; 135, 141; 136, call; 136, 137; 136, 138; 137, identifier:op; 138, argument_list; 138, 139; 138, 140; 139, identifier:value; 140, identifier:best_value; 141, block; 141, 142; 141, 146; 141, 150; 141, 158; 141, 166; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:best_value; 145, identifier:value; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:best_moves; 149, identifier:moves; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:best_moves; 154, identifier:insert; 155, argument_list; 155, 156; 155, 157; 156, integer:0; 157, identifier:move; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:alpha_beta; 161, call; 161, 162; 161, 163; 162, identifier:update; 163, argument_list; 163, 164; 163, 165; 164, identifier:alpha_beta; 165, identifier:best_value; 166, if_statement; 166, 167; 166, 174; 167, comparison_operator:<=; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:alpha_beta; 170, integer:1; 171, subscript; 171, 172; 171, 173; 172, identifier:alpha_beta; 173, integer:0; 174, block; 174, 175; 175, break_statement; 176, return_statement; 176, 177; 177, expression_list; 177, 178; 177, 179; 178, identifier:best_moves; 179, identifier:best_value | def alphabeta(game, alpha_beta=(-float('inf'), float('inf')),
player=dominoes.players.identity):
'''
Runs minimax search with alpha-beta pruning on the provided game.
:param Game game: game to search
:param tuple alpha_beta: a tuple of two floats that indicate
the initial values of alpha and beta,
respectively. The default is (-inf, inf).
:param callable player: player used to sort moves to be explored.
Ordering better moves first may significantly
reduce the amount of moves that need to be
explored. The identity player is the default.
'''
if game.result is not None:
return [], game.result.points
if game.turn % 2:
best_value = float('inf')
op = operator.lt
update = lambda ab, v: (ab[0], min(ab[1], v))
else:
best_value = -float('inf')
op = operator.gt
update = lambda ab, v: (max(ab[0], v), ab[1])
for move, new_game in make_moves(game, player):
moves, value = alphabeta(new_game, alpha_beta, player)
if op(value, best_value):
best_value = value
best_moves = moves
best_moves.insert(0, move)
alpha_beta = update(alpha_beta, best_value)
if alpha_beta[1] <= alpha_beta[0]:
break
return best_moves, best_value |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:csv; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:cls; 5, identifier:d; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:header; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sort_keys; 14, True; 15, block; 15, 16; 15, 25; 15, 36; 15, 63; 15, 74; 15, 85; 15, 109; 15, 113; 15, 117; 15, 128; 15, 148; 15, 202; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:first_element; 19, subscript; 19, 20; 19, 24; 20, call; 20, 21; 20, 22; 21, identifier:list; 22, argument_list; 22, 23; 23, identifier:d; 24, integer:0; 25, function_definition; 25, 26; 25, 27; 25, 28; 26, function_name:_keys; 27, parameters; 28, block; 28, 29; 29, return_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:list; 32, argument_list; 32, 33; 33, subscript; 33, 34; 33, 35; 34, identifier:d; 35, identifier:first_element; 36, function_definition; 36, 37; 36, 38; 36, 41; 37, function_name:_get; 38, parameters; 38, 39; 38, 40; 39, identifier:element; 40, identifier:key; 41, block; 41, 42; 41, 61; 42, try_statement; 42, 43; 42, 55; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:tmp; 47, call; 47, 48; 47, 49; 48, identifier:str; 49, argument_list; 49, 50; 50, subscript; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:d; 53, identifier:element; 54, identifier:key; 55, except_clause; 55, 56; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:tmp; 60, string:' '; 61, return_statement; 61, 62; 62, identifier:tmp; 63, if_statement; 63, 64; 63, 71; 64, boolean_operator:or; 64, 65; 64, 68; 65, comparison_operator:is; 65, 66; 65, 67; 66, identifier:d; 67, None; 68, comparison_operator:==; 68, 69; 68, 70; 69, identifier:d; 70, dictionary; 71, block; 71, 72; 72, return_statement; 72, 73; 73, None; 74, if_statement; 74, 75; 74, 78; 75, comparison_operator:is; 75, 76; 75, 77; 76, identifier:order; 77, None; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:order; 82, call; 82, 83; 82, 84; 83, identifier:_keys; 84, argument_list; 85, if_statement; 85, 86; 85, 93; 85, 98; 86, boolean_operator:and; 86, 87; 86, 90; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:header; 89, None; 90, comparison_operator:is; 90, 91; 90, 92; 91, identifier:order; 92, None; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:header; 97, identifier:order; 98, elif_clause; 98, 99; 98, 102; 99, comparison_operator:is; 99, 100; 99, 101; 100, identifier:header; 101, None; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:header; 106, call; 106, 107; 106, 108; 107, identifier:_keys; 108, argument_list; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:table; 112, string:""; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:content; 116, list:[]; 117, for_statement; 117, 118; 117, 119; 117, 120; 118, identifier:attribute; 119, identifier:order; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:content; 125, identifier:append; 126, argument_list; 126, 127; 127, identifier:attribute; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:table; 131, binary_operator:+; 131, 132; 131, 147; 132, binary_operator:+; 132, 133; 132, 134; 133, identifier:table; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, string:","; 137, identifier:join; 138, argument_list; 138, 139; 139, list_comprehension; 139, 140; 139, 144; 140, call; 140, 141; 140, 142; 141, identifier:str; 142, argument_list; 142, 143; 143, identifier:e; 144, for_in_clause; 144, 145; 144, 146; 145, identifier:e; 146, identifier:content; 147, string:"\n"; 148, for_statement; 148, 149; 148, 150; 148, 151; 149, identifier:job; 150, identifier:d; 151, block; 151, 152; 151, 156; 151, 182; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:content; 155, list:[]; 156, for_statement; 156, 157; 156, 158; 156, 159; 157, identifier:attribute; 158, identifier:order; 159, block; 159, 160; 160, try_statement; 160, 161; 160, 173; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:content; 166, identifier:append; 167, argument_list; 167, 168; 168, subscript; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:d; 171, identifier:job; 172, identifier:attribute; 173, except_clause; 173, 174; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:content; 179, identifier:append; 180, argument_list; 180, 181; 181, string:"None"; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:table; 185, binary_operator:+; 185, 186; 185, 201; 186, binary_operator:+; 186, 187; 186, 188; 187, identifier:table; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, string:","; 191, identifier:join; 192, argument_list; 192, 193; 193, list_comprehension; 193, 194; 193, 198; 194, call; 194, 195; 194, 196; 195, identifier:str; 196, argument_list; 196, 197; 197, identifier:e; 198, for_in_clause; 198, 199; 198, 200; 199, identifier:e; 200, identifier:content; 201, string:"\n"; 202, return_statement; 202, 203; 203, identifier:table | def csv(cls,
d,
order=None,
header=None,
sort_keys=True):
first_element = list(d)[0]
def _keys():
return list(d[first_element])
def _get(element, key):
try:
tmp = str(d[element][key])
except:
tmp = ' '
return tmp
if d is None or d == {}:
return None
if order is None:
order = _keys()
if header is None and order is not None:
header = order
elif header is None:
header = _keys()
table = ""
content = []
for attribute in order:
content.append(attribute)
table = table + ",".join([str(e) for e in content]) + "\n"
for job in d:
content = []
for attribute in order:
try:
content.append(d[job][attribute])
except:
content.append("None")
table = table + ",".join([str(e) for e in content]) + "\n"
return table |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:deauthorize_application; 3, parameters; 3, 4; 4, identifier:request; 5, block; 5, 6; 6, if_statement; 6, 7; 6, 10; 6, 48; 7, attribute; 7, 8; 7, 9; 8, identifier:request; 9, identifier:facebook; 10, block; 10, 11; 10, 32; 10, 38; 10, 44; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:user; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:User; 18, identifier:objects; 19, identifier:get; 20, argument_list; 20, 21; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:facebook_id; 23, attribute; 23, 24; 23, 31; 24, attribute; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:request; 28, identifier:facebook; 29, identifier:signed_request; 30, identifier:user; 31, identifier:id; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:user; 36, identifier:authorized; 37, False; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:user; 42, identifier:save; 43, argument_list; 44, return_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:HttpResponse; 47, argument_list; 48, else_clause; 48, 49; 49, block; 49, 50; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:HttpResponse; 53, argument_list; 53, 54; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:status; 56, integer:400 | def deauthorize_application(request):
if request.facebook:
user = User.objects.get(
facebook_id = request.facebook.signed_request.user.id
)
user.authorized = False
user.save()
return HttpResponse()
else:
return HttpResponse(status=400) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_handle_send_response; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:result; 6, identifier:payloadsByTopicPart; 7, identifier:deferredsByTopicPart; 8, block; 8, 9; 8, 50; 8, 98; 8, 122; 8, 267; 8, 271; 8, 412; 8, 471; 8, 479; 9, function_definition; 9, 10; 9, 11; 9, 16; 10, function_name:_deliver_result; 11, parameters; 11, 12; 11, 13; 12, identifier:d_list; 13, default_parameter; 13, 14; 13, 15; 14, identifier:result; 15, None; 16, block; 16, 17; 17, for_statement; 17, 18; 17, 19; 17, 20; 18, identifier:d; 19, identifier:d_list; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 28; 21, 35; 22, not_operator; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 27; 26, identifier:d; 27, identifier:Deferred; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:_deliver_result; 32, argument_list; 32, 33; 32, 34; 33, identifier:d; 34, identifier:result; 35, else_clause; 35, 36; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 42; 38, not_operator; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:d; 41, identifier:called; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:d; 47, identifier:callback; 48, argument_list; 48, 49; 49, identifier:result; 50, function_definition; 50, 51; 50, 52; 50, 54; 51, function_name:_do_retry; 52, parameters; 52, 53; 53, identifier:payloads; 54, block; 54, 55; 54, 79; 54, 85; 54, 96; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:d; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:client; 63, identifier:send_produce_request; 64, argument_list; 64, 65; 64, 66; 64, 71; 64, 76; 65, identifier:payloads; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:acks; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:req_acks; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:timeout; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:ack_timeout; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:fail_on_error; 78, False; 79, expression_statement; 79, 80; 80, augmented_assignment:+=; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_req_attempts; 84, integer:1; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:d; 89, identifier:addBoth; 90, argument_list; 90, 91; 90, 94; 90, 95; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:_handle_send_response; 94, identifier:payloadsByTopicPart; 95, identifier:deferredsByTopicPart; 96, return_statement; 96, 97; 97, identifier:d; 98, function_definition; 98, 99; 98, 100; 98, 103; 99, function_name:_cancel_retry; 100, parameters; 100, 101; 100, 102; 101, identifier:failure; 102, identifier:dc; 103, block; 103, 104; 103, 110; 103, 120; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:dc; 108, identifier:cancel; 109, argument_list; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:_deliver_result; 113, argument_list; 113, 114; 113, 119; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:deferredsByTopicPart; 117, identifier:values; 118, argument_list; 119, identifier:failure; 120, return_statement; 120, 121; 121, identifier:failure; 122, function_definition; 122, 123; 122, 124; 122, 126; 123, function_name:_check_retry_payloads; 124, parameters; 124, 125; 125, identifier:failed_payloads_with_errs; 126, block; 126, 127; 126, 163; 126, 169; 126, 194; 126, 202; 126, 210; 126, 216; 126, 245; 126, 258; 126, 265; 127, if_statement; 127, 128; 127, 135; 128, comparison_operator:>=; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_req_attempts; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:_max_attempts; 135, block; 135, 136; 135, 162; 136, for_statement; 136, 137; 136, 140; 136, 141; 137, pattern_list; 137, 138; 137, 139; 138, identifier:p; 139, identifier:f; 140, identifier:failed_payloads_with_errs; 141, block; 141, 142; 141, 154; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:t_and_p; 145, call; 145, 146; 145, 147; 146, identifier:TopicAndPartition; 147, argument_list; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:p; 150, identifier:topic; 151, attribute; 151, 152; 151, 153; 152, identifier:p; 153, identifier:partition; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:_deliver_result; 157, argument_list; 157, 158; 157, 161; 158, subscript; 158, 159; 158, 160; 159, identifier:deferredsByTopicPart; 160, identifier:t_and_p; 161, identifier:f; 162, return_statement; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:d; 166, call; 166, 167; 166, 168; 167, identifier:Deferred; 168, argument_list; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:dc; 172, call; 172, 173; 172, 180; 173, attribute; 173, 174; 173, 179; 174, attribute; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:client; 178, identifier:reactor; 179, identifier:callLater; 180, argument_list; 180, 181; 180, 184; 180, 187; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:_retry_interval; 184, attribute; 184, 185; 184, 186; 185, identifier:d; 186, identifier:callback; 187, list_comprehension; 187, 188; 187, 189; 188, identifier:p; 189, for_in_clause; 189, 190; 189, 193; 190, pattern_list; 190, 191; 190, 192; 191, identifier:p; 192, identifier:f; 193, identifier:failed_payloads; 194, expression_statement; 194, 195; 195, augmented_assignment:*=; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:_retry_interval; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:RETRY_INTERVAL_FACTOR; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:d; 206, identifier:addErrback; 207, argument_list; 207, 208; 207, 209; 208, identifier:_cancel_retry; 209, identifier:dc; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:reset_topics; 213, call; 213, 214; 213, 215; 214, identifier:set; 215, argument_list; 216, for_statement; 216, 217; 216, 220; 216, 221; 217, pattern_list; 217, 218; 217, 219; 218, identifier:payload; 219, identifier:e; 220, identifier:failed_payloads; 221, block; 221, 222; 222, if_statement; 222, 223; 222, 235; 223, parenthesized_expression; 223, 224; 224, boolean_operator:or; 224, 225; 224, 230; 225, call; 225, 226; 225, 227; 226, identifier:isinstance; 227, argument_list; 227, 228; 227, 229; 228, identifier:e; 229, identifier:NotLeaderForPartitionError; 230, call; 230, 231; 230, 232; 231, identifier:isinstance; 232, argument_list; 232, 233; 232, 234; 233, identifier:e; 234, identifier:UnknownTopicOrPartitionError; 235, block; 235, 236; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:reset_topics; 240, identifier:add; 241, argument_list; 241, 242; 242, attribute; 242, 243; 242, 244; 243, identifier:payload; 244, identifier:topic; 245, if_statement; 245, 246; 245, 247; 246, identifier:reset_topics; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 255; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:client; 254, identifier:reset_topic_metadata; 255, argument_list; 255, 256; 256, list_splat; 256, 257; 257, identifier:reset_topics; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:d; 262, identifier:addCallback; 263, argument_list; 263, 264; 264, identifier:_do_retry; 265, return_statement; 265, 266; 266, identifier:d; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:failed_payloads; 270, list:[]; 271, if_statement; 271, 272; 271, 274; 271, 308; 272, not_operator; 272, 273; 273, identifier:result; 274, block; 274, 275; 274, 297; 274, 307; 275, if_statement; 275, 276; 275, 281; 275, 286; 276, comparison_operator:==; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:req_acks; 280, identifier:PRODUCER_ACK_NOT_REQUIRED; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:result; 285, None; 286, else_clause; 286, 287; 287, block; 287, 288; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:result; 291, call; 291, 292; 291, 293; 292, identifier:Failure; 293, argument_list; 293, 294; 294, call; 294, 295; 294, 296; 295, identifier:NoResponseError; 296, argument_list; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 300; 299, identifier:_deliver_result; 300, argument_list; 300, 301; 300, 306; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:deferredsByTopicPart; 304, identifier:values; 305, argument_list; 306, identifier:result; 307, return_statement; 308, elif_clause; 308, 309; 308, 314; 309, call; 309, 310; 309, 311; 310, identifier:isinstance; 311, argument_list; 311, 312; 311, 313; 312, identifier:result; 313, identifier:Failure; 314, block; 314, 315; 315, if_statement; 315, 316; 315, 323; 315, 386; 316, not_operator; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:result; 320, identifier:check; 321, argument_list; 321, 322; 322, identifier:FailedPayloadsError; 323, block; 323, 324; 324, if_statement; 324, 325; 324, 331; 324, 354; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:result; 328, identifier:check; 329, argument_list; 329, 330; 330, identifier:KafkaError; 331, block; 331, 332; 331, 340; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 337; 334, pattern_list; 334, 335; 334, 336; 335, identifier:failure; 336, identifier:result; 337, expression_list; 337, 338; 337, 339; 338, identifier:result; 339, list:[]; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:failed_payloads; 343, list_comprehension; 343, 344; 343, 347; 344, tuple; 344, 345; 344, 346; 345, identifier:p; 346, identifier:failure; 347, for_in_clause; 347, 348; 347, 349; 348, identifier:p; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:payloadsByTopicPart; 352, identifier:values; 353, argument_list; 354, else_clause; 354, 355; 355, block; 355, 356; 355, 375; 355, 385; 356, if_statement; 356, 357; 356, 364; 357, not_operator; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:result; 361, identifier:check; 362, argument_list; 362, 363; 363, identifier:tid_CancelledError; 364, block; 364, 365; 365, expression_statement; 365, 366; 366, call; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:log; 369, identifier:error; 370, argument_list; 370, 371; 370, 374; 371, concatenated_string; 371, 372; 371, 373; 372, string:"Unexpected failure: %r in "; 373, string:"_handle_send_response"; 374, identifier:result; 375, expression_statement; 375, 376; 376, call; 376, 377; 376, 378; 377, identifier:_deliver_result; 378, argument_list; 378, 379; 378, 384; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:deferredsByTopicPart; 382, identifier:values; 383, argument_list; 384, identifier:result; 385, return_statement; 386, else_clause; 386, 387; 387, block; 387, 388; 387, 392; 387, 402; 388, expression_statement; 388, 389; 389, assignment; 389, 390; 389, 391; 390, identifier:failure; 391, identifier:result; 392, expression_statement; 392, 393; 393, assignment; 393, 394; 393, 395; 394, identifier:result; 395, subscript; 395, 396; 395, 401; 396, attribute; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:failure; 399, identifier:value; 400, identifier:args; 401, integer:0; 402, expression_statement; 402, 403; 403, assignment; 403, 404; 403, 405; 404, identifier:failed_payloads; 405, subscript; 405, 406; 405, 411; 406, attribute; 406, 407; 406, 410; 407, attribute; 407, 408; 407, 409; 408, identifier:failure; 409, identifier:value; 410, identifier:args; 411, integer:1; 412, for_statement; 412, 413; 412, 414; 412, 415; 413, identifier:res; 414, identifier:result; 415, block; 415, 416; 415, 428; 415, 438; 416, expression_statement; 416, 417; 417, assignment; 417, 418; 417, 419; 418, identifier:t_and_p; 419, call; 419, 420; 419, 421; 420, identifier:TopicAndPartition; 421, argument_list; 421, 422; 421, 425; 422, attribute; 422, 423; 422, 424; 423, identifier:res; 424, identifier:topic; 425, attribute; 425, 426; 425, 427; 426, identifier:res; 427, identifier:partition; 428, expression_statement; 428, 429; 429, assignment; 429, 430; 429, 431; 430, identifier:t_and_p_err; 431, call; 431, 432; 431, 433; 432, identifier:_check_error; 433, argument_list; 433, 434; 433, 435; 434, identifier:res; 435, keyword_argument; 435, 436; 435, 437; 436, identifier:raiseException; 437, False; 438, if_statement; 438, 439; 438, 441; 438, 454; 439, not_operator; 439, 440; 440, identifier:t_and_p_err; 441, block; 441, 442; 441, 448; 442, expression_statement; 442, 443; 443, assignment; 443, 444; 443, 445; 444, identifier:d_list; 445, subscript; 445, 446; 445, 447; 446, identifier:deferredsByTopicPart; 447, identifier:t_and_p; 448, expression_statement; 448, 449; 449, call; 449, 450; 449, 451; 450, identifier:_deliver_result; 451, argument_list; 451, 452; 451, 453; 452, identifier:d_list; 453, identifier:res; 454, else_clause; 454, 455; 455, block; 455, 456; 455, 462; 456, expression_statement; 456, 457; 457, assignment; 457, 458; 457, 459; 458, identifier:p; 459, subscript; 459, 460; 459, 461; 460, identifier:payloadsByTopicPart; 461, identifier:t_and_p; 462, expression_statement; 462, 463; 463, call; 463, 464; 463, 467; 464, attribute; 464, 465; 464, 466; 465, identifier:failed_payloads; 466, identifier:append; 467, argument_list; 467, 468; 468, tuple; 468, 469; 468, 470; 469, identifier:p; 470, identifier:t_and_p_err; 471, if_statement; 471, 472; 471, 473; 472, identifier:failed_payloads; 473, block; 473, 474; 474, return_statement; 474, 475; 475, call; 475, 476; 475, 477; 476, identifier:_check_retry_payloads; 477, argument_list; 477, 478; 478, identifier:failed_payloads; 479, return_statement | def _handle_send_response(self, result, payloadsByTopicPart,
deferredsByTopicPart):
def _deliver_result(d_list, result=None):
for d in d_list:
if not isinstance(d, Deferred):
_deliver_result(d, result)
else:
if not d.called:
d.callback(result)
def _do_retry(payloads):
d = self.client.send_produce_request(
payloads, acks=self.req_acks, timeout=self.ack_timeout,
fail_on_error=False)
self._req_attempts += 1
d.addBoth(self._handle_send_response, payloadsByTopicPart,
deferredsByTopicPart)
return d
def _cancel_retry(failure, dc):
dc.cancel()
_deliver_result(deferredsByTopicPart.values(), failure)
return failure
def _check_retry_payloads(failed_payloads_with_errs):
if self._req_attempts >= self._max_attempts:
for p, f in failed_payloads_with_errs:
t_and_p = TopicAndPartition(p.topic, p.partition)
_deliver_result(deferredsByTopicPart[t_and_p], f)
return
d = Deferred()
dc = self.client.reactor.callLater(
self._retry_interval, d.callback, [p for p, f in
failed_payloads])
self._retry_interval *= self.RETRY_INTERVAL_FACTOR
d.addErrback(_cancel_retry, dc)
reset_topics = set()
for payload, e in failed_payloads:
if (isinstance(e, NotLeaderForPartitionError) or
isinstance(e, UnknownTopicOrPartitionError)):
reset_topics.add(payload.topic)
if reset_topics:
self.client.reset_topic_metadata(*reset_topics)
d.addCallback(_do_retry)
return d
failed_payloads = []
if not result:
if self.req_acks == PRODUCER_ACK_NOT_REQUIRED:
result = None
else:
result = Failure(NoResponseError())
_deliver_result(deferredsByTopicPart.values(), result)
return
elif isinstance(result, Failure):
if not result.check(FailedPayloadsError):
if result.check(KafkaError):
failure, result = result, []
failed_payloads = [(p, failure) for p in
payloadsByTopicPart.values()]
else:
if not result.check(tid_CancelledError):
log.error("Unexpected failure: %r in "
"_handle_send_response", result)
_deliver_result(deferredsByTopicPart.values(), result)
return
else:
failure = result
result = failure.value.args[0]
failed_payloads = failure.value.args[1]
for res in result:
t_and_p = TopicAndPartition(res.topic, res.partition)
t_and_p_err = _check_error(res, raiseException=False)
if not t_and_p_err:
d_list = deferredsByTopicPart[t_and_p]
_deliver_result(d_list, res)
else:
p = payloadsByTopicPart[t_and_p]
failed_payloads.append((p, t_and_p_err))
if failed_payloads:
return _check_retry_payloads(failed_payloads)
return |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:ordering_url; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:field_name; 6, block; 6, 7; 6, 15; 6, 19; 6, 31; 6, 50; 6, 59; 6, 71; 6, 78; 6, 117; 6, 121; 6, 192; 6, 203; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:path; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:request; 14, identifier:path; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:direction; 18, string:""; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:query_params; 22, call; 22, 23; 22, 30; 23, attribute; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:request; 28, identifier:GET; 29, identifier:copy; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:ordering; 34, call; 34, 35; 34, 48; 35, attribute; 35, 36; 35, 47; 36, call; 36, 37; 36, 44; 37, attribute; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:request; 42, identifier:GET; 43, identifier:get; 44, argument_list; 44, 45; 44, 46; 45, string:"order"; 46, string:""; 47, identifier:split; 48, argument_list; 48, 49; 49, string:","; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:field; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_get_ordering_field_lookup; 57, argument_list; 57, 58; 58, identifier:field_name; 59, if_statement; 59, 60; 59, 62; 60, not_operator; 60, 61; 61, identifier:ordering; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:ordering; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:get_default_ordering; 70, argument_list; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:merged_ordering; 74, call; 74, 75; 74, 76; 75, identifier:list; 76, argument_list; 76, 77; 77, identifier:ordering; 78, for_statement; 78, 79; 78, 80; 78, 85; 79, identifier:ordering_field; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:get_ordering_fields_lookups; 84, argument_list; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 109; 87, boolean_operator:and; 87, 88; 87, 97; 88, parenthesized_expression; 88, 89; 89, comparison_operator:not; 89, 90; 89, 96; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:ordering_field; 93, identifier:lstrip; 94, argument_list; 94, 95; 95, string:"-"; 96, identifier:ordering; 97, parenthesized_expression; 97, 98; 98, comparison_operator:not; 98, 99; 98, 108; 99, parenthesized_expression; 99, 100; 100, binary_operator:+; 100, 101; 100, 102; 101, string:"-"; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:ordering_field; 105, identifier:lstrip; 106, argument_list; 106, 107; 107, string:"-"; 108, identifier:ordering; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:merged_ordering; 114, identifier:append; 115, argument_list; 115, 116; 116, identifier:ordering_field; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:new_ordering; 120, list:[]; 121, for_statement; 121, 122; 121, 123; 121, 124; 122, identifier:item; 123, identifier:merged_ordering; 124, block; 124, 125; 125, if_statement; 125, 126; 125, 139; 126, comparison_operator:==; 126, 127; 126, 133; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:item; 130, identifier:lstrip; 131, argument_list; 131, 132; 132, string:"-"; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:field; 136, identifier:lstrip; 137, argument_list; 137, 138; 138, string:"-"; 139, block; 139, 140; 140, if_statement; 140, 141; 140, 153; 140, 176; 141, boolean_operator:or; 141, 142; 141, 148; 142, parenthesized_expression; 142, 143; 143, comparison_operator:==; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:item; 146, integer:0; 147, string:"-"; 148, not_operator; 148, 149; 149, parenthesized_expression; 149, 150; 150, comparison_operator:in; 150, 151; 150, 152; 151, identifier:item; 152, identifier:ordering; 153, block; 153, 154; 153, 163; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:in; 155, 156; 155, 157; 156, identifier:item; 157, identifier:ordering; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:direction; 162, string:"desc"; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:new_ordering; 167, identifier:insert; 168, argument_list; 168, 169; 168, 170; 169, integer:0; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:item; 173, identifier:lstrip; 174, argument_list; 174, 175; 175, string:"-"; 176, else_clause; 176, 177; 177, block; 177, 178; 177, 182; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:direction; 181, string:"asc"; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:new_ordering; 186, identifier:insert; 187, argument_list; 187, 188; 187, 189; 188, integer:0; 189, binary_operator:+; 189, 190; 189, 191; 190, string:"-"; 191, identifier:item; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:query_params; 196, string:"order"; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, string:","; 200, identifier:join; 201, argument_list; 201, 202; 202, identifier:new_ordering; 203, return_statement; 203, 204; 204, tuple; 204, 205; 204, 217; 205, binary_operator:+; 205, 206; 205, 209; 206, binary_operator:+; 206, 207; 206, 208; 207, identifier:path; 208, string:"?"; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:query_params; 212, identifier:urlencode; 213, argument_list; 213, 214; 214, keyword_argument; 214, 215; 214, 216; 215, identifier:safe; 216, string:","; 217, identifier:direction | def ordering_url(self, field_name):
path = self.request.path
direction = ""
query_params = self.request.GET.copy()
ordering = self.request.GET.get("order", "").split(",")
field = self._get_ordering_field_lookup(field_name)
if not ordering:
ordering = self.get_default_ordering()
merged_ordering = list(ordering)
for ordering_field in self.get_ordering_fields_lookups():
if (ordering_field.lstrip("-") not in ordering) and (
("-" + ordering_field.lstrip("-")) not in ordering
):
merged_ordering.append(ordering_field)
new_ordering = []
for item in merged_ordering:
if item.lstrip("-") == field.lstrip("-"):
if (item[0] == "-") or not (item in ordering):
if item in ordering:
direction = "desc"
new_ordering.insert(0, item.lstrip("-"))
else:
direction = "asc"
new_ordering.insert(0, "-" + item)
query_params["order"] = ",".join(new_ordering)
return (path + "?" + query_params.urlencode(safe=","), direction) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:load_maf; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:optional_cols; 7, list:[]; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_key; 10, identifier:variant_ascending_position_sort_key; 11, default_parameter; 11, 12; 11, 13; 12, identifier:distinct; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:raise_on_error; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:encoding; 19, None; 20, block; 20, 21; 20, 34; 20, 51; 20, 55; 20, 59; 20, 63; 20, 327; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:maf_df; 24, call; 24, 25; 24, 26; 25, identifier:load_maf_dataframe; 26, argument_list; 26, 27; 26, 28; 26, 31; 27, identifier:path; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:raise_on_error; 30, identifier:raise_on_error; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:encoding; 33, identifier:encoding; 34, if_statement; 34, 35; 34, 43; 35, boolean_operator:and; 35, 36; 35, 42; 36, comparison_operator:==; 36, 37; 36, 41; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, identifier:maf_df; 41, integer:0; 42, identifier:raise_on_error; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 50; 49, string:"Empty MAF file %s"; 50, identifier:path; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:ensembl_objects; 54, dictionary; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:variants; 58, list:[]; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:metadata; 62, dictionary; 63, for_statement; 63, 64; 63, 67; 63, 72; 64, pattern_list; 64, 65; 64, 66; 65, identifier:_; 66, identifier:x; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:maf_df; 70, identifier:iterrows; 71, argument_list; 72, block; 72, 73; 72, 79; 72, 110; 72, 116; 72, 122; 72, 128; 72, 176; 72, 231; 72, 250; 72, 301; 72, 320; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:contig; 76, attribute; 76, 77; 76, 78; 77, identifier:x; 78, identifier:Chromosome; 79, if_statement; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:isnull; 82, argument_list; 82, 83; 83, identifier:contig; 84, block; 84, 85; 84, 92; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:error_message; 88, binary_operator:%; 88, 89; 88, 90; 89, string:"Invalid contig name: %s"; 90, tuple; 90, 91; 91, identifier:contig; 92, if_statement; 92, 93; 92, 94; 92, 100; 93, identifier:raise_on_error; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:ValueError; 98, argument_list; 98, 99; 99, identifier:error_message; 100, else_clause; 100, 101; 101, block; 101, 102; 101, 109; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logging; 106, identifier:warn; 107, argument_list; 107, 108; 108, identifier:error_message; 109, continue_statement; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:start_pos; 113, attribute; 113, 114; 113, 115; 114, identifier:x; 115, identifier:Start_Position; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:ref; 119, attribute; 119, 120; 119, 121; 120, identifier:x; 121, identifier:Reference_Allele; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:ncbi_build; 125, attribute; 125, 126; 125, 127; 126, identifier:x; 127, identifier:NCBI_Build; 128, if_statement; 128, 129; 128, 132; 128, 139; 129, comparison_operator:in; 129, 130; 129, 131; 130, identifier:ncbi_build; 131, identifier:ensembl_objects; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:ensembl; 136, subscript; 136, 137; 136, 138; 137, identifier:ensembl_objects; 138, identifier:ncbi_build; 139, else_clause; 139, 140; 140, block; 140, 141; 140, 163; 140, 170; 141, if_statement; 141, 142; 141, 147; 141, 154; 142, call; 142, 143; 142, 144; 143, identifier:isinstance; 144, argument_list; 144, 145; 144, 146; 145, identifier:ncbi_build; 146, identifier:int; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:reference_name; 151, binary_operator:%; 151, 152; 151, 153; 152, string:"B%d"; 153, identifier:ncbi_build; 154, else_clause; 154, 155; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:reference_name; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, identifier:ncbi_build; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:ensembl; 166, call; 166, 167; 166, 168; 167, identifier:infer_genome; 168, argument_list; 168, 169; 169, identifier:reference_name; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:ensembl_objects; 174, identifier:ncbi_build; 175, identifier:ensembl; 176, if_statement; 176, 177; 176, 182; 176, 189; 177, comparison_operator:!=; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:x; 180, identifier:Tumor_Seq_Allele1; 181, identifier:ref; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:alt; 186, attribute; 186, 187; 186, 188; 187, identifier:x; 188, identifier:Tumor_Seq_Allele1; 189, else_clause; 189, 190; 190, block; 190, 191; 190, 225; 191, if_statement; 191, 192; 191, 197; 192, comparison_operator:==; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:x; 195, identifier:Tumor_Seq_Allele2; 196, identifier:ref; 197, block; 197, 198; 197, 207; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:error_message; 201, parenthesized_expression; 201, 202; 202, binary_operator:%; 202, 203; 202, 204; 203, string:"Both tumor alleles agree with reference %s: %s"; 204, tuple; 204, 205; 204, 206; 205, identifier:ref; 206, identifier:x; 207, if_statement; 207, 208; 207, 209; 207, 215; 208, identifier:raise_on_error; 209, block; 209, 210; 210, raise_statement; 210, 211; 211, call; 211, 212; 211, 213; 212, identifier:ValueError; 213, argument_list; 213, 214; 214, identifier:error_message; 215, else_clause; 215, 216; 216, block; 216, 217; 216, 224; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:logging; 221, identifier:warn; 222, argument_list; 222, 223; 223, identifier:error_message; 224, continue_statement; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:alt; 228, attribute; 228, 229; 228, 230; 229, identifier:x; 230, identifier:Tumor_Seq_Allele2; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:variant; 234, call; 234, 235; 234, 236; 235, identifier:Variant; 236, argument_list; 236, 237; 236, 238; 236, 239; 236, 243; 236, 247; 237, identifier:contig; 238, identifier:start_pos; 239, call; 239, 240; 239, 241; 240, identifier:str; 241, argument_list; 241, 242; 242, identifier:ref; 243, call; 243, 244; 243, 245; 244, identifier:str; 245, argument_list; 245, 246; 246, identifier:alt; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:ensembl; 249, identifier:ensembl; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 255; 252, subscript; 252, 253; 252, 254; 253, identifier:metadata; 254, identifier:variant; 255, dictionary; 255, 256; 255, 261; 255, 266; 255, 271; 255, 276; 255, 281; 255, 286; 255, 291; 255, 296; 256, pair; 256, 257; 256, 258; 257, string:'Hugo_Symbol'; 258, attribute; 258, 259; 258, 260; 259, identifier:x; 260, identifier:Hugo_Symbol; 261, pair; 261, 262; 261, 263; 262, string:'Center'; 263, attribute; 263, 264; 263, 265; 264, identifier:x; 265, identifier:Center; 266, pair; 266, 267; 266, 268; 267, string:'Strand'; 268, attribute; 268, 269; 268, 270; 269, identifier:x; 270, identifier:Strand; 271, pair; 271, 272; 271, 273; 272, string:'Variant_Classification'; 273, attribute; 273, 274; 273, 275; 274, identifier:x; 275, identifier:Variant_Classification; 276, pair; 276, 277; 276, 278; 277, string:'Variant_Type'; 278, attribute; 278, 279; 278, 280; 279, identifier:x; 280, identifier:Variant_Type; 281, pair; 281, 282; 281, 283; 282, string:'dbSNP_RS'; 283, attribute; 283, 284; 283, 285; 284, identifier:x; 285, identifier:dbSNP_RS; 286, pair; 286, 287; 286, 288; 287, string:'dbSNP_Val_Status'; 288, attribute; 288, 289; 288, 290; 289, identifier:x; 290, identifier:dbSNP_Val_Status; 291, pair; 291, 292; 291, 293; 292, string:'Tumor_Sample_Barcode'; 293, attribute; 293, 294; 293, 295; 294, identifier:x; 295, identifier:Tumor_Sample_Barcode; 296, pair; 296, 297; 296, 298; 297, string:'Matched_Norm_Sample_Barcode'; 298, attribute; 298, 299; 298, 300; 299, identifier:x; 300, identifier:Matched_Norm_Sample_Barcode; 301, for_statement; 301, 302; 301, 303; 301, 304; 302, identifier:optional_col; 303, identifier:optional_cols; 304, block; 304, 305; 305, if_statement; 305, 306; 305, 309; 306, comparison_operator:in; 306, 307; 306, 308; 307, identifier:optional_col; 308, identifier:x; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 317; 312, subscript; 312, 313; 312, 316; 313, subscript; 313, 314; 313, 315; 314, identifier:metadata; 315, identifier:variant; 316, identifier:optional_col; 317, subscript; 317, 318; 317, 319; 318, identifier:x; 319, identifier:optional_col; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:variants; 324, identifier:append; 325, argument_list; 325, 326; 326, identifier:variant; 327, return_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:VariantCollection; 330, argument_list; 330, 331; 330, 334; 330, 340; 330, 343; 331, keyword_argument; 331, 332; 331, 333; 332, identifier:variants; 333, identifier:variants; 334, keyword_argument; 334, 335; 334, 336; 335, identifier:source_to_metadata_dict; 336, dictionary; 336, 337; 337, pair; 337, 338; 337, 339; 338, identifier:path; 339, identifier:metadata; 340, keyword_argument; 340, 341; 340, 342; 341, identifier:sort_key; 342, identifier:sort_key; 343, keyword_argument; 343, 344; 343, 345; 344, identifier:distinct; 345, identifier:distinct | def load_maf(
path,
optional_cols=[],
sort_key=variant_ascending_position_sort_key,
distinct=True,
raise_on_error=True,
encoding=None):
maf_df = load_maf_dataframe(path, raise_on_error=raise_on_error, encoding=encoding)
if len(maf_df) == 0 and raise_on_error:
raise ValueError("Empty MAF file %s" % path)
ensembl_objects = {}
variants = []
metadata = {}
for _, x in maf_df.iterrows():
contig = x.Chromosome
if isnull(contig):
error_message = "Invalid contig name: %s" % (contig,)
if raise_on_error:
raise ValueError(error_message)
else:
logging.warn(error_message)
continue
start_pos = x.Start_Position
ref = x.Reference_Allele
ncbi_build = x.NCBI_Build
if ncbi_build in ensembl_objects:
ensembl = ensembl_objects[ncbi_build]
else:
if isinstance(ncbi_build, int):
reference_name = "B%d" % ncbi_build
else:
reference_name = str(ncbi_build)
ensembl = infer_genome(reference_name)
ensembl_objects[ncbi_build] = ensembl
if x.Tumor_Seq_Allele1 != ref:
alt = x.Tumor_Seq_Allele1
else:
if x.Tumor_Seq_Allele2 == ref:
error_message = (
"Both tumor alleles agree with reference %s: %s" % (
ref, x,))
if raise_on_error:
raise ValueError(error_message)
else:
logging.warn(error_message)
continue
alt = x.Tumor_Seq_Allele2
variant = Variant(
contig,
start_pos,
str(ref),
str(alt),
ensembl=ensembl)
metadata[variant] = {
'Hugo_Symbol': x.Hugo_Symbol,
'Center': x.Center,
'Strand': x.Strand,
'Variant_Classification': x.Variant_Classification,
'Variant_Type': x.Variant_Type,
'dbSNP_RS': x.dbSNP_RS,
'dbSNP_Val_Status': x.dbSNP_Val_Status,
'Tumor_Sample_Barcode': x.Tumor_Sample_Barcode,
'Matched_Norm_Sample_Barcode': x.Matched_Norm_Sample_Barcode,
}
for optional_col in optional_cols:
if optional_col in x:
metadata[variant][optional_col] = x[optional_col]
variants.append(variant)
return VariantCollection(
variants=variants,
source_to_metadata_dict={path: metadata},
sort_key=sort_key,
distinct=distinct) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 2, function_name:load_vcf; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 25; 3, 28; 3, 31; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:genome; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reference_vcf_key; 10, string:"reference"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:only_passing; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:allow_extended_nucleotides; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:include_info; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:chunk_size; 22, binary_operator:**; 22, 23; 22, 24; 23, integer:10; 24, integer:5; 25, default_parameter; 25, 26; 25, 27; 26, identifier:max_variants; 27, None; 28, default_parameter; 28, 29; 28, 30; 29, identifier:sort_key; 30, identifier:variant_ascending_position_sort_key; 31, default_parameter; 31, 32; 31, 33; 32, identifier:distinct; 33, True; 34, block; 34, 35; 34, 41; 34, 48; 34, 157; 34, 164; 34, 170; 34, 181; 34, 204; 34, 233; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:require_string; 38, argument_list; 38, 39; 38, 40; 39, identifier:path; 40, string:"Path or URL to VCF"; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:parsed_path; 44, call; 44, 45; 44, 46; 45, identifier:parse_url_or_path; 46, argument_list; 46, 47; 47, identifier:path; 48, if_statement; 48, 49; 48, 62; 49, boolean_operator:and; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:parsed_path; 52, identifier:scheme; 53, comparison_operator:!=; 53, 54; 53, 61; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:parsed_path; 58, identifier:scheme; 59, identifier:lower; 60, argument_list; 61, string:"file"; 62, block; 62, 63; 62, 76; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, tuple_pattern; 65, 66; 65, 67; 66, identifier:filename; 67, identifier:headers; 68, call; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:urllib; 72, identifier:request; 73, identifier:urlretrieve; 74, argument_list; 74, 75; 75, identifier:path; 76, try_statement; 76, 77; 76, 140; 77, block; 77, 78; 77, 96; 77, 104; 77, 108; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:new_filename; 81, binary_operator:%; 81, 82; 81, 83; 82, string:"%s.%s"; 83, tuple; 83, 84; 83, 85; 84, identifier:filename; 85, subscript; 85, 86; 85, 94; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:parsed_path; 90, identifier:path; 91, identifier:split; 92, argument_list; 92, 93; 93, string:"."; 94, unary_operator:-; 94, 95; 95, integer:1; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:os; 100, identifier:rename; 101, argument_list; 101, 102; 101, 103; 102, identifier:filename; 103, identifier:new_filename; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:filename; 107, identifier:new_filename; 108, return_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:load_vcf; 111, argument_list; 111, 112; 111, 113; 111, 116; 111, 119; 111, 122; 111, 125; 111, 128; 111, 131; 111, 134; 111, 137; 112, identifier:filename; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:genome; 115, identifier:genome; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:reference_vcf_key; 118, identifier:reference_vcf_key; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:only_passing; 121, identifier:only_passing; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:allow_extended_nucleotides; 124, identifier:allow_extended_nucleotides; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:include_info; 127, identifier:include_info; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:chunk_size; 130, identifier:chunk_size; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:max_variants; 133, identifier:max_variants; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:sort_key; 136, identifier:sort_key; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:distinct; 139, identifier:distinct; 140, finally_clause; 140, 141; 141, block; 141, 142; 141, 150; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:info; 147, argument_list; 147, 148; 147, 149; 148, string:"Removing temporary file: %s"; 149, identifier:filename; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:os; 154, identifier:unlink; 155, argument_list; 155, 156; 156, identifier:filename; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:handle; 160, call; 160, 161; 160, 162; 161, identifier:PyVCFReaderFromPathOrURL; 162, argument_list; 162, 163; 163, identifier:path; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:handle; 168, identifier:close; 169, argument_list; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:genome; 173, call; 173, 174; 173, 175; 174, identifier:infer_genome_from_vcf; 175, argument_list; 175, 176; 175, 177; 175, 180; 176, identifier:genome; 177, attribute; 177, 178; 177, 179; 178, identifier:handle; 179, identifier:vcf_reader; 180, identifier:reference_vcf_key; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:df_iterator; 184, call; 184, 185; 184, 186; 185, identifier:read_vcf_into_dataframe; 186, argument_list; 186, 187; 186, 188; 186, 191; 186, 201; 187, identifier:path; 188, keyword_argument; 188, 189; 188, 190; 189, identifier:include_info; 190, identifier:include_info; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:sample_names; 193, conditional_expression:if; 193, 194; 193, 199; 193, 200; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:handle; 197, identifier:vcf_reader; 198, identifier:samples; 199, identifier:include_info; 200, None; 201, keyword_argument; 201, 202; 201, 203; 202, identifier:chunk_size; 203, identifier:chunk_size; 204, if_statement; 204, 205; 204, 206; 204, 227; 205, identifier:include_info; 206, block; 206, 207; 207, function_definition; 207, 208; 207, 209; 207, 212; 208, function_name:sample_info_parser; 209, parameters; 209, 210; 209, 211; 210, identifier:unparsed_sample_info_strings; 211, identifier:format_string; 212, block; 212, 213; 213, return_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:pyvcf_calls_to_sample_info_list; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 223; 218, attribute; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:handle; 221, identifier:vcf_reader; 222, identifier:_parse_samples; 223, argument_list; 223, 224; 223, 225; 223, 226; 224, identifier:unparsed_sample_info_strings; 225, identifier:format_string; 226, None; 227, else_clause; 227, 228; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:sample_info_parser; 232, None; 233, return_statement; 233, 234; 234, call; 234, 235; 234, 236; 235, identifier:dataframes_to_variant_collection; 236, argument_list; 236, 237; 236, 238; 236, 241; 236, 251; 236, 254; 236, 257; 236, 267; 236, 270; 236, 279; 237, identifier:df_iterator; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:source_path; 240, identifier:path; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:info_parser; 243, conditional_expression:if; 243, 244; 243, 249; 243, 250; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:handle; 247, identifier:vcf_reader; 248, identifier:_parse_info; 249, identifier:include_info; 250, None; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:only_passing; 253, identifier:only_passing; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:max_variants; 256, identifier:max_variants; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:sample_names; 259, conditional_expression:if; 259, 260; 259, 265; 259, 266; 260, attribute; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:handle; 263, identifier:vcf_reader; 264, identifier:samples; 265, identifier:include_info; 266, None; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:sample_info_parser; 269, identifier:sample_info_parser; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:variant_kwargs; 272, dictionary; 272, 273; 272, 276; 273, pair; 273, 274; 273, 275; 274, string:'ensembl'; 275, identifier:genome; 276, pair; 276, 277; 276, 278; 277, string:'allow_extended_nucleotides'; 278, identifier:allow_extended_nucleotides; 279, keyword_argument; 279, 280; 279, 281; 280, identifier:variant_collection_kwargs; 281, dictionary; 281, 282; 281, 285; 282, pair; 282, 283; 282, 284; 283, string:'sort_key'; 284, identifier:sort_key; 285, pair; 285, 286; 285, 287; 286, string:'distinct'; 287, identifier:distinct | def load_vcf(
path,
genome=None,
reference_vcf_key="reference",
only_passing=True,
allow_extended_nucleotides=False,
include_info=True,
chunk_size=10 ** 5,
max_variants=None,
sort_key=variant_ascending_position_sort_key,
distinct=True):
require_string(path, "Path or URL to VCF")
parsed_path = parse_url_or_path(path)
if parsed_path.scheme and parsed_path.scheme.lower() != "file":
(filename, headers) = urllib.request.urlretrieve(path)
try:
new_filename = "%s.%s" % (
filename, parsed_path.path.split(".")[-1])
os.rename(filename, new_filename)
filename = new_filename
return load_vcf(
filename,
genome=genome,
reference_vcf_key=reference_vcf_key,
only_passing=only_passing,
allow_extended_nucleotides=allow_extended_nucleotides,
include_info=include_info,
chunk_size=chunk_size,
max_variants=max_variants,
sort_key=sort_key,
distinct=distinct)
finally:
logger.info("Removing temporary file: %s", filename)
os.unlink(filename)
handle = PyVCFReaderFromPathOrURL(path)
handle.close()
genome = infer_genome_from_vcf(
genome,
handle.vcf_reader,
reference_vcf_key)
df_iterator = read_vcf_into_dataframe(
path,
include_info=include_info,
sample_names=handle.vcf_reader.samples if include_info else None,
chunk_size=chunk_size)
if include_info:
def sample_info_parser(unparsed_sample_info_strings, format_string):
return pyvcf_calls_to_sample_info_list(
handle.vcf_reader._parse_samples(
unparsed_sample_info_strings, format_string, None))
else:
sample_info_parser = None
return dataframes_to_variant_collection(
df_iterator,
source_path=path,
info_parser=handle.vcf_reader._parse_info if include_info else None,
only_passing=only_passing,
max_variants=max_variants,
sample_names=handle.vcf_reader.samples if include_info else None,
sample_info_parser=sample_info_parser,
variant_kwargs={
'ensembl': genome,
'allow_extended_nucleotides': allow_extended_nucleotides},
variant_collection_kwargs={
'sort_key': sort_key,
'distinct': distinct}) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:top_expression_effect; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:expression_levels; 6, block; 6, 7; 6, 16; 6, 26; 6, 44; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:effect_expression_dict; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:effect_expression; 14, argument_list; 14, 15; 15, identifier:expression_levels; 16, if_statement; 16, 17; 16, 23; 17, comparison_operator:==; 17, 18; 17, 22; 18, call; 18, 19; 18, 20; 19, identifier:len; 20, argument_list; 20, 21; 21, identifier:effect_expression_dict; 22, integer:0; 23, block; 23, 24; 24, return_statement; 24, 25; 25, None; 26, function_definition; 26, 27; 26, 28; 26, 30; 27, function_name:key_fn; 28, parameters; 28, 29; 29, identifier:effect_fpkm_pair; 30, block; 30, 31; 30, 37; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, tuple_pattern; 33, 34; 33, 35; 34, identifier:effect; 35, identifier:fpkm; 36, identifier:effect_fpkm_pair; 37, return_statement; 37, 38; 38, tuple; 38, 39; 38, 40; 39, identifier:fpkm; 40, call; 40, 41; 40, 42; 41, identifier:multi_gene_effect_sort_key; 42, argument_list; 42, 43; 43, identifier:effect; 44, return_statement; 44, 45; 45, subscript; 45, 46; 45, 57; 46, call; 46, 47; 46, 48; 47, identifier:max; 48, argument_list; 48, 49; 48, 54; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:effect_expression_dict; 52, identifier:items; 53, argument_list; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:key; 56, identifier:key_fn; 57, integer:0 | def top_expression_effect(self, expression_levels):
effect_expression_dict = self.effect_expression(expression_levels)
if len(effect_expression_dict) == 0:
return None
def key_fn(effect_fpkm_pair):
(effect, fpkm) = effect_fpkm_pair
return (fpkm, multi_gene_effect_sort_key(effect))
return max(effect_expression_dict.items(), key=key_fn)[0] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:callback; 7, None; 8, block; 8, 9; 8, 15; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:items; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:items; 15, if_statement; 15, 16; 15, 17; 15, 31; 16, identifier:callback; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:__class__; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:sorted; 26, argument_list; 26, 27; 26, 28; 27, identifier:items; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:key; 30, identifier:callback; 31, else_clause; 31, 32; 32, block; 32, 33; 33, return_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:__class__; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:sorted; 41, argument_list; 41, 42; 42, identifier:items | def sort(self, callback=None):
items = self.items
if callback:
return self.__class__(sorted(items, key=callback))
else:
return self.__class__(sorted(items)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:scan_for_spec; 3, parameters; 3, 4; 4, identifier:keyword; 5, block; 5, 6; 5, 20; 5, 29; 5, 44; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:keyword; 9, call; 9, 10; 9, 18; 10, attribute; 10, 11; 10, 17; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:keyword; 14, identifier:lstrip; 15, argument_list; 15, 16; 16, string:'('; 17, identifier:rstrip; 18, argument_list; 18, 19; 19, string:')'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:matches; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:release_line_re; 26, identifier:findall; 27, argument_list; 27, 28; 28, identifier:keyword; 29, if_statement; 29, 30; 29, 31; 30, identifier:matches; 31, block; 31, 32; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:Spec; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:">={}"; 39, identifier:format; 40, argument_list; 40, 41; 41, subscript; 41, 42; 41, 43; 42, identifier:matches; 43, integer:0; 44, try_statement; 44, 45; 44, 51; 45, block; 45, 46; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:Spec; 49, argument_list; 49, 50; 50, identifier:keyword; 51, except_clause; 51, 52; 51, 53; 52, identifier:ValueError; 53, block; 53, 54; 54, return_statement; 54, 55; 55, None | def scan_for_spec(keyword):
keyword = keyword.lstrip('(').rstrip(')')
matches = release_line_re.findall(keyword)
if matches:
return Spec(">={}".format(matches[0]))
try:
return Spec(keyword)
except ValueError:
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:get_students; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:gradebook_id; 7, string:''; 8, default_parameter; 8, 9; 8, 10; 9, identifier:simple; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:section_name; 13, string:''; 14, default_parameter; 14, 15; 14, 16; 15, identifier:include_photo; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:include_grade_info; 19, False; 20, default_parameter; 20, 21; 20, 22; 21, identifier:include_grade_history; 22, False; 23, default_parameter; 23, 24; 23, 25; 24, identifier:include_makeup_grades; 25, False; 26, block; 26, 27; 26, 65; 26, 69; 26, 118; 26, 141; 26, 207; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:params; 30, call; 30, 31; 30, 32; 31, identifier:dict; 32, argument_list; 32, 33; 32, 41; 32, 49; 32, 57; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:includePhoto; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:json; 38, identifier:dumps; 39, argument_list; 39, 40; 40, identifier:include_photo; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:includeGradeInfo; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:json; 46, identifier:dumps; 47, argument_list; 47, 48; 48, identifier:include_grade_info; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:includeGradeHistory; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:json; 54, identifier:dumps; 55, argument_list; 55, 56; 56, identifier:include_grade_history; 57, keyword_argument; 57, 58; 57, 59; 58, identifier:includeMakeupGrades; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:json; 62, identifier:dumps; 63, argument_list; 63, 64; 64, identifier:include_makeup_grades; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:url; 68, string:'students/{gradebookId}'; 69, if_statement; 69, 70; 69, 71; 70, identifier:section_name; 71, block; 71, 72; 71, 83; 71, 109; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, pattern_list; 74, 75; 74, 76; 75, identifier:group_id; 76, identifier:_; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:get_section_by_name; 81, argument_list; 81, 82; 82, identifier:section_name; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:group_id; 86, None; 87, block; 87, 88; 87, 97; 87, 104; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:failure_message; 91, parenthesized_expression; 91, 92; 92, binary_operator:%; 92, 93; 92, 96; 93, concatenated_string; 93, 94; 93, 95; 94, string:'in get_students -- Error: '; 95, string:'No such section %s'; 96, identifier:section_name; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:log; 101, identifier:critical; 102, argument_list; 102, 103; 103, identifier:failure_message; 104, raise_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:PyLmodNoSuchSection; 107, argument_list; 107, 108; 108, identifier:failure_message; 109, expression_statement; 109, 110; 110, augmented_assignment:+=; 110, 111; 110, 112; 111, identifier:url; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, string:'/section/{0}'; 115, identifier:format; 116, argument_list; 116, 117; 117, identifier:group_id; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:student_data; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:get; 125, argument_list; 125, 126; 125, 138; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:url; 129, identifier:format; 130, argument_list; 130, 131; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:gradebookId; 133, boolean_operator:or; 133, 134; 133, 135; 134, identifier:gradebook_id; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:gradebook_id; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:params; 140, identifier:params; 141, if_statement; 141, 142; 141, 143; 142, identifier:simple; 143, block; 143, 144; 143, 159; 143, 196; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:student_map; 147, call; 147, 148; 147, 149; 148, identifier:dict; 149, argument_list; 149, 150; 149, 153; 149, 156; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:accountEmail; 152, string:'email'; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:displayName; 155, string:'name'; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:section; 158, string:'section'; 159, function_definition; 159, 160; 159, 161; 159, 163; 160, function_name:remap; 161, parameters; 161, 162; 162, identifier:students; 163, block; 163, 164; 163, 180; 163, 194; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:newx; 167, call; 167, 168; 167, 169; 168, identifier:dict; 169, generator_expression; 169, 170; 169, 177; 170, tuple; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:student_map; 173, identifier:k; 174, subscript; 174, 175; 174, 176; 175, identifier:students; 176, identifier:k; 177, for_in_clause; 177, 178; 177, 179; 178, identifier:k; 179, identifier:student_map; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:newx; 184, string:'email'; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:newx; 189, string:'email'; 190, identifier:replace; 191, argument_list; 191, 192; 191, 193; 192, string:'@mit.edu'; 193, string:'@MIT.EDU'; 194, return_statement; 194, 195; 195, identifier:newx; 196, return_statement; 196, 197; 197, list_comprehension; 197, 198; 197, 202; 198, call; 198, 199; 198, 200; 199, identifier:remap; 200, argument_list; 200, 201; 201, identifier:x; 202, for_in_clause; 202, 203; 202, 204; 203, identifier:x; 204, subscript; 204, 205; 204, 206; 205, identifier:student_data; 206, string:'data'; 207, return_statement; 207, 208; 208, subscript; 208, 209; 208, 210; 209, identifier:student_data; 210, string:'data' | def get_students(
self,
gradebook_id='',
simple=False,
section_name='',
include_photo=False,
include_grade_info=False,
include_grade_history=False,
include_makeup_grades=False
):
params = dict(
includePhoto=json.dumps(include_photo),
includeGradeInfo=json.dumps(include_grade_info),
includeGradeHistory=json.dumps(include_grade_history),
includeMakeupGrades=json.dumps(include_makeup_grades),
)
url = 'students/{gradebookId}'
if section_name:
group_id, _ = self.get_section_by_name(section_name)
if group_id is None:
failure_message = (
'in get_students -- Error: '
'No such section %s' % section_name
)
log.critical(failure_message)
raise PyLmodNoSuchSection(failure_message)
url += '/section/{0}'.format(group_id)
student_data = self.get(
url.format(
gradebookId=gradebook_id or self.gradebook_id
),
params=params,
)
if simple:
student_map = dict(
accountEmail='email',
displayName='name',
section='section'
)
def remap(students):
newx = dict((student_map[k], students[k]) for k in student_map)
newx['email'] = newx['email'].replace('@mit.edu', '@MIT.EDU')
return newx
return [remap(x) for x in student_data['data']]
return student_data['data'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_staff; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:gradebook_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:simple; 8, False; 9, block; 9, 10; 9, 33; 9, 81; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:staff_data; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:get; 17, argument_list; 17, 18; 17, 30; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, string:'staff/{gradebookId}'; 21, identifier:format; 22, argument_list; 22, 23; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:gradebookId; 25, boolean_operator:or; 25, 26; 25, 27; 26, identifier:gradebook_id; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:gradebook_id; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:params; 32, None; 33, if_statement; 33, 34; 33, 35; 34, identifier:simple; 35, block; 35, 36; 35, 40; 35, 49; 35, 79; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:simple_list; 39, list:[]; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:unraveled_list; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:unravel_staff; 47, argument_list; 47, 48; 48, identifier:staff_data; 49, for_statement; 49, 50; 49, 51; 49, 56; 50, identifier:member; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:unraveled_list; 54, identifier:__iter__; 55, argument_list; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:simple_list; 61, identifier:append; 62, argument_list; 62, 63; 63, dictionary; 63, 64; 63, 69; 63, 74; 64, pair; 64, 65; 64, 66; 65, string:'accountEmail'; 66, subscript; 66, 67; 66, 68; 67, identifier:member; 68, string:'accountEmail'; 69, pair; 69, 70; 69, 71; 70, string:'displayName'; 71, subscript; 71, 72; 71, 73; 72, identifier:member; 73, string:'displayName'; 74, pair; 74, 75; 74, 76; 75, string:'role'; 76, subscript; 76, 77; 76, 78; 77, identifier:member; 78, string:'role'; 79, return_statement; 79, 80; 80, identifier:simple_list; 81, return_statement; 81, 82; 82, subscript; 82, 83; 82, 84; 83, identifier:staff_data; 84, string:'data' | def get_staff(self, gradebook_id, simple=False):
staff_data = self.get(
'staff/{gradebookId}'.format(
gradebookId=gradebook_id or self.gradebook_id
),
params=None,
)
if simple:
simple_list = []
unraveled_list = self.unravel_staff(staff_data)
for member in unraveled_list.__iter__():
simple_list.append({
'accountEmail': member['accountEmail'],
'displayName': member['displayName'],
'role': member['role'],
})
return simple_list
return staff_data['data'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_course_guide_staff; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:course_id; 7, string:''; 8, block; 8, 9; 8, 32; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:staff_data; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:get; 16, argument_list; 16, 17; 16, 29; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, string:'courseguide/course/{courseId}/staff'; 20, identifier:format; 21, argument_list; 21, 22; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:courseId; 24, boolean_operator:or; 24, 25; 24, 26; 25, identifier:course_id; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:course_id; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:params; 31, None; 32, return_statement; 32, 33; 33, subscript; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:staff_data; 36, string:'response'; 37, string:'docs' | def get_course_guide_staff(self, course_id=''):
staff_data = self.get(
'courseguide/course/{courseId}/staff'.format(
courseId=course_id or self.course_id
),
params=None
)
return staff_data['response']['docs'] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:optimize; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:self; 5, identifier:problem; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_iterations; 8, integer:100; 9, default_parameter; 9, 10; 9, 11; 10, identifier:max_seconds; 11, call; 11, 12; 11, 13; 12, identifier:float; 13, argument_list; 13, 14; 14, string:'inf'; 15, default_parameter; 15, 16; 15, 17; 16, identifier:cache_encoded; 17, True; 18, default_parameter; 18, 19; 18, 20; 19, identifier:cache_solution; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:clear_cache; 23, True; 24, default_parameter; 24, 25; 24, 26; 25, identifier:logging_func; 26, identifier:_print_fitnesses; 27, default_parameter; 27, 28; 27, 29; 28, identifier:n_processes; 29, integer:0; 30, block; 30, 31; 30, 44; 30, 76; 30, 82; 30, 88; 30, 98; 30, 106; 30, 319; 31, if_statement; 31, 32; 31, 38; 32, not_operator; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:isinstance; 35, argument_list; 35, 36; 35, 37; 36, identifier:problem; 37, identifier:Problem; 38, block; 38, 39; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:TypeError; 42, argument_list; 42, 43; 43, string:'problem must be an instance of Problem class'; 44, if_statement; 44, 45; 44, 48; 44, 70; 45, comparison_operator:>; 45, 46; 45, 47; 46, identifier:n_processes; 47, integer:0; 48, block; 48, 49; 49, try_statement; 49, 50; 49, 62; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:pool; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:multiprocessing; 57, identifier:Pool; 58, argument_list; 58, 59; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:processes; 61, identifier:n_processes; 62, except_clause; 62, 63; 62, 64; 63, identifier:NameError; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:ImportError; 68, argument_list; 68, 69; 69, string:'pickle, dill, or multiprocessing library is not available.'; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:pool; 75, None; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:__max_iterations; 81, identifier:max_iterations; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_reset; 87, argument_list; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:best_solution; 91, dictionary; 91, 92; 91, 95; 92, pair; 92, 93; 92, 94; 93, string:'solution'; 94, None; 95, pair; 95, 96; 95, 97; 96, string:'fitness'; 97, None; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:population; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:initial_population; 105, argument_list; 106, try_statement; 106, 107; 106, 265; 107, block; 107, 108; 107, 116; 107, 249; 107, 257; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:start; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:time; 114, identifier:clock; 115, argument_list; 116, for_statement; 116, 117; 116, 120; 116, 126; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:iteration; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:itertools; 123, identifier:count; 124, argument_list; 124, 125; 125, integer:1; 126, block; 126, 127; 126, 149; 126, 169; 126, 190; 126, 209; 126, 219; 126, 231; 126, 239; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 133; 129, pattern_list; 129, 130; 129, 131; 129, 132; 130, identifier:solutions; 131, identifier:fitnesses; 132, identifier:finished; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:_get_fitnesses; 137, argument_list; 137, 138; 137, 139; 137, 140; 137, 143; 137, 146; 138, identifier:problem; 139, identifier:population; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:cache_encoded; 142, identifier:cache_encoded; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:cache_solution; 145, identifier:cache_solution; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:pool; 148, identifier:pool; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, pattern_list; 151, 152; 151, 153; 152, identifier:best_index; 153, identifier:best_fitness; 154, call; 154, 155; 154, 156; 155, identifier:max; 156, argument_list; 156, 157; 156, 161; 157, call; 157, 158; 157, 159; 158, identifier:enumerate; 159, argument_list; 159, 160; 160, identifier:fitnesses; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:key; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:operator; 166, identifier:itemgetter; 167, argument_list; 167, 168; 168, integer:1; 169, if_statement; 169, 170; 169, 175; 170, comparison_operator:>; 170, 171; 170, 172; 171, identifier:best_fitness; 172, subscript; 172, 173; 172, 174; 173, identifier:best_solution; 174, string:'fitness'; 175, block; 175, 176; 175, 182; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:best_solution; 180, string:'fitness'; 181, identifier:best_fitness; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:best_solution; 186, string:'solution'; 187, subscript; 187, 188; 187, 189; 188, identifier:solutions; 189, identifier:best_index; 190, if_statement; 190, 191; 190, 192; 191, identifier:logging_func; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 196; 195, identifier:logging_func; 196, argument_list; 196, 197; 196, 200; 196, 201; 196, 202; 196, 203; 196, 206; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:iteration; 200, identifier:population; 201, identifier:solutions; 202, identifier:fitnesses; 203, subscript; 203, 204; 203, 205; 204, identifier:best_solution; 205, string:'solution'; 206, subscript; 206, 207; 206, 208; 207, identifier:best_solution; 208, string:'fitness'; 209, if_statement; 209, 210; 209, 211; 210, identifier:finished; 211, block; 211, 212; 211, 218; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:solution_found; 217, True; 218, break_statement; 219, if_statement; 219, 220; 219, 229; 220, comparison_operator:>=; 220, 221; 220, 228; 221, binary_operator:-; 221, 222; 221, 227; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:time; 225, identifier:clock; 226, argument_list; 227, identifier:start; 228, identifier:max_seconds; 229, block; 229, 230; 230, break_statement; 231, if_statement; 231, 232; 231, 237; 232, comparison_operator:>=; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:iteration; 236, identifier:max_iterations; 237, block; 237, 238; 238, break_statement; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:population; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:next_population; 246, argument_list; 246, 247; 246, 248; 247, identifier:population; 248, identifier:fitnesses; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:best_solution; 254, subscript; 254, 255; 254, 256; 255, identifier:best_solution; 256, string:'solution'; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:best_fitness; 262, subscript; 262, 263; 262, 264; 263, identifier:best_solution; 264, string:'fitness'; 265, finally_clause; 265, 266; 266, block; 266, 267; 266, 298; 267, if_statement; 267, 268; 267, 269; 268, identifier:clear_cache; 269, block; 269, 270; 269, 276; 269, 282; 269, 290; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:__encoded_cache; 275, dictionary; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:__solution_cache; 281, dictionary; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:self; 286, identifier:_get_encoded_key; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:_get_encoded_key_type; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:_get_solution_key; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:_get_solution_key_type; 298, try_statement; 298, 299; 298, 312; 299, block; 299, 300; 299, 306; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:pool; 304, identifier:terminate; 305, argument_list; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:pool; 310, identifier:close; 311, argument_list; 312, except_clause; 312, 313; 312, 314; 313, identifier:AttributeError; 314, block; 314, 315; 315, assert_statement; 315, 316; 316, comparison_operator:is; 316, 317; 316, 318; 317, identifier:pool; 318, None; 319, return_statement; 319, 320; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:best_solution | def optimize(self, problem, max_iterations=100, max_seconds=float('inf'),
cache_encoded=True, cache_solution=False, clear_cache=True,
logging_func=_print_fitnesses,
n_processes=0):
if not isinstance(problem, Problem):
raise TypeError('problem must be an instance of Problem class')
if n_processes > 0:
try:
pool = multiprocessing.Pool(processes=n_processes)
except NameError:
raise ImportError(
'pickle, dill, or multiprocessing library is not available.'
)
else:
pool = None
self.__max_iterations = max_iterations
self._reset()
best_solution = {'solution': None, 'fitness': None}
population = self.initial_population()
try:
start = time.clock()
for self.iteration in itertools.count(1):
solutions, fitnesses, finished = self._get_fitnesses(
problem,
population,
cache_encoded=cache_encoded,
cache_solution=cache_solution,
pool=pool)
best_index, best_fitness = max(
enumerate(fitnesses), key=operator.itemgetter(1))
if best_fitness > best_solution['fitness']:
best_solution['fitness'] = best_fitness
best_solution['solution'] = solutions[best_index]
if logging_func:
logging_func(self.iteration, population, solutions,
fitnesses, best_solution['solution'],
best_solution['fitness'])
if finished:
self.solution_found = True
break
if time.clock() - start >= max_seconds:
break
if self.iteration >= max_iterations:
break
population = self.next_population(population, fitnesses)
self.best_solution = best_solution['solution']
self.best_fitness = best_solution['fitness']
finally:
if clear_cache:
self.__encoded_cache = {}
self.__solution_cache = {}
self._get_encoded_key = self._get_encoded_key_type
self._get_solution_key = self._get_solution_key_type
try:
pool.terminate()
pool.close()
except AttributeError:
assert pool is None
return self.best_solution |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:inspect; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 23; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:inspector; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:stix2patterns; 13, identifier:inspector; 14, identifier:InspectionListener; 15, argument_list; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:walk; 21, argument_list; 21, 22; 22, identifier:inspector; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:inspector; 27, identifier:pattern_data; 28, argument_list | def inspect(self):
inspector = stix2patterns.inspector.InspectionListener()
self.walk(inspector)
return inspector.pattern_data() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:best_kmers; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 4, identifier:dt; 5, identifier:response; 6, identifier:sequence; 7, default_parameter; 7, 8; 7, 9; 8, identifier:k; 9, integer:6; 10, default_parameter; 10, 11; 10, 12; 11, identifier:consider_shift; 12, True; 13, default_parameter; 13, 14; 13, 15; 14, identifier:n_cores; 15, integer:1; 16, default_parameter; 16, 17; 16, 18; 17, identifier:seq_align; 18, string:"start"; 19, default_parameter; 19, 20; 19, 21; 20, identifier:trim_seq_len; 21, None; 22, block; 22, 23; 22, 29; 22, 35; 22, 67; 22, 75; 22, 82; 22, 97; 22, 105; 22, 123; 22, 297; 22, 308; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:y; 26, subscript; 26, 27; 26, 28; 27, identifier:dt; 28, identifier:response; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:seq; 32, subscript; 32, 33; 32, 34; 33, identifier:dt; 34, identifier:sequence; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:trim_seq_len; 38, None; 39, block; 39, 40; 39, 53; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:seq; 43, call; 43, 44; 43, 45; 44, identifier:pad_sequences; 45, argument_list; 45, 46; 45, 47; 45, 50; 46, identifier:seq; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:align; 49, identifier:seq_align; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:maxlen; 52, identifier:trim_seq_len; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:seq; 56, list_comprehension; 56, 57; 56, 64; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:s; 60, identifier:replace; 61, argument_list; 61, 62; 61, 63; 62, string:"N"; 63, string:""; 64, for_in_clause; 64, 65; 64, 66; 65, identifier:s; 66, identifier:seq; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:dt_kmer; 70, call; 70, 71; 70, 72; 71, identifier:kmer_count; 72, argument_list; 72, 73; 72, 74; 73, identifier:seq; 74, identifier:k; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:Xsp; 78, call; 78, 79; 78, 80; 79, identifier:csc_matrix; 80, argument_list; 80, 81; 81, identifier:dt_kmer; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:en; 85, call; 85, 86; 85, 87; 86, identifier:ElasticNet; 87, argument_list; 87, 88; 87, 91; 87, 94; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:alpha; 90, integer:1; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:standardize; 93, False; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:n_splits; 96, integer:3; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:en; 101, identifier:fit; 102, argument_list; 102, 103; 102, 104; 103, identifier:Xsp; 104, identifier:y; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:nonzero_kmers; 108, call; 108, 109; 108, 122; 109, attribute; 109, 110; 109, 121; 110, subscript; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:dt_kmer; 114, identifier:columns; 115, identifier:values; 116, comparison_operator:!=; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:en; 119, identifier:coef_; 120, integer:0; 121, identifier:tolist; 122, argument_list; 123, function_definition; 123, 124; 123, 125; 123, 133; 124, function_name:find_next_best; 125, parameters; 125, 126; 125, 127; 125, 128; 125, 129; 125, 130; 126, identifier:dt_kmer; 127, identifier:y; 128, identifier:selected_kmers; 129, identifier:to_be_selected_kmers; 130, default_parameter; 130, 131; 130, 132; 131, identifier:consider_shift; 132, True; 133, block; 133, 134; 133, 146; 133, 159; 133, 166; 133, 232; 133, 247; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, pattern_list; 136, 137; 136, 138; 137, identifier:F; 138, identifier:pval; 139, call; 139, 140; 139, 141; 140, identifier:f_regression; 141, argument_list; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:dt_kmer; 144, identifier:to_be_selected_kmers; 145, identifier:y; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:kmer; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:to_be_selected_kmers; 152, identifier:pop; 153, argument_list; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:pval; 157, identifier:argmin; 158, argument_list; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:selected_kmers; 163, identifier:append; 164, argument_list; 164, 165; 165, identifier:kmer; 166, function_definition; 166, 167; 166, 168; 166, 174; 167, function_name:select_criterion; 168, parameters; 168, 169; 168, 170; 168, 171; 169, identifier:s1; 170, identifier:s2; 171, default_parameter; 171, 172; 171, 173; 172, identifier:consider_shift; 173, True; 174, block; 174, 175; 174, 186; 174, 208; 174, 230; 175, if_statement; 175, 176; 175, 183; 176, comparison_operator:<=; 176, 177; 176, 182; 177, call; 177, 178; 177, 179; 178, identifier:hamming_distance; 179, argument_list; 179, 180; 179, 181; 180, identifier:s1; 181, identifier:s2; 182, integer:1; 183, block; 183, 184; 184, return_statement; 184, 185; 185, False; 186, if_statement; 186, 187; 186, 205; 187, boolean_operator:and; 187, 188; 187, 189; 188, identifier:consider_shift; 189, comparison_operator:==; 189, 190; 189, 204; 190, call; 190, 191; 190, 192; 191, identifier:hamming_distance; 192, argument_list; 192, 193; 192, 198; 193, subscript; 193, 194; 193, 195; 194, identifier:s1; 195, slice; 195, 196; 195, 197; 196, integer:1; 197, colon; 198, subscript; 198, 199; 198, 200; 199, identifier:s2; 200, slice; 200, 201; 200, 202; 201, colon; 202, unary_operator:-; 202, 203; 203, integer:1; 204, integer:0; 205, block; 205, 206; 206, return_statement; 206, 207; 207, False; 208, if_statement; 208, 209; 208, 227; 209, boolean_operator:and; 209, 210; 209, 211; 210, identifier:consider_shift; 211, comparison_operator:==; 211, 212; 211, 226; 212, call; 212, 213; 212, 214; 213, identifier:hamming_distance; 214, argument_list; 214, 215; 214, 221; 215, subscript; 215, 216; 215, 217; 216, identifier:s1; 217, slice; 217, 218; 217, 219; 218, colon; 219, unary_operator:-; 219, 220; 220, integer:1; 221, subscript; 221, 222; 221, 223; 222, identifier:s2; 223, slice; 223, 224; 223, 225; 224, integer:1; 225, colon; 226, integer:0; 227, block; 227, 228; 228, return_statement; 228, 229; 229, False; 230, return_statement; 230, 231; 231, True; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:to_be_selected_kmers; 235, list_comprehension; 235, 236; 235, 237; 235, 240; 236, identifier:ckmer; 237, for_in_clause; 237, 238; 237, 239; 238, identifier:ckmer; 239, identifier:to_be_selected_kmers; 240, if_clause; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:select_criterion; 243, argument_list; 243, 244; 243, 245; 243, 246; 244, identifier:ckmer; 245, identifier:kmer; 246, identifier:consider_shift; 247, if_statement; 247, 248; 247, 254; 247, 257; 248, comparison_operator:==; 248, 249; 248, 253; 249, call; 249, 250; 249, 251; 250, identifier:len; 251, argument_list; 251, 252; 252, identifier:to_be_selected_kmers; 253, integer:0; 254, block; 254, 255; 255, return_statement; 255, 256; 256, identifier:selected_kmers; 257, else_clause; 257, 258; 258, block; 258, 259; 258, 265; 258, 275; 258, 288; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:lm; 262, call; 262, 263; 262, 264; 263, identifier:LinearRegression; 264, argument_list; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:lm; 269, identifier:fit; 270, argument_list; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:dt_kmer; 273, identifier:selected_kmers; 274, identifier:y; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:y_new; 278, binary_operator:-; 278, 279; 278, 280; 279, identifier:y; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:lm; 283, identifier:predict; 284, argument_list; 284, 285; 285, subscript; 285, 286; 285, 287; 286, identifier:dt_kmer; 287, identifier:selected_kmers; 288, return_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:find_next_best; 291, argument_list; 291, 292; 291, 293; 291, 294; 291, 295; 291, 296; 292, identifier:dt_kmer; 293, identifier:y_new; 294, identifier:selected_kmers; 295, identifier:to_be_selected_kmers; 296, identifier:consider_shift; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:selected_kmers; 300, call; 300, 301; 300, 302; 301, identifier:find_next_best; 302, argument_list; 302, 303; 302, 304; 302, 305; 302, 306; 302, 307; 303, identifier:dt_kmer; 304, identifier:y; 305, list:[]; 306, identifier:nonzero_kmers; 307, identifier:consider_shift; 308, return_statement; 308, 309; 309, identifier:selected_kmers | def best_kmers(dt, response, sequence, k=6, consider_shift=True, n_cores=1,
seq_align="start", trim_seq_len=None):
y = dt[response]
seq = dt[sequence]
if trim_seq_len is not None:
seq = pad_sequences(seq, align=seq_align, maxlen=trim_seq_len)
seq = [s.replace("N", "") for s in seq]
dt_kmer = kmer_count(seq, k)
Xsp = csc_matrix(dt_kmer)
en = ElasticNet(alpha=1, standardize=False, n_splits=3)
en.fit(Xsp, y)
nonzero_kmers = dt_kmer.columns.values[en.coef_ != 0].tolist()
def find_next_best(dt_kmer, y, selected_kmers, to_be_selected_kmers, consider_shift=True):
F, pval = f_regression(dt_kmer[to_be_selected_kmers], y)
kmer = to_be_selected_kmers.pop(pval.argmin())
selected_kmers.append(kmer)
def select_criterion(s1, s2, consider_shift=True):
if hamming_distance(s1, s2) <= 1:
return False
if consider_shift and hamming_distance(s1[1:], s2[:-1]) == 0:
return False
if consider_shift and hamming_distance(s1[:-1], s2[1:]) == 0:
return False
return True
to_be_selected_kmers = [ckmer for ckmer in to_be_selected_kmers
if select_criterion(ckmer, kmer, consider_shift)]
if len(to_be_selected_kmers) == 0:
return selected_kmers
else:
lm = LinearRegression()
lm.fit(dt_kmer[selected_kmers], y)
y_new = y - lm.predict(dt_kmer[selected_kmers])
return find_next_best(dt_kmer, y_new, selected_kmers, to_be_selected_kmers, consider_shift)
selected_kmers = find_next_best(dt_kmer, y, [], nonzero_kmers, consider_shift)
return selected_kmers |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_custom_rdd_reduce; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:reduce_func; 6, block; 6, 7; 6, 47; 6, 62; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:accumulating_iter; 9, parameters; 9, 10; 10, identifier:iterator; 11, block; 11, 12; 11, 16; 11, 39; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:acc; 15, None; 16, for_statement; 16, 17; 16, 18; 16, 19; 17, identifier:obj; 18, identifier:iterator; 19, block; 19, 20; 20, if_statement; 20, 21; 20, 24; 20, 29; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:acc; 23, None; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:acc; 28, identifier:obj; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:acc; 34, call; 34, 35; 34, 36; 35, identifier:reduce_func; 36, argument_list; 36, 37; 36, 38; 37, identifier:acc; 38, identifier:obj; 39, if_statement; 39, 40; 39, 43; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:acc; 42, None; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, yield; 45, 46; 46, identifier:acc; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:vals; 50, call; 50, 51; 50, 61; 51, attribute; 51, 52; 51, 60; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_rdd; 57, identifier:mapPartitions; 58, argument_list; 58, 59; 59, identifier:accumulating_iter; 60, identifier:collect; 61, argument_list; 62, return_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:reduce; 65, argument_list; 65, 66; 65, 67; 66, identifier:accumulating_iter; 67, identifier:vals | def _custom_rdd_reduce(self, reduce_func):
def accumulating_iter(iterator):
acc = None
for obj in iterator:
if acc is None:
acc = obj
else:
acc = reduce_func(acc, obj)
if acc is not None:
yield acc
vals = self._rdd.mapPartitions(accumulating_iter).collect()
return reduce(accumulating_iter, vals) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:__sort_analyses; 3, parameters; 3, 4; 4, identifier:sentence; 5, block; 5, 6; 5, 8; 5, 64; 6, expression_statement; 6, 7; 7, string:''' Sorts analysis of all the words in the sentence.
This is required for consistency, because by default, analyses are
listed in arbitrary order; '''; 8, for_statement; 8, 9; 8, 10; 8, 11; 9, identifier:word; 10, identifier:sentence; 11, block; 11, 12; 12, if_statement; 12, 13; 12, 16; 12, 27; 13, comparison_operator:not; 13, 14; 13, 15; 14, identifier:ANALYSIS; 15, identifier:word; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:Exception; 20, argument_list; 20, 21; 21, binary_operator:+; 21, 22; 21, 23; 22, string:'(!) Error: no analysis found from word: '; 23, call; 23, 24; 23, 25; 24, identifier:str; 25, argument_list; 25, 26; 26, identifier:word; 27, else_clause; 27, 28; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:word; 33, identifier:ANALYSIS; 34, call; 34, 35; 34, 36; 35, identifier:sorted; 36, argument_list; 36, 37; 36, 40; 36, 41; 37, subscript; 37, 38; 37, 39; 38, identifier:word; 39, identifier:ANALYSIS; 40, line_continuation:\; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:key; 43, lambda; 43, 44; 43, 46; 44, lambda_parameters; 44, 45; 45, identifier:x; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, string:"_"; 49, identifier:join; 50, argument_list; 50, 51; 51, list:[x[ROOT],x[POSTAG],x[FORM],x[CLITIC]]; 51, 52; 51, 55; 51, 58; 51, 61; 52, subscript; 52, 53; 52, 54; 53, identifier:x; 54, identifier:ROOT; 55, subscript; 55, 56; 55, 57; 56, identifier:x; 57, identifier:POSTAG; 58, subscript; 58, 59; 58, 60; 59, identifier:x; 60, identifier:FORM; 61, subscript; 61, 62; 61, 63; 62, identifier:x; 63, identifier:CLITIC; 64, return_statement; 64, 65; 65, identifier:sentence | def __sort_analyses(sentence):
''' Sorts analysis of all the words in the sentence.
This is required for consistency, because by default, analyses are
listed in arbitrary order; '''
for word in sentence:
if ANALYSIS not in word:
raise Exception( '(!) Error: no analysis found from word: '+str(word) )
else:
word[ANALYSIS] = sorted(word[ANALYSIS], \
key=lambda x : "_".join( [x[ROOT],x[POSTAG],x[FORM],x[CLITIC]] ))
return sentence |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:tag; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:text; 6, block; 6, 7; 6, 43; 6, 52; 6, 82; 7, if_statement; 7, 8; 7, 13; 7, 25; 8, comparison_operator:==; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:search_method; 12, string:'ahocorasick'; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:events; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_find_keywords_ahocorasick; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:text; 24, identifier:text; 25, elif_clause; 25, 26; 25, 31; 26, comparison_operator:==; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:search_method; 30, string:'naive'; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:events; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_find_keywords_naive; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:text; 42, identifier:text; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:events; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_resolve_conflicts; 50, argument_list; 50, 51; 51, identifier:events; 52, if_statement; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:mapping; 56, block; 56, 57; 57, for_statement; 57, 58; 57, 59; 57, 60; 58, identifier:item; 59, identifier:events; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:item; 65, string:'type'; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:map; 70, subscript; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:text; 73, identifier:text; 74, slice; 74, 75; 74, 78; 74, 79; 75, subscript; 75, 76; 75, 77; 76, identifier:item; 77, string:'start'; 78, colon; 79, subscript; 79, 80; 79, 81; 80, identifier:item; 81, string:'end'; 82, if_statement; 82, 83; 82, 86; 82, 89; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:return_layer; 86, block; 86, 87; 87, return_statement; 87, 88; 88, identifier:events; 89, else_clause; 89, 90; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 95; 94, identifier:text; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:layer_name; 98, identifier:events | def tag(self, text):
if self.search_method == 'ahocorasick':
events = self._find_keywords_ahocorasick(text.text)
elif self.search_method == 'naive':
events = self._find_keywords_naive(text.text)
events = self._resolve_conflicts(events)
if self.mapping:
for item in events:
item['type'] = self.map[
text.text[item['start']:item['end']]
]
if self.return_layer:
return events
else:
text[self.layer_name] = events |
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:cls; 5, identifier:term; 6, default_parameter; 6, 7; 6, 8; 7, identifier:fields; 8, tuple; 9, block; 9, 10; 9, 31; 9, 43; 9, 51; 9, 62; 9, 74; 9, 78; 9, 82; 9, 147; 9, 162; 9, 172; 10, if_statement; 10, 11; 10, 22; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:any; 14, argument_list; 14, 15; 15, tuple; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:cls; 19, identifier:_meta; 20, identifier:search_fields; 21, identifier:fields; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:AttributeError; 26, argument_list; 26, 27; 27, concatenated_string; 27, 28; 27, 29; 27, 30; 28, string:"A list of searchable fields must be provided in the class's "; 29, string:"search_fields or provided to this function in the `fields` "; 30, string:"kwarg."; 31, if_statement; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:fields; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:fields; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:cls; 41, identifier:_meta; 42, identifier:search_fields; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:query; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:cls; 49, identifier:select; 50, argument_list; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:like_term; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, string:''; 57, identifier:join; 58, argument_list; 58, 59; 59, tuple; 59, 60; 59, 61; 60, identifier:term; 61, string:'%'; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:full_like_term; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, string:''; 68, identifier:join; 69, argument_list; 69, 70; 70, tuple; 70, 71; 70, 72; 70, 73; 71, string:'%'; 72, identifier:term; 73, string:'%'; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:order_by; 77, list:[]; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:clauses; 81, list:[]; 82, for_statement; 82, 83; 82, 84; 82, 85; 83, identifier:field_name; 84, identifier:fields; 85, block; 85, 86; 85, 94; 85, 114; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:field; 89, call; 89, 90; 89, 91; 90, identifier:getattr; 91, argument_list; 91, 92; 91, 93; 92, identifier:cls; 93, identifier:field_name; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:clauses; 98, identifier:append; 99, argument_list; 99, 100; 100, binary_operator:|; 100, 101; 100, 110; 101, binary_operator:|; 101, 102; 101, 106; 102, parenthesized_expression; 102, 103; 103, comparison_operator:==; 103, 104; 103, 105; 104, identifier:field; 105, identifier:term; 106, parenthesized_expression; 106, 107; 107, binary_operator:**; 107, 108; 107, 109; 108, identifier:field; 109, identifier:like_term; 110, parenthesized_expression; 110, 111; 111, binary_operator:**; 111, 112; 111, 113; 112, identifier:field; 113, identifier:full_like_term; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:order_by; 118, identifier:append; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 146; 121, attribute; 121, 122; 121, 145; 122, call; 122, 123; 122, 124; 123, identifier:case; 124, argument_list; 124, 125; 124, 126; 124, 142; 125, None; 126, tuple; 126, 127; 126, 132; 126, 137; 127, tuple; 127, 128; 127, 131; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:field; 130, identifier:term; 131, integer:0; 132, tuple; 132, 133; 132, 136; 133, binary_operator:**; 133, 134; 133, 135; 134, identifier:field; 135, identifier:like_term; 136, integer:1; 137, tuple; 137, 138; 137, 141; 138, binary_operator:**; 138, 139; 138, 140; 139, identifier:field; 140, identifier:full_like_term; 141, integer:2; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:default; 144, integer:3; 145, identifier:asc; 146, argument_list; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:query; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:query; 153, identifier:where; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:reduce; 157, argument_list; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:operator; 160, identifier:or_; 161, identifier:clauses; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:query; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:query; 168, identifier:order_by; 169, argument_list; 169, 170; 170, list_splat; 170, 171; 171, identifier:order_by; 172, return_statement; 172, 173; 173, identifier:query | def search(cls, term, fields=()):
if not any((cls._meta.search_fields, fields)):
raise AttributeError(
"A list of searchable fields must be provided in the class's "
"search_fields or provided to this function in the `fields` "
"kwarg."
)
if not fields:
fields = cls._meta.search_fields
query = cls.select()
like_term = ''.join((term, '%'))
full_like_term = ''.join(('%', term, '%'))
order_by = []
clauses = []
for field_name in fields:
field = getattr(cls, field_name)
clauses.append(
(field == term) |
(field ** like_term) |
(field ** full_like_term)
)
order_by.append(case(None, (
(field == term, 0),
(field ** like_term, 1),
(field ** full_like_term, 2),
), default=3).asc())
query = query.where(reduce(operator.or_, clauses))
query = query.order_by(*order_by)
return query |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:dependency_sort; 3, parameters; 3, 4; 4, identifier:dependency_tree; 5, block; 5, 6; 5, 10; 5, 16; 5, 35; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sorted; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:processed; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 16, for_statement; 16, 17; 16, 20; 16, 25; 17, pattern_list; 17, 18; 17, 19; 18, identifier:key; 19, identifier:deps; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:dependency_tree; 23, identifier:iteritems; 24, argument_list; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:_sort_r; 29, argument_list; 29, 30; 29, 31; 29, 32; 29, 33; 29, 34; 30, identifier:sorted; 31, identifier:processed; 32, identifier:key; 33, identifier:deps; 34, identifier:dependency_tree; 35, return_statement; 35, 36; 36, identifier:sorted | def dependency_sort(dependency_tree):
sorted = []
processed = set()
for key, deps in dependency_tree.iteritems():
_sort_r(sorted, processed, key, deps, dependency_tree)
return sorted |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_sort_r; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:sorted; 5, identifier:processed; 6, identifier:key; 7, identifier:deps; 8, identifier:dependency_tree; 9, block; 9, 10; 9, 16; 9, 23; 9, 62; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:in; 11, 12; 11, 13; 12, identifier:key; 13, identifier:processed; 14, block; 14, 15; 15, return_statement; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:processed; 20, identifier:add; 21, argument_list; 21, 22; 22, identifier:key; 23, for_statement; 23, 24; 23, 25; 23, 26; 24, identifier:dep_key; 25, identifier:deps; 26, block; 26, 27; 26, 36; 26, 53; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:dep_deps; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:dependency_tree; 33, identifier:get; 34, argument_list; 34, 35; 35, identifier:dep_key; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:dep_deps; 39, None; 40, block; 40, 41; 40, 52; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:log; 45, identifier:debug; 46, argument_list; 46, 47; 46, 48; 47, string:'"%s" not found, skipped'; 48, call; 48, 49; 48, 50; 49, identifier:Repr; 50, argument_list; 50, 51; 51, identifier:dep_key; 52, continue_statement; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:_sort_r; 56, argument_list; 56, 57; 56, 58; 56, 59; 56, 60; 56, 61; 57, identifier:sorted; 58, identifier:processed; 59, identifier:dep_key; 60, identifier:dep_deps; 61, identifier:dependency_tree; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:sorted; 66, identifier:append; 67, argument_list; 67, 68; 68, tuple; 68, 69; 68, 70; 69, identifier:key; 70, identifier:deps | def _sort_r(sorted, processed, key, deps, dependency_tree):
if key in processed:
return
processed.add(key)
for dep_key in deps:
dep_deps = dependency_tree.get(dep_key)
if dep_deps is None:
log.debug('"%s" not found, skipped', Repr(dep_key))
continue
_sort_r(sorted, processed, dep_key, dep_deps, dependency_tree)
sorted.append((key, deps)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name: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:count; 7, integer:30; 8, default_parameter; 8, 9; 8, 10; 9, identifier:order; 10, string:'user_ptime'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:asc; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:show_dir; 16, True; 17, default_parameter; 17, 18; 17, 19; 18, identifier:natsort; 19, True; 20, block; 20, 21; 20, 30; 20, 36; 20, 40; 20, 48; 20, 59; 20, 70; 20, 81; 20, 87; 20, 106; 20, 119; 20, 187; 20, 191; 20, 228; 21, if_statement; 21, 22; 21, 27; 22, comparison_operator:is; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:cid; 26, None; 27, block; 27, 28; 28, return_statement; 28, 29; 29, False; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:reload; 35, argument_list; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:kwargs; 39, dictionary; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:kwargs; 44, string:'cid'; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:cid; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:kwargs; 52, string:'asc'; 53, conditional_expression:if; 53, 54; 53, 55; 53, 58; 54, integer:1; 55, comparison_operator:is; 55, 56; 55, 57; 56, identifier:asc; 57, True; 58, integer:0; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:kwargs; 63, string:'show_dir'; 64, conditional_expression:if; 64, 65; 64, 66; 64, 69; 65, integer:1; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:show_dir; 68, True; 69, integer:0; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:kwargs; 74, string:'natsort'; 75, conditional_expression:if; 75, 76; 75, 77; 75, 80; 76, integer:1; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:natsort; 79, True; 80, integer:0; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:kwargs; 85, string:'o'; 86, identifier:order; 87, if_statement; 87, 88; 87, 99; 88, boolean_operator:or; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:is_root; 92, comparison_operator:==; 92, 93; 92, 94; 93, identifier:self; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:api; 98, identifier:receiver_directory; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, augmented_assignment:+=; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_count; 105, integer:1; 106, if_statement; 106, 107; 106, 112; 107, comparison_operator:<=; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:count; 111, identifier:count; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:count; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:count; 119, try_statement; 119, 120; 119, 144; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:entries; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_load_entries; 128, argument_list; 128, 129; 128, 136; 128, 139; 128, 142; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:func; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:api; 135, identifier:_req_files; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:count; 138, identifier:count; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:page; 141, integer:1; 142, dictionary_splat; 142, 143; 143, identifier:kwargs; 144, except_clause; 144, 145; 144, 149; 145, as_pattern; 145, 146; 145, 147; 146, identifier:RequestFailure; 147, as_pattern_target; 147, 148; 148, identifier:e; 149, block; 149, 150; 150, if_statement; 150, 151; 150, 158; 150, 183; 151, boolean_operator:and; 151, 152; 151, 155; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:natsort; 154, True; 155, comparison_operator:==; 155, 156; 155, 157; 156, identifier:order; 157, string:'file_name'; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 160, 163; 161, identifier:entries; 162, line_continuation:\; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:_load_entries; 167, argument_list; 167, 168; 167, 175; 167, 178; 167, 181; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:func; 170, attribute; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:api; 174, identifier:_req_aps_natsort_files; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:count; 177, identifier:count; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:page; 180, integer:1; 181, dictionary_splat; 181, 182; 182, identifier:kwargs; 183, else_clause; 183, 184; 184, block; 184, 185; 185, raise_statement; 185, 186; 186, identifier:e; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:res; 190, list:[]; 191, for_statement; 191, 192; 191, 193; 191, 194; 192, identifier:entry; 193, identifier:entries; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 199; 195, 213; 196, comparison_operator:in; 196, 197; 196, 198; 197, string:'pid'; 198, identifier:entry; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:res; 204, identifier:append; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 208; 207, identifier:_instantiate_directory; 208, argument_list; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:api; 212, identifier:entry; 213, else_clause; 213, 214; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:res; 219, identifier:append; 220, argument_list; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:_instantiate_file; 223, argument_list; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:api; 227, identifier:entry; 228, return_statement; 228, 229; 229, identifier:res | def list(self, count=30, order='user_ptime', asc=False, show_dir=True,
natsort=True):
if self.cid is None:
return False
self.reload()
kwargs = {}
kwargs['cid'] = self.cid
kwargs['asc'] = 1 if asc is True else 0
kwargs['show_dir'] = 1 if show_dir is True else 0
kwargs['natsort'] = 1 if natsort is True else 0
kwargs['o'] = order
if self.is_root or self == self.api.receiver_directory:
self._count += 1
if self.count <= count:
count = self.count
try:
entries = self._load_entries(func=self.api._req_files,
count=count, page=1, **kwargs)
except RequestFailure as e:
if natsort is True and order == 'file_name':
entries = \
self._load_entries(func=self.api._req_aps_natsort_files,
count=count, page=1, **kwargs)
else:
raise e
res = []
for entry in entries:
if 'pid' in entry:
res.append(_instantiate_directory(self.api, entry))
else:
res.append(_instantiate_file(self.api, entry))
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:list_items; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_key; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 11, 25; 11, 40; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:items; 15, call; 15, 16; 15, 17; 16, identifier:list; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:items; 23, identifier:values; 24, argument_list; 25, if_statement; 25, 26; 25, 27; 26, identifier:sort_key; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:items; 32, identifier:sort; 33, argument_list; 33, 34; 33, 37; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:key; 36, identifier:sort_key; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:reverse; 39, identifier:reverse; 40, return_statement; 40, 41; 41, identifier:items | def list_items(self, sort_key=None, reverse=False):
items = list(self.items.values())
if sort_key:
items.sort(key=sort_key, reverse=reverse)
return items |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_prepare_axes; 3, parameters; 3, 4; 3, 5; 4, identifier:node; 5, identifier:sort_key; 6, block; 6, 7; 6, 13; 6, 19; 6, 36; 6, 40; 6, 121; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:links; 10, attribute; 10, 11; 10, 12; 11, identifier:node; 12, identifier:links; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:o_links; 16, attribute; 16, 17; 16, 18; 17, identifier:node; 18, identifier:_overlapping_links; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:overlap; 22, set_comprehension; 22, 23; 22, 24; 22, 27; 23, identifier:ax2; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:ax; 26, identifier:links; 27, for_in_clause; 27, 28; 27, 29; 28, identifier:ax2; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:o_links; 32, identifier:get; 33, argument_list; 33, 34; 33, 35; 34, identifier:ax; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:axes; 39, list:[]; 40, for_statement; 40, 41; 40, 42; 40, 53; 41, identifier:axis; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 44, 50; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:links; 48, identifier:keys; 49, argument_list; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:key; 52, identifier:sort_key; 53, block; 53, 54; 53, 60; 53, 66; 53, 112; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:in; 55, 56; 55, 57; 56, identifier:axis; 57, identifier:overlap; 58, block; 58, 59; 59, continue_statement; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:tgt; 63, subscript; 63, 64; 63, 65; 64, identifier:links; 65, identifier:axis; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:in; 67, 68; 67, 69; 68, identifier:axis; 69, identifier:o_links; 70, block; 70, 71; 70, 84; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, pattern_list; 73, 74; 73, 75; 74, identifier:s; 75, identifier:e; 76, expression_list; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:axis; 79, integer:0; 80, subscript; 80, 81; 80, 82; 81, identifier:axis; 82, unary_operator:-; 82, 83; 83, integer:1; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:axis; 87, binary_operator:%; 87, 88; 87, 89; 88, string:'%s%s%s'; 89, tuple; 89, 90; 89, 91; 89, 111; 90, identifier:s; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, string:'&'; 94, identifier:join; 95, generator_expression; 95, 96; 95, 103; 96, subscript; 96, 97; 96, 98; 97, identifier:a; 98, slice; 98, 99; 98, 100; 98, 101; 99, integer:1; 100, colon; 101, unary_operator:-; 101, 102; 102, integer:1; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:a; 105, binary_operator:+; 105, 106; 105, 108; 106, list:[axis]; 106, 107; 107, identifier:axis; 108, subscript; 108, 109; 108, 110; 109, identifier:o_links; 110, identifier:axis; 111, identifier:e; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:axes; 116, identifier:append; 117, argument_list; 117, 118; 118, tuple; 118, 119; 118, 120; 119, identifier:axis; 120, identifier:tgt; 121, return_statement; 121, 122; 122, identifier:axes | def _prepare_axes(node, sort_key):
links = node.links
o_links = node._overlapping_links
overlap = {ax2 for ax in links for ax2 in o_links.get(ax, [])}
axes = []
for axis in sorted(links.keys(), key=sort_key):
if axis in overlap: continue
tgt = links[axis]
if axis in o_links:
s, e = axis[0], axis[-1]
axis = '%s%s%s' % (
s, '&'.join(a[1:-1] for a in [axis] + o_links[axis]), e
)
axes.append((axis, tgt))
return axes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_vid_split; 3, parameters; 3, 4; 4, identifier:vs; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:match; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:var_re; 12, identifier:match; 13, argument_list; 13, 14; 14, identifier:vs; 15, if_statement; 15, 16; 15, 19; 15, 33; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:match; 18, None; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:ValueError; 23, argument_list; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, string:'Invalid variable string: {}'; 27, identifier:format; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:str; 31, argument_list; 31, 32; 32, identifier:vs; 33, else_clause; 33, 34; 34, block; 34, 35; 35, return_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:match; 39, identifier:groups; 40, argument_list | def sort_vid_split(vs):
match = var_re.match(vs)
if match is None:
raise ValueError('Invalid variable string: {}'.format(str(vs)))
else:
return match.groups() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:properties; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 15; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:d; 9, call; 9, 10; 9, 11; 10, identifier:dict; 11, argument_list; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:sortinfo; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:in; 16, 17; 16, 18; 17, identifier:CVARSORT; 18, identifier:d; 19, block; 19, 20; 20, delete_statement; 20, 21; 21, subscript; 21, 22; 21, 23; 22, identifier:d; 23, identifier:CVARSORT; 24, return_statement; 24, 25; 25, identifier:d | def properties(self):
d = dict(self.sortinfo)
if CVARSORT in d:
del d[CVARSORT]
return d |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build_messages_modules; 3, parameters; 3, 4; 4, identifier:messages; 5, block; 5, 6; 5, 15; 5, 54; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:data; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:collections; 12, identifier:defaultdict; 13, argument_list; 13, 14; 14, identifier:list; 15, for_statement; 15, 16; 15, 17; 15, 18; 16, identifier:line; 17, identifier:messages; 18, block; 18, 19; 18, 28; 18, 37; 18, 45; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:module_name; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:line; 25, identifier:get; 26, argument_list; 26, 27; 27, string:'module'; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:module_path; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:line; 34, identifier:get; 35, argument_list; 35, 36; 36, string:'path'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:module_info; 40, call; 40, 41; 40, 42; 41, identifier:ModuleInfo; 42, argument_list; 42, 43; 42, 44; 43, identifier:module_name; 44, identifier:module_path; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:data; 50, identifier:module_info; 51, identifier:append; 52, argument_list; 52, 53; 53, identifier:line; 54, for_statement; 54, 55; 54, 58; 54, 63; 55, pattern_list; 55, 56; 55, 57; 56, identifier:module; 57, identifier:module_messages; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:data; 61, identifier:items; 62, argument_list; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, yield; 65, 66; 66, tuple; 66, 67; 66, 68; 67, identifier:module; 68, call; 68, 69; 68, 70; 69, identifier:sorted; 70, argument_list; 70, 71; 70, 72; 71, identifier:module_messages; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:key; 74, lambda; 74, 75; 74, 77; 75, lambda_parameters; 75, 76; 76, identifier:x; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:x; 80, identifier:get; 81, argument_list; 81, 82; 82, string:'line' | def build_messages_modules(messages):
data = collections.defaultdict(list)
for line in messages:
module_name = line.get('module')
module_path = line.get('path')
module_info = ModuleInfo(
module_name,
module_path,
)
data[module_info].append(line)
for module, module_messages in data.items():
yield (
module,
sorted(module_messages, key=lambda x: x.get('line'))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:write; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:nml; 5, identifier:nml_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort; 11, False; 12, block; 12, 13; 12, 40; 13, if_statement; 13, 14; 13, 26; 13, 34; 14, boolean_operator:and; 14, 15; 14, 21; 15, not_operator; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:nml; 20, identifier:Namelist; 21, call; 21, 22; 21, 23; 22, identifier:isinstance; 23, argument_list; 23, 24; 23, 25; 24, identifier:nml; 25, identifier:dict; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:nml_in; 30, call; 30, 31; 30, 32; 31, identifier:Namelist; 32, argument_list; 32, 33; 33, identifier:nml; 34, else_clause; 34, 35; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:nml_in; 39, identifier:nml; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:nml_in; 44, identifier:write; 45, argument_list; 45, 46; 45, 47; 45, 50; 46, identifier:nml_path; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:force; 49, identifier:force; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:sort; 52, identifier:sort | def write(nml, nml_path, force=False, sort=False):
if not isinstance(nml, Namelist) and isinstance(nml, dict):
nml_in = Namelist(nml)
else:
nml_in = nml
nml_in.write(nml_path, force=force, sort=sort) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:date_key; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:month_string; 6, block; 6, 7; 6, 18; 6, 26; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:month; 11, identifier:year; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:month_string; 15, identifier:split; 16, argument_list; 16, 17; 17, string:','; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:month_ord; 21, subscript; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:cls; 24, identifier:month_ordinal; 25, identifier:month; 26, return_statement; 26, 27; 27, expression_list; 27, 28; 27, 29; 28, identifier:year; 29, identifier:month_ord | def date_key(cls, month_string):
month, year = month_string.split(',')
month_ord = cls.month_ordinal[month]
return year, month_ord |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:SynchronizedClassMethod; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:locks_attr_names; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 19; 8, 28; 8, 50; 8, 176; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:locks_attr_names; 12, list_comprehension; 12, 13; 12, 14; 12, 17; 13, identifier:lock_name; 14, for_in_clause; 14, 15; 14, 16; 15, identifier:lock_name; 16, identifier:locks_attr_names; 17, if_clause; 17, 18; 18, identifier:lock_name; 19, if_statement; 19, 20; 19, 22; 20, not_operator; 20, 21; 21, identifier:locks_attr_names; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ValueError; 26, argument_list; 26, 27; 27, string:"The lock names list can't be empty"; 28, if_statement; 28, 29; 28, 36; 29, boolean_operator:or; 29, 30; 29, 33; 30, comparison_operator:not; 30, 31; 30, 32; 31, string:"sorted"; 32, identifier:kwargs; 33, subscript; 33, 34; 33, 35; 34, identifier:kwargs; 35, string:"sorted"; 36, block; 36, 37; 36, 44; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:locks_attr_names; 40, call; 40, 41; 40, 42; 41, identifier:list; 42, argument_list; 42, 43; 43, identifier:locks_attr_names; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:locks_attr_names; 48, identifier:sort; 49, argument_list; 50, function_definition; 50, 51; 50, 52; 50, 54; 51, function_name:wrapped; 52, parameters; 52, 53; 53, identifier:method; 54, block; 54, 55; 54, 174; 55, decorated_definition; 55, 56; 55, 63; 56, decorator; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:functools; 60, identifier:wraps; 61, argument_list; 61, 62; 62, identifier:method; 63, function_definition; 63, 64; 63, 65; 63, 71; 64, function_name:synchronized; 65, parameters; 65, 66; 65, 67; 65, 69; 66, identifier:self; 67, list_splat_pattern; 67, 68; 68, identifier:args; 69, dictionary_splat_pattern; 69, 70; 70, identifier:kwargs; 71, block; 71, 72; 71, 84; 71, 92; 71, 96; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:locks; 75, list_comprehension; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:getattr; 78, argument_list; 78, 79; 78, 80; 79, identifier:self; 80, identifier:attr_name; 81, for_in_clause; 81, 82; 81, 83; 82, identifier:attr_name; 83, identifier:locks_attr_names; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:locked; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:collections; 90, identifier:deque; 91, argument_list; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:i; 95, integer:0; 96, try_statement; 96, 97; 96, 151; 97, block; 97, 98; 97, 142; 98, for_statement; 98, 99; 98, 100; 98, 101; 99, identifier:lock; 100, identifier:locks; 101, block; 101, 102; 101, 125; 101, 129; 101, 135; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:lock; 105, None; 106, block; 106, 107; 107, raise_statement; 107, 108; 108, call; 108, 109; 108, 110; 109, identifier:AttributeError; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:"Lock '{0}' can't be None in class {1}"; 114, identifier:format; 115, argument_list; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:locks_attr_names; 118, identifier:i; 119, attribute; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:type; 122, argument_list; 122, 123; 123, identifier:self; 124, identifier:__name__; 125, expression_statement; 125, 126; 126, augmented_assignment:+=; 126, 127; 126, 128; 127, identifier:i; 128, integer:1; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:lock; 133, identifier:acquire; 134, argument_list; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:locked; 139, identifier:appendleft; 140, argument_list; 140, 141; 141, identifier:lock; 142, return_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:method; 145, argument_list; 145, 146; 145, 147; 145, 149; 146, identifier:self; 147, list_splat; 147, 148; 148, identifier:args; 149, dictionary_splat; 149, 150; 150, identifier:kwargs; 151, finally_clause; 151, 152; 152, block; 152, 153; 152, 163; 152, 169; 153, for_statement; 153, 154; 153, 155; 153, 156; 154, identifier:lock; 155, identifier:locked; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:lock; 161, identifier:release; 162, argument_list; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:locked; 167, identifier:clear; 168, argument_list; 169, delete_statement; 169, 170; 170, subscript; 170, 171; 170, 172; 171, identifier:locks; 172, slice; 172, 173; 173, colon; 174, return_statement; 174, 175; 175, identifier:synchronized; 176, return_statement; 176, 177; 177, identifier:wrapped | def SynchronizedClassMethod(*locks_attr_names, **kwargs):
locks_attr_names = [
lock_name for lock_name in locks_attr_names if lock_name
]
if not locks_attr_names:
raise ValueError("The lock names list can't be empty")
if "sorted" not in kwargs or kwargs["sorted"]:
locks_attr_names = list(locks_attr_names)
locks_attr_names.sort()
def wrapped(method):
@functools.wraps(method)
def synchronized(self, *args, **kwargs):
locks = [getattr(self, attr_name) for attr_name in locks_attr_names]
locked = collections.deque()
i = 0
try:
for lock in locks:
if lock is None:
raise AttributeError(
"Lock '{0}' can't be None in class {1}".format(
locks_attr_names[i], type(self).__name__
)
)
i += 1
lock.acquire()
locked.appendleft(lock)
return method(self, *args, **kwargs)
finally:
for lock in locked:
lock.release()
locked.clear()
del locks[:]
return synchronized
return wrapped |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__sort_registry; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:svc_ref; 6, block; 6, 7; 7, with_statement; 7, 8; 7, 13; 8, with_clause; 8, 9; 9, with_item; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:__svc_lock; 13, block; 13, 14; 13, 31; 13, 62; 13, 68; 14, if_statement; 14, 15; 14, 20; 15, comparison_operator:not; 15, 16; 15, 17; 16, identifier:svc_ref; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:__svc_registry; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:BundleException; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, string:"Unknown service: {0}"; 28, identifier:format; 29, argument_list; 29, 30; 30, identifier:svc_ref; 31, for_statement; 31, 32; 31, 33; 31, 39; 32, identifier:spec; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:svc_ref; 36, identifier:get_property; 37, argument_list; 37, 38; 38, identifier:OBJECTCLASS; 39, block; 39, 40; 39, 48; 39, 58; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:spec_refs; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:__svc_specs; 47, identifier:spec; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:idx; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:bisect; 54, identifier:bisect_left; 55, argument_list; 55, 56; 55, 57; 56, identifier:spec_refs; 57, identifier:svc_ref; 58, delete_statement; 58, 59; 59, subscript; 59, 60; 59, 61; 60, identifier:spec_refs; 61, identifier:idx; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:svc_ref; 66, identifier:update_sort_key; 67, argument_list; 68, for_statement; 68, 69; 68, 70; 68, 76; 69, identifier:spec; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:svc_ref; 73, identifier:get_property; 74, argument_list; 74, 75; 75, identifier:OBJECTCLASS; 76, block; 76, 77; 76, 85; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:spec_refs; 80, subscript; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:__svc_specs; 84, identifier:spec; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:bisect; 89, identifier:insort_left; 90, argument_list; 90, 91; 90, 92; 91, identifier:spec_refs; 92, identifier:svc_ref | def __sort_registry(self, svc_ref):
with self.__svc_lock:
if svc_ref not in self.__svc_registry:
raise BundleException("Unknown service: {0}".format(svc_ref))
for spec in svc_ref.get_property(OBJECTCLASS):
spec_refs = self.__svc_specs[spec]
idx = bisect.bisect_left(spec_refs, svc_ref)
del spec_refs[idx]
svc_ref.update_sort_key()
for spec in svc_ref.get_property(OBJECTCLASS):
spec_refs = self.__svc_specs[spec]
bisect.insort_left(spec_refs, svc_ref) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:sorted_timezones; 3, parameters; 4, block; 4, 5; 4, 59; 4, 67; 4, 71; 4, 91; 4, 138; 4, 220; 4, 226; 5, function_definition; 5, 6; 5, 7; 5, 9; 6, function_name:hourmin; 7, parameters; 7, 8; 8, identifier:delta; 9, block; 9, 10; 9, 45; 9, 55; 10, if_statement; 10, 11; 10, 16; 10, 31; 11, comparison_operator:<; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:delta; 14, identifier:days; 15, integer:0; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:hours; 21, identifier:remaining; 22, call; 22, 23; 22, 24; 23, identifier:divmod; 24, argument_list; 24, 25; 24, 30; 25, binary_operator:-; 25, 26; 25, 27; 26, integer:86400; 27, attribute; 27, 28; 27, 29; 28, identifier:delta; 29, identifier:seconds; 30, integer:3600; 31, else_clause; 31, 32; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, pattern_list; 35, 36; 35, 37; 36, identifier:hours; 37, identifier:remaining; 38, call; 38, 39; 38, 40; 39, identifier:divmod; 40, argument_list; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:delta; 43, identifier:seconds; 44, integer:3600; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, pattern_list; 47, 48; 47, 49; 48, identifier:minutes; 49, identifier:remaining; 50, call; 50, 51; 50, 52; 51, identifier:divmod; 52, argument_list; 52, 53; 52, 54; 53, identifier:remaining; 54, integer:60; 55, return_statement; 55, 56; 56, expression_list; 56, 57; 56, 58; 57, identifier:hours; 58, identifier:minutes; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:now; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:datetime; 65, identifier:utcnow; 66, argument_list; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:timezone_country; 70, dictionary; 71, for_statement; 71, 72; 71, 73; 71, 76; 72, identifier:countrycode; 73, attribute; 73, 74; 73, 75; 74, identifier:pytz; 75, identifier:country_timezones; 76, block; 76, 77; 77, for_statement; 77, 78; 77, 79; 77, 84; 78, identifier:timezone; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:pytz; 82, identifier:country_timezones; 83, identifier:countrycode; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:timezone_country; 89, identifier:timezone; 90, identifier:countrycode; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:timezones; 94, list_comprehension; 94, 95; 94, 111; 94, 116; 95, tuple; 95, 96; 95, 110; 96, call; 96, 97; 96, 105; 97, attribute; 97, 98; 97, 104; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:pytz; 101, identifier:timezone; 102, argument_list; 102, 103; 103, identifier:tzname; 104, identifier:utcoffset; 105, argument_list; 105, 106; 105, 107; 106, identifier:now; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:is_dst; 109, False; 110, identifier:tzname; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:tzname; 113, attribute; 113, 114; 113, 115; 114, identifier:pytz; 115, identifier:common_timezones; 116, if_clause; 116, 117; 117, boolean_operator:and; 117, 118; 117, 133; 118, boolean_operator:and; 118, 119; 118, 126; 119, not_operator; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:tzname; 123, identifier:startswith; 124, argument_list; 124, 125; 125, string:'US/'; 126, not_operator; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:tzname; 130, identifier:startswith; 131, argument_list; 131, 132; 132, string:'Canada/'; 133, comparison_operator:not; 133, 134; 133, 135; 134, identifier:tzname; 135, tuple; 135, 136; 135, 137; 136, string:'GMT'; 137, string:'UTC'; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:presorted; 141, list_comprehension; 141, 142; 141, 215; 142, tuple; 142, 143; 142, 144; 142, 214; 143, identifier:delta; 144, binary_operator:%; 144, 145; 144, 146; 145, string:'%s%s - %s%s (%s)'; 146, tuple; 146, 147; 146, 172; 146, 178; 146, 193; 146, 200; 147, boolean_operator:or; 147, 148; 147, 171; 148, boolean_operator:or; 148, 149; 148, 157; 149, parenthesized_expression; 149, 150; 150, boolean_operator:and; 150, 151; 150, 156; 151, comparison_operator:<; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:delta; 154, identifier:days; 155, integer:0; 156, string:'-'; 157, parenthesized_expression; 157, 158; 158, boolean_operator:and; 158, 159; 158, 170; 159, boolean_operator:and; 159, 160; 159, 165; 160, comparison_operator:==; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:delta; 163, identifier:days; 164, integer:0; 165, comparison_operator:==; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:delta; 168, identifier:seconds; 169, integer:0; 170, string:' '; 171, string:'+'; 172, binary_operator:%; 172, 173; 172, 174; 173, string:'%02d:%02d'; 174, call; 174, 175; 174, 176; 175, identifier:hourmin; 176, argument_list; 176, 177; 177, identifier:delta; 178, conditional_expression:if; 178, 179; 178, 189; 178, 192; 179, parenthesized_expression; 179, 180; 180, binary_operator:+; 180, 181; 180, 188; 181, subscript; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:pytz; 184, identifier:country_names; 185, subscript; 185, 186; 185, 187; 186, identifier:timezone_country; 187, identifier:name; 188, string:': '; 189, comparison_operator:in; 189, 190; 189, 191; 190, identifier:name; 191, identifier:timezone_country; 192, string:''; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:name; 196, identifier:replace; 197, argument_list; 197, 198; 197, 199; 198, string:'_'; 199, string:' '; 200, call; 200, 201; 200, 209; 201, attribute; 201, 202; 201, 208; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:pytz; 205, identifier:timezone; 206, argument_list; 206, 207; 207, identifier:name; 208, identifier:tzname; 209, argument_list; 209, 210; 209, 211; 210, identifier:now; 211, keyword_argument; 211, 212; 211, 213; 212, identifier:is_dst; 213, False; 214, identifier:name; 215, for_in_clause; 215, 216; 215, 219; 216, pattern_list; 216, 217; 216, 218; 217, identifier:delta; 218, identifier:name; 219, identifier:timezones; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:presorted; 224, identifier:sort; 225, argument_list; 226, return_statement; 226, 227; 227, list_comprehension; 227, 228; 227, 231; 228, tuple; 228, 229; 228, 230; 229, identifier:name; 230, identifier:label; 231, for_in_clause; 231, 232; 231, 236; 232, tuple_pattern; 232, 233; 232, 234; 232, 235; 233, identifier:delta; 234, identifier:label; 235, identifier:name; 236, identifier:presorted | def sorted_timezones():
def hourmin(delta):
if delta.days < 0:
hours, remaining = divmod(86400 - delta.seconds, 3600)
else:
hours, remaining = divmod(delta.seconds, 3600)
minutes, remaining = divmod(remaining, 60)
return hours, minutes
now = datetime.utcnow()
timezone_country = {}
for countrycode in pytz.country_timezones:
for timezone in pytz.country_timezones[countrycode]:
timezone_country[timezone] = countrycode
timezones = [(pytz.timezone(tzname).utcoffset(now, is_dst=False), tzname) for tzname in pytz.common_timezones
if not tzname.startswith('US/') and not tzname.startswith('Canada/') and tzname not in ('GMT', 'UTC')]
presorted = [(delta, '%s%s - %s%s (%s)' % (
(delta.days < 0 and '-') or (delta.days == 0 and delta.seconds == 0 and ' ') or '+',
'%02d:%02d' % hourmin(delta),
(pytz.country_names[timezone_country[name]] + ': ') if name in timezone_country else '',
name.replace('_', ' '),
pytz.timezone(name).tzname(now, is_dst=False)), name) for delta, name in timezones]
presorted.sort()
return [(name, label) for (delta, label, name) in presorted] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:alphanum_order; 3, parameters; 3, 4; 4, identifier:triples; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 9, 11; 10, identifier:triples; 11, keyword_argument; 11, 12; 11, 13; 12, identifier:key; 13, lambda; 13, 14; 13, 16; 14, lambda_parameters; 14, 15; 15, identifier:t; 16, list_comprehension; 16, 17; 16, 28; 17, conditional_expression:if; 17, 18; 17, 22; 17, 27; 18, call; 18, 19; 18, 20; 19, identifier:int; 20, argument_list; 20, 21; 21, identifier:t; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:t; 25, identifier:isdigit; 26, argument_list; 27, identifier:t; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:t; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:re; 33, identifier:split; 34, argument_list; 34, 35; 34, 36; 35, string:r'([0-9]+)'; 36, boolean_operator:or; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:t; 39, identifier:relation; 40, string:'' | def alphanum_order(triples):
return sorted(
triples,
key=lambda t: [
int(t) if t.isdigit() else t
for t in re.split(r'([0-9]+)', t.relation or '')
]
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_encode_penman; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:g; 6, default_parameter; 6, 7; 6, 8; 7, identifier:top; 8, None; 9, block; 9, 10; 9, 21; 9, 32; 9, 40; 9, 50; 9, 131; 9, 138; 9, 143; 9, 211; 9, 263; 9, 268; 9, 358; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:top; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:top; 18, attribute; 18, 19; 18, 20; 19, identifier:g; 20, identifier:top; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:remaining; 24, call; 24, 25; 24, 26; 25, identifier:set; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:g; 30, identifier:triples; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:variables; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:g; 38, identifier:variables; 39, argument_list; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:store; 43, call; 43, 44; 43, 45; 44, identifier:defaultdict; 45, argument_list; 45, 46; 46, lambda; 46, 47; 47, tuple; 47, 48; 47, 49; 48, list:[]; 49, list:[]; 50, for_statement; 50, 51; 50, 52; 50, 57; 51, identifier:t; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:g; 55, identifier:triples; 56, argument_list; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 62; 58, 96; 59, attribute; 59, 60; 59, 61; 60, identifier:t; 61, identifier:inverted; 62, block; 62, 63; 62, 76; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 74; 65, attribute; 65, 66; 65, 73; 66, subscript; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 69; 68, identifier:store; 69, attribute; 69, 70; 69, 71; 70, identifier:t; 71, identifier:target; 72, integer:0; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:t; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 87; 78, attribute; 78, 79; 78, 86; 79, subscript; 79, 80; 79, 85; 80, subscript; 80, 81; 80, 82; 81, identifier:store; 82, attribute; 82, 83; 82, 84; 83, identifier:t; 84, identifier:source; 85, integer:1; 86, identifier:append; 87, argument_list; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:Triple; 90, argument_list; 90, 91; 90, 93; 91, list_splat; 91, 92; 92, identifier:t; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:inverted; 95, False; 96, else_clause; 96, 97; 97, block; 97, 98; 97, 111; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 109; 100, attribute; 100, 101; 100, 108; 101, subscript; 101, 102; 101, 107; 102, subscript; 102, 103; 102, 104; 103, identifier:store; 104, attribute; 104, 105; 104, 106; 105, identifier:t; 106, identifier:source; 107, integer:0; 108, identifier:append; 109, argument_list; 109, 110; 110, identifier:t; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 122; 113, attribute; 113, 114; 113, 121; 114, subscript; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 117; 116, identifier:store; 117, attribute; 117, 118; 117, 119; 118, identifier:t; 119, identifier:target; 120, integer:1; 121, identifier:append; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:Triple; 125, argument_list; 125, 126; 125, 128; 126, list_splat; 126, 127; 127, identifier:t; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:inverted; 130, True; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:p; 134, call; 134, 135; 134, 136; 135, identifier:defaultdict; 136, argument_list; 136, 137; 137, identifier:list; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:topolist; 141, list:[top]; 141, 142; 142, identifier:top; 143, function_definition; 143, 144; 143, 145; 143, 147; 144, function_name:_update; 145, parameters; 145, 146; 146, identifier:t; 147, block; 147, 148; 147, 171; 147, 180; 147, 187; 147, 209; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, pattern_list; 150, 151; 150, 152; 151, identifier:src; 152, identifier:tgt; 153, conditional_expression:if; 153, 154; 153, 161; 153, 164; 154, tuple; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:t; 157, integer:2; 158, subscript; 158, 159; 158, 160; 159, identifier:t; 160, integer:0; 161, attribute; 161, 162; 161, 163; 162, identifier:t; 163, identifier:inverted; 164, tuple; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:t; 167, integer:0; 168, subscript; 168, 169; 168, 170; 169, identifier:t; 170, integer:2; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, subscript; 174, 175; 174, 176; 175, identifier:p; 176, identifier:src; 177, identifier:append; 178, argument_list; 178, 179; 179, identifier:t; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:remaining; 184, identifier:remove; 185, argument_list; 185, 186; 186, identifier:t; 187, if_statement; 187, 188; 187, 199; 188, boolean_operator:and; 188, 189; 188, 192; 189, comparison_operator:in; 189, 190; 189, 191; 190, identifier:tgt; 191, identifier:variables; 192, comparison_operator:!=; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:t; 195, identifier:relation; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:TYPE_REL; 199, block; 199, 200; 199, 207; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:topolist; 204, identifier:append; 205, argument_list; 205, 206; 206, identifier:tgt; 207, return_statement; 207, 208; 208, identifier:tgt; 209, return_statement; 209, 210; 210, None; 211, function_definition; 211, 212; 211, 213; 211, 215; 212, function_name:_explore_preferred; 213, parameters; 213, 214; 214, identifier:src; 215, block; 215, 216; 215, 230; 215, 256; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:ts; 219, subscript; 219, 220; 219, 229; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:store; 223, identifier:get; 224, argument_list; 224, 225; 224, 226; 225, identifier:src; 226, tuple; 226, 227; 226, 228; 227, list:[]; 228, list:[]; 229, integer:0; 230, for_statement; 230, 231; 230, 232; 230, 233; 231, identifier:t; 232, identifier:ts; 233, block; 233, 234; 234, if_statement; 234, 235; 234, 238; 235, comparison_operator:in; 235, 236; 235, 237; 236, identifier:t; 237, identifier:remaining; 238, block; 238, 239; 238, 246; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:tgt; 242, call; 242, 243; 242, 244; 243, identifier:_update; 244, argument_list; 244, 245; 245, identifier:t; 246, if_statement; 246, 247; 246, 250; 247, comparison_operator:is; 247, 248; 247, 249; 248, identifier:tgt; 249, None; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:_explore_preferred; 254, argument_list; 254, 255; 255, identifier:tgt; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 262; 258, subscript; 258, 259; 258, 260; 259, identifier:ts; 260, slice; 260, 261; 261, colon; 262, list:[]; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:_explore_preferred; 266, argument_list; 266, 267; 267, identifier:top; 268, while_statement; 268, 269; 268, 270; 269, identifier:remaining; 270, block; 270, 271; 270, 289; 270, 308; 270, 328; 270, 341; 270, 348; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:flip_candidates; 274, list_comprehension; 274, 275; 274, 286; 275, subscript; 275, 276; 275, 285; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:store; 279, identifier:get; 280, argument_list; 280, 281; 280, 282; 281, identifier:v; 282, tuple; 282, 283; 282, 284; 283, list:[]; 284, list:[]; 285, integer:1; 286, for_in_clause; 286, 287; 286, 288; 287, identifier:v; 288, identifier:topolist; 289, for_statement; 289, 290; 289, 291; 289, 292; 290, identifier:fc; 291, identifier:flip_candidates; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 299; 295, subscript; 295, 296; 295, 297; 296, identifier:fc; 297, slice; 297, 298; 298, colon; 299, list_comprehension; 299, 300; 299, 301; 299, 304; 300, identifier:c; 301, for_in_clause; 301, 302; 301, 303; 302, identifier:c; 303, identifier:fc; 304, if_clause; 304, 305; 305, comparison_operator:in; 305, 306; 305, 307; 306, identifier:c; 307, identifier:remaining; 308, if_statement; 308, 309; 308, 322; 309, not_operator; 309, 310; 310, call; 310, 311; 310, 312; 311, identifier:any; 312, generator_expression; 312, 313; 312, 319; 313, comparison_operator:>; 313, 314; 313, 318; 314, call; 314, 315; 314, 316; 315, identifier:len; 316, argument_list; 316, 317; 317, identifier:fc; 318, integer:0; 319, for_in_clause; 319, 320; 319, 321; 320, identifier:fc; 321, identifier:flip_candidates; 322, block; 322, 323; 323, raise_statement; 323, 324; 324, call; 324, 325; 324, 326; 325, identifier:EncodeError; 326, argument_list; 326, 327; 327, string:'Invalid graph; possibly disconnected.'; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:c; 331, call; 331, 332; 331, 333; 332, identifier:next; 333, generator_expression; 333, 334; 333, 335; 333, 338; 334, identifier:c; 335, for_in_clause; 335, 336; 335, 337; 336, identifier:fc; 337, identifier:flip_candidates; 338, for_in_clause; 338, 339; 338, 340; 339, identifier:c; 340, identifier:fc; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 344; 343, identifier:tgt; 344, call; 344, 345; 344, 346; 345, identifier:_update; 346, argument_list; 346, 347; 347, identifier:c; 348, if_statement; 348, 349; 348, 352; 349, comparison_operator:is; 349, 350; 349, 351; 350, identifier:tgt; 351, None; 352, block; 352, 353; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 356; 355, identifier:_explore_preferred; 356, argument_list; 356, 357; 357, identifier:tgt; 358, return_statement; 358, 359; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:self; 362, identifier:_layout; 363, argument_list; 363, 364; 363, 365; 363, 366; 363, 367; 364, identifier:p; 365, identifier:top; 366, integer:0; 367, call; 367, 368; 367, 369; 368, identifier:set; 369, argument_list | def _encode_penman(self, g, top=None):
if top is None:
top = g.top
remaining = set(g.triples())
variables = g.variables()
store = defaultdict(lambda: ([], []))
for t in g.triples():
if t.inverted:
store[t.target][0].append(t)
store[t.source][1].append(Triple(*t, inverted=False))
else:
store[t.source][0].append(t)
store[t.target][1].append(Triple(*t, inverted=True))
p = defaultdict(list)
topolist = [top]
def _update(t):
src, tgt = (t[2], t[0]) if t.inverted else (t[0], t[2])
p[src].append(t)
remaining.remove(t)
if tgt in variables and t.relation != self.TYPE_REL:
topolist.append(tgt)
return tgt
return None
def _explore_preferred(src):
ts = store.get(src, ([], []))[0]
for t in ts:
if t in remaining:
tgt = _update(t)
if tgt is not None:
_explore_preferred(tgt)
ts[:] = []
_explore_preferred(top)
while remaining:
flip_candidates = [store.get(v, ([],[]))[1] for v in topolist]
for fc in flip_candidates:
fc[:] = [c for c in fc if c in remaining]
if not any(len(fc) > 0 for fc in flip_candidates):
raise EncodeError('Invalid graph; possibly disconnected.')
c = next(c for fc in flip_candidates for c in fc)
tgt = _update(c)
if tgt is not None:
_explore_preferred(tgt)
return self._layout(p, top, 0, set()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:copy; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:__class__; 11, argument_list; 11, 12; 11, 13; 11, 18; 12, identifier:self; 13, keyword_argument; 13, 14; 13, 15; 14, identifier:key; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_key; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:load; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_load | def copy(self):
return self.__class__(self, key=self._key, load=self._load) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:copy; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:__class__; 11, argument_list; 11, 12; 11, 15; 11, 18; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_key; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_load; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_iteritems; 22, argument_list | def copy(self):
return self.__class__(self._key, self._load, self._iteritems()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_group; 3, parameters; 3, 4; 3, 5; 4, identifier:d; 5, default_parameter; 5, 6; 5, 7; 6, identifier:return_only_first; 7, False; 8, block; 8, 9; 8, 11; 8, 18; 8, 25; 8, 44; 9, expression_statement; 9, 10; 10, string:''' Sort a dictionary of relative paths and cluster equal paths together at the same time '''; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:d_sort; 14, call; 14, 15; 14, 16; 15, identifier:sort_dict_of_paths; 16, argument_list; 16, 17; 17, identifier:d; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:base_elt; 21, tuple; 21, 22; 21, 24; 22, unary_operator:-; 22, 23; 23, integer:1; 24, None; 25, while_statement; 25, 26; 25, 34; 26, parenthesized_expression; 26, 27; 27, boolean_operator:and; 27, 28; 27, 33; 28, comparison_operator:is; 28, 29; 28, 32; 29, subscript; 29, 30; 29, 31; 30, identifier:base_elt; 31, integer:1; 32, None; 33, identifier:d_sort; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:base_elt; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:d_sort; 41, identifier:pop; 42, argument_list; 42, 43; 43, integer:0; 44, if_statement; 44, 45; 44, 50; 44, 53; 45, comparison_operator:is; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:base_elt; 48, integer:1; 49, None; 50, block; 50, 51; 51, return_statement; 51, 52; 52, None; 53, else_clause; 53, 54; 54, block; 54, 55; 54, 59; 54, 67; 54, 118; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:lst; 58, list:[]; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:lst; 63, identifier:append; 64, argument_list; 64, 65; 65, list:[base_elt]; 65, 66; 66, identifier:base_elt; 67, if_statement; 67, 68; 67, 69; 68, identifier:d_sort; 69, block; 69, 70; 70, for_statement; 70, 71; 70, 72; 70, 73; 71, identifier:elt; 72, identifier:d_sort; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 80; 75, comparison_operator:is; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:elt; 78, integer:1; 79, None; 80, block; 80, 81; 81, if_statement; 81, 82; 81, 89; 81, 100; 82, comparison_operator:==; 82, 83; 82, 86; 83, subscript; 83, 84; 83, 85; 84, identifier:elt; 85, integer:1; 86, subscript; 86, 87; 86, 88; 87, identifier:base_elt; 88, integer:1; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 98; 92, attribute; 92, 93; 92, 97; 93, subscript; 93, 94; 93, 95; 94, identifier:lst; 95, unary_operator:-; 95, 96; 96, integer:1; 97, identifier:append; 98, argument_list; 98, 99; 99, identifier:elt; 100, else_clause; 100, 101; 101, block; 101, 102; 101, 106; 101, 114; 102, if_statement; 102, 103; 102, 104; 103, identifier:return_only_first; 104, block; 104, 105; 105, break_statement; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:lst; 110, identifier:append; 111, argument_list; 111, 112; 112, list:[elt]; 112, 113; 113, identifier:elt; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:base_elt; 117, identifier:elt; 118, return_statement; 118, 119; 119, identifier:lst | def sort_group(d, return_only_first=False):
''' Sort a dictionary of relative paths and cluster equal paths together at the same time '''
d_sort = sort_dict_of_paths(d)
base_elt = (-1, None)
while (base_elt[1] is None and d_sort):
base_elt = d_sort.pop(0)
if base_elt[1] is None:
return None
else:
lst = []
lst.append([base_elt])
if d_sort:
for elt in d_sort:
if elt[1] is not None:
if elt[1] == base_elt[1]:
lst[-1].append(elt)
else:
if return_only_first: break
lst.append([elt])
base_elt = elt
return lst |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:group_files_by_size_fast; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:fileslist; 5, identifier:nbgroups; 6, default_parameter; 6, 7; 6, 8; 7, identifier:mode; 8, integer:1; 9, block; 9, 10; 9, 12; 9, 18; 9, 22; 9, 26; 9, 45; 9, 50; 9, 302; 10, expression_statement; 10, 11; 11, string:'''Given a files list with sizes, output a list where the files are grouped in nbgroups per cluster.
Pseudo-code for algorithm in O(n log(g)) (thank's to insertion sort or binary search trees)
See for more infos: http://cs.stackexchange.com/questions/44406/fast-algorithm-for-clustering-groups-of-elements-given-their-size-time/44614
For each file:
- If to-fill list is empty or file.size > first-key(to-fill):
* Create cluster c with file in first group g1
* Add to-fill[file.size].append([c, g2], [c, g3], ..., [c, gn])
- Else:
* ksize = first-key(to-fill)
* c, g = to-fill[ksize].popitem(0)
* Add file to cluster c in group g
* nsize = ksize - file.size
* if nsize > 0:
. to-fill[nsize].append([c, g])
. sort to-fill if not an automatic ordering structure
'''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ftofill; 15, call; 15, 16; 15, 17; 16, identifier:SortedList; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:ftofill_pointer; 21, dictionary; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:fgrouped; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:ford; 29, call; 29, 30; 29, 31; 30, identifier:sorted; 31, argument_list; 31, 32; 31, 37; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:fileslist; 35, identifier:iteritems; 36, argument_list; 37, keyword_argument; 37, 38; 37, 39; 38, identifier:key; 39, lambda; 39, 40; 39, 42; 40, lambda_parameters; 40, 41; 41, identifier:x; 42, subscript; 42, 43; 42, 44; 43, identifier:x; 44, integer:1; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:last_cid; 48, unary_operator:-; 48, 49; 49, integer:1; 50, while_statement; 50, 51; 50, 52; 51, identifier:ford; 52, block; 52, 53; 52, 63; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, pattern_list; 55, 56; 55, 57; 56, identifier:fname; 57, identifier:fsize; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:ford; 61, identifier:pop; 62, argument_list; 63, if_statement; 63, 64; 63, 73; 63, 228; 64, boolean_operator:or; 64, 65; 64, 67; 65, not_operator; 65, 66; 66, identifier:ftofill; 67, comparison_operator:>; 67, 68; 67, 69; 68, identifier:fsize; 69, subscript; 69, 70; 69, 71; 70, identifier:ftofill; 71, unary_operator:-; 71, 72; 72, integer:1; 73, block; 73, 74; 73, 78; 73, 85; 73, 95; 74, expression_statement; 74, 75; 75, augmented_assignment:+=; 75, 76; 75, 77; 76, identifier:last_cid; 77, integer:1; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:fgrouped; 82, identifier:append; 83, argument_list; 83, 84; 84, list:[]; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:fgrouped; 90, identifier:last_cid; 91, identifier:append; 92, argument_list; 92, 93; 93, list:[fname]; 93, 94; 94, identifier:fname; 95, if_statement; 95, 96; 95, 99; 95, 151; 96, comparison_operator:==; 96, 97; 96, 98; 97, identifier:mode; 98, integer:0; 99, block; 99, 100; 100, for_statement; 100, 101; 100, 102; 100, 111; 101, identifier:g; 102, call; 102, 103; 102, 104; 103, identifier:xrange; 104, argument_list; 104, 105; 104, 108; 104, 109; 105, binary_operator:-; 105, 106; 105, 107; 106, identifier:nbgroups; 107, integer:1; 108, integer:0; 109, unary_operator:-; 109, 110; 110, integer:1; 111, block; 111, 112; 111, 121; 111, 133; 111, 144; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, subscript; 115, 116; 115, 117; 116, identifier:fgrouped; 117, identifier:last_cid; 118, identifier:append; 119, argument_list; 119, 120; 120, list:[]; 121, if_statement; 121, 122; 121, 126; 122, not_operator; 122, 123; 123, comparison_operator:in; 123, 124; 123, 125; 124, identifier:fsize; 125, identifier:ftofill_pointer; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, subscript; 129, 130; 129, 131; 130, identifier:ftofill_pointer; 131, identifier:fsize; 132, list:[]; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:ftofill_pointer; 138, identifier:fsize; 139, identifier:append; 140, argument_list; 140, 141; 141, tuple; 141, 142; 141, 143; 142, identifier:last_cid; 143, identifier:g; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:ftofill; 148, identifier:add; 149, argument_list; 149, 150; 150, identifier:fsize; 151, else_clause; 151, 152; 152, block; 152, 153; 153, for_statement; 153, 154; 153, 155; 153, 160; 154, identifier:g; 155, call; 155, 156; 155, 157; 156, identifier:xrange; 157, argument_list; 157, 158; 157, 159; 158, integer:1; 159, identifier:nbgroups; 160, block; 160, 161; 160, 177; 160, 187; 160, 193; 161, try_statement; 161, 162; 161, 173; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, pattern_list; 165, 166; 165, 167; 166, identifier:fgname; 167, identifier:fgsize; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:ford; 171, identifier:pop; 172, argument_list; 173, except_clause; 173, 174; 173, 175; 174, identifier:IndexError; 175, block; 175, 176; 176, break_statement; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:fgrouped; 182, identifier:last_cid; 183, identifier:append; 184, argument_list; 184, 185; 185, list:[fgname]; 185, 186; 186, identifier:fgname; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:diff_size; 190, binary_operator:-; 190, 191; 190, 192; 191, identifier:fsize; 192, identifier:fgsize; 193, if_statement; 193, 194; 193, 197; 194, comparison_operator:>; 194, 195; 194, 196; 195, identifier:diff_size; 196, integer:0; 197, block; 197, 198; 197, 210; 197, 221; 198, if_statement; 198, 199; 198, 203; 199, not_operator; 199, 200; 200, comparison_operator:in; 200, 201; 200, 202; 201, identifier:diff_size; 202, identifier:ftofill_pointer; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:ftofill_pointer; 208, identifier:diff_size; 209, list:[]; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:ftofill_pointer; 215, identifier:diff_size; 216, identifier:append; 217, argument_list; 217, 218; 218, tuple; 218, 219; 218, 220; 219, identifier:last_cid; 220, identifier:g; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:ftofill; 225, identifier:add; 226, argument_list; 226, 227; 227, identifier:diff_size; 228, else_clause; 228, 229; 229, block; 229, 230; 229, 238; 229, 250; 229, 261; 229, 267; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:ksize; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:ftofill; 236, identifier:pop; 237, argument_list; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 243; 240, pattern_list; 240, 241; 240, 242; 241, identifier:c; 242, identifier:g; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:ftofill_pointer; 247, identifier:ksize; 248, identifier:pop; 249, argument_list; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 259; 252, attribute; 252, 253; 252, 258; 253, subscript; 253, 254; 253, 257; 254, subscript; 254, 255; 254, 256; 255, identifier:fgrouped; 256, identifier:c; 257, identifier:g; 258, identifier:append; 259, argument_list; 259, 260; 260, identifier:fname; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:nsize; 264, binary_operator:-; 264, 265; 264, 266; 265, identifier:ksize; 266, identifier:fsize; 267, if_statement; 267, 268; 267, 271; 268, comparison_operator:>; 268, 269; 268, 270; 269, identifier:nsize; 270, integer:0; 271, block; 271, 272; 271, 284; 271, 295; 272, if_statement; 272, 273; 272, 277; 273, not_operator; 273, 274; 274, comparison_operator:in; 274, 275; 274, 276; 275, identifier:nsize; 276, identifier:ftofill_pointer; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 283; 280, subscript; 280, 281; 280, 282; 281, identifier:ftofill_pointer; 282, identifier:nsize; 283, list:[]; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, subscript; 287, 288; 287, 289; 288, identifier:ftofill_pointer; 289, identifier:nsize; 290, identifier:append; 291, argument_list; 291, 292; 292, tuple; 292, 293; 292, 294; 293, identifier:c; 294, identifier:g; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:ftofill; 299, identifier:add; 300, argument_list; 300, 301; 301, identifier:nsize; 302, return_statement; 302, 303; 303, identifier:fgrouped | def group_files_by_size_fast(fileslist, nbgroups, mode=1):
'''Given a files list with sizes, output a list where the files are grouped in nbgroups per cluster.
Pseudo-code for algorithm in O(n log(g)) (thank's to insertion sort or binary search trees)
See for more infos: http://cs.stackexchange.com/questions/44406/fast-algorithm-for-clustering-groups-of-elements-given-their-size-time/44614
For each file:
- If to-fill list is empty or file.size > first-key(to-fill):
* Create cluster c with file in first group g1
* Add to-fill[file.size].append([c, g2], [c, g3], ..., [c, gn])
- Else:
* ksize = first-key(to-fill)
* c, g = to-fill[ksize].popitem(0)
* Add file to cluster c in group g
* nsize = ksize - file.size
* if nsize > 0:
. to-fill[nsize].append([c, g])
. sort to-fill if not an automatic ordering structure
'''
ftofill = SortedList()
ftofill_pointer = {}
fgrouped = []
ford = sorted(fileslist.iteritems(), key=lambda x: x[1])
last_cid = -1
while ford:
fname, fsize = ford.pop()
if not ftofill or fsize > ftofill[-1]:
last_cid += 1
fgrouped.append([])
fgrouped[last_cid].append([fname])
if mode==0:
for g in xrange(nbgroups-1, 0, -1):
fgrouped[last_cid].append([])
if not fsize in ftofill_pointer:
ftofill_pointer[fsize] = []
ftofill_pointer[fsize].append((last_cid, g))
ftofill.add(fsize)
else:
for g in xrange(1, nbgroups):
try:
fgname, fgsize = ford.pop()
except IndexError:
break
fgrouped[last_cid].append([fgname])
diff_size = fsize - fgsize
if diff_size > 0:
if not diff_size in ftofill_pointer:
ftofill_pointer[diff_size] = []
ftofill_pointer[diff_size].append((last_cid, g))
ftofill.add(diff_size)
else:
ksize = ftofill.pop()
c, g = ftofill_pointer[ksize].pop()
fgrouped[c][g].append(fname)
nsize = ksize - fsize
if nsize > 0:
if not nsize in ftofill_pointer:
ftofill_pointer[nsize] = []
ftofill_pointer[nsize].append((c, g))
ftofill.add(nsize)
return fgrouped |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:print_; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:rows; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, integer:15; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort; 10, string:'size'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:order; 13, string:'descending'; 14, block; 14, 15; 14, 19; 14, 33; 14, 55; 14, 61; 14, 76; 14, 186; 14, 195; 14, 212; 14, 218; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:localrows; 18, list:[]; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:row; 21, identifier:rows; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:localrows; 27, identifier:append; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:list; 31, argument_list; 31, 32; 32, identifier:row; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 34, 43; 34, 45; 35, identifier:sortby; 36, ERROR; 36, 37; 36, 38; 36, 40; 37, string:'type'; 38, ERROR; 38, 39; 39, identifier:if; 40, comparison_operator:not; 40, 41; 40, 42; 41, identifier:sort; 42, identifier:sortby; 43, ERROR; 43, 44; 44, identifier:raise; 45, type; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:ValueError; 48, argument_list; 48, 49; 49, binary_operator:+; 49, 50; 49, 51; 50, string:"invalid sort, should be one of"; 51, call; 51, 52; 51, 53; 52, identifier:str; 53, argument_list; 53, 54; 54, identifier:sortby; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:orders; 58, list:['ascending', 'descending']; 58, 59; 58, 60; 59, string:'ascending'; 60, string:'descending'; 61, if_statement; 61, 62; 61, 65; 62, comparison_operator:not; 62, 63; 62, 64; 63, identifier:order; 64, identifier:orders; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:ValueError; 69, argument_list; 69, 70; 70, binary_operator:+; 70, 71; 70, 72; 71, string:"invalid order, should be one of"; 72, call; 72, 73; 72, 74; 73, identifier:str; 74, argument_list; 74, 75; 75, identifier:orders; 76, if_statement; 76, 77; 76, 85; 76, 133; 77, comparison_operator:==; 77, 78; 77, 84; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:sortby; 81, identifier:index; 82, argument_list; 82, 83; 83, identifier:sort; 84, integer:0; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 90; 86, 108; 87, comparison_operator:==; 87, 88; 87, 89; 88, identifier:order; 89, string:"ascending"; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:localrows; 95, identifier:sort; 96, argument_list; 96, 97; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:key; 99, lambda; 99, 100; 99, 102; 100, lambda_parameters; 100, 101; 101, identifier:x; 102, call; 102, 103; 102, 104; 103, identifier:_repr; 104, argument_list; 104, 105; 105, subscript; 105, 106; 105, 107; 106, identifier:x; 107, integer:0; 108, elif_clause; 108, 109; 108, 112; 109, comparison_operator:==; 109, 110; 109, 111; 110, identifier:order; 111, string:"descending"; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:localrows; 117, identifier:sort; 118, argument_list; 118, 119; 118, 130; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:key; 121, lambda; 121, 122; 121, 124; 122, lambda_parameters; 122, 123; 123, identifier:x; 124, call; 124, 125; 124, 126; 125, identifier:_repr; 126, argument_list; 126, 127; 127, subscript; 127, 128; 127, 129; 128, identifier:x; 129, integer:0; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:reverse; 132, True; 133, else_clause; 133, 134; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 139; 135, 159; 136, comparison_operator:==; 136, 137; 136, 138; 137, identifier:order; 138, string:"ascending"; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:localrows; 144, identifier:sort; 145, argument_list; 145, 146; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:key; 148, lambda; 148, 149; 148, 151; 149, lambda_parameters; 149, 150; 150, identifier:x; 151, subscript; 151, 152; 151, 153; 152, identifier:x; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:sortby; 156, identifier:index; 157, argument_list; 157, 158; 158, identifier:sort; 159, elif_clause; 159, 160; 159, 163; 160, comparison_operator:==; 160, 161; 160, 162; 161, identifier:order; 162, string:"descending"; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:localrows; 168, identifier:sort; 169, argument_list; 169, 170; 169, 183; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:key; 172, lambda; 172, 173; 172, 175; 173, lambda_parameters; 173, 174; 174, identifier:x; 175, subscript; 175, 176; 175, 177; 176, identifier:x; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:sortby; 180, identifier:index; 181, argument_list; 181, 182; 182, identifier:sort; 183, keyword_argument; 183, 184; 183, 185; 184, identifier:reverse; 185, True; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:localrows; 189, subscript; 189, 190; 189, 191; 190, identifier:localrows; 191, slice; 191, 192; 191, 193; 191, 194; 192, integer:0; 193, colon; 194, identifier:limit; 195, for_statement; 195, 196; 195, 197; 195, 198; 196, identifier:row; 197, identifier:localrows; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:row; 203, integer:2; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:stringutils; 207, identifier:pp; 208, argument_list; 208, 209; 209, subscript; 209, 210; 209, 211; 210, identifier:row; 211, integer:2; 212, ERROR; 212, 213; 212, 216; 212, 217; 213, attribute; 213, 214; 213, 215; 214, identifier:localrows; 215, identifier:insert; 216, integer:0; 217, string:"types"; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:_print_table; 221, argument_list; 221, 222; 222, identifier:localrows | def print_(rows, limit=15, sort='size', order='descending'):
localrows = []
for row in rows:
localrows.append(list(row))
sortby = ['type', '
if sort not in sortby:
raise ValueError("invalid sort, should be one of" + str(sortby))
orders = ['ascending', 'descending']
if order not in orders:
raise ValueError("invalid order, should be one of" + str(orders))
if sortby.index(sort) == 0:
if order == "ascending":
localrows.sort(key=lambda x: _repr(x[0]))
elif order == "descending":
localrows.sort(key=lambda x: _repr(x[0]), reverse=True)
else:
if order == "ascending":
localrows.sort(key=lambda x: x[sortby.index(sort)])
elif order == "descending":
localrows.sort(key=lambda x: x[sortby.index(sort)], reverse=True)
localrows = localrows[0:limit]
for row in localrows:
row[2] = stringutils.pp(row[2])
localrows.insert(0,["types", "
_print_table(localrows) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:split_and_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 17; 5, 35; 5, 50; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:graphs; 9, call; 9, 10; 9, 11; 10, identifier:list; 11, argument_list; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:split; 16, argument_list; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:graphs; 21, identifier:sort; 22, argument_list; 22, 23; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:key; 25, lambda; 25, 26; 25, 28; 26, lambda_parameters; 26, 27; 27, identifier:x; 28, unary_operator:-; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:x; 34, identifier:metadata; 35, for_statement; 35, 36; 35, 39; 35, 43; 36, pattern_list; 36, 37; 36, 38; 37, identifier:index; 38, identifier:graph; 39, call; 39, 40; 39, 41; 40, identifier:enumerate; 41, argument_list; 41, 42; 42, identifier:graphs; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:graph; 48, identifier:index; 49, identifier:index; 50, return_statement; 50, 51; 51, identifier:graphs | def split_and_sort(self):
graphs = list(self.split())
graphs.sort(key=lambda x: -len(x.metadata))
for index, graph in enumerate(graphs):
graph.index = index
return graphs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 31; 2, function_name:profile; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, default_parameter; 4, 5; 4, 6; 5, identifier:fn; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:skip; 9, integer:0; 10, default_parameter; 10, 11; 10, 12; 11, identifier:filename; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:immediate; 15, False; 16, default_parameter; 16, 17; 16, 18; 17, identifier:dirs; 18, False; 19, default_parameter; 19, 20; 19, 21; 20, identifier:sort; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:entries; 24, integer:40; 25, default_parameter; 25, 26; 25, 27; 26, identifier:profiler; 27, tuple; 27, 28; 27, 29; 27, 30; 28, string:'cProfile'; 29, string:'profile'; 30, string:'hotshot'; 31, block; 31, 32; 31, 70; 31, 82; 31, 112; 31, 137; 31, 153; 31, 161; 31, 169; 31, 177; 31, 185; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:fn; 35, None; 36, block; 36, 37; 36, 68; 37, function_definition; 37, 38; 37, 39; 37, 41; 38, function_name:decorator; 39, parameters; 39, 40; 40, identifier:fn; 41, block; 41, 42; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:profile; 45, argument_list; 45, 46; 45, 47; 45, 50; 45, 53; 45, 56; 45, 59; 45, 62; 45, 65; 46, identifier:fn; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:skip; 49, identifier:skip; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:filename; 52, identifier:filename; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:immediate; 55, identifier:immediate; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:dirs; 58, identifier:dirs; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:sort; 61, identifier:sort; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:entries; 64, identifier:entries; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:profiler; 67, identifier:profiler; 68, return_statement; 68, 69; 69, identifier:decorator; 70, if_statement; 70, 71; 70, 76; 71, call; 71, 72; 71, 73; 72, identifier:isinstance; 73, argument_list; 73, 74; 73, 75; 74, identifier:profiler; 75, identifier:str; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:profiler; 80, list:[profiler]; 80, 81; 81, identifier:profiler; 82, for_statement; 82, 83; 82, 84; 82, 85; 82, 98; 83, identifier:p; 84, identifier:profiler; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 90; 87, comparison_operator:in; 87, 88; 87, 89; 88, identifier:p; 89, identifier:AVAILABLE_PROFILERS; 90, block; 90, 91; 90, 97; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:profiler_class; 94, subscript; 94, 95; 94, 96; 95, identifier:AVAILABLE_PROFILERS; 96, identifier:p; 97, break_statement; 98, else_clause; 98, 99; 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:'only these profilers are available: %s'; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, string:', '; 109, identifier:join; 110, argument_list; 110, 111; 111, identifier:AVAILABLE_PROFILERS; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:fp; 115, call; 115, 116; 115, 117; 116, identifier:profiler_class; 117, argument_list; 117, 118; 117, 119; 117, 122; 117, 125; 117, 128; 117, 131; 117, 134; 118, identifier:fn; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:skip; 121, identifier:skip; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:filename; 124, identifier:filename; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:immediate; 127, identifier:immediate; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:dirs; 130, identifier:dirs; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:sort; 133, identifier:sort; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:entries; 136, identifier:entries; 137, function_definition; 137, 138; 137, 139; 137, 144; 138, function_name:new_fn; 139, parameters; 139, 140; 139, 142; 140, list_splat_pattern; 140, 141; 141, identifier:args; 142, dictionary_splat_pattern; 142, 143; 143, identifier:kw; 144, block; 144, 145; 145, return_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:fp; 148, argument_list; 148, 149; 148, 151; 149, list_splat; 149, 150; 150, identifier:args; 151, dictionary_splat; 151, 152; 152, identifier:kw; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:new_fn; 157, identifier:__doc__; 158, attribute; 158, 159; 158, 160; 159, identifier:fn; 160, identifier:__doc__; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:new_fn; 165, identifier:__name__; 166, attribute; 166, 167; 166, 168; 167, identifier:fn; 168, identifier:__name__; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:new_fn; 173, identifier:__dict__; 174, attribute; 174, 175; 174, 176; 175, identifier:fn; 176, identifier:__dict__; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:new_fn; 181, identifier:__module__; 182, attribute; 182, 183; 182, 184; 183, identifier:fn; 184, identifier:__module__; 185, return_statement; 185, 186; 186, identifier:new_fn | def profile(fn=None, skip=0, filename=None, immediate=False, dirs=False,
sort=None, entries=40,
profiler=('cProfile', 'profile', 'hotshot')):
if fn is None:
def decorator(fn):
return profile(fn, skip=skip, filename=filename,
immediate=immediate, dirs=dirs,
sort=sort, entries=entries,
profiler=profiler)
return decorator
if isinstance(profiler, str):
profiler = [profiler]
for p in profiler:
if p in AVAILABLE_PROFILERS:
profiler_class = AVAILABLE_PROFILERS[p]
break
else:
raise ValueError('only these profilers are available: %s'
% ', '.join(AVAILABLE_PROFILERS))
fp = profiler_class(fn, skip=skip, filename=filename,
immediate=immediate, dirs=dirs,
sort=sort, entries=entries)
def new_fn(*args, **kw):
return fp(*args, **kw)
new_fn.__doc__ = fn.__doc__
new_fn.__name__ = fn.__name__
new_fn.__dict__ = fn.__dict__
new_fn.__module__ = fn.__module__
return new_fn |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_kernel_arguments; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 36; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:declarations; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 21; 11, pattern_list; 11, 12; 11, 13; 12, identifier:name; 13, identifier:data; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_kernel_data; 19, identifier:items; 20, argument_list; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:declarations; 26, identifier:extend; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:data; 31, identifier:get_kernel_parameters; 32, argument_list; 32, 33; 33, binary_operator:+; 33, 34; 33, 35; 34, string:'_'; 35, identifier:name; 36, return_statement; 36, 37; 37, identifier:declarations | def _get_kernel_arguments(self):
declarations = []
for name, data in self._kernel_data.items():
declarations.extend(data.get_kernel_parameters('_' + name))
return declarations |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:topological_sort; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 36; 5, 58; 5, 87; 5, 114; 5, 215; 5, 220; 5, 229; 5, 236; 5, 241; 5, 245; 5, 278; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:check_self_dependencies; 8, parameters; 8, 9; 9, identifier:input_data; 10, block; 10, 11; 11, for_statement; 11, 12; 11, 15; 11, 20; 12, pattern_list; 12, 13; 12, 14; 13, identifier:k; 14, identifier:v; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:input_data; 18, identifier:items; 19, argument_list; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:in; 22, 23; 22, 24; 23, identifier:k; 24, identifier:v; 25, block; 25, 26; 26, raise_statement; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:ValueError; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:'Self-dependency, {} depends on itself.'; 33, identifier:format; 34, argument_list; 34, 35; 35, identifier:k; 36, function_definition; 36, 37; 36, 38; 36, 40; 37, function_name:prepare_input_data; 38, parameters; 38, 39; 39, identifier:input_data; 40, block; 40, 41; 41, return_statement; 41, 42; 42, dictionary_comprehension; 42, 43; 42, 49; 43, pair; 43, 44; 43, 45; 44, identifier:k; 45, call; 45, 46; 45, 47; 46, identifier:set; 47, argument_list; 47, 48; 48, identifier:v; 49, for_in_clause; 49, 50; 49, 53; 50, pattern_list; 50, 51; 50, 52; 51, identifier:k; 52, identifier:v; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:input_data; 56, identifier:items; 57, argument_list; 58, function_definition; 58, 59; 58, 60; 58, 62; 59, function_name:find_items_without_dependencies; 60, parameters; 60, 61; 61, identifier:input_data; 62, block; 62, 63; 63, return_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:list; 66, argument_list; 66, 67; 67, binary_operator:-; 67, 68; 67, 79; 68, call; 68, 69; 68, 70; 69, identifier:reduce; 70, argument_list; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:set; 73, identifier:union; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:input_data; 77, identifier:values; 78, argument_list; 79, call; 79, 80; 79, 81; 80, identifier:set; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:input_data; 85, identifier:keys; 86, argument_list; 87, function_definition; 87, 88; 87, 89; 87, 91; 88, function_name:add_empty_dependencies; 89, parameters; 89, 90; 90, identifier:data; 91, block; 91, 92; 91, 99; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:items_without_dependencies; 95, call; 95, 96; 95, 97; 96, identifier:find_items_without_dependencies; 97, argument_list; 97, 98; 98, identifier:data; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:data; 103, identifier:update; 104, argument_list; 104, 105; 105, dictionary_comprehension; 105, 106; 105, 111; 106, pair; 106, 107; 106, 108; 107, identifier:item; 108, call; 108, 109; 108, 110; 109, identifier:set; 110, argument_list; 111, for_in_clause; 111, 112; 111, 113; 112, identifier:item; 113, identifier:items_without_dependencies; 114, function_definition; 114, 115; 114, 116; 114, 118; 115, function_name:get_sorted; 116, parameters; 116, 117; 117, identifier:input_data; 118, block; 118, 119; 118, 123; 118, 180; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:data; 122, identifier:input_data; 123, while_statement; 123, 124; 123, 125; 124, True; 125, block; 125, 126; 125, 149; 125, 154; 125, 157; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:ordered; 129, call; 129, 130; 129, 131; 130, identifier:set; 131, generator_expression; 131, 132; 131, 133; 131, 142; 132, identifier:item; 133, for_in_clause; 133, 134; 133, 137; 134, pattern_list; 134, 135; 134, 136; 135, identifier:item; 136, identifier:dep; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:data; 140, identifier:items; 141, argument_list; 142, if_clause; 142, 143; 143, comparison_operator:==; 143, 144; 143, 148; 144, call; 144, 145; 144, 146; 145, identifier:len; 146, argument_list; 146, 147; 147, identifier:dep; 148, integer:0; 149, if_statement; 149, 150; 149, 152; 150, not_operator; 150, 151; 151, identifier:ordered; 152, block; 152, 153; 153, break_statement; 154, expression_statement; 154, 155; 155, yield; 155, 156; 156, identifier:ordered; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:data; 160, dictionary_comprehension; 160, 161; 160, 167; 160, 176; 161, pair; 161, 162; 161, 163; 162, identifier:item; 163, parenthesized_expression; 163, 164; 164, binary_operator:-; 164, 165; 164, 166; 165, identifier:dep; 166, identifier:ordered; 167, for_in_clause; 167, 168; 167, 171; 168, pattern_list; 168, 169; 168, 170; 169, identifier:item; 170, identifier:dep; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:data; 174, identifier:items; 175, argument_list; 176, if_clause; 176, 177; 177, comparison_operator:not; 177, 178; 177, 179; 178, identifier:item; 179, identifier:ordered; 180, if_statement; 180, 181; 180, 187; 181, comparison_operator:!=; 181, 182; 181, 186; 182, call; 182, 183; 182, 184; 183, identifier:len; 184, argument_list; 184, 185; 185, identifier:data; 186, integer:0; 187, block; 187, 188; 188, raise_statement; 188, 189; 189, call; 189, 190; 189, 191; 190, identifier:ValueError; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, concatenated_string; 194, 195; 194, 196; 195, string:'Cyclic dependencies exist '; 196, string:'among these items: {}'; 197, identifier:format; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, string:', '; 202, identifier:join; 203, generator_expression; 203, 204; 203, 208; 204, call; 204, 205; 204, 206; 205, identifier:repr; 206, argument_list; 206, 207; 207, identifier:x; 208, for_in_clause; 208, 209; 208, 210; 209, identifier:x; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:data; 213, identifier:items; 214, argument_list; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 218; 217, identifier:check_self_dependencies; 218, argument_list; 218, 219; 219, identifier:data; 220, if_statement; 220, 221; 220, 226; 221, not_operator; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:len; 224, argument_list; 224, 225; 225, identifier:data; 226, block; 226, 227; 227, return_statement; 227, 228; 228, list:[]; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:data_copy; 232, call; 232, 233; 232, 234; 233, identifier:prepare_input_data; 234, argument_list; 234, 235; 235, identifier:data; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:add_empty_dependencies; 239, argument_list; 239, 240; 240, identifier:data_copy; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:result; 244, list:[]; 245, for_statement; 245, 246; 245, 247; 245, 251; 246, identifier:d; 247, call; 247, 248; 247, 249; 248, identifier:get_sorted; 249, argument_list; 249, 250; 250, identifier:data_copy; 251, block; 251, 252; 251, 271; 252, try_statement; 252, 253; 252, 261; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:d; 257, call; 257, 258; 257, 259; 258, identifier:sorted; 259, argument_list; 259, 260; 260, identifier:d; 261, except_clause; 261, 262; 261, 263; 262, identifier:TypeError; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:d; 267, call; 267, 268; 267, 269; 268, identifier:list; 269, argument_list; 269, 270; 270, identifier:d; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:result; 275, identifier:extend; 276, argument_list; 276, 277; 277, identifier:d; 278, return_statement; 278, 279; 279, identifier:result | def topological_sort(data):
def check_self_dependencies(input_data):
for k, v in input_data.items():
if k in v:
raise ValueError('Self-dependency, {} depends on itself.'.format(k))
def prepare_input_data(input_data):
return {k: set(v) for k, v in input_data.items()}
def find_items_without_dependencies(input_data):
return list(reduce(set.union, input_data.values()) - set(input_data.keys()))
def add_empty_dependencies(data):
items_without_dependencies = find_items_without_dependencies(data)
data.update({item: set() for item in items_without_dependencies})
def get_sorted(input_data):
data = input_data
while True:
ordered = set(item for item, dep in data.items() if len(dep) == 0)
if not ordered:
break
yield ordered
data = {item: (dep - ordered) for item, dep in data.items() if item not in ordered}
if len(data) != 0:
raise ValueError('Cyclic dependencies exist '
'among these items: {}'.format(', '.join(repr(x) for x in data.items())))
check_self_dependencies(data)
if not len(data):
return []
data_copy = prepare_input_data(data)
add_empty_dependencies(data_copy)
result = []
for d in get_sorted(data_copy):
try:
d = sorted(d)
except TypeError:
d = list(d)
result.extend(d)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_posts; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:include_draft; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:filter_functions; 10, None; 11, block; 11, 12; 11, 136; 11, 150; 11, 169; 11, 179; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:posts_generator; 14, parameters; 14, 15; 15, identifier:path; 16, block; 16, 17; 17, if_statement; 17, 18; 17, 26; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:os; 22, identifier:path; 23, identifier:isdir; 24, argument_list; 24, 25; 25, identifier:path; 26, block; 26, 27; 27, for_statement; 27, 28; 27, 29; 27, 35; 28, identifier:file; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:os; 32, identifier:listdir; 33, argument_list; 33, 34; 34, identifier:path; 35, block; 35, 36; 35, 49; 35, 60; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, pattern_list; 38, 39; 38, 40; 39, identifier:filename; 40, identifier:ext; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:os; 45, identifier:path; 46, identifier:splitext; 47, argument_list; 47, 48; 48, identifier:file; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:format_name; 52, call; 52, 53; 52, 54; 53, identifier:get_standard_format_name; 54, argument_list; 54, 55; 55, subscript; 55, 56; 55, 57; 56, identifier:ext; 57, slice; 57, 58; 57, 59; 58, integer:1; 59, colon; 60, if_statement; 60, 61; 60, 72; 61, boolean_operator:and; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:format_name; 64, None; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:re; 68, identifier:match; 69, argument_list; 69, 70; 69, 71; 70, string:r'\d{4}-\d{2}-\d{2}-.+'; 71, identifier:filename; 72, block; 72, 73; 72, 79; 72, 85; 72, 108; 72, 123; 72, 133; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:post; 76, call; 76, 77; 76, 78; 77, identifier:Post; 78, argument_list; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:post; 83, identifier:format; 84, identifier:format_name; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 94; 87, pattern_list; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:post; 90, identifier:meta; 91, attribute; 91, 92; 91, 93; 92, identifier:post; 93, identifier:raw_content; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:FileStorage; 97, identifier:read_file; 98, argument_list; 98, 99; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:os; 103, identifier:path; 104, identifier:join; 105, argument_list; 105, 106; 105, 107; 106, identifier:path; 107, identifier:file; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:post; 112, identifier:rel_url; 113, binary_operator:+; 113, 114; 113, 122; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:filename; 117, identifier:replace; 118, argument_list; 118, 119; 118, 120; 118, 121; 119, string:'-'; 120, string:'/'; 121, integer:3; 122, string:'/'; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:post; 127, identifier:unique_key; 128, binary_operator:+; 128, 129; 128, 130; 129, string:'/post/'; 130, attribute; 130, 131; 130, 132; 131, identifier:post; 132, identifier:rel_url; 133, expression_statement; 133, 134; 134, yield; 134, 135; 135, identifier:post; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:posts_path; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:os; 143, identifier:path; 144, identifier:join; 145, argument_list; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:current_app; 148, identifier:instance_path; 149, string:'posts'; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:result; 153, call; 153, 154; 153, 155; 154, identifier:filter; 155, argument_list; 155, 156; 155, 165; 156, lambda; 156, 157; 156, 159; 157, lambda_parameters; 157, 158; 158, identifier:p; 159, boolean_operator:or; 159, 160; 159, 161; 160, identifier:include_draft; 161, not_operator; 161, 162; 162, attribute; 162, 163; 162, 164; 163, identifier:p; 164, identifier:is_draft; 165, call; 165, 166; 165, 167; 166, identifier:posts_generator; 167, argument_list; 167, 168; 168, identifier:posts_path; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:result; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_filter_result; 176, argument_list; 176, 177; 176, 178; 177, identifier:result; 178, identifier:filter_functions; 179, return_statement; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:sorted; 182, argument_list; 182, 183; 182, 184; 182, 192; 183, identifier:result; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:key; 186, lambda; 186, 187; 186, 189; 187, lambda_parameters; 187, 188; 188, identifier:p; 189, attribute; 189, 190; 189, 191; 190, identifier:p; 191, identifier:created; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:reverse; 194, True | def get_posts(self, include_draft=False, filter_functions=None):
def posts_generator(path):
if os.path.isdir(path):
for file in os.listdir(path):
filename, ext = os.path.splitext(file)
format_name = get_standard_format_name(ext[1:])
if format_name is not None and re.match(
r'\d{4}-\d{2}-\d{2}-.+', filename):
post = Post()
post.format = format_name
post.meta, post.raw_content = FileStorage.read_file(
os.path.join(path, file))
post.rel_url = filename.replace('-', '/', 3) + '/'
post.unique_key = '/post/' + post.rel_url
yield post
posts_path = os.path.join(current_app.instance_path, 'posts')
result = filter(lambda p: include_draft or not p.is_draft,
posts_generator(posts_path))
result = self._filter_result(result, filter_functions)
return sorted(result, key=lambda p: p.created, reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:arbitrary_object_to_string; 3, parameters; 3, 4; 4, identifier:a_thing; 5, block; 5, 6; 5, 13; 5, 24; 5, 50; 5, 65; 5, 81; 5, 93; 5, 159; 5, 169; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:a_thing; 9, None; 10, block; 10, 11; 11, return_statement; 11, 12; 12, string:''; 13, if_statement; 13, 14; 13, 21; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:a_thing; 18, attribute; 18, 19; 18, 20; 19, identifier:six; 20, identifier:string_types; 21, block; 21, 22; 22, return_statement; 22, 23; 23, identifier:a_thing; 24, if_statement; 24, 25; 24, 36; 25, boolean_operator:and; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:six; 28, identifier:PY3; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:a_thing; 33, attribute; 33, 34; 33, 35; 34, identifier:six; 35, identifier:binary_type; 36, block; 36, 37; 37, try_statement; 37, 38; 37, 46; 38, block; 38, 39; 39, return_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:a_thing; 43, identifier:decode; 44, argument_list; 44, 45; 45, string:'utf-8'; 46, except_clause; 46, 47; 46, 48; 47, identifier:UnicodeDecodeError; 48, block; 48, 49; 49, pass_statement; 50, try_statement; 50, 51; 50, 58; 51, block; 51, 52; 52, return_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:a_thing; 56, identifier:to_str; 57, argument_list; 58, except_clause; 58, 59; 58, 63; 59, tuple; 59, 60; 59, 61; 59, 62; 60, identifier:AttributeError; 61, identifier:KeyError; 62, identifier:TypeError; 63, block; 63, 64; 64, pass_statement; 65, try_statement; 65, 66; 65, 74; 66, block; 66, 67; 67, return_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:arbitrary_object_to_string; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:a_thing; 73, identifier:a_type; 74, except_clause; 74, 75; 74, 79; 75, tuple; 75, 76; 75, 77; 75, 78; 76, identifier:AttributeError; 77, identifier:KeyError; 78, identifier:TypeError; 79, block; 79, 80; 80, pass_statement; 81, try_statement; 81, 82; 81, 87; 82, block; 82, 83; 83, return_statement; 83, 84; 84, subscript; 84, 85; 84, 86; 85, identifier:known_mapping_type_to_str; 86, identifier:a_thing; 87, except_clause; 87, 88; 87, 91; 88, tuple; 88, 89; 88, 90; 89, identifier:KeyError; 90, identifier:TypeError; 91, block; 91, 92; 92, pass_statement; 93, try_statement; 93, 94; 93, 155; 94, block; 94, 95; 95, if_statement; 95, 96; 95, 104; 96, comparison_operator:not; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:a_thing; 99, identifier:__module__; 100, tuple; 100, 101; 100, 102; 100, 103; 101, string:'__builtin__'; 102, string:'builtins'; 103, string:'exceptions'; 104, block; 104, 105; 104, 147; 105, if_statement; 105, 106; 105, 111; 105, 139; 106, comparison_operator:==; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:a_thing; 109, identifier:__module__; 110, string:"__main__"; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:module_name; 115, parenthesized_expression; 115, 116; 116, call; 116, 117; 116, 137; 117, attribute; 117, 118; 117, 136; 118, call; 118, 119; 118, 133; 119, attribute; 119, 120; 119, 132; 120, subscript; 120, 121; 120, 128; 121, attribute; 121, 122; 121, 127; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:sys; 125, identifier:modules; 126, string:'__main__'; 127, identifier:__file__; 128, slice; 128, 129; 128, 130; 129, colon; 130, unary_operator:-; 130, 131; 131, integer:3; 132, identifier:replace; 133, argument_list; 133, 134; 133, 135; 134, string:'/'; 135, string:'.'; 136, identifier:strip; 137, argument_list; 137, 138; 138, string:'.'; 139, else_clause; 139, 140; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:module_name; 144, attribute; 144, 145; 144, 146; 145, identifier:a_thing; 146, identifier:__module__; 147, return_statement; 147, 148; 148, binary_operator:%; 148, 149; 148, 150; 149, string:"%s.%s"; 150, tuple; 150, 151; 150, 152; 151, identifier:module_name; 152, attribute; 152, 153; 152, 154; 153, identifier:a_thing; 154, identifier:__name__; 155, except_clause; 155, 156; 155, 157; 156, identifier:AttributeError; 157, block; 157, 158; 158, pass_statement; 159, try_statement; 159, 160; 159, 165; 160, block; 160, 161; 161, return_statement; 161, 162; 162, attribute; 162, 163; 162, 164; 163, identifier:a_thing; 164, identifier:__name__; 165, except_clause; 165, 166; 165, 167; 166, identifier:AttributeError; 167, block; 167, 168; 168, pass_statement; 169, return_statement; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:str; 172, argument_list; 172, 173; 173, identifier:a_thing | def arbitrary_object_to_string(a_thing):
if a_thing is None:
return ''
if isinstance(a_thing, six.string_types):
return a_thing
if six.PY3 and isinstance(a_thing, six.binary_type):
try:
return a_thing.decode('utf-8')
except UnicodeDecodeError:
pass
try:
return a_thing.to_str()
except (AttributeError, KeyError, TypeError):
pass
try:
return arbitrary_object_to_string(a_thing.a_type)
except (AttributeError, KeyError, TypeError):
pass
try:
return known_mapping_type_to_str[a_thing]
except (KeyError, TypeError):
pass
try:
if a_thing.__module__ not in ('__builtin__', 'builtins', 'exceptions'):
if a_thing.__module__ == "__main__":
module_name = (
sys.modules['__main__']
.__file__[:-3]
.replace('/', '.')
.strip('.')
)
else:
module_name = a_thing.__module__
return "%s.%s" % (module_name, a_thing.__name__)
except AttributeError:
pass
try:
return a_thing.__name__
except AttributeError:
pass
return str(a_thing) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add_parser; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 16; 9, 24; 9, 32; 9, 38; 9, 50; 9, 66; 9, 84; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:command_name; 13, subscript; 13, 14; 13, 15; 14, identifier:args; 15, integer:0; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:new_kwargs; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:kwargs; 22, identifier:copy; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:new_kwargs; 28, string:'configman_subparsers_option'; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_configman_option; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:new_kwargs; 36, string:'subparser_name'; 37, identifier:command_name; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:subparsers; 41, attribute; 41, 42; 41, 49; 42, attribute; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_configman_option; 47, identifier:foreign_data; 48, identifier:argparse; 49, identifier:subparsers; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:a_subparser; 53, call; 53, 54; 53, 61; 54, attribute; 54, 55; 54, 60; 55, call; 55, 56; 55, 57; 56, identifier:super; 57, argument_list; 57, 58; 57, 59; 58, identifier:ConfigmanSubParsersAction; 59, identifier:self; 60, identifier:add_parser; 61, argument_list; 61, 62; 61, 64; 62, list_splat; 62, 63; 63, identifier:args; 64, dictionary_splat; 64, 65; 65, identifier:new_kwargs; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:subparsers; 70, identifier:command_name; 71, call; 71, 72; 71, 73; 72, identifier:DotDict; 73, argument_list; 73, 74; 74, dictionary; 74, 75; 74, 78; 74, 81; 75, pair; 75, 76; 75, 77; 76, string:"args"; 77, identifier:args; 78, pair; 78, 79; 78, 80; 79, string:"kwargs"; 80, identifier:new_kwargs; 81, pair; 81, 82; 81, 83; 82, string:"subparser"; 83, identifier:a_subparser; 84, return_statement; 84, 85; 85, identifier:a_subparser | def add_parser(self, *args, **kwargs):
command_name = args[0]
new_kwargs = kwargs.copy()
new_kwargs['configman_subparsers_option'] = self._configman_option
new_kwargs['subparser_name'] = command_name
subparsers = self._configman_option.foreign_data.argparse.subparsers
a_subparser = super(ConfigmanSubParsersAction, self).add_parser(
*args,
**new_kwargs
)
subparsers[command_name] = DotDict({
"args": args,
"kwargs": new_kwargs,
"subparser": a_subparser
})
return a_subparser |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_parse_and_sort_accept_header; 3, parameters; 3, 4; 4, identifier:accept_header; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 9, 23; 9, 31; 10, list_comprehension; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:_split_into_mimetype_and_priority; 13, argument_list; 13, 14; 14, identifier:x; 15, for_in_clause; 15, 16; 15, 17; 16, identifier:x; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:accept_header; 20, identifier:split; 21, argument_list; 21, 22; 22, string:','; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:key; 25, lambda; 25, 26; 25, 28; 26, lambda_parameters; 26, 27; 27, identifier:x; 28, subscript; 28, 29; 28, 30; 29, identifier:x; 30, integer:1; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:reverse; 33, True | def _parse_and_sort_accept_header(accept_header):
return sorted([_split_into_mimetype_and_priority(x) for x in accept_header.split(',')],
key=lambda x: x[1], reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_name; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 23; 6, if_statement; 6, 7; 6, 16; 7, boolean_operator:and; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_record; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_record; 15, identifier:sort_name; 16, block; 16, 17; 17, return_statement; 17, 18; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_record; 22, identifier:sort_name; 23, return_statement; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:name | def sort_name(self):
if self._record and self._record.sort_name:
return self._record.sort_name
return self.name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.