sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_cyclic_graph_best_effort; 3, parameters; 3, 4; 3, 5; 4, identifier:graph; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pick_first; 7, string:'head'; 8, block; 8, 9; 8, 13; 8, 19; 8, 42; 8, 46; 8, 84; 8, 88; 8, 126; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ordered; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:visited; 16, call; 16, 17; 16, 18; 17, identifier:set; 18, argument_list; 19, if_statement; 19, 20; 19, 23; 19, 32; 20, comparison_operator:==; 20, 21; 20, 22; 21, identifier:pick_first; 22, string:'head'; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:fst_attr; 28, identifier:snd_attr; 29, tuple; 29, 30; 29, 31; 30, string:'head_node'; 31, string:'update_node'; 32, else_clause; 32, 33; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, pattern_list; 36, 37; 36, 38; 37, identifier:fst_attr; 38, identifier:snd_attr; 39, tuple; 39, 40; 39, 41; 40, string:'update_node'; 41, string:'head_node'; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:current; 45, identifier:FIRST; 46, while_statement; 46, 47; 46, 50; 47, comparison_operator:is; 47, 48; 47, 49; 48, identifier:current; 49, None; 50, block; 50, 51; 50, 58; 50, 68; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:visited; 55, identifier:add; 56, argument_list; 56, 57; 57, identifier:current; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:current; 61, call; 61, 62; 61, 63; 62, identifier:getattr; 63, argument_list; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:graph; 66, identifier:current; 67, identifier:fst_attr; 68, if_statement; 68, 69; 68, 76; 69, boolean_operator:and; 69, 70; 69, 73; 70, comparison_operator:not; 70, 71; 70, 72; 71, identifier:current; 72, identifier:visited; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:current; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:ordered; 81, identifier:append; 82, argument_list; 82, 83; 83, identifier:current; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:current; 87, identifier:FIRST; 88, while_statement; 88, 89; 88, 92; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:current; 91, None; 92, block; 92, 93; 92, 100; 92, 110; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:visited; 97, identifier:add; 98, argument_list; 98, 99; 99, identifier:current; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:current; 103, call; 103, 104; 103, 105; 104, identifier:getattr; 105, argument_list; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:graph; 108, identifier:current; 109, identifier:snd_attr; 110, if_statement; 110, 111; 110, 118; 111, boolean_operator:and; 111, 112; 111, 115; 112, comparison_operator:not; 112, 113; 112, 114; 113, identifier:current; 114, identifier:visited; 115, comparison_operator:is; 115, 116; 115, 117; 116, identifier:current; 117, None; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:ordered; 123, identifier:append; 124, argument_list; 124, 125; 125, identifier:current; 126, return_statement; 126, 127; 127, identifier:ordered
def sort_cyclic_graph_best_effort(graph, pick_first='head'): ordered = [] visited = set() if pick_first == 'head': fst_attr, snd_attr = ('head_node', 'update_node') else: fst_attr, snd_attr = ('update_node', 'head_node') current = FIRST while current is not None: visited.add(current) current = getattr(graph[current], fst_attr) if current not in visited and current is not None: ordered.append(current) current = FIRST while current is not None: visited.add(current) current = getattr(graph[current], snd_attr) if current not in visited and current is not None: ordered.append(current) return ordered
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:circlescan; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:x0; 5, identifier:y0; 6, identifier:r1; 7, identifier:r2; 8, block; 8, 9; 8, 19; 8, 29; 8, 33; 8, 43; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:<; 10, 11; 10, 12; 11, identifier:r1; 12, integer:0; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:ValueError; 17, argument_list; 17, 18; 18, string:"Initial radius must be non-negative"; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:<; 20, 21; 20, 22; 21, identifier:r2; 22, integer:0; 23, block; 23, 24; 24, raise_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:ValueError; 27, argument_list; 27, 28; 28, string:"Final radius must be non-negative"; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:previous; 32, list:[]; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:rstep; 36, conditional_expression:if; 36, 37; 36, 38; 36, 41; 37, integer:1; 38, comparison_operator:>=; 38, 39; 38, 40; 39, identifier:r2; 40, identifier:r1; 41, unary_operator:-; 41, 42; 42, integer:1; 43, for_statement; 43, 44; 43, 45; 43, 53; 44, identifier:distance; 45, call; 45, 46; 45, 47; 46, identifier:range; 47, argument_list; 47, 48; 47, 49; 47, 52; 48, identifier:r1; 49, binary_operator:+; 49, 50; 49, 51; 50, identifier:r2; 51, identifier:rstep; 52, identifier:rstep; 53, block; 53, 54; 54, if_statement; 54, 55; 54, 58; 54, 64; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:distance; 57, integer:0; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, yield; 60, 61; 61, expression_list; 61, 62; 61, 63; 62, identifier:x0; 63, identifier:y0; 64, else_clause; 64, 65; 65, block; 65, 66; 65, 70; 65, 158; 65, 165; 65, 169; 65, 321; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:a; 69, float:0.707107; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:rotations; 73, dictionary; 73, 74; 73, 83; 73, 93; 73, 103; 73, 115; 73, 126; 73, 138; 73, 148; 74, pair; 74, 75; 74, 76; 75, integer:0; 76, list:[[ 1, 0], [ 0, 1]]; 76, 77; 76, 80; 77, list:[ 1, 0]; 77, 78; 77, 79; 78, integer:1; 79, integer:0; 80, list:[ 0, 1]; 80, 81; 80, 82; 81, integer:0; 82, integer:1; 83, pair; 83, 84; 83, 85; 84, integer:1; 85, list:[[ a, a], [-a, a]]; 85, 86; 85, 89; 86, list:[ a, a]; 86, 87; 86, 88; 87, identifier:a; 88, identifier:a; 89, list:[-a, a]; 89, 90; 89, 92; 90, unary_operator:-; 90, 91; 91, identifier:a; 92, identifier:a; 93, pair; 93, 94; 93, 95; 94, integer:2; 95, list:[[ 0, 1], [-1, 0]]; 95, 96; 95, 99; 96, list:[ 0, 1]; 96, 97; 96, 98; 97, integer:0; 98, integer:1; 99, list:[-1, 0]; 99, 100; 99, 102; 100, unary_operator:-; 100, 101; 101, integer:1; 102, integer:0; 103, pair; 103, 104; 103, 105; 104, integer:3; 105, list:[[-a, a], [-a,-a]]; 105, 106; 105, 110; 106, list:[-a, a]; 106, 107; 106, 109; 107, unary_operator:-; 107, 108; 108, identifier:a; 109, identifier:a; 110, list:[-a,-a]; 110, 111; 110, 113; 111, unary_operator:-; 111, 112; 112, identifier:a; 113, unary_operator:-; 113, 114; 114, identifier:a; 115, pair; 115, 116; 115, 117; 116, integer:4; 117, list:[[-1, 0], [ 0,-1]]; 117, 118; 117, 122; 118, list:[-1, 0]; 118, 119; 118, 121; 119, unary_operator:-; 119, 120; 120, integer:1; 121, integer:0; 122, list:[ 0,-1]; 122, 123; 122, 124; 123, integer:0; 124, unary_operator:-; 124, 125; 125, integer:1; 126, pair; 126, 127; 126, 128; 127, integer:5; 128, list:[[-a,-a], [ a,-a]]; 128, 129; 128, 134; 129, list:[-a,-a]; 129, 130; 129, 132; 130, unary_operator:-; 130, 131; 131, identifier:a; 132, unary_operator:-; 132, 133; 133, identifier:a; 134, list:[ a,-a]; 134, 135; 134, 136; 135, identifier:a; 136, unary_operator:-; 136, 137; 137, identifier:a; 138, pair; 138, 139; 138, 140; 139, integer:6; 140, list:[[ 0,-1], [ 1, 0]]; 140, 141; 140, 145; 141, list:[ 0,-1]; 141, 142; 141, 143; 142, integer:0; 143, unary_operator:-; 143, 144; 144, integer:1; 145, list:[ 1, 0]; 145, 146; 145, 147; 146, integer:1; 147, integer:0; 148, pair; 148, 149; 148, 150; 149, integer:7; 150, list:[[ a,-a], [ a, a]]; 150, 151; 150, 155; 151, list:[ a,-a]; 151, 152; 151, 153; 152, identifier:a; 153, unary_operator:-; 153, 154; 154, identifier:a; 155, list:[ a, a]; 155, 156; 155, 157; 156, identifier:a; 157, identifier:a; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:nangles; 161, call; 161, 162; 161, 163; 162, identifier:len; 163, argument_list; 163, 164; 164, identifier:rotations; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:current; 168, list:[]; 169, for_statement; 169, 170; 169, 171; 169, 175; 170, identifier:angle; 171, call; 171, 172; 171, 173; 172, identifier:range; 173, argument_list; 173, 174; 174, identifier:nangles; 175, block; 175, 176; 175, 180; 175, 184; 175, 190; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:x; 179, integer:0; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:y; 183, identifier:distance; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:d; 187, binary_operator:-; 187, 188; 187, 189; 188, integer:1; 189, identifier:distance; 190, while_statement; 190, 191; 190, 194; 191, comparison_operator:<; 191, 192; 191, 193; 192, identifier:x; 193, identifier:y; 194, block; 194, 195; 194, 217; 194, 239; 194, 245; 194, 251; 194, 269; 194, 286; 194, 317; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:xr; 198, binary_operator:+; 198, 199; 198, 208; 199, binary_operator:*; 199, 200; 199, 207; 200, subscript; 200, 201; 200, 206; 201, subscript; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:rotations; 204, identifier:angle; 205, integer:0; 206, integer:0; 207, identifier:x; 208, binary_operator:*; 208, 209; 208, 216; 209, subscript; 209, 210; 209, 215; 210, subscript; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:rotations; 213, identifier:angle; 214, integer:0; 215, integer:1; 216, identifier:y; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:yr; 220, binary_operator:+; 220, 221; 220, 230; 221, binary_operator:*; 221, 222; 221, 229; 222, subscript; 222, 223; 222, 228; 223, subscript; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:rotations; 226, identifier:angle; 227, integer:1; 228, integer:0; 229, identifier:x; 230, binary_operator:*; 230, 231; 230, 238; 231, subscript; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:rotations; 235, identifier:angle; 236, integer:1; 237, integer:1; 238, identifier:y; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:xr; 242, binary_operator:+; 242, 243; 242, 244; 243, identifier:x0; 244, identifier:xr; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:yr; 248, binary_operator:+; 248, 249; 248, 250; 249, identifier:y0; 250, identifier:yr; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:point; 254, tuple; 254, 255; 254, 262; 255, call; 255, 256; 255, 257; 256, identifier:int; 257, argument_list; 257, 258; 258, call; 258, 259; 258, 260; 259, identifier:round; 260, argument_list; 260, 261; 261, identifier:xr; 262, call; 262, 263; 262, 264; 263, identifier:int; 264, argument_list; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:round; 267, argument_list; 267, 268; 268, identifier:yr; 269, if_statement; 269, 270; 269, 273; 270, comparison_operator:not; 270, 271; 270, 272; 271, identifier:point; 272, identifier:previous; 273, block; 273, 274; 273, 279; 274, expression_statement; 274, 275; 275, yield; 275, 276; 276, expression_list; 276, 277; 276, 278; 277, identifier:xr; 278, identifier:yr; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:current; 283, identifier:append; 284, argument_list; 284, 285; 285, identifier:point; 286, if_statement; 286, 287; 286, 291; 286, 300; 287, parenthesized_expression; 287, 288; 288, comparison_operator:<; 288, 289; 288, 290; 289, identifier:d; 290, integer:0; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, augmented_assignment:+=; 293, 294; 293, 295; 294, identifier:d; 295, binary_operator:+; 295, 296; 295, 297; 296, integer:3; 297, binary_operator:*; 297, 298; 297, 299; 298, integer:2; 299, identifier:x; 300, else_clause; 300, 301; 301, block; 301, 302; 301, 313; 302, expression_statement; 302, 303; 303, augmented_assignment:+=; 303, 304; 303, 305; 304, identifier:d; 305, binary_operator:-; 305, 306; 305, 307; 306, integer:5; 307, binary_operator:*; 307, 308; 307, 309; 308, integer:2; 309, parenthesized_expression; 309, 310; 310, binary_operator:-; 310, 311; 310, 312; 311, identifier:y; 312, identifier:x; 313, expression_statement; 313, 314; 314, augmented_assignment:-=; 314, 315; 314, 316; 315, identifier:y; 316, integer:1; 317, expression_statement; 317, 318; 318, augmented_assignment:+=; 318, 319; 318, 320; 319, identifier:x; 320, integer:1; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:previous; 324, identifier:current
def circlescan(x0, y0, r1, r2): if r1 < 0: raise ValueError("Initial radius must be non-negative") if r2 < 0: raise ValueError("Final radius must be non-negative") previous = [] rstep = 1 if r2 >= r1 else -1 for distance in range(r1, r2 + rstep, rstep): if distance == 0: yield x0, y0 else: a = 0.707107 rotations = {0: [[ 1, 0], [ 0, 1]], 1: [[ a, a], [-a, a]], 2: [[ 0, 1], [-1, 0]], 3: [[-a, a], [-a,-a]], 4: [[-1, 0], [ 0,-1]], 5: [[-a,-a], [ a,-a]], 6: [[ 0,-1], [ 1, 0]], 7: [[ a,-a], [ a, a]]} nangles = len(rotations) current = [] for angle in range(nangles): x = 0 y = distance d = 1 - distance while x < y: xr = rotations[angle][0][0]*x + rotations[angle][0][1]*y yr = rotations[angle][1][0]*x + rotations[angle][1][1]*y xr = x0 + xr yr = y0 + yr point = (int(round(xr)), int(round(yr))) if point not in previous: yield xr, yr current.append(point) if (d < 0): d += 3 + 2 * x else: d += 5 - 2 * (y-x) y -= 1 x += 1 previous = current
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:ringscan; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:x0; 5, identifier:y0; 6, identifier:r1; 7, identifier:r2; 8, default_parameter; 8, 9; 8, 10; 9, identifier:metric; 10, identifier:chebyshev; 11, block; 11, 12; 11, 22; 11, 32; 11, 45; 11, 49; 11, 99; 11, 106; 11, 112; 11, 122; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:<; 13, 14; 13, 15; 14, identifier:r1; 15, integer:0; 16, block; 16, 17; 17, raise_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:ValueError; 20, argument_list; 20, 21; 21, string:"Initial radius must be non-negative"; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:<; 23, 24; 23, 25; 24, identifier:r2; 25, integer:0; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:ValueError; 30, argument_list; 30, 31; 31, string:"Final radius must be non-negative"; 32, if_statement; 32, 33; 32, 39; 33, not_operator; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:hasattr; 36, argument_list; 36, 37; 36, 38; 37, identifier:metric; 38, string:"__call__"; 39, block; 39, 40; 40, raise_statement; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:TypeError; 43, argument_list; 43, 44; 44, string:"Metric not callable"; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:direction; 48, integer:0; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:steps; 52, dictionary; 52, 53; 52, 58; 52, 64; 52, 70; 52, 77; 52, 83; 52, 89; 52, 94; 53, pair; 53, 54; 53, 55; 54, integer:0; 55, list:[ 1, 0]; 55, 56; 55, 57; 56, integer:1; 57, integer:0; 58, pair; 58, 59; 58, 60; 59, integer:1; 60, list:[ 1,-1]; 60, 61; 60, 62; 61, integer:1; 62, unary_operator:-; 62, 63; 63, integer:1; 64, pair; 64, 65; 64, 66; 65, integer:2; 66, list:[ 0,-1]; 66, 67; 66, 68; 67, integer:0; 68, unary_operator:-; 68, 69; 69, integer:1; 70, pair; 70, 71; 70, 72; 71, integer:3; 72, list:[-1,-1]; 72, 73; 72, 75; 73, unary_operator:-; 73, 74; 74, integer:1; 75, unary_operator:-; 75, 76; 76, integer:1; 77, pair; 77, 78; 77, 79; 78, integer:4; 79, list:[-1, 0]; 79, 80; 79, 82; 80, unary_operator:-; 80, 81; 81, integer:1; 82, integer:0; 83, pair; 83, 84; 83, 85; 84, integer:5; 85, list:[-1, 1]; 85, 86; 85, 88; 86, unary_operator:-; 86, 87; 87, integer:1; 88, integer:1; 89, pair; 89, 90; 89, 91; 90, integer:6; 91, list:[ 0, 1]; 91, 92; 91, 93; 92, integer:0; 93, integer:1; 94, pair; 94, 95; 94, 96; 95, integer:7; 96, list:[ 1, 1]; 96, 97; 96, 98; 97, integer:1; 98, integer:1; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:nsteps; 102, call; 102, 103; 102, 104; 103, identifier:len; 104, argument_list; 104, 105; 105, identifier:steps; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:center; 109, list:[x0, y0]; 109, 110; 109, 111; 110, identifier:x0; 111, identifier:y0; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:rstep; 115, conditional_expression:if; 115, 116; 115, 117; 115, 120; 116, integer:1; 117, comparison_operator:>=; 117, 118; 117, 119; 118, identifier:r2; 119, identifier:r1; 120, unary_operator:-; 120, 121; 121, integer:1; 122, for_statement; 122, 123; 122, 124; 122, 132; 123, identifier:distance; 124, call; 124, 125; 124, 126; 125, identifier:range; 126, argument_list; 126, 127; 126, 128; 126, 131; 127, identifier:r1; 128, binary_operator:+; 128, 129; 128, 130; 129, identifier:r2; 130, identifier:rstep; 131, identifier:rstep; 132, block; 132, 133; 132, 141; 132, 145; 132, 149; 132, 238; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:initial; 136, list:[x0, y0 + distance]; 136, 137; 136, 138; 137, identifier:x0; 138, binary_operator:+; 138, 139; 138, 140; 139, identifier:y0; 140, identifier:distance; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:current; 144, identifier:initial; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:ntrys; 148, integer:0; 149, while_statement; 149, 150; 149, 151; 150, True; 151, block; 151, 152; 151, 167; 151, 186; 151, 215; 151, 219; 151, 228; 151, 232; 152, if_statement; 152, 153; 152, 156; 153, comparison_operator:==; 153, 154; 153, 155; 154, identifier:distance; 155, integer:0; 156, block; 156, 157; 156, 166; 157, expression_statement; 157, 158; 158, yield; 158, 159; 159, expression_list; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:current; 162, integer:0; 163, subscript; 163, 164; 163, 165; 164, identifier:current; 165, integer:1; 166, break_statement; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:nextpoint; 170, list_comprehension; 170, 171; 170, 180; 171, binary_operator:+; 171, 172; 171, 175; 172, subscript; 172, 173; 172, 174; 173, identifier:current; 174, identifier:i; 175, subscript; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:steps; 178, identifier:direction; 179, identifier:i; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:i; 182, call; 182, 183; 182, 184; 183, identifier:range; 184, argument_list; 184, 185; 185, integer:2; 186, if_statement; 186, 187; 186, 194; 187, comparison_operator:!=; 187, 188; 187, 193; 188, call; 188, 189; 188, 190; 189, identifier:metric; 190, argument_list; 190, 191; 190, 192; 191, identifier:center; 192, identifier:nextpoint; 193, identifier:distance; 194, block; 194, 195; 194, 199; 194, 205; 194, 214; 195, expression_statement; 195, 196; 196, augmented_assignment:+=; 196, 197; 196, 198; 197, identifier:ntrys; 198, integer:1; 199, if_statement; 199, 200; 199, 203; 200, comparison_operator:==; 200, 201; 200, 202; 201, identifier:ntrys; 202, identifier:nsteps; 203, block; 203, 204; 204, break_statement; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:direction; 208, binary_operator:%; 208, 209; 208, 213; 209, parenthesized_expression; 209, 210; 210, binary_operator:+; 210, 211; 210, 212; 211, identifier:direction; 212, integer:1; 213, identifier:nsteps; 214, continue_statement; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:ntrys; 218, integer:0; 219, expression_statement; 219, 220; 220, yield; 220, 221; 221, expression_list; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:current; 224, integer:0; 225, subscript; 225, 226; 225, 227; 226, identifier:current; 227, integer:1; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:current; 231, identifier:nextpoint; 232, if_statement; 232, 233; 232, 236; 233, comparison_operator:==; 233, 234; 233, 235; 234, identifier:current; 235, identifier:initial; 236, block; 236, 237; 237, break_statement; 238, if_statement; 238, 239; 238, 242; 239, comparison_operator:==; 239, 240; 239, 241; 240, identifier:ntrys; 241, identifier:nsteps; 242, block; 242, 243; 243, break_statement
def ringscan(x0, y0, r1, r2, metric=chebyshev): if r1 < 0: raise ValueError("Initial radius must be non-negative") if r2 < 0: raise ValueError("Final radius must be non-negative") if not hasattr(metric, "__call__"): raise TypeError("Metric not callable") direction = 0 steps = {0: [ 1, 0], 1: [ 1,-1], 2: [ 0,-1], 3: [-1,-1], 4: [-1, 0], 5: [-1, 1], 6: [ 0, 1], 7: [ 1, 1]} nsteps = len(steps) center = [x0, y0] rstep = 1 if r2 >= r1 else -1 for distance in range(r1, r2 + rstep, rstep): initial = [x0, y0 + distance] current = initial ntrys = 0 while True: if distance == 0: yield current[0], current[1] break nextpoint = [current[i] + steps[direction][i] for i in range(2)] if metric(center, nextpoint) != distance: ntrys += 1 if ntrys == nsteps: break direction = (direction + 1) % nsteps continue ntrys = 0 yield current[0], current[1] current = nextpoint if current == initial: break if ntrys == nsteps: break
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:fetch; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:callback; 6, block; 6, 7; 6, 22; 6, 32; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:session; 10, call; 10, 11; 10, 18; 11, attribute; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:client; 16, identifier:sync; 17, identifier:start; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:device_uuid; 22, if_statement; 22, 23; 22, 30; 23, boolean_operator:or; 23, 24; 23, 27; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:session; 26, None; 27, comparison_operator:not; 27, 28; 27, 29; 28, string:'id'; 29, identifier:session; 30, block; 30, 31; 31, return_statement; 32, while_statement; 32, 33; 32, 34; 33, True; 34, block; 34, 35; 34, 53; 34, 58; 34, 62; 34, 90; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:queue_items; 38, call; 38, 39; 38, 46; 39, attribute; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:client; 44, identifier:sync; 45, identifier:fetch; 46, argument_list; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:device_uuid; 50, subscript; 50, 51; 50, 52; 51, identifier:session; 52, string:'id'; 53, if_statement; 53, 54; 53, 56; 54, not_operator; 54, 55; 55, identifier:queue_items; 56, block; 56, 57; 57, break_statement; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:ack_keys; 61, list:[]; 62, for_statement; 62, 63; 62, 64; 62, 65; 63, identifier:item; 64, identifier:queue_items; 65, block; 65, 66; 66, if_statement; 66, 67; 66, 76; 67, call; 67, 68; 67, 69; 68, identifier:callback; 69, argument_list; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:item; 72, string:'meta'; 73, subscript; 73, 74; 73, 75; 74, identifier:item; 75, string:'data'; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:ack_keys; 81, identifier:append; 82, argument_list; 82, 83; 83, subscript; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, subscript; 85, 86; 85, 87; 86, identifier:item; 87, string:'meta'; 88, string:'sync'; 89, string:'ack_key'; 90, if_statement; 90, 91; 90, 92; 91, identifier:ack_keys; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 102; 95, attribute; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:client; 100, identifier:sync; 101, identifier:ack; 102, argument_list; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:device_uuid; 106, identifier:ack_keys
def fetch(self, callback): session = self.client.sync.start(self.device_uuid) if session is None or 'id' not in session: return while True: queue_items = self.client.sync.fetch(self.device_uuid, session['id']) if not queue_items: break ack_keys = [] for item in queue_items: if callback(item['meta'], item['data']): ack_keys.append(item['meta']['sync']['ack_key']) if ack_keys: self.client.sync.ack(self.device_uuid, ack_keys)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:define_residues_for_plotting_traj; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:analysis_cutoff; 6, block; 6, 7; 6, 13; 6, 55; 6, 86; 6, 128; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:residue_counts_fraction; 12, dictionary; 13, for_statement; 13, 14; 13, 15; 13, 18; 14, identifier:traj; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:residue_counts; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 26; 21, subscript; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:residue_counts_fraction; 25, identifier:traj; 26, dictionary_comprehension; 26, 27; 26, 42; 27, pair; 27, 28; 27, 29; 28, identifier:residue; 29, binary_operator:/; 29, 30; 29, 34; 30, call; 30, 31; 30, 32; 31, identifier:float; 32, argument_list; 32, 33; 33, identifier:values; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:contacts_per_timeframe; 41, identifier:traj; 42, for_in_clause; 42, 43; 42, 46; 43, pattern_list; 43, 44; 43, 45; 44, identifier:residue; 45, identifier:values; 46, call; 46, 47; 46, 54; 47, attribute; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:residue_counts; 52, identifier:traj; 53, identifier:items; 54, argument_list; 55, for_statement; 55, 56; 55, 57; 55, 60; 56, identifier:traj; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:residue_counts_fraction; 60, block; 60, 61; 61, for_statement; 61, 62; 61, 63; 61, 68; 62, identifier:residue; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:residue_counts_fraction; 67, identifier:traj; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 78; 71, attribute; 71, 72; 71, 77; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:frequency; 76, identifier:residue; 77, identifier:append; 78, argument_list; 78, 79; 79, subscript; 79, 80; 79, 85; 80, subscript; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:residue_counts_fraction; 84, identifier:traj; 85, identifier:residue; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:topology_data; 92, identifier:dict_of_plotted_res; 93, dictionary_comprehension; 93, 94; 93, 101; 93, 106; 94, pair; 94, 95; 94, 96; 95, identifier:i; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:frequency; 100, identifier:i; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:i; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:frequency; 106, if_clause; 106, 107; 107, comparison_operator:>; 107, 108; 107, 116; 108, call; 108, 109; 108, 110; 109, identifier:sum; 110, argument_list; 110, 111; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:frequency; 115, identifier:i; 116, parenthesized_expression; 116, 117; 117, binary_operator:*; 117, 118; 117, 127; 118, call; 118, 119; 118, 120; 119, identifier:int; 120, argument_list; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:len; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:trajectory; 127, identifier:analysis_cutoff; 128, assert_statement; 128, 129; 128, 139; 129, comparison_operator:!=; 129, 130; 129, 138; 130, call; 130, 131; 130, 132; 131, identifier:len; 132, argument_list; 132, 133; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:topology_data; 137, identifier:dict_of_plotted_res; 138, integer:0; 139, binary_operator:+; 139, 140; 139, 173; 140, binary_operator:+; 140, 141; 140, 159; 141, binary_operator:+; 141, 142; 141, 158; 142, binary_operator:+; 142, 143; 142, 144; 143, string:"Nothing to draw for this ligand:(residue number: "; 144, call; 144, 145; 144, 146; 145, identifier:str; 146, argument_list; 146, 147; 147, subscript; 147, 148; 147, 157; 148, attribute; 148, 149; 148, 156; 149, attribute; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:topology_data; 154, identifier:universe; 155, identifier:ligand; 156, identifier:resids; 157, integer:0; 158, string:" on the chain "; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, subscript; 162, 163; 162, 172; 163, attribute; 163, 164; 163, 171; 164, attribute; 164, 165; 164, 170; 165, attribute; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:topology_data; 169, identifier:universe; 170, identifier:ligand; 171, identifier:segids; 172, integer:0; 173, string:") - try reducing the analysis cutoff."
def define_residues_for_plotting_traj(self, analysis_cutoff): self.residue_counts_fraction = {} for traj in self.residue_counts: self.residue_counts_fraction[traj] = {residue:float(values)/len(self.contacts_per_timeframe[traj]) for residue,values in self.residue_counts[traj].items()} for traj in self.residue_counts_fraction: for residue in self.residue_counts_fraction[traj]: self.frequency[residue].append(self.residue_counts_fraction[traj][residue]) self.topology_data.dict_of_plotted_res = {i:self.frequency[i] for i in self.frequency if sum(self.frequency[i])>(int(len(self.trajectory))*analysis_cutoff)} assert len(self.topology_data.dict_of_plotted_res)!=0,"Nothing to draw for this ligand:(residue number: "+ str(self.topology_data.universe.ligand.resids[0]) +" on the chain "+ str(self.topology_data.universe.ligand.segids[0]) +") - try reducing the analysis cutoff."
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:find_donors_and_acceptors_in_ligand; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 22; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:atom_names; 9, list_comprehension; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:x; 12, identifier:name; 13, for_in_clause; 13, 14; 13, 15; 14, identifier:x; 15, attribute; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:topology_data; 20, identifier:universe; 21, identifier:ligand; 22, try_statement; 22, 23; 22, 86; 23, block; 23, 24; 23, 55; 24, for_statement; 24, 25; 24, 26; 24, 41; 25, identifier:atom; 26, call; 26, 27; 26, 34; 27, attribute; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:topology_data; 32, identifier:mol; 33, identifier:GetSubstructMatches; 34, argument_list; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:HDonorSmarts; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:uniquify; 40, integer:1; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:donors; 48, identifier:append; 49, argument_list; 49, 50; 50, subscript; 50, 51; 50, 52; 51, identifier:atom_names; 52, subscript; 52, 53; 52, 54; 53, identifier:atom; 54, integer:0; 55, for_statement; 55, 56; 55, 57; 55, 72; 56, identifier:atom; 57, call; 57, 58; 57, 65; 58, attribute; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:topology_data; 63, identifier:mol; 64, identifier:GetSubstructMatches; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:HAcceptorSmarts; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:uniquify; 71, integer:1; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:acceptors; 79, identifier:append; 80, argument_list; 80, 81; 81, subscript; 81, 82; 81, 83; 82, identifier:atom_names; 83, subscript; 83, 84; 83, 85; 84, identifier:atom; 85, integer:0; 86, except_clause; 86, 87; 86, 91; 87, as_pattern; 87, 88; 87, 89; 88, identifier:Exception; 89, as_pattern_target; 89, 90; 90, identifier:e; 91, block; 91, 92; 91, 101; 91, 107; 91, 113; 91, 140; 91, 144; 91, 155; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:m; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:Chem; 98, identifier:MolFromPDBFile; 99, argument_list; 99, 100; 100, string:"lig.pdb"; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:donors; 106, list:[]; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:acceptors; 112, list:[]; 113, for_statement; 113, 114; 113, 115; 113, 126; 114, identifier:atom; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:m; 118, identifier:GetSubstructMatches; 119, argument_list; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:HDonorSmarts; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:uniquify; 125, integer:1; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:donors; 133, identifier:append; 134, argument_list; 134, 135; 135, subscript; 135, 136; 135, 137; 136, identifier:atom_names; 137, subscript; 137, 138; 137, 139; 138, identifier:atom; 139, integer:0; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:haccep; 143, string:"[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N;v3;!$(N-*=!@[O,N,P,S])]),$([nH0,o,s;+0])]"; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:HAcceptorSmarts; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:Chem; 152, identifier:MolFromSmarts; 153, argument_list; 153, 154; 154, identifier:haccep; 155, for_statement; 155, 156; 155, 157; 155, 168; 156, identifier:atom; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:m; 160, identifier:GetSubstructMatches; 161, argument_list; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:HAcceptorSmarts; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:uniquify; 167, integer:1; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:acceptors; 175, identifier:append; 176, argument_list; 176, 177; 177, subscript; 177, 178; 177, 179; 178, identifier:atom_names; 179, subscript; 179, 180; 179, 181; 180, identifier:atom; 181, integer:0
def find_donors_and_acceptors_in_ligand(self): atom_names=[x.name for x in self.topology_data.universe.ligand] try: for atom in self.topology_data.mol.GetSubstructMatches(self.HDonorSmarts, uniquify=1): self.donors.append(atom_names[atom[0]]) for atom in self.topology_data.mol.GetSubstructMatches(self.HAcceptorSmarts, uniquify=1): self.acceptors.append(atom_names[atom[0]]) except Exception as e: m = Chem.MolFromPDBFile("lig.pdb") self.donors = [] self.acceptors = [] for atom in m.GetSubstructMatches(self.HDonorSmarts, uniquify=1): self.donors.append(atom_names[atom[0]]) haccep = "[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N;v3;!$(N-*=!@[O,N,P,S])]),$([nH0,o,s;+0])]" self.HAcceptorSmarts = Chem.MolFromSmarts(haccep) for atom in m.GetSubstructMatches(self.HAcceptorSmarts, uniquify=1): self.acceptors.append(atom_names[atom[0]])
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:determine_hbonds_for_drawing; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:analysis_cutoff; 6, block; 6, 7; 6, 16; 6, 83; 6, 120; 6, 126; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:frequency; 12, call; 12, 13; 12, 14; 13, identifier:defaultdict; 14, argument_list; 14, 15; 15, identifier:int; 16, for_statement; 16, 17; 16, 18; 16, 21; 17, identifier:traj; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:hbonds_by_type; 21, block; 21, 22; 22, for_statement; 22, 23; 22, 24; 22, 29; 23, identifier:bond; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:hbonds_by_type; 28, identifier:traj; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 36; 30, 59; 31, comparison_operator:!=; 31, 32; 31, 35; 32, subscript; 32, 33; 32, 34; 33, identifier:bond; 34, string:"donor_resnm"; 35, string:"LIG"; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, augmented_assignment:+=; 38, 39; 38, 56; 39, subscript; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:frequency; 43, tuple; 43, 44; 43, 47; 43, 50; 43, 53; 44, subscript; 44, 45; 44, 46; 45, identifier:bond; 46, string:"donor_idx"; 47, subscript; 47, 48; 47, 49; 48, identifier:bond; 49, string:"acceptor_atom"; 50, subscript; 50, 51; 50, 52; 51, identifier:bond; 52, string:"donor_atom"; 53, subscript; 53, 54; 53, 55; 54, identifier:bond; 55, string:"acceptor_idx"; 56, subscript; 56, 57; 56, 58; 57, identifier:bond; 58, string:"frequency"; 59, else_clause; 59, 60; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, augmented_assignment:+=; 62, 63; 62, 80; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:frequency; 67, tuple; 67, 68; 67, 71; 67, 74; 67, 77; 68, subscript; 68, 69; 68, 70; 69, identifier:bond; 70, string:"acceptor_idx"; 71, subscript; 71, 72; 71, 73; 72, identifier:bond; 73, string:"donor_atom"; 74, subscript; 74, 75; 74, 76; 75, identifier:bond; 76, string:"acceptor_atom"; 77, subscript; 77, 78; 77, 79; 78, identifier:bond; 79, string:"donor_idx"; 80, subscript; 80, 81; 80, 82; 81, identifier:bond; 82, string:"frequency"; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:frequency; 88, dictionary_comprehension; 88, 89; 88, 96; 88, 101; 89, pair; 89, 90; 89, 91; 90, identifier:i; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:frequency; 95, identifier:i; 96, for_in_clause; 96, 97; 96, 98; 97, identifier:i; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:frequency; 101, if_clause; 101, 102; 102, comparison_operator:>; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:frequency; 107, identifier:i; 108, parenthesized_expression; 108, 109; 109, binary_operator:*; 109, 110; 109, 119; 110, call; 110, 111; 110, 112; 111, identifier:int; 112, argument_list; 112, 113; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:trajectory; 119, identifier:analysis_cutoff; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:hbonds_for_drawing; 125, dictionary; 126, for_statement; 126, 127; 126, 128; 126, 131; 127, identifier:bond; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:frequency; 131, block; 131, 132; 131, 138; 131, 248; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:atomname; 135, subscript; 135, 136; 135, 137; 136, identifier:bond; 137, integer:1; 138, if_statement; 138, 139; 138, 154; 138, 159; 139, boolean_operator:or; 139, 140; 139, 147; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:atomname; 143, identifier:startswith; 144, argument_list; 144, 145; 144, 146; 145, string:"O"; 146, integer:0; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:atomname; 150, identifier:startswith; 151, argument_list; 151, 152; 151, 153; 152, string:"N"; 153, integer:0; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:lig_atom; 158, identifier:atomname; 159, else_clause; 159, 160; 160, block; 160, 161; 160, 190; 160, 203; 160, 219; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:atomindex; 164, subscript; 164, 165; 164, 189; 165, list_comprehension; 165, 166; 165, 167; 165, 183; 166, identifier:index; 167, for_in_clause; 167, 168; 167, 171; 168, pattern_list; 168, 169; 168, 170; 169, identifier:index; 170, identifier:atom; 171, call; 171, 172; 171, 173; 172, identifier:enumerate; 173, argument_list; 173, 174; 174, attribute; 174, 175; 174, 182; 175, attribute; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:topology_data; 180, identifier:universe; 181, identifier:ligand; 182, identifier:atoms; 183, if_clause; 183, 184; 184, comparison_operator:==; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:atom; 187, identifier:name; 188, identifier:atomname; 189, integer:0; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:rdkit_atom; 193, call; 193, 194; 193, 201; 194, attribute; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:topology_data; 199, identifier:mol; 200, identifier:GetAtomWithIdx; 201, argument_list; 201, 202; 202, identifier:atomindex; 203, for_statement; 203, 204; 203, 205; 203, 210; 204, identifier:neigh; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:rdkit_atom; 208, identifier:GetNeighbors; 209, argument_list; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:neigh_atom_id; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:neigh; 217, identifier:GetIdx; 218, argument_list; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:lig_atom; 222, subscript; 222, 223; 222, 247; 223, list_comprehension; 223, 224; 223, 227; 223, 243; 224, attribute; 224, 225; 224, 226; 225, identifier:atom; 226, identifier:name; 227, for_in_clause; 227, 228; 227, 231; 228, pattern_list; 228, 229; 228, 230; 229, identifier:index; 230, identifier:atom; 231, call; 231, 232; 231, 233; 232, identifier:enumerate; 233, argument_list; 233, 234; 234, attribute; 234, 235; 234, 242; 235, attribute; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:topology_data; 240, identifier:universe; 241, identifier:ligand; 242, identifier:atoms; 243, if_clause; 243, 244; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:index; 246, identifier:neigh_atom_id; 247, integer:0; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 265; 250, subscript; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:hbonds_for_drawing; 254, tuple; 254, 255; 254, 258; 254, 259; 254, 262; 255, subscript; 255, 256; 255, 257; 256, identifier:bond; 257, integer:0; 258, identifier:lig_atom; 259, subscript; 259, 260; 259, 261; 260, identifier:bond; 261, integer:2; 262, subscript; 262, 263; 262, 264; 263, identifier:bond; 264, integer:3; 265, subscript; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:frequency; 269, identifier:bond
def determine_hbonds_for_drawing(self, analysis_cutoff): self.frequency = defaultdict(int) for traj in self.hbonds_by_type: for bond in self.hbonds_by_type[traj]: if bond["donor_resnm"]!="LIG": self.frequency[(bond["donor_idx"],bond["acceptor_atom"],bond["donor_atom"],bond["acceptor_idx"])] += bond["frequency"] else: self.frequency[(bond["acceptor_idx"],bond["donor_atom"],bond["acceptor_atom"],bond["donor_idx"])] += bond["frequency"] self.frequency = {i:self.frequency[i] for i in self.frequency if self.frequency[i]>(int(len(self.trajectory))*analysis_cutoff)} self.hbonds_for_drawing = {} for bond in self.frequency: atomname = bond[1] if atomname.startswith("O",0) or atomname.startswith("N",0): lig_atom=atomname else: atomindex = [index for index,atom in enumerate(self.topology_data.universe.ligand.atoms) if atom.name==atomname][0] rdkit_atom = self.topology_data.mol.GetAtomWithIdx(atomindex) for neigh in rdkit_atom.GetNeighbors(): neigh_atom_id = neigh.GetIdx() lig_atom = [atom.name for index,atom in enumerate(self.topology_data.universe.ligand.atoms) if index==neigh_atom_id][0] self.hbonds_for_drawing[(bond[0],lig_atom,bond[2],bond[3])]=self.frequency[bond]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:distance_function_match; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:l1; 5, identifier:l2; 6, identifier:thresh; 7, identifier:dist_fn; 8, default_parameter; 8, 9; 8, 10; 9, identifier:norm_funcs; 10, list:[]; 11, block; 11, 12; 11, 16; 11, 26; 11, 36; 11, 92; 11, 112; 11, 118; 11, 156; 11, 230; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:common; 15, list:[]; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:l1; 19, call; 19, 20; 19, 21; 20, identifier:list; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:enumerate; 24, argument_list; 24, 25; 25, identifier:l1; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:l2; 29, call; 29, 30; 29, 31; 30, identifier:list; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:enumerate; 34, argument_list; 34, 35; 35, identifier:l2; 36, for_statement; 36, 37; 36, 38; 36, 39; 37, identifier:norm_fn; 38, identifier:norm_funcs; 39, block; 39, 40; 39, 74; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 46; 42, pattern_list; 42, 43; 42, 44; 42, 45; 43, identifier:new_common; 44, identifier:l1; 45, identifier:l2; 46, call; 46, 47; 46, 48; 47, identifier:_match_by_norm_func; 48, argument_list; 48, 49; 48, 50; 48, 51; 48, 60; 48, 73; 49, identifier:l1; 50, identifier:l2; 51, lambda; 51, 52; 51, 54; 52, lambda_parameters; 52, 53; 53, identifier:a; 54, call; 54, 55; 54, 56; 55, identifier:norm_fn; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:a; 59, integer:1; 60, lambda; 60, 61; 60, 64; 61, lambda_parameters; 61, 62; 61, 63; 62, identifier:a1; 63, identifier:a2; 64, call; 64, 65; 64, 66; 65, identifier:dist_fn; 66, argument_list; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:a1; 69, integer:1; 70, subscript; 70, 71; 70, 72; 71, identifier:a2; 72, integer:1; 73, identifier:thresh; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:common; 78, identifier:extend; 79, generator_expression; 79, 80; 79, 87; 80, tuple; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:c1; 83, integer:0; 84, subscript; 84, 85; 84, 86; 85, identifier:c2; 86, integer:0; 87, for_in_clause; 87, 88; 87, 91; 88, pattern_list; 88, 89; 88, 90; 89, identifier:c1; 90, identifier:c2; 91, identifier:new_common; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:dist_matrix; 95, list_comprehension; 95, 96; 95, 107; 96, list_comprehension; 96, 97; 96, 102; 97, call; 97, 98; 97, 99; 98, identifier:dist_fn; 99, argument_list; 99, 100; 99, 101; 100, identifier:e1; 101, identifier:e2; 102, for_in_clause; 102, 103; 102, 106; 103, pattern_list; 103, 104; 103, 105; 104, identifier:i2; 105, identifier:e2; 106, identifier:l2; 107, for_in_clause; 107, 108; 107, 111; 108, pattern_list; 108, 109; 108, 110; 109, identifier:i1; 110, identifier:e1; 111, identifier:l1; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:components; 115, call; 115, 116; 115, 117; 116, identifier:BipartiteConnectedComponents; 117, argument_list; 118, for_statement; 118, 119; 118, 120; 118, 127; 119, identifier:l1_i; 120, call; 120, 121; 120, 122; 121, identifier:range; 122, argument_list; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, identifier:l1; 127, block; 127, 128; 128, for_statement; 128, 129; 128, 130; 128, 137; 129, identifier:l2_i; 130, call; 130, 131; 130, 132; 131, identifier:range; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, identifier:l2; 137, block; 137, 138; 137, 148; 138, if_statement; 138, 139; 138, 146; 139, comparison_operator:>; 139, 140; 139, 145; 140, subscript; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:dist_matrix; 143, identifier:l1_i; 144, identifier:l2_i; 145, identifier:thresh; 146, block; 146, 147; 147, continue_statement; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:components; 152, identifier:add_edge; 153, argument_list; 153, 154; 153, 155; 154, identifier:l1_i; 155, identifier:l2_i; 156, for_statement; 156, 157; 156, 160; 156, 165; 157, pattern_list; 157, 158; 157, 159; 158, identifier:l1_indices; 159, identifier:l2_indices; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:components; 163, identifier:get_connected_components; 164, argument_list; 165, block; 165, 166; 165, 176; 165, 186; 165, 202; 165, 212; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:part_l1; 169, list_comprehension; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:l1; 172, identifier:i; 173, for_in_clause; 173, 174; 173, 175; 174, identifier:i; 175, identifier:l1_indices; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:part_l2; 179, list_comprehension; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:l2; 182, identifier:i; 183, for_in_clause; 183, 184; 183, 185; 184, identifier:i; 185, identifier:l2_indices; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:part_dist_matrix; 189, list_comprehension; 189, 190; 189, 199; 190, list_comprehension; 190, 191; 190, 196; 191, subscript; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:dist_matrix; 194, identifier:l1_i; 195, identifier:l2_i; 196, for_in_clause; 196, 197; 196, 198; 197, identifier:l2_i; 198, identifier:l2_indices; 199, for_in_clause; 199, 200; 199, 201; 200, identifier:l1_i; 201, identifier:l1_indices; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:part_cmn; 205, call; 205, 206; 205, 207; 206, identifier:_match_munkres; 207, argument_list; 207, 208; 207, 209; 207, 210; 207, 211; 208, identifier:part_l1; 209, identifier:part_l2; 210, identifier:part_dist_matrix; 211, identifier:thresh; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:common; 216, identifier:extend; 217, generator_expression; 217, 218; 217, 225; 218, tuple; 218, 219; 218, 222; 219, subscript; 219, 220; 219, 221; 220, identifier:c1; 221, integer:0; 222, subscript; 222, 223; 222, 224; 223, identifier:c2; 224, integer:0; 225, for_in_clause; 225, 226; 225, 229; 226, pattern_list; 226, 227; 226, 228; 227, identifier:c1; 228, identifier:c2; 229, identifier:part_cmn; 230, return_statement; 230, 231; 231, identifier:common
def distance_function_match(l1, l2, thresh, dist_fn, norm_funcs=[]): common = [] l1 = list(enumerate(l1)) l2 = list(enumerate(l2)) for norm_fn in norm_funcs: new_common, l1, l2 = _match_by_norm_func( l1, l2, lambda a: norm_fn(a[1]), lambda a1, a2: dist_fn(a1[1], a2[1]), thresh) common.extend((c1[0], c2[0]) for c1, c2 in new_common) dist_matrix = [[dist_fn(e1, e2) for i2, e2 in l2] for i1, e1 in l1] components = BipartiteConnectedComponents() for l1_i in range(len(l1)): for l2_i in range(len(l2)): if dist_matrix[l1_i][l2_i] > thresh: continue components.add_edge(l1_i, l2_i) for l1_indices, l2_indices in components.get_connected_components(): part_l1 = [l1[i] for i in l1_indices] part_l2 = [l2[i] for i in l2_indices] part_dist_matrix = [[dist_matrix[l1_i][l2_i] for l2_i in l2_indices] for l1_i in l1_indices] part_cmn = _match_munkres(part_l1, part_l2, part_dist_matrix, thresh) common.extend((c1[0], c2[0]) for c1, c2 in part_cmn) return common
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_match_by_norm_func; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:l1; 5, identifier:l2; 6, identifier:norm_fn; 7, identifier:dist_fn; 8, identifier:thresh; 9, block; 9, 10; 9, 14; 9, 27; 9, 40; 9, 59; 9, 78; 9, 220; 9, 230; 9, 240; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:common; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:l1_only_idx; 17, call; 17, 18; 17, 19; 18, identifier:set; 19, argument_list; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:range; 22, argument_list; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:l1; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:l2_only_idx; 30, call; 30, 31; 30, 32; 31, identifier:set; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:range; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:len; 38, argument_list; 38, 39; 39, identifier:l2; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:buckets_l1; 43, call; 43, 44; 43, 45; 44, identifier:_group_by_fn; 45, argument_list; 45, 46; 45, 50; 46, call; 46, 47; 46, 48; 47, identifier:enumerate; 48, argument_list; 48, 49; 49, identifier:l1; 50, lambda; 50, 51; 50, 53; 51, lambda_parameters; 51, 52; 52, identifier:x; 53, call; 53, 54; 53, 55; 54, identifier:norm_fn; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:x; 58, integer:1; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:buckets_l2; 62, call; 62, 63; 62, 64; 63, identifier:_group_by_fn; 64, argument_list; 64, 65; 64, 69; 65, call; 65, 66; 65, 67; 66, identifier:enumerate; 67, argument_list; 67, 68; 68, identifier:l2; 69, lambda; 69, 70; 69, 72; 70, lambda_parameters; 70, 71; 71, identifier:x; 72, call; 72, 73; 72, 74; 73, identifier:norm_fn; 74, argument_list; 74, 75; 75, subscript; 75, 76; 75, 77; 76, identifier:x; 77, integer:1; 78, for_statement; 78, 79; 78, 82; 78, 87; 79, pattern_list; 79, 80; 79, 81; 80, identifier:normed; 81, identifier:l1_elements; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:buckets_l1; 85, identifier:items; 86, argument_list; 87, block; 87, 88; 87, 98; 87, 106; 87, 116; 87, 126; 87, 169; 87, 173; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:l2_elements; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:buckets_l2; 94, identifier:get; 95, argument_list; 95, 96; 95, 97; 96, identifier:normed; 97, list:[]; 98, if_statement; 98, 99; 98, 104; 99, boolean_operator:or; 99, 100; 99, 102; 100, not_operator; 100, 101; 101, identifier:l1_elements; 102, not_operator; 102, 103; 103, identifier:l2_elements; 104, block; 104, 105; 105, continue_statement; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 113; 108, pattern_list; 108, 109; 108, 110; 109, identifier:_; 110, tuple_pattern; 110, 111; 110, 112; 111, identifier:_; 112, identifier:e1_first; 113, subscript; 113, 114; 113, 115; 114, identifier:l1_elements; 115, integer:0; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 123; 118, pattern_list; 118, 119; 118, 120; 119, identifier:_; 120, tuple_pattern; 120, 121; 120, 122; 121, identifier:_; 122, identifier:e2_first; 123, subscript; 123, 124; 123, 125; 124, identifier:l2_elements; 125, integer:0; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:match_is_ambiguous; 129, not_operator; 129, 130; 130, parenthesized_expression; 130, 131; 131, boolean_operator:and; 131, 132; 131, 141; 132, comparison_operator:==; 132, 133; 132, 137; 133, call; 133, 134; 133, 135; 134, identifier:len; 135, argument_list; 135, 136; 136, identifier:l1_elements; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:l2_elements; 141, parenthesized_expression; 141, 142; 142, boolean_operator:or; 142, 143; 142, 156; 143, call; 143, 144; 143, 145; 144, identifier:all; 145, generator_expression; 145, 146; 145, 149; 146, comparison_operator:==; 146, 147; 146, 148; 147, identifier:e2; 148, identifier:e2_first; 149, for_in_clause; 149, 150; 149, 155; 150, tuple_pattern; 150, 151; 150, 152; 151, identifier:_; 152, tuple_pattern; 152, 153; 152, 154; 153, identifier:_; 154, identifier:e2; 155, identifier:l2_elements; 156, call; 156, 157; 156, 158; 157, identifier:all; 158, generator_expression; 158, 159; 158, 162; 159, comparison_operator:==; 159, 160; 159, 161; 160, identifier:e1; 161, identifier:e1_first; 162, for_in_clause; 162, 163; 162, 168; 163, tuple_pattern; 163, 164; 163, 165; 164, identifier:_; 165, tuple_pattern; 165, 166; 165, 167; 166, identifier:_; 167, identifier:e1; 168, identifier:l1_elements; 169, if_statement; 169, 170; 169, 171; 170, identifier:match_is_ambiguous; 171, block; 171, 172; 172, continue_statement; 173, for_statement; 173, 174; 173, 181; 173, 186; 174, pattern_list; 174, 175; 174, 178; 175, tuple_pattern; 175, 176; 175, 177; 176, identifier:e1_idx; 177, identifier:e1; 178, tuple_pattern; 178, 179; 178, 180; 179, identifier:e2_idx; 180, identifier:e2; 181, call; 181, 182; 181, 183; 182, identifier:zip; 183, argument_list; 183, 184; 183, 185; 184, identifier:l1_elements; 185, identifier:l2_elements; 186, block; 186, 187; 186, 197; 186, 204; 186, 211; 187, if_statement; 187, 188; 187, 195; 188, comparison_operator:>; 188, 189; 188, 194; 189, call; 189, 190; 189, 191; 190, identifier:dist_fn; 191, argument_list; 191, 192; 191, 193; 192, identifier:e1; 193, identifier:e2; 194, identifier:thresh; 195, block; 195, 196; 196, continue_statement; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:l1_only_idx; 201, identifier:remove; 202, argument_list; 202, 203; 203, identifier:e1_idx; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:l2_only_idx; 208, identifier:remove; 209, argument_list; 209, 210; 210, identifier:e2_idx; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:common; 215, identifier:append; 216, argument_list; 216, 217; 217, tuple; 217, 218; 217, 219; 218, identifier:e1; 219, identifier:e2; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:l1_only; 223, list_comprehension; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:l1; 226, identifier:i; 227, for_in_clause; 227, 228; 227, 229; 228, identifier:i; 229, identifier:l1_only_idx; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:l2_only; 233, list_comprehension; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:l2; 236, identifier:i; 237, for_in_clause; 237, 238; 237, 239; 238, identifier:i; 239, identifier:l2_only_idx; 240, return_statement; 240, 241; 241, expression_list; 241, 242; 241, 243; 241, 244; 242, identifier:common; 243, identifier:l1_only; 244, identifier:l2_only
def _match_by_norm_func(l1, l2, norm_fn, dist_fn, thresh): common = [] l1_only_idx = set(range(len(l1))) l2_only_idx = set(range(len(l2))) buckets_l1 = _group_by_fn(enumerate(l1), lambda x: norm_fn(x[1])) buckets_l2 = _group_by_fn(enumerate(l2), lambda x: norm_fn(x[1])) for normed, l1_elements in buckets_l1.items(): l2_elements = buckets_l2.get(normed, []) if not l1_elements or not l2_elements: continue _, (_, e1_first) = l1_elements[0] _, (_, e2_first) = l2_elements[0] match_is_ambiguous = not ( len(l1_elements) == len(l2_elements) and ( all(e2 == e2_first for (_, (_, e2)) in l2_elements) or all(e1 == e1_first for (_, (_, e1)) in l1_elements) ) ) if match_is_ambiguous: continue for (e1_idx, e1), (e2_idx, e2) in zip(l1_elements, l2_elements): if dist_fn(e1, e2) > thresh: continue l1_only_idx.remove(e1_idx) l2_only_idx.remove(e2_idx) common.append((e1, e2)) l1_only = [l1[i] for i in l1_only_idx] l2_only = [l2[i] for i in l2_only_idx] return common, l1_only, l2_only
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:props; 5, identifier:fp; 6, default_parameter; 6, 7; 6, 8; 7, identifier:separator; 8, string:'='; 9, default_parameter; 9, 10; 9, 11; 10, identifier:comments; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:timestamp; 14, True; 15, default_parameter; 15, 16; 15, 17; 16, identifier:sort_keys; 17, False; 18, block; 18, 19; 18, 35; 18, 58; 19, if_statement; 19, 20; 19, 23; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:comments; 22, None; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:print; 27, argument_list; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:to_comment; 30, argument_list; 30, 31; 31, identifier:comments; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:file; 34, identifier:fp; 35, if_statement; 35, 36; 35, 43; 36, boolean_operator:and; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:timestamp; 39, None; 40, comparison_operator:is; 40, 41; 40, 42; 41, identifier:timestamp; 42, False; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:print; 47, argument_list; 47, 48; 47, 55; 48, call; 48, 49; 48, 50; 49, identifier:to_comment; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:java_timestamp; 53, argument_list; 53, 54; 54, identifier:timestamp; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:file; 57, identifier:fp; 58, for_statement; 58, 59; 58, 62; 58, 69; 59, pattern_list; 59, 60; 59, 61; 60, identifier:k; 61, identifier:v; 62, call; 62, 63; 62, 64; 63, identifier:itemize; 64, argument_list; 64, 65; 64, 66; 65, identifier:props; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:sort_keys; 68, identifier:sort_keys; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:print; 73, argument_list; 73, 74; 73, 80; 74, call; 74, 75; 74, 76; 75, identifier:join_key_value; 76, argument_list; 76, 77; 76, 78; 76, 79; 77, identifier:k; 78, identifier:v; 79, identifier:separator; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:file; 82, identifier:fp
def dump(props, fp, separator='=', comments=None, timestamp=True, sort_keys=False): if comments is not None: print(to_comment(comments), file=fp) if timestamp is not None and timestamp is not False: print(to_comment(java_timestamp(timestamp)), file=fp) for k,v in itemize(props, sort_keys=sort_keys): print(join_key_value(k, v, separator), file=fp)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:dumps; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:props; 5, default_parameter; 5, 6; 5, 7; 6, identifier:separator; 7, string:'='; 8, default_parameter; 8, 9; 8, 10; 9, identifier:comments; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:timestamp; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort_keys; 16, False; 17, block; 17, 18; 17, 24; 17, 42; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:s; 21, call; 21, 22; 21, 23; 22, identifier:StringIO; 23, argument_list; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:dump; 27, argument_list; 27, 28; 27, 29; 27, 30; 27, 33; 27, 36; 27, 39; 28, identifier:props; 29, identifier:s; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:separator; 32, identifier:separator; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:comments; 35, identifier:comments; 36, keyword_argument; 36, 37; 36, 38; 37, identifier:timestamp; 38, identifier:timestamp; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:sort_keys; 41, identifier:sort_keys; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:s; 46, identifier:getvalue; 47, argument_list
def dumps(props, separator='=', comments=None, timestamp=True, sort_keys=False): s = StringIO() dump(props, s, separator=separator, comments=comments, timestamp=timestamp, sort_keys=sort_keys) return s.getvalue()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:variants; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:case_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:skip; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:count; 11, integer:1000; 12, default_parameter; 12, 13; 12, 14; 13, identifier:filters; 14, None; 15, block; 15, 16; 15, 22; 15, 34; 15, 40; 15, 51; 15, 55; 15, 90; 15, 123; 15, 197; 15, 263; 15, 277; 15, 314; 15, 364; 15, 395; 15, 399; 15, 428; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:filters; 19, boolean_operator:or; 19, 20; 19, 21; 20, identifier:filters; 21, dictionary; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:logger; 26, identifier:debug; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:"Looking for variants in {0}"; 31, identifier:format; 32, argument_list; 32, 33; 33, identifier:case_id; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:limit; 37, binary_operator:+; 37, 38; 37, 39; 38, identifier:count; 39, identifier:skip; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:gemini_query; 43, boolean_operator:or; 43, 44; 43, 50; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:filters; 47, identifier:get; 48, argument_list; 48, 49; 49, string:'gemini_query'; 50, string:"SELECT * from variants v"; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:any_filter; 54, False; 55, if_statement; 55, 56; 55, 62; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:filters; 59, identifier:get; 60, argument_list; 60, 61; 61, string:'frequency'; 62, block; 62, 63; 62, 69; 62, 80; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:frequency; 66, subscript; 66, 67; 66, 68; 67, identifier:filters; 68, string:'frequency'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:extra_info; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, concatenated_string; 74, 75; 74, 76; 75, string:"(v.max_aaf_all < {0} or v.max_aaf_all is"; 76, string:" Null)"; 77, identifier:format; 78, argument_list; 78, 79; 79, identifier:frequency; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:gemini_query; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:build_gemini_query; 87, argument_list; 87, 88; 87, 89; 88, identifier:gemini_query; 89, identifier:extra_info; 90, if_statement; 90, 91; 90, 97; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:filters; 94, identifier:get; 95, argument_list; 95, 96; 96, string:'cadd'; 97, block; 97, 98; 97, 104; 97, 113; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:cadd_score; 101, subscript; 101, 102; 101, 103; 102, identifier:filters; 103, string:'cadd'; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:extra_info; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:"(v.cadd_scaled > {0})"; 110, identifier:format; 111, argument_list; 111, 112; 112, identifier:cadd_score; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:gemini_query; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:build_gemini_query; 120, argument_list; 120, 121; 120, 122; 121, identifier:gemini_query; 122, identifier:extra_info; 123, if_statement; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:filters; 127, identifier:get; 128, argument_list; 128, 129; 129, string:'gene_ids'; 130, block; 130, 131; 130, 145; 130, 149; 130, 183; 130, 187; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:gene_list; 134, list_comprehension; 134, 135; 134, 140; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:gene_id; 138, identifier:strip; 139, argument_list; 140, for_in_clause; 140, 141; 140, 142; 141, identifier:gene_id; 142, subscript; 142, 143; 142, 144; 143, identifier:filters; 144, string:'gene_ids'; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:gene_string; 148, string:"v.gene in ("; 149, for_statement; 149, 150; 149, 153; 149, 157; 150, pattern_list; 150, 151; 150, 152; 151, identifier:index; 152, identifier:gene_id; 153, call; 153, 154; 153, 155; 154, identifier:enumerate; 155, argument_list; 155, 156; 156, identifier:gene_list; 157, block; 157, 158; 158, if_statement; 158, 159; 158, 162; 158, 172; 159, comparison_operator:==; 159, 160; 159, 161; 160, identifier:index; 161, integer:0; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, augmented_assignment:+=; 164, 165; 164, 166; 165, identifier:gene_string; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, string:"'{0}'"; 169, identifier:format; 170, argument_list; 170, 171; 171, identifier:gene_id; 172, else_clause; 172, 173; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, augmented_assignment:+=; 175, 176; 175, 177; 176, identifier:gene_string; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, string:", '{0}'"; 180, identifier:format; 181, argument_list; 181, 182; 182, identifier:gene_id; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 186; 185, identifier:gene_string; 186, string:")"; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:gemini_query; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:build_gemini_query; 194, argument_list; 194, 195; 194, 196; 195, identifier:gemini_query; 196, identifier:gene_string; 197, if_statement; 197, 198; 197, 204; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:filters; 201, identifier:get; 202, argument_list; 202, 203; 203, string:'range'; 204, block; 204, 205; 204, 213; 204, 231; 204, 253; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:chrom; 208, subscript; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:filters; 211, string:'range'; 212, string:'chromosome'; 213, if_statement; 213, 214; 213, 221; 214, not_operator; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:chrom; 218, identifier:startswith; 219, argument_list; 219, 220; 220, string:'chr'; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:chrom; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, string:"chr{0}"; 228, identifier:format; 229, argument_list; 229, 230; 230, identifier:chrom; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:range_string; 234, call; 234, 235; 234, 241; 235, attribute; 235, 236; 235, 240; 236, concatenated_string; 236, 237; 236, 238; 236, 239; 237, string:"v.chrom = '{0}' AND "; 238, string:"((v.start BETWEEN {1} AND {2}) OR "; 239, string:"(v.end BETWEEN {1} AND {2}))"; 240, identifier:format; 241, argument_list; 241, 242; 241, 243; 241, 248; 242, identifier:chrom; 243, subscript; 243, 244; 243, 247; 244, subscript; 244, 245; 244, 246; 245, identifier:filters; 246, string:'range'; 247, string:'start'; 248, subscript; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:filters; 251, string:'range'; 252, string:'end'; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:gemini_query; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:build_gemini_query; 260, argument_list; 260, 261; 260, 262; 261, identifier:gemini_query; 262, identifier:range_string; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:filtered_variants; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:_variants; 270, argument_list; 270, 271; 270, 274; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:case_id; 273, identifier:case_id; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:gemini_query; 276, identifier:gemini_query; 277, if_statement; 277, 278; 277, 284; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:filters; 281, identifier:get; 282, argument_list; 282, 283; 283, string:'consequence'; 284, block; 284, 285; 284, 294; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:consequences; 288, call; 288, 289; 288, 290; 289, identifier:set; 290, argument_list; 290, 291; 291, subscript; 291, 292; 291, 293; 292, identifier:filters; 293, string:'consequence'; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:filtered_variants; 297, generator_expression; 297, 298; 297, 299; 297, 302; 298, identifier:variant; 299, for_in_clause; 299, 300; 299, 301; 300, identifier:variant; 301, identifier:filtered_variants; 302, if_clause; 302, 303; 303, call; 303, 304; 303, 312; 304, attribute; 304, 305; 304, 311; 305, call; 305, 306; 305, 307; 306, identifier:set; 307, argument_list; 307, 308; 308, attribute; 308, 309; 308, 310; 309, identifier:variant; 310, identifier:consequences; 311, identifier:intersection; 312, argument_list; 312, 313; 313, identifier:consequences; 314, if_statement; 314, 315; 314, 321; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:filters; 318, identifier:get; 319, argument_list; 319, 320; 320, string:'impact_severities'; 321, block; 321, 322; 321, 339; 321, 343; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:severities; 325, call; 325, 326; 325, 327; 326, identifier:set; 327, argument_list; 327, 328; 328, list_comprehension; 328, 329; 328, 334; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:severity; 332, identifier:strip; 333, argument_list; 334, for_in_clause; 334, 335; 334, 336; 335, identifier:severity; 336, subscript; 336, 337; 336, 338; 337, identifier:filters; 338, string:'impact_severities'; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 342; 341, identifier:new_filtered_variants; 342, list:[]; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:filtered_variants; 346, generator_expression; 346, 347; 346, 348; 346, 351; 347, identifier:variant; 348, for_in_clause; 348, 349; 348, 350; 349, identifier:variant; 350, identifier:filtered_variants; 351, if_clause; 351, 352; 352, call; 352, 353; 352, 362; 353, attribute; 353, 354; 353, 361; 354, call; 354, 355; 354, 356; 355, identifier:set; 356, argument_list; 356, 357; 357, list:[variant.impact_severity]; 357, 358; 358, attribute; 358, 359; 358, 360; 359, identifier:variant; 360, identifier:impact_severity; 361, identifier:intersection; 362, argument_list; 362, 363; 363, identifier:severities; 364, if_statement; 364, 365; 364, 371; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:filters; 368, identifier:get; 369, argument_list; 369, 370; 370, string:'sv_len'; 371, block; 371, 372; 371, 381; 372, expression_statement; 372, 373; 373, assignment; 373, 374; 373, 375; 374, identifier:sv_len; 375, call; 375, 376; 375, 377; 376, identifier:int; 377, argument_list; 377, 378; 378, subscript; 378, 379; 378, 380; 379, identifier:filters; 380, string:'sv_len'; 381, expression_statement; 381, 382; 382, assignment; 382, 383; 382, 384; 383, identifier:filtered_variants; 384, generator_expression; 384, 385; 384, 386; 384, 389; 385, identifier:variant; 386, for_in_clause; 386, 387; 386, 388; 387, identifier:variant; 388, identifier:filtered_variants; 389, if_clause; 389, 390; 390, comparison_operator:>=; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:variant; 393, identifier:sv_len; 394, identifier:sv_len; 395, expression_statement; 395, 396; 396, assignment; 396, 397; 396, 398; 397, identifier:variants; 398, list:[]; 399, for_statement; 399, 400; 399, 403; 399, 407; 400, pattern_list; 400, 401; 400, 402; 401, identifier:index; 402, identifier:variant_obj; 403, call; 403, 404; 403, 405; 404, identifier:enumerate; 405, argument_list; 405, 406; 406, identifier:filtered_variants; 407, block; 407, 408; 408, if_statement; 408, 409; 408, 412; 409, comparison_operator:>=; 409, 410; 409, 411; 410, identifier:index; 411, identifier:skip; 412, block; 412, 413; 413, if_statement; 413, 414; 413, 417; 413, 425; 414, comparison_operator:<; 414, 415; 414, 416; 415, identifier:index; 416, identifier:limit; 417, block; 417, 418; 418, expression_statement; 418, 419; 419, call; 419, 420; 419, 423; 420, attribute; 420, 421; 420, 422; 421, identifier:variants; 422, identifier:append; 423, argument_list; 423, 424; 424, identifier:variant_obj; 425, else_clause; 425, 426; 426, block; 426, 427; 427, break_statement; 428, return_statement; 428, 429; 429, call; 429, 430; 429, 431; 430, identifier:Results; 431, argument_list; 431, 432; 431, 433; 432, identifier:variants; 433, call; 433, 434; 433, 435; 434, identifier:len; 435, argument_list; 435, 436; 436, identifier:variants
def variants(self, case_id, skip=0, count=1000, filters=None): filters = filters or {} logger.debug("Looking for variants in {0}".format(case_id)) limit = count + skip gemini_query = filters.get('gemini_query') or "SELECT * from variants v" any_filter = False if filters.get('frequency'): frequency = filters['frequency'] extra_info = "(v.max_aaf_all < {0} or v.max_aaf_all is"\ " Null)".format(frequency) gemini_query = self.build_gemini_query(gemini_query, extra_info) if filters.get('cadd'): cadd_score = filters['cadd'] extra_info = "(v.cadd_scaled > {0})".format(cadd_score) gemini_query = self.build_gemini_query(gemini_query, extra_info) if filters.get('gene_ids'): gene_list = [gene_id.strip() for gene_id in filters['gene_ids']] gene_string = "v.gene in (" for index, gene_id in enumerate(gene_list): if index == 0: gene_string += "'{0}'".format(gene_id) else: gene_string += ", '{0}'".format(gene_id) gene_string += ")" gemini_query = self.build_gemini_query(gemini_query, gene_string) if filters.get('range'): chrom = filters['range']['chromosome'] if not chrom.startswith('chr'): chrom = "chr{0}".format(chrom) range_string = "v.chrom = '{0}' AND "\ "((v.start BETWEEN {1} AND {2}) OR "\ "(v.end BETWEEN {1} AND {2}))".format( chrom, filters['range']['start'], filters['range']['end'] ) gemini_query = self.build_gemini_query(gemini_query, range_string) filtered_variants = self._variants( case_id=case_id, gemini_query=gemini_query, ) if filters.get('consequence'): consequences = set(filters['consequence']) filtered_variants = (variant for variant in filtered_variants if set(variant.consequences).intersection(consequences)) if filters.get('impact_severities'): severities = set([severity.strip() for severity in filters['impact_severities']]) new_filtered_variants = [] filtered_variants = (variant for variant in filtered_variants if set([variant.impact_severity]).intersection(severities)) if filters.get('sv_len'): sv_len = int(filters['sv_len']) filtered_variants = (variant for variant in filtered_variants if variant.sv_len >= sv_len) variants = [] for index, variant_obj in enumerate(filtered_variants): if index >= skip: if index < limit: variants.append(variant_obj) else: break return Results(variants, len(variants))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_format_variant; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 4, identifier:self; 5, identifier:case_id; 6, identifier:gemini_variant; 7, identifier:individual_objs; 8, default_parameter; 8, 9; 8, 10; 9, identifier:index; 10, integer:0; 11, default_parameter; 11, 12; 11, 13; 12, identifier:add_all_info; 13, False; 14, block; 14, 15; 14, 21; 14, 44; 14, 84; 14, 92; 14, 101; 14, 115; 14, 121; 14, 129; 14, 137; 14, 148; 14, 159; 14, 273; 14, 280; 14, 294; 14, 301; 14, 328; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:chrom; 18, subscript; 18, 19; 18, 20; 19, identifier:gemini_variant; 20, string:'chrom'; 21, if_statement; 21, 22; 21, 35; 22, boolean_operator:or; 22, 23; 22, 29; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:chrom; 26, identifier:startswith; 27, argument_list; 27, 28; 28, string:'chr'; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:chrom; 32, identifier:startswith; 33, argument_list; 33, 34; 34, string:'CHR'; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:chrom; 39, subscript; 39, 40; 39, 41; 40, identifier:chrom; 41, slice; 41, 42; 41, 43; 42, integer:3; 43, colon; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:variant_dict; 47, dictionary; 47, 48; 47, 51; 47, 59; 47, 64; 47, 69; 47, 74; 47, 79; 48, pair; 48, 49; 48, 50; 49, string:'CHROM'; 50, identifier:chrom; 51, pair; 51, 52; 51, 53; 52, string:'POS'; 53, call; 53, 54; 53, 55; 54, identifier:str; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:gemini_variant; 58, string:'start'; 59, pair; 59, 60; 59, 61; 60, string:'ID'; 61, subscript; 61, 62; 61, 63; 62, identifier:gemini_variant; 63, string:'rs_ids'; 64, pair; 64, 65; 64, 66; 65, string:'REF'; 66, subscript; 66, 67; 66, 68; 67, identifier:gemini_variant; 68, string:'ref'; 69, pair; 69, 70; 69, 71; 70, string:'ALT'; 71, subscript; 71, 72; 71, 73; 72, identifier:gemini_variant; 73, string:'alt'; 74, pair; 74, 75; 74, 76; 75, string:'QUAL'; 76, subscript; 76, 77; 76, 78; 77, identifier:gemini_variant; 78, string:'qual'; 79, pair; 79, 80; 79, 81; 80, string:'FILTER'; 81, subscript; 81, 82; 81, 83; 82, identifier:gemini_variant; 83, string:'filter'; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:variant; 87, call; 87, 88; 87, 89; 88, identifier:Variant; 89, argument_list; 89, 90; 90, dictionary_splat; 90, 91; 91, identifier:variant_dict; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:variant; 96, identifier:update_variant_id; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 100; 99, identifier:gemini_variant; 100, string:'variant_id'; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:logger; 105, identifier:debug; 106, argument_list; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:"Creating a variant object of variant {0}"; 110, identifier:format; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:variant; 114, identifier:variant_id; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, subscript; 117, 118; 117, 119; 118, identifier:variant; 119, string:'index'; 120, identifier:index; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:_add_most_severe_consequence; 126, argument_list; 126, 127; 126, 128; 127, identifier:variant; 128, identifier:gemini_variant; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:_add_impact_severity; 134, argument_list; 134, 135; 134, 136; 135, identifier:variant; 136, identifier:gemini_variant; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:variant; 141, identifier:start; 142, call; 142, 143; 142, 144; 143, identifier:int; 144, argument_list; 144, 145; 145, subscript; 145, 146; 145, 147; 146, identifier:gemini_variant; 147, string:'start'; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:variant; 152, identifier:stop; 153, call; 153, 154; 153, 155; 154, identifier:int; 155, argument_list; 155, 156; 156, subscript; 156, 157; 156, 158; 157, identifier:gemini_variant; 158, string:'end'; 159, if_statement; 159, 160; 159, 165; 159, 192; 160, comparison_operator:==; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:variant_type; 164, string:'sv'; 165, block; 165, 166; 165, 174; 165, 185; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:variant; 170, identifier:sv_type; 171, subscript; 171, 172; 171, 173; 172, identifier:gemini_variant; 173, string:'sub_type'; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:variant; 178, identifier:stop; 179, call; 179, 180; 179, 181; 180, identifier:int; 181, argument_list; 181, 182; 182, subscript; 182, 183; 182, 184; 183, identifier:gemini_variant; 184, string:'end'; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_add_sv_coordinates; 190, argument_list; 190, 191; 191, identifier:variant; 192, else_clause; 192, 193; 193, block; 193, 194; 193, 202; 193, 210; 193, 218; 193, 226; 193, 239; 193, 245; 193, 256; 193, 262; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:_add_transcripts; 199, argument_list; 199, 200; 199, 201; 200, identifier:variant; 201, identifier:gemini_variant; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:_add_thousand_g; 207, argument_list; 207, 208; 207, 209; 208, identifier:variant; 209, identifier:gemini_variant; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:_add_exac; 215, argument_list; 215, 216; 215, 217; 216, identifier:variant; 217, identifier:gemini_variant; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:_add_gmaf; 223, argument_list; 223, 224; 223, 225; 224, identifier:variant; 225, identifier:gemini_variant; 226, if_statement; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:gemini_variant; 229, string:'cadd_scaled'; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:variant; 235, identifier:cadd_score; 236, subscript; 236, 237; 236, 238; 237, identifier:gemini_variant; 238, string:'cadd_scaled'; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:polyphen; 242, subscript; 242, 243; 242, 244; 243, identifier:gemini_variant; 244, string:'polyphen_pred'; 245, if_statement; 245, 246; 245, 247; 246, identifier:polyphen; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:variant; 252, identifier:add_severity; 253, argument_list; 253, 254; 253, 255; 254, string:'Polyphen'; 255, identifier:polyphen; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:sift; 259, subscript; 259, 260; 259, 261; 260, identifier:gemini_variant; 261, string:'sift_pred'; 262, if_statement; 262, 263; 262, 264; 263, identifier:sift; 264, block; 264, 265; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:variant; 269, identifier:add_severity; 270, argument_list; 270, 271; 270, 272; 271, string:'SIFT'; 272, identifier:sift; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:_add_hgnc_symbols; 278, argument_list; 278, 279; 279, identifier:variant; 280, if_statement; 280, 281; 280, 286; 281, comparison_operator:==; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:variant_type; 285, string:'snv'; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:_add_genes; 292, argument_list; 292, 293; 293, identifier:variant; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:_add_consequences; 299, argument_list; 299, 300; 300, identifier:variant; 301, if_statement; 301, 302; 301, 303; 302, identifier:add_all_info; 303, block; 303, 304; 303, 314; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:_add_genotypes; 309, argument_list; 309, 310; 309, 311; 309, 312; 309, 313; 310, identifier:variant; 311, identifier:gemini_variant; 312, identifier:case_id; 313, identifier:individual_objs; 314, if_statement; 314, 315; 314, 320; 315, comparison_operator:==; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:variant_type; 319, string:'sv'; 320, block; 320, 321; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:_add_genes; 326, argument_list; 326, 327; 327, identifier:variant; 328, return_statement; 328, 329; 329, identifier:variant
def _format_variant(self, case_id, gemini_variant, individual_objs, index=0, add_all_info=False): chrom = gemini_variant['chrom'] if chrom.startswith('chr') or chrom.startswith('CHR'): chrom = chrom[3:] variant_dict = { 'CHROM':chrom, 'POS':str(gemini_variant['start']), 'ID':gemini_variant['rs_ids'], 'REF':gemini_variant['ref'], 'ALT':gemini_variant['alt'], 'QUAL':gemini_variant['qual'], 'FILTER':gemini_variant['filter'] } variant = Variant(**variant_dict) variant.update_variant_id(gemini_variant['variant_id']) logger.debug("Creating a variant object of variant {0}".format( variant.variant_id)) variant['index'] = index self._add_most_severe_consequence(variant, gemini_variant) self._add_impact_severity(variant, gemini_variant) variant.start = int(gemini_variant['start']) variant.stop = int(gemini_variant['end']) if self.variant_type == 'sv': variant.sv_type = gemini_variant['sub_type'] variant.stop = int(gemini_variant['end']) self._add_sv_coordinates(variant) else: self._add_transcripts(variant, gemini_variant) self._add_thousand_g(variant, gemini_variant) self._add_exac(variant, gemini_variant) self._add_gmaf(variant, gemini_variant) if gemini_variant['cadd_scaled']: variant.cadd_score = gemini_variant['cadd_scaled'] polyphen = gemini_variant['polyphen_pred'] if polyphen: variant.add_severity('Polyphen', polyphen) sift = gemini_variant['sift_pred'] if sift: variant.add_severity('SIFT', sift) self._add_hgnc_symbols(variant) if self.variant_type == 'snv': self._add_genes(variant) self._add_consequences(variant) if add_all_info: self._add_genotypes(variant, gemini_variant, case_id, individual_objs) if self.variant_type == 'sv': self._add_genes(variant) return variant
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:arg; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 182; 9, function_definition; 9, 10; 9, 11; 9, 13; 10, function_name:decorate; 11, parameters; 11, 12; 12, identifier:func; 13, block; 13, 14; 13, 33; 13, 43; 13, 62; 13, 137; 13, 180; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:func; 18, identifier:__cmd_name__; 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:'cmd_name'; 25, call; 25, 26; 25, 27; 26, identifier:getattr; 27, argument_list; 27, 28; 27, 29; 27, 30; 28, identifier:func; 29, string:'__cmd_name__'; 30, attribute; 30, 31; 30, 32; 31, identifier:func; 32, identifier:__name__; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:func; 37, identifier:__cls__; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:utils; 41, identifier:check_class; 42, argument_list; 43, if_statement; 43, 44; 43, 50; 44, not_operator; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:hasattr; 47, argument_list; 47, 48; 47, 49; 48, identifier:func; 49, string:'__arguments__'; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:func; 55, identifier:__arguments__; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:utils; 59, identifier:get_functarguments; 60, argument_list; 60, 61; 61, identifier:func; 62, if_statement; 62, 63; 62, 72; 63, boolean_operator:or; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:args; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, identifier:kwargs; 72, block; 72, 73; 72, 97; 72, 126; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:arg_name; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:kwargs; 79, identifier:get; 80, argument_list; 80, 81; 80, 82; 81, string:'dest'; 82, call; 82, 83; 82, 94; 83, attribute; 83, 84; 83, 93; 84, call; 84, 85; 84, 91; 85, attribute; 85, 86; 85, 90; 86, subscript; 86, 87; 86, 88; 87, identifier:args; 88, unary_operator:-; 88, 89; 89, integer:1; 90, identifier:lstrip; 91, argument_list; 91, 92; 92, string:'-'; 93, identifier:replace; 94, argument_list; 94, 95; 94, 96; 95, string:'-'; 96, string:'_'; 97, try_statement; 97, 98; 97, 122; 98, block; 98, 99; 98, 110; 98, 116; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:idx; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:func; 106, identifier:__named__; 107, identifier:index; 108, argument_list; 108, 109; 109, identifier:arg_name; 110, delete_statement; 110, 111; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:func; 114, identifier:__named__; 115, identifier:idx; 116, delete_statement; 116, 117; 117, subscript; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:func; 120, identifier:__arguments__; 121, identifier:idx; 122, except_clause; 122, 123; 122, 124; 123, identifier:ValueError; 124, block; 124, 125; 125, pass_statement; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:func; 131, identifier:__arguments__; 132, identifier:append; 133, argument_list; 133, 134; 134, tuple; 134, 135; 134, 136; 135, identifier:args; 136, identifier:kwargs; 137, if_statement; 137, 138; 137, 151; 138, boolean_operator:and; 138, 139; 138, 144; 139, comparison_operator:is; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:func; 142, identifier:__cls__; 143, None; 144, call; 144, 145; 144, 146; 145, identifier:isinstance; 146, argument_list; 146, 147; 146, 148; 147, identifier:func; 148, attribute; 148, 149; 148, 150; 149, identifier:types; 150, identifier:FunctionType; 151, block; 151, 152; 151, 161; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:ap_; 155, call; 155, 156; 155, 157; 156, identifier:ArgParseInator; 157, argument_list; 157, 158; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:skip_init; 160, True; 161, if_statement; 161, 162; 161, 169; 162, comparison_operator:not; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:func; 165, identifier:__cmd_name__; 166, attribute; 166, 167; 166, 168; 167, identifier:ap_; 168, identifier:commands; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 179; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:ap_; 175, identifier:commands; 176, attribute; 176, 177; 176, 178; 177, identifier:func; 178, identifier:__cmd_name__; 179, identifier:func; 180, return_statement; 180, 181; 181, identifier:func; 182, return_statement; 182, 183; 183, identifier:decorate
def arg(*args, **kwargs): def decorate(func): func.__cmd_name__ = kwargs.pop( 'cmd_name', getattr(func, '__cmd_name__', func.__name__)) func.__cls__ = utils.check_class() if not hasattr(func, '__arguments__'): func.__arguments__ = utils.get_functarguments(func) if len(args) or len(kwargs): arg_name = kwargs.get( 'dest', args[-1].lstrip('-').replace('-', '_')) try: idx = func.__named__.index(arg_name) del func.__named__[idx] del func.__arguments__[idx] except ValueError: pass func.__arguments__.append((args, kwargs,)) if func.__cls__ is None and isinstance(func, types.FunctionType): ap_ = ArgParseInator(skip_init=True) if func.__cmd_name__ not in ap_.commands: ap_.commands[func.__cmd_name__] = func return func return decorate
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:class_args; 3, parameters; 3, 4; 4, identifier:cls; 5, block; 5, 6; 5, 15; 5, 23; 5, 29; 5, 33; 5, 44; 5, 92; 5, 150; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ap_; 9, call; 9, 10; 9, 11; 10, identifier:ArgParseInator; 11, argument_list; 11, 12; 12, keyword_argument; 12, 13; 12, 14; 13, identifier:skip_init; 14, True; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:utils; 19, identifier:collect_appendvars; 20, argument_list; 20, 21; 20, 22; 21, identifier:ap_; 22, identifier:cls; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:cls; 27, identifier:__cls__; 28, identifier:cls; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:cmds; 32, dictionary; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:cls; 37, identifier:__arguments__; 38, call; 38, 39; 38, 40; 39, identifier:getattr; 40, argument_list; 40, 41; 40, 42; 40, 43; 41, identifier:cls; 42, string:'__arguments__'; 43, list:[]; 44, for_statement; 44, 45; 44, 46; 44, 71; 45, identifier:func; 46, list_comprehension; 46, 47; 46, 48; 46, 57; 47, identifier:f; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:f; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:cls; 54, identifier:__dict__; 55, identifier:values; 56, argument_list; 57, if_clause; 57, 58; 58, boolean_operator:and; 58, 59; 58, 64; 59, call; 59, 60; 59, 61; 60, identifier:hasattr; 61, argument_list; 61, 62; 61, 63; 62, identifier:f; 63, string:'__cmd_name__'; 64, not_operator; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:inspect; 68, identifier:isclass; 69, argument_list; 69, 70; 70, identifier:f; 71, block; 71, 72; 71, 78; 71, 84; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:func; 76, identifier:__subcommands__; 77, None; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:func; 82, identifier:__cls__; 83, identifier:cls; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 88; 87, identifier:cmds; 88, attribute; 88, 89; 88, 90; 89, identifier:func; 90, identifier:__cmd_name__; 91, identifier:func; 92, if_statement; 92, 93; 92, 106; 92, 123; 93, boolean_operator:and; 93, 94; 93, 99; 94, call; 94, 95; 94, 96; 95, identifier:hasattr; 96, argument_list; 96, 97; 96, 98; 97, identifier:cls; 98, string:'__cmd_name__'; 99, comparison_operator:not; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:cls; 102, identifier:__cmd_name__; 103, attribute; 103, 104; 103, 105; 104, identifier:ap_; 105, identifier:commands; 106, block; 106, 107; 106, 113; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:cls; 111, identifier:__subcommands__; 112, identifier:cmds; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 122; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:ap_; 118, identifier:commands; 119, attribute; 119, 120; 119, 121; 120, identifier:cls; 121, identifier:__cmd_name__; 122, identifier:cls; 123, else_clause; 123, 124; 124, block; 124, 125; 125, for_statement; 125, 126; 125, 129; 125, 134; 126, pattern_list; 126, 127; 126, 128; 127, identifier:name; 128, identifier:func; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:cmds; 132, identifier:items; 133, argument_list; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 141; 136, comparison_operator:not; 136, 137; 136, 138; 137, identifier:name; 138, attribute; 138, 139; 138, 140; 139, identifier:ap_; 140, identifier:commands; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:ap_; 147, identifier:commands; 148, identifier:name; 149, identifier:func; 150, return_statement; 150, 151; 151, identifier:cls
def class_args(cls): ap_ = ArgParseInator(skip_init=True) utils.collect_appendvars(ap_, cls) cls.__cls__ = cls cmds = {} cls.__arguments__ = getattr(cls, '__arguments__', []) for func in [f for f in cls.__dict__.values() if hasattr(f, '__cmd_name__') and not inspect.isclass(f)]: func.__subcommands__ = None func.__cls__ = cls cmds[func.__cmd_name__] = func if hasattr(cls, '__cmd_name__') and cls.__cmd_name__ not in ap_.commands: cls.__subcommands__ = cmds ap_.commands[cls.__cmd_name__] = cls else: for name, func in cmds.items(): if name not in ap_.commands: ap_.commands[name] = func return cls
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_args; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 18; 5, 36; 5, 58; 5, 98; 5, 110; 5, 222; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_compile; 11, argument_list; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:args; 17, None; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:_self_event; 23, argument_list; 23, 24; 23, 25; 23, 26; 23, 34; 24, string:'before_parse'; 25, string:'parse'; 26, list_splat; 26, 27; 27, subscript; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:sys; 30, identifier:argv; 31, slice; 31, 32; 31, 33; 32, integer:1; 33, colon; 34, dictionary_splat; 34, 35; 35, dictionary; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:cmds; 39, list_comprehension; 39, 40; 39, 41; 39, 50; 40, identifier:cmd; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:cmd; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:sys; 46, identifier:argv; 47, slice; 47, 48; 47, 49; 48, integer:1; 49, colon; 50, if_clause; 50, 51; 51, not_operator; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:cmd; 55, identifier:startswith; 56, argument_list; 56, 57; 57, string:"-"; 58, if_statement; 58, 59; 58, 85; 59, parenthesized_expression; 59, 60; 60, boolean_operator:and; 60, 61; 60, 78; 61, boolean_operator:and; 61, 62; 61, 75; 62, boolean_operator:and; 62, 63; 62, 69; 63, comparison_operator:>; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:cmds; 68, integer:0; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:utils; 73, identifier:check_help; 74, argument_list; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:default_cmd; 78, comparison_operator:not; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:cmds; 81, integer:0; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:commands; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:sys; 91, identifier:argv; 92, identifier:insert; 93, argument_list; 93, 94; 93, 95; 94, integer:1; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:default_cmd; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:args; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:parser; 108, identifier:parse_args; 109, argument_list; 110, if_statement; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:args; 114, block; 114, 115; 114, 201; 114, 216; 115, if_statement; 115, 116; 115, 127; 116, boolean_operator:and; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:add_output; 120, comparison_operator:is; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:args; 125, identifier:output; 126, None; 127, block; 127, 128; 127, 138; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:encoding; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:args; 137, identifier:encoding; 138, if_statement; 138, 139; 138, 150; 138, 169; 139, comparison_operator:==; 139, 140; 139, 149; 140, call; 140, 141; 140, 148; 141, attribute; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:args; 146, identifier:encoding; 147, identifier:lower; 148, argument_list; 149, string:'raw'; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:_output; 156, call; 156, 157; 156, 158; 157, identifier:open; 158, argument_list; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:args; 163, identifier:output; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:args; 168, identifier:write_mode; 169, else_clause; 169, 170; 170, block; 170, 171; 170, 174; 171, import_statement; 171, 172; 172, dotted_name; 172, 173; 173, identifier:codecs; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:_output; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:codecs; 182, identifier:open; 183, argument_list; 183, 184; 183, 189; 183, 194; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:args; 188, identifier:output; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:args; 193, identifier:write_mode; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:encoding; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:args; 200, identifier:encoding; 201, if_statement; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:_cfg_factory; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:cfg_file; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:args; 215, identifier:config; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:_is_parsed; 221, True; 222, return_statement; 222, 223; 223, identifier:self
def parse_args(self): self._compile() self.args = None self._self_event('before_parse', 'parse', *sys.argv[1:], **{}) cmds = [cmd for cmd in sys.argv[1:] if not cmd.startswith("-")] if (len(cmds) > 0 and not utils.check_help() and self.default_cmd and cmds[0] not in self.commands): sys.argv.insert(1, self.default_cmd) self.args = self.parser.parse_args() if self.args: if self.add_output and self.args.output is not None: self.encoding = self.args.encoding if self.args.encoding.lower() == 'raw': self._output = open(self.args.output, self.args.write_mode) else: import codecs self._output = codecs.open( self.args.output, self.args.write_mode, encoding=self.args.encoding) if self._cfg_factory: self.cfg_file = self.args.config self._is_parsed = True return self
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:check_command; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:new_attributes; 7, block; 7, 8; 7, 20; 7, 72; 7, 101; 7, 109; 7, 123; 8, if_statement; 8, 9; 8, 13; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_is_parsed; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:parse_args; 19, argument_list; 20, if_statement; 20, 21; 20, 25; 20, 30; 20, 41; 21, not_operator; 21, 22; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:commands; 25, block; 25, 26; 26, raise_statement; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:exceptions; 29, identifier:ArgParseInatorNoCommandsFound; 30, elif_clause; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_single; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:func; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_single; 41, else_clause; 41, 42; 42, block; 42, 43; 42, 60; 43, if_statement; 43, 44; 43, 50; 44, not_operator; 44, 45; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:args; 49, identifier:command; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 58; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:parser; 57, identifier:error; 58, argument_list; 58, 59; 59, string:"too few arguments"; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:func; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:commands; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:args; 71, identifier:command; 72, if_statement; 72, 73; 72, 82; 72, 95; 73, boolean_operator:and; 73, 74; 73, 79; 74, call; 74, 75; 74, 76; 75, identifier:hasattr; 76, argument_list; 76, 77; 76, 78; 77, identifier:func; 78, string:'__subcommands__'; 79, attribute; 79, 80; 79, 81; 80, identifier:func; 81, identifier:__subcommands__; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:command; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:func; 89, identifier:__subcommands__; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:args; 94, identifier:subcommand; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:command; 100, identifier:func; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:cmd_name; 106, attribute; 106, 107; 106, 108; 107, identifier:command; 108, identifier:__cmd_name__; 109, if_statement; 109, 110; 109, 120; 110, not_operator; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:check_auth; 115, argument_list; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:id; 118, argument_list; 118, 119; 119, identifier:command; 120, block; 120, 121; 121, return_statement; 121, 122; 122, integer:0; 123, return_statement; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_execute; 128, argument_list; 128, 129; 128, 130; 128, 131; 129, identifier:func; 130, identifier:command; 131, dictionary_splat; 131, 132; 132, identifier:new_attributes
def check_command(self, **new_attributes): if not self._is_parsed: self.parse_args() if not self.commands: raise exceptions.ArgParseInatorNoCommandsFound elif self._single: func = self._single else: if not self.args.command: self.parser.error("too few arguments") func = self.commands[self.args.command] if hasattr(func, '__subcommands__') and func.__subcommands__: command = func.__subcommands__[self.args.subcommand] else: command = func self.cmd_name = command.__cmd_name__ if not self.check_auth(id(command)): return 0 return self._execute(func, command, **new_attributes)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:merge; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 25; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:merged_root; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_recursive_merge; 15, argument_list; 15, 16; 15, 19; 15, 22; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:root; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:head; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:update; 25, if_statement; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:conflicts; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:MergeError; 33, argument_list; 33, 34; 33, 35; 34, string:'Conflicts Occurred in Merge Process'; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:conflicts
def merge(self): self.merged_root = self._recursive_merge(self.root, self.head, self.update) if self.conflicts: raise MergeError('Conflicts Occurred in Merge Process', self.conflicts)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_zadd; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:key; 6, identifier:pk; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ts; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:ttl; 12, None; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:r; 20, identifier:eval; 21, argument_list; 21, 22; 21, 25; 21, 26; 21, 27; 21, 34; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:LUA_ZADD; 25, integer:1; 26, identifier:key; 27, boolean_operator:or; 27, 28; 27, 29; 28, identifier:ts; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_time; 33, argument_list; 34, identifier:pk
def _zadd(self, key, pk, ts=None, ttl=None): return self.r.eval(self.LUA_ZADD, 1, key, ts or self._time(), pk)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:add; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:event; 6, identifier:pk; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ts; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:ttl; 12, None; 13, block; 13, 14; 13, 24; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:key; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_keygen; 21, argument_list; 21, 22; 21, 23; 22, identifier:event; 23, identifier:ts; 24, try_statement; 24, 25; 24, 38; 25, block; 25, 26; 25, 36; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_zadd; 31, argument_list; 31, 32; 31, 33; 31, 34; 31, 35; 32, identifier:key; 33, identifier:pk; 34, identifier:ts; 35, identifier:ttl; 36, return_statement; 36, 37; 37, True; 38, except_clause; 38, 39; 38, 45; 39, as_pattern; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:redis; 42, identifier:ConnectionError; 43, as_pattern_target; 43, 44; 44, identifier:e; 45, block; 45, 46; 45, 57; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:logger; 52, identifier:error; 53, argument_list; 53, 54; 54, binary_operator:%; 54, 55; 54, 56; 55, string:"redis event store failed with connection error %r"; 56, identifier:e; 57, return_statement; 57, 58; 58, False
def add(self, event, pk, ts=None, ttl=None): key = self._keygen(event, ts) try: self._zadd(key, pk, ts, ttl) return True except redis.ConnectionError as e: self.logger.error( "redis event store failed with connection error %r" % e) return False
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:add_parameter; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 27; 7, 38; 7, 48; 7, 57; 7, 79; 7, 87; 7, 113; 7, 126; 7, 136; 7, 152; 7, 179; 7, 216; 7, 224; 7, 252; 7, 287; 7, 303; 7, 316; 8, expression_statement; 8, 9; 9, string:'''Add the parameter to ``Parameters``. **Arguments** The arguments are lumped into two groups:``Parameters.add_parameter`` and ``argparse.ArgumentParser.add_argument``. Parameters that are only used by ``Parameters.add_parameter`` are removed before ``kwargs`` is passed directly to argparse.ArgumentParser.add_argument``. .. note:: Once ``parse`` has been called ``Parameters.parsed`` will be True and it is inadvisable to add more parameters to the ``Parameters``. *``Parameters.add_parameter`` Arguments* :``environment_prefix``: Prefix to add when searching the environment for this parameter. Default: os.path.basename(sys.argv[0]). :``group``: Group (namespace or prefix) for parameter (corresponds to section name in configuration files). Default: 'default'. :``options``: REQUIRED. The list of options to match for this parameter in argv. :``only``: Iterable containing the components that this parameter applies to (i.e. 'environment', 'configuration', 'argument'). Default: ('environment', 'configuration', 'argument'). *``argparse.ArgumentParser.add_argument`` Arguments* :``name or flags``: Positional argument filled in by options keyword argument. :``action``: The basic type of action to be taken when this argument is encountered at the command line. :``nargs``: The number of command-line arguments that should be consumed. :``const``: A constant value required by some action and nargs selections. :``default``: The value produced if the argument is absent from the command line. :``type``: The type to which the command-line argument should be converted. :``choices``: A container of the allowable values for the argument. :``required``: Whether or not the command-line option may be omitted (optionals only). :``help``: A brief description of what the argument does. :``metavar``: A name for the argument in usage messages. :``dest``: The name of the attribute to be added to the object returned by parse_args(). '''; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:parameter_name; 13, call; 13, 14; 13, 25; 14, attribute; 14, 15; 14, 24; 15, call; 15, 16; 15, 17; 16, identifier:max; 17, argument_list; 17, 18; 17, 21; 18, subscript; 18, 19; 18, 20; 19, identifier:kwargs; 20, string:'options'; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, identifier:len; 24, identifier:lstrip; 25, argument_list; 25, 26; 26, string:'-'; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:in; 28, 29; 28, 30; 29, string:'dest'; 30, identifier:kwargs; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:parameter_name; 35, subscript; 35, 36; 35, 37; 36, identifier:kwargs; 37, string:'dest'; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:group; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:kwargs; 44, identifier:pop; 45, argument_list; 45, 46; 45, 47; 46, string:'group'; 47, string:'default'; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:groups; 54, identifier:add; 55, argument_list; 55, 56; 56, identifier:group; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:parameter_name; 60, call; 60, 61; 60, 76; 61, attribute; 61, 62; 61, 75; 62, call; 62, 63; 62, 73; 63, attribute; 63, 64; 63, 72; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, string:'.'; 67, identifier:join; 68, argument_list; 68, 69; 69, list:[ group, parameter_name ]; 69, 70; 69, 71; 70, identifier:group; 71, identifier:parameter_name; 72, identifier:lstrip; 73, argument_list; 73, 74; 74, string:'.'; 75, identifier:replace; 76, argument_list; 76, 77; 76, 78; 77, string:'-'; 78, string:'_'; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:logger; 83, identifier:info; 84, argument_list; 84, 85; 84, 86; 85, string:'adding parameter %s'; 86, identifier:parameter_name; 87, if_statement; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:parsed; 91, block; 91, 92; 91, 100; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:logger; 96, identifier:warn; 97, argument_list; 97, 98; 97, 99; 98, string:'adding parameter %s after parse'; 99, identifier:parameter_name; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:warnings; 104, identifier:warn; 105, argument_list; 105, 106; 105, 112; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, string:'adding parameter {} after parse'; 109, identifier:format; 110, argument_list; 110, 111; 111, identifier:parameter_name; 112, identifier:RuntimeWarning; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:parameters; 119, identifier:parameter_name; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:copy; 123, identifier:copy; 124, argument_list; 124, 125; 125, identifier:kwargs; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 135; 128, subscript; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:parameters; 133, identifier:parameter_name; 134, string:'group'; 135, identifier:group; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 145; 138, subscript; 138, 139; 138, 144; 139, subscript; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:parameters; 143, identifier:parameter_name; 144, string:'type'; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:kwargs; 148, identifier:get; 149, argument_list; 149, 150; 149, 151; 150, string:'type'; 151, identifier:str; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 161; 154, subscript; 154, 155; 154, 160; 155, subscript; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:parameters; 159, identifier:parameter_name; 160, string:'environment_prefix'; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:kwargs; 164, identifier:pop; 165, argument_list; 165, 166; 165, 167; 166, string:'environment_prefix'; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:os; 171, identifier:path; 172, identifier:basename; 173, argument_list; 173, 174; 174, subscript; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:sys; 177, identifier:argv; 178, integer:0; 179, if_statement; 179, 180; 179, 189; 180, comparison_operator:is; 180, 181; 180, 188; 181, subscript; 181, 182; 181, 187; 182, subscript; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:parameters; 186, identifier:parameter_name; 187, string:'environment_prefix'; 188, None; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 199; 192, subscript; 192, 193; 192, 198; 193, subscript; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:parameters; 197, identifier:parameter_name; 198, string:'environment_prefix'; 199, call; 199, 200; 199, 213; 200, attribute; 200, 201; 200, 212; 201, call; 201, 202; 201, 211; 202, attribute; 202, 203; 202, 210; 203, subscript; 203, 204; 203, 209; 204, subscript; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:parameters; 208, identifier:parameter_name; 209, string:'environment_prefix'; 210, identifier:upper; 211, argument_list; 212, identifier:replace; 213, argument_list; 213, 214; 213, 215; 214, string:'-'; 215, string:'_'; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:logger; 220, identifier:info; 221, argument_list; 221, 222; 221, 223; 222, string:'group: %s'; 223, identifier:group; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 237; 226, attribute; 226, 227; 226, 236; 227, call; 227, 228; 227, 233; 228, attribute; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:self; 231, identifier:grouped_parameters; 232, identifier:setdefault; 233, argument_list; 233, 234; 233, 235; 234, identifier:group; 235, dictionary; 236, identifier:setdefault; 237, argument_list; 237, 238; 237, 247; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:parameter_name; 241, identifier:replace; 242, argument_list; 242, 243; 242, 246; 243, binary_operator:+; 243, 244; 243, 245; 244, identifier:group; 245, string:'.'; 246, string:''; 247, subscript; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:parameters; 251, identifier:parameter_name; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:action_defaults; 255, dictionary; 255, 256; 255, 264; 255, 272; 255, 275; 255, 278; 255, 281; 255, 284; 256, pair; 256, 257; 256, 258; 257, string:'store'; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:kwargs; 261, identifier:get; 262, argument_list; 262, 263; 263, string:'default'; 264, pair; 264, 265; 264, 266; 265, string:'store_const'; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:kwargs; 269, identifier:get; 270, argument_list; 270, 271; 271, string:'const'; 272, pair; 272, 273; 272, 274; 273, string:'store_true'; 274, False; 275, pair; 275, 276; 275, 277; 276, string:'store_false'; 277, True; 278, pair; 278, 279; 278, 280; 279, string:'append'; 280, list:[]; 281, pair; 281, 282; 281, 283; 282, string:'append_const'; 283, list:[]; 284, pair; 284, 285; 284, 286; 285, string:'count'; 286, integer:0; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 294; 289, subscript; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:self; 292, identifier:defaults; 293, identifier:parameter_name; 294, subscript; 294, 295; 294, 296; 295, identifier:action_defaults; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:kwargs; 299, identifier:get; 300, argument_list; 300, 301; 300, 302; 301, string:'action'; 302, string:'store'; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:logger; 307, identifier:info; 308, argument_list; 308, 309; 308, 310; 309, string:'default value: %s'; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:kwargs; 313, identifier:get; 314, argument_list; 314, 315; 315, string:'default'; 316, if_statement; 316, 317; 316, 327; 317, comparison_operator:in; 317, 318; 317, 319; 318, string:'argument'; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:kwargs; 322, identifier:pop; 323, argument_list; 323, 324; 323, 325; 324, string:'only'; 325, list:[ 'argument' ]; 325, 326; 326, string:'argument'; 327, block; 327, 328; 327, 352; 327, 417; 328, if_statement; 328, 329; 328, 334; 329, comparison_operator:not; 329, 330; 329, 331; 330, identifier:group; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:_group_parsers; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 342; 337, subscript; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:_group_parsers; 341, identifier:group; 342, call; 342, 343; 342, 350; 343, attribute; 343, 344; 343, 349; 344, subscript; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:self; 347, identifier:_group_parsers; 348, string:'default'; 349, identifier:add_argument_group; 350, argument_list; 350, 351; 351, identifier:group; 352, if_statement; 352, 353; 352, 360; 353, boolean_operator:and; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:self; 356, identifier:_group_prefix; 357, comparison_operator:!=; 357, 358; 357, 359; 358, identifier:group; 359, string:'default'; 360, block; 360, 361; 360, 373; 360, 382; 360, 407; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:long_option; 364, call; 364, 365; 364, 366; 365, identifier:max; 366, argument_list; 366, 367; 366, 370; 367, subscript; 367, 368; 367, 369; 368, identifier:kwargs; 369, string:'options'; 370, keyword_argument; 370, 371; 370, 372; 371, identifier:key; 372, identifier:len; 373, expression_statement; 373, 374; 374, call; 374, 375; 374, 380; 375, attribute; 375, 376; 375, 379; 376, subscript; 376, 377; 376, 378; 377, identifier:kwargs; 378, string:'options'; 379, identifier:remove; 380, argument_list; 380, 381; 381, identifier:long_option; 382, expression_statement; 382, 383; 383, call; 383, 384; 383, 389; 384, attribute; 384, 385; 384, 388; 385, subscript; 385, 386; 385, 387; 386, identifier:kwargs; 387, string:'options'; 388, identifier:append; 389, argument_list; 389, 390; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:long_option; 393, identifier:replace; 394, argument_list; 394, 395; 394, 396; 395, string:'--'; 396, binary_operator:+; 396, 397; 396, 406; 397, binary_operator:+; 397, 398; 397, 399; 398, string:'--'; 399, call; 399, 400; 399, 403; 400, attribute; 400, 401; 400, 402; 401, identifier:group; 402, identifier:replace; 403, argument_list; 403, 404; 403, 405; 404, string:'_'; 405, string:'-'; 406, string:'-'; 407, expression_statement; 407, 408; 408, call; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:logger; 411, identifier:debug; 412, argument_list; 412, 413; 412, 414; 413, string:'options: %s'; 414, subscript; 414, 415; 414, 416; 415, identifier:kwargs; 416, string:'options'; 417, expression_statement; 417, 418; 418, call; 418, 419; 418, 426; 419, attribute; 419, 420; 419, 425; 420, subscript; 420, 421; 420, 424; 421, attribute; 421, 422; 421, 423; 422, identifier:self; 423, identifier:_group_parsers; 424, identifier:group; 425, identifier:add_argument; 426, argument_list; 426, 427; 426, 434; 427, list_splat; 427, 428; 428, call; 428, 429; 428, 432; 429, attribute; 429, 430; 429, 431; 430, identifier:kwargs; 431, identifier:pop; 432, argument_list; 432, 433; 433, string:'options'; 434, dictionary_splat; 434, 435; 435, identifier:kwargs
def add_parameter(self, **kwargs): '''Add the parameter to ``Parameters``. **Arguments** The arguments are lumped into two groups:``Parameters.add_parameter`` and ``argparse.ArgumentParser.add_argument``. Parameters that are only used by ``Parameters.add_parameter`` are removed before ``kwargs`` is passed directly to argparse.ArgumentParser.add_argument``. .. note:: Once ``parse`` has been called ``Parameters.parsed`` will be True and it is inadvisable to add more parameters to the ``Parameters``. *``Parameters.add_parameter`` Arguments* :``environment_prefix``: Prefix to add when searching the environment for this parameter. Default: os.path.basename(sys.argv[0]). :``group``: Group (namespace or prefix) for parameter (corresponds to section name in configuration files). Default: 'default'. :``options``: REQUIRED. The list of options to match for this parameter in argv. :``only``: Iterable containing the components that this parameter applies to (i.e. 'environment', 'configuration', 'argument'). Default: ('environment', 'configuration', 'argument'). *``argparse.ArgumentParser.add_argument`` Arguments* :``name or flags``: Positional argument filled in by options keyword argument. :``action``: The basic type of action to be taken when this argument is encountered at the command line. :``nargs``: The number of command-line arguments that should be consumed. :``const``: A constant value required by some action and nargs selections. :``default``: The value produced if the argument is absent from the command line. :``type``: The type to which the command-line argument should be converted. :``choices``: A container of the allowable values for the argument. :``required``: Whether or not the command-line option may be omitted (optionals only). :``help``: A brief description of what the argument does. :``metavar``: A name for the argument in usage messages. :``dest``: The name of the attribute to be added to the object returned by parse_args(). ''' parameter_name = max(kwargs['options'], key = len).lstrip('-') if 'dest' in kwargs: parameter_name = kwargs['dest'] group = kwargs.pop('group', 'default') self.groups.add(group) parameter_name = '.'.join([ group, parameter_name ]).lstrip('.').replace('-', '_') logger.info('adding parameter %s', parameter_name) if self.parsed: logger.warn('adding parameter %s after parse', parameter_name) warnings.warn('adding parameter {} after parse'.format(parameter_name), RuntimeWarning) self.parameters[parameter_name] = copy.copy(kwargs) self.parameters[parameter_name]['group'] = group self.parameters[parameter_name]['type'] = kwargs.get('type', str) self.parameters[parameter_name]['environment_prefix'] = kwargs.pop('environment_prefix', os.path.basename(sys.argv[0])) if self.parameters[parameter_name]['environment_prefix'] is not None: self.parameters[parameter_name]['environment_prefix'] = self.parameters[parameter_name]['environment_prefix'].upper().replace('-', '_') logger.info('group: %s', group) self.grouped_parameters.setdefault(group, {}).setdefault(parameter_name.replace(group + '.', ''), self.parameters[parameter_name]) action_defaults = { 'store': kwargs.get('default'), 'store_const': kwargs.get('const'), 'store_true': False, 'store_false': True, 'append': [], 'append_const': [], 'count': 0, } self.defaults[parameter_name] = action_defaults[kwargs.get('action', 'store')] logger.info('default value: %s', kwargs.get('default')) if 'argument' in kwargs.pop('only', [ 'argument' ]): if group not in self._group_parsers: self._group_parsers[group] = self._group_parsers['default'].add_argument_group(group) if self._group_prefix and group != 'default': long_option = max(kwargs['options'], key = len) kwargs['options'].remove(long_option) kwargs['options'].append(long_option.replace('--', '--' + group.replace('_', '-') + '-')) logger.debug('options: %s', kwargs['options']) self._group_parsers[group].add_argument(*kwargs.pop('options'), **kwargs)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:mysql_pub; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:mysql_dsn; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tables; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:blocking; 10, False; 11, dictionary_splat_pattern; 11, 12; 12, identifier:kwargs; 13, block; 13, 14; 13, 21; 13, 47; 13, 76; 13, 108; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:parsed; 17, call; 17, 18; 17, 19; 18, identifier:urlparse; 19, argument_list; 19, 20; 20, identifier:mysql_dsn; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:mysql_settings; 24, dictionary; 24, 25; 24, 30; 24, 37; 24, 42; 25, pair; 25, 26; 25, 27; 26, string:"host"; 27, attribute; 27, 28; 27, 29; 28, identifier:parsed; 29, identifier:hostname; 30, pair; 30, 31; 30, 32; 31, string:"port"; 32, boolean_operator:or; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:parsed; 35, identifier:port; 36, integer:3306; 37, pair; 37, 38; 37, 39; 38, string:"user"; 39, attribute; 39, 40; 39, 41; 40, identifier:parsed; 41, identifier:username; 42, pair; 42, 43; 42, 44; 43, string:"passwd"; 44, attribute; 44, 45; 44, 46; 45, identifier:parsed; 46, identifier:password; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:stream; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:pymysqlreplication; 53, identifier:BinLogStreamReader; 54, argument_list; 54, 55; 54, 56; 54, 65; 54, 68; 54, 74; 55, identifier:mysql_settings; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:server_id; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:random; 61, identifier:randint; 62, argument_list; 62, 63; 62, 64; 63, integer:1000000000; 64, integer:4294967295; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:blocking; 67, identifier:blocking; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:only_events; 70, list:[DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent]; 70, 71; 70, 72; 70, 73; 71, identifier:DeleteRowsEvent; 72, identifier:UpdateRowsEvent; 73, identifier:WriteRowsEvent; 74, dictionary_splat; 74, 75; 75, identifier:kwargs; 76, function_definition; 76, 77; 76, 78; 76, 80; 77, function_name:_pk; 78, parameters; 78, 79; 79, identifier:values; 80, block; 80, 81; 80, 96; 81, if_statement; 81, 82; 81, 89; 82, call; 82, 83; 82, 84; 83, identifier:isinstance; 84, argument_list; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:event; 87, identifier:primary_key; 88, identifier:str; 89, block; 89, 90; 90, return_statement; 90, 91; 91, subscript; 91, 92; 91, 93; 92, identifier:values; 93, attribute; 93, 94; 93, 95; 94, identifier:event; 95, identifier:primary_key; 96, return_statement; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:tuple; 99, generator_expression; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:values; 102, identifier:k; 103, for_in_clause; 103, 104; 103, 105; 104, identifier:k; 105, attribute; 105, 106; 105, 107; 106, identifier:event; 107, identifier:primary_key; 108, for_statement; 108, 109; 108, 110; 108, 111; 109, identifier:event; 110, identifier:stream; 111, block; 111, 112; 111, 119; 111, 129; 111, 153; 111, 166; 111, 376; 112, if_statement; 112, 113; 112, 117; 113, not_operator; 113, 114; 114, attribute; 114, 115; 114, 116; 115, identifier:event; 116, identifier:primary_key; 117, block; 117, 118; 118, continue_statement; 119, if_statement; 119, 120; 119, 127; 120, boolean_operator:and; 120, 121; 120, 122; 121, identifier:tables; 122, comparison_operator:not; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:event; 125, identifier:table; 126, identifier:tables; 127, block; 127, 128; 128, continue_statement; 129, try_statement; 129, 130; 129, 137; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:rows; 134, attribute; 134, 135; 134, 136; 135, identifier:event; 136, identifier:rows; 137, except_clause; 137, 138; 137, 144; 138, as_pattern; 138, 139; 138, 142; 139, tuple; 139, 140; 139, 141; 140, identifier:UnicodeDecodeError; 141, identifier:ValueError; 142, as_pattern_target; 142, 143; 143, identifier:e; 144, block; 144, 145; 144, 152; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:logger; 149, identifier:exception; 150, argument_list; 150, 151; 151, identifier:e; 152, continue_statement; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:timestamp; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:datetime; 160, identifier:datetime; 161, identifier:fromtimestamp; 162, argument_list; 162, 163; 163, attribute; 163, 164; 163, 165; 164, identifier:event; 165, identifier:timestamp; 166, if_statement; 166, 167; 166, 172; 166, 236; 166, 306; 167, call; 167, 168; 167, 169; 168, identifier:isinstance; 169, argument_list; 169, 170; 169, 171; 170, identifier:event; 171, identifier:WriteRowsEvent; 172, block; 172, 173; 172, 181; 172, 188; 172, 197; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:sg_name; 176, binary_operator:%; 176, 177; 176, 178; 177, string:"%s_write"; 178, attribute; 178, 179; 178, 180; 179, identifier:event; 180, identifier:table; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:sg; 184, call; 184, 185; 184, 186; 185, identifier:signal; 186, argument_list; 186, 187; 187, identifier:sg_name; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:sg_raw; 191, call; 191, 192; 191, 193; 192, identifier:signal; 193, argument_list; 193, 194; 194, binary_operator:%; 194, 195; 194, 196; 195, string:"%s_raw"; 196, identifier:sg_name; 197, for_statement; 197, 198; 197, 199; 197, 200; 198, identifier:row; 199, identifier:rows; 200, block; 200, 201; 200, 210; 200, 217; 200, 224; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:pk; 204, call; 204, 205; 204, 206; 205, identifier:_pk; 206, argument_list; 206, 207; 207, subscript; 207, 208; 207, 209; 208, identifier:row; 209, string:"values"; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:sg; 214, identifier:send; 215, argument_list; 215, 216; 216, identifier:pk; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:sg_raw; 221, identifier:send; 222, argument_list; 222, 223; 223, identifier:row; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:logger; 228, identifier:debug; 229, argument_list; 229, 230; 230, binary_operator:%; 230, 231; 230, 232; 231, string:"%s -> %s, %s"; 232, tuple; 232, 233; 232, 234; 232, 235; 233, identifier:sg_name; 234, identifier:pk; 235, identifier:timestamp; 236, elif_clause; 236, 237; 236, 242; 237, call; 237, 238; 237, 239; 238, identifier:isinstance; 239, argument_list; 239, 240; 239, 241; 240, identifier:event; 241, identifier:UpdateRowsEvent; 242, block; 242, 243; 242, 251; 242, 258; 242, 267; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:sg_name; 246, binary_operator:%; 246, 247; 246, 248; 247, string:"%s_update"; 248, attribute; 248, 249; 248, 250; 249, identifier:event; 250, identifier:table; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:sg; 254, call; 254, 255; 254, 256; 255, identifier:signal; 256, argument_list; 256, 257; 257, identifier:sg_name; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:sg_raw; 261, call; 261, 262; 261, 263; 262, identifier:signal; 263, argument_list; 263, 264; 264, binary_operator:%; 264, 265; 264, 266; 265, string:"%s_raw"; 266, identifier:sg_name; 267, for_statement; 267, 268; 267, 269; 267, 270; 268, identifier:row; 269, identifier:rows; 270, block; 270, 271; 270, 280; 270, 287; 270, 294; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:pk; 274, call; 274, 275; 274, 276; 275, identifier:_pk; 276, argument_list; 276, 277; 277, subscript; 277, 278; 277, 279; 278, identifier:row; 279, string:"after_values"; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:sg; 284, identifier:send; 285, argument_list; 285, 286; 286, identifier:pk; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:sg_raw; 291, identifier:send; 292, argument_list; 292, 293; 293, identifier:row; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:logger; 298, identifier:debug; 299, argument_list; 299, 300; 300, binary_operator:%; 300, 301; 300, 302; 301, string:"%s -> %s, %s"; 302, tuple; 302, 303; 302, 304; 302, 305; 303, identifier:sg_name; 304, identifier:pk; 305, identifier:timestamp; 306, elif_clause; 306, 307; 306, 312; 307, call; 307, 308; 307, 309; 308, identifier:isinstance; 309, argument_list; 309, 310; 309, 311; 310, identifier:event; 311, identifier:DeleteRowsEvent; 312, block; 312, 313; 312, 321; 312, 328; 312, 337; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:sg_name; 316, binary_operator:%; 316, 317; 316, 318; 317, string:"%s_delete"; 318, attribute; 318, 319; 318, 320; 319, identifier:event; 320, identifier:table; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:sg; 324, call; 324, 325; 324, 326; 325, identifier:signal; 326, argument_list; 326, 327; 327, identifier:sg_name; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:sg_raw; 331, call; 331, 332; 331, 333; 332, identifier:signal; 333, argument_list; 333, 334; 334, binary_operator:%; 334, 335; 334, 336; 335, string:"%s_raw"; 336, identifier:sg_name; 337, for_statement; 337, 338; 337, 339; 337, 340; 338, identifier:row; 339, identifier:rows; 340, block; 340, 341; 340, 350; 340, 357; 340, 364; 341, expression_statement; 341, 342; 342, assignment; 342, 343; 342, 344; 343, identifier:pk; 344, call; 344, 345; 344, 346; 345, identifier:_pk; 346, argument_list; 346, 347; 347, subscript; 347, 348; 347, 349; 348, identifier:row; 349, string:"values"; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:sg; 354, identifier:send; 355, argument_list; 355, 356; 356, identifier:pk; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:sg_raw; 361, identifier:send; 362, argument_list; 362, 363; 363, identifier:row; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:logger; 368, identifier:debug; 369, argument_list; 369, 370; 370, binary_operator:%; 370, 371; 370, 372; 371, string:"%s -> %s, %s"; 372, tuple; 372, 373; 372, 374; 372, 375; 373, identifier:sg_name; 374, identifier:pk; 375, identifier:timestamp; 376, expression_statement; 376, 377; 377, call; 377, 378; 377, 384; 378, attribute; 378, 379; 378, 383; 379, call; 379, 380; 379, 381; 380, identifier:signal; 381, argument_list; 381, 382; 382, string:"mysql_binlog_pos"; 383, identifier:send; 384, argument_list; 384, 385; 385, binary_operator:%; 385, 386; 385, 387; 386, string:"%s:%s"; 387, tuple; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:stream; 390, identifier:log_file; 391, attribute; 391, 392; 391, 393; 392, identifier:stream; 393, identifier:log_pos
def mysql_pub(mysql_dsn, tables=None, blocking=False, **kwargs): parsed = urlparse(mysql_dsn) mysql_settings = { "host": parsed.hostname, "port": parsed.port or 3306, "user": parsed.username, "passwd": parsed.password } stream = pymysqlreplication.BinLogStreamReader( mysql_settings, server_id=random.randint(1000000000, 4294967295), blocking=blocking, only_events=[DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent], **kwargs ) def _pk(values): if isinstance(event.primary_key, str): return values[event.primary_key] return tuple(values[k] for k in event.primary_key) for event in stream: if not event.primary_key: continue if tables and event.table not in tables: continue try: rows = event.rows except (UnicodeDecodeError, ValueError) as e: logger.exception(e) continue timestamp = datetime.datetime.fromtimestamp(event.timestamp) if isinstance(event, WriteRowsEvent): sg_name = "%s_write" % event.table sg = signal(sg_name) sg_raw = signal("%s_raw" % sg_name) for row in rows: pk = _pk(row["values"]) sg.send(pk) sg_raw.send(row) logger.debug("%s -> %s, %s" % (sg_name, pk, timestamp)) elif isinstance(event, UpdateRowsEvent): sg_name = "%s_update" % event.table sg = signal(sg_name) sg_raw = signal("%s_raw" % sg_name) for row in rows: pk = _pk(row["after_values"]) sg.send(pk) sg_raw.send(row) logger.debug("%s -> %s, %s" % (sg_name, pk, timestamp)) elif isinstance(event, DeleteRowsEvent): sg_name = "%s_delete" % event.table sg = signal(sg_name) sg_raw = signal("%s_raw" % sg_name) for row in rows: pk = _pk(row["values"]) sg.send(pk) sg_raw.send(row) logger.debug("%s -> %s, %s" % (sg_name, pk, timestamp)) signal("mysql_binlog_pos").send( "%s:%s" % (stream.log_file, stream.log_pos))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:do_step; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:values; 6, identifier:xy_values; 7, identifier:coeff; 8, identifier:width; 9, block; 9, 10; 9, 25; 9, 196; 9, 215; 9, 233; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:forces; 13, dictionary_comprehension; 13, 14; 13, 17; 14, pair; 14, 15; 14, 16; 15, identifier:k; 16, list:[]; 17, for_in_clause; 17, 18; 17, 21; 18, pattern_list; 18, 19; 18, 20; 19, identifier:k; 20, identifier:i; 21, call; 21, 22; 21, 23; 22, identifier:enumerate; 23, argument_list; 23, 24; 24, identifier:xy_values; 25, for_statement; 25, 26; 25, 33; 25, 41; 26, pattern_list; 26, 27; 26, 30; 27, tuple_pattern; 27, 28; 27, 29; 28, identifier:index1; 29, identifier:value1; 30, tuple_pattern; 30, 31; 30, 32; 31, identifier:index2; 32, identifier:value2; 33, call; 33, 34; 33, 35; 34, identifier:combinations; 35, argument_list; 35, 36; 35, 40; 36, call; 36, 37; 36, 38; 37, identifier:enumerate; 38, argument_list; 38, 39; 39, identifier:xy_values; 40, integer:2; 41, block; 41, 42; 41, 63; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:f; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:calc_2d_forces; 49, argument_list; 49, 50; 49, 53; 49, 56; 49, 59; 49, 62; 50, subscript; 50, 51; 50, 52; 51, identifier:value1; 52, integer:0; 53, subscript; 53, 54; 53, 55; 54, identifier:value1; 55, integer:1; 56, subscript; 56, 57; 56, 58; 57, identifier:value2; 58, integer:0; 59, subscript; 59, 60; 59, 61; 60, identifier:value2; 61, integer:1; 62, identifier:width; 63, if_statement; 63, 64; 63, 71; 63, 133; 64, comparison_operator:<; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:coeff; 67, identifier:index1; 68, subscript; 68, 69; 68, 70; 69, identifier:coeff; 70, identifier:index2; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 86; 72, 109; 73, comparison_operator:<; 73, 74; 73, 81; 74, binary_operator:-; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:b_lenght; 78, subscript; 78, 79; 78, 80; 79, identifier:coeff; 80, identifier:index2; 81, binary_operator:/; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:b_lenght; 85, integer:10; 86, block; 86, 87; 86, 98; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:forces; 92, identifier:index1; 93, identifier:append; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 97; 96, identifier:f; 97, integer:1; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:forces; 103, identifier:index2; 104, identifier:append; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 108; 107, identifier:f; 108, integer:0; 109, else_clause; 109, 110; 110, block; 110, 111; 110, 122; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:forces; 116, identifier:index1; 117, identifier:append; 118, argument_list; 118, 119; 119, subscript; 119, 120; 119, 121; 120, identifier:f; 121, integer:0; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:forces; 127, identifier:index2; 128, identifier:append; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 132; 131, identifier:f; 132, integer:1; 133, else_clause; 133, 134; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 149; 135, 172; 136, comparison_operator:<; 136, 137; 136, 144; 137, binary_operator:-; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:b_lenght; 141, subscript; 141, 142; 141, 143; 142, identifier:coeff; 143, identifier:index1; 144, binary_operator:/; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:b_lenght; 148, integer:10; 149, block; 149, 150; 149, 161; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:forces; 155, identifier:index1; 156, identifier:append; 157, argument_list; 157, 158; 158, subscript; 158, 159; 158, 160; 159, identifier:f; 160, integer:0; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:forces; 166, identifier:index2; 167, identifier:append; 168, argument_list; 168, 169; 169, subscript; 169, 170; 169, 171; 170, identifier:f; 171, integer:1; 172, else_clause; 172, 173; 173, block; 173, 174; 173, 185; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, subscript; 177, 178; 177, 179; 178, identifier:forces; 179, identifier:index1; 180, identifier:append; 181, argument_list; 181, 182; 182, subscript; 182, 183; 182, 184; 183, identifier:f; 184, integer:1; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:forces; 190, identifier:index2; 191, identifier:append; 192, argument_list; 192, 193; 193, subscript; 193, 194; 193, 195; 194, identifier:f; 195, integer:0; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:forces; 199, dictionary_comprehension; 199, 200; 199, 206; 200, pair; 200, 201; 200, 202; 201, identifier:k; 202, call; 202, 203; 202, 204; 203, identifier:sum; 204, argument_list; 204, 205; 205, identifier:v; 206, for_in_clause; 206, 207; 206, 210; 207, pattern_list; 207, 208; 207, 209; 208, identifier:k; 209, identifier:v; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:forces; 213, identifier:items; 214, argument_list; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:energy; 218, call; 218, 219; 218, 220; 219, identifier:sum; 220, argument_list; 220, 221; 221, list_comprehension; 221, 222; 221, 226; 222, call; 222, 223; 222, 224; 223, identifier:abs; 224, argument_list; 224, 225; 225, identifier:x; 226, for_in_clause; 226, 227; 226, 228; 227, identifier:x; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:forces; 231, identifier:values; 232, argument_list; 233, return_statement; 233, 234; 234, expression_list; 234, 235; 234, 252; 235, list_comprehension; 235, 236; 235, 244; 236, parenthesized_expression; 236, 237; 237, binary_operator:+; 237, 238; 237, 243; 238, binary_operator:/; 238, 239; 238, 242; 239, subscript; 239, 240; 239, 241; 240, identifier:forces; 241, identifier:k; 242, integer:10; 243, identifier:v; 244, for_in_clause; 244, 245; 244, 248; 245, pattern_list; 245, 246; 245, 247; 246, identifier:k; 247, identifier:v; 248, call; 248, 249; 248, 250; 249, identifier:enumerate; 250, argument_list; 250, 251; 251, identifier:values; 252, identifier:energy
def do_step(self, values, xy_values,coeff, width): forces = {k:[] for k,i in enumerate(xy_values)} for (index1, value1), (index2,value2) in combinations(enumerate(xy_values),2): f = self.calc_2d_forces(value1[0],value1[1],value2[0],value2[1],width) if coeff[index1] < coeff[index2]: if self.b_lenght-coeff[index2]<self.b_lenght/10: forces[index1].append(f[1]) forces[index2].append(f[0]) else: forces[index1].append(f[0]) forces[index2].append(f[1]) else: if self.b_lenght-coeff[index1]<self.b_lenght/10: forces[index1].append(f[0]) forces[index2].append(f[1]) else: forces[index1].append(f[1]) forces[index2].append(f[0]) forces = {k:sum(v) for k,v in forces.items()} energy = sum([abs(x) for x in forces.values()]) return [(forces[k]/10+v) for k, v in enumerate(values)], energy
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:execute_get; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:resource; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 19; 8, 31; 8, 37; 8, 43; 8, 112; 8, 152; 8, 164; 8, 191; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:url; 12, binary_operator:%; 12, 13; 12, 14; 13, string:'%s/%s'; 14, tuple; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:base_url; 18, identifier:resource; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:headers; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:kwargs; 25, identifier:pop; 26, argument_list; 26, 27; 26, 28; 27, string:'headers'; 28, call; 28, 29; 28, 30; 29, identifier:dict; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:headers; 35, string:'Accept'; 36, string:'application/json'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:headers; 41, string:'Content-Type'; 42, string:'application/json'; 43, if_statement; 43, 44; 43, 45; 44, identifier:kwargs; 45, block; 45, 46; 45, 55; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:separator; 49, conditional_expression:if; 49, 50; 49, 51; 49, 54; 50, string:'&'; 51, comparison_operator:in; 51, 52; 51, 53; 52, string:'?'; 53, identifier:url; 54, string:'?'; 55, for_statement; 55, 56; 55, 59; 55, 64; 56, pattern_list; 56, 57; 56, 58; 57, identifier:key; 58, identifier:value; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:kwargs; 62, identifier:items; 63, argument_list; 64, block; 64, 65; 64, 108; 65, if_statement; 65, 66; 65, 80; 65, 96; 66, boolean_operator:and; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:hasattr; 69, argument_list; 69, 70; 69, 71; 70, identifier:value; 71, string:'__iter__'; 72, comparison_operator:not; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:type; 75, argument_list; 75, 76; 76, identifier:value; 77, attribute; 77, 78; 77, 79; 78, identifier:six; 79, identifier:string_types; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:url; 84, binary_operator:%; 84, 85; 84, 86; 85, string:'%s%s%s=%s'; 86, tuple; 86, 87; 86, 88; 86, 89; 86, 90; 87, identifier:url; 88, identifier:separator; 89, identifier:key; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, string:','; 93, identifier:join; 94, argument_list; 94, 95; 95, identifier:value; 96, else_clause; 96, 97; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:url; 101, binary_operator:%; 101, 102; 101, 103; 102, string:'%s%s%s=%s'; 103, tuple; 103, 104; 103, 105; 103, 106; 103, 107; 104, identifier:url; 105, identifier:separator; 106, identifier:key; 107, identifier:value; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:separator; 111, string:'&'; 112, if_statement; 112, 113; 112, 116; 112, 127; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:_access_token; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:headers; 121, string:'Authorization'; 122, binary_operator:%; 122, 123; 122, 124; 123, string:'Bearer %s'; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:_access_token; 127, else_clause; 127, 128; 128, block; 128, 129; 128, 138; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:separator; 132, conditional_expression:if; 132, 133; 132, 134; 132, 137; 133, string:'&'; 134, comparison_operator:in; 134, 135; 134, 136; 135, string:'?'; 136, identifier:url; 137, string:'?'; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:url; 141, binary_operator:%; 141, 142; 141, 143; 142, string:'%s%sclient_id=%s&client_secret=%s'; 143, tuple; 143, 144; 143, 145; 143, 146; 143, 149; 144, identifier:url; 145, identifier:separator; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:_client_id; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:_client_secret; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:response; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:requests; 158, identifier:get; 159, argument_list; 159, 160; 159, 161; 160, identifier:url; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:headers; 163, identifier:headers; 164, if_statement; 164, 165; 164, 172; 165, comparison_operator:!=; 165, 166; 165, 171; 166, binary_operator://; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:response; 169, identifier:status_code; 170, integer:100; 171, integer:2; 172, block; 172, 173; 173, raise_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:GhostException; 176, argument_list; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:response; 179, identifier:status_code; 180, call; 180, 181; 180, 188; 181, attribute; 181, 182; 181, 187; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:response; 185, identifier:json; 186, argument_list; 187, identifier:get; 188, argument_list; 188, 189; 188, 190; 189, string:'errors'; 190, list:[]; 191, return_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:response; 195, identifier:json; 196, argument_list
def execute_get(self, resource, **kwargs): url = '%s/%s' % (self.base_url, resource) headers = kwargs.pop('headers', dict()) headers['Accept'] = 'application/json' headers['Content-Type'] = 'application/json' if kwargs: separator = '&' if '?' in url else '?' for key, value in kwargs.items(): if hasattr(value, '__iter__') and type(value) not in six.string_types: url = '%s%s%s=%s' % (url, separator, key, ','.join(value)) else: url = '%s%s%s=%s' % (url, separator, key, value) separator = '&' if self._access_token: headers['Authorization'] = 'Bearer %s' % self._access_token else: separator = '&' if '?' in url else '?' url = '%s%sclient_id=%s&client_secret=%s' % ( url, separator, self._client_id, self._client_secret ) response = requests.get(url, headers=headers) if response.status_code // 100 != 2: raise GhostException(response.status_code, response.json().get('errors', [])) return response.json()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:variants; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:case_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:skip; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:count; 11, integer:1000; 12, default_parameter; 12, 13; 12, 14; 13, identifier:filters; 14, None; 15, block; 15, 16; 15, 22; 15, 33; 15, 39; 15, 45; 15, 70; 15, 74; 15, 91; 15, 95; 15, 112; 15, 116; 15, 133; 15, 137; 15, 154; 15, 158; 15, 175; 15, 181; 15, 190; 15, 200; 15, 210; 15, 220; 15, 224; 15, 228; 15, 406; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:filters; 19, boolean_operator:or; 19, 20; 19, 21; 20, identifier:filters; 21, dictionary; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:case_obj; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:case; 29, argument_list; 29, 30; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:case_id; 32, identifier:case_id; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:limit; 36, binary_operator:+; 36, 37; 36, 38; 37, identifier:count; 38, identifier:skip; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:genes; 42, call; 42, 43; 42, 44; 43, identifier:set; 44, argument_list; 45, if_statement; 45, 46; 45, 52; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:filters; 49, identifier:get; 50, argument_list; 50, 51; 51, string:'gene_ids'; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:genes; 56, call; 56, 57; 56, 58; 57, identifier:set; 58, argument_list; 58, 59; 59, list_comprehension; 59, 60; 59, 65; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:gene_id; 63, identifier:strip; 64, argument_list; 65, for_in_clause; 65, 66; 65, 67; 66, identifier:gene_id; 67, subscript; 67, 68; 67, 69; 68, identifier:filters; 69, string:'gene_ids'; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:frequency; 73, None; 74, if_statement; 74, 75; 74, 81; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:filters; 78, identifier:get; 79, argument_list; 79, 80; 80, string:'frequency'; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:frequency; 85, call; 85, 86; 85, 87; 86, identifier:float; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 90; 89, identifier:filters; 90, string:'frequency'; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:cadd; 94, None; 95, if_statement; 95, 96; 95, 102; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:filters; 99, identifier:get; 100, argument_list; 100, 101; 101, string:'cadd'; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:cadd; 106, call; 106, 107; 106, 108; 107, identifier:float; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 111; 110, identifier:filters; 111, string:'cadd'; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:genetic_models; 115, None; 116, if_statement; 116, 117; 116, 123; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:filters; 120, identifier:get; 121, argument_list; 121, 122; 122, string:'genetic_models'; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:genetic_models; 127, call; 127, 128; 127, 129; 128, identifier:set; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 132; 131, identifier:filters; 132, string:'genetic_models'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:sv_len; 136, None; 137, if_statement; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:filters; 141, identifier:get; 142, argument_list; 142, 143; 143, string:'sv_len'; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:sv_len; 148, call; 148, 149; 148, 150; 149, identifier:float; 150, argument_list; 150, 151; 151, subscript; 151, 152; 151, 153; 152, identifier:filters; 153, string:'sv_len'; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:impact_severities; 157, None; 158, if_statement; 158, 159; 158, 165; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:filters; 162, identifier:get; 163, argument_list; 163, 164; 164, string:'impact_severities'; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:impact_severities; 169, call; 169, 170; 169, 171; 170, identifier:set; 171, argument_list; 171, 172; 172, subscript; 172, 173; 172, 174; 173, identifier:filters; 174, string:'impact_severities'; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:vcf_file_path; 178, attribute; 178, 179; 178, 180; 179, identifier:case_obj; 180, identifier:variant_source; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:head; 186, call; 186, 187; 186, 188; 187, identifier:get_header; 188, argument_list; 188, 189; 189, identifier:vcf_file_path; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:vep_header; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:head; 199, identifier:vep_columns; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:snpeff_header; 205, attribute; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:head; 209, identifier:snpeff_columns; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:variants; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:_get_filtered_variants; 217, argument_list; 217, 218; 217, 219; 218, identifier:vcf_file_path; 219, identifier:filters; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:result; 223, list:[]; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:skip_index; 227, integer:0; 228, for_statement; 228, 229; 228, 232; 228, 236; 229, pattern_list; 229, 230; 229, 231; 230, identifier:index; 231, identifier:variant; 232, call; 232, 233; 232, 234; 233, identifier:enumerate; 234, argument_list; 234, 235; 235, identifier:variants; 236, block; 236, 237; 236, 241; 237, expression_statement; 237, 238; 238, augmented_assignment:+=; 238, 239; 238, 240; 239, identifier:index; 240, integer:1; 241, if_statement; 241, 242; 241, 245; 241, 400; 242, comparison_operator:>=; 242, 243; 242, 244; 243, identifier:skip_index; 244, identifier:skip; 245, block; 245, 246; 245, 263; 245, 286; 245, 303; 245, 319; 245, 335; 245, 362; 245, 378; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:variant_obj; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:_format_variants; 253, argument_list; 253, 254; 253, 257; 253, 260; 254, keyword_argument; 254, 255; 254, 256; 255, identifier:variant; 256, identifier:variant; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:index; 259, identifier:index; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:case_obj; 262, identifier:case_obj; 263, if_statement; 263, 264; 263, 267; 264, boolean_operator:and; 264, 265; 264, 266; 265, identifier:genes; 266, identifier:variant_obj; 267, block; 267, 268; 268, if_statement; 268, 269; 268, 281; 269, not_operator; 269, 270; 270, call; 270, 271; 270, 279; 271, attribute; 271, 272; 271, 278; 272, call; 272, 273; 272, 274; 273, identifier:set; 274, argument_list; 274, 275; 275, subscript; 275, 276; 275, 277; 276, identifier:variant_obj; 277, string:'gene_symbols'; 278, identifier:intersection; 279, argument_list; 279, 280; 280, identifier:genes; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:variant_obj; 285, None; 286, if_statement; 286, 287; 286, 290; 287, boolean_operator:and; 287, 288; 287, 289; 288, identifier:impact_severities; 289, identifier:variant_obj; 290, block; 290, 291; 291, if_statement; 291, 292; 291, 298; 292, not_operator; 292, 293; 293, comparison_operator:in; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:variant_obj; 296, string:'impact_severity'; 297, identifier:impact_severities; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:variant_obj; 302, None; 303, if_statement; 303, 304; 303, 307; 304, boolean_operator:and; 304, 305; 304, 306; 305, identifier:frequency; 306, identifier:variant_obj; 307, block; 307, 308; 308, if_statement; 308, 309; 308, 314; 309, comparison_operator:>; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:variant_obj; 312, identifier:max_freq; 313, identifier:frequency; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:variant_obj; 318, None; 319, if_statement; 319, 320; 319, 323; 320, boolean_operator:and; 320, 321; 320, 322; 321, identifier:cadd; 322, identifier:variant_obj; 323, block; 323, 324; 324, if_statement; 324, 325; 324, 330; 325, comparison_operator:<; 325, 326; 325, 329; 326, subscript; 326, 327; 326, 328; 327, identifier:variant_obj; 328, string:'cadd_score'; 329, identifier:cadd; 330, block; 330, 331; 331, expression_statement; 331, 332; 332, assignment; 332, 333; 332, 334; 333, identifier:variant_obj; 334, None; 335, if_statement; 335, 336; 335, 339; 336, boolean_operator:and; 336, 337; 336, 338; 337, identifier:genetic_models; 338, identifier:variant_obj; 339, block; 339, 340; 339, 349; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 343; 342, identifier:models; 343, call; 343, 344; 343, 345; 344, identifier:set; 345, argument_list; 345, 346; 346, attribute; 346, 347; 346, 348; 347, identifier:variant_obj; 348, identifier:genetic_models; 349, if_statement; 349, 350; 349, 357; 350, not_operator; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:models; 354, identifier:intersection; 355, argument_list; 355, 356; 356, identifier:genetic_models; 357, block; 357, 358; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 361; 360, identifier:variant_obj; 361, None; 362, if_statement; 362, 363; 362, 366; 363, boolean_operator:and; 363, 364; 363, 365; 364, identifier:sv_len; 365, identifier:variant_obj; 366, block; 366, 367; 367, if_statement; 367, 368; 367, 373; 368, comparison_operator:<; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:variant_obj; 371, identifier:sv_len; 372, identifier:sv_len; 373, block; 373, 374; 374, expression_statement; 374, 375; 375, assignment; 375, 376; 375, 377; 376, identifier:variant_obj; 377, None; 378, if_statement; 378, 379; 378, 380; 379, identifier:variant_obj; 380, block; 380, 381; 380, 385; 381, expression_statement; 381, 382; 382, augmented_assignment:+=; 382, 383; 382, 384; 383, identifier:skip_index; 384, integer:1; 385, if_statement; 385, 386; 385, 389; 385, 397; 386, comparison_operator:<=; 386, 387; 386, 388; 387, identifier:skip_index; 388, identifier:limit; 389, block; 389, 390; 390, expression_statement; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:result; 394, identifier:append; 395, argument_list; 395, 396; 396, identifier:variant_obj; 397, else_clause; 397, 398; 398, block; 398, 399; 399, break_statement; 400, else_clause; 400, 401; 401, block; 401, 402; 402, expression_statement; 402, 403; 403, augmented_assignment:+=; 403, 404; 403, 405; 404, identifier:skip_index; 405, integer:1; 406, return_statement; 406, 407; 407, call; 407, 408; 407, 409; 408, identifier:Results; 409, argument_list; 409, 410; 409, 411; 410, identifier:result; 411, call; 411, 412; 411, 413; 412, identifier:len; 413, argument_list; 413, 414; 414, identifier:result
def variants(self, case_id, skip=0, count=1000, filters=None): filters = filters or {} case_obj = self.case(case_id=case_id) limit = count + skip genes = set() if filters.get('gene_ids'): genes = set([gene_id.strip() for gene_id in filters['gene_ids']]) frequency = None if filters.get('frequency'): frequency = float(filters['frequency']) cadd = None if filters.get('cadd'): cadd = float(filters['cadd']) genetic_models = None if filters.get('genetic_models'): genetic_models = set(filters['genetic_models']) sv_len = None if filters.get('sv_len'): sv_len = float(filters['sv_len']) impact_severities = None if filters.get('impact_severities'): impact_severities = set(filters['impact_severities']) vcf_file_path = case_obj.variant_source self.head = get_header(vcf_file_path) self.vep_header = self.head.vep_columns self.snpeff_header = self.head.snpeff_columns variants = self._get_filtered_variants(vcf_file_path, filters) result = [] skip_index = 0 for index, variant in enumerate(variants): index += 1 if skip_index >= skip: variant_obj = self._format_variants( variant=variant, index=index, case_obj=case_obj, ) if genes and variant_obj: if not set(variant_obj['gene_symbols']).intersection(genes): variant_obj = None if impact_severities and variant_obj: if not variant_obj['impact_severity'] in impact_severities: variant_obj = None if frequency and variant_obj: if variant_obj.max_freq > frequency: variant_obj = None if cadd and variant_obj: if variant_obj['cadd_score'] < cadd: variant_obj = None if genetic_models and variant_obj: models = set(variant_obj.genetic_models) if not models.intersection(genetic_models): variant_obj = None if sv_len and variant_obj: if variant_obj.sv_len < sv_len: variant_obj = None if variant_obj: skip_index += 1 if skip_index <= limit: result.append(variant_obj) else: break else: skip_index += 1 return Results(result, len(result))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_get_filtered_variants; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:vcf_file_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filters; 8, dictionary; 9, block; 9, 10; 9, 16; 9, 22; 9, 28; 9, 53; 9, 70; 9, 87; 9, 99; 9, 153; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:genes; 13, call; 13, 14; 13, 15; 14, identifier:set; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:consequences; 19, call; 19, 20; 19, 21; 20, identifier:set; 21, argument_list; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:sv_types; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 28, if_statement; 28, 29; 28, 35; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:filters; 32, identifier:get; 33, argument_list; 33, 34; 34, string:'gene_ids'; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:genes; 39, call; 39, 40; 39, 41; 40, identifier:set; 41, argument_list; 41, 42; 42, list_comprehension; 42, 43; 42, 48; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:gene_id; 46, identifier:strip; 47, argument_list; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:gene_id; 50, subscript; 50, 51; 50, 52; 51, identifier:filters; 52, string:'gene_ids'; 53, if_statement; 53, 54; 53, 60; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:filters; 57, identifier:get; 58, argument_list; 58, 59; 59, string:'consequence'; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:consequences; 64, call; 64, 65; 64, 66; 65, identifier:set; 66, argument_list; 66, 67; 67, subscript; 67, 68; 67, 69; 68, identifier:filters; 69, string:'consequence'; 70, if_statement; 70, 71; 70, 77; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:filters; 74, identifier:get; 75, argument_list; 75, 76; 76, string:'sv_types'; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:sv_types; 81, call; 81, 82; 81, 83; 82, identifier:set; 83, argument_list; 83, 84; 84, subscript; 84, 85; 84, 86; 85, identifier:filters; 86, string:'sv_types'; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:logger; 91, identifier:info; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, string:"Get variants from {0}"; 96, identifier:format; 97, argument_list; 97, 98; 98, identifier:vcf_file_path; 99, if_statement; 99, 100; 99, 106; 99, 144; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:filters; 103, identifier:get; 104, argument_list; 104, 105; 105, string:'range'; 106, block; 106, 107; 106, 130; 106, 137; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:range_str; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, string:"{0}:{1}-{2}"; 113, identifier:format; 114, argument_list; 114, 115; 114, 120; 114, 125; 115, subscript; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:filters; 118, string:'range'; 119, string:'chromosome'; 120, subscript; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:filters; 123, string:'range'; 124, string:'start'; 125, subscript; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:filters; 128, string:'range'; 129, string:'end'; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:vcf; 133, call; 133, 134; 133, 135; 134, identifier:VCF; 135, argument_list; 135, 136; 136, identifier:vcf_file_path; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:handle; 140, call; 140, 141; 140, 142; 141, identifier:vcf; 142, argument_list; 142, 143; 143, identifier:range_str; 144, else_clause; 144, 145; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:handle; 149, call; 149, 150; 149, 151; 150, identifier:VCF; 151, argument_list; 151, 152; 152, identifier:vcf_file_path; 153, for_statement; 153, 154; 153, 155; 153, 156; 154, identifier:variant; 155, identifier:handle; 156, block; 156, 157; 156, 164; 156, 168; 156, 196; 156, 219; 156, 242; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:variant_line; 160, call; 160, 161; 160, 162; 161, identifier:str; 162, argument_list; 162, 163; 163, identifier:variant; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:keep_variant; 167, True; 168, if_statement; 168, 169; 168, 172; 169, boolean_operator:and; 169, 170; 169, 171; 170, identifier:genes; 171, identifier:keep_variant; 172, block; 172, 173; 172, 177; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:keep_variant; 176, False; 177, for_statement; 177, 178; 177, 179; 177, 180; 178, identifier:gene; 179, identifier:genes; 180, block; 180, 181; 181, if_statement; 181, 182; 181, 190; 182, comparison_operator:in; 182, 183; 182, 189; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:"{0}"; 186, identifier:format; 187, argument_list; 187, 188; 188, identifier:gene; 189, identifier:variant_line; 190, block; 190, 191; 190, 195; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:keep_variant; 194, True; 195, break_statement; 196, if_statement; 196, 197; 196, 200; 197, boolean_operator:and; 197, 198; 197, 199; 198, identifier:consequences; 199, identifier:keep_variant; 200, block; 200, 201; 200, 205; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:keep_variant; 204, False; 205, for_statement; 205, 206; 205, 207; 205, 208; 206, identifier:consequence; 207, identifier:consequences; 208, block; 208, 209; 209, if_statement; 209, 210; 209, 213; 210, comparison_operator:in; 210, 211; 210, 212; 211, identifier:consequence; 212, identifier:variant_line; 213, block; 213, 214; 213, 218; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:keep_variant; 217, True; 218, break_statement; 219, if_statement; 219, 220; 219, 223; 220, boolean_operator:and; 220, 221; 220, 222; 221, identifier:sv_types; 222, identifier:keep_variant; 223, block; 223, 224; 223, 228; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:keep_variant; 227, False; 228, for_statement; 228, 229; 228, 230; 228, 231; 229, identifier:sv_type; 230, identifier:sv_types; 231, block; 231, 232; 232, if_statement; 232, 233; 232, 236; 233, comparison_operator:in; 233, 234; 233, 235; 234, identifier:sv_type; 235, identifier:variant_line; 236, block; 236, 237; 236, 241; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:keep_variant; 240, True; 241, break_statement; 242, if_statement; 242, 243; 242, 244; 243, identifier:keep_variant; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, yield; 246, 247; 247, identifier:variant
def _get_filtered_variants(self, vcf_file_path, filters={}): genes = set() consequences = set() sv_types = set() if filters.get('gene_ids'): genes = set([gene_id.strip() for gene_id in filters['gene_ids']]) if filters.get('consequence'): consequences = set(filters['consequence']) if filters.get('sv_types'): sv_types = set(filters['sv_types']) logger.info("Get variants from {0}".format(vcf_file_path)) if filters.get('range'): range_str = "{0}:{1}-{2}".format( filters['range']['chromosome'], filters['range']['start'], filters['range']['end']) vcf = VCF(vcf_file_path) handle = vcf(range_str) else: handle = VCF(vcf_file_path) for variant in handle: variant_line = str(variant) keep_variant = True if genes and keep_variant: keep_variant = False for gene in genes: if "{0}".format(gene) in variant_line: keep_variant = True break if consequences and keep_variant: keep_variant = False for consequence in consequences: if consequence in variant_line: keep_variant = True break if sv_types and keep_variant: keep_variant = False for sv_type in sv_types: if sv_type in variant_line: keep_variant = True break if keep_variant: yield variant
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:group; 3, parameters; 3, 4; 3, 5; 4, identifier:iterable; 5, identifier:key; 6, block; 6, 7; 7, for_statement; 7, 8; 7, 11; 7, 24; 8, pattern_list; 8, 9; 8, 10; 9, identifier:_; 10, identifier:grouped; 11, call; 11, 12; 11, 13; 12, identifier:groupby; 13, argument_list; 13, 14; 13, 21; 14, call; 14, 15; 14, 16; 15, identifier:sorted; 16, argument_list; 16, 17; 16, 18; 17, identifier:iterable; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:key; 20, identifier:key; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, identifier:key; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, yield; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:list; 29, argument_list; 29, 30; 30, identifier:grouped
def group(iterable, key): for _, grouped in groupby(sorted(iterable, key=key), key=key): yield list(grouped)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 32; 5, 43; 5, 49; 5, 55; 5, 64; 5, 80; 5, 100; 5, 123; 5, 243; 5, 303; 6, expression_statement; 6, 7; 7, string:'''Run the LaTeX compilation.'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:old_dir; 13, list:[]; 14, if_statement; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:opt; 19, identifier:clean; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:old_dir; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:os; 29, identifier:listdir; 30, argument_list; 30, 31; 31, string:'.'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 38; 34, pattern_list; 34, 35; 34, 36; 34, 37; 35, identifier:cite_counter; 36, identifier:toc_file; 37, identifier:gloss_files; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_read_latex_files; 42, argument_list; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:latex_run; 48, argument_list; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:read_glossaries; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:gloss_changed; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:makeindex_runs; 62, argument_list; 62, 63; 63, identifier:gloss_files; 64, if_statement; 64, 65; 64, 73; 65, boolean_operator:or; 65, 66; 65, 67; 66, identifier:gloss_changed; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_is_toc_changed; 71, argument_list; 71, 72; 72, identifier:toc_file; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:latex_run; 79, argument_list; 80, if_statement; 80, 81; 80, 87; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:_need_bib_run; 85, argument_list; 85, 86; 86, identifier:cite_counter; 87, block; 87, 88; 87, 94; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:bibtex_run; 93, argument_list; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:latex_run; 99, argument_list; 100, while_statement; 100, 101; 100, 107; 101, parenthesized_expression; 101, 102; 102, comparison_operator:<; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:latex_run_counter; 106, identifier:MAX_RUNS; 107, block; 107, 108; 107, 117; 108, if_statement; 108, 109; 108, 115; 109, not_operator; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:need_latex_rerun; 114, argument_list; 115, block; 115, 116; 116, break_statement; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:latex_run; 122, argument_list; 123, if_statement; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:opt; 128, identifier:check_cite; 129, block; 129, 130; 129, 136; 129, 159; 129, 185; 129, 208; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:cites; 133, call; 133, 134; 133, 135; 134, identifier:set; 135, argument_list; 136, with_statement; 136, 137; 136, 150; 137, with_clause; 137, 138; 138, with_item; 138, 139; 139, as_pattern; 139, 140; 139, 148; 140, call; 140, 141; 140, 142; 141, identifier:open; 142, argument_list; 142, 143; 143, binary_operator:%; 143, 144; 143, 145; 144, string:'%s.aux'; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:project_name; 148, as_pattern_target; 148, 149; 149, identifier:fobj; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:aux_content; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:fobj; 157, identifier:read; 158, argument_list; 159, for_statement; 159, 160; 159, 161; 159, 167; 160, identifier:match; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:BIBCITE_PATTERN; 164, identifier:finditer; 165, argument_list; 165, 166; 166, identifier:aux_content; 167, block; 167, 168; 167, 178; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:name; 171, subscript; 171, 172; 171, 177; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:match; 175, identifier:groups; 176, argument_list; 177, integer:0; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:cites; 182, identifier:add; 183, argument_list; 183, 184; 184, identifier:name; 185, with_statement; 185, 186; 185, 199; 186, with_clause; 186, 187; 187, with_item; 187, 188; 188, as_pattern; 188, 189; 188, 197; 189, call; 189, 190; 189, 191; 190, identifier:open; 191, argument_list; 191, 192; 192, binary_operator:%; 192, 193; 192, 194; 193, string:'%s.bib'; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:bib_file; 197, as_pattern_target; 197, 198; 198, identifier:fobj; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:bib_content; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:fobj; 206, identifier:read; 207, argument_list; 208, for_statement; 208, 209; 208, 210; 208, 216; 209, identifier:match; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:BIBENTRY_PATTERN; 213, identifier:finditer; 214, argument_list; 214, 215; 215, identifier:bib_content; 216, block; 216, 217; 216, 227; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:name; 220, subscript; 220, 221; 220, 226; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:match; 224, identifier:groups; 225, argument_list; 226, integer:0; 227, if_statement; 227, 228; 227, 231; 228, comparison_operator:not; 228, 229; 228, 230; 229, identifier:name; 230, identifier:cites; 231, block; 231, 232; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 239; 234, attribute; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:log; 238, identifier:info; 239, argument_list; 239, 240; 240, binary_operator:%; 240, 241; 240, 242; 241, string:'Bib entry not cited: "%s"'; 242, identifier:name; 243, if_statement; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:opt; 248, identifier:clean; 249, block; 249, 250; 249, 254; 249, 265; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:ending; 253, string:'.dvi'; 254, if_statement; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:opt; 259, identifier:pdf; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:ending; 264, string:'.pdf'; 265, for_statement; 265, 266; 265, 267; 265, 273; 266, identifier:fname; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:os; 270, identifier:listdir; 271, argument_list; 271, 272; 272, string:'.'; 273, block; 273, 274; 274, if_statement; 274, 275; 274, 289; 275, not_operator; 275, 276; 276, parenthesized_expression; 276, 277; 277, boolean_operator:or; 277, 278; 277, 283; 278, comparison_operator:in; 278, 279; 278, 280; 279, identifier:fname; 280, attribute; 280, 281; 280, 282; 281, identifier:self; 282, identifier:old_dir; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:fname; 286, identifier:endswith; 287, argument_list; 287, 288; 288, identifier:ending; 289, block; 289, 290; 290, try_statement; 290, 291; 290, 299; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:os; 296, identifier:remove; 297, argument_list; 297, 298; 298, identifier:fname; 299, except_clause; 299, 300; 299, 301; 300, identifier:IOError; 301, block; 301, 302; 302, pass_statement; 303, if_statement; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:self; 307, identifier:opt; 308, identifier:preview; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:open_preview; 315, argument_list
def run(self): '''Run the LaTeX compilation.''' self.old_dir = [] if self.opt.clean: self.old_dir = os.listdir('.') cite_counter, toc_file, gloss_files = self._read_latex_files() self.latex_run() self.read_glossaries() gloss_changed = self.makeindex_runs(gloss_files) if gloss_changed or self._is_toc_changed(toc_file): self.latex_run() if self._need_bib_run(cite_counter): self.bibtex_run() self.latex_run() while (self.latex_run_counter < MAX_RUNS): if not self.need_latex_rerun(): break self.latex_run() if self.opt.check_cite: cites = set() with open('%s.aux' % self.project_name) as fobj: aux_content = fobj.read() for match in BIBCITE_PATTERN.finditer(aux_content): name = match.groups()[0] cites.add(name) with open('%s.bib' % self.bib_file) as fobj: bib_content = fobj.read() for match in BIBENTRY_PATTERN.finditer(bib_content): name = match.groups()[0] if name not in cites: self.log.info('Bib entry not cited: "%s"' % name) if self.opt.clean: ending = '.dvi' if self.opt.pdf: ending = '.pdf' for fname in os.listdir('.'): if not (fname in self.old_dir or fname.endswith(ending)): try: os.remove(fname) except IOError: pass if self.opt.preview: self.open_preview()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:embed_ising; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:source_linear; 5, identifier:source_quadratic; 6, identifier:embedding; 7, identifier:target_adjacency; 8, default_parameter; 8, 9; 8, 10; 9, identifier:chain_strength; 10, float:1.0; 11, block; 11, 12; 11, 34; 11, 44; 11, 130; 11, 134; 11, 300; 11, 304; 11, 323; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:unused; 15, binary_operator:-; 15, 16; 15, 21; 16, set_comprehension; 16, 17; 16, 18; 17, identifier:v; 18, for_in_clause; 18, 19; 18, 20; 19, identifier:v; 20, identifier:target_adjacency; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, call; 23, 24; 23, 25; 24, identifier:set; 25, argument_list; 26, identifier:union; 27, argument_list; 27, 28; 28, list_splat; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:embedding; 32, identifier:values; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:target_linear; 37, dictionary_comprehension; 37, 38; 37, 41; 38, pair; 38, 39; 38, 40; 39, identifier:v; 40, float:0.; 41, for_in_clause; 41, 42; 41, 43; 42, identifier:v; 43, identifier:target_adjacency; 44, for_statement; 44, 45; 44, 48; 44, 52; 45, pattern_list; 45, 46; 45, 47; 46, identifier:v; 47, identifier:bias; 48, call; 48, 49; 48, 50; 49, identifier:iteritems; 50, argument_list; 50, 51; 51, identifier:source_linear; 52, block; 52, 53; 52, 96; 52, 105; 53, try_statement; 53, 54; 53, 61; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:chain_variables; 58, subscript; 58, 59; 58, 60; 59, identifier:embedding; 60, identifier:v; 61, except_clause; 61, 62; 61, 63; 62, identifier:KeyError; 63, block; 63, 64; 63, 90; 64, try_statement; 64, 65; 64, 77; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:embedding; 70, identifier:v; 71, set; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:unused; 75, identifier:pop; 76, argument_list; 77, except_clause; 77, 78; 77, 79; 78, identifier:KeyError; 79, block; 79, 80; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:ValueError; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, string:'no embedding provided for source variable {}'; 87, identifier:format; 88, argument_list; 88, 89; 89, identifier:v; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:chain_variables; 93, subscript; 93, 94; 93, 95; 94, identifier:embedding; 95, identifier:v; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:b; 99, binary_operator:/; 99, 100; 99, 101; 100, identifier:bias; 101, call; 101, 102; 101, 103; 102, identifier:len; 103, argument_list; 103, 104; 104, identifier:chain_variables; 105, for_statement; 105, 106; 105, 107; 105, 108; 106, identifier:s; 107, identifier:chain_variables; 108, block; 108, 109; 109, try_statement; 109, 110; 109, 117; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, augmented_assignment:+=; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:target_linear; 115, identifier:s; 116, identifier:b; 117, except_clause; 117, 118; 117, 119; 118, identifier:KeyError; 119, block; 119, 120; 120, raise_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:ValueError; 123, argument_list; 123, 124; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, string:'chain variable {} not in target_adjacency'; 127, identifier:format; 128, argument_list; 128, 129; 129, identifier:s; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:target_quadratic; 133, dictionary; 134, for_statement; 134, 135; 134, 140; 134, 144; 135, pattern_list; 135, 136; 135, 139; 136, tuple_pattern; 136, 137; 136, 138; 137, identifier:u; 138, identifier:v; 139, identifier:bias; 140, call; 140, 141; 140, 142; 141, identifier:iteritems; 142, argument_list; 142, 143; 143, identifier:source_quadratic; 144, block; 144, 145; 144, 151; 144, 166; 144, 181; 144, 230; 144, 245; 144, 254; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:edges; 148, call; 148, 149; 148, 150; 149, identifier:set; 150, argument_list; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:not; 152, 153; 152, 154; 153, identifier:u; 154, identifier:embedding; 155, block; 155, 156; 156, raise_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:ValueError; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, string:'no embedding provided for source variable {}'; 163, identifier:format; 164, argument_list; 164, 165; 165, identifier:u; 166, if_statement; 166, 167; 166, 170; 167, comparison_operator:not; 167, 168; 167, 169; 168, identifier:v; 169, identifier:embedding; 170, block; 170, 171; 171, raise_statement; 171, 172; 172, call; 172, 173; 172, 174; 173, identifier:ValueError; 174, argument_list; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, string:'no embedding provided for source variable {}'; 178, identifier:format; 179, argument_list; 179, 180; 180, identifier:v; 181, for_statement; 181, 182; 181, 183; 181, 186; 182, identifier:s; 183, subscript; 183, 184; 183, 185; 184, identifier:embedding; 185, identifier:u; 186, block; 186, 187; 187, for_statement; 187, 188; 187, 189; 187, 192; 188, identifier:t; 189, subscript; 189, 190; 189, 191; 190, identifier:embedding; 191, identifier:v; 192, block; 192, 193; 193, try_statement; 193, 194; 193, 217; 194, block; 194, 195; 195, if_statement; 195, 196; 195, 207; 196, boolean_operator:and; 196, 197; 196, 202; 197, comparison_operator:in; 197, 198; 197, 199; 198, identifier:s; 199, subscript; 199, 200; 199, 201; 200, identifier:target_adjacency; 201, identifier:t; 202, comparison_operator:not; 202, 203; 202, 206; 203, tuple; 203, 204; 203, 205; 204, identifier:t; 205, identifier:s; 206, identifier:edges; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:edges; 212, identifier:add; 213, argument_list; 213, 214; 214, tuple; 214, 215; 214, 216; 215, identifier:s; 216, identifier:t; 217, except_clause; 217, 218; 217, 219; 218, identifier:KeyError; 219, block; 219, 220; 220, raise_statement; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:ValueError; 223, argument_list; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, string:'chain variable {} not in target_adjacency'; 227, identifier:format; 228, argument_list; 228, 229; 229, identifier:s; 230, if_statement; 230, 231; 230, 233; 231, not_operator; 231, 232; 232, identifier:edges; 233, block; 233, 234; 234, raise_statement; 234, 235; 235, call; 235, 236; 235, 237; 236, identifier:ValueError; 237, argument_list; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, string:"no edges in target graph between source variables {}, {}"; 241, identifier:format; 242, argument_list; 242, 243; 242, 244; 243, identifier:u; 244, identifier:v; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:b; 248, binary_operator:/; 248, 249; 248, 250; 249, identifier:bias; 250, call; 250, 251; 250, 252; 251, identifier:len; 252, argument_list; 252, 253; 253, identifier:edges; 254, for_statement; 254, 255; 254, 258; 254, 259; 255, pattern_list; 255, 256; 255, 257; 256, identifier:s; 257, identifier:t; 258, identifier:edges; 259, block; 259, 260; 260, if_statement; 260, 261; 260, 266; 260, 275; 260, 290; 261, comparison_operator:in; 261, 262; 261, 265; 262, tuple; 262, 263; 262, 264; 263, identifier:s; 264, identifier:t; 265, identifier:target_quadratic; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, augmented_assignment:+=; 268, 269; 268, 274; 269, subscript; 269, 270; 269, 271; 270, identifier:target_quadratic; 271, tuple; 271, 272; 271, 273; 272, identifier:s; 273, identifier:t; 274, identifier:b; 275, elif_clause; 275, 276; 275, 281; 276, comparison_operator:in; 276, 277; 276, 280; 277, tuple; 277, 278; 277, 279; 278, identifier:t; 279, identifier:s; 280, identifier:target_quadratic; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, augmented_assignment:+=; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 286; 285, identifier:target_quadratic; 286, tuple; 286, 287; 286, 288; 287, identifier:t; 288, identifier:s; 289, identifier:b; 290, else_clause; 290, 291; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 299; 294, subscript; 294, 295; 294, 296; 295, identifier:target_quadratic; 296, tuple; 296, 297; 296, 298; 297, identifier:s; 298, identifier:t; 299, identifier:b; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:chain_quadratic; 303, dictionary; 304, for_statement; 304, 305; 304, 306; 304, 310; 305, identifier:chain; 306, call; 306, 307; 306, 308; 307, identifier:itervalues; 308, argument_list; 308, 309; 309, identifier:embedding; 310, block; 310, 311; 311, expression_statement; 311, 312; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:chain_quadratic; 315, identifier:update; 316, argument_list; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:chain_to_quadratic; 319, argument_list; 319, 320; 319, 321; 319, 322; 320, identifier:chain; 321, identifier:target_adjacency; 322, identifier:chain_strength; 323, return_statement; 323, 324; 324, expression_list; 324, 325; 324, 326; 324, 327; 325, identifier:target_linear; 326, identifier:target_quadratic; 327, identifier:chain_quadratic
def embed_ising(source_linear, source_quadratic, embedding, target_adjacency, chain_strength=1.0): unused = {v for v in target_adjacency} - set().union(*embedding.values()) target_linear = {v: 0. for v in target_adjacency} for v, bias in iteritems(source_linear): try: chain_variables = embedding[v] except KeyError: try: embedding[v] = {unused.pop()} except KeyError: raise ValueError('no embedding provided for source variable {}'.format(v)) chain_variables = embedding[v] b = bias / len(chain_variables) for s in chain_variables: try: target_linear[s] += b except KeyError: raise ValueError('chain variable {} not in target_adjacency'.format(s)) target_quadratic = {} for (u, v), bias in iteritems(source_quadratic): edges = set() if u not in embedding: raise ValueError('no embedding provided for source variable {}'.format(u)) if v not in embedding: raise ValueError('no embedding provided for source variable {}'.format(v)) for s in embedding[u]: for t in embedding[v]: try: if s in target_adjacency[t] and (t, s) not in edges: edges.add((s, t)) except KeyError: raise ValueError('chain variable {} not in target_adjacency'.format(s)) if not edges: raise ValueError("no edges in target graph between source variables {}, {}".format(u, v)) b = bias / len(edges) for s, t in edges: if (s, t) in target_quadratic: target_quadratic[(s, t)] += b elif (t, s) in target_quadratic: target_quadratic[(t, s)] += b else: target_quadratic[(s, t)] = b chain_quadratic = {} for chain in itervalues(embedding): chain_quadratic.update(chain_to_quadratic(chain, target_adjacency, chain_strength)) return target_linear, target_quadratic, chain_quadratic
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:fit_richness; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:atol; 7, float:1.e-3; 8, default_parameter; 8, 9; 8, 10; 9, identifier:maxiter; 10, integer:50; 11, block; 11, 12; 11, 38; 11, 61; 11, 80; 11, 100; 11, 120; 11, 124; 11, 128; 11, 240; 11, 249; 12, if_statement; 12, 13; 12, 25; 13, call; 13, 14; 13, 24; 14, attribute; 14, 15; 14, 23; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:np; 18, identifier:isnan; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:u; 23, identifier:any; 24, argument_list; 25, block; 25, 26; 25, 33; 26, expression_statement; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:logger; 30, identifier:warning; 31, argument_list; 31, 32; 32, string:"NaN signal probability found"; 33, return_statement; 33, 34; 34, expression_list; 34, 35; 34, 36; 34, 37; 35, float:0.; 36, float:0.; 37, None; 38, if_statement; 38, 39; 38, 48; 39, not_operator; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:np; 43, identifier:any; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:u; 48, block; 48, 49; 48, 56; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:logger; 53, identifier:warning; 54, argument_list; 54, 55; 55, string:"Signal probability is zero for all objects"; 56, return_statement; 56, 57; 57, expression_list; 57, 58; 57, 59; 57, 60; 58, float:0.; 59, float:0.; 60, None; 61, if_statement; 61, 62; 61, 67; 62, comparison_operator:==; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:f; 66, integer:0; 67, block; 67, 68; 67, 75; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:logger; 72, identifier:warning; 73, argument_list; 73, 74; 74, string:"Observable fraction is zero"; 75, return_statement; 75, 76; 76, expression_list; 76, 77; 76, 78; 76, 79; 77, float:0.; 78, float:0.; 79, None; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:richness; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:np; 86, identifier:array; 87, argument_list; 87, 88; 88, list:[0., 1./self.f, 10./self.f]; 88, 89; 88, 90; 88, 95; 89, float:0.; 90, binary_operator:/; 90, 91; 90, 92; 91, float:1.; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:f; 95, binary_operator:/; 95, 96; 95, 97; 96, float:10.; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:f; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:loglike; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:array; 107, argument_list; 107, 108; 108, list_comprehension; 108, 109; 108, 117; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:value; 113, argument_list; 113, 114; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:richness; 116, identifier:r; 117, for_in_clause; 117, 118; 117, 119; 118, identifier:r; 119, identifier:richness; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:found_maximum; 123, False; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:iteration; 127, integer:0; 128, while_statement; 128, 129; 128, 131; 129, not_operator; 129, 130; 130, identifier:found_maximum; 131, block; 131, 132; 131, 148; 131, 223; 131, 227; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:parabola; 135, call; 135, 136; 135, 143; 136, attribute; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:ugali; 140, identifier:utils; 141, identifier:parabola; 142, identifier:Parabola; 143, argument_list; 143, 144; 143, 145; 144, identifier:richness; 145, binary_operator:*; 145, 146; 145, 147; 146, float:2.; 147, identifier:loglike; 148, if_statement; 148, 149; 148, 154; 148, 159; 149, comparison_operator:<; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:parabola; 152, identifier:vertex_x; 153, float:0.; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:found_maximum; 158, True; 159, else_clause; 159, 160; 160, block; 160, 161; 160, 173; 160, 193; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:richness; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:np; 167, identifier:append; 168, argument_list; 168, 169; 168, 170; 169, identifier:richness; 170, attribute; 170, 171; 170, 172; 171, identifier:parabola; 172, identifier:vertex_x; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:loglike; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:np; 179, identifier:append; 180, argument_list; 180, 181; 180, 182; 181, identifier:loglike; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:value; 186, argument_list; 186, 187; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:richness; 189, subscript; 189, 190; 189, 191; 190, identifier:richness; 191, unary_operator:-; 191, 192; 192, integer:1; 193, if_statement; 193, 194; 193, 218; 194, comparison_operator:<; 194, 195; 194, 217; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:np; 198, identifier:fabs; 199, argument_list; 199, 200; 200, binary_operator:-; 200, 201; 200, 205; 201, subscript; 201, 202; 201, 203; 202, identifier:loglike; 203, unary_operator:-; 203, 204; 204, integer:1; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:np; 208, identifier:max; 209, argument_list; 209, 210; 210, subscript; 210, 211; 210, 212; 211, identifier:loglike; 212, slice; 212, 213; 212, 214; 212, 215; 213, integer:0; 214, colon; 215, unary_operator:-; 215, 216; 216, integer:1; 217, identifier:atol; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:found_maximum; 222, True; 223, expression_statement; 223, 224; 224, augmented_assignment:+=; 224, 225; 224, 226; 225, identifier:iteration; 226, integer:1; 227, if_statement; 227, 228; 227, 231; 228, comparison_operator:>; 228, 229; 228, 230; 229, identifier:iteration; 230, identifier:maxiter; 231, block; 231, 232; 231, 239; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:logger; 236, identifier:warning; 237, argument_list; 237, 238; 238, string:"Maximum number of iterations reached"; 239, break_statement; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:index; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:np; 246, identifier:argmax; 247, argument_list; 247, 248; 248, identifier:loglike; 249, return_statement; 249, 250; 250, expression_list; 250, 251; 250, 254; 250, 257; 251, subscript; 251, 252; 251, 253; 252, identifier:loglike; 253, identifier:index; 254, subscript; 254, 255; 254, 256; 255, identifier:richness; 256, identifier:index; 257, identifier:parabola
def fit_richness(self, atol=1.e-3, maxiter=50): if np.isnan(self.u).any(): logger.warning("NaN signal probability found") return 0., 0., None if not np.any(self.u): logger.warning("Signal probability is zero for all objects") return 0., 0., None if self.f == 0: logger.warning("Observable fraction is zero") return 0., 0., None richness = np.array([0., 1./self.f, 10./self.f]) loglike = np.array([self.value(richness=r) for r in richness]) found_maximum = False iteration = 0 while not found_maximum: parabola = ugali.utils.parabola.Parabola(richness, 2.*loglike) if parabola.vertex_x < 0.: found_maximum = True else: richness = np.append(richness, parabola.vertex_x) loglike = np.append(loglike, self.value(richness=richness[-1])) if np.fabs(loglike[-1] - np.max(loglike[0: -1])) < atol: found_maximum = True iteration+=1 if iteration > maxiter: logger.warning("Maximum number of iterations reached") break index = np.argmax(loglike) return loglike[index], richness[index], parabola
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:make_request; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:url; 5, default_parameter; 5, 6; 5, 7; 6, identifier:method; 7, string:'GET'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:query; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:body; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:auth; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:timeout; 19, integer:10; 20, default_parameter; 20, 21; 20, 22; 21, identifier:client; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:macaroons; 25, None; 26, block; 26, 27; 26, 31; 26, 41; 26, 70; 26, 121; 26, 132; 26, 147; 26, 159; 26, 202; 26, 263; 26, 271; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:headers; 30, dictionary; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:kwargs; 34, dictionary; 34, 35; 34, 38; 35, pair; 35, 36; 35, 37; 36, string:'timeout'; 37, identifier:timeout; 38, pair; 38, 39; 38, 40; 39, string:'headers'; 40, identifier:headers; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:body; 44, None; 45, block; 45, 46; 45, 64; 46, if_statement; 46, 47; 46, 54; 47, call; 47, 48; 47, 49; 48, identifier:isinstance; 49, argument_list; 49, 50; 49, 51; 50, identifier:body; 51, attribute; 51, 52; 51, 53; 52, identifier:collections; 53, identifier:Mapping; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:body; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:json; 61, identifier:dumps; 62, argument_list; 62, 63; 63, identifier:body; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:kwargs; 68, string:'data'; 69, identifier:body; 70, if_statement; 70, 71; 70, 76; 70, 94; 70, 109; 71, comparison_operator:in; 71, 72; 71, 73; 72, identifier:method; 73, tuple; 73, 74; 73, 75; 74, string:'GET'; 75, string:'HEAD'; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 79; 78, identifier:query; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:url; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, string:'{}?{}'; 86, identifier:format; 87, argument_list; 87, 88; 87, 89; 88, identifier:url; 89, call; 89, 90; 89, 91; 90, identifier:urlencode; 91, argument_list; 91, 92; 91, 93; 92, identifier:query; 93, True; 94, elif_clause; 94, 95; 94, 102; 95, comparison_operator:in; 95, 96; 95, 97; 96, identifier:method; 97, tuple; 97, 98; 97, 99; 97, 100; 97, 101; 98, string:'DELETE'; 99, string:'PATCH'; 100, string:'POST'; 101, string:'PUT'; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:headers; 107, string:'Content-Type'; 108, string:'application/json'; 109, else_clause; 109, 110; 110, block; 110, 111; 111, raise_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:ValueError; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:'invalid method {}'; 118, identifier:format; 119, argument_list; 119, 120; 120, identifier:method; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:macaroons; 124, None; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:headers; 130, string:'Macaroons'; 131, identifier:macaroons; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:kwargs; 136, string:'auth'; 137, conditional_expression:if; 137, 138; 137, 139; 137, 142; 138, identifier:auth; 139, comparison_operator:is; 139, 140; 139, 141; 140, identifier:client; 141, None; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:client; 145, identifier:auth; 146, argument_list; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:api_method; 150, call; 150, 151; 150, 152; 151, identifier:getattr; 152, argument_list; 152, 153; 152, 154; 153, identifier:requests; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:method; 157, identifier:lower; 158, argument_list; 159, try_statement; 159, 160; 159, 170; 159, 183; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:response; 164, call; 164, 165; 164, 166; 165, identifier:api_method; 166, argument_list; 166, 167; 166, 168; 167, identifier:url; 168, dictionary_splat; 168, 169; 169, identifier:kwargs; 170, except_clause; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:requests; 174, identifier:exceptions; 175, identifier:Timeout; 176, block; 176, 177; 177, raise_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:timeout_error; 180, argument_list; 180, 181; 180, 182; 181, identifier:url; 182, identifier:timeout; 183, except_clause; 183, 184; 183, 188; 184, as_pattern; 184, 185; 184, 186; 185, identifier:Exception; 186, as_pattern_target; 186, 187; 187, identifier:err; 188, block; 188, 189; 188, 197; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:msg; 192, call; 192, 193; 192, 194; 193, identifier:_server_error_message; 194, argument_list; 194, 195; 194, 196; 195, identifier:url; 196, identifier:err; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:ServerError; 200, argument_list; 200, 201; 201, identifier:msg; 202, try_statement; 202, 203; 202, 210; 202, 238; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:response; 208, identifier:raise_for_status; 209, argument_list; 210, except_clause; 210, 211; 210, 215; 211, as_pattern; 211, 212; 211, 213; 212, identifier:HTTPError; 213, as_pattern_target; 213, 214; 214, identifier:err; 215, block; 215, 216; 215, 228; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:msg; 219, call; 219, 220; 219, 221; 220, identifier:_server_error_message; 221, argument_list; 221, 222; 221, 223; 222, identifier:url; 223, attribute; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:err; 226, identifier:response; 227, identifier:text; 228, raise_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:ServerError; 231, argument_list; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:err; 235, identifier:response; 236, identifier:status_code; 237, identifier:msg; 238, except_clause; 238, 239; 238, 247; 239, as_pattern; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:requests; 243, identifier:exceptions; 244, identifier:RequestException; 245, as_pattern_target; 245, 246; 246, identifier:err; 247, block; 247, 248; 247, 258; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:msg; 251, call; 251, 252; 251, 253; 252, identifier:_server_error_message; 253, argument_list; 253, 254; 253, 255; 254, identifier:url; 255, attribute; 255, 256; 255, 257; 256, identifier:err; 257, identifier:message; 258, raise_statement; 258, 259; 259, call; 259, 260; 259, 261; 260, identifier:ServerError; 261, argument_list; 261, 262; 262, identifier:msg; 263, if_statement; 263, 264; 263, 268; 264, not_operator; 264, 265; 265, attribute; 265, 266; 265, 267; 266, identifier:response; 267, identifier:content; 268, block; 268, 269; 269, return_statement; 269, 270; 270, dictionary; 271, try_statement; 271, 272; 271, 279; 272, block; 272, 273; 273, return_statement; 273, 274; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:response; 277, identifier:json; 278, argument_list; 279, except_clause; 279, 280; 279, 284; 280, as_pattern; 280, 281; 280, 282; 281, identifier:Exception; 282, as_pattern_target; 282, 283; 283, identifier:err; 284, block; 284, 285; 284, 295; 284, 302; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:msg; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, string:'Error decoding JSON response: {} message: {}'; 291, identifier:format; 292, argument_list; 292, 293; 292, 294; 293, identifier:url; 294, identifier:err; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:log; 299, identifier:error; 300, argument_list; 300, 301; 301, identifier:msg; 302, raise_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:ServerError; 305, argument_list; 305, 306; 306, identifier:msg
def make_request( url, method='GET', query=None, body=None, auth=None, timeout=10, client=None, macaroons=None): headers = {} kwargs = {'timeout': timeout, 'headers': headers} if body is not None: if isinstance(body, collections.Mapping): body = json.dumps(body) kwargs['data'] = body if method in ('GET', 'HEAD'): if query: url = '{}?{}'.format(url, urlencode(query, True)) elif method in ('DELETE', 'PATCH', 'POST', 'PUT'): headers['Content-Type'] = 'application/json' else: raise ValueError('invalid method {}'.format(method)) if macaroons is not None: headers['Macaroons'] = macaroons kwargs['auth'] = auth if client is None else client.auth() api_method = getattr(requests, method.lower()) try: response = api_method(url, **kwargs) except requests.exceptions.Timeout: raise timeout_error(url, timeout) except Exception as err: msg = _server_error_message(url, err) raise ServerError(msg) try: response.raise_for_status() except HTTPError as err: msg = _server_error_message(url, err.response.text) raise ServerError(err.response.status_code, msg) except requests.exceptions.RequestException as err: msg = _server_error_message(url, err.message) raise ServerError(msg) if not response.content: return {} try: return response.json() except Exception as err: msg = 'Error decoding JSON response: {} message: {}'.format(url, err) log.error(msg) raise ServerError(msg)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:time_stops; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 14; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:supports_time; 11, block; 11, 12; 12, return_statement; 12, 13; 13, list:[]; 14, if_statement; 14, 15; 14, 22; 14, 325; 15, comparison_operator:==; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:service; 20, identifier:calendar; 21, string:'standard'; 22, block; 22, 23; 22, 31; 22, 39; 22, 46; 22, 288; 22, 323; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:units; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:service; 30, identifier:time_interval_units; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:interval; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:service; 38, identifier:time_interval; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:steps; 42, list:[self.time_start]; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:time_start; 46, if_statement; 46, 47; 46, 53; 46, 100; 46, 177; 47, comparison_operator:in; 47, 48; 47, 49; 48, identifier:units; 49, tuple; 49, 50; 49, 51; 49, 52; 50, string:'years'; 51, string:'decades'; 52, string:'centuries'; 53, block; 53, 54; 53, 82; 54, if_statement; 54, 55; 54, 58; 54, 63; 54, 74; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:units; 57, string:'years'; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:years; 62, identifier:interval; 63, elif_clause; 63, 64; 63, 67; 64, comparison_operator:==; 64, 65; 64, 66; 65, identifier:units; 66, string:'decades'; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:years; 71, binary_operator:*; 71, 72; 71, 73; 72, integer:10; 73, identifier:interval; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:years; 79, binary_operator:*; 79, 80; 79, 81; 80, integer:100; 81, identifier:interval; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:next_value; 85, lambda; 85, 86; 85, 88; 86, lambda_parameters; 86, 87; 87, identifier:x; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:x; 91, identifier:replace; 92, argument_list; 92, 93; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:year; 95, binary_operator:+; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:x; 98, identifier:year; 99, identifier:years; 100, elif_clause; 100, 101; 100, 104; 101, comparison_operator:==; 101, 102; 101, 103; 102, identifier:units; 103, string:'months'; 104, block; 104, 105; 104, 173; 105, function_definition; 105, 106; 105, 107; 105, 109; 106, function_name:_fn; 107, parameters; 107, 108; 108, identifier:x; 109, block; 109, 110; 109, 127; 109, 140; 109, 158; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:year; 113, binary_operator:+; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:x; 116, identifier:year; 117, binary_operator://; 117, 118; 117, 126; 118, parenthesized_expression; 118, 119; 119, binary_operator:-; 119, 120; 119, 125; 120, binary_operator:+; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:x; 123, identifier:month; 124, identifier:interval; 125, integer:1; 126, integer:12; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:month; 130, boolean_operator:or; 130, 131; 130, 139; 131, binary_operator:%; 131, 132; 131, 138; 132, parenthesized_expression; 132, 133; 133, binary_operator:+; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:x; 136, identifier:month; 137, identifier:interval; 138, integer:12; 139, integer:12; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:day; 143, call; 143, 144; 143, 145; 144, identifier:min; 145, argument_list; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:x; 148, identifier:day; 149, subscript; 149, 150; 149, 157; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:calendar; 153, identifier:monthrange; 154, argument_list; 154, 155; 154, 156; 155, identifier:year; 156, identifier:month; 157, integer:1; 158, return_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:x; 162, identifier:replace; 163, argument_list; 163, 164; 163, 167; 163, 170; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:year; 166, identifier:year; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:month; 169, identifier:month; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:day; 172, identifier:day; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:next_value; 176, identifier:_fn; 177, else_clause; 177, 178; 178, block; 178, 179; 178, 279; 179, if_statement; 179, 180; 179, 183; 179, 193; 179, 207; 179, 221; 179, 235; 179, 249; 179, 263; 180, comparison_operator:==; 180, 181; 180, 182; 181, identifier:units; 182, string:'milliseconds'; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:delta; 187, call; 187, 188; 187, 189; 188, identifier:timedelta; 189, argument_list; 189, 190; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:milliseconds; 192, identifier:interval; 193, elif_clause; 193, 194; 193, 197; 194, comparison_operator:==; 194, 195; 194, 196; 195, identifier:units; 196, string:'seconds'; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:delta; 201, call; 201, 202; 201, 203; 202, identifier:timedelta; 203, argument_list; 203, 204; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:seconds; 206, identifier:interval; 207, elif_clause; 207, 208; 207, 211; 208, comparison_operator:==; 208, 209; 208, 210; 209, identifier:units; 210, string:'minutes'; 211, block; 211, 212; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:delta; 215, call; 215, 216; 215, 217; 216, identifier:timedelta; 217, argument_list; 217, 218; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:minutes; 220, identifier:interval; 221, elif_clause; 221, 222; 221, 225; 222, comparison_operator:==; 222, 223; 222, 224; 223, identifier:units; 224, string:'hours'; 225, block; 225, 226; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:delta; 229, call; 229, 230; 229, 231; 230, identifier:timedelta; 231, argument_list; 231, 232; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:hours; 234, identifier:interval; 235, elif_clause; 235, 236; 235, 239; 236, comparison_operator:==; 236, 237; 236, 238; 237, identifier:units; 238, string:'days'; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:delta; 243, call; 243, 244; 243, 245; 244, identifier:timedelta; 245, argument_list; 245, 246; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:days; 248, identifier:interval; 249, elif_clause; 249, 250; 249, 253; 250, comparison_operator:==; 250, 251; 250, 252; 251, identifier:units; 252, string:'weeks'; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:delta; 257, call; 257, 258; 257, 259; 258, identifier:timedelta; 259, argument_list; 259, 260; 260, keyword_argument; 260, 261; 260, 262; 261, identifier:weeks; 262, identifier:interval; 263, else_clause; 263, 264; 264, block; 264, 265; 265, raise_statement; 265, 266; 266, call; 266, 267; 266, 268; 267, identifier:ValidationError; 268, argument_list; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, string:"Service has an invalid time_interval_units: {}"; 272, identifier:format; 273, argument_list; 273, 274; 274, attribute; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:service; 278, identifier:time_interval_units; 279, expression_statement; 279, 280; 280, assignment; 280, 281; 280, 282; 281, identifier:next_value; 282, lambda; 282, 283; 282, 285; 283, lambda_parameters; 283, 284; 284, identifier:x; 285, binary_operator:+; 285, 286; 285, 287; 286, identifier:x; 287, identifier:delta; 288, while_statement; 288, 289; 288, 297; 289, comparison_operator:<; 289, 290; 289, 294; 290, subscript; 290, 291; 290, 292; 291, identifier:steps; 292, unary_operator:-; 292, 293; 293, integer:1; 294, attribute; 294, 295; 294, 296; 295, identifier:self; 296, identifier:time_end; 297, block; 297, 298; 297, 308; 297, 316; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:value; 301, call; 301, 302; 301, 303; 302, identifier:next_value; 303, argument_list; 303, 304; 304, subscript; 304, 305; 304, 306; 305, identifier:steps; 306, unary_operator:-; 306, 307; 307, integer:1; 308, if_statement; 308, 309; 308, 314; 309, comparison_operator:>; 309, 310; 309, 311; 310, identifier:value; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:time_end; 314, block; 314, 315; 315, break_statement; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:steps; 320, identifier:append; 321, argument_list; 321, 322; 322, identifier:value; 323, return_statement; 323, 324; 324, identifier:steps; 325, else_clause; 325, 326; 326, block; 326, 327; 327, raise_statement; 327, 328; 328, identifier:NotImplementedError
def time_stops(self): if not self.supports_time: return [] if self.service.calendar == 'standard': units = self.service.time_interval_units interval = self.service.time_interval steps = [self.time_start] if units in ('years', 'decades', 'centuries'): if units == 'years': years = interval elif units == 'decades': years = 10 * interval else: years = 100 * interval next_value = lambda x: x.replace(year=x.year + years) elif units == 'months': def _fn(x): year = x.year + (x.month+interval-1) // 12 month = (x.month+interval) % 12 or 12 day = min(x.day, calendar.monthrange(year, month)[1]) return x.replace(year=year, month=month, day=day) next_value = _fn else: if units == 'milliseconds': delta = timedelta(milliseconds=interval) elif units == 'seconds': delta = timedelta(seconds=interval) elif units == 'minutes': delta = timedelta(minutes=interval) elif units == 'hours': delta = timedelta(hours=interval) elif units == 'days': delta = timedelta(days=interval) elif units == 'weeks': delta = timedelta(weeks=interval) else: raise ValidationError( "Service has an invalid time_interval_units: {}".format(self.service.time_interval_units) ) next_value = lambda x: x + delta while steps[-1] < self.time_end: value = next_value(steps[-1]) if value > self.time_end: break steps.append(value) return steps else: raise NotImplementedError
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:sort_strings; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:strings; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sort_order; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:case_sensitive; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort_order_first; 16, True; 17, block; 17, 18; 17, 50; 17, 63; 17, 200; 18, if_statement; 18, 19; 18, 21; 19, not_operator; 19, 20; 20, identifier:case_sensitive; 21, block; 21, 22; 21, 36; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:sort_order; 25, call; 25, 26; 25, 27; 26, identifier:tuple; 27, generator_expression; 27, 28; 27, 33; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:s; 31, identifier:lower; 32, argument_list; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:s; 35, identifier:sort_order; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:strings; 39, call; 39, 40; 39, 41; 40, identifier:tuple; 41, generator_expression; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:s; 45, identifier:lower; 46, argument_list; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:s; 49, identifier:strings; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:prefix_len; 53, call; 53, 54; 53, 55; 54, identifier:max; 55, generator_expression; 55, 56; 55, 60; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, identifier:s; 60, for_in_clause; 60, 61; 60, 62; 61, identifier:s; 62, identifier:sort_order; 63, function_definition; 63, 64; 63, 65; 63, 71; 64, function_name:compare; 65, parameters; 65, 66; 65, 67; 65, 68; 66, identifier:a; 67, identifier:b; 68, default_parameter; 68, 69; 68, 70; 69, identifier:prefix_len; 70, identifier:prefix_len; 71, block; 71, 72; 71, 176; 72, if_statement; 72, 73; 72, 74; 73, identifier:prefix_len; 74, block; 74, 75; 75, if_statement; 75, 76; 75, 83; 75, 158; 76, comparison_operator:in; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 79; 78, identifier:a; 79, slice; 79, 80; 79, 81; 80, colon; 81, identifier:prefix_len; 82, identifier:sort_order; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 92; 84, 144; 85, comparison_operator:in; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 88; 87, identifier:b; 88, slice; 88, 89; 88, 90; 89, colon; 90, identifier:prefix_len; 91, identifier:sort_order; 92, block; 92, 93; 92, 117; 92, 131; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:comparison; 96, binary_operator:-; 96, 97; 96, 107; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:sort_order; 100, identifier:index; 101, argument_list; 101, 102; 102, subscript; 102, 103; 102, 104; 103, identifier:a; 104, slice; 104, 105; 104, 106; 105, colon; 106, identifier:prefix_len; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:sort_order; 110, identifier:index; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:b; 114, slice; 114, 115; 114, 116; 115, colon; 116, identifier:prefix_len; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:comparison; 120, call; 120, 121; 120, 122; 121, identifier:int; 122, argument_list; 122, 123; 123, binary_operator:/; 123, 124; 123, 125; 124, identifier:comparison; 125, call; 125, 126; 125, 127; 126, identifier:abs; 127, argument_list; 127, 128; 128, boolean_operator:or; 128, 129; 128, 130; 129, identifier:comparison; 130, integer:1; 131, if_statement; 131, 132; 131, 133; 132, identifier:comparison; 133, block; 133, 134; 134, return_statement; 134, 135; 135, binary_operator:*; 135, 136; 135, 137; 136, identifier:comparison; 137, parenthesized_expression; 137, 138; 138, binary_operator:+; 138, 139; 138, 143; 139, binary_operator:*; 139, 140; 139, 142; 140, unary_operator:-; 140, 141; 141, integer:2; 142, identifier:reverse; 143, integer:1; 144, elif_clause; 144, 145; 144, 146; 145, identifier:sort_order_first; 146, block; 146, 147; 147, return_statement; 147, 148; 148, binary_operator:*; 148, 149; 148, 151; 149, unary_operator:-; 149, 150; 150, integer:1; 151, parenthesized_expression; 151, 152; 152, binary_operator:+; 152, 153; 152, 157; 153, binary_operator:*; 153, 154; 153, 156; 154, unary_operator:-; 154, 155; 155, integer:2; 156, identifier:reverse; 157, integer:1; 158, elif_clause; 158, 159; 158, 168; 159, boolean_operator:and; 159, 160; 159, 161; 160, identifier:sort_order_first; 161, comparison_operator:in; 161, 162; 161, 167; 162, subscript; 162, 163; 162, 164; 163, identifier:b; 164, slice; 164, 165; 164, 166; 165, colon; 166, identifier:prefix_len; 167, identifier:sort_order; 168, block; 168, 169; 169, return_statement; 169, 170; 170, binary_operator:+; 170, 171; 170, 175; 171, binary_operator:*; 171, 172; 171, 174; 172, unary_operator:-; 172, 173; 173, integer:2; 174, identifier:reverse; 175, integer:1; 176, return_statement; 176, 177; 177, binary_operator:*; 177, 178; 177, 193; 178, parenthesized_expression; 178, 179; 179, binary_operator:+; 179, 180; 179, 187; 180, binary_operator:*; 180, 181; 180, 183; 181, unary_operator:-; 181, 182; 182, integer:1; 183, parenthesized_expression; 183, 184; 184, comparison_operator:<; 184, 185; 184, 186; 185, identifier:a; 186, identifier:b; 187, binary_operator:*; 187, 188; 187, 189; 188, integer:1; 189, parenthesized_expression; 189, 190; 190, comparison_operator:>; 190, 191; 190, 192; 191, identifier:a; 192, identifier:b; 193, parenthesized_expression; 193, 194; 194, binary_operator:+; 194, 195; 194, 199; 195, binary_operator:*; 195, 196; 195, 198; 196, unary_operator:-; 196, 197; 197, integer:2; 198, identifier:reverse; 199, integer:1; 200, return_statement; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:sorted; 203, argument_list; 203, 204; 203, 205; 204, identifier:strings; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:key; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:functools; 210, identifier:cmp_to_key; 211, argument_list; 211, 212; 212, identifier:compare
def sort_strings(strings, sort_order=None, reverse=False, case_sensitive=False, sort_order_first=True): if not case_sensitive: sort_order = tuple(s.lower() for s in sort_order) strings = tuple(s.lower() for s in strings) prefix_len = max(len(s) for s in sort_order) def compare(a, b, prefix_len=prefix_len): if prefix_len: if a[:prefix_len] in sort_order: if b[:prefix_len] in sort_order: comparison = sort_order.index(a[:prefix_len]) - sort_order.index(b[:prefix_len]) comparison = int(comparison / abs(comparison or 1)) if comparison: return comparison * (-2 * reverse + 1) elif sort_order_first: return -1 * (-2 * reverse + 1) elif sort_order_first and b[:prefix_len] in sort_order: return -2 * reverse + 1 return (-1 * (a < b) + 1 * (a > b)) * (-2 * reverse + 1) return sorted(strings, key=functools.cmp_to_key(compare))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:clean_field_dict; 3, parameters; 3, 4; 3, 5; 3, 10; 4, identifier:field_dict; 5, default_parameter; 5, 6; 5, 7; 6, identifier:cleaner; 7, attribute; 7, 8; 7, 9; 8, identifier:str; 9, identifier:strip; 10, default_parameter; 10, 11; 10, 12; 11, identifier:time_zone; 12, None; 13, block; 13, 14; 13, 16; 13, 20; 13, 29; 13, 95; 14, expression_statement; 14, 15; 15, identifier:r; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:d; 19, dictionary; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:time_zone; 23, None; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:tz; 28, identifier:DEFAULT_TZ; 29, for_statement; 29, 30; 29, 33; 29, 37; 30, pattern_list; 30, 31; 30, 32; 31, identifier:k; 32, identifier:v; 33, call; 33, 34; 33, 35; 34, identifier:viewitems; 35, argument_list; 35, 36; 36, identifier:field_dict; 37, block; 37, 38; 37, 44; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:==; 39, 40; 39, 41; 40, identifier:k; 41, string:'_state'; 42, block; 42, 43; 43, continue_statement; 44, if_statement; 44, 45; 44, 50; 44, 63; 44, 87; 45, call; 45, 46; 45, 47; 46, identifier:isinstance; 47, argument_list; 47, 48; 47, 49; 48, identifier:v; 49, identifier:basestring; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:d; 55, identifier:k; 56, call; 56, 57; 56, 58; 57, identifier:cleaner; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:str; 61, argument_list; 61, 62; 62, identifier:v; 63, elif_clause; 63, 64; 63, 75; 64, call; 64, 65; 64, 66; 65, identifier:isinstance; 66, argument_list; 66, 67; 66, 68; 67, identifier:v; 68, tuple; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:datetime; 71, identifier:datetime; 72, attribute; 72, 73; 72, 74; 73, identifier:datetime; 74, identifier:date; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, subscript; 78, 79; 78, 80; 79, identifier:d; 80, identifier:k; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:tz; 84, identifier:localize; 85, argument_list; 85, 86; 86, identifier:v; 87, else_clause; 87, 88; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:d; 93, identifier:k; 94, identifier:v; 95, return_statement; 95, 96; 96, identifier:d
def clean_field_dict(field_dict, cleaner=str.strip, time_zone=None): r d = {} if time_zone is None: tz = DEFAULT_TZ for k, v in viewitems(field_dict): if k == '_state': continue if isinstance(v, basestring): d[k] = cleaner(str(v)) elif isinstance(v, (datetime.datetime, datetime.date)): d[k] = tz.localize(v) else: d[k] = v return d
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:hist_from_counts; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:counts; 5, default_parameter; 5, 6; 5, 7; 6, identifier:normalize; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:cumulative; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:to_str; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sep; 16, string:','; 17, default_parameter; 17, 18; 17, 19; 18, identifier:min_bin; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:max_bin; 22, None; 23, block; 23, 24; 23, 42; 23, 75; 23, 92; 23, 96; 23, 218; 23, 229; 23, 233; 23, 264; 23, 282; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:counters; 27, list:[dict((i, c)for i, c in enumerate(counts))]; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:dict; 30, generator_expression; 30, 31; 30, 34; 31, tuple; 31, 32; 31, 33; 32, identifier:i; 33, identifier:c; 34, for_in_clause; 34, 35; 34, 38; 35, pattern_list; 35, 36; 35, 37; 36, identifier:i; 37, identifier:c; 38, call; 38, 39; 38, 40; 39, identifier:enumerate; 40, argument_list; 40, 41; 41, identifier:counts; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:intkeys_list; 45, list_comprehension; 45, 46; 45, 72; 46, list_comprehension; 46, 47; 46, 48; 46, 51; 47, identifier:c; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:c; 50, identifier:counts_dict; 51, if_clause; 51, 52; 52, parenthesized_expression; 52, 53; 53, boolean_operator:or; 53, 54; 53, 59; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:c; 58, identifier:int; 59, parenthesized_expression; 59, 60; 60, boolean_operator:and; 60, 61; 60, 66; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:c; 65, identifier:float; 66, comparison_operator:==; 66, 67; 66, 71; 67, call; 67, 68; 67, 69; 68, identifier:int; 69, argument_list; 69, 70; 70, identifier:c; 71, identifier:c; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:counts_dict; 74, identifier:counters; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, pattern_list; 77, 78; 77, 79; 78, identifier:min_bin; 79, identifier:max_bin; 80, expression_list; 80, 81; 80, 84; 81, boolean_operator:or; 81, 82; 81, 83; 82, identifier:min_bin; 83, integer:0; 84, boolean_operator:or; 84, 85; 84, 86; 85, identifier:max_bin; 86, binary_operator:-; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:counts; 91, integer:1; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:histograms; 95, list:[]; 96, for_statement; 96, 97; 96, 100; 96, 105; 97, pattern_list; 97, 98; 97, 99; 98, identifier:intkeys; 99, identifier:counts; 100, call; 100, 101; 100, 102; 101, identifier:zip; 102, argument_list; 102, 103; 102, 104; 103, identifier:intkeys_list; 104, identifier:counters; 105, block; 105, 106; 105, 113; 105, 118; 105, 150; 106, expression_statement; 106, 107; 107, augmented_assignment:+=; 107, 108; 107, 109; 108, identifier:histograms; 109, list:[OrderedDict()]; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:OrderedDict; 112, argument_list; 113, if_statement; 113, 114; 113, 116; 114, not_operator; 114, 115; 115, identifier:intkeys; 116, block; 116, 117; 117, continue_statement; 118, if_statement; 118, 119; 118, 120; 119, identifier:normalize; 120, block; 120, 121; 120, 133; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:N; 124, call; 124, 125; 124, 126; 125, identifier:sum; 126, generator_expression; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:counts; 129, identifier:c; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:c; 132, identifier:intkeys; 133, for_statement; 133, 134; 133, 135; 133, 136; 134, identifier:c; 135, identifier:intkeys; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:counts; 141, identifier:c; 142, binary_operator:/; 142, 143; 142, 149; 143, call; 143, 144; 143, 145; 144, identifier:float; 145, argument_list; 145, 146; 146, subscript; 146, 147; 146, 148; 147, identifier:counts; 148, identifier:c; 149, identifier:N; 150, if_statement; 150, 151; 150, 152; 150, 191; 151, identifier:cumulative; 152, block; 152, 153; 153, for_statement; 153, 154; 153, 155; 153, 162; 154, identifier:i; 155, call; 155, 156; 155, 157; 156, identifier:range; 157, argument_list; 157, 158; 157, 159; 158, identifier:min_bin; 159, binary_operator:+; 159, 160; 159, 161; 160, identifier:max_bin; 161, integer:1; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 171; 165, subscript; 165, 166; 165, 170; 166, subscript; 166, 167; 166, 168; 167, identifier:histograms; 168, unary_operator:-; 168, 169; 169, integer:1; 170, identifier:i; 171, binary_operator:+; 171, 172; 171, 179; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:counts; 175, identifier:get; 176, argument_list; 176, 177; 176, 178; 177, identifier:i; 178, integer:0; 179, call; 179, 180; 179, 186; 180, attribute; 180, 181; 180, 185; 181, subscript; 181, 182; 181, 183; 182, identifier:histograms; 183, unary_operator:-; 183, 184; 184, integer:1; 185, identifier:get; 186, argument_list; 186, 187; 186, 190; 187, binary_operator:-; 187, 188; 187, 189; 188, identifier:i; 189, integer:1; 190, integer:0; 191, else_clause; 191, 192; 192, block; 192, 193; 193, for_statement; 193, 194; 193, 195; 193, 202; 194, identifier:i; 195, call; 195, 196; 195, 197; 196, identifier:range; 197, argument_list; 197, 198; 197, 199; 198, identifier:min_bin; 199, binary_operator:+; 199, 200; 199, 201; 200, identifier:max_bin; 201, integer:1; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 211; 205, subscript; 205, 206; 205, 210; 206, subscript; 206, 207; 206, 208; 207, identifier:histograms; 208, unary_operator:-; 208, 209; 209, integer:1; 210, identifier:i; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:counts; 214, identifier:get; 215, argument_list; 215, 216; 215, 217; 216, identifier:i; 217, integer:0; 218, if_statement; 218, 219; 218, 221; 219, not_operator; 219, 220; 220, identifier:histograms; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:histograms; 225, list:[OrderedDict()]; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:OrderedDict; 228, argument_list; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:aligned_histograms; 232, list:[]; 233, for_statement; 233, 234; 233, 235; 233, 242; 234, identifier:i; 235, call; 235, 236; 235, 237; 236, identifier:range; 237, argument_list; 237, 238; 237, 239; 238, identifier:min_bin; 239, binary_operator:+; 239, 240; 239, 241; 240, identifier:max_bin; 241, integer:1; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, augmented_assignment:+=; 244, 245; 244, 246; 245, identifier:aligned_histograms; 246, list:[tuple([i] + [hist.get(i, 0) for hist in histograms])]; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:tuple; 249, argument_list; 249, 250; 250, binary_operator:+; 250, 251; 250, 253; 251, list:[i]; 251, 252; 252, identifier:i; 253, list_comprehension; 253, 254; 253, 261; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:hist; 257, identifier:get; 258, argument_list; 258, 259; 258, 260; 259, identifier:i; 260, integer:0; 261, for_in_clause; 261, 262; 261, 263; 262, identifier:hist; 263, identifier:histograms; 264, if_statement; 264, 265; 264, 266; 265, identifier:to_str; 266, block; 266, 267; 267, return_statement; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:str_from_table; 270, argument_list; 270, 271; 270, 272; 270, 275; 271, identifier:aligned_histograms; 272, keyword_argument; 272, 273; 272, 274; 273, identifier:sep; 274, identifier:sep; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:max_rows; 277, binary_operator:+; 277, 278; 277, 281; 278, binary_operator:*; 278, 279; 278, 280; 279, integer:365; 280, integer:2; 281, integer:1; 282, return_statement; 282, 283; 283, identifier:aligned_histograms
def hist_from_counts(counts, normalize=False, cumulative=False, to_str=False, sep=',', min_bin=None, max_bin=None): counters = [dict((i, c)for i, c in enumerate(counts))] intkeys_list = [[c for c in counts_dict if (isinstance(c, int) or (isinstance(c, float) and int(c) == c))] for counts_dict in counters] min_bin, max_bin = min_bin or 0, max_bin or len(counts) - 1 histograms = [] for intkeys, counts in zip(intkeys_list, counters): histograms += [OrderedDict()] if not intkeys: continue if normalize: N = sum(counts[c] for c in intkeys) for c in intkeys: counts[c] = float(counts[c]) / N if cumulative: for i in range(min_bin, max_bin + 1): histograms[-1][i] = counts.get(i, 0) + histograms[-1].get(i - 1, 0) else: for i in range(min_bin, max_bin + 1): histograms[-1][i] = counts.get(i, 0) if not histograms: histograms = [OrderedDict()] aligned_histograms = [] for i in range(min_bin, max_bin + 1): aligned_histograms += [tuple([i] + [hist.get(i, 0) for hist in histograms])] if to_str: return str_from_table(aligned_histograms, sep=sep, max_rows=365 * 2 + 1) return aligned_histograms
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:normalize_serial_number; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 16; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 4, identifier:sn; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_length; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:left_fill; 10, string:'0'; 11, default_parameter; 11, 12; 11, 13; 12, identifier:right_fill; 13, call; 13, 14; 13, 15; 14, identifier:str; 15, argument_list; 16, default_parameter; 16, 17; 16, 18; 17, identifier:blank; 18, call; 18, 19; 18, 20; 19, identifier:str; 20, argument_list; 21, default_parameter; 21, 22; 21, 23; 22, identifier:valid_chars; 23, string:' -0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 24, default_parameter; 24, 25; 24, 26; 25, identifier:invalid_chars; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:strip_whitespace; 29, True; 30, default_parameter; 30, 31; 30, 32; 31, identifier:join; 32, False; 33, default_parameter; 33, 34; 33, 35; 34, identifier:na; 35, attribute; 35, 36; 35, 37; 36, identifier:rex; 37, identifier:nones; 38, block; 38, 39; 38, 41; 38, 60; 38, 79; 38, 98; 38, 117; 38, 136; 38, 155; 38, 174; 38, 193; 38, 212; 38, 231; 38, 240; 38, 252; 38, 263; 38, 304; 38, 313; 38, 324; 38, 358; 38, 370; 38, 394; 38, 416; 39, expression_statement; 39, 40; 40, identifier:r; 41, if_statement; 41, 42; 41, 45; 41, 52; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:max_length; 44, None; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:max_length; 49, attribute; 49, 50; 49, 51; 50, identifier:normalize_serial_number; 51, identifier:max_length; 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:normalize_serial_number; 58, identifier:max_length; 59, identifier:max_length; 60, if_statement; 60, 61; 60, 64; 60, 71; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:left_fill; 63, None; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:left_fill; 68, attribute; 68, 69; 68, 70; 69, identifier:normalize_serial_number; 70, identifier:left_fill; 71, else_clause; 71, 72; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:normalize_serial_number; 77, identifier:left_fill; 78, identifier:left_fill; 79, if_statement; 79, 80; 79, 83; 79, 90; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:right_fill; 82, None; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:right_fill; 87, attribute; 87, 88; 87, 89; 88, identifier:normalize_serial_number; 89, identifier:right_fill; 90, else_clause; 90, 91; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:normalize_serial_number; 96, identifier:right_fill; 97, identifier:right_fill; 98, if_statement; 98, 99; 98, 102; 98, 109; 99, comparison_operator:is; 99, 100; 99, 101; 100, identifier:blank; 101, None; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:blank; 106, attribute; 106, 107; 106, 108; 107, identifier:normalize_serial_number; 108, identifier:blank; 109, else_clause; 109, 110; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:normalize_serial_number; 115, identifier:blank; 116, identifier:blank; 117, if_statement; 117, 118; 117, 121; 117, 128; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:valid_chars; 120, None; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:valid_chars; 125, attribute; 125, 126; 125, 127; 126, identifier:normalize_serial_number; 127, identifier:valid_chars; 128, else_clause; 128, 129; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:normalize_serial_number; 134, identifier:valid_chars; 135, identifier:valid_chars; 136, if_statement; 136, 137; 136, 140; 136, 147; 137, comparison_operator:is; 137, 138; 137, 139; 138, identifier:invalid_chars; 139, None; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:invalid_chars; 144, attribute; 144, 145; 144, 146; 145, identifier:normalize_serial_number; 146, identifier:invalid_chars; 147, else_clause; 147, 148; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:normalize_serial_number; 153, identifier:invalid_chars; 154, identifier:invalid_chars; 155, if_statement; 155, 156; 155, 159; 155, 166; 156, comparison_operator:is; 156, 157; 156, 158; 157, identifier:strip_whitespace; 158, None; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:strip_whitespace; 163, attribute; 163, 164; 163, 165; 164, identifier:normalize_serial_number; 165, identifier:strip_whitespace; 166, else_clause; 166, 167; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:normalize_serial_number; 172, identifier:strip_whitespace; 173, identifier:strip_whitespace; 174, if_statement; 174, 175; 174, 178; 174, 185; 175, comparison_operator:is; 175, 176; 175, 177; 176, identifier:join; 177, None; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:join; 182, attribute; 182, 183; 182, 184; 183, identifier:normalize_serial_number; 184, identifier:join; 185, else_clause; 185, 186; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:normalize_serial_number; 191, identifier:join; 192, identifier:join; 193, if_statement; 193, 194; 193, 197; 193, 204; 194, comparison_operator:is; 194, 195; 194, 196; 195, identifier:na; 196, None; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:na; 201, attribute; 201, 202; 201, 203; 202, identifier:normalize_serial_number; 203, identifier:na; 204, else_clause; 204, 205; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:normalize_serial_number; 210, identifier:na; 211, identifier:na; 212, if_statement; 212, 213; 212, 216; 213, comparison_operator:is; 213, 214; 213, 215; 214, identifier:invalid_chars; 215, None; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:invalid_chars; 220, generator_expression; 220, 221; 220, 222; 220, 227; 221, identifier:c; 222, for_in_clause; 222, 223; 222, 224; 223, identifier:c; 224, attribute; 224, 225; 224, 226; 225, identifier:charlist; 226, identifier:ascii_all; 227, if_clause; 227, 228; 228, comparison_operator:not; 228, 229; 228, 230; 229, identifier:c; 230, identifier:valid_chars; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:invalid_chars; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, string:''; 237, identifier:join; 238, argument_list; 238, 239; 239, identifier:invalid_chars; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:sn; 243, call; 243, 244; 243, 250; 244, attribute; 244, 245; 244, 249; 245, call; 245, 246; 245, 247; 246, identifier:str; 247, argument_list; 247, 248; 248, identifier:sn; 249, identifier:strip; 250, argument_list; 250, 251; 251, identifier:invalid_chars; 252, if_statement; 252, 253; 252, 254; 253, identifier:strip_whitespace; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 258; 257, identifier:sn; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:sn; 261, identifier:strip; 262, argument_list; 263, if_statement; 263, 264; 263, 265; 264, identifier:invalid_chars; 265, block; 265, 266; 266, if_statement; 266, 267; 266, 268; 266, 291; 267, identifier:join; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:sn; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:sn; 275, identifier:translate; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 279; 278, identifier:dict; 279, argument_list; 279, 280; 280, call; 280, 281; 280, 282; 281, identifier:zip; 282, argument_list; 282, 283; 282, 284; 283, identifier:invalid_chars; 284, binary_operator:*; 284, 285; 284, 287; 285, list:['']; 285, 286; 286, string:''; 287, call; 287, 288; 287, 289; 288, identifier:len; 289, argument_list; 289, 290; 290, identifier:invalid_chars; 291, else_clause; 291, 292; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:sn; 296, subscript; 296, 297; 296, 302; 297, call; 297, 298; 297, 299; 298, identifier:multisplit; 299, argument_list; 299, 300; 299, 301; 300, identifier:sn; 301, identifier:invalid_chars; 302, unary_operator:-; 302, 303; 303, integer:1; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:sn; 307, subscript; 307, 308; 307, 309; 308, identifier:sn; 309, slice; 309, 310; 309, 312; 310, unary_operator:-; 310, 311; 311, identifier:max_length; 312, colon; 313, if_statement; 313, 314; 313, 315; 314, identifier:strip_whitespace; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:sn; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:sn; 322, identifier:strip; 323, argument_list; 324, if_statement; 324, 325; 324, 326; 325, identifier:na; 326, block; 326, 327; 327, if_statement; 327, 328; 327, 341; 327, 346; 328, boolean_operator:and; 328, 329; 328, 338; 329, call; 329, 330; 329, 331; 330, identifier:isinstance; 331, argument_list; 331, 332; 331, 333; 332, identifier:na; 333, tuple; 333, 334; 333, 335; 333, 336; 333, 337; 334, identifier:tuple; 335, identifier:set; 336, identifier:dict; 337, identifier:list; 338, comparison_operator:in; 338, 339; 338, 340; 339, identifier:sn; 340, identifier:na; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:sn; 345, string:''; 346, elif_clause; 346, 347; 346, 353; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:na; 350, identifier:match; 351, argument_list; 351, 352; 352, identifier:sn; 353, block; 353, 354; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 357; 356, identifier:sn; 357, string:''; 358, if_statement; 358, 359; 358, 367; 359, boolean_operator:and; 359, 360; 359, 362; 360, not_operator; 360, 361; 361, identifier:sn; 362, not_operator; 362, 363; 363, parenthesized_expression; 363, 364; 364, comparison_operator:is; 364, 365; 364, 366; 365, identifier:blank; 366, False; 367, block; 367, 368; 368, return_statement; 368, 369; 369, identifier:blank; 370, if_statement; 370, 371; 370, 372; 371, identifier:left_fill; 372, block; 372, 373; 373, expression_statement; 373, 374; 374, assignment; 374, 375; 374, 376; 375, identifier:sn; 376, binary_operator:+; 376, 377; 376, 393; 377, binary_operator:*; 377, 378; 377, 379; 378, identifier:left_fill; 379, call; 379, 380; 379, 381; 380, identifier:int; 381, argument_list; 381, 382; 382, binary_operator:-; 382, 383; 382, 384; 383, identifier:max_length; 384, binary_operator:/; 384, 385; 384, 389; 385, call; 385, 386; 385, 387; 386, identifier:len; 387, argument_list; 387, 388; 388, identifier:sn; 389, call; 389, 390; 389, 391; 390, identifier:len; 391, argument_list; 391, 392; 392, identifier:left_fill; 393, identifier:sn; 394, if_statement; 394, 395; 394, 396; 395, identifier:right_fill; 396, block; 396, 397; 397, expression_statement; 397, 398; 398, assignment; 398, 399; 398, 400; 399, identifier:sn; 400, binary_operator:+; 400, 401; 400, 402; 401, identifier:sn; 402, binary_operator:*; 402, 403; 402, 404; 403, identifier:right_fill; 404, parenthesized_expression; 404, 405; 405, binary_operator:-; 405, 406; 405, 407; 406, identifier:max_length; 407, binary_operator:/; 407, 408; 407, 412; 408, call; 408, 409; 408, 410; 409, identifier:len; 410, argument_list; 410, 411; 411, identifier:sn; 412, call; 412, 413; 412, 414; 413, identifier:len; 414, argument_list; 414, 415; 415, identifier:right_fill; 416, return_statement; 416, 417; 417, identifier:sn
def normalize_serial_number(sn, max_length=None, left_fill='0', right_fill=str(), blank=str(), valid_chars=' -0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', invalid_chars=None, strip_whitespace=True, join=False, na=rex.nones): r if max_length is None: max_length = normalize_serial_number.max_length else: normalize_serial_number.max_length = max_length if left_fill is None: left_fill = normalize_serial_number.left_fill else: normalize_serial_number.left_fill = left_fill if right_fill is None: right_fill = normalize_serial_number.right_fill else: normalize_serial_number.right_fill = right_fill if blank is None: blank = normalize_serial_number.blank else: normalize_serial_number.blank = blank if valid_chars is None: valid_chars = normalize_serial_number.valid_chars else: normalize_serial_number.valid_chars = valid_chars if invalid_chars is None: invalid_chars = normalize_serial_number.invalid_chars else: normalize_serial_number.invalid_chars = invalid_chars if strip_whitespace is None: strip_whitespace = normalize_serial_number.strip_whitespace else: normalize_serial_number.strip_whitespace = strip_whitespace if join is None: join = normalize_serial_number.join else: normalize_serial_number.join = join if na is None: na = normalize_serial_number.na else: normalize_serial_number.na = na if invalid_chars is None: invalid_chars = (c for c in charlist.ascii_all if c not in valid_chars) invalid_chars = ''.join(invalid_chars) sn = str(sn).strip(invalid_chars) if strip_whitespace: sn = sn.strip() if invalid_chars: if join: sn = sn.translate(dict(zip(invalid_chars, [''] * len(invalid_chars)))) else: sn = multisplit(sn, invalid_chars)[-1] sn = sn[-max_length:] if strip_whitespace: sn = sn.strip() if na: if isinstance(na, (tuple, set, dict, list)) and sn in na: sn = '' elif na.match(sn): sn = '' if not sn and not (blank is False): return blank if left_fill: sn = left_fill * int(max_length - len(sn) / len(left_fill)) + sn if right_fill: sn = sn + right_fill * (max_length - len(sn) / len(right_fill)) return sn
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:listify; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:values; 5, default_parameter; 5, 6; 5, 7; 6, identifier:N; 7, integer:1; 8, default_parameter; 8, 9; 8, 10; 9, identifier:delim; 10, None; 11, block; 11, 12; 11, 21; 11, 87; 11, 135; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:ans; 15, conditional_expression:if; 15, 16; 15, 17; 15, 20; 16, list:[]; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:values; 19, None; 20, identifier:values; 21, if_statement; 21, 22; 21, 34; 21, 42; 22, boolean_operator:and; 22, 23; 22, 28; 23, call; 23, 24; 23, 25; 24, identifier:hasattr; 25, argument_list; 25, 26; 25, 27; 26, identifier:ans; 27, string:'__iter__'; 28, not_operator; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 33; 32, identifier:ans; 33, identifier:basestring; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:ans; 38, call; 38, 39; 38, 40; 39, identifier:list; 40, argument_list; 40, 41; 41, identifier:ans; 42, else_clause; 42, 43; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 56; 44, 80; 45, boolean_operator:and; 45, 46; 45, 51; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:delim; 50, identifier:basestring; 51, call; 51, 52; 51, 53; 52, identifier:isinstance; 53, argument_list; 53, 54; 53, 55; 54, identifier:ans; 55, identifier:basestring; 56, block; 56, 57; 57, try_statement; 57, 58; 57, 68; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:ans; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:ans; 65, identifier:split; 66, argument_list; 66, 67; 67, identifier:delim; 68, except_clause; 68, 69; 68, 74; 69, tuple; 69, 70; 69, 71; 69, 72; 69, 73; 70, identifier:IndexError; 71, identifier:ValueError; 72, identifier:AttributeError; 73, identifier:TypeError; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:ans; 78, list:[ans]; 78, 79; 79, identifier:ans; 80, else_clause; 80, 81; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:ans; 85, list:[ans]; 85, 86; 86, identifier:ans; 87, if_statement; 87, 88; 87, 92; 87, 121; 88, call; 88, 89; 88, 90; 89, identifier:len; 90, argument_list; 90, 91; 91, identifier:ans; 92, block; 92, 93; 93, if_statement; 93, 94; 93, 104; 94, boolean_operator:and; 94, 95; 94, 101; 95, comparison_operator:<; 95, 96; 95, 100; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, identifier:ans; 100, identifier:N; 101, comparison_operator:>; 101, 102; 101, 103; 102, identifier:N; 103, integer:1; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, augmented_assignment:+=; 106, 107; 106, 108; 107, identifier:ans; 108, binary_operator:*; 108, 109; 108, 114; 109, list:[ans[-1]]; 109, 110; 110, subscript; 110, 111; 110, 112; 111, identifier:ans; 112, unary_operator:-; 112, 113; 113, integer:1; 114, parenthesized_expression; 114, 115; 115, binary_operator:-; 115, 116; 115, 117; 116, identifier:N; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, identifier:ans; 121, else_clause; 121, 122; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 127; 124, comparison_operator:>; 124, 125; 124, 126; 125, identifier:N; 126, integer:1; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:ans; 131, binary_operator:*; 131, 132; 131, 134; 132, list:[[]]; 132, 133; 133, list:[]; 134, identifier:N; 135, return_statement; 135, 136; 136, identifier:ans
def listify(values, N=1, delim=None): ans = [] if values is None else values if hasattr(ans, '__iter__') and not isinstance(ans, basestring): ans = list(ans) else: if isinstance(delim, basestring) and isinstance(ans, basestring): try: ans = ans.split(delim) except (IndexError, ValueError, AttributeError, TypeError): ans = [ans] else: ans = [ans] if len(ans): if len(ans) < N and N > 1: ans += [ans[-1]] * (N - len(ans)) else: if N > 1: ans = [[]] * N return ans
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:best_fit; 3, parameters; 3, 4; 3, 5; 4, identifier:li; 5, identifier:value; 6, block; 6, 7; 6, 24; 6, 36; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:index; 10, call; 10, 11; 10, 12; 11, identifier:min; 12, argument_list; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:bisect_left; 15, argument_list; 15, 16; 15, 17; 16, identifier:li; 17, identifier:value; 18, binary_operator:-; 18, 19; 18, 23; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, identifier:li; 23, integer:1; 24, if_statement; 24, 25; 24, 33; 25, comparison_operator:in; 25, 26; 25, 27; 26, identifier:index; 27, tuple; 27, 28; 27, 29; 28, integer:0; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:li; 33, block; 33, 34; 34, return_statement; 34, 35; 35, identifier:index; 36, if_statement; 36, 37; 36, 50; 36, 53; 37, comparison_operator:<; 37, 38; 37, 43; 38, binary_operator:-; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:li; 41, identifier:index; 42, identifier:value; 43, binary_operator:-; 43, 44; 43, 45; 44, identifier:value; 45, subscript; 45, 46; 45, 47; 46, identifier:li; 47, binary_operator:-; 47, 48; 47, 49; 48, identifier:index; 49, integer:1; 50, block; 50, 51; 51, return_statement; 51, 52; 52, identifier:index; 53, else_clause; 53, 54; 54, block; 54, 55; 55, return_statement; 55, 56; 56, binary_operator:-; 56, 57; 56, 58; 57, identifier:index; 58, integer:1
def best_fit(li, value): index = min(bisect_left(li, value), len(li) - 1) if index in (0, len(li)): return index if li[index] - value < value - li[index-1]: return index else: return index-1
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:proj4_to_epsg; 3, parameters; 3, 4; 4, identifier:projection; 5, block; 5, 6; 5, 32; 5, 43; 5, 56; 5, 77; 5, 89; 5, 163; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:make_definition; 8, parameters; 8, 9; 9, identifier:value; 10, block; 10, 11; 11, return_statement; 11, 12; 12, set_comprehension; 12, 13; 12, 22; 12, 30; 13, call; 13, 14; 13, 21; 14, attribute; 14, 15; 14, 20; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:x; 18, identifier:strip; 19, argument_list; 20, identifier:lower; 21, argument_list; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:x; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:value; 27, identifier:split; 28, argument_list; 28, 29; 29, string:'+'; 30, if_clause; 30, 31; 31, identifier:x; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:match; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:EPSG_RE; 38, identifier:search; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:projection; 42, identifier:srs; 43, if_statement; 43, 44; 43, 45; 44, identifier:match; 45, block; 45, 46; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:int; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:match; 53, identifier:group; 54, argument_list; 54, 55; 55, integer:1; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:pyproj_data_dir; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:os; 63, identifier:path; 64, identifier:join; 65, argument_list; 65, 66; 65, 76; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:os; 70, identifier:path; 71, identifier:dirname; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:pyproj; 75, identifier:__file__; 76, string:'data'; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:pyproj_epsg_file; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:os; 84, identifier:path; 85, identifier:join; 86, argument_list; 86, 87; 86, 88; 87, identifier:pyproj_data_dir; 88, string:'epsg'; 89, if_statement; 89, 90; 89, 98; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:os; 94, identifier:path; 95, identifier:exists; 96, argument_list; 96, 97; 97, identifier:pyproj_epsg_file; 98, block; 98, 99; 98, 108; 98, 116; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:definition; 102, call; 102, 103; 102, 104; 103, identifier:make_definition; 104, argument_list; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:projection; 107, identifier:srs; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:f; 111, call; 111, 112; 111, 113; 112, identifier:open; 113, argument_list; 113, 114; 113, 115; 114, identifier:pyproj_epsg_file; 115, string:'r'; 116, for_statement; 116, 117; 116, 118; 116, 123; 117, identifier:line; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:f; 121, identifier:readlines; 122, argument_list; 123, block; 123, 124; 123, 133; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:match; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:PYPROJ_EPSG_FILE_RE; 130, identifier:search; 131, argument_list; 131, 132; 132, identifier:line; 133, if_statement; 133, 134; 133, 135; 134, identifier:match; 135, block; 135, 136; 135, 148; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:file_definition; 139, call; 139, 140; 139, 141; 140, identifier:make_definition; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:match; 145, identifier:group; 146, argument_list; 146, 147; 147, integer:2; 148, if_statement; 148, 149; 148, 152; 149, comparison_operator:==; 149, 150; 149, 151; 150, identifier:definition; 151, identifier:file_definition; 152, block; 152, 153; 153, return_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:int; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:match; 160, identifier:group; 161, argument_list; 161, 162; 162, integer:1; 163, return_statement; 163, 164; 164, None
def proj4_to_epsg(projection): def make_definition(value): return {x.strip().lower() for x in value.split('+') if x} match = EPSG_RE.search(projection.srs) if match: return int(match.group(1)) pyproj_data_dir = os.path.join(os.path.dirname(pyproj.__file__), 'data') pyproj_epsg_file = os.path.join(pyproj_data_dir, 'epsg') if os.path.exists(pyproj_epsg_file): definition = make_definition(projection.srs) f = open(pyproj_epsg_file, 'r') for line in f.readlines(): match = PYPROJ_EPSG_FILE_RE.search(line) if match: file_definition = make_definition(match.group(2)) if definition == file_definition: return int(match.group(1)) return None
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:index_pix_in_pixels; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:pix; 5, identifier:pixels; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:outside; 11, unary_operator:-; 11, 12; 12, integer:1; 13, block; 13, 14; 13, 26; 13, 36; 13, 77; 14, if_statement; 14, 15; 14, 16; 15, identifier:sort; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:pixels; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:np; 23, identifier:sort; 24, argument_list; 24, 25; 25, identifier:pixels; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:index; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:np; 32, identifier:searchsorted; 33, argument_list; 33, 34; 33, 35; 34, identifier:pixels; 35, identifier:pix; 36, if_statement; 36, 37; 36, 43; 36, 62; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:np; 40, identifier:isscalar; 41, argument_list; 41, 42; 42, identifier:index; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 57; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 56; 47, attribute; 47, 48; 47, 55; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:np; 51, identifier:in1d; 52, argument_list; 52, 53; 52, 54; 53, identifier:pix; 54, identifier:pixels; 55, identifier:any; 56, argument_list; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:index; 61, identifier:outside; 62, else_clause; 62, 63; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 76; 66, subscript; 66, 67; 66, 68; 67, identifier:index; 68, unary_operator:~; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:in1d; 73, argument_list; 73, 74; 73, 75; 74, identifier:pix; 75, identifier:pixels; 76, identifier:outside; 77, return_statement; 77, 78; 78, identifier:index
def index_pix_in_pixels(pix,pixels,sort=False,outside=-1): if sort: pixels = np.sort(pixels) index = np.searchsorted(pixels,pix) if np.isscalar(index): if not np.in1d(pix,pixels).any(): index = outside else: index[~np.in1d(pix,pixels)] = outside return index
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:files; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:entity_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:manifest; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:filename; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:read_file; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:channel; 17, None; 18, block; 18, 19; 18, 21; 18, 66; 18, 70; 18, 102; 19, expression_statement; 19, 20; 20, string:''' Get the files or file contents of a file for an entity. If all files are requested, a dictionary of filenames and urls for the files in the archive are returned. If filename is provided, the url of just that file is returned, if it exists. If filename is provided and read_file is true, the *contents* of the file are returned, if the file exists. @param entity_id The id of the entity to get files for @param manifest The manifest of files for the entity. Providing this reduces queries; if not provided, the manifest is looked up in the charmstore. @param filename The name of the file in the archive to get. @param read_file Whether to get the url for the file or the file contents. @param channel Optional channel name. '''; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:manifest; 24, None; 25, block; 25, 26; 25, 41; 25, 49; 25, 58; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:manifest_url; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, string:'{}/{}/meta/manifest'; 32, identifier:format; 33, argument_list; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:url; 37, call; 37, 38; 37, 39; 38, identifier:_get_path; 39, argument_list; 39, 40; 40, identifier:entity_id; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:manifest_url; 44, call; 44, 45; 44, 46; 45, identifier:_add_channel; 46, argument_list; 46, 47; 46, 48; 47, identifier:manifest_url; 48, identifier:channel; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:manifest; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_get; 56, argument_list; 56, 57; 57, identifier:manifest_url; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:manifest; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:manifest; 64, identifier:json; 65, argument_list; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:files; 69, dictionary; 70, for_statement; 70, 71; 70, 72; 70, 73; 71, identifier:f; 72, identifier:manifest; 73, block; 73, 74; 73, 80; 73, 96; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:manifest_name; 77, subscript; 77, 78; 77, 79; 78, identifier:f; 79, string:'Name'; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:file_url; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:file_url; 87, argument_list; 87, 88; 87, 92; 87, 93; 88, call; 88, 89; 88, 90; 89, identifier:_get_path; 90, argument_list; 90, 91; 91, identifier:entity_id; 92, identifier:manifest_name; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:channel; 95, identifier:channel; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:files; 100, identifier:manifest_name; 101, identifier:file_url; 102, if_statement; 102, 103; 102, 104; 102, 146; 103, identifier:filename; 104, block; 104, 105; 104, 115; 104, 126; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:file_url; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:files; 111, identifier:get; 112, argument_list; 112, 113; 112, 114; 113, identifier:filename; 114, None; 115, if_statement; 115, 116; 115, 119; 116, comparison_operator:is; 116, 117; 116, 118; 117, identifier:file_url; 118, None; 119, block; 119, 120; 120, raise_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:EntityNotFound; 123, argument_list; 123, 124; 123, 125; 124, identifier:entity_id; 125, identifier:filename; 126, if_statement; 126, 127; 126, 128; 126, 142; 127, identifier:read_file; 128, block; 128, 129; 128, 138; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:data; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:_get; 136, argument_list; 136, 137; 137, identifier:file_url; 138, return_statement; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:data; 141, identifier:text; 142, else_clause; 142, 143; 143, block; 143, 144; 144, return_statement; 144, 145; 145, identifier:file_url; 146, else_clause; 146, 147; 147, block; 147, 148; 148, return_statement; 148, 149; 149, identifier:files
def files(self, entity_id, manifest=None, filename=None, read_file=False, channel=None): ''' Get the files or file contents of a file for an entity. If all files are requested, a dictionary of filenames and urls for the files in the archive are returned. If filename is provided, the url of just that file is returned, if it exists. If filename is provided and read_file is true, the *contents* of the file are returned, if the file exists. @param entity_id The id of the entity to get files for @param manifest The manifest of files for the entity. Providing this reduces queries; if not provided, the manifest is looked up in the charmstore. @param filename The name of the file in the archive to get. @param read_file Whether to get the url for the file or the file contents. @param channel Optional channel name. ''' if manifest is None: manifest_url = '{}/{}/meta/manifest'.format(self.url, _get_path(entity_id)) manifest_url = _add_channel(manifest_url, channel) manifest = self._get(manifest_url) manifest = manifest.json() files = {} for f in manifest: manifest_name = f['Name'] file_url = self.file_url(_get_path(entity_id), manifest_name, channel=channel) files[manifest_name] = file_url if filename: file_url = files.get(filename, None) if file_url is None: raise EntityNotFound(entity_id, filename) if read_file: data = self._get(file_url) return data.text else: return file_url else: return files
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:self; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:includes; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:doc_type; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:limit; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:autocomplete; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:promulgated_only; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:tags; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:sort; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:owner; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:series; 32, None; 33, block; 33, 34; 33, 36; 33, 50; 33, 65; 33, 79; 33, 91; 33, 122; 33, 156; 33, 165; 34, expression_statement; 34, 35; 35, string:''' Search for entities in the charmstore. @param text The text to search for. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param limit Maximum number of results to return. @param autocomplete Whether to prefix/suffix match search terms. @param promulgated_only Whether to filter to only promulgated charms. @param tags The tags to filter; can be a list of tags or a single tag. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. '''; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:queries; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_common_query_parameters; 43, argument_list; 43, 44; 43, 45; 43, 46; 43, 47; 43, 48; 43, 49; 44, identifier:doc_type; 45, identifier:includes; 46, identifier:owner; 47, identifier:promulgated_only; 48, identifier:series; 49, identifier:sort; 50, if_statement; 50, 51; 50, 55; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:text; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:queries; 60, identifier:append; 61, argument_list; 61, 62; 62, tuple; 62, 63; 62, 64; 63, string:'text'; 64, identifier:text; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:limit; 68, None; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:queries; 74, identifier:append; 75, argument_list; 75, 76; 76, tuple; 76, 77; 76, 78; 77, string:'limit'; 78, identifier:limit; 79, if_statement; 79, 80; 79, 81; 80, identifier:autocomplete; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:queries; 86, identifier:append; 87, argument_list; 87, 88; 88, tuple; 88, 89; 88, 90; 89, string:'autocomplete'; 90, integer:1; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:tags; 94, None; 95, block; 95, 96; 95, 113; 96, if_statement; 96, 97; 96, 103; 97, comparison_operator:is; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:type; 100, argument_list; 100, 101; 101, identifier:tags; 102, identifier:list; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:tags; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:','; 110, identifier:join; 111, argument_list; 111, 112; 112, identifier:tags; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:queries; 117, identifier:append; 118, argument_list; 118, 119; 119, tuple; 119, 120; 119, 121; 120, string:'tags'; 121, identifier:tags; 122, if_statement; 122, 123; 122, 127; 122, 143; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, identifier:queries; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:url; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, string:'{}/search?{}'; 134, identifier:format; 135, argument_list; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:url; 139, call; 139, 140; 139, 141; 140, identifier:urlencode; 141, argument_list; 141, 142; 142, identifier:queries; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:url; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, string:'{}/search'; 151, identifier:format; 152, argument_list; 152, 153; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:url; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:data; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_get; 163, argument_list; 163, 164; 164, identifier:url; 165, return_statement; 165, 166; 166, subscript; 166, 167; 166, 172; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:data; 170, identifier:json; 171, argument_list; 172, string:'Results'
def search(self, text, includes=None, doc_type=None, limit=None, autocomplete=False, promulgated_only=False, tags=None, sort=None, owner=None, series=None): ''' Search for entities in the charmstore. @param text The text to search for. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param limit Maximum number of results to return. @param autocomplete Whether to prefix/suffix match search terms. @param promulgated_only Whether to filter to only promulgated charms. @param tags The tags to filter; can be a list of tags or a single tag. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = self._common_query_parameters(doc_type, includes, owner, promulgated_only, series, sort) if len(text): queries.append(('text', text)) if limit is not None: queries.append(('limit', limit)) if autocomplete: queries.append(('autocomplete', 1)) if tags is not None: if type(tags) is list: tags = ','.join(tags) queries.append(('tags', tags)) if len(queries): url = '{}/search?{}'.format(self.url, urlencode(queries)) else: url = '{}/search'.format(self.url) data = self._get(url) return data.json()['Results']
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:includes; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:doc_type; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:promulgated_only; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sort; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:owner; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:series; 22, None; 23, block; 23, 24; 23, 26; 23, 40; 23, 74; 23, 83; 24, expression_statement; 24, 25; 25, string:''' List entities in the charmstore. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. '''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:queries; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_common_query_parameters; 33, argument_list; 33, 34; 33, 35; 33, 36; 33, 37; 33, 38; 33, 39; 34, identifier:doc_type; 35, identifier:includes; 36, identifier:owner; 37, identifier:promulgated_only; 38, identifier:series; 39, identifier:sort; 40, if_statement; 40, 41; 40, 45; 40, 61; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:queries; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:url; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:'{}/list?{}'; 52, identifier:format; 53, argument_list; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:url; 57, call; 57, 58; 57, 59; 58, identifier:urlencode; 59, argument_list; 59, 60; 60, identifier:queries; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:url; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:'{}/list'; 69, identifier:format; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:url; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:data; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_get; 81, argument_list; 81, 82; 82, identifier:url; 83, return_statement; 83, 84; 84, subscript; 84, 85; 84, 90; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:data; 88, identifier:json; 89, argument_list; 90, string:'Results'
def list(self, includes=None, doc_type=None, promulgated_only=False, sort=None, owner=None, series=None): ''' List entities in the charmstore. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = self._common_query_parameters(doc_type, includes, owner, promulgated_only, series, sort) if len(queries): url = '{}/list?{}'.format(self.url, urlencode(queries)) else: url = '{}/list'.format(self.url) data = self._get(url) return data.json()['Results']
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_common_query_parameters; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:self; 5, identifier:doc_type; 6, identifier:includes; 7, identifier:owner; 8, identifier:promulgated_only; 9, identifier:series; 10, identifier:sort; 11, block; 11, 12; 11, 14; 11, 18; 11, 36; 11, 50; 11, 62; 11, 76; 11, 107; 11, 121; 12, expression_statement; 12, 13; 13, string:''' Extract common query parameters between search and list into slice. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. '''; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:queries; 17, list:[]; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:includes; 21, None; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:queries; 27, identifier:extend; 28, argument_list; 28, 29; 29, list_comprehension; 29, 30; 29, 33; 30, tuple; 30, 31; 30, 32; 31, string:'include'; 32, identifier:include; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:include; 35, identifier:includes; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:doc_type; 39, None; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:queries; 45, identifier:append; 46, argument_list; 46, 47; 47, tuple; 47, 48; 47, 49; 48, string:'type'; 49, identifier:doc_type; 50, if_statement; 50, 51; 50, 52; 51, identifier:promulgated_only; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:queries; 57, identifier:append; 58, argument_list; 58, 59; 59, tuple; 59, 60; 59, 61; 60, string:'promulgated'; 61, integer:1; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:is; 63, 64; 63, 65; 64, identifier:owner; 65, None; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:queries; 71, identifier:append; 72, argument_list; 72, 73; 73, tuple; 73, 74; 73, 75; 74, string:'owner'; 75, identifier:owner; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:is; 77, 78; 77, 79; 78, identifier:series; 79, None; 80, block; 80, 81; 80, 98; 81, if_statement; 81, 82; 81, 88; 82, comparison_operator:is; 82, 83; 82, 87; 83, call; 83, 84; 83, 85; 84, identifier:type; 85, argument_list; 85, 86; 86, identifier:series; 87, identifier:list; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:series; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, string:','; 95, identifier:join; 96, argument_list; 96, 97; 97, identifier:series; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:queries; 102, identifier:append; 103, argument_list; 103, 104; 104, tuple; 104, 105; 104, 106; 105, string:'series'; 106, identifier:series; 107, if_statement; 107, 108; 107, 111; 108, comparison_operator:is; 108, 109; 108, 110; 109, identifier:sort; 110, None; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:queries; 116, identifier:append; 117, argument_list; 117, 118; 118, tuple; 118, 119; 118, 120; 119, string:'sort'; 120, identifier:sort; 121, return_statement; 121, 122; 122, identifier:queries
def _common_query_parameters(self, doc_type, includes, owner, promulgated_only, series, sort): ''' Extract common query parameters between search and list into slice. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = [] if includes is not None: queries.extend([('include', include) for include in includes]) if doc_type is not None: queries.append(('type', doc_type)) if promulgated_only: queries.append(('promulgated', 1)) if owner is not None: queries.append(('owner', owner)) if series is not None: if type(series) is list: series = ','.join(series) queries.append(('series', series)) if sort is not None: queries.append(('sort', sort)) return queries
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:extract_one; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:L; 6, identifier:P; 7, identifier:R; 8, block; 8, 9; 8, 12; 8, 105; 8, 114; 8, 117; 8, 125; 8, 180; 8, 189; 8, 192; 9, expression_statement; 9, 10; 10, yield; 10, 11; 11, string:"*bias*"; 12, if_statement; 12, 13; 12, 18; 12, 23; 12, 33; 13, call; 13, 14; 13, 15; 14, identifier:match; 15, argument_list; 15, 16; 15, 17; 16, identifier:QUOTE; 17, identifier:L; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:L; 22, identifier:QUOTE_TOKEN; 23, elif_clause; 23, 24; 23, 28; 24, call; 24, 25; 24, 26; 25, identifier:isnumberlike; 26, argument_list; 26, 27; 27, identifier:L; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:L; 32, identifier:NUMBER_TOKEN; 33, else_clause; 33, 34; 34, block; 34, 35; 34, 50; 34, 58; 34, 82; 34, 90; 35, expression_statement; 35, 36; 36, yield; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, string:"len(L)={}"; 40, identifier:format; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:min; 44, argument_list; 44, 45; 44, 49; 45, call; 45, 46; 45, 47; 46, identifier:len; 47, argument_list; 47, 48; 48, identifier:L; 49, identifier:CLIP; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:in; 51, 52; 51, 53; 52, string:"."; 53, identifier:L; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, yield; 56, 57; 57, string:"L:*period*"; 58, if_statement; 58, 59; 58, 63; 59, not_operator; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:nocase; 63, block; 63, 64; 63, 71; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:cf; 67, call; 67, 68; 67, 69; 68, identifier:case_feature; 69, argument_list; 69, 70; 70, identifier:R; 71, if_statement; 71, 72; 71, 73; 72, identifier:cf; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, yield; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, string:"L:{}'"; 79, identifier:format; 80, argument_list; 80, 81; 81, identifier:cf; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:L; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:L; 88, identifier:upper; 89, argument_list; 90, if_statement; 90, 91; 90, 101; 91, not_operator; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:any; 94, generator_expression; 94, 95; 94, 98; 95, comparison_operator:in; 95, 96; 95, 97; 96, identifier:char; 97, identifier:VOWELS; 98, for_in_clause; 98, 99; 98, 100; 99, identifier:char; 100, identifier:L; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, yield; 103, 104; 104, string:"L:*no-vowel*"; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:L_feat; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, string:"L='{}'"; 111, identifier:format; 112, argument_list; 112, 113; 113, identifier:L; 114, expression_statement; 114, 115; 115, yield; 115, 116; 116, identifier:L_feat; 117, expression_statement; 117, 118; 118, yield; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, string:"P='{}'"; 122, identifier:format; 123, argument_list; 123, 124; 124, identifier:P; 125, if_statement; 125, 126; 125, 131; 125, 136; 125, 146; 126, call; 126, 127; 126, 128; 127, identifier:match; 128, argument_list; 128, 129; 128, 130; 129, identifier:QUOTE; 130, identifier:R; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:R; 135, identifier:QUOTE_TOKEN; 136, elif_clause; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:isnumberlike; 139, argument_list; 139, 140; 140, identifier:R; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:R; 145, identifier:NUMBER_TOKEN; 146, else_clause; 146, 147; 147, block; 147, 148; 147, 172; 148, if_statement; 148, 149; 148, 153; 149, not_operator; 149, 150; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:nocase; 153, block; 153, 154; 153, 161; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:cf; 157, call; 157, 158; 157, 159; 158, identifier:case_feature; 159, argument_list; 159, 160; 160, identifier:R; 161, if_statement; 161, 162; 161, 163; 162, identifier:cf; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, yield; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, string:"R:{}'"; 169, identifier:format; 170, argument_list; 170, 171; 171, identifier:cf; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:R; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:R; 178, identifier:upper; 179, argument_list; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:R_feat; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, string:"R='{}'"; 186, identifier:format; 187, argument_list; 187, 188; 188, identifier:R; 189, expression_statement; 189, 190; 190, yield; 190, 191; 191, identifier:R_feat; 192, expression_statement; 192, 193; 193, yield; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, string:"{},{}"; 197, identifier:format; 198, argument_list; 198, 199; 198, 200; 199, identifier:L_feat; 200, identifier:R_feat
def extract_one(self, L, P, R): yield "*bias*" if match(QUOTE, L): L = QUOTE_TOKEN elif isnumberlike(L): L = NUMBER_TOKEN else: yield "len(L)={}".format(min(len(L), CLIP)) if "." in L: yield "L:*period*" if not self.nocase: cf = case_feature(R) if cf: yield "L:{}'".format(cf) L = L.upper() if not any(char in VOWELS for char in L): yield "L:*no-vowel*" L_feat = "L='{}'".format(L) yield L_feat yield "P='{}'".format(P) if match(QUOTE, R): R = QUOTE_TOKEN elif isnumberlike(R): R = NUMBER_TOKEN else: if not self.nocase: cf = case_feature(R) if cf: yield "R:{}'".format(cf) R = R.upper() R_feat = "R='{}'".format(R) yield R_feat yield "{},{}".format(L_feat, R_feat)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:call; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:command; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 24; 8, 34; 8, 38; 8, 105; 8, 121; 8, 179; 8, 229; 9, for_statement; 9, 10; 9, 11; 9, 16; 10, identifier:hook; 11, subscript; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_hooks; 15, string:'precall'; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:hook; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, identifier:self; 22, identifier:command; 23, identifier:kwargs; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:op; 27, call; 27, 28; 27, 29; 28, identifier:getattr; 29, argument_list; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:client; 33, identifier:command; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:attempt; 37, integer:0; 38, while_statement; 38, 39; 38, 40; 39, True; 40, block; 40, 41; 41, try_statement; 41, 42; 41, 52; 42, block; 42, 43; 42, 51; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:data; 46, call; 46, 47; 46, 48; 47, identifier:op; 48, argument_list; 48, 49; 49, dictionary_splat; 49, 50; 50, identifier:kwargs; 51, break_statement; 52, except_clause; 52, 53; 52, 57; 53, as_pattern; 53, 54; 53, 55; 54, identifier:ClientError; 55, as_pattern_target; 55, 56; 56, identifier:e; 57, block; 57, 58; 57, 66; 57, 70; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:exc; 61, call; 61, 62; 61, 63; 62, identifier:translate_exception; 63, argument_list; 63, 64; 63, 65; 64, identifier:e; 65, identifier:kwargs; 66, expression_statement; 66, 67; 67, augmented_assignment:+=; 67, 68; 67, 69; 68, identifier:attempt; 69, integer:1; 70, if_statement; 70, 71; 70, 76; 70, 97; 71, call; 71, 72; 71, 73; 72, identifier:isinstance; 73, argument_list; 73, 74; 73, 75; 74, identifier:exc; 75, identifier:ThroughputException; 76, block; 76, 77; 76, 90; 77, if_statement; 77, 78; 77, 83; 78, comparison_operator:>; 78, 79; 78, 80; 79, identifier:attempt; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:request_retries; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:exc; 88, identifier:re_raise; 89, argument_list; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:exponential_sleep; 95, argument_list; 95, 96; 96, identifier:attempt; 97, else_clause; 97, 98; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:exc; 103, identifier:re_raise; 104, argument_list; 105, for_statement; 105, 106; 105, 107; 105, 112; 106, identifier:hook; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:_hooks; 111, string:'postcall'; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:hook; 116, argument_list; 116, 117; 116, 118; 116, 119; 116, 120; 117, identifier:self; 118, identifier:command; 119, identifier:kwargs; 120, identifier:data; 121, if_statement; 121, 122; 121, 125; 122, comparison_operator:in; 122, 123; 122, 124; 123, string:'ConsumedCapacity'; 124, identifier:data; 125, block; 125, 126; 125, 132; 125, 138; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:is_read; 129, comparison_operator:in; 129, 130; 129, 131; 130, identifier:command; 131, identifier:READ_COMMANDS; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:consumed; 135, subscript; 135, 136; 135, 137; 136, identifier:data; 137, string:'ConsumedCapacity'; 138, if_statement; 138, 139; 138, 144; 138, 161; 139, call; 139, 140; 139, 141; 140, identifier:isinstance; 141, argument_list; 141, 142; 141, 143; 142, identifier:consumed; 143, identifier:list; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:data; 149, string:'consumed_capacity'; 150, list_comprehension; 150, 151; 150, 158; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:ConsumedCapacity; 154, identifier:from_response; 155, argument_list; 155, 156; 155, 157; 156, identifier:cap; 157, identifier:is_read; 158, for_in_clause; 158, 159; 158, 160; 159, identifier:cap; 160, identifier:consumed; 161, else_clause; 161, 162; 162, block; 162, 163; 162, 173; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:capacity; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:ConsumedCapacity; 169, identifier:from_response; 170, argument_list; 170, 171; 170, 172; 171, identifier:consumed; 172, identifier:is_read; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:data; 177, string:'consumed_capacity'; 178, identifier:capacity; 179, if_statement; 179, 180; 179, 183; 180, comparison_operator:in; 180, 181; 180, 182; 181, string:'consumed_capacity'; 182, identifier:data; 183, block; 183, 184; 183, 208; 184, if_statement; 184, 185; 184, 192; 184, 199; 185, call; 185, 186; 185, 187; 186, identifier:isinstance; 187, argument_list; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:data; 190, string:'consumed_capacity'; 191, identifier:list; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:all_caps; 196, subscript; 196, 197; 196, 198; 197, identifier:data; 198, string:'consumed_capacity'; 199, else_clause; 199, 200; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:all_caps; 204, list:[data['consumed_capacity']]; 204, 205; 205, subscript; 205, 206; 205, 207; 206, identifier:data; 207, string:'consumed_capacity'; 208, for_statement; 208, 209; 208, 210; 208, 215; 209, identifier:hook; 210, subscript; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:_hooks; 214, string:'capacity'; 215, block; 215, 216; 216, for_statement; 216, 217; 216, 218; 216, 219; 217, identifier:cap; 218, identifier:all_caps; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 223; 222, identifier:hook; 223, argument_list; 223, 224; 223, 225; 223, 226; 223, 227; 223, 228; 224, identifier:self; 225, identifier:command; 226, identifier:kwargs; 227, identifier:data; 228, identifier:cap; 229, return_statement; 229, 230; 230, identifier:data
def call(self, command, **kwargs): for hook in self._hooks['precall']: hook(self, command, kwargs) op = getattr(self.client, command) attempt = 0 while True: try: data = op(**kwargs) break except ClientError as e: exc = translate_exception(e, kwargs) attempt += 1 if isinstance(exc, ThroughputException): if attempt > self.request_retries: exc.re_raise() self.exponential_sleep(attempt) else: exc.re_raise() for hook in self._hooks['postcall']: hook(self, command, kwargs, data) if 'ConsumedCapacity' in data: is_read = command in READ_COMMANDS consumed = data['ConsumedCapacity'] if isinstance(consumed, list): data['consumed_capacity'] = [ ConsumedCapacity.from_response(cap, is_read) for cap in consumed ] else: capacity = ConsumedCapacity.from_response(consumed, is_read) data['consumed_capacity'] = capacity if 'consumed_capacity' in data: if isinstance(data['consumed_capacity'], list): all_caps = data['consumed_capacity'] else: all_caps = [data['consumed_capacity']] for hook in self._hooks['capacity']: for cap in all_caps: hook(self, command, kwargs, data, cap) return data
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:delete_item2; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, identifier:self; 5, identifier:tablename; 6, identifier:key; 7, default_parameter; 7, 8; 7, 9; 8, identifier:expr_values; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:alias; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:condition; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:returns; 18, identifier:NONE; 19, default_parameter; 19, 20; 19, 21; 20, identifier:return_capacity; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:return_item_collection_metrics; 24, identifier:NONE; 25, dictionary_splat_pattern; 25, 26; 26, identifier:kwargs; 27, block; 27, 28; 27, 59; 27, 70; 27, 79; 27, 88; 27, 97; 27, 108; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:keywords; 31, dictionary; 31, 32; 31, 35; 31, 45; 31, 48; 31, 56; 32, pair; 32, 33; 32, 34; 33, string:'TableName'; 34, identifier:tablename; 35, pair; 35, 36; 35, 37; 36, string:'Key'; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:dynamizer; 42, identifier:encode_keys; 43, argument_list; 43, 44; 44, identifier:key; 45, pair; 45, 46; 45, 47; 46, string:'ReturnValues'; 47, identifier:returns; 48, pair; 48, 49; 48, 50; 49, string:'ReturnConsumedCapacity'; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_default_capacity; 54, argument_list; 54, 55; 55, identifier:return_capacity; 56, pair; 56, 57; 56, 58; 57, string:'ReturnItemCollectionMetrics'; 58, identifier:return_item_collection_metrics; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:values; 62, call; 62, 63; 62, 64; 63, identifier:build_expression_values; 64, argument_list; 64, 65; 64, 68; 64, 69; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:dynamizer; 68, identifier:expr_values; 69, identifier:kwargs; 70, if_statement; 70, 71; 70, 72; 71, identifier:values; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, subscript; 75, 76; 75, 77; 76, identifier:keywords; 77, string:'ExpressionAttributeValues'; 78, identifier:values; 79, if_statement; 79, 80; 79, 81; 80, identifier:alias; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:keywords; 86, string:'ExpressionAttributeNames'; 87, identifier:alias; 88, if_statement; 88, 89; 88, 90; 89, identifier:condition; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:keywords; 95, string:'ConditionExpression'; 96, identifier:condition; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:result; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:call; 104, argument_list; 104, 105; 104, 106; 105, string:'delete_item'; 106, dictionary_splat; 106, 107; 107, identifier:keywords; 108, if_statement; 108, 109; 108, 110; 109, identifier:result; 110, block; 110, 111; 111, return_statement; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:Result; 114, argument_list; 114, 115; 114, 118; 114, 119; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:dynamizer; 118, identifier:result; 119, string:'Attributes'
def delete_item2(self, tablename, key, expr_values=None, alias=None, condition=None, returns=NONE, return_capacity=None, return_item_collection_metrics=NONE, **kwargs): keywords = { 'TableName': tablename, 'Key': self.dynamizer.encode_keys(key), 'ReturnValues': returns, 'ReturnConsumedCapacity': self._default_capacity(return_capacity), 'ReturnItemCollectionMetrics': return_item_collection_metrics, } values = build_expression_values(self.dynamizer, expr_values, kwargs) if values: keywords['ExpressionAttributeValues'] = values if alias: keywords['ExpressionAttributeNames'] = alias if condition: keywords['ConditionExpression'] = condition result = self.call('delete_item', **keywords) if result: return Result(self.dynamizer, result, 'Attributes')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:update_item; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, identifier:tablename; 6, identifier:key; 7, identifier:updates; 8, default_parameter; 8, 9; 8, 10; 9, identifier:returns; 10, identifier:NONE; 11, default_parameter; 11, 12; 11, 13; 12, identifier:return_capacity; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:expect_or; 16, False; 17, dictionary_splat_pattern; 17, 18; 18, identifier:kwargs; 19, block; 19, 20; 19, 31; 19, 35; 19, 39; 19, 51; 19, 83; 19, 116; 19, 142; 19, 165; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:key; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:dynamizer; 28, identifier:encode_keys; 29, argument_list; 29, 30; 30, identifier:key; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:attr_updates; 34, dictionary; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:expected; 38, dictionary; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:keywords; 42, dictionary; 42, 43; 43, pair; 43, 44; 43, 45; 44, string:'ReturnConsumedCapacity'; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_default_capacity; 49, argument_list; 49, 50; 50, identifier:return_capacity; 51, for_statement; 51, 52; 51, 53; 51, 54; 52, identifier:update; 53, identifier:updates; 54, block; 54, 55; 54, 69; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:attr_updates; 59, identifier:update; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:update; 64, identifier:attrs; 65, argument_list; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:dynamizer; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:expected; 73, identifier:update; 74, argument_list; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:update; 78, identifier:expected; 79, argument_list; 79, 80; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:dynamizer; 83, for_statement; 83, 84; 83, 87; 83, 99; 84, pattern_list; 84, 85; 84, 86; 85, identifier:k; 86, identifier:v; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:six; 90, identifier:iteritems; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:encode_query_kwargs; 94, argument_list; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:dynamizer; 98, identifier:kwargs; 99, block; 99, 100; 99, 110; 100, if_statement; 100, 101; 100, 104; 101, comparison_operator:in; 101, 102; 101, 103; 102, identifier:k; 103, identifier:expected; 104, block; 104, 105; 105, raise_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:ValueError; 108, argument_list; 108, 109; 109, string:"Cannot have more than one condition on a single field"; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:expected; 114, identifier:k; 115, identifier:v; 116, if_statement; 116, 117; 116, 118; 117, identifier:expected; 118, block; 118, 119; 118, 125; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:keywords; 123, string:'Expected'; 124, identifier:expected; 125, if_statement; 125, 126; 125, 132; 126, comparison_operator:>; 126, 127; 126, 131; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:expected; 131, integer:1; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:keywords; 137, string:'ConditionalOperator'; 138, conditional_expression:if; 138, 139; 138, 140; 138, 141; 139, string:'OR'; 140, identifier:expect_or; 141, string:'AND'; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:result; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:call; 149, argument_list; 149, 150; 149, 151; 149, 154; 149, 157; 149, 160; 149, 163; 150, string:'update_item'; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:TableName; 153, identifier:tablename; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:Key; 156, identifier:key; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:AttributeUpdates; 159, identifier:attr_updates; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:ReturnValues; 162, identifier:returns; 163, dictionary_splat; 163, 164; 164, identifier:keywords; 165, if_statement; 165, 166; 165, 167; 166, identifier:result; 167, block; 167, 168; 168, return_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:Result; 171, argument_list; 171, 172; 171, 175; 171, 176; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:dynamizer; 175, identifier:result; 176, string:'Attributes'
def update_item(self, tablename, key, updates, returns=NONE, return_capacity=None, expect_or=False, **kwargs): key = self.dynamizer.encode_keys(key) attr_updates = {} expected = {} keywords = { 'ReturnConsumedCapacity': self._default_capacity(return_capacity), } for update in updates: attr_updates.update(update.attrs(self.dynamizer)) expected.update(update.expected(self.dynamizer)) for k, v in six.iteritems(encode_query_kwargs(self.dynamizer, kwargs)): if k in expected: raise ValueError("Cannot have more than one condition on a single field") expected[k] = v if expected: keywords['Expected'] = expected if len(expected) > 1: keywords['ConditionalOperator'] = 'OR' if expect_or else 'AND' result = self.call('update_item', TableName=tablename, Key=key, AttributeUpdates=attr_updates, ReturnValues=returns, **keywords) if result: return Result(self.dynamizer, result, 'Attributes')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 4, identifier:self; 5, identifier:tablename; 6, default_parameter; 6, 7; 6, 8; 7, identifier:attributes; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:consistent; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:count; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:index; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:limit; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:desc; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:return_capacity; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:filter; 29, None; 30, default_parameter; 30, 31; 30, 32; 31, identifier:filter_or; 32, False; 33, default_parameter; 33, 34; 33, 35; 34, identifier:exclusive_start_key; 35, None; 36, dictionary_splat_pattern; 36, 37; 37, identifier:kwargs; 38, block; 38, 39; 38, 70; 38, 81; 38, 92; 38, 126; 38, 145; 38, 160; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:keywords; 42, dictionary; 42, 43; 42, 46; 42, 54; 42, 57; 42, 61; 43, pair; 43, 44; 43, 45; 44, string:'TableName'; 45, identifier:tablename; 46, pair; 46, 47; 46, 48; 47, string:'ReturnConsumedCapacity'; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_default_capacity; 52, argument_list; 52, 53; 53, identifier:return_capacity; 54, pair; 54, 55; 54, 56; 55, string:'ConsistentRead'; 56, identifier:consistent; 57, pair; 57, 58; 57, 59; 58, string:'ScanIndexForward'; 59, not_operator; 59, 60; 60, identifier:desc; 61, pair; 61, 62; 61, 63; 62, string:'KeyConditions'; 63, call; 63, 64; 63, 65; 64, identifier:encode_query_kwargs; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:dynamizer; 69, identifier:kwargs; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:attributes; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:keywords; 79, string:'AttributesToGet'; 80, identifier:attributes; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:index; 84, None; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:keywords; 90, string:'IndexName'; 91, identifier:index; 92, if_statement; 92, 93; 92, 96; 93, comparison_operator:is; 93, 94; 93, 95; 94, identifier:filter; 95, None; 96, block; 96, 97; 96, 114; 97, if_statement; 97, 98; 97, 104; 98, comparison_operator:>; 98, 99; 98, 103; 99, call; 99, 100; 99, 101; 100, identifier:len; 101, argument_list; 101, 102; 102, identifier:filter; 103, integer:1; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:keywords; 109, string:'ConditionalOperator'; 110, conditional_expression:if; 110, 111; 110, 112; 110, 113; 111, string:'OR'; 112, identifier:filter_or; 113, string:'AND'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:keywords; 118, string:'QueryFilter'; 119, call; 119, 120; 119, 121; 120, identifier:encode_query_kwargs; 121, argument_list; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:dynamizer; 125, identifier:filter; 126, if_statement; 126, 127; 126, 130; 127, comparison_operator:is; 127, 128; 127, 129; 128, identifier:exclusive_start_key; 129, None; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 136; 132, 137; 133, subscript; 133, 134; 133, 135; 134, identifier:keywords; 135, string:'ExclusiveStartKey'; 136, line_continuation:\; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:dynamizer; 142, identifier:maybe_encode_keys; 143, argument_list; 143, 144; 144, identifier:exclusive_start_key; 145, if_statement; 145, 146; 145, 152; 146, not_operator; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:isinstance; 149, argument_list; 149, 150; 149, 151; 150, identifier:limit; 151, identifier:Limit; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:limit; 156, call; 156, 157; 156, 158; 157, identifier:Limit; 158, argument_list; 158, 159; 159, identifier:limit; 160, if_statement; 160, 161; 160, 162; 160, 178; 161, identifier:count; 162, block; 162, 163; 162, 169; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:keywords; 167, string:'Select'; 168, identifier:COUNT; 169, return_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:_count; 174, argument_list; 174, 175; 174, 176; 174, 177; 175, string:'query'; 176, identifier:limit; 177, identifier:keywords; 178, else_clause; 178, 179; 179, block; 179, 180; 180, return_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:ResultSet; 183, argument_list; 183, 184; 183, 185; 183, 186; 183, 187; 184, identifier:self; 185, identifier:limit; 186, string:'query'; 187, dictionary_splat; 187, 188; 188, identifier:keywords
def query(self, tablename, attributes=None, consistent=False, count=False, index=None, limit=None, desc=False, return_capacity=None, filter=None, filter_or=False, exclusive_start_key=None, **kwargs): keywords = { 'TableName': tablename, 'ReturnConsumedCapacity': self._default_capacity(return_capacity), 'ConsistentRead': consistent, 'ScanIndexForward': not desc, 'KeyConditions': encode_query_kwargs(self.dynamizer, kwargs), } if attributes is not None: keywords['AttributesToGet'] = attributes if index is not None: keywords['IndexName'] = index if filter is not None: if len(filter) > 1: keywords['ConditionalOperator'] = 'OR' if filter_or else 'AND' keywords['QueryFilter'] = encode_query_kwargs(self.dynamizer, filter) if exclusive_start_key is not None: keywords['ExclusiveStartKey'] = \ self.dynamizer.maybe_encode_keys(exclusive_start_key) if not isinstance(limit, Limit): limit = Limit(limit) if count: keywords['Select'] = COUNT return self._count('query', limit, keywords) else: return ResultSet(self, limit, 'query', **keywords)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:letter_scales; 3, parameters; 3, 4; 4, identifier:counts; 5, block; 5, 6; 5, 26; 5, 46; 5, 60; 6, try_statement; 6, 7; 6, 21; 7, block; 7, 8; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:scale; 11, binary_operator:/; 11, 12; 11, 13; 12, float:1.0; 13, call; 13, 14; 13, 15; 14, identifier:sum; 15, argument_list; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:counts; 19, identifier:values; 20, argument_list; 21, except_clause; 21, 22; 21, 23; 22, identifier:ZeroDivisionError; 23, block; 23, 24; 24, return_statement; 24, 25; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:freqs; 29, list_comprehension; 29, 30; 29, 35; 29, 44; 30, tuple; 30, 31; 30, 32; 31, identifier:aa; 32, binary_operator:*; 32, 33; 32, 34; 33, identifier:cnt; 34, identifier:scale; 35, for_in_clause; 35, 36; 35, 39; 36, pattern_list; 36, 37; 36, 38; 37, identifier:aa; 38, identifier:cnt; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:counts; 42, identifier:iteritems; 43, argument_list; 44, if_clause; 44, 45; 45, identifier:cnt; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:freqs; 50, identifier:sort; 51, argument_list; 51, 52; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:key; 54, lambda; 54, 55; 54, 57; 55, lambda_parameters; 55, 56; 56, identifier:pair; 57, subscript; 57, 58; 57, 59; 58, identifier:pair; 59, integer:1; 60, return_statement; 60, 61; 61, identifier:freqs
def letter_scales(counts): try: scale = 1.0 / sum(counts.values()) except ZeroDivisionError: return [] freqs = [(aa, cnt*scale) for aa, cnt in counts.iteritems() if cnt] freqs.sort(key=lambda pair: pair[1]) return freqs
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:count_diffs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 4, identifier:align; 5, identifier:feats; 6, identifier:inseq; 7, identifier:locus; 8, identifier:cutoff; 9, default_parameter; 9, 10; 9, 11; 10, identifier:verbose; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:verbosity; 14, integer:0; 15, block; 15, 16; 15, 27; 15, 31; 15, 35; 15, 39; 15, 43; 15, 47; 15, 51; 15, 80; 15, 186; 15, 192; 15, 198; 15, 204; 15, 210; 15, 216; 15, 225; 15, 236; 15, 361; 15, 367; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:nfeats; 19, call; 19, 20; 19, 21; 20, identifier:len; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:feats; 25, identifier:keys; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:mm; 30, integer:0; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:insr; 34, integer:0; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:dels; 38, integer:0; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:gaps; 42, integer:0; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:match; 46, integer:0; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:lastb; 50, string:''; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:l; 54, conditional_expression:if; 54, 55; 54, 61; 54, 74; 55, call; 55, 56; 55, 57; 56, identifier:len; 57, argument_list; 57, 58; 58, subscript; 58, 59; 58, 60; 59, identifier:align; 60, integer:0; 61, comparison_operator:>; 61, 62; 61, 68; 62, call; 62, 63; 62, 64; 63, identifier:len; 64, argument_list; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:align; 67, integer:0; 68, call; 68, 69; 68, 70; 69, identifier:len; 70, argument_list; 70, 71; 71, subscript; 71, 72; 71, 73; 72, identifier:align; 73, integer:1; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:align; 79, integer:1; 80, for_statement; 80, 81; 80, 82; 80, 87; 81, identifier:i; 82, call; 82, 83; 82, 84; 83, identifier:range; 84, argument_list; 84, 85; 84, 86; 85, integer:0; 86, identifier:l; 87, block; 87, 88; 88, if_statement; 88, 89; 88, 104; 88, 157; 89, boolean_operator:or; 89, 90; 89, 97; 90, comparison_operator:==; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:align; 94, integer:0; 95, identifier:i; 96, string:"-"; 97, comparison_operator:==; 97, 98; 97, 103; 98, subscript; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:align; 101, integer:1; 102, identifier:i; 103, string:"-"; 104, block; 104, 105; 104, 131; 105, if_statement; 105, 106; 105, 113; 106, comparison_operator:==; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:align; 110, integer:0; 111, identifier:i; 112, string:"-"; 113, block; 113, 114; 113, 118; 113, 127; 114, expression_statement; 114, 115; 115, augmented_assignment:+=; 115, 116; 115, 117; 116, identifier:insr; 117, integer:1; 118, if_statement; 118, 119; 118, 122; 119, comparison_operator:!=; 119, 120; 119, 121; 120, identifier:lastb; 121, string:'-'; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, augmented_assignment:+=; 124, 125; 124, 126; 125, identifier:gaps; 126, integer:1; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:lastb; 130, string:"-"; 131, if_statement; 131, 132; 131, 139; 132, comparison_operator:==; 132, 133; 132, 138; 133, subscript; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:align; 136, integer:1; 137, identifier:i; 138, string:"-"; 139, block; 139, 140; 139, 144; 139, 153; 140, expression_statement; 140, 141; 141, augmented_assignment:+=; 141, 142; 141, 143; 142, identifier:dels; 143, integer:1; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:!=; 145, 146; 145, 147; 146, identifier:lastb; 147, string:'-'; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, augmented_assignment:+=; 150, 151; 150, 152; 151, identifier:gaps; 152, integer:1; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:lastb; 156, string:"-"; 157, else_clause; 157, 158; 158, block; 158, 159; 158, 163; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:lastb; 162, string:''; 163, if_statement; 163, 164; 163, 175; 163, 180; 164, comparison_operator:!=; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:align; 168, integer:0; 169, identifier:i; 170, subscript; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:align; 173, integer:1; 174, identifier:i; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, augmented_assignment:+=; 177, 178; 177, 179; 178, identifier:mm; 179, integer:1; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, augmented_assignment:+=; 183, 184; 183, 185; 184, identifier:match; 185, integer:1; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:gper; 189, binary_operator:/; 189, 190; 189, 191; 190, identifier:gaps; 191, identifier:nfeats; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:delper; 195, binary_operator:/; 195, 196; 195, 197; 196, identifier:dels; 197, identifier:l; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:iper; 201, binary_operator:/; 201, 202; 201, 203; 202, identifier:insr; 203, identifier:l; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:mmper; 207, binary_operator:/; 207, 208; 207, 209; 208, identifier:mm; 209, identifier:l; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:mper; 213, binary_operator:/; 213, 214; 213, 215; 214, identifier:match; 215, identifier:l; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:mper2; 219, binary_operator:/; 219, 220; 219, 221; 220, identifier:match; 221, call; 221, 222; 221, 223; 222, identifier:len; 223, argument_list; 223, 224; 224, identifier:inseq; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:logger; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:logging; 231, identifier:getLogger; 232, argument_list; 232, 233; 233, binary_operator:+; 233, 234; 233, 235; 234, string:"Logger."; 235, identifier:__name__; 236, if_statement; 236, 237; 236, 242; 237, boolean_operator:and; 237, 238; 237, 239; 238, identifier:verbose; 239, comparison_operator:>; 239, 240; 239, 241; 240, identifier:verbosity; 241, integer:0; 242, block; 242, 243; 242, 264; 242, 277; 242, 291; 242, 305; 242, 319; 242, 333; 242, 347; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:logger; 247, identifier:info; 248, argument_list; 248, 249; 249, binary_operator:+; 249, 250; 249, 251; 250, string:"Features algined = "; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, string:","; 254, identifier:join; 255, argument_list; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:list; 258, argument_list; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:feats; 262, identifier:keys; 263, argument_list; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:logger; 268, identifier:info; 269, argument_list; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, string:'{:<22}{:<6d}'; 273, identifier:format; 274, argument_list; 274, 275; 274, 276; 275, string:"Number of feats: "; 276, identifier:nfeats; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:logger; 281, identifier:info; 282, argument_list; 282, 283; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, string:'{:<22}{:<6d}{:<1.2f}'; 286, identifier:format; 287, argument_list; 287, 288; 287, 289; 287, 290; 288, string:"Number of gaps: "; 289, identifier:gaps; 290, identifier:gper; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:logger; 295, identifier:info; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, string:'{:<22}{:<6d}{:<1.2f}'; 300, identifier:format; 301, argument_list; 301, 302; 301, 303; 301, 304; 302, string:"Number of deletions: "; 303, identifier:dels; 304, identifier:delper; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:logger; 309, identifier:info; 310, argument_list; 310, 311; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, string:'{:<22}{:<6d}{:<1.2f}'; 314, identifier:format; 315, argument_list; 315, 316; 315, 317; 315, 318; 316, string:"Number of insertions: "; 317, identifier:insr; 318, identifier:iper; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:logger; 323, identifier:info; 324, argument_list; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, string:'{:<22}{:<6d}{:<1.2f}'; 328, identifier:format; 329, argument_list; 329, 330; 329, 331; 329, 332; 330, string:"Number of mismatches: "; 331, identifier:mm; 332, identifier:mmper; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:logger; 337, identifier:info; 338, argument_list; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, string:'{:<22}{:<6d}{:<1.2f}'; 342, identifier:format; 343, argument_list; 343, 344; 343, 345; 343, 346; 344, string:"Number of matches: "; 345, identifier:match; 346, identifier:mper; 347, expression_statement; 347, 348; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:logger; 351, identifier:info; 352, argument_list; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, string:'{:<22}{:<6d}{:<1.2f}'; 356, identifier:format; 357, argument_list; 357, 358; 357, 359; 357, 360; 358, string:"Number of matches: "; 359, identifier:match; 360, identifier:mper2; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:indel; 364, binary_operator:+; 364, 365; 364, 366; 365, identifier:iper; 366, identifier:delper; 367, if_statement; 367, 368; 367, 382; 367, 397; 368, boolean_operator:and; 368, 369; 368, 379; 369, boolean_operator:and; 369, 370; 369, 376; 370, comparison_operator:>; 370, 371; 370, 375; 371, call; 371, 372; 371, 373; 372, identifier:len; 373, argument_list; 373, 374; 374, identifier:inseq; 375, integer:6000; 376, comparison_operator:<; 376, 377; 376, 378; 377, identifier:mmper; 378, float:.10; 379, comparison_operator:>; 379, 380; 379, 381; 380, identifier:mper2; 381, float:.80; 382, block; 382, 383; 382, 393; 383, if_statement; 383, 384; 383, 385; 384, identifier:verbose; 385, block; 385, 386; 386, expression_statement; 386, 387; 387, call; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:logger; 390, identifier:info; 391, argument_list; 391, 392; 392, string:"Alignment coverage high enough to complete annotation 11"; 393, return_statement; 393, 394; 394, expression_list; 394, 395; 394, 396; 395, identifier:insr; 396, identifier:dels; 397, else_clause; 397, 398; 398, block; 398, 399; 398, 405; 399, expression_statement; 399, 400; 400, assignment; 400, 401; 400, 402; 401, identifier:indel_mm; 402, binary_operator:+; 402, 403; 402, 404; 403, identifier:indel; 404, identifier:mper2; 405, if_statement; 405, 406; 405, 422; 405, 440; 406, boolean_operator:and; 406, 407; 406, 419; 407, boolean_operator:and; 407, 408; 407, 416; 408, parenthesized_expression; 408, 409; 409, boolean_operator:or; 409, 410; 409, 413; 410, comparison_operator:>; 410, 411; 410, 412; 411, identifier:indel; 412, float:0.5; 413, comparison_operator:>; 413, 414; 413, 415; 414, identifier:mmper; 415, float:0.05; 416, comparison_operator:<; 416, 417; 416, 418; 417, identifier:mper2; 418, identifier:cutoff; 419, comparison_operator:!=; 419, 420; 419, 421; 420, identifier:indel_mm; 421, integer:1; 422, block; 422, 423; 422, 433; 423, if_statement; 423, 424; 423, 425; 424, identifier:verbose; 425, block; 425, 426; 426, expression_statement; 426, 427; 427, call; 427, 428; 427, 431; 428, attribute; 428, 429; 428, 430; 429, identifier:logger; 430, identifier:info; 431, argument_list; 431, 432; 432, string:"Alignment coverage NOT high enough to return annotation"; 433, return_statement; 433, 434; 434, call; 434, 435; 434, 436; 435, identifier:Annotation; 436, argument_list; 436, 437; 437, keyword_argument; 437, 438; 437, 439; 438, identifier:complete_annotation; 439, False; 440, else_clause; 440, 441; 441, block; 441, 442; 441, 452; 442, if_statement; 442, 443; 442, 444; 443, identifier:verbose; 444, block; 444, 445; 445, expression_statement; 445, 446; 446, call; 446, 447; 446, 450; 447, attribute; 447, 448; 447, 449; 448, identifier:logger; 449, identifier:info; 450, argument_list; 450, 451; 451, string:"Alignment coverage high enough to complete annotation"; 452, return_statement; 452, 453; 453, expression_list; 453, 454; 453, 455; 454, identifier:insr; 455, identifier:dels
def count_diffs(align, feats, inseq, locus, cutoff, verbose=False, verbosity=0): nfeats = len(feats.keys()) mm = 0 insr = 0 dels = 0 gaps = 0 match = 0 lastb = '' l = len(align[0]) if len(align[0]) > len(align[1]) else len(align[1]) for i in range(0, l): if align[0][i] == "-" or align[1][i] == "-": if align[0][i] == "-": insr += 1 if lastb != '-': gaps += 1 lastb = "-" if align[1][i] == "-": dels += 1 if lastb != '-': gaps += 1 lastb = "-" else: lastb = '' if align[0][i] != align[1][i]: mm += 1 else: match += 1 gper = gaps / nfeats delper = dels / l iper = insr / l mmper = mm / l mper = match / l mper2 = match / len(inseq) logger = logging.getLogger("Logger." + __name__) if verbose and verbosity > 0: logger.info("Features algined = " + ",".join(list(feats.keys()))) logger.info('{:<22}{:<6d}'.format("Number of feats: ", nfeats)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of gaps: ", gaps, gper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of deletions: ", dels, delper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of insertions: ", insr, iper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of mismatches: ", mm, mmper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of matches: ", match, mper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of matches: ", match, mper2)) indel = iper + delper if len(inseq) > 6000 and mmper < .10 and mper2 > .80: if verbose: logger.info("Alignment coverage high enough to complete annotation 11") return insr, dels else: indel_mm = indel + mper2 if (indel > 0.5 or mmper > 0.05) and mper2 < cutoff and indel_mm != 1: if verbose: logger.info("Alignment coverage NOT high enough to return annotation") return Annotation(complete_annotation=False) else: if verbose: logger.info("Alignment coverage high enough to complete annotation") return insr, dels
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd_debug; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:argv; 6, identifier:help; 7, block; 7, 8; 7, 26; 7, 32; 7, 54; 7, 71; 7, 88; 7, 105; 7, 122; 7, 145; 7, 154; 7, 163; 7, 171; 7, 181; 7, 315; 7, 345; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:parser; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:argparse; 14, identifier:ArgumentParser; 15, argument_list; 15, 16; 15, 23; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:prog; 18, binary_operator:%; 18, 19; 18, 20; 19, string:"%s debug"; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:progname; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:description; 25, identifier:help; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:instances; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:instances; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:parser; 36, identifier:add_argument; 37, argument_list; 37, 38; 37, 39; 37, 42; 37, 45; 37, 48; 38, string:"instance"; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:nargs; 41, integer:1; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:metavar; 44, string:"instance"; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:help; 47, string:"Name of the instance from the config."; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:choices; 50, call; 50, 51; 50, 52; 51, identifier:sorted; 52, argument_list; 52, 53; 53, identifier:instances; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:parser; 58, identifier:add_argument; 59, argument_list; 59, 60; 59, 61; 59, 62; 59, 65; 59, 68; 60, string:"-v"; 61, string:"--verbose"; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:dest; 64, string:"verbose"; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:action; 67, string:"store_true"; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:help; 70, string:"Print more info and output the startup script"; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:parser; 75, identifier:add_argument; 76, argument_list; 76, 77; 76, 78; 76, 79; 76, 82; 76, 85; 77, string:"-c"; 78, string:"--console-output"; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:dest; 81, string:"console_output"; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:action; 84, string:"store_true"; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:help; 87, string:"Prints the console output of the instance if available"; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:parser; 92, identifier:add_argument; 93, argument_list; 93, 94; 93, 95; 93, 96; 93, 99; 93, 102; 94, string:"-i"; 95, string:"--interactive"; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:dest; 98, string:"interactive"; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:action; 101, string:"store_true"; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:help; 104, string:"Creates a connection and drops you into an interactive Python session"; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:parser; 109, identifier:add_argument; 110, argument_list; 110, 111; 110, 112; 110, 113; 110, 116; 110, 119; 111, string:"-r"; 112, string:"--raw"; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:dest; 115, string:"raw"; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:action; 118, string:"store_true"; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:help; 121, string:"Outputs the raw possibly compressed startup script"; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:parser; 126, identifier:add_argument; 127, argument_list; 127, 128; 127, 129; 127, 130; 127, 133; 127, 136; 127, 139; 127, 142; 128, string:"-o"; 129, string:"--override"; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:nargs; 132, string:"*"; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:type; 135, identifier:str; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:dest; 138, string:"overrides"; 139, keyword_argument; 139, 140; 139, 141; 140, identifier:metavar; 141, string:"OVERRIDE"; 142, keyword_argument; 142, 143; 142, 144; 143, identifier:help; 144, string:"Option to override instance config for startup script (name=value)."; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:args; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:parser; 151, identifier:parse_args; 152, argument_list; 152, 153; 153, identifier:argv; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:overrides; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_parse_overrides; 161, argument_list; 161, 162; 162, identifier:args; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:overrides; 167, string:'instances'; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:instances; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:instance; 174, subscript; 174, 175; 174, 176; 175, identifier:instances; 176, subscript; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:args; 179, identifier:instance; 180, integer:0; 181, if_statement; 181, 182; 181, 187; 182, call; 182, 183; 182, 184; 183, identifier:hasattr; 184, argument_list; 184, 185; 184, 186; 185, identifier:instance; 186, string:'startup_script'; 187, block; 187, 188; 187, 202; 187, 213; 187, 227; 187, 285; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:startup_script; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:instance; 194, identifier:startup_script; 195, argument_list; 195, 196; 195, 199; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:overrides; 198, identifier:overrides; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:debug; 201, True; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:max_size; 205, call; 205, 206; 205, 207; 206, identifier:getattr; 207, argument_list; 207, 208; 207, 209; 207, 210; 208, identifier:instance; 209, string:'max_startup_script_size'; 210, binary_operator:*; 210, 211; 210, 212; 211, integer:16; 212, integer:1024; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:log; 217, identifier:info; 218, argument_list; 218, 219; 218, 220; 218, 226; 219, string:"Length of startup script: %s/%s"; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, subscript; 223, 224; 223, 225; 224, identifier:startup_script; 225, string:'raw'; 226, identifier:max_size; 227, if_statement; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:args; 230, identifier:verbose; 231, block; 231, 232; 232, if_statement; 232, 233; 232, 238; 232, 276; 233, comparison_operator:in; 233, 234; 233, 235; 234, string:'startup_script'; 235, attribute; 235, 236; 235, 237; 236, identifier:instance; 237, identifier:config; 238, block; 238, 239; 239, if_statement; 239, 240; 239, 247; 239, 255; 239, 267; 240, comparison_operator:==; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:startup_script; 243, string:'original'; 244, subscript; 244, 245; 244, 246; 245, identifier:startup_script; 246, string:'raw'; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:log; 252, identifier:info; 253, argument_list; 253, 254; 254, string:"Startup script:"; 255, elif_clause; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:args; 258, identifier:raw; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:log; 264, identifier:info; 265, argument_list; 265, 266; 266, string:"Compressed startup script:"; 267, else_clause; 267, 268; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:log; 273, identifier:info; 274, argument_list; 274, 275; 275, string:"Uncompressed startup script:"; 276, else_clause; 276, 277; 277, block; 277, 278; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:log; 282, identifier:info; 283, argument_list; 283, 284; 284, string:"No startup script specified"; 285, if_statement; 285, 286; 285, 289; 285, 300; 286, attribute; 286, 287; 286, 288; 287, identifier:args; 288, identifier:raw; 289, block; 289, 290; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:print; 293, argument_list; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:startup_script; 296, string:'raw'; 297, keyword_argument; 297, 298; 297, 299; 298, identifier:end; 299, string:''; 300, elif_clause; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:args; 303, identifier:verbose; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 308; 307, identifier:print; 308, argument_list; 308, 309; 308, 312; 309, subscript; 309, 310; 309, 311; 310, identifier:startup_script; 311, string:'original'; 312, keyword_argument; 312, 313; 312, 314; 313, identifier:end; 314, string:''; 315, if_statement; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:args; 318, identifier:console_output; 319, block; 319, 320; 320, if_statement; 320, 321; 320, 326; 320, 336; 321, call; 321, 322; 321, 323; 322, identifier:hasattr; 323, argument_list; 323, 324; 323, 325; 324, identifier:instance; 325, string:'get_console_output'; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:print; 330, argument_list; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:instance; 334, identifier:get_console_output; 335, argument_list; 336, else_clause; 336, 337; 337, block; 337, 338; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:log; 342, identifier:error; 343, argument_list; 343, 344; 344, string:"The instance doesn't support console output."; 345, if_statement; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:args; 348, identifier:interactive; 349, block; 349, 350; 349, 353; 349, 358; 349, 378; 349, 385; 349, 408; 350, import_statement; 350, 351; 351, dotted_name; 351, 352; 352, identifier:readline; 353, import_from_statement; 353, 354; 353, 356; 354, dotted_name; 354, 355; 355, identifier:pprint; 356, dotted_name; 356, 357; 357, identifier:pprint; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 361; 360, identifier:local; 361, call; 361, 362; 361, 363; 362, identifier:dict; 363, argument_list; 363, 364; 363, 367; 363, 372; 363, 375; 364, keyword_argument; 364, 365; 364, 366; 365, identifier:ctrl; 366, identifier:self; 367, keyword_argument; 367, 368; 367, 369; 368, identifier:instances; 369, attribute; 369, 370; 369, 371; 370, identifier:self; 371, identifier:instances; 372, keyword_argument; 372, 373; 372, 374; 373, identifier:instance; 374, identifier:instance; 375, keyword_argument; 375, 376; 375, 377; 376, identifier:pprint; 377, identifier:pprint; 378, expression_statement; 378, 379; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:readline; 382, identifier:parse_and_bind; 383, argument_list; 383, 384; 384, string:'tab: complete'; 385, try_statement; 385, 386; 385, 404; 386, block; 386, 387; 386, 390; 387, import_statement; 387, 388; 388, dotted_name; 388, 389; 389, identifier:rlcompleter; 390, expression_statement; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:readline; 394, identifier:set_completer; 395, argument_list; 395, 396; 396, attribute; 396, 397; 396, 403; 397, call; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, identifier:rlcompleter; 400, identifier:Completer; 401, argument_list; 401, 402; 402, identifier:local; 403, identifier:complete; 404, except_clause; 404, 405; 404, 406; 405, identifier:ImportError; 406, block; 406, 407; 407, pass_statement; 408, expression_statement; 408, 409; 409, call; 409, 410; 409, 416; 410, attribute; 410, 411; 410, 415; 411, call; 411, 412; 411, 413; 412, identifier:__import__; 413, argument_list; 413, 414; 414, string:"code"; 415, identifier:interact; 416, argument_list; 416, 417; 417, keyword_argument; 417, 418; 417, 419; 418, identifier:local; 419, identifier:local
def cmd_debug(self, argv, help): parser = argparse.ArgumentParser( prog="%s debug" % self.progname, description=help, ) instances = self.instances parser.add_argument("instance", nargs=1, metavar="instance", help="Name of the instance from the config.", choices=sorted(instances)) parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Print more info and output the startup script") parser.add_argument("-c", "--console-output", dest="console_output", action="store_true", help="Prints the console output of the instance if available") parser.add_argument("-i", "--interactive", dest="interactive", action="store_true", help="Creates a connection and drops you into an interactive Python session") parser.add_argument("-r", "--raw", dest="raw", action="store_true", help="Outputs the raw possibly compressed startup script") parser.add_argument("-o", "--override", nargs="*", type=str, dest="overrides", metavar="OVERRIDE", help="Option to override instance config for startup script (name=value).") args = parser.parse_args(argv) overrides = self._parse_overrides(args) overrides['instances'] = self.instances instance = instances[args.instance[0]] if hasattr(instance, 'startup_script'): startup_script = instance.startup_script(overrides=overrides, debug=True) max_size = getattr(instance, 'max_startup_script_size', 16 * 1024) log.info("Length of startup script: %s/%s", len(startup_script['raw']), max_size) if args.verbose: if 'startup_script' in instance.config: if startup_script['original'] == startup_script['raw']: log.info("Startup script:") elif args.raw: log.info("Compressed startup script:") else: log.info("Uncompressed startup script:") else: log.info("No startup script specified") if args.raw: print(startup_script['raw'], end='') elif args.verbose: print(startup_script['original'], end='') if args.console_output: if hasattr(instance, 'get_console_output'): print(instance.get_console_output()) else: log.error("The instance doesn't support console output.") if args.interactive: import readline from pprint import pprint local = dict( ctrl=self, instances=self.instances, instance=instance, pprint=pprint) readline.parse_and_bind('tab: complete') try: import rlcompleter readline.set_completer(rlcompleter.Completer(local).complete) except ImportError: pass __import__("code").interact(local=local)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd_ssh; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:argv; 6, identifier:help; 7, block; 7, 8; 7, 26; 7, 37; 7, 59; 7, 74; 7, 81; 7, 85; 7, 89; 7, 146; 7, 191; 7, 197; 7, 213; 7, 271; 7, 277; 7, 289; 7, 295; 7, 311; 7, 321; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:parser; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:argparse; 14, identifier:ArgumentParser; 15, argument_list; 15, 16; 15, 23; 16, keyword_argument; 16, 17; 16, 18; 17, identifier:prog; 18, binary_operator:%; 18, 19; 18, 20; 19, string:"%s ssh"; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:progname; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:description; 25, identifier:help; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:instances; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:get_instances; 33, argument_list; 33, 34; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:command; 36, string:'init_ssh_key'; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:parser; 41, identifier:add_argument; 42, argument_list; 42, 43; 42, 44; 42, 47; 42, 50; 42, 53; 43, string:"instance"; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:nargs; 46, integer:1; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:metavar; 49, string:"instance"; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:help; 52, string:"Name of the instance from the config."; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:choices; 55, call; 55, 56; 55, 57; 56, identifier:sorted; 57, argument_list; 57, 58; 58, identifier:instances; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:parser; 63, identifier:add_argument; 64, argument_list; 64, 65; 64, 66; 64, 71; 65, string:"..."; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:nargs; 68, attribute; 68, 69; 68, 70; 69, identifier:argparse; 70, identifier:REMAINDER; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:help; 73, string:"ssh options"; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:iargs; 77, call; 77, 78; 77, 79; 78, identifier:enumerate; 79, argument_list; 79, 80; 80, identifier:argv; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:sid_index; 84, None; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:user; 88, None; 89, for_statement; 89, 90; 89, 93; 89, 94; 90, pattern_list; 90, 91; 90, 92; 91, identifier:i; 92, identifier:arg; 93, identifier:iargs; 94, block; 94, 95; 94, 109; 95, if_statement; 95, 96; 95, 103; 96, not_operator; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:arg; 100, identifier:startswith; 101, argument_list; 101, 102; 102, string:'-'; 103, block; 103, 104; 103, 108; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:sid_index; 107, identifier:i; 108, break_statement; 109, if_statement; 109, 110; 109, 115; 109, 117; 110, comparison_operator:in; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:arg; 113, integer:1; 114, string:'1246AaCfgKkMNnqsTtVvXxYy'; 115, block; 115, 116; 116, continue_statement; 117, elif_clause; 117, 118; 117, 123; 118, comparison_operator:in; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:arg; 121, integer:1; 122, string:'bcDeFiLlmOopRSw'; 123, block; 123, 124; 123, 132; 123, 145; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:value; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:iargs; 130, identifier:next; 131, argument_list; 132, if_statement; 132, 133; 132, 138; 133, comparison_operator:==; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:arg; 136, integer:1; 137, string:'l'; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:user; 142, subscript; 142, 143; 142, 144; 143, identifier:value; 144, integer:1; 145, continue_statement; 146, if_statement; 146, 147; 146, 150; 146, 158; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:sid_index; 149, None; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:parser; 155, identifier:parse_args; 156, argument_list; 156, 157; 157, list:[]; 158, else_clause; 158, 159; 159, block; 159, 160; 159, 166; 159, 183; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:sid; 163, subscript; 163, 164; 163, 165; 164, identifier:argv; 165, identifier:sid_index; 166, if_statement; 166, 167; 166, 170; 167, comparison_operator:in; 167, 168; 167, 169; 168, string:'@'; 169, identifier:sid; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, pattern_list; 173, 174; 173, 175; 174, identifier:user; 175, identifier:sid; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:sid; 179, identifier:split; 180, argument_list; 180, 181; 180, 182; 181, string:'@'; 182, integer:1; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:parser; 187, identifier:parse_args; 188, argument_list; 188, 189; 189, list:[sid]; 189, 190; 190, identifier:sid; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:instance; 194, subscript; 194, 195; 194, 196; 195, identifier:instances; 196, identifier:sid; 197, if_statement; 197, 198; 197, 201; 198, comparison_operator:is; 198, 199; 198, 200; 199, identifier:user; 200, None; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:user; 205, call; 205, 206; 205, 211; 206, attribute; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:instance; 209, identifier:config; 210, identifier:get; 211, argument_list; 211, 212; 212, string:'user'; 213, try_statement; 213, 214; 213, 226; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:ssh_info; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:instance; 221, identifier:init_ssh_key; 222, argument_list; 222, 223; 223, keyword_argument; 223, 224; 223, 225; 224, identifier:user; 225, identifier:user; 226, except_clause; 226, 227; 226, 239; 227, as_pattern; 227, 228; 227, 237; 228, tuple; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:instance; 232, identifier:paramiko; 233, identifier:SSHException; 234, attribute; 234, 235; 234, 236; 235, identifier:socket; 236, identifier:error; 237, as_pattern_target; 237, 238; 238, identifier:e; 239, block; 239, 240; 239, 247; 239, 257; 239, 264; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:log; 244, identifier:error; 245, argument_list; 245, 246; 246, string:"Couldn't validate fingerprint for ssh connection."; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:log; 251, identifier:error; 252, argument_list; 252, 253; 253, call; 253, 254; 253, 255; 254, identifier:unicode; 255, argument_list; 255, 256; 256, identifier:e; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:log; 261, identifier:error; 262, argument_list; 262, 263; 263, string:"Is the instance finished starting up?"; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:sys; 268, identifier:exit; 269, argument_list; 269, 270; 270, integer:1; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:client; 274, subscript; 274, 275; 274, 276; 275, identifier:ssh_info; 276, string:'client'; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 288; 279, attribute; 279, 280; 279, 287; 280, attribute; 280, 281; 280, 286; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:client; 284, identifier:get_transport; 285, argument_list; 286, identifier:sock; 287, identifier:close; 288, argument_list; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:client; 293, identifier:close; 294, argument_list; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 305; 297, subscript; 297, 298; 297, 299; 298, identifier:argv; 299, slice; 299, 300; 299, 301; 299, 302; 300, identifier:sid_index; 301, colon; 302, binary_operator:+; 302, 303; 302, 304; 303, identifier:sid_index; 304, integer:1; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:instance; 308, identifier:ssh_args_from_info; 309, argument_list; 309, 310; 310, identifier:ssh_info; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 319; 313, subscript; 313, 314; 313, 315; 314, identifier:argv; 315, slice; 315, 316; 315, 317; 315, 318; 316, integer:0; 317, colon; 318, integer:0; 319, list:['ssh']; 319, 320; 320, string:'ssh'; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:os; 325, identifier:execvp; 326, argument_list; 326, 327; 326, 328; 327, string:'ssh'; 328, identifier:argv
def cmd_ssh(self, argv, help): parser = argparse.ArgumentParser( prog="%s ssh" % self.progname, description=help, ) instances = self.get_instances(command='init_ssh_key') parser.add_argument("instance", nargs=1, metavar="instance", help="Name of the instance from the config.", choices=sorted(instances)) parser.add_argument("...", nargs=argparse.REMAINDER, help="ssh options") iargs = enumerate(argv) sid_index = None user = None for i, arg in iargs: if not arg.startswith('-'): sid_index = i break if arg[1] in '1246AaCfgKkMNnqsTtVvXxYy': continue elif arg[1] in 'bcDeFiLlmOopRSw': value = iargs.next() if arg[1] == 'l': user = value[1] continue if sid_index is None: parser.parse_args([]) else: sid = argv[sid_index] if '@' in sid: user, sid = sid.split('@', 1) parser.parse_args([sid]) instance = instances[sid] if user is None: user = instance.config.get('user') try: ssh_info = instance.init_ssh_key(user=user) except (instance.paramiko.SSHException, socket.error) as e: log.error("Couldn't validate fingerprint for ssh connection.") log.error(unicode(e)) log.error("Is the instance finished starting up?") sys.exit(1) client = ssh_info['client'] client.get_transport().sock.close() client.close() argv[sid_index:sid_index + 1] = instance.ssh_args_from_info(ssh_info) argv[0:0] = ['ssh'] os.execvp('ssh', argv)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 9; 2, function_name:add_alignment; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:ref_seq; 6, identifier:annotation; 7, type; 7, 8; 8, identifier:Annotation; 9, block; 9, 10; 9, 17; 9, 21; 9, 34; 9, 52; 9, 425; 9, 431; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:seq_features; 13, call; 13, 14; 13, 15; 14, identifier:get_seqs; 15, argument_list; 15, 16; 16, identifier:ref_seq; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:annoated_align; 20, dictionary; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:allele; 24, subscript; 24, 25; 24, 33; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:ref_seq; 29, identifier:description; 30, identifier:split; 31, argument_list; 31, 32; 32, string:","; 33, integer:0; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:locus; 37, subscript; 37, 38; 37, 51; 38, call; 38, 39; 38, 49; 39, attribute; 39, 40; 39, 48; 40, subscript; 40, 41; 40, 47; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:allele; 44, identifier:split; 45, argument_list; 45, 46; 46, string:"*"; 47, integer:0; 48, identifier:split; 49, argument_list; 49, 50; 50, string:"-"; 51, integer:1; 52, for_statement; 52, 53; 52, 54; 52, 55; 53, identifier:feat; 54, identifier:seq_features; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 62; 56, 392; 57, comparison_operator:in; 57, 58; 57, 59; 58, identifier:feat; 59, attribute; 59, 60; 59, 61; 60, identifier:annotation; 61, identifier:annotation; 62, block; 62, 63; 62, 124; 63, if_statement; 63, 64; 63, 73; 63, 97; 64, call; 64, 65; 64, 66; 65, identifier:isinstance; 66, argument_list; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:annotation; 70, identifier:annotation; 71, identifier:feat; 72, identifier:DBSeq; 73, block; 73, 74; 73, 88; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:seq_len; 77, call; 77, 78; 77, 79; 78, identifier:len; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:str; 82, argument_list; 82, 83; 83, subscript; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:annotation; 86, identifier:annotation; 87, identifier:feat; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:ref_len; 91, call; 91, 92; 91, 93; 92, identifier:len; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:seq_features; 96, identifier:feat; 97, else_clause; 97, 98; 98, block; 98, 99; 98, 115; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:seq_len; 102, call; 102, 103; 102, 104; 103, identifier:len; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:str; 107, argument_list; 107, 108; 108, attribute; 108, 109; 108, 114; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:annotation; 112, identifier:annotation; 113, identifier:feat; 114, identifier:seq; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:ref_len; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:seq_features; 123, identifier:feat; 124, if_statement; 124, 125; 124, 128; 124, 281; 125, comparison_operator:==; 125, 126; 125, 127; 126, identifier:seq_len; 127, identifier:ref_len; 128, block; 128, 129; 128, 142; 128, 158; 128, 233; 128, 262; 128, 271; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:seq; 132, call; 132, 133; 132, 134; 133, identifier:list; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 141; 136, subscript; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:annotation; 139, identifier:annotation; 140, identifier:feat; 141, identifier:seq; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:gaps; 145, subscript; 145, 146; 145, 157; 146, subscript; 146, 147; 146, 156; 147, subscript; 147, 148; 147, 155; 148, subscript; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:refdata; 153, identifier:annoated_alignments; 154, identifier:locus; 155, identifier:allele; 156, identifier:feat; 157, string:'Gaps'; 158, if_statement; 158, 159; 158, 168; 159, boolean_operator:and; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:verbose; 163, comparison_operator:>; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:verbosity; 167, integer:0; 168, block; 168, 169; 168, 184; 168, 199; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:logger; 175, identifier:info; 176, argument_list; 176, 177; 177, binary_operator:+; 177, 178; 177, 183; 178, binary_operator:+; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:logname; 182, string:" Lengths match for "; 183, identifier:feat; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:logger; 190, identifier:info; 191, argument_list; 191, 192; 192, binary_operator:+; 192, 193; 192, 198; 193, binary_operator:+; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:logname; 197, string:" Gaps at "; 198, identifier:feat; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:logger; 205, identifier:info; 206, argument_list; 206, 207; 207, binary_operator:+; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:logname; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, string:"-"; 214, identifier:join; 215, argument_list; 215, 216; 216, list_comprehension; 216, 217; 216, 230; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, string:","; 220, identifier:join; 221, argument_list; 221, 222; 222, list_comprehension; 222, 223; 222, 227; 223, call; 223, 224; 223, 225; 224, identifier:str; 225, argument_list; 225, 226; 226, identifier:s; 227, for_in_clause; 227, 228; 227, 229; 228, identifier:s; 229, identifier:g; 230, for_in_clause; 230, 231; 230, 232; 231, identifier:g; 232, identifier:gaps; 233, for_statement; 233, 234; 233, 235; 233, 243; 234, identifier:i; 235, call; 235, 236; 235, 237; 236, identifier:range; 237, argument_list; 237, 238; 237, 239; 238, integer:0; 239, call; 239, 240; 239, 241; 240, identifier:len; 241, argument_list; 241, 242; 242, identifier:gaps; 243, block; 243, 244; 244, for_statement; 244, 245; 244, 246; 244, 249; 245, identifier:j; 246, subscript; 246, 247; 246, 248; 247, identifier:gaps; 248, identifier:i; 249, block; 249, 250; 249, 254; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:loc; 253, identifier:j; 254, expression_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:seq; 258, identifier:insert; 259, argument_list; 259, 260; 259, 261; 260, identifier:loc; 261, string:'-'; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:nseq; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, string:''; 268, identifier:join; 269, argument_list; 269, 270; 270, identifier:seq; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:annoated_align; 275, identifier:update; 276, argument_list; 276, 277; 277, dictionary; 277, 278; 278, pair; 278, 279; 278, 280; 279, identifier:feat; 280, identifier:nseq; 281, else_clause; 281, 282; 282, block; 282, 283; 282, 296; 282, 312; 282, 324; 282, 378; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:in_seq; 286, call; 286, 287; 286, 288; 287, identifier:str; 288, argument_list; 288, 289; 289, attribute; 289, 290; 289, 295; 290, subscript; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:annotation; 293, identifier:annotation; 294, identifier:feat; 295, identifier:seq; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:ref_seq; 299, subscript; 299, 300; 299, 311; 300, subscript; 300, 301; 300, 310; 301, subscript; 301, 302; 301, 309; 302, subscript; 302, 303; 302, 308; 303, attribute; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:refdata; 307, identifier:annoated_alignments; 308, identifier:locus; 309, identifier:allele; 310, identifier:feat; 311, string:'Seq'; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:alignment; 315, call; 315, 316; 315, 321; 316, attribute; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:pairwise2; 319, identifier:align; 320, identifier:globalxx; 321, argument_list; 321, 322; 321, 323; 322, identifier:in_seq; 323, identifier:ref_seq; 324, if_statement; 324, 325; 324, 334; 325, boolean_operator:and; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:self; 328, identifier:verbose; 329, comparison_operator:>; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:verbosity; 333, integer:0; 334, block; 334, 335; 334, 350; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 342; 337, attribute; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:logger; 341, identifier:info; 342, argument_list; 342, 343; 343, binary_operator:+; 343, 344; 343, 349; 344, binary_operator:+; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:self; 347, identifier:logname; 348, string:" Align2 -> in_seq != ref_len "; 349, identifier:feat; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 357; 352, attribute; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:logger; 356, identifier:info; 357, argument_list; 357, 358; 358, binary_operator:+; 358, 359; 358, 374; 359, binary_operator:+; 359, 360; 359, 373; 360, binary_operator:+; 360, 361; 360, 366; 361, binary_operator:+; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:logname; 365, string:" "; 366, call; 366, 367; 366, 368; 367, identifier:str; 368, argument_list; 368, 369; 369, call; 369, 370; 369, 371; 370, identifier:len; 371, argument_list; 371, 372; 372, identifier:in_seq; 373, string:" == "; 374, call; 374, 375; 374, 376; 375, identifier:str; 376, argument_list; 376, 377; 377, identifier:ref_len; 378, expression_statement; 378, 379; 379, call; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:annoated_align; 382, identifier:update; 383, argument_list; 383, 384; 384, dictionary; 384, 385; 385, pair; 385, 386; 385, 387; 386, identifier:feat; 387, subscript; 387, 388; 387, 391; 388, subscript; 388, 389; 388, 390; 389, identifier:alignment; 390, integer:0; 391, integer:0; 392, else_clause; 392, 393; 393, block; 393, 394; 393, 415; 394, expression_statement; 394, 395; 395, assignment; 395, 396; 395, 397; 396, identifier:nseq; 397, call; 397, 398; 397, 401; 398, attribute; 398, 399; 398, 400; 399, string:''; 400, identifier:join; 401, argument_list; 401, 402; 402, call; 402, 403; 402, 404; 403, identifier:list; 404, argument_list; 404, 405; 405, call; 405, 406; 405, 407; 406, identifier:repeat; 407, argument_list; 407, 408; 407, 409; 408, string:'-'; 409, call; 409, 410; 409, 411; 410, identifier:len; 411, argument_list; 411, 412; 412, subscript; 412, 413; 412, 414; 413, identifier:seq_features; 414, identifier:feat; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 420; 417, attribute; 417, 418; 417, 419; 418, identifier:annoated_align; 419, identifier:update; 420, argument_list; 420, 421; 421, dictionary; 421, 422; 422, pair; 422, 423; 422, 424; 423, identifier:feat; 424, identifier:nseq; 425, expression_statement; 425, 426; 426, assignment; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:annotation; 429, identifier:aligned; 430, identifier:annoated_align; 431, return_statement; 431, 432; 432, identifier:annotation
def add_alignment(self, ref_seq, annotation) -> Annotation: seq_features = get_seqs(ref_seq) annoated_align = {} allele = ref_seq.description.split(",")[0] locus = allele.split("*")[0].split("-")[1] for feat in seq_features: if feat in annotation.annotation: if isinstance(annotation.annotation[feat], DBSeq): seq_len = len(str(annotation.annotation[feat])) ref_len = len(seq_features[feat]) else: seq_len = len(str(annotation.annotation[feat].seq)) ref_len = len(seq_features[feat]) if seq_len == ref_len: seq = list(annotation.annotation[feat].seq) gaps = self.refdata.annoated_alignments[locus][allele][feat]['Gaps'] if self.verbose and self.verbosity > 0: self.logger.info(self.logname + " Lengths match for " + feat) self.logger.info(self.logname + " Gaps at " + feat) self.logger.info(self.logname + "-".join([",".join([str(s) for s in g]) for g in gaps])) for i in range(0, len(gaps)): for j in gaps[i]: loc = j seq.insert(loc, '-') nseq = ''.join(seq) annoated_align.update({feat: nseq}) else: in_seq = str(annotation.annotation[feat].seq) ref_seq = self.refdata.annoated_alignments[locus][allele][feat]['Seq'] alignment = pairwise2.align.globalxx(in_seq, ref_seq) if self.verbose and self.verbosity > 0: self.logger.info(self.logname + " Align2 -> in_seq != ref_len " + feat) self.logger.info(self.logname + " " + str(len(in_seq)) + " == " + str(ref_len)) annoated_align.update({feat: alignment[0][0]}) else: nseq = ''.join(list(repeat('-', len(seq_features[feat])))) annoated_align.update({feat: nseq}) annotation.aligned = annoated_align return annotation
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:build_tree; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:data; 6, identifier:tagname; 7, default_parameter; 7, 8; 7, 9; 8, identifier:attrs; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:depth; 12, integer:0; 13, block; 13, 14; 13, 16; 13, 25; 13, 46; 14, expression_statement; 14, 15; 15, identifier:r; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:data; 19, None; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:data; 24, string:''; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:indent; 28, conditional_expression:if; 28, 29; 28, 40; 28, 45; 29, parenthesized_expression; 29, 30; 30, binary_operator:%; 30, 31; 30, 32; 31, string:'\n%s'; 32, parenthesized_expression; 32, 33; 33, binary_operator:*; 33, 34; 33, 39; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:__options; 38, string:'indent'; 39, identifier:depth; 40, subscript; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:__options; 44, string:'indent'; 45, string:''; 46, if_statement; 46, 47; 46, 54; 46, 229; 46, 251; 47, call; 47, 48; 47, 49; 48, identifier:isinstance; 49, argument_list; 49, 50; 49, 51; 50, identifier:data; 51, attribute; 51, 52; 51, 53; 52, identifier:utils; 53, identifier:DictTypes; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 72; 55, 94; 56, boolean_operator:and; 56, 57; 56, 62; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:__options; 61, string:'hasattr'; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:check_structure; 66, argument_list; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:data; 70, identifier:keys; 71, argument_list; 72, block; 72, 73; 72, 84; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, pattern_list; 75, 76; 75, 77; 76, identifier:attrs; 77, identifier:values; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:pickdata; 82, argument_list; 82, 83; 83, identifier:data; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:build_tree; 89, argument_list; 89, 90; 89, 91; 89, 92; 89, 93; 90, identifier:values; 91, identifier:tagname; 92, identifier:attrs; 93, identifier:depth; 94, else_clause; 94, 95; 95, block; 95, 96; 95, 115; 95, 123; 95, 152; 95, 211; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:__tree; 102, identifier:append; 103, argument_list; 103, 104; 104, binary_operator:%; 104, 105; 104, 106; 105, string:'%s%s'; 106, tuple; 106, 107; 106, 108; 107, identifier:indent; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:tag_start; 112, argument_list; 112, 113; 112, 114; 113, identifier:tagname; 114, identifier:attrs; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:iter; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:data; 121, identifier:iteritems; 122, argument_list; 123, if_statement; 123, 124; 123, 129; 124, subscript; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:__options; 128, string:'ksort'; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:iter; 133, call; 133, 134; 133, 135; 134, identifier:sorted; 135, argument_list; 135, 136; 135, 137; 135, 145; 136, identifier:iter; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:key; 139, lambda; 139, 140; 139, 142; 140, lambda_parameters; 140, 141; 141, identifier:x; 142, subscript; 142, 143; 142, 144; 143, identifier:x; 144, integer:0; 145, keyword_argument; 145, 146; 145, 147; 146, identifier:reverse; 147, subscript; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:__options; 151, string:'reverse'; 152, for_statement; 152, 153; 152, 156; 152, 157; 153, pattern_list; 153, 154; 153, 155; 154, identifier:k; 155, identifier:v; 156, identifier:iter; 157, block; 157, 158; 157, 162; 157, 199; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:attrs; 161, dictionary; 162, if_statement; 162, 163; 162, 187; 163, boolean_operator:and; 163, 164; 163, 177; 164, boolean_operator:and; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:__options; 169, string:'hasattr'; 170, call; 170, 171; 170, 172; 171, identifier:isinstance; 172, argument_list; 172, 173; 172, 174; 173, identifier:v; 174, attribute; 174, 175; 174, 176; 175, identifier:utils; 176, identifier:DictTypes; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:check_structure; 181, argument_list; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:v; 185, identifier:keys; 186, argument_list; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, pattern_list; 190, 191; 190, 192; 191, identifier:attrs; 192, identifier:v; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:pickdata; 197, argument_list; 197, 198; 198, identifier:v; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:build_tree; 204, argument_list; 204, 205; 204, 206; 204, 207; 204, 208; 205, identifier:v; 206, identifier:k; 207, identifier:attrs; 208, binary_operator:+; 208, 209; 208, 210; 209, identifier:depth; 210, integer:1; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:__tree; 217, identifier:append; 218, argument_list; 218, 219; 219, binary_operator:%; 219, 220; 219, 221; 220, string:'%s%s'; 221, tuple; 221, 222; 221, 223; 222, identifier:indent; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:tag_end; 227, argument_list; 227, 228; 228, identifier:tagname; 229, elif_clause; 229, 230; 229, 236; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:utils; 233, identifier:is_iterable; 234, argument_list; 234, 235; 235, identifier:data; 236, block; 236, 237; 237, for_statement; 237, 238; 237, 239; 237, 240; 238, identifier:v; 239, identifier:data; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:build_tree; 246, argument_list; 246, 247; 246, 248; 246, 249; 246, 250; 247, identifier:v; 248, identifier:tagname; 249, identifier:attrs; 250, identifier:depth; 251, else_clause; 251, 252; 252, block; 252, 253; 252, 262; 252, 276; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:__tree; 259, identifier:append; 260, argument_list; 260, 261; 261, identifier:indent; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:data; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:safedata; 269, argument_list; 269, 270; 269, 271; 270, identifier:data; 271, subscript; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:__options; 275, string:'cdata'; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 283; 278, attribute; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:__tree; 282, identifier:append; 283, argument_list; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:build_tag; 288, argument_list; 288, 289; 288, 290; 288, 291; 289, identifier:tagname; 290, identifier:data; 291, identifier:attrs
def build_tree(self, data, tagname, attrs=None, depth=0): r if data is None: data = '' indent = ('\n%s' % (self.__options['indent'] * depth)) if self.__options['indent'] else '' if isinstance(data, utils.DictTypes): if self.__options['hasattr'] and self.check_structure(data.keys()): attrs, values = self.pickdata(data) self.build_tree(values, tagname, attrs, depth) else: self.__tree.append('%s%s' % (indent, self.tag_start(tagname, attrs))) iter = data.iteritems() if self.__options['ksort']: iter = sorted(iter, key=lambda x:x[0], reverse=self.__options['reverse']) for k, v in iter: attrs = {} if self.__options['hasattr'] and isinstance(v, utils.DictTypes) and self.check_structure(v.keys()): attrs, v = self.pickdata(v) self.build_tree(v, k, attrs, depth+1) self.__tree.append('%s%s' % (indent, self.tag_end(tagname))) elif utils.is_iterable(data): for v in data: self.build_tree(v, tagname, attrs, depth) else: self.__tree.append(indent) data = self.safedata(data, self.__options['cdata']) self.__tree.append(self.build_tag(tagname, data, attrs))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_parse_remind; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:filename; 6, default_parameter; 6, 7; 6, 8; 7, identifier:lines; 8, string:''; 9, block; 9, 10; 9, 14; 9, 18; 9, 37; 9, 58; 9, 107; 9, 115; 9, 278; 9, 344; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:files; 13, dictionary; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:reminders; 17, dictionary; 18, if_statement; 18, 19; 18, 20; 19, identifier:lines; 20, block; 20, 21; 20, 25; 20, 31; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:filename; 24, string:'-'; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, subscript; 27, 28; 27, 29; 28, identifier:files; 29, identifier:filename; 30, identifier:lines; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, subscript; 33, 34; 33, 35; 34, identifier:reminders; 35, identifier:filename; 36, dictionary; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:cmd; 40, list:['remind', '-l', '-s%d' % self._month, '-b1', '-y', '-r', filename, str(self._startdate)]; 40, 41; 40, 42; 40, 43; 40, 48; 40, 49; 40, 50; 40, 51; 40, 52; 41, string:'remind'; 42, string:'-l'; 43, binary_operator:%; 43, 44; 43, 45; 44, string:'-s%d'; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_month; 48, string:'-b1'; 49, string:'-y'; 50, string:'-r'; 51, identifier:filename; 52, call; 52, 53; 52, 54; 53, identifier:str; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_startdate; 58, try_statement; 58, 59; 58, 92; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:rem; 63, call; 63, 64; 63, 90; 64, attribute; 64, 65; 64, 89; 65, subscript; 65, 66; 65, 88; 66, call; 66, 67; 66, 79; 67, attribute; 67, 68; 67, 78; 68, call; 68, 69; 68, 70; 69, identifier:Popen; 70, argument_list; 70, 71; 70, 72; 70, 75; 71, identifier:cmd; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:stdin; 74, identifier:PIPE; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:stdout; 77, identifier:PIPE; 78, identifier:communicate; 79, argument_list; 79, 80; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:input; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:lines; 85, identifier:encode; 86, argument_list; 86, 87; 87, string:'utf-8'; 88, integer:0; 89, identifier:decode; 90, argument_list; 90, 91; 91, string:'utf-8'; 92, except_clause; 92, 93; 92, 94; 93, identifier:OSError; 94, block; 94, 95; 95, raise_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:OSError; 98, argument_list; 98, 99; 99, binary_operator:%; 99, 100; 99, 101; 100, string:'Error running: %s'; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, string:' '; 104, identifier:join; 105, argument_list; 105, 106; 106, identifier:cmd; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:rem; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:rem; 113, identifier:splitlines; 114, argument_list; 115, for_statement; 115, 116; 115, 119; 115, 135; 116, tuple_pattern; 116, 117; 116, 118; 117, identifier:fileinfo; 118, identifier:line; 119, call; 119, 120; 119, 121; 120, identifier:zip; 121, argument_list; 121, 122; 121, 128; 122, subscript; 122, 123; 122, 124; 123, identifier:rem; 124, slice; 124, 125; 124, 126; 124, 127; 125, colon; 126, colon; 127, integer:2; 128, subscript; 128, 129; 128, 130; 129, identifier:rem; 130, slice; 130, 131; 130, 132; 130, 133; 130, 134; 131, integer:1; 132, colon; 133, colon; 134, integer:2; 135, block; 135, 136; 135, 144; 135, 150; 135, 194; 135, 209; 135, 219; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:fileinfo; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:fileinfo; 142, identifier:split; 143, argument_list; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:src_filename; 147, subscript; 147, 148; 147, 149; 148, identifier:fileinfo; 149, integer:3; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:not; 151, 152; 151, 153; 152, identifier:src_filename; 153, identifier:files; 154, block; 154, 155; 154, 168; 154, 174; 154, 181; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:files; 159, identifier:src_filename; 160, call; 160, 161; 160, 167; 161, attribute; 161, 162; 161, 166; 162, call; 162, 163; 162, 164; 163, identifier:open; 164, argument_list; 164, 165; 165, identifier:src_filename; 166, identifier:readlines; 167, argument_list; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:reminders; 172, identifier:src_filename; 173, dictionary; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:mtime; 177, call; 177, 178; 177, 179; 178, identifier:getmtime; 179, argument_list; 179, 180; 180, identifier:src_filename; 181, if_statement; 181, 182; 181, 187; 182, comparison_operator:>; 182, 183; 182, 184; 183, identifier:mtime; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:_mtime; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:_mtime; 193, identifier:mtime; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:text; 197, subscript; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:files; 200, identifier:src_filename; 201, binary_operator:-; 201, 202; 201, 208; 202, call; 202, 203; 202, 204; 203, identifier:int; 204, argument_list; 204, 205; 205, subscript; 205, 206; 205, 207; 206, identifier:fileinfo; 207, integer:2; 208, integer:1; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:event; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:_parse_remind_line; 216, argument_list; 216, 217; 216, 218; 217, identifier:line; 218, identifier:text; 219, if_statement; 219, 220; 219, 227; 219, 254; 220, comparison_operator:in; 220, 221; 220, 224; 221, subscript; 221, 222; 221, 223; 222, identifier:event; 223, string:'uid'; 224, subscript; 224, 225; 224, 226; 225, identifier:reminders; 226, identifier:src_filename; 227, block; 227, 228; 227, 242; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 239; 230, subscript; 230, 231; 230, 238; 231, subscript; 231, 232; 231, 235; 232, subscript; 232, 233; 232, 234; 233, identifier:reminders; 234, identifier:src_filename; 235, subscript; 235, 236; 235, 237; 236, identifier:event; 237, string:'uid'; 238, string:'dtstart'; 239, subscript; 239, 240; 239, 241; 240, identifier:event; 241, string:'dtstart'; 242, expression_statement; 242, 243; 243, augmented_assignment:+=; 243, 244; 243, 253; 244, subscript; 244, 245; 244, 252; 245, subscript; 245, 246; 245, 249; 246, subscript; 246, 247; 246, 248; 247, identifier:reminders; 248, identifier:src_filename; 249, subscript; 249, 250; 249, 251; 250, identifier:event; 251, string:'uid'; 252, string:'line'; 253, identifier:line; 254, else_clause; 254, 255; 255, block; 255, 256; 255, 266; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 265; 258, subscript; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:reminders; 261, identifier:src_filename; 262, subscript; 262, 263; 262, 264; 263, identifier:event; 264, string:'uid'; 265, identifier:event; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 277; 268, subscript; 268, 269; 268, 276; 269, subscript; 269, 270; 269, 273; 270, subscript; 270, 271; 270, 272; 271, identifier:reminders; 272, identifier:src_filename; 273, subscript; 273, 274; 273, 275; 274, identifier:event; 275, string:'uid'; 276, string:'line'; 277, identifier:line; 278, for_statement; 278, 279; 278, 280; 278, 285; 279, identifier:source; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:files; 283, identifier:values; 284, argument_list; 285, block; 285, 286; 286, for_statement; 286, 287; 286, 288; 286, 289; 287, identifier:line; 288, identifier:source; 289, block; 289, 290; 290, if_statement; 290, 291; 290, 297; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:line; 294, identifier:startswith; 295, argument_list; 295, 296; 296, string:'include'; 297, block; 297, 298; 297, 313; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:new_file; 301, call; 301, 302; 301, 312; 302, attribute; 302, 303; 302, 311; 303, subscript; 303, 304; 303, 310; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:line; 307, identifier:split; 308, argument_list; 308, 309; 309, string:' '; 310, integer:1; 311, identifier:strip; 312, argument_list; 313, if_statement; 313, 314; 313, 317; 314, comparison_operator:not; 314, 315; 314, 316; 315, identifier:new_file; 316, identifier:reminders; 317, block; 317, 318; 317, 324; 317, 331; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 323; 320, subscript; 320, 321; 320, 322; 321, identifier:reminders; 322, identifier:new_file; 323, dictionary; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:mtime; 327, call; 327, 328; 327, 329; 328, identifier:getmtime; 329, argument_list; 329, 330; 330, identifier:new_file; 331, if_statement; 331, 332; 331, 337; 332, comparison_operator:>; 332, 333; 332, 334; 333, identifier:mtime; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:_mtime; 337, block; 337, 338; 338, expression_statement; 338, 339; 339, assignment; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:self; 342, identifier:_mtime; 343, identifier:mtime; 344, return_statement; 344, 345; 345, identifier:reminders
def _parse_remind(self, filename, lines=''): files = {} reminders = {} if lines: filename = '-' files[filename] = lines reminders[filename] = {} cmd = ['remind', '-l', '-s%d' % self._month, '-b1', '-y', '-r', filename, str(self._startdate)] try: rem = Popen(cmd, stdin=PIPE, stdout=PIPE).communicate(input=lines.encode('utf-8'))[0].decode('utf-8') except OSError: raise OSError('Error running: %s' % ' '.join(cmd)) rem = rem.splitlines() for (fileinfo, line) in zip(rem[::2], rem[1::2]): fileinfo = fileinfo.split() src_filename = fileinfo[3] if src_filename not in files: files[src_filename] = open(src_filename).readlines() reminders[src_filename] = {} mtime = getmtime(src_filename) if mtime > self._mtime: self._mtime = mtime text = files[src_filename][int(fileinfo[2]) - 1] event = self._parse_remind_line(line, text) if event['uid'] in reminders[src_filename]: reminders[src_filename][event['uid']]['dtstart'] += event['dtstart'] reminders[src_filename][event['uid']]['line'] += line else: reminders[src_filename][event['uid']] = event reminders[src_filename][event['uid']]['line'] = line for source in files.values(): for line in source: if line.startswith('include'): new_file = line.split(' ')[1].strip() if new_file not in reminders: reminders[new_file] = {} mtime = getmtime(new_file) if mtime > self._mtime: self._mtime = mtime return reminders
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_parse_remind_line; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:line; 6, identifier:text; 7, block; 7, 8; 7, 12; 7, 22; 7, 40; 7, 132; 7, 154; 7, 174; 7, 203; 7, 219; 7, 230; 7, 237; 7, 257; 7, 276; 7, 295; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:event; 11, dictionary; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:line; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:line; 18, identifier:split; 19, argument_list; 19, 20; 19, 21; 20, None; 21, integer:6; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:dat; 25, list_comprehension; 25, 26; 25, 30; 26, call; 26, 27; 26, 28; 27, identifier:int; 28, argument_list; 28, 29; 29, identifier:f; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:f; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, subscript; 34, 35; 34, 36; 35, identifier:line; 36, integer:0; 37, identifier:split; 38, argument_list; 38, 39; 39, string:'/'; 40, if_statement; 40, 41; 40, 46; 40, 112; 41, comparison_operator:!=; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:line; 44, integer:4; 45, string:'*'; 46, block; 46, 47; 46, 60; 46, 89; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:start; 50, call; 50, 51; 50, 52; 51, identifier:divmod; 52, argument_list; 52, 53; 52, 59; 53, call; 53, 54; 53, 55; 54, identifier:int; 55, argument_list; 55, 56; 56, subscript; 56, 57; 56, 58; 57, identifier:line; 58, integer:4; 59, integer:60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:event; 64, string:'dtstart'; 65, list:[datetime(dat[0], dat[1], dat[2], start[0], start[1], tzinfo=self._localtz)]; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:datetime; 68, argument_list; 68, 69; 68, 72; 68, 75; 68, 78; 68, 81; 68, 84; 69, subscript; 69, 70; 69, 71; 70, identifier:dat; 71, integer:0; 72, subscript; 72, 73; 72, 74; 73, identifier:dat; 74, integer:1; 75, subscript; 75, 76; 75, 77; 76, identifier:dat; 77, integer:2; 78, subscript; 78, 79; 78, 80; 79, identifier:start; 80, integer:0; 81, subscript; 81, 82; 81, 83; 82, identifier:start; 83, integer:1; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:tzinfo; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:_localtz; 89, if_statement; 89, 90; 89, 95; 90, comparison_operator:!=; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:line; 93, integer:3; 94, string:'*'; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:event; 100, string:'duration'; 101, call; 101, 102; 101, 103; 102, identifier:timedelta; 103, argument_list; 103, 104; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:minutes; 106, call; 106, 107; 106, 108; 107, identifier:int; 108, argument_list; 108, 109; 109, subscript; 109, 110; 109, 111; 110, identifier:line; 111, integer:3; 112, else_clause; 112, 113; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, subscript; 116, 117; 116, 118; 117, identifier:event; 118, string:'dtstart'; 119, list:[date(dat[0], dat[1], dat[2])]; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:date; 122, argument_list; 122, 123; 122, 126; 122, 129; 123, subscript; 123, 124; 123, 125; 124, identifier:dat; 125, integer:0; 126, subscript; 126, 127; 126, 128; 127, identifier:dat; 128, integer:1; 129, subscript; 129, 130; 129, 131; 130, identifier:dat; 131, integer:2; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:msg; 135, conditional_expression:if; 135, 136; 135, 146; 135, 151; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, string:' '; 139, identifier:join; 140, argument_list; 140, 141; 141, subscript; 141, 142; 141, 143; 142, identifier:line; 143, slice; 143, 144; 143, 145; 144, integer:5; 145, colon; 146, comparison_operator:==; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:line; 149, integer:4; 150, string:'*'; 151, subscript; 151, 152; 151, 153; 152, identifier:line; 153, integer:6; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:msg; 157, call; 157, 158; 157, 171; 158, attribute; 158, 159; 158, 170; 159, call; 159, 160; 159, 167; 160, attribute; 160, 161; 160, 166; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:msg; 164, identifier:strip; 165, argument_list; 166, identifier:replace; 167, argument_list; 167, 168; 167, 169; 168, string:'%_'; 169, string:'\n'; 170, identifier:replace; 171, argument_list; 171, 172; 171, 173; 172, string:'["["]'; 173, string:'['; 174, if_statement; 174, 175; 174, 178; 174, 195; 175, comparison_operator:in; 175, 176; 175, 177; 176, string:' at '; 177, identifier:msg; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 188; 181, tuple_pattern; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:event; 184, string:'msg'; 185, subscript; 185, 186; 185, 187; 186, identifier:event; 187, string:'location'; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:msg; 191, identifier:rsplit; 192, argument_list; 192, 193; 192, 194; 193, string:' at '; 194, integer:1; 195, else_clause; 195, 196; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:event; 201, string:'msg'; 202, identifier:msg; 203, if_statement; 203, 204; 203, 207; 204, comparison_operator:in; 204, 205; 204, 206; 205, string:'%"'; 206, identifier:text; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, subscript; 210, 211; 210, 212; 211, identifier:event; 212, string:'description'; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:Remind; 216, identifier:_gen_description; 217, argument_list; 217, 218; 218, identifier:text; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:tags; 222, call; 222, 223; 222, 228; 223, attribute; 223, 224; 223, 227; 224, subscript; 224, 225; 224, 226; 225, identifier:line; 226, integer:2; 227, identifier:split; 228, argument_list; 228, 229; 229, string:','; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:classes; 233, list:['PUBLIC', 'PRIVATE', 'CONFIDENTIAL']; 233, 234; 233, 235; 233, 236; 234, string:'PUBLIC'; 235, string:'PRIVATE'; 236, string:'CONFIDENTIAL'; 237, for_statement; 237, 238; 237, 239; 237, 245; 238, identifier:tag; 239, subscript; 239, 240; 239, 241; 240, identifier:tags; 241, slice; 241, 242; 241, 243; 242, colon; 243, unary_operator:-; 243, 244; 244, integer:1; 245, block; 245, 246; 246, if_statement; 246, 247; 246, 250; 247, comparison_operator:in; 247, 248; 247, 249; 248, identifier:tag; 249, identifier:classes; 250, block; 250, 251; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 256; 253, subscript; 253, 254; 253, 255; 254, identifier:event; 255, string:'class'; 256, identifier:tag; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:event; 261, string:'categories'; 262, list_comprehension; 262, 263; 262, 264; 262, 272; 263, identifier:tag; 264, for_in_clause; 264, 265; 264, 266; 265, identifier:tag; 266, subscript; 266, 267; 266, 268; 267, identifier:tags; 268, slice; 268, 269; 268, 270; 269, colon; 270, unary_operator:-; 270, 271; 271, integer:1; 272, if_clause; 272, 273; 273, comparison_operator:not; 273, 274; 273, 275; 274, identifier:tag; 275, identifier:classes; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:event; 280, string:'uid'; 281, binary_operator:%; 281, 282; 281, 283; 282, string:'%s@%s'; 283, tuple; 283, 284; 283, 292; 284, subscript; 284, 285; 284, 289; 285, subscript; 285, 286; 285, 287; 286, identifier:tags; 287, unary_operator:-; 287, 288; 288, integer:1; 289, slice; 289, 290; 289, 291; 290, integer:7; 291, colon; 292, call; 292, 293; 292, 294; 293, identifier:getfqdn; 294, argument_list; 295, return_statement; 295, 296; 296, identifier:event
def _parse_remind_line(self, line, text): event = {} line = line.split(None, 6) dat = [int(f) for f in line[0].split('/')] if line[4] != '*': start = divmod(int(line[4]), 60) event['dtstart'] = [datetime(dat[0], dat[1], dat[2], start[0], start[1], tzinfo=self._localtz)] if line[3] != '*': event['duration'] = timedelta(minutes=int(line[3])) else: event['dtstart'] = [date(dat[0], dat[1], dat[2])] msg = ' '.join(line[5:]) if line[4] == '*' else line[6] msg = msg.strip().replace('%_', '\n').replace('["["]', '[') if ' at ' in msg: (event['msg'], event['location']) = msg.rsplit(' at ', 1) else: event['msg'] = msg if '%"' in text: event['description'] = Remind._gen_description(text) tags = line[2].split(',') classes = ['PUBLIC', 'PRIVATE', 'CONFIDENTIAL'] for tag in tags[:-1]: if tag in classes: event['class'] = tag event['categories'] = [tag for tag in tags[:-1] if tag not in classes] event['uid'] = '%s@%s' % (tags[-1][7:], getfqdn()) return event
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_gen_vevent; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:event; 6, identifier:vevent; 7, block; 7, 8; 7, 23; 7, 41; 7, 54; 7, 67; 7, 85; 7, 112; 7, 130; 7, 148; 7, 281; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 18; 10, attribute; 10, 11; 10, 17; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:vevent; 14, identifier:add; 15, argument_list; 15, 16; 16, string:'dtstart'; 17, identifier:value; 18, subscript; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:event; 21, string:'dtstart'; 22, integer:0; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 33; 25, attribute; 25, 26; 25, 32; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:vevent; 29, identifier:add; 30, argument_list; 30, 31; 31, string:'dtstamp'; 32, identifier:value; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:datetime; 36, identifier:fromtimestamp; 37, argument_list; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_mtime; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 51; 43, attribute; 43, 44; 43, 50; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:vevent; 47, identifier:add; 48, argument_list; 48, 49; 49, string:'summary'; 50, identifier:value; 51, subscript; 51, 52; 51, 53; 52, identifier:event; 53, string:'msg'; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 64; 56, attribute; 56, 57; 56, 63; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:vevent; 60, identifier:add; 61, argument_list; 61, 62; 62, string:'uid'; 63, identifier:value; 64, subscript; 64, 65; 64, 66; 65, identifier:event; 66, string:'uid'; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:in; 68, 69; 68, 70; 69, string:'class'; 70, identifier:event; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 82; 74, attribute; 74, 75; 74, 81; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:vevent; 78, identifier:add; 79, argument_list; 79, 80; 80, string:'class'; 81, identifier:value; 82, subscript; 82, 83; 82, 84; 83, identifier:event; 84, string:'class'; 85, if_statement; 85, 86; 85, 98; 86, boolean_operator:and; 86, 87; 86, 90; 87, comparison_operator:in; 87, 88; 87, 89; 88, string:'categories'; 89, identifier:event; 90, comparison_operator:>; 90, 91; 90, 97; 91, call; 91, 92; 91, 93; 92, identifier:len; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:event; 96, string:'categories'; 97, integer:0; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 109; 101, attribute; 101, 102; 101, 108; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:vevent; 105, identifier:add; 106, argument_list; 106, 107; 107, string:'categories'; 108, identifier:value; 109, subscript; 109, 110; 109, 111; 110, identifier:event; 111, string:'categories'; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:in; 113, 114; 113, 115; 114, string:'location'; 115, identifier:event; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 127; 119, attribute; 119, 120; 119, 126; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:vevent; 123, identifier:add; 124, argument_list; 124, 125; 125, string:'location'; 126, identifier:value; 127, subscript; 127, 128; 127, 129; 128, identifier:event; 129, string:'location'; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:in; 131, 132; 131, 133; 132, string:'description'; 133, identifier:event; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 145; 137, attribute; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:vevent; 141, identifier:add; 142, argument_list; 142, 143; 143, string:'description'; 144, identifier:value; 145, subscript; 145, 146; 145, 147; 146, identifier:event; 147, string:'description'; 148, if_statement; 148, 149; 148, 158; 148, 249; 149, call; 149, 150; 149, 151; 150, identifier:isinstance; 151, argument_list; 151, 152; 151, 157; 152, subscript; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:event; 155, string:'dtstart'; 156, integer:0; 157, identifier:datetime; 158, block; 158, 159; 158, 214; 159, if_statement; 159, 160; 159, 167; 160, comparison_operator:!=; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:_alarm; 164, call; 164, 165; 164, 166; 165, identifier:timedelta; 166, argument_list; 167, block; 167, 168; 167, 177; 167, 190; 167, 201; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:valarm; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:vevent; 174, identifier:add; 175, argument_list; 175, 176; 176, string:'valarm'; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 187; 179, attribute; 179, 180; 179, 186; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:valarm; 183, identifier:add; 184, argument_list; 184, 185; 185, string:'trigger'; 186, identifier:value; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_alarm; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 200; 192, attribute; 192, 193; 192, 199; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:valarm; 196, identifier:add; 197, argument_list; 197, 198; 198, string:'action'; 199, identifier:value; 200, string:'DISPLAY'; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 211; 203, attribute; 203, 204; 203, 210; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:valarm; 207, identifier:add; 208, argument_list; 208, 209; 209, string:'description'; 210, identifier:value; 211, subscript; 211, 212; 211, 213; 212, identifier:event; 213, string:'msg'; 214, if_statement; 214, 215; 214, 218; 214, 232; 215, comparison_operator:in; 215, 216; 215, 217; 216, string:'duration'; 217, identifier:event; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 229; 221, attribute; 221, 222; 221, 228; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:vevent; 225, identifier:add; 226, argument_list; 226, 227; 227, string:'duration'; 228, identifier:value; 229, subscript; 229, 230; 229, 231; 230, identifier:event; 231, string:'duration'; 232, else_clause; 232, 233; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 244; 236, attribute; 236, 237; 236, 243; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:vevent; 240, identifier:add; 241, argument_list; 241, 242; 242, string:'dtend'; 243, identifier:value; 244, subscript; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:event; 247, string:'dtstart'; 248, integer:0; 249, elif_clause; 249, 250; 249, 258; 250, comparison_operator:==; 250, 251; 250, 257; 251, call; 251, 252; 251, 253; 252, identifier:len; 253, argument_list; 253, 254; 254, subscript; 254, 255; 254, 256; 255, identifier:event; 256, string:'dtstart'; 257, integer:1; 258, block; 258, 259; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 269; 261, attribute; 261, 262; 261, 268; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:vevent; 265, identifier:add; 266, argument_list; 266, 267; 267, string:'dtend'; 268, identifier:value; 269, binary_operator:+; 269, 270; 269, 275; 270, subscript; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:event; 273, string:'dtstart'; 274, integer:0; 275, call; 275, 276; 275, 277; 276, identifier:timedelta; 277, argument_list; 277, 278; 278, keyword_argument; 278, 279; 278, 280; 279, identifier:days; 280, integer:1; 281, if_statement; 281, 282; 281, 290; 282, comparison_operator:>; 282, 283; 282, 289; 283, call; 283, 284; 283, 285; 284, identifier:len; 285, argument_list; 285, 286; 286, subscript; 286, 287; 286, 288; 287, identifier:event; 288, string:'dtstart'; 289, integer:1; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:Remind; 295, identifier:_gen_dtend_rrule; 296, argument_list; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:event; 299, string:'dtstart'; 300, identifier:vevent
def _gen_vevent(self, event, vevent): vevent.add('dtstart').value = event['dtstart'][0] vevent.add('dtstamp').value = datetime.fromtimestamp(self._mtime) vevent.add('summary').value = event['msg'] vevent.add('uid').value = event['uid'] if 'class' in event: vevent.add('class').value = event['class'] if 'categories' in event and len(event['categories']) > 0: vevent.add('categories').value = event['categories'] if 'location' in event: vevent.add('location').value = event['location'] if 'description' in event: vevent.add('description').value = event['description'] if isinstance(event['dtstart'][0], datetime): if self._alarm != timedelta(): valarm = vevent.add('valarm') valarm.add('trigger').value = self._alarm valarm.add('action').value = 'DISPLAY' valarm.add('description').value = event['msg'] if 'duration' in event: vevent.add('duration').value = event['duration'] else: vevent.add('dtend').value = event['dtstart'][0] elif len(event['dtstart']) == 1: vevent.add('dtend').value = event['dtstart'][0] + timedelta(days=1) if len(event['dtstart']) > 1: Remind._gen_dtend_rrule(event['dtstart'], vevent)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:to_remind; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:self; 5, identifier:vevent; 6, default_parameter; 6, 7; 6, 8; 7, identifier:label; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:priority; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:tags; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:tail; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:sep; 20, string:" "; 21, default_parameter; 21, 22; 21, 23; 22, identifier:postdate; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:posttime; 26, None; 27, block; 27, 28; 27, 33; 27, 37; 27, 55; 27, 63; 27, 85; 27, 89; 27, 104; 27, 126; 27, 159; 27, 169; 27, 181; 27, 195; 27, 204; 27, 257; 27, 320; 27, 357; 27, 383; 27, 404; 27, 437; 27, 452; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:remind; 31, list:['REM']; 31, 32; 32, string:'REM'; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:trigdates; 36, None; 37, if_statement; 37, 38; 37, 43; 38, call; 38, 39; 38, 40; 39, identifier:hasattr; 40, argument_list; 40, 41; 40, 42; 41, identifier:vevent; 42, string:'rrule'; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:trigdates; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:Remind; 50, identifier:_parse_rruleset; 51, argument_list; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:vevent; 54, identifier:rruleset; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:dtstart; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:vevent; 61, identifier:dtstart; 62, identifier:value; 63, if_statement; 63, 64; 63, 73; 64, boolean_operator:and; 64, 65; 64, 70; 65, call; 65, 66; 65, 67; 66, identifier:isinstance; 67, argument_list; 67, 68; 67, 69; 68, identifier:dtstart; 69, identifier:datetime; 70, attribute; 70, 71; 70, 72; 71, identifier:dtstart; 72, identifier:tzinfo; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:dtstart; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:dtstart; 80, identifier:astimezone; 81, argument_list; 81, 82; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:_localtz; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:dtend; 88, None; 89, if_statement; 89, 90; 89, 95; 90, call; 90, 91; 90, 92; 91, identifier:hasattr; 92, argument_list; 92, 93; 92, 94; 93, identifier:vevent; 94, string:'dtend'; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:dtend; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:vevent; 102, identifier:dtend; 103, identifier:value; 104, if_statement; 104, 105; 104, 114; 105, boolean_operator:and; 105, 106; 105, 111; 106, call; 106, 107; 106, 108; 107, identifier:isinstance; 108, argument_list; 108, 109; 108, 110; 109, identifier:dtend; 110, identifier:datetime; 111, attribute; 111, 112; 111, 113; 112, identifier:dtend; 113, identifier:tzinfo; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:dtend; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:dtend; 121, identifier:astimezone; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:_localtz; 126, if_statement; 126, 127; 126, 140; 127, boolean_operator:and; 127, 128; 127, 134; 128, not_operator; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:hasattr; 131, argument_list; 131, 132; 131, 133; 132, identifier:vevent; 133, string:'rdate'; 134, not_operator; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:isinstance; 137, argument_list; 137, 138; 137, 139; 138, identifier:trigdates; 139, identifier:str; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:remind; 145, identifier:append; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 156; 148, attribute; 148, 149; 148, 155; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:dtstart; 152, identifier:strftime; 153, argument_list; 153, 154; 154, string:'%b %d %Y'; 155, identifier:replace; 156, argument_list; 156, 157; 156, 158; 157, string:' 0'; 158, string:' '; 159, if_statement; 159, 160; 159, 161; 160, identifier:postdate; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:remind; 166, identifier:append; 167, argument_list; 167, 168; 168, identifier:postdate; 169, if_statement; 169, 170; 169, 171; 170, identifier:priority; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:remind; 176, identifier:append; 177, argument_list; 177, 178; 178, binary_operator:%; 178, 179; 178, 180; 179, string:'PRIORITY %s'; 180, identifier:priority; 181, if_statement; 181, 182; 181, 187; 182, call; 182, 183; 182, 184; 183, identifier:isinstance; 184, argument_list; 184, 185; 184, 186; 185, identifier:trigdates; 186, identifier:list; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:remind; 192, identifier:extend; 193, argument_list; 193, 194; 194, identifier:trigdates; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:duration; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:Remind; 201, identifier:_event_duration; 202, argument_list; 202, 203; 203, identifier:vevent; 204, if_statement; 204, 205; 204, 217; 205, boolean_operator:and; 205, 206; 205, 212; 206, comparison_operator:is; 206, 207; 206, 211; 207, call; 207, 208; 207, 209; 208, identifier:type; 209, argument_list; 209, 210; 210, identifier:dtstart; 211, identifier:date; 212, comparison_operator:>; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:duration; 215, identifier:days; 216, integer:1; 217, block; 217, 218; 217, 225; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:remind; 222, identifier:append; 223, argument_list; 223, 224; 224, string:'*1'; 225, if_statement; 225, 226; 225, 229; 226, comparison_operator:is; 226, 227; 226, 228; 227, identifier:dtend; 228, None; 229, block; 229, 230; 229, 239; 230, expression_statement; 230, 231; 231, augmented_assignment:-=; 231, 232; 231, 233; 232, identifier:dtend; 233, call; 233, 234; 233, 235; 234, identifier:timedelta; 235, argument_list; 235, 236; 236, keyword_argument; 236, 237; 236, 238; 237, identifier:days; 238, integer:1; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:remind; 243, identifier:append; 244, argument_list; 244, 245; 245, call; 245, 246; 245, 254; 246, attribute; 246, 247; 246, 253; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:dtend; 250, identifier:strftime; 251, argument_list; 251, 252; 252, string:'UNTIL %b %d %Y'; 253, identifier:replace; 254, argument_list; 254, 255; 254, 256; 255, string:' 0'; 256, string:' '; 257, if_statement; 257, 258; 257, 263; 258, call; 258, 259; 258, 260; 259, identifier:isinstance; 260, argument_list; 260, 261; 260, 262; 261, identifier:dtstart; 262, identifier:datetime; 263, block; 263, 264; 263, 282; 263, 292; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:remind; 268, identifier:append; 269, argument_list; 269, 270; 270, call; 270, 271; 270, 279; 271, attribute; 271, 272; 271, 278; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:dtstart; 275, identifier:strftime; 276, argument_list; 276, 277; 277, string:'AT %H:%M'; 278, identifier:replace; 279, argument_list; 279, 280; 279, 281; 280, string:' 0'; 281, string:' '; 282, if_statement; 282, 283; 282, 284; 283, identifier:posttime; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:remind; 289, identifier:append; 290, argument_list; 290, 291; 291, identifier:posttime; 292, if_statement; 292, 293; 292, 300; 293, comparison_operator:>; 293, 294; 293, 299; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:duration; 297, identifier:total_seconds; 298, argument_list; 299, integer:0; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:remind; 305, identifier:append; 306, argument_list; 306, 307; 307, binary_operator:%; 307, 308; 307, 309; 308, string:'DURATION %d:%02d'; 309, call; 309, 310; 309, 311; 310, identifier:divmod; 311, argument_list; 311, 312; 311, 319; 312, binary_operator:/; 312, 313; 312, 318; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:duration; 316, identifier:total_seconds; 317, argument_list; 318, integer:60; 319, integer:60; 320, if_statement; 320, 321; 320, 326; 320, 343; 321, call; 321, 322; 321, 323; 322, identifier:hasattr; 323, argument_list; 323, 324; 323, 325; 324, identifier:vevent; 325, string:'rdate'; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:remind; 331, identifier:append; 332, argument_list; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:Remind; 336, identifier:_parse_rdate; 337, argument_list; 337, 338; 338, attribute; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:vevent; 341, identifier:rdate; 342, identifier:value; 343, elif_clause; 343, 344; 343, 349; 344, call; 344, 345; 344, 346; 345, identifier:isinstance; 346, argument_list; 346, 347; 346, 348; 347, identifier:trigdates; 348, identifier:str; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:remind; 354, identifier:append; 355, argument_list; 355, 356; 356, identifier:trigdates; 357, if_statement; 357, 358; 357, 363; 358, call; 358, 359; 358, 360; 359, identifier:hasattr; 360, argument_list; 360, 361; 360, 362; 361, identifier:vevent; 362, string:'class'; 363, block; 363, 364; 364, expression_statement; 364, 365; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:remind; 368, identifier:append; 369, argument_list; 369, 370; 370, binary_operator:%; 370, 371; 370, 372; 371, string:'TAG %s'; 372, call; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:Remind; 375, identifier:_abbr_tag; 376, argument_list; 376, 377; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:vevent; 380, identifier:getChildValue; 381, argument_list; 381, 382; 382, string:'class'; 383, if_statement; 383, 384; 383, 385; 384, identifier:tags; 385, block; 385, 386; 386, expression_statement; 386, 387; 387, call; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:remind; 390, identifier:extend; 391, argument_list; 391, 392; 392, list_comprehension; 392, 393; 392, 401; 393, binary_operator:%; 393, 394; 393, 395; 394, string:'TAG %s'; 395, call; 395, 396; 395, 399; 396, attribute; 396, 397; 396, 398; 397, identifier:Remind; 398, identifier:_abbr_tag; 399, argument_list; 399, 400; 400, identifier:tag; 401, for_in_clause; 401, 402; 401, 403; 402, identifier:tag; 403, identifier:tags; 404, if_statement; 404, 405; 404, 410; 405, call; 405, 406; 405, 407; 406, identifier:hasattr; 407, argument_list; 407, 408; 407, 409; 408, identifier:vevent; 409, string:'categories_list'; 410, block; 410, 411; 411, for_statement; 411, 412; 411, 413; 411, 416; 412, identifier:categories; 413, attribute; 413, 414; 413, 415; 414, identifier:vevent; 415, identifier:categories_list; 416, block; 416, 417; 417, for_statement; 417, 418; 417, 419; 417, 422; 418, identifier:category; 419, attribute; 419, 420; 419, 421; 420, identifier:categories; 421, identifier:value; 422, block; 422, 423; 423, expression_statement; 423, 424; 424, call; 424, 425; 424, 428; 425, attribute; 425, 426; 425, 427; 426, identifier:remind; 427, identifier:append; 428, argument_list; 428, 429; 429, binary_operator:%; 429, 430; 429, 431; 430, string:'TAG %s'; 431, call; 431, 432; 431, 435; 432, attribute; 432, 433; 432, 434; 433, identifier:Remind; 434, identifier:_abbr_tag; 435, argument_list; 435, 436; 436, identifier:category; 437, expression_statement; 437, 438; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:remind; 441, identifier:append; 442, argument_list; 442, 443; 443, call; 443, 444; 443, 447; 444, attribute; 444, 445; 444, 446; 445, identifier:Remind; 446, identifier:_gen_msg; 447, argument_list; 447, 448; 447, 449; 447, 450; 447, 451; 448, identifier:vevent; 449, identifier:label; 450, identifier:tail; 451, identifier:sep; 452, return_statement; 452, 453; 453, binary_operator:+; 453, 454; 453, 460; 454, call; 454, 455; 454, 458; 455, attribute; 455, 456; 455, 457; 456, string:' '; 457, identifier:join; 458, argument_list; 458, 459; 459, identifier:remind; 460, string:'\n'
def to_remind(self, vevent, label=None, priority=None, tags=None, tail=None, sep=" ", postdate=None, posttime=None): remind = ['REM'] trigdates = None if hasattr(vevent, 'rrule'): trigdates = Remind._parse_rruleset(vevent.rruleset) dtstart = vevent.dtstart.value if isinstance(dtstart, datetime) and dtstart.tzinfo: dtstart = dtstart.astimezone(self._localtz) dtend = None if hasattr(vevent, 'dtend'): dtend = vevent.dtend.value if isinstance(dtend, datetime) and dtend.tzinfo: dtend = dtend.astimezone(self._localtz) if not hasattr(vevent, 'rdate') and not isinstance(trigdates, str): remind.append(dtstart.strftime('%b %d %Y').replace(' 0', ' ')) if postdate: remind.append(postdate) if priority: remind.append('PRIORITY %s' % priority) if isinstance(trigdates, list): remind.extend(trigdates) duration = Remind._event_duration(vevent) if type(dtstart) is date and duration.days > 1: remind.append('*1') if dtend is not None: dtend -= timedelta(days=1) remind.append(dtend.strftime('UNTIL %b %d %Y').replace(' 0', ' ')) if isinstance(dtstart, datetime): remind.append(dtstart.strftime('AT %H:%M').replace(' 0', ' ')) if posttime: remind.append(posttime) if duration.total_seconds() > 0: remind.append('DURATION %d:%02d' % divmod(duration.total_seconds() / 60, 60)) if hasattr(vevent, 'rdate'): remind.append(Remind._parse_rdate(vevent.rdate.value)) elif isinstance(trigdates, str): remind.append(trigdates) if hasattr(vevent, 'class'): remind.append('TAG %s' % Remind._abbr_tag(vevent.getChildValue('class'))) if tags: remind.extend(['TAG %s' % Remind._abbr_tag(tag) for tag in tags]) if hasattr(vevent, 'categories_list'): for categories in vevent.categories_list: for category in categories.value: remind.append('TAG %s' % Remind._abbr_tag(category)) remind.append(Remind._gen_msg(vevent, label, tail, sep)) return ' '.join(remind) + '\n'
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:module_name_from_path; 3, parameters; 3, 4; 3, 5; 4, identifier:folder_name; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, False; 8, block; 8, 9; 8, 20; 8, 31; 8, 42; 8, 48; 8, 55; 8, 59; 8, 69; 8, 170; 8, 180; 8, 186; 8, 195; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:folder_name; 12, subscript; 12, 13; 12, 19; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:folder_name; 16, identifier:split; 17, argument_list; 17, 18; 18, string:'.pyc'; 19, integer:0; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:folder_name; 23, subscript; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:folder_name; 27, identifier:split; 28, argument_list; 28, 29; 29, string:'.py'; 30, integer:0; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:folder_name; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:os; 38, identifier:path; 39, identifier:normpath; 40, argument_list; 40, 41; 41, identifier:folder_name; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:path; 45, binary_operator:+; 45, 46; 45, 47; 46, identifier:folder_name; 47, string:'/'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:package; 51, call; 51, 52; 51, 53; 52, identifier:get_python_package; 53, argument_list; 53, 54; 54, identifier:path; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:module; 58, list:[]; 59, if_statement; 59, 60; 59, 61; 60, identifier:verbose; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:print; 65, argument_list; 65, 66; 66, tuple; 66, 67; 66, 68; 67, string:'folder_name'; 68, identifier:folder_name; 69, while_statement; 69, 70; 69, 71; 70, True; 71, block; 71, 72; 71, 83; 71, 97; 71, 121; 71, 142; 71, 160; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:path; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:os; 79, identifier:path; 80, identifier:dirname; 81, argument_list; 81, 82; 82, identifier:path; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:module; 87, identifier:append; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:basename; 95, argument_list; 95, 96; 96, identifier:path; 97, if_statement; 97, 98; 97, 108; 98, comparison_operator:==; 98, 99; 98, 107; 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:basename; 105, argument_list; 105, 106; 106, identifier:path; 107, identifier:package; 108, block; 108, 109; 108, 120; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:path; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:os; 116, identifier:path; 117, identifier:dirname; 118, argument_list; 118, 119; 119, identifier:path; 120, break_statement; 121, if_statement; 121, 122; 121, 132; 122, comparison_operator:==; 122, 123; 122, 131; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:os; 127, identifier:path; 128, identifier:dirname; 129, argument_list; 129, 130; 130, identifier:path; 131, identifier:path; 132, block; 132, 133; 132, 141; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, pattern_list; 135, 136; 135, 137; 136, identifier:path; 137, identifier:module; 138, expression_list; 138, 139; 138, 140; 139, None; 140, None; 141, break_statement; 142, if_statement; 142, 143; 142, 144; 143, identifier:verbose; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:print; 148, argument_list; 148, 149; 149, tuple; 149, 150; 149, 151; 149, 152; 150, string:'path'; 151, identifier:path; 152, call; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:os; 156, identifier:path; 157, identifier:dirname; 158, argument_list; 158, 159; 159, identifier:path; 160, if_statement; 160, 161; 160, 162; 161, identifier:verbose; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:print; 166, argument_list; 166, 167; 167, tuple; 167, 168; 167, 169; 168, string:'module'; 169, identifier:module; 170, if_statement; 170, 171; 170, 172; 171, identifier:verbose; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:print; 176, argument_list; 176, 177; 177, tuple; 177, 178; 177, 179; 178, string:'module'; 179, identifier:module; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:module; 184, identifier:reverse; 185, argument_list; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:module; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, string:'.'; 192, identifier:join; 193, argument_list; 193, 194; 194, identifier:module; 195, return_statement; 195, 196; 196, expression_list; 196, 197; 196, 198; 197, identifier:module; 198, identifier:path
def module_name_from_path(folder_name, verbose=False): folder_name = folder_name.split('.pyc')[0] folder_name = folder_name.split('.py')[0] folder_name = os.path.normpath(folder_name) path = folder_name + '/' package = get_python_package(path) module = [] if verbose: print(('folder_name', folder_name)) while True: path = os.path.dirname(path) module.append(os.path.basename(path)) if os.path.basename(path) == package: path = os.path.dirname(path) break if os.path.dirname(path) == path: path, module = None, None break if verbose: print(('path', path, os.path.dirname(path))) if verbose: print(('module', module)) if verbose: print(('module', module)) module.reverse() module = '.'.join(module) return module, path
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:main; 3, parameters; 4, block; 4, 5; 4, 13; 4, 30; 4, 47; 4, 61; 4, 75; 4, 89; 4, 97; 4, 103; 4, 109; 4, 113; 4, 122; 4, 126; 4, 135; 4, 139; 4, 148; 4, 152; 4, 161; 4, 181; 4, 185; 4, 211; 4, 223; 4, 354; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:parser; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:argparse; 11, identifier:ArgumentParser; 12, argument_list; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:parser; 17, identifier:add_argument; 18, argument_list; 18, 19; 18, 20; 18, 21; 18, 24; 18, 27; 19, string:"-f"; 20, string:"--file"; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:required; 23, True; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:help; 26, string:"input file"; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:type; 29, identifier:str; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:parser; 34, identifier:add_argument; 35, argument_list; 35, 36; 35, 37; 35, 38; 35, 41; 35, 44; 36, string:"-l"; 37, string:"--locus"; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:required; 40, True; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:help; 43, string:"Locus"; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:type; 46, identifier:str; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:parser; 51, identifier:add_argument; 52, argument_list; 52, 53; 52, 54; 52, 55; 52, 58; 53, string:"-k"; 54, string:"--kir"; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:help; 57, string:"Option for running with KIR"; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:action; 60, string:'store_true'; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:parser; 65, identifier:add_argument; 66, argument_list; 66, 67; 66, 68; 66, 69; 66, 72; 67, string:"-s"; 68, string:"--server"; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:help; 71, string:"Option for running with a server"; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:action; 74, string:'store_true'; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:parser; 79, identifier:add_argument; 80, argument_list; 80, 81; 80, 82; 80, 83; 80, 86; 81, string:"-v"; 82, string:"--verbose"; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:help; 85, string:"Option for running in verbose"; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:action; 88, string:'store_true'; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:args; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:parser; 95, identifier:parse_args; 96, argument_list; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:fastafile; 100, attribute; 100, 101; 100, 102; 101, identifier:args; 102, identifier:file; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:locus; 106, attribute; 106, 107; 106, 108; 107, identifier:args; 108, identifier:locus; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:verbose; 112, False; 113, if_statement; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:args; 116, identifier:verbose; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:verbose; 121, True; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:verbose; 125, False; 126, if_statement; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:args; 129, identifier:verbose; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:verbose; 134, True; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:kir; 138, False; 139, if_statement; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:args; 142, identifier:kir; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:kir; 147, True; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:serv; 151, False; 152, if_statement; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:args; 155, identifier:server; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:serv; 160, True; 161, if_statement; 161, 162; 161, 163; 162, identifier:verbose; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:logging; 168, identifier:basicConfig; 169, argument_list; 169, 170; 169, 173; 169, 176; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:format; 172, string:'%(asctime)s - %(name)-35s - %(levelname)-5s - %(message)s'; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:datefmt; 175, string:'%m/%d/%Y %I:%M:%S %p'; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:level; 178, attribute; 178, 179; 178, 180; 179, identifier:logging; 180, identifier:INFO; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:server; 184, None; 185, if_statement; 185, 186; 185, 187; 186, identifier:serv; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:server; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:BioSeqDatabase; 194, identifier:open_database; 195, argument_list; 195, 196; 195, 199; 195, 202; 195, 205; 195, 208; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:driver; 198, string:"pymysql"; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:user; 201, string:"root"; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:passwd; 204, string:""; 205, keyword_argument; 205, 206; 205, 207; 206, identifier:host; 207, string:"localhost"; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:db; 210, string:"bioseqdb"; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:seqann; 214, call; 214, 215; 214, 216; 215, identifier:BioSeqAnn; 216, argument_list; 216, 217; 216, 220; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:verbose; 219, True; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:kir; 222, identifier:kir; 223, for_statement; 223, 224; 223, 225; 223, 232; 224, identifier:seq; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:SeqIO; 228, identifier:parse; 229, argument_list; 229, 230; 229, 231; 230, identifier:fastafile; 231, string:"fasta"; 232, block; 232, 233; 232, 245; 232, 262; 232, 266; 232, 349; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:ann; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:seqann; 239, identifier:annotate; 240, argument_list; 240, 241; 240, 242; 241, identifier:seq; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:locus; 244, identifier:locus; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 248; 247, identifier:print; 248, argument_list; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, string:'{:*^20} {:^20} {:*^20}'; 252, identifier:format; 253, argument_list; 253, 254; 253, 255; 253, 261; 254, string:""; 255, call; 255, 256; 255, 257; 256, identifier:str; 257, argument_list; 257, 258; 258, attribute; 258, 259; 258, 260; 259, identifier:seq; 260, identifier:description; 261, string:""; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:l; 265, integer:0; 266, for_statement; 266, 267; 266, 268; 266, 271; 267, identifier:f; 268, attribute; 268, 269; 268, 270; 269, identifier:ann; 270, identifier:annotation; 271, block; 271, 272; 272, if_statement; 272, 273; 272, 282; 272, 313; 273, call; 273, 274; 273, 275; 274, identifier:isinstance; 275, argument_list; 275, 276; 275, 281; 276, subscript; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:ann; 279, identifier:annotation; 280, identifier:f; 281, identifier:DBSeq; 282, block; 282, 283; 282, 302; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:print; 286, argument_list; 286, 287; 286, 288; 286, 291; 286, 299; 287, identifier:f; 288, attribute; 288, 289; 288, 290; 289, identifier:ann; 290, identifier:method; 291, call; 291, 292; 291, 293; 292, identifier:str; 293, argument_list; 293, 294; 294, subscript; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:ann; 297, identifier:annotation; 298, identifier:f; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:sep; 301, string:"\t"; 302, expression_statement; 302, 303; 303, augmented_assignment:+=; 303, 304; 303, 305; 304, identifier:l; 305, call; 305, 306; 305, 307; 306, identifier:len; 307, argument_list; 307, 308; 308, subscript; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:ann; 311, identifier:annotation; 312, identifier:f; 313, else_clause; 313, 314; 314, block; 314, 315; 314, 336; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 318; 317, identifier:print; 318, argument_list; 318, 319; 318, 320; 318, 323; 318, 333; 319, identifier:f; 320, attribute; 320, 321; 320, 322; 321, identifier:ann; 322, identifier:method; 323, call; 323, 324; 323, 325; 324, identifier:str; 325, argument_list; 325, 326; 326, attribute; 326, 327; 326, 332; 327, subscript; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:ann; 330, identifier:annotation; 331, identifier:f; 332, identifier:seq; 333, keyword_argument; 333, 334; 333, 335; 334, identifier:sep; 335, string:"\t"; 336, expression_statement; 336, 337; 337, augmented_assignment:+=; 337, 338; 337, 339; 338, identifier:l; 339, call; 339, 340; 339, 341; 340, identifier:len; 341, argument_list; 341, 342; 342, attribute; 342, 343; 342, 348; 343, subscript; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:ann; 346, identifier:annotation; 347, identifier:f; 348, identifier:seq; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 352; 351, identifier:print; 352, argument_list; 352, 353; 353, string:""; 354, if_statement; 354, 355; 354, 356; 355, identifier:serv; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, identifier:server; 361, identifier:close; 362, argument_list
def main(): parser = argparse.ArgumentParser() parser.add_argument("-f", "--file", required=True, help="input file", type=str) parser.add_argument("-l", "--locus", required=True, help="Locus", type=str) parser.add_argument("-k", "--kir", help="Option for running with KIR", action='store_true') parser.add_argument("-s", "--server", help="Option for running with a server", action='store_true') parser.add_argument("-v", "--verbose", help="Option for running in verbose", action='store_true') args = parser.parse_args() fastafile = args.file locus = args.locus verbose = False if args.verbose: verbose = True verbose = False if args.verbose: verbose = True kir = False if args.kir: kir = True serv = False if args.server: serv = True if verbose: logging.basicConfig(format='%(asctime)s - %(name)-35s - %(levelname)-5s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) server = None if serv: server = BioSeqDatabase.open_database(driver="pymysql", user="root", passwd="", host="localhost", db="bioseqdb") seqann = BioSeqAnn(verbose=True, kir=kir) for seq in SeqIO.parse(fastafile, "fasta"): ann = seqann.annotate(seq, locus=locus) print('{:*^20} {:^20} {:*^20}'.format("", str(seq.description), "")) l = 0 for f in ann.annotation: if isinstance(ann.annotation[f], DBSeq): print(f, ann.method, str(ann.annotation[f]), sep="\t") l += len(ann.annotation[f]) else: print(f, ann.method, str(ann.annotation[f].seq), sep="\t") l += len(ann.annotation[f].seq) print("") if serv: server.close()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_push_subtree; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:leaves; 7, type; 7, 8; 8, generic_type; 8, 9; 8, 10; 9, identifier:List; 10, type_parameter; 10, 11; 11, type; 11, 12; 12, identifier:bytes; 13, block; 13, 14; 13, 21; 13, 36; 13, 49; 13, 67; 13, 82; 13, 87; 13, 105; 13, 115; 13, 130; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:size; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, identifier:leaves; 21, if_statement; 21, 22; 21, 28; 22, comparison_operator:!=; 22, 23; 22, 27; 23, call; 23, 24; 23, 25; 24, identifier:count_bits_set; 25, argument_list; 25, 26; 26, identifier:size; 27, integer:1; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:ValueError; 32, argument_list; 32, 33; 33, binary_operator:%; 33, 34; 33, 35; 34, string:"invalid subtree with size != 2^k: %s"; 35, identifier:size; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, pattern_list; 38, 39; 38, 40; 39, identifier:subtree_h; 40, identifier:mintree_h; 41, expression_list; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:lowest_bit_set; 44, argument_list; 44, 45; 45, identifier:size; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:__mintree_height; 49, if_statement; 49, 50; 49, 57; 50, boolean_operator:and; 50, 51; 50, 54; 51, comparison_operator:>; 51, 52; 51, 53; 52, identifier:mintree_h; 53, integer:0; 54, comparison_operator:>; 54, 55; 54, 56; 55, identifier:subtree_h; 56, identifier:mintree_h; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ValueError; 61, argument_list; 61, 62; 62, binary_operator:%; 62, 63; 62, 64; 63, string:"subtree %s > current smallest subtree %s"; 64, tuple; 64, 65; 64, 66; 65, identifier:subtree_h; 66, identifier:mintree_h; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, pattern_list; 69, 70; 69, 71; 70, identifier:root_hash; 71, identifier:hashes; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:__hasher; 77, identifier:_hash_full; 78, argument_list; 78, 79; 78, 80; 78, 81; 79, identifier:leaves; 80, integer:0; 81, identifier:size; 82, assert_statement; 82, 83; 83, comparison_operator:==; 83, 84; 83, 85; 84, identifier:hashes; 85, tuple; 85, 86; 86, identifier:root_hash; 87, if_statement; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:hashStore; 91, block; 91, 92; 92, for_statement; 92, 93; 92, 94; 92, 95; 93, identifier:h; 94, identifier:hashes; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:hashStore; 102, identifier:writeLeaf; 103, argument_list; 103, 104; 104, identifier:h; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:new_node_hashes; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:__push_subtree_hash; 112, argument_list; 112, 113; 112, 114; 113, identifier:subtree_h; 114, identifier:root_hash; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:nodes; 118, list_comprehension; 118, 119; 118, 125; 119, tuple; 119, 120; 119, 123; 119, 124; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:tree_size; 123, identifier:height; 124, identifier:h; 125, for_in_clause; 125, 126; 125, 129; 126, pattern_list; 126, 127; 126, 128; 127, identifier:h; 128, identifier:height; 129, identifier:new_node_hashes; 130, if_statement; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:hashStore; 134, block; 134, 135; 135, for_statement; 135, 136; 135, 137; 135, 138; 136, identifier:node; 137, identifier:nodes; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:hashStore; 145, identifier:writeNode; 146, argument_list; 146, 147; 147, identifier:node
def _push_subtree(self, leaves: List[bytes]): size = len(leaves) if count_bits_set(size) != 1: raise ValueError("invalid subtree with size != 2^k: %s" % size) subtree_h, mintree_h = lowest_bit_set(size), self.__mintree_height if mintree_h > 0 and subtree_h > mintree_h: raise ValueError("subtree %s > current smallest subtree %s" % ( subtree_h, mintree_h)) root_hash, hashes = self.__hasher._hash_full(leaves, 0, size) assert hashes == (root_hash,) if self.hashStore: for h in hashes: self.hashStore.writeLeaf(h) new_node_hashes = self.__push_subtree_hash(subtree_h, root_hash) nodes = [(self.tree_size, height, h) for h, height in new_node_hashes] if self.hashStore: for node in nodes: self.hashStore.writeNode(node)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:blocks; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:aln; 5, default_parameter; 5, 6; 5, 7; 6, identifier:threshold; 7, float:0.5; 8, default_parameter; 8, 9; 8, 10; 9, identifier:weights; 10, None; 11, block; 11, 12; 11, 17; 11, 108; 11, 121; 11, 140; 11, 150; 11, 171; 11, 175; 11, 205; 12, assert_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:len; 15, argument_list; 15, 16; 16, identifier:aln; 17, if_statement; 17, 18; 17, 21; 17, 45; 18, comparison_operator:==; 18, 19; 18, 20; 19, identifier:weights; 20, False; 21, block; 21, 22; 22, function_definition; 22, 23; 22, 24; 22, 26; 23, function_name:pct_nongaps; 24, parameters; 24, 25; 25, identifier:col; 26, block; 26, 27; 27, return_statement; 27, 28; 28, binary_operator:-; 28, 29; 28, 30; 29, integer:1; 30, parenthesized_expression; 30, 31; 31, binary_operator:/; 31, 32; 31, 41; 32, call; 32, 33; 32, 34; 33, identifier:float; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:col; 38, identifier:count; 39, argument_list; 39, 40; 40, string:'-'; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:col; 45, else_clause; 45, 46; 46, block; 46, 47; 46, 62; 47, if_statement; 47, 48; 47, 53; 48, comparison_operator:in; 48, 49; 48, 50; 49, identifier:weights; 50, tuple; 50, 51; 50, 52; 51, None; 52, True; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:weights; 57, call; 57, 58; 57, 59; 58, identifier:sequence_weights; 59, argument_list; 59, 60; 59, 61; 60, identifier:aln; 61, string:'avg1'; 62, function_definition; 62, 63; 62, 64; 62, 66; 63, function_name:pct_nongaps; 64, parameters; 64, 65; 65, identifier:col; 66, block; 66, 67; 66, 77; 66, 98; 67, assert_statement; 67, 68; 68, comparison_operator:==; 68, 69; 68, 73; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:col; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, identifier:weights; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:ngaps; 80, call; 80, 81; 80, 82; 81, identifier:sum; 82, generator_expression; 82, 83; 82, 89; 83, binary_operator:*; 83, 84; 83, 85; 84, identifier:wt; 85, parenthesized_expression; 85, 86; 86, comparison_operator:==; 86, 87; 86, 88; 87, identifier:c; 88, string:'-'; 89, for_in_clause; 89, 90; 89, 93; 90, pattern_list; 90, 91; 90, 92; 91, identifier:wt; 92, identifier:c; 93, call; 93, 94; 93, 95; 94, identifier:zip; 95, argument_list; 95, 96; 95, 97; 96, identifier:weights; 97, identifier:col; 98, return_statement; 98, 99; 99, binary_operator:-; 99, 100; 99, 101; 100, integer:1; 101, parenthesized_expression; 101, 102; 102, binary_operator:/; 102, 103; 102, 104; 103, identifier:ngaps; 104, call; 104, 105; 104, 106; 105, identifier:len; 106, argument_list; 106, 107; 107, identifier:col; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:seqstrs; 111, list_comprehension; 111, 112; 111, 118; 112, call; 112, 113; 112, 114; 113, identifier:str; 114, argument_list; 114, 115; 115, attribute; 115, 116; 115, 117; 116, identifier:rec; 117, identifier:seq; 118, for_in_clause; 118, 119; 118, 120; 119, identifier:rec; 120, identifier:aln; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:clean_cols; 124, list_comprehension; 124, 125; 124, 126; 124, 133; 125, identifier:col; 126, for_in_clause; 126, 127; 126, 128; 127, identifier:col; 128, call; 128, 129; 128, 130; 129, identifier:zip; 130, argument_list; 130, 131; 131, list_splat; 131, 132; 132, identifier:seqstrs; 133, if_clause; 133, 134; 134, comparison_operator:>=; 134, 135; 134, 139; 135, call; 135, 136; 135, 137; 136, identifier:pct_nongaps; 137, argument_list; 137, 138; 138, identifier:col; 139, identifier:threshold; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:alphabet; 143, attribute; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:aln; 147, integer:0; 148, identifier:seq; 149, identifier:alphabet; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:clean_seqs; 153, list_comprehension; 153, 154; 153, 164; 154, call; 154, 155; 154, 156; 155, identifier:Seq; 156, argument_list; 156, 157; 156, 163; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, string:''; 160, identifier:join; 161, argument_list; 161, 162; 162, identifier:row; 163, identifier:alphabet; 164, for_in_clause; 164, 165; 164, 166; 165, identifier:row; 166, call; 166, 167; 166, 168; 167, identifier:zip; 168, argument_list; 168, 169; 169, list_splat; 169, 170; 170, identifier:clean_cols; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:clean_recs; 174, list:[]; 175, for_statement; 175, 176; 175, 179; 175, 184; 176, pattern_list; 176, 177; 176, 178; 177, identifier:rec; 178, identifier:seq; 179, call; 179, 180; 179, 181; 180, identifier:zip; 181, argument_list; 181, 182; 181, 183; 182, identifier:aln; 183, identifier:clean_seqs; 184, block; 184, 185; 184, 192; 184, 198; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:newrec; 188, call; 188, 189; 188, 190; 189, identifier:deepcopy; 190, argument_list; 190, 191; 191, identifier:rec; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:newrec; 196, identifier:seq; 197, identifier:seq; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:clean_recs; 202, identifier:append; 203, argument_list; 203, 204; 204, identifier:newrec; 205, return_statement; 205, 206; 206, call; 206, 207; 206, 208; 207, identifier:MultipleSeqAlignment; 208, argument_list; 208, 209; 208, 210; 209, identifier:clean_recs; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:alphabet; 212, identifier:alphabet
def blocks(aln, threshold=0.5, weights=None): assert len(aln) if weights == False: def pct_nongaps(col): return 1 - (float(col.count('-')) / len(col)) else: if weights in (None, True): weights = sequence_weights(aln, 'avg1') def pct_nongaps(col): assert len(col) == len(weights) ngaps = sum(wt * (c == '-') for wt, c in zip(weights, col)) return 1 - (ngaps / len(col)) seqstrs = [str(rec.seq) for rec in aln] clean_cols = [col for col in zip(*seqstrs) if pct_nongaps(col) >= threshold] alphabet = aln[0].seq.alphabet clean_seqs = [Seq(''.join(row), alphabet) for row in zip(*clean_cols)] clean_recs = [] for rec, seq in zip(aln, clean_seqs): newrec = deepcopy(rec) newrec.seq = seq clean_recs.append(newrec) return MultipleSeqAlignment(clean_recs, alphabet=alphabet)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sequence_weights; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:aln; 5, default_parameter; 5, 6; 5, 7; 6, identifier:scaling; 7, string:'none'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:gap_chars; 10, string:'-.'; 11, block; 11, 12; 11, 117; 11, 212; 11, 222; 11, 226; 11, 279; 11, 301; 11, 384; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:expectk; 15, list:[0.0, 1.0, 1.953, 2.861, 3.705, 4.524, 5.304, 6.026, 6.724, 7.397, 8.04, 8.622, 9.191, 9.739, 10.264, 10.758, 11.194, 11.635, 12.049, 12.468, 12.806, 13.185, 13.539, 13.863, 14.177, 14.466, 14.737, 15.005, 15.245, 15.491, 15.681, 15.916, 16.12, 16.301, 16.485, 16.671, 16.831, 16.979, 17.151, 17.315, 17.427, 17.559, 17.68, 17.791, 17.914, 18.009, 18.113, 18.203, 18.298, 18.391, 18.46, 18.547, 18.617, 18.669, 18.77, 18.806, 18.858, 18.934, 18.978, 19.027, 19.085, 19.119, 19.169, 19.202, 19.256, 19.291, 19.311, 19.357, 19.399, 19.416, 19.456, 19.469, 19.5, 19.53, 19.553, 19.562, 19.602, 19.608, 19.629, 19.655, 19.67, 19.681, 19.7, 19.716, 19.724, 19.748, 19.758, 19.765, 19.782, 19.791, 19.799, 19.812, 19.82, 19.828, 19.844, 19.846, 19.858, 19.863, 19.862, 19.871, 19.882]; 15, 16; 15, 17; 15, 18; 15, 19; 15, 20; 15, 21; 15, 22; 15, 23; 15, 24; 15, 25; 15, 26; 15, 27; 15, 28; 15, 29; 15, 30; 15, 31; 15, 32; 15, 33; 15, 34; 15, 35; 15, 36; 15, 37; 15, 38; 15, 39; 15, 40; 15, 41; 15, 42; 15, 43; 15, 44; 15, 45; 15, 46; 15, 47; 15, 48; 15, 49; 15, 50; 15, 51; 15, 52; 15, 53; 15, 54; 15, 55; 15, 56; 15, 57; 15, 58; 15, 59; 15, 60; 15, 61; 15, 62; 15, 63; 15, 64; 15, 65; 15, 66; 15, 67; 15, 68; 15, 69; 15, 70; 15, 71; 15, 72; 15, 73; 15, 74; 15, 75; 15, 76; 15, 77; 15, 78; 15, 79; 15, 80; 15, 81; 15, 82; 15, 83; 15, 84; 15, 85; 15, 86; 15, 87; 15, 88; 15, 89; 15, 90; 15, 91; 15, 92; 15, 93; 15, 94; 15, 95; 15, 96; 15, 97; 15, 98; 15, 99; 15, 100; 15, 101; 15, 102; 15, 103; 15, 104; 15, 105; 15, 106; 15, 107; 15, 108; 15, 109; 15, 110; 15, 111; 15, 112; 15, 113; 15, 114; 15, 115; 15, 116; 16, float:0.0; 17, float:1.0; 18, float:1.953; 19, float:2.861; 20, float:3.705; 21, float:4.524; 22, float:5.304; 23, float:6.026; 24, float:6.724; 25, float:7.397; 26, float:8.04; 27, float:8.622; 28, float:9.191; 29, float:9.739; 30, float:10.264; 31, float:10.758; 32, float:11.194; 33, float:11.635; 34, float:12.049; 35, float:12.468; 36, float:12.806; 37, float:13.185; 38, float:13.539; 39, float:13.863; 40, float:14.177; 41, float:14.466; 42, float:14.737; 43, float:15.005; 44, float:15.245; 45, float:15.491; 46, float:15.681; 47, float:15.916; 48, float:16.12; 49, float:16.301; 50, float:16.485; 51, float:16.671; 52, float:16.831; 53, float:16.979; 54, float:17.151; 55, float:17.315; 56, float:17.427; 57, float:17.559; 58, float:17.68; 59, float:17.791; 60, float:17.914; 61, float:18.009; 62, float:18.113; 63, float:18.203; 64, float:18.298; 65, float:18.391; 66, float:18.46; 67, float:18.547; 68, float:18.617; 69, float:18.669; 70, float:18.77; 71, float:18.806; 72, float:18.858; 73, float:18.934; 74, float:18.978; 75, float:19.027; 76, float:19.085; 77, float:19.119; 78, float:19.169; 79, float:19.202; 80, float:19.256; 81, float:19.291; 82, float:19.311; 83, float:19.357; 84, float:19.399; 85, float:19.416; 86, float:19.456; 87, float:19.469; 88, float:19.5; 89, float:19.53; 90, float:19.553; 91, float:19.562; 92, float:19.602; 93, float:19.608; 94, float:19.629; 95, float:19.655; 96, float:19.67; 97, float:19.681; 98, float:19.7; 99, float:19.716; 100, float:19.724; 101, float:19.748; 102, float:19.758; 103, float:19.765; 104, float:19.782; 105, float:19.791; 106, float:19.799; 107, float:19.812; 108, float:19.82; 109, float:19.828; 110, float:19.844; 111, float:19.846; 112, float:19.858; 113, float:19.863; 114, float:19.862; 115, float:19.871; 116, float:19.882; 117, function_definition; 117, 118; 117, 119; 117, 121; 118, function_name:col_weight; 119, parameters; 119, 120; 120, identifier:column; 121, block; 121, 122; 121, 135; 121, 161; 121, 168; 121, 175; 121, 198; 121, 208; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:min_nongap; 125, call; 125, 126; 125, 127; 126, identifier:max; 127, argument_list; 127, 128; 127, 129; 128, integer:2; 129, binary_operator:*; 129, 130; 129, 131; 130, float:.2; 131, call; 131, 132; 131, 133; 132, identifier:len; 133, argument_list; 133, 134; 134, identifier:column; 135, if_statement; 135, 136; 135, 150; 136, comparison_operator:<; 136, 137; 136, 149; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, list_comprehension; 140, 141; 140, 142; 140, 145; 141, identifier:c; 142, for_in_clause; 142, 143; 142, 144; 143, identifier:c; 144, identifier:column; 145, if_clause; 145, 146; 146, comparison_operator:not; 146, 147; 146, 148; 147, identifier:c; 148, identifier:gap_chars; 149, identifier:min_nongap; 150, block; 150, 151; 151, return_statement; 151, 152; 152, tuple; 152, 153; 152, 160; 153, binary_operator:*; 153, 154; 153, 156; 154, list:[0]; 154, 155; 155, integer:0; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:column; 160, integer:0; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:counts; 164, call; 164, 165; 164, 166; 165, identifier:Counter; 166, argument_list; 166, 167; 167, identifier:column; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:n_residues; 171, call; 171, 172; 171, 173; 172, identifier:len; 173, argument_list; 173, 174; 174, identifier:counts; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:freqs; 178, call; 178, 179; 178, 180; 179, identifier:dict; 180, generator_expression; 180, 181; 180, 189; 181, tuple; 181, 182; 181, 183; 182, identifier:aa; 183, binary_operator:/; 183, 184; 183, 185; 184, float:1.0; 185, parenthesized_expression; 185, 186; 186, binary_operator:*; 186, 187; 186, 188; 187, identifier:n_residues; 188, identifier:count; 189, for_in_clause; 189, 190; 189, 193; 190, pattern_list; 190, 191; 190, 192; 191, identifier:aa; 192, identifier:count; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:counts; 196, identifier:iteritems; 197, argument_list; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:weights; 201, list_comprehension; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:freqs; 204, identifier:aa; 205, for_in_clause; 205, 206; 205, 207; 206, identifier:aa; 207, identifier:column; 208, return_statement; 208, 209; 209, tuple; 209, 210; 209, 211; 210, identifier:weights; 211, identifier:n_residues; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:seq_weights; 215, binary_operator:*; 215, 216; 215, 218; 216, list:[0]; 216, 217; 217, integer:0; 218, call; 218, 219; 218, 220; 219, identifier:len; 220, argument_list; 220, 221; 221, identifier:aln; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:tot_nres; 225, float:0.0; 226, for_statement; 226, 227; 226, 228; 226, 233; 227, identifier:col; 228, call; 228, 229; 228, 230; 229, identifier:zip; 230, argument_list; 230, 231; 231, list_splat; 231, 232; 232, identifier:aln; 233, block; 233, 234; 233, 243; 233, 250; 233, 264; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, pattern_list; 236, 237; 236, 238; 237, identifier:wts; 238, identifier:nres; 239, call; 239, 240; 239, 241; 240, identifier:col_weight; 241, argument_list; 241, 242; 242, identifier:col; 243, assert_statement; 243, 244; 244, comparison_operator:<=; 244, 245; 244, 249; 245, call; 245, 246; 245, 247; 246, identifier:sum; 247, argument_list; 247, 248; 248, identifier:wts; 249, integer:20; 250, expression_statement; 250, 251; 251, augmented_assignment:+=; 251, 252; 251, 253; 252, identifier:tot_nres; 253, conditional_expression:if; 253, 254; 253, 257; 253, 263; 254, subscript; 254, 255; 254, 256; 255, identifier:expectk; 256, identifier:nres; 257, comparison_operator:<; 257, 258; 257, 259; 258, identifier:nres; 259, call; 259, 260; 259, 261; 260, identifier:len; 261, argument_list; 261, 262; 262, identifier:expectk; 263, integer:20; 264, for_statement; 264, 265; 264, 268; 264, 272; 265, pattern_list; 265, 266; 265, 267; 266, identifier:idx; 267, identifier:wt; 268, call; 268, 269; 268, 270; 269, identifier:enumerate; 270, argument_list; 270, 271; 271, identifier:wts; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, augmented_assignment:+=; 274, 275; 274, 278; 275, subscript; 275, 276; 275, 277; 276, identifier:seq_weights; 277, identifier:idx; 278, identifier:wt; 279, if_statement; 279, 280; 279, 283; 280, comparison_operator:==; 280, 281; 280, 282; 281, identifier:scaling; 282, string:'none'; 283, block; 283, 284; 283, 293; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:avg_seq_len; 287, binary_operator:/; 287, 288; 287, 289; 288, identifier:tot_nres; 289, call; 289, 290; 289, 291; 290, identifier:len; 291, argument_list; 291, 292; 292, identifier:aln; 293, return_statement; 293, 294; 294, list_comprehension; 294, 295; 294, 298; 295, binary_operator:/; 295, 296; 295, 297; 296, identifier:wt; 297, identifier:avg_seq_len; 298, for_in_clause; 298, 299; 298, 300; 299, identifier:wt; 300, identifier:seq_weights; 301, if_statement; 301, 302; 301, 305; 301, 315; 301, 329; 301, 346; 301, 375; 302, comparison_operator:==; 302, 303; 302, 304; 303, identifier:scaling; 304, string:'max1'; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:scale; 309, binary_operator:/; 309, 310; 309, 311; 310, float:1.0; 311, call; 311, 312; 311, 313; 312, identifier:max; 313, argument_list; 313, 314; 314, identifier:seq_weights; 315, elif_clause; 315, 316; 315, 319; 316, comparison_operator:==; 316, 317; 316, 318; 317, identifier:scaling; 318, string:'sum1'; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 323; 322, identifier:scale; 323, binary_operator:/; 323, 324; 323, 325; 324, float:1.0; 325, call; 325, 326; 325, 327; 326, identifier:sum; 327, argument_list; 327, 328; 328, identifier:seq_weights; 329, elif_clause; 329, 330; 329, 333; 330, comparison_operator:==; 330, 331; 330, 332; 331, identifier:scaling; 332, string:'avg1'; 333, block; 333, 334; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:scale; 337, binary_operator:/; 337, 338; 337, 342; 338, call; 338, 339; 338, 340; 339, identifier:len; 340, argument_list; 340, 341; 341, identifier:aln; 342, call; 342, 343; 342, 344; 343, identifier:sum; 344, argument_list; 344, 345; 345, identifier:seq_weights; 346, elif_clause; 346, 347; 346, 350; 347, comparison_operator:==; 347, 348; 347, 349; 348, identifier:scaling; 349, string:'andy'; 350, block; 350, 351; 350, 363; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 354; 353, identifier:scale; 354, binary_operator:/; 354, 355; 354, 359; 355, call; 355, 356; 355, 357; 356, identifier:len; 357, argument_list; 357, 358; 358, identifier:aln; 359, call; 359, 360; 359, 361; 360, identifier:sum; 361, argument_list; 361, 362; 362, identifier:seq_weights; 363, return_statement; 363, 364; 364, list_comprehension; 364, 365; 364, 372; 365, call; 365, 366; 365, 367; 366, identifier:min; 367, argument_list; 367, 368; 367, 371; 368, binary_operator:*; 368, 369; 368, 370; 369, identifier:scale; 370, identifier:wt; 371, float:1.0; 372, for_in_clause; 372, 373; 372, 374; 373, identifier:wt; 374, identifier:seq_weights; 375, else_clause; 375, 376; 376, block; 376, 377; 377, raise_statement; 377, 378; 378, call; 378, 379; 378, 380; 379, identifier:ValueError; 380, argument_list; 380, 381; 381, binary_operator:%; 381, 382; 381, 383; 382, string:"Unknown scaling scheme '%s'"; 383, identifier:scaling; 384, return_statement; 384, 385; 385, list_comprehension; 385, 386; 385, 389; 386, binary_operator:*; 386, 387; 386, 388; 387, identifier:scale; 388, identifier:wt; 389, for_in_clause; 389, 390; 389, 391; 390, identifier:wt; 391, identifier:seq_weights
def sequence_weights(aln, scaling='none', gap_chars='-.'): expectk = [0.0, 1.0, 1.953, 2.861, 3.705, 4.524, 5.304, 6.026, 6.724, 7.397, 8.04, 8.622, 9.191, 9.739, 10.264, 10.758, 11.194, 11.635, 12.049, 12.468, 12.806, 13.185, 13.539, 13.863, 14.177, 14.466, 14.737, 15.005, 15.245, 15.491, 15.681, 15.916, 16.12, 16.301, 16.485, 16.671, 16.831, 16.979, 17.151, 17.315, 17.427, 17.559, 17.68, 17.791, 17.914, 18.009, 18.113, 18.203, 18.298, 18.391, 18.46, 18.547, 18.617, 18.669, 18.77, 18.806, 18.858, 18.934, 18.978, 19.027, 19.085, 19.119, 19.169, 19.202, 19.256, 19.291, 19.311, 19.357, 19.399, 19.416, 19.456, 19.469, 19.5, 19.53, 19.553, 19.562, 19.602, 19.608, 19.629, 19.655, 19.67, 19.681, 19.7, 19.716, 19.724, 19.748, 19.758, 19.765, 19.782, 19.791, 19.799, 19.812, 19.82, 19.828, 19.844, 19.846, 19.858, 19.863, 19.862, 19.871, 19.882] def col_weight(column): min_nongap = max(2, .2*len(column)) if len([c for c in column if c not in gap_chars]) < min_nongap: return ([0] * len(column), 0) counts = Counter(column) n_residues = len(counts) freqs = dict((aa, 1.0 / (n_residues * count)) for aa, count in counts.iteritems()) weights = [freqs[aa] for aa in column] return (weights, n_residues) seq_weights = [0] * len(aln) tot_nres = 0.0 for col in zip(*aln): wts, nres = col_weight(col) assert sum(wts) <= 20 tot_nres += expectk[nres] if nres < len(expectk) else 20 for idx, wt in enumerate(wts): seq_weights[idx] += wt if scaling == 'none': avg_seq_len = tot_nres / len(aln) return [wt/avg_seq_len for wt in seq_weights] if scaling == 'max1': scale = 1.0 / max(seq_weights) elif scaling == 'sum1': scale = 1.0 / sum(seq_weights) elif scaling == 'avg1': scale = len(aln) / sum(seq_weights) elif scaling == 'andy': scale = len(aln) / sum(seq_weights) return [min(scale * wt, 1.0) for wt in seq_weights] else: raise ValueError("Unknown scaling scheme '%s'" % scaling) return [scale * wt for wt in seq_weights]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:load_and_append; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:instrument_dict; 5, default_parameter; 5, 6; 5, 7; 6, identifier:instruments; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:raise_errors; 10, False; 11, block; 11, 12; 11, 21; 11, 25; 11, 32; 11, 36; 11, 282; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:instruments; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:instruments; 20, dictionary; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:updated_instruments; 24, dictionary; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:updated_instruments; 29, identifier:update; 30, argument_list; 30, 31; 31, identifier:instruments; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:loaded_failed; 35, dictionary; 36, for_statement; 36, 37; 36, 40; 36, 45; 37, pattern_list; 37, 38; 37, 39; 38, identifier:instrument_name; 39, identifier:instrument_class_name; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:instrument_dict; 43, identifier:items; 44, argument_list; 45, block; 45, 46; 45, 50; 45, 54; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:instrument_settings; 49, None; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:module; 53, None; 54, if_statement; 54, 55; 54, 74; 54, 92; 55, boolean_operator:and; 55, 56; 55, 66; 55, 67; 56, comparison_operator:in; 56, 57; 56, 58; 57, identifier:instrument_name; 58, call; 58, 59; 58, 60; 59, identifier:list; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:instruments; 64, identifier:keys; 65, argument_list; 66, line_continuation:\; 67, comparison_operator:==; 67, 68; 67, 69; 68, identifier:instrument_class_name; 69, attribute; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:instruments; 72, identifier:instrument_name; 73, identifier:__name__; 74, block; 74, 75; 74, 86; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:print; 78, argument_list; 78, 79; 79, parenthesized_expression; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, string:'WARNING: instrument {:s} already exists. Did not load!'; 83, identifier:format; 84, argument_list; 84, 85; 85, identifier:instrument_name; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:loaded_failed; 90, identifier:instrument_name; 91, identifier:instrument_name; 92, else_clause; 92, 93; 93, block; 93, 94; 93, 98; 93, 276; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:instrument_instance; 97, None; 98, if_statement; 98, 99; 98, 104; 98, 206; 98, 237; 99, call; 99, 100; 99, 101; 100, identifier:isinstance; 101, argument_list; 101, 102; 101, 103; 102, identifier:instrument_class_name; 103, identifier:dict; 104, block; 104, 105; 104, 116; 104, 125; 104, 134; 104, 143; 104, 150; 104, 158; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:in; 106, 107; 106, 108; 107, string:'settings'; 108, identifier:instrument_class_name; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:instrument_settings; 113, subscript; 113, 114; 113, 115; 114, identifier:instrument_class_name; 115, string:'settings'; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:instrument_filepath; 119, call; 119, 120; 119, 121; 120, identifier:str; 121, argument_list; 121, 122; 122, subscript; 122, 123; 122, 124; 123, identifier:instrument_class_name; 124, string:'filepath'; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:instrument_class_name; 128, call; 128, 129; 128, 130; 129, identifier:str; 130, argument_list; 130, 131; 131, subscript; 131, 132; 131, 133; 132, identifier:instrument_class_name; 133, string:'class'; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, pattern_list; 136, 137; 136, 138; 137, identifier:path_to_module; 138, identifier:_; 139, call; 139, 140; 139, 141; 140, identifier:module_name_from_path; 141, argument_list; 141, 142; 142, identifier:instrument_filepath; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:module; 146, call; 146, 147; 146, 148; 147, identifier:import_module; 148, argument_list; 148, 149; 149, identifier:path_to_module; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:class_of_instrument; 153, call; 153, 154; 153, 155; 154, identifier:getattr; 155, argument_list; 155, 156; 155, 157; 156, identifier:module; 157, identifier:instrument_class_name; 158, try_statement; 158, 159; 158, 188; 159, block; 159, 160; 160, if_statement; 160, 161; 160, 164; 160, 174; 161, comparison_operator:is; 161, 162; 161, 163; 162, identifier:instrument_settings; 163, None; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:instrument_instance; 168, call; 168, 169; 168, 170; 169, identifier:class_of_instrument; 170, argument_list; 170, 171; 171, keyword_argument; 171, 172; 171, 173; 172, identifier:name; 173, identifier:instrument_name; 174, else_clause; 174, 175; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:instrument_instance; 179, call; 179, 180; 179, 181; 180, identifier:class_of_instrument; 181, argument_list; 181, 182; 181, 185; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:name; 184, identifier:instrument_name; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:settings; 187, identifier:instrument_settings; 188, except_clause; 188, 189; 188, 193; 189, as_pattern; 189, 190; 189, 191; 190, identifier:Exception; 191, as_pattern_target; 191, 192; 192, identifier:e; 193, block; 193, 194; 193, 200; 193, 205; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:loaded_failed; 198, identifier:instrument_name; 199, identifier:e; 200, if_statement; 200, 201; 200, 202; 201, identifier:raise_errors; 202, block; 202, 203; 203, raise_statement; 203, 204; 204, identifier:e; 205, continue_statement; 206, elif_clause; 206, 207; 206, 212; 207, call; 207, 208; 207, 209; 208, identifier:isinstance; 209, argument_list; 209, 210; 209, 211; 210, identifier:instrument_class_name; 211, identifier:Instrument; 212, block; 212, 213; 212, 219; 212, 235; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:instrument_class_name; 216, attribute; 216, 217; 216, 218; 217, identifier:instrument_class_name; 218, identifier:__class__; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:instrument_filepath; 222, call; 222, 223; 222, 228; 223, attribute; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:os; 226, identifier:path; 227, identifier:dirname; 228, argument_list; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:inspect; 232, identifier:getfile; 233, argument_list; 233, 234; 234, identifier:instrument_class_name; 235, raise_statement; 235, 236; 236, identifier:NotImplementedError; 237, elif_clause; 237, 238; 237, 243; 238, call; 238, 239; 238, 240; 239, identifier:issubclass; 240, argument_list; 240, 241; 240, 242; 241, identifier:instrument_class_name; 242, identifier:Instrument; 243, block; 243, 244; 243, 248; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:class_of_instrument; 247, identifier:instrument_class_name; 248, if_statement; 248, 249; 248, 252; 248, 262; 249, comparison_operator:is; 249, 250; 249, 251; 250, identifier:instrument_settings; 251, None; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:instrument_instance; 256, call; 256, 257; 256, 258; 257, identifier:class_of_instrument; 258, argument_list; 258, 259; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:name; 261, identifier:instrument_name; 262, else_clause; 262, 263; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:instrument_instance; 267, call; 267, 268; 267, 269; 268, identifier:class_of_instrument; 269, argument_list; 269, 270; 269, 273; 270, keyword_argument; 270, 271; 270, 272; 271, identifier:name; 272, identifier:instrument_name; 273, keyword_argument; 273, 274; 273, 275; 274, identifier:settings; 275, identifier:instrument_settings; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:updated_instruments; 280, identifier:instrument_name; 281, identifier:instrument_instance; 282, return_statement; 282, 283; 283, expression_list; 283, 284; 283, 285; 284, identifier:updated_instruments; 285, identifier:loaded_failed
def load_and_append(instrument_dict, instruments=None, raise_errors=False): if instruments is None: instruments = {} updated_instruments = {} updated_instruments.update(instruments) loaded_failed = {} for instrument_name, instrument_class_name in instrument_dict.items(): instrument_settings = None module = None if instrument_name in list(instruments.keys()) \ and instrument_class_name == instruments[instrument_name].__name__: print(('WARNING: instrument {:s} already exists. Did not load!'.format(instrument_name))) loaded_failed[instrument_name] = instrument_name else: instrument_instance = None if isinstance(instrument_class_name, dict): if 'settings' in instrument_class_name: instrument_settings = instrument_class_name['settings'] instrument_filepath = str(instrument_class_name['filepath']) instrument_class_name = str(instrument_class_name['class']) path_to_module, _ = module_name_from_path(instrument_filepath) module = import_module(path_to_module) class_of_instrument = getattr(module, instrument_class_name) try: if instrument_settings is None: instrument_instance = class_of_instrument(name=instrument_name) else: instrument_instance = class_of_instrument(name=instrument_name, settings=instrument_settings) except Exception as e: loaded_failed[instrument_name] = e if raise_errors: raise e continue elif isinstance(instrument_class_name, Instrument): instrument_class_name = instrument_class_name.__class__ instrument_filepath = os.path.dirname(inspect.getfile(instrument_class_name)) raise NotImplementedError elif issubclass(instrument_class_name, Instrument): class_of_instrument = instrument_class_name if instrument_settings is None: instrument_instance = class_of_instrument(name=instrument_name) else: instrument_instance = class_of_instrument(name=instrument_name, settings=instrument_settings) updated_instruments[instrument_name] = instrument_instance return updated_instruments, loaded_failed
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_scan_nodes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:nodelist; 5, identifier:context; 6, identifier:instance_types; 7, default_parameter; 7, 8; 7, 9; 8, identifier:current_block; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:ignore_blocks; 12, None; 13, block; 13, 14; 13, 18; 13, 301; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:results; 17, list:[]; 18, for_statement; 18, 19; 18, 20; 18, 21; 19, identifier:node; 20, identifier:nodelist; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 28; 22, 36; 22, 110; 22, 126; 22, 184; 22, 200; 22, 256; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 27; 26, identifier:node; 27, identifier:instance_types; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:results; 33, identifier:append; 34, argument_list; 34, 35; 35, identifier:node; 36, elif_clause; 36, 37; 36, 42; 37, call; 37, 38; 37, 39; 38, identifier:isinstance; 39, argument_list; 39, 40; 39, 41; 40, identifier:node; 41, identifier:IncludeNode; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:node; 46, identifier:template; 47, block; 47, 48; 47, 81; 47, 98; 48, if_statement; 48, 49; 48, 61; 48, 73; 49, not_operator; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:callable; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:getattr; 55, argument_list; 55, 56; 55, 59; 55, 60; 56, attribute; 56, 57; 56, 58; 57, identifier:node; 58, identifier:template; 59, string:'render'; 60, None; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:template; 65, call; 65, 66; 65, 67; 66, identifier:get_template; 67, argument_list; 67, 68; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:node; 71, identifier:template; 72, identifier:var; 73, else_clause; 73, 74; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:template; 78, attribute; 78, 79; 78, 80; 79, identifier:node; 80, identifier:template; 81, if_statement; 81, 82; 81, 91; 82, boolean_operator:and; 82, 83; 82, 86; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:TemplateAdapter; 85, None; 86, call; 86, 87; 86, 88; 87, identifier:isinstance; 88, argument_list; 88, 89; 88, 90; 89, identifier:template; 90, identifier:TemplateAdapter; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:template; 95, attribute; 95, 96; 95, 97; 96, identifier:template; 97, identifier:template; 98, expression_statement; 98, 99; 99, augmented_assignment:+=; 99, 100; 99, 101; 100, identifier:results; 101, call; 101, 102; 101, 103; 102, identifier:_scan_nodes; 103, argument_list; 103, 104; 103, 107; 103, 108; 103, 109; 104, attribute; 104, 105; 104, 106; 105, identifier:template; 106, identifier:nodelist; 107, identifier:context; 108, identifier:instance_types; 109, identifier:current_block; 110, elif_clause; 110, 111; 110, 116; 111, call; 111, 112; 111, 113; 112, identifier:isinstance; 113, argument_list; 113, 114; 113, 115; 114, identifier:node; 115, identifier:ExtendsNode; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, augmented_assignment:+=; 118, 119; 118, 120; 119, identifier:results; 120, call; 120, 121; 120, 122; 121, identifier:_extend_nodelist; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:node; 124, identifier:context; 125, identifier:instance_types; 126, elif_clause; 126, 127; 126, 134; 127, boolean_operator:and; 127, 128; 127, 133; 128, call; 128, 129; 128, 130; 129, identifier:isinstance; 130, argument_list; 130, 131; 130, 132; 131, identifier:node; 132, identifier:VariableNode; 133, identifier:current_block; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 143; 136, comparison_operator:==; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:node; 140, identifier:filter_expression; 141, identifier:token; 142, string:'block.super'; 143, block; 143, 144; 143, 168; 144, if_statement; 144, 145; 144, 153; 145, not_operator; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:hasattr; 148, argument_list; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:current_block; 151, identifier:parent; 152, string:'nodelist'; 153, block; 153, 154; 154, raise_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:TemplateSyntaxError; 157, argument_list; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, concatenated_string; 160, 161; 160, 162; 161, string:"Cannot read {{{{ block.super }}}} for {{% block {0} %}}, "; 162, string:"the parent template doesn't have this block."; 163, identifier:format; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:current_block; 167, identifier:name; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:results; 171, call; 171, 172; 171, 173; 172, identifier:_scan_nodes; 173, argument_list; 173, 174; 173, 179; 173, 180; 173, 181; 174, attribute; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:current_block; 177, identifier:parent; 178, identifier:nodelist; 179, identifier:context; 180, identifier:instance_types; 181, attribute; 181, 182; 181, 183; 182, identifier:current_block; 183, identifier:parent; 184, elif_clause; 184, 185; 184, 198; 185, boolean_operator:and; 185, 186; 185, 193; 186, boolean_operator:and; 186, 187; 186, 192; 187, call; 187, 188; 187, 189; 188, identifier:isinstance; 189, argument_list; 189, 190; 189, 191; 190, identifier:node; 191, identifier:BlockNode; 192, identifier:ignore_blocks; 193, comparison_operator:in; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:node; 196, identifier:name; 197, identifier:ignore_blocks; 198, block; 198, 199; 199, continue_statement; 200, elif_clause; 200, 201; 200, 206; 201, call; 201, 202; 201, 203; 202, identifier:hasattr; 203, argument_list; 203, 204; 203, 205; 204, identifier:node; 205, string:'child_nodelists'; 206, block; 206, 207; 207, for_statement; 207, 208; 207, 209; 207, 212; 208, identifier:nodelist_name; 209, attribute; 209, 210; 209, 211; 210, identifier:node; 211, identifier:child_nodelists; 212, block; 212, 213; 213, if_statement; 213, 214; 213, 219; 214, call; 214, 215; 214, 216; 215, identifier:hasattr; 216, argument_list; 216, 217; 216, 218; 217, identifier:node; 218, identifier:nodelist_name; 219, block; 219, 220; 219, 228; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:subnodelist; 223, call; 223, 224; 223, 225; 224, identifier:getattr; 225, argument_list; 225, 226; 225, 227; 226, identifier:node; 227, identifier:nodelist_name; 228, if_statement; 228, 229; 228, 234; 229, call; 229, 230; 229, 231; 230, identifier:isinstance; 231, argument_list; 231, 232; 231, 233; 232, identifier:subnodelist; 233, identifier:NodeList; 234, block; 234, 235; 234, 246; 235, if_statement; 235, 236; 235, 241; 236, call; 236, 237; 236, 238; 237, identifier:isinstance; 238, argument_list; 238, 239; 238, 240; 239, identifier:node; 240, identifier:BlockNode; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:current_block; 245, identifier:node; 246, expression_statement; 246, 247; 247, augmented_assignment:+=; 247, 248; 247, 249; 248, identifier:results; 249, call; 249, 250; 249, 251; 250, identifier:_scan_nodes; 251, argument_list; 251, 252; 251, 253; 251, 254; 251, 255; 252, identifier:subnodelist; 253, identifier:context; 254, identifier:instance_types; 255, identifier:current_block; 256, else_clause; 256, 257; 257, block; 257, 258; 258, for_statement; 258, 259; 258, 260; 258, 264; 259, identifier:attr; 260, call; 260, 261; 260, 262; 261, identifier:dir; 262, argument_list; 262, 263; 263, identifier:node; 264, block; 264, 265; 264, 273; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:obj; 268, call; 268, 269; 268, 270; 269, identifier:getattr; 270, argument_list; 270, 271; 270, 272; 271, identifier:node; 272, identifier:attr; 273, if_statement; 273, 274; 273, 279; 274, call; 274, 275; 274, 276; 275, identifier:isinstance; 276, argument_list; 276, 277; 276, 278; 277, identifier:obj; 278, identifier:NodeList; 279, block; 279, 280; 279, 291; 280, if_statement; 280, 281; 280, 286; 281, call; 281, 282; 281, 283; 282, identifier:isinstance; 283, argument_list; 283, 284; 283, 285; 284, identifier:node; 285, identifier:BlockNode; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:current_block; 290, identifier:node; 291, expression_statement; 291, 292; 292, augmented_assignment:+=; 292, 293; 292, 294; 293, identifier:results; 294, call; 294, 295; 294, 296; 295, identifier:_scan_nodes; 296, argument_list; 296, 297; 296, 298; 296, 299; 296, 300; 297, identifier:obj; 298, identifier:context; 299, identifier:instance_types; 300, identifier:current_block; 301, return_statement; 301, 302; 302, identifier:results
def _scan_nodes(nodelist, context, instance_types, current_block=None, ignore_blocks=None): results = [] for node in nodelist: if isinstance(node, instance_types): results.append(node) elif isinstance(node, IncludeNode): if node.template: if not callable(getattr(node.template, 'render', None)): template = get_template(node.template.var) else: template = node.template if TemplateAdapter is not None and isinstance(template, TemplateAdapter): template = template.template results += _scan_nodes(template.nodelist, context, instance_types, current_block) elif isinstance(node, ExtendsNode): results += _extend_nodelist(node, context, instance_types) elif isinstance(node, VariableNode) and current_block: if node.filter_expression.token == 'block.super': if not hasattr(current_block.parent, 'nodelist'): raise TemplateSyntaxError( "Cannot read {{{{ block.super }}}} for {{% block {0} %}}, " "the parent template doesn't have this block.".format( current_block.name )) results += _scan_nodes(current_block.parent.nodelist, context, instance_types, current_block.parent) elif isinstance(node, BlockNode) and ignore_blocks and node.name in ignore_blocks: continue elif hasattr(node, 'child_nodelists'): for nodelist_name in node.child_nodelists: if hasattr(node, nodelist_name): subnodelist = getattr(node, nodelist_name) if isinstance(subnodelist, NodeList): if isinstance(node, BlockNode): current_block = node results += _scan_nodes(subnodelist, context, instance_types, current_block) else: for attr in dir(node): obj = getattr(node, attr) if isinstance(obj, NodeList): if isinstance(node, BlockNode): current_block = node results += _scan_nodes(obj, context, instance_types, current_block) return results
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run_command; 3, parameters; 3, 4; 4, identifier:commands; 5, block; 5, 6; 5, 10; 5, 14; 5, 18; 5, 177; 5, 182; 5, 221; 5, 231; 5, 237; 5, 245; 5, 264; 5, 276; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:use_shell; 9, False; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:subprocess_flags; 13, integer:0; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:startupinfo; 17, None; 18, if_statement; 18, 19; 18, 22; 18, 83; 19, comparison_operator:==; 19, 20; 19, 21; 20, identifier:sysstr; 21, string:'Windows'; 22, block; 22, 23; 22, 45; 22, 48; 22, 52; 22, 63; 22, 67; 22, 75; 23, if_statement; 23, 24; 23, 29; 24, call; 24, 25; 24, 26; 25, identifier:isinstance; 26, argument_list; 26, 27; 26, 28; 27, identifier:commands; 28, identifier:list; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:commands; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, string:' '; 36, identifier:join; 37, generator_expression; 37, 38; 37, 42; 38, call; 38, 39; 38, 40; 39, identifier:str; 40, argument_list; 40, 41; 41, identifier:c; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:c; 44, identifier:commands; 45, import_statement; 45, 46; 46, dotted_name; 46, 47; 47, identifier:ctypes; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:SEM_NOGPFAULTERRORBOX; 51, integer:0x0002; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 61; 54, attribute; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:ctypes; 58, identifier:windll; 59, identifier:kernel32; 60, identifier:SetErrorMode; 61, argument_list; 61, 62; 62, identifier:SEM_NOGPFAULTERRORBOX; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:subprocess_flags; 66, integer:0x8000000; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:startupinfo; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:subprocess; 73, identifier:STARTUPINFO; 74, argument_list; 75, expression_statement; 75, 76; 76, augmented_assignment:|=; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:startupinfo; 79, identifier:dwFlags; 80, attribute; 80, 81; 80, 82; 81, identifier:subprocess; 82, identifier:STARTF_USESHOWWINDOW; 83, else_clause; 83, 84; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 90; 85, 95; 86, call; 86, 87; 86, 88; 87, identifier:is_string; 88, argument_list; 88, 89; 89, identifier:commands; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:use_shell; 94, True; 95, elif_clause; 95, 96; 95, 101; 96, call; 96, 97; 96, 98; 97, identifier:isinstance; 98, argument_list; 98, 99; 98, 100; 99, identifier:commands; 100, identifier:list; 101, block; 101, 102; 101, 146; 102, if_statement; 102, 103; 102, 131; 103, boolean_operator:or; 103, 104; 103, 117; 103, 118; 104, comparison_operator:==; 104, 105; 104, 110; 104, 116; 105, subscript; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:commands; 108, integer:0; 109, integer:0; 110, subscript; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:commands; 113, integer:0; 114, unary_operator:-; 114, 115; 115, integer:1; 116, string:'"'; 117, line_continuation:\; 118, comparison_operator:==; 118, 119; 118, 124; 118, 130; 119, subscript; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:commands; 122, integer:0; 123, integer:0; 124, subscript; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:commands; 127, integer:0; 128, unary_operator:-; 128, 129; 129, integer:1; 130, string:"'"; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:commands; 136, integer:0; 137, subscript; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:commands; 140, integer:0; 141, slice; 141, 142; 141, 143; 141, 144; 142, integer:1; 143, colon; 144, unary_operator:-; 144, 145; 145, integer:1; 146, for_statement; 146, 147; 146, 150; 146, 154; 147, pattern_list; 147, 148; 147, 149; 148, identifier:idx; 149, identifier:v; 150, call; 150, 151; 150, 152; 151, identifier:enumerate; 152, argument_list; 152, 153; 153, identifier:commands; 154, block; 154, 155; 155, if_statement; 155, 156; 155, 167; 156, boolean_operator:or; 156, 157; 156, 162; 157, call; 157, 158; 157, 159; 158, identifier:isinstance; 159, argument_list; 159, 160; 159, 161; 160, identifier:v; 161, identifier:int; 162, call; 162, 163; 162, 164; 163, identifier:isinstance; 164, argument_list; 164, 165; 164, 166; 165, identifier:v; 166, identifier:float; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:commands; 172, identifier:idx; 173, call; 173, 174; 173, 175; 174, identifier:repr; 175, argument_list; 175, 176; 176, identifier:v; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:print; 180, argument_list; 180, 181; 181, identifier:commands; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:process; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:subprocess; 188, identifier:Popen; 189, argument_list; 189, 190; 189, 191; 189, 194; 189, 199; 189, 207; 189, 212; 189, 215; 189, 218; 190, identifier:commands; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:shell; 193, identifier:use_shell; 194, keyword_argument; 194, 195; 194, 196; 195, identifier:stdout; 196, attribute; 196, 197; 196, 198; 197, identifier:subprocess; 198, identifier:PIPE; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:stdin; 201, call; 201, 202; 201, 203; 202, identifier:open; 203, argument_list; 203, 204; 204, attribute; 204, 205; 204, 206; 205, identifier:os; 206, identifier:devnull; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:stderr; 209, attribute; 209, 210; 209, 211; 210, identifier:subprocess; 211, identifier:STDOUT; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:universal_newlines; 214, True; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:startupinfo; 217, identifier:startupinfo; 218, keyword_argument; 218, 219; 218, 220; 219, identifier:creationflags; 220, identifier:subprocess_flags; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 226; 223, pattern_list; 223, 224; 223, 225; 224, identifier:out; 225, identifier:err; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:process; 229, identifier:communicate; 230, argument_list; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:recode; 234, attribute; 234, 235; 234, 236; 235, identifier:process; 236, identifier:returncode; 237, if_statement; 237, 238; 237, 241; 238, comparison_operator:is; 238, 239; 238, 240; 239, identifier:out; 240, None; 241, block; 241, 242; 242, return_statement; 242, 243; 243, list:['']; 243, 244; 244, string:''; 245, if_statement; 245, 246; 245, 253; 246, boolean_operator:and; 246, 247; 246, 250; 247, comparison_operator:is; 247, 248; 247, 249; 248, identifier:recode; 249, None; 250, comparison_operator:!=; 250, 251; 250, 252; 251, identifier:recode; 252, integer:0; 253, block; 253, 254; 254, raise_statement; 254, 255; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:subprocess; 258, identifier:CalledProcessError; 259, argument_list; 259, 260; 259, 262; 259, 263; 260, unary_operator:-; 260, 261; 261, integer:1; 262, identifier:commands; 263, string:"ERROR occurred when running subprocess!"; 264, if_statement; 264, 265; 264, 268; 265, comparison_operator:in; 265, 266; 265, 267; 266, string:'\n'; 267, identifier:out; 268, block; 268, 269; 269, return_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:out; 273, identifier:split; 274, argument_list; 274, 275; 275, string:'\n'; 276, return_statement; 276, 277; 277, list:[out]; 277, 278; 278, identifier:out
def run_command(commands): use_shell = False subprocess_flags = 0 startupinfo = None if sysstr == 'Windows': if isinstance(commands, list): commands = ' '.join(str(c) for c in commands) import ctypes SEM_NOGPFAULTERRORBOX = 0x0002 ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX) subprocess_flags = 0x8000000 startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW else: if is_string(commands): use_shell = True elif isinstance(commands, list): if commands[0][0] == commands[0][-1] == '"' or \ commands[0][0] == commands[0][-1] == "'": commands[0] = commands[0][1:-1] for idx, v in enumerate(commands): if isinstance(v, int) or isinstance(v, float): commands[idx] = repr(v) print(commands) process = subprocess.Popen(commands, shell=use_shell, stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT, universal_newlines=True, startupinfo=startupinfo, creationflags=subprocess_flags) out, err = process.communicate() recode = process.returncode if out is None: return [''] if recode is not None and recode != 0: raise subprocess.CalledProcessError(-1, commands, "ERROR occurred when running subprocess!") if '\n' in out: return out.split('\n') return [out]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:intersect_keys; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:keys; 5, identifier:reffile; 6, default_parameter; 6, 7; 6, 8; 7, identifier:cache; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:clean_accs; 11, False; 12, block; 12, 13; 12, 17; 12, 107; 12, 139; 12, 153; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:index; 16, None; 17, if_statement; 17, 18; 17, 19; 17, 101; 18, identifier:cache; 19, block; 19, 20; 19, 26; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:refcache; 23, binary_operator:+; 23, 24; 23, 25; 24, identifier:reffile; 25, string:'.sqlite'; 26, if_statement; 26, 27; 26, 35; 27, call; 27, 28; 27, 33; 28, attribute; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:os; 31, identifier:path; 32, identifier:exists; 33, argument_list; 33, 34; 34, identifier:refcache; 35, block; 35, 36; 36, if_statement; 36, 37; 36, 54; 36, 62; 37, comparison_operator:<; 37, 38; 37, 46; 38, attribute; 38, 39; 38, 45; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:stat; 43, argument_list; 43, 44; 44, identifier:refcache; 45, identifier:st_mtime; 46, attribute; 46, 47; 46, 53; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:os; 50, identifier:stat; 51, argument_list; 51, 52; 52, identifier:reffile; 53, identifier:st_mtime; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logging; 59, identifier:warn; 60, argument_list; 60, 61; 61, string:"Outdated cache; rebuilding index"; 62, else_clause; 62, 63; 63, block; 63, 64; 64, try_statement; 64, 65; 64, 87; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:index; 69, parenthesized_expression; 69, 70; 70, conditional_expression:if; 70, 71; 70, 80; 70, 81; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:SeqIO; 74, identifier:index_db; 75, argument_list; 75, 76; 75, 77; 76, identifier:refcache; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:key_function; 79, identifier:clean_accession; 80, identifier:clean_accs; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:SeqIO; 84, identifier:index_db; 85, argument_list; 85, 86; 86, identifier:refcache; 87, except_clause; 87, 88; 87, 89; 88, identifier:Exception; 89, block; 89, 90; 89, 97; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logging; 94, identifier:warn; 95, argument_list; 95, 96; 96, string:"Skipping corrupted cache; rebuilding index"; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:index; 100, None; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:refcache; 106, string:':memory:'; 107, if_statement; 107, 108; 107, 111; 108, comparison_operator:is; 108, 109; 108, 110; 109, identifier:index; 110, None; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:index; 115, parenthesized_expression; 115, 116; 116, conditional_expression:if; 116, 117; 116, 129; 116, 130; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:SeqIO; 120, identifier:index_db; 121, argument_list; 121, 122; 121, 123; 121, 125; 121, 126; 122, identifier:refcache; 123, list:[reffile]; 123, 124; 124, identifier:reffile; 125, string:'fasta'; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:key_function; 128, identifier:clean_accession; 129, identifier:clean_accs; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:SeqIO; 133, identifier:index_db; 134, argument_list; 134, 135; 134, 136; 134, 138; 135, identifier:refcache; 136, list:[reffile]; 136, 137; 137, identifier:reffile; 138, string:'fasta'; 139, if_statement; 139, 140; 139, 141; 140, identifier:clean_accs; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:keys; 145, generator_expression; 145, 146; 145, 150; 146, call; 146, 147; 146, 148; 147, identifier:clean_accession; 148, argument_list; 148, 149; 149, identifier:k; 150, for_in_clause; 150, 151; 150, 152; 151, identifier:k; 152, identifier:keys; 153, for_statement; 153, 154; 153, 155; 153, 156; 154, identifier:key; 155, identifier:keys; 156, block; 156, 157; 156, 180; 157, try_statement; 157, 158; 157, 165; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:record; 162, subscript; 162, 163; 162, 164; 163, identifier:index; 164, identifier:key; 165, except_clause; 165, 166; 165, 167; 166, identifier:LookupError; 167, block; 167, 168; 167, 179; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:logging; 172, identifier:info; 173, argument_list; 173, 174; 173, 175; 174, string:"No match: %s"; 175, call; 175, 176; 175, 177; 176, identifier:repr; 177, argument_list; 177, 178; 178, identifier:key; 179, continue_statement; 180, expression_statement; 180, 181; 181, yield; 181, 182; 182, identifier:record
def intersect_keys(keys, reffile, cache=False, clean_accs=False): index = None if cache: refcache = reffile + '.sqlite' if os.path.exists(refcache): if os.stat(refcache).st_mtime < os.stat(reffile).st_mtime: logging.warn("Outdated cache; rebuilding index") else: try: index = (SeqIO.index_db(refcache, key_function=clean_accession) if clean_accs else SeqIO.index_db(refcache)) except Exception: logging.warn("Skipping corrupted cache; rebuilding index") index = None else: refcache = ':memory:' if index is None: index = (SeqIO.index_db(refcache, [reffile], 'fasta', key_function=clean_accession) if clean_accs else SeqIO.index_db(refcache, [reffile], 'fasta')) if clean_accs: keys = (clean_accession(k) for k in keys) for key in keys: try: record = index[key] except LookupError: logging.info("No match: %s", repr(key)) continue yield record
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:family_check; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 22; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 13; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:logger; 12, identifier:info; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, string:"Checking family relations for {0}"; 17, identifier:format; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:family_id; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:individual_id; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:individuals; 27, block; 27, 28; 27, 42; 27, 50; 27, 64; 27, 92; 27, 98; 27, 104; 27, 225; 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:logger; 34, identifier:debug; 35, argument_list; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:"Checking individual {0}"; 39, identifier:format; 40, argument_list; 40, 41; 41, identifier:individual_id; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:individual; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:individuals; 49, identifier:individual_id; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:logger; 56, identifier:debug; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:"Checking if individual {0} is affected"; 61, identifier:format; 62, argument_list; 62, 63; 63, identifier:individual_id; 64, if_statement; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:individual; 67, identifier:affected; 68, block; 68, 69; 68, 83; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:logger; 75, identifier:debug; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, string:"Found affected individual {0}"; 80, identifier:format; 81, argument_list; 81, 82; 82, identifier:individual_id; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:affected_individuals; 89, identifier:add; 90, argument_list; 90, 91; 91, identifier:individual_id; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:father; 95, attribute; 95, 96; 95, 97; 96, identifier:individual; 97, identifier:father; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:mother; 101, attribute; 101, 102; 101, 103; 102, identifier:individual; 103, identifier:mother; 104, if_statement; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:individual; 107, identifier:has_parents; 108, block; 108, 109; 108, 123; 108, 129; 108, 170; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:logger; 115, identifier:debug; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:"Individual {0} has parents"; 120, identifier:format; 121, argument_list; 121, 122; 122, identifier:individual_id; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:no_relations; 128, False; 129, try_statement; 129, 130; 129, 151; 130, block; 130, 131; 130, 141; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:check_parent; 136, argument_list; 136, 137; 136, 138; 137, identifier:father; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:father; 140, True; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:check_parent; 146, argument_list; 146, 147; 146, 148; 147, identifier:mother; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:father; 150, False; 151, except_clause; 151, 152; 151, 156; 152, as_pattern; 152, 153; 152, 154; 153, identifier:PedigreeError; 154, as_pattern_target; 154, 155; 155, identifier:e; 156, block; 156, 157; 156, 168; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:logger; 163, identifier:error; 164, argument_list; 164, 165; 165, attribute; 165, 166; 165, 167; 166, identifier:e; 167, identifier:message; 168, raise_statement; 168, 169; 169, identifier:e; 170, if_statement; 170, 171; 170, 174; 170, 190; 170, 209; 171, attribute; 171, 172; 171, 173; 172, identifier:individual; 173, identifier:has_both_parents; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:trios; 181, identifier:append; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 185; 184, identifier:set; 185, argument_list; 185, 186; 186, list:[individual_id, father, mother]; 186, 187; 186, 188; 186, 189; 187, identifier:individual_id; 188, identifier:father; 189, identifier:mother; 190, elif_clause; 190, 191; 190, 194; 191, comparison_operator:!=; 191, 192; 191, 193; 192, identifier:father; 193, string:'0'; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:duos; 201, identifier:append; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:set; 205, argument_list; 205, 206; 206, list:[individual_id, father]; 206, 207; 206, 208; 207, identifier:individual_id; 208, identifier:father; 209, else_clause; 209, 210; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:duos; 217, identifier:append; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 221; 220, identifier:set; 221, argument_list; 221, 222; 222, list:[individual_id, mother]; 222, 223; 222, 224; 223, identifier:individual_id; 224, identifier:mother; 225, for_statement; 225, 226; 225, 227; 225, 230; 226, identifier:individual_2_id; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:individuals; 230, block; 230, 231; 231, if_statement; 231, 232; 231, 235; 232, comparison_operator:!=; 232, 233; 232, 234; 233, identifier:individual_id; 234, identifier:individual_2_id; 235, block; 235, 236; 236, if_statement; 236, 237; 236, 244; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:check_siblings; 241, argument_list; 241, 242; 241, 243; 242, identifier:individual_id; 243, identifier:individual_2_id; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 252; 247, attribute; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:individual; 250, identifier:siblings; 251, identifier:add; 252, argument_list; 252, 253; 253, identifier:individual_2_id
def family_check(self): self.logger.info("Checking family relations for {0}".format( self.family_id) ) for individual_id in self.individuals: self.logger.debug("Checking individual {0}".format(individual_id)) individual = self.individuals[individual_id] self.logger.debug("Checking if individual {0} is affected".format( individual_id)) if individual.affected: self.logger.debug("Found affected individual {0}".format( individual_id) ) self.affected_individuals.add(individual_id) father = individual.father mother = individual.mother if individual.has_parents: self.logger.debug("Individual {0} has parents".format( individual_id)) self.no_relations = False try: self.check_parent(father, father=True) self.check_parent(mother, father=False) except PedigreeError as e: self.logger.error(e.message) raise e if individual.has_both_parents: self.trios.append(set([individual_id, father, mother])) elif father != '0': self.duos.append(set([individual_id, father])) else: self.duos.append(set([individual_id, mother])) for individual_2_id in self.individuals: if individual_id != individual_2_id: if self.check_siblings(individual_id, individual_2_id): individual.siblings.add(individual_2_id)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:to_ped; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:outfile; 7, None; 8, block; 8, 9; 8, 20; 8, 28; 8, 65; 8, 84; 8, 113; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:ped_header; 12, list:[ ' 'IndividualID', 'PaternalID', 'MaternalID', 'Sex', 'Phenotype', ]; 12, 13; 12, 14; 12, 16; 12, 17; 12, 18; 12, 19; 13, string:' '; 14, ERROR; 14, 15; 15, identifier:IndividualID; 16, string:'PaternalID'; 17, string:'MaternalID'; 18, string:'Sex'; 19, string:'Phenotype'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:extra_headers; 23, list:[ 'InheritanceModel', 'Proband', 'Consultand', 'Alive' ]; 23, 24; 23, 25; 23, 26; 23, 27; 24, string:'InheritanceModel'; 25, string:'Proband'; 26, string:'Consultand'; 27, string:'Alive'; 28, for_statement; 28, 29; 28, 30; 28, 33; 29, identifier:individual_id; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:individuals; 33, block; 33, 34; 33, 42; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:individual; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:individuals; 41, identifier:individual_id; 42, for_statement; 42, 43; 42, 44; 42, 47; 43, identifier:info; 44, attribute; 44, 45; 44, 46; 45, identifier:individual; 46, identifier:extra_info; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:in; 49, 50; 49, 51; 50, identifier:info; 51, identifier:extra_headers; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:not; 54, 55; 54, 56; 55, identifier:info; 56, identifier:ped_header; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:ped_header; 62, identifier:append; 63, argument_list; 63, 64; 64, identifier:info; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 72; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:logger; 71, identifier:debug; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, string:"Ped headers found: {0}"; 76, identifier:format; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, string:', '; 81, identifier:join; 82, argument_list; 82, 83; 83, identifier:ped_header; 84, if_statement; 84, 85; 84, 86; 84, 101; 85, identifier:outfile; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:outfile; 91, identifier:write; 92, argument_list; 92, 93; 93, binary_operator:+; 93, 94; 93, 100; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, string:'\t'; 97, identifier:join; 98, argument_list; 98, 99; 99, identifier:ped_header; 100, string:'\n'; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:print; 106, argument_list; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, string:'\t'; 110, identifier:join; 111, argument_list; 111, 112; 112, identifier:ped_header; 113, for_statement; 113, 114; 113, 115; 113, 120; 114, identifier:individual; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:to_json; 119, argument_list; 120, block; 120, 121; 120, 125; 120, 134; 120, 143; 120, 152; 120, 161; 120, 170; 120, 179; 120, 210; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:ped_info; 124, list:[]; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:ped_info; 129, identifier:append; 130, argument_list; 130, 131; 131, subscript; 131, 132; 131, 133; 132, identifier:individual; 133, string:'family_id'; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:ped_info; 138, identifier:append; 139, argument_list; 139, 140; 140, subscript; 140, 141; 140, 142; 141, identifier:individual; 142, string:'id'; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:ped_info; 147, identifier:append; 148, argument_list; 148, 149; 149, subscript; 149, 150; 149, 151; 150, identifier:individual; 151, string:'father'; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:ped_info; 156, identifier:append; 157, argument_list; 157, 158; 158, subscript; 158, 159; 158, 160; 159, identifier:individual; 160, string:'mother'; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:ped_info; 165, identifier:append; 166, argument_list; 166, 167; 167, subscript; 167, 168; 167, 169; 168, identifier:individual; 169, string:'sex'; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:ped_info; 174, identifier:append; 175, argument_list; 175, 176; 176, subscript; 176, 177; 176, 178; 177, identifier:individual; 178, string:'phenotype'; 179, if_statement; 179, 180; 179, 186; 180, comparison_operator:>; 180, 181; 180, 185; 181, call; 181, 182; 181, 183; 182, identifier:len; 183, argument_list; 183, 184; 184, identifier:ped_header; 185, integer:6; 186, block; 186, 187; 187, for_statement; 187, 188; 187, 189; 187, 194; 188, identifier:header; 189, subscript; 189, 190; 189, 191; 190, identifier:ped_header; 191, slice; 191, 192; 191, 193; 192, integer:6; 193, colon; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:ped_info; 199, identifier:append; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:individual; 205, string:'extra_info'; 206, identifier:get; 207, argument_list; 207, 208; 207, 209; 208, identifier:header; 209, string:'.'; 210, if_statement; 210, 211; 210, 212; 210, 227; 211, identifier:outfile; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:outfile; 217, identifier:write; 218, argument_list; 218, 219; 219, binary_operator:+; 219, 220; 219, 226; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, string:'\t'; 223, identifier:join; 224, argument_list; 224, 225; 225, identifier:ped_info; 226, string:'\n'; 227, else_clause; 227, 228; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:print; 232, argument_list; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, string:'\t'; 236, identifier:join; 237, argument_list; 237, 238; 238, identifier:ped_info
def to_ped(self, outfile=None): ped_header = [ ' 'IndividualID', 'PaternalID', 'MaternalID', 'Sex', 'Phenotype', ] extra_headers = [ 'InheritanceModel', 'Proband', 'Consultand', 'Alive' ] for individual_id in self.individuals: individual = self.individuals[individual_id] for info in individual.extra_info: if info in extra_headers: if info not in ped_header: ped_header.append(info) self.logger.debug("Ped headers found: {0}".format( ', '.join(ped_header) )) if outfile: outfile.write('\t'.join(ped_header)+'\n') else: print('\t'.join(ped_header)) for individual in self.to_json(): ped_info = [] ped_info.append(individual['family_id']) ped_info.append(individual['id']) ped_info.append(individual['father']) ped_info.append(individual['mother']) ped_info.append(individual['sex']) ped_info.append(individual['phenotype']) if len(ped_header) > 6: for header in ped_header[6:]: ped_info.append(individual['extra_info'].get(header, '.')) if outfile: outfile.write('\t'.join(ped_info)+'\n') else: print('\t'.join(ped_info))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:refresh_instruments; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 21; 5, 118; 5, 127; 5, 156; 6, function_definition; 6, 7; 6, 8; 6, 11; 7, function_name:list_access_nested_dict; 8, parameters; 8, 9; 8, 10; 9, identifier:dict; 10, identifier:somelist; 11, block; 11, 12; 12, return_statement; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:reduce; 15, argument_list; 15, 16; 15, 19; 15, 20; 16, attribute; 16, 17; 16, 18; 17, identifier:operator; 18, identifier:getitem; 19, identifier:somelist; 20, identifier:dict; 21, function_definition; 21, 22; 21, 23; 21, 25; 22, function_name:update; 23, parameters; 23, 24; 24, identifier:item; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 32; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:item; 30, identifier:isExpanded; 31, argument_list; 32, block; 32, 33; 33, for_statement; 33, 34; 33, 35; 33, 43; 34, identifier:index; 35, call; 35, 36; 35, 37; 36, identifier:range; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:item; 41, identifier:childCount; 42, argument_list; 43, block; 43, 44; 43, 53; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:child; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:item; 50, identifier:child; 51, argument_list; 51, 52; 52, identifier:index; 53, if_statement; 53, 54; 53, 61; 53, 111; 54, comparison_operator:==; 54, 55; 54, 60; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:child; 58, identifier:childCount; 59, argument_list; 60, integer:0; 61, block; 61, 62; 61, 72; 61, 78; 61, 105; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, pattern_list; 64, 65; 64, 66; 65, identifier:instrument; 66, identifier:path_to_instrument; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:child; 70, identifier:get_instrument; 71, argument_list; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:path_to_instrument; 76, identifier:reverse; 77, argument_list; 78, try_statement; 78, 79; 78, 92; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:value; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:instrument; 86, identifier:read_probes; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 90; 89, identifier:path_to_instrument; 90, unary_operator:-; 90, 91; 91, integer:1; 92, except_clause; 92, 93; 92, 94; 93, identifier:AssertionError; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:value; 98, call; 98, 99; 98, 100; 99, identifier:list_access_nested_dict; 100, argument_list; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:instrument; 103, identifier:settings; 104, identifier:path_to_instrument; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:child; 109, identifier:value; 110, identifier:value; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:update; 116, argument_list; 116, 117; 117, identifier:child; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 125; 120, attribute; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:tree_settings; 124, identifier:blockSignals; 125, argument_list; 125, 126; 126, True; 127, for_statement; 127, 128; 127, 129; 127, 139; 128, identifier:index; 129, call; 129, 130; 129, 131; 130, identifier:range; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 138; 133, attribute; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:tree_settings; 137, identifier:topLevelItemCount; 138, argument_list; 139, block; 139, 140; 139, 151; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:instrument; 143, call; 143, 144; 143, 149; 144, attribute; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:tree_settings; 148, identifier:topLevelItem; 149, argument_list; 149, 150; 150, identifier:index; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:update; 154, argument_list; 154, 155; 155, identifier:instrument; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:tree_settings; 162, identifier:blockSignals; 163, argument_list; 163, 164; 164, False
def refresh_instruments(self): def list_access_nested_dict(dict, somelist): return reduce(operator.getitem, somelist, dict) def update(item): if item.isExpanded(): for index in range(item.childCount()): child = item.child(index) if child.childCount() == 0: instrument, path_to_instrument = child.get_instrument() path_to_instrument.reverse() try: value = instrument.read_probes(path_to_instrument[-1]) except AssertionError: value = list_access_nested_dict(instrument.settings, path_to_instrument) child.value = value else: update(child) self.tree_settings.blockSignals(True) for index in range(self.tree_settings.topLevelItemCount()): instrument = self.tree_settings.topLevelItem(index) update(instrument) self.tree_settings.blockSignals(False)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:post; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:endpoint; 6, identifier:data; 7, default_parameter; 7, 8; 7, 9; 8, identifier:parallelism; 9, integer:5; 10, block; 10, 11; 10, 45; 10, 57; 10, 71; 10, 79; 10, 115; 10, 127; 10, 131; 10, 138; 10, 205; 10, 242; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:headers; 14, dictionary; 14, 15; 14, 18; 14, 21; 14, 29; 14, 37; 15, pair; 15, 16; 15, 17; 16, string:"Content-Type"; 17, string:"application/json"; 18, pair; 18, 19; 18, 20; 19, string:"Accept"; 20, string:"application/json"; 21, pair; 21, 22; 21, 23; 22, string:"x-standardize-only"; 23, conditional_expression:if; 23, 24; 23, 25; 23, 28; 24, string:"true"; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:standardize; 28, string:"false"; 29, pair; 29, 30; 29, 31; 30, string:"x-include-invalid"; 31, conditional_expression:if; 31, 32; 31, 33; 31, 36; 32, string:"true"; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:invalid; 36, string:"false"; 37, pair; 37, 38; 37, 39; 38, string:"x-accept-keypair"; 39, conditional_expression:if; 39, 40; 39, 41; 39, 44; 40, string:"true"; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:accept_keypair; 44, string:"false"; 45, if_statement; 45, 46; 45, 50; 46, not_operator; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:logging; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:headers; 55, string:"x-suppress-logging"; 56, string:"false"; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:params; 60, dictionary; 60, 61; 60, 66; 61, pair; 61, 62; 61, 63; 62, string:"auth-id"; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:auth_id; 66, pair; 66, 67; 66, 68; 67, string:"auth-token"; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:auth_token; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:url; 74, binary_operator:+; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:BASE_URL; 78, identifier:endpoint; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:rs; 82, generator_expression; 82, 83; 82, 108; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:grequests; 86, identifier:post; 87, argument_list; 87, 88; 87, 91; 87, 102; 87, 105; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:url; 90, identifier:url; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:data; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:json; 96, identifier:dumps; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:stringify; 100, argument_list; 100, 101; 101, identifier:data_chunk; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:params; 104, identifier:params; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:headers; 107, identifier:headers; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:data_chunk; 110, call; 110, 111; 110, 112; 111, identifier:chunker; 112, argument_list; 112, 113; 112, 114; 113, identifier:data; 114, integer:100; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:responses; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:grequests; 121, identifier:imap; 122, argument_list; 122, 123; 122, 124; 123, identifier:rs; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:size; 126, identifier:parallelism; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:status_codes; 130, dictionary; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:addresses; 134, call; 134, 135; 134, 136; 135, identifier:AddressCollection; 136, argument_list; 136, 137; 137, list:[]; 138, for_statement; 138, 139; 138, 140; 138, 141; 139, identifier:response; 140, identifier:responses; 141, block; 141, 142; 141, 171; 142, if_statement; 142, 143; 142, 152; 142, 161; 143, comparison_operator:not; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:response; 146, identifier:status_code; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:status_codes; 150, identifier:keys; 151, argument_list; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 160; 155, subscript; 155, 156; 155, 157; 156, identifier:status_codes; 157, attribute; 157, 158; 157, 159; 158, identifier:response; 159, identifier:status_code; 160, integer:1; 161, else_clause; 161, 162; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, augmented_assignment:+=; 164, 165; 164, 170; 165, subscript; 165, 166; 165, 167; 166, identifier:status_codes; 167, attribute; 167, 168; 167, 169; 168, identifier:response; 169, identifier:status_code; 170, integer:1; 171, if_statement; 171, 172; 171, 177; 171, 194; 172, comparison_operator:==; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:response; 175, identifier:status_code; 176, integer:200; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 186; 180, subscript; 180, 181; 180, 182; 181, identifier:addresses; 182, slice; 182, 183; 182, 184; 182, 185; 183, integer:0; 184, colon; 185, integer:0; 186, call; 186, 187; 186, 188; 187, identifier:AddressCollection; 188, argument_list; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:response; 192, identifier:json; 193, argument_list; 194, elif_clause; 194, 195; 194, 200; 195, comparison_operator:==; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:response; 198, identifier:status_code; 199, integer:401; 200, block; 200, 201; 201, raise_statement; 201, 202; 202, subscript; 202, 203; 202, 204; 203, identifier:ERROR_CODES; 204, integer:401; 205, if_statement; 205, 206; 205, 216; 206, comparison_operator:==; 206, 207; 206, 215; 207, call; 207, 208; 207, 209; 208, identifier:len; 209, argument_list; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:status_codes; 213, identifier:keys; 214, argument_list; 215, integer:1; 216, block; 216, 217; 217, if_statement; 217, 218; 217, 221; 217, 226; 218, comparison_operator:in; 218, 219; 218, 220; 219, integer:200; 220, identifier:status_codes; 221, block; 221, 222; 222, return_statement; 222, 223; 223, expression_list; 223, 224; 223, 225; 224, identifier:addresses; 225, identifier:status_codes; 226, else_clause; 226, 227; 227, block; 227, 228; 228, raise_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:ERROR_CODES; 232, identifier:get; 233, argument_list; 233, 234; 233, 241; 234, subscript; 234, 235; 234, 240; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:status_codes; 238, identifier:keys; 239, argument_list; 240, integer:0; 241, identifier:SmartyStreetsError; 242, return_statement; 242, 243; 243, expression_list; 243, 244; 243, 245; 244, identifier:addresses; 245, identifier:status_codes
def post(self, endpoint, data, parallelism=5): headers = { "Content-Type": "application/json", "Accept": "application/json", "x-standardize-only": "true" if self.standardize else "false", "x-include-invalid": "true" if self.invalid else "false", "x-accept-keypair": "true" if self.accept_keypair else "false", } if not self.logging: headers["x-suppress-logging"] = "false" params = {"auth-id": self.auth_id, "auth-token": self.auth_token} url = self.BASE_URL + endpoint rs = ( grequests.post( url=url, data=json.dumps(stringify(data_chunk)), params=params, headers=headers, ) for data_chunk in chunker(data, 100) ) responses = grequests.imap(rs, size=parallelism) status_codes = {} addresses = AddressCollection([]) for response in responses: if response.status_code not in status_codes.keys(): status_codes[response.status_code] = 1 else: status_codes[response.status_code] += 1 if response.status_code == 200: addresses[0:0] = AddressCollection( response.json() ) elif response.status_code == 401: raise ERROR_CODES[401] if len(status_codes.keys()) == 1: if 200 in status_codes: return addresses, status_codes else: raise ERROR_CODES.get(status_codes.keys()[0], SmartyStreetsError) return addresses, status_codes
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_contents_static; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:block_alias; 6, identifier:context; 7, block; 7, 8; 7, 15; 7, 23; 7, 66; 7, 72; 7, 79; 7, 88; 7, 270; 7, 276; 7, 287; 7, 296; 7, 306; 7, 327; 7, 331; 7, 387; 8, if_statement; 8, 9; 8, 12; 9, comparison_operator:not; 9, 10; 9, 11; 10, string:'request'; 11, identifier:context; 12, block; 12, 13; 13, return_statement; 13, 14; 14, string:''; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:current_url; 18, attribute; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:context; 21, string:'request'; 22, identifier:path; 23, try_statement; 23, 24; 23, 59; 24, block; 24, 25; 24, 32; 24, 36; 24, 49; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:resolver_match; 28, call; 28, 29; 28, 30; 29, identifier:resolve; 30, argument_list; 30, 31; 31, identifier:current_url; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:namespace; 35, string:''; 36, if_statement; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:resolver_match; 39, identifier:namespaces; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:namespace; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:resolver_match; 47, identifier:namespaces; 48, integer:0; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:resolved_view_name; 52, binary_operator:%; 52, 53; 52, 54; 53, string:':%s:%s'; 54, tuple; 54, 55; 54, 56; 55, identifier:namespace; 56, attribute; 56, 57; 56, 58; 57, identifier:resolver_match; 58, identifier:url_name; 59, except_clause; 59, 60; 59, 61; 60, identifier:Resolver404; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:resolved_view_name; 65, None; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_cache_init; 71, argument_list; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:cache_entry_name; 75, call; 75, 76; 75, 77; 76, identifier:cache_get_key; 77, argument_list; 77, 78; 78, identifier:block_alias; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:siteblocks_static; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_cache_get; 86, argument_list; 86, 87; 87, identifier:cache_entry_name; 88, if_statement; 88, 89; 88, 91; 89, not_operator; 89, 90; 90, identifier:siteblocks_static; 91, block; 91, 92; 91, 114; 91, 126; 91, 262; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:blocks; 95, call; 95, 96; 95, 111; 96, attribute; 96, 97; 96, 110; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:Block; 101, identifier:objects; 102, identifier:filter; 103, argument_list; 103, 104; 103, 107; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:alias; 106, identifier:block_alias; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:hidden; 109, False; 110, identifier:only; 111, argument_list; 111, 112; 111, 113; 112, string:'url'; 113, string:'contents'; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:siteblocks_static; 117, list:[defaultdict(list), defaultdict(list)]; 117, 118; 117, 122; 118, call; 118, 119; 118, 120; 119, identifier:defaultdict; 120, argument_list; 120, 121; 121, identifier:list; 122, call; 122, 123; 122, 124; 123, identifier:defaultdict; 124, argument_list; 124, 125; 125, identifier:list; 126, for_statement; 126, 127; 126, 128; 126, 129; 127, identifier:block; 128, identifier:blocks; 129, block; 129, 130; 129, 190; 130, if_statement; 130, 131; 130, 136; 130, 143; 130, 175; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:block; 134, identifier:url; 135, string:'*'; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:url_re; 140, attribute; 140, 141; 140, 142; 141, identifier:block; 142, identifier:url; 143, elif_clause; 143, 144; 143, 152; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:block; 148, identifier:url; 149, identifier:startswith; 150, argument_list; 150, 151; 151, string:':'; 152, block; 152, 153; 152, 159; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:url_re; 156, attribute; 156, 157; 156, 158; 157, identifier:block; 158, identifier:url; 159, if_statement; 159, 160; 159, 168; 160, comparison_operator:==; 160, 161; 160, 167; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:url_re; 164, identifier:count; 165, argument_list; 165, 166; 166, string:':'; 167, integer:1; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:url_re; 172, binary_operator:%; 172, 173; 172, 174; 173, string:':%s'; 174, identifier:url_re; 175, else_clause; 175, 176; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:url_re; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:re; 183, identifier:compile; 184, argument_list; 184, 185; 185, binary_operator:%; 185, 186; 185, 187; 186, string:r'%s'; 187, attribute; 187, 188; 187, 189; 188, identifier:block; 189, identifier:url; 190, if_statement; 190, 191; 190, 194; 190, 210; 190, 230; 191, attribute; 191, 192; 191, 193; 192, identifier:block; 193, identifier:access_guest; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 206; 197, attribute; 197, 198; 197, 205; 198, subscript; 198, 199; 198, 204; 199, subscript; 199, 200; 199, 201; 200, identifier:siteblocks_static; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:IDX_GUEST; 204, identifier:url_re; 205, identifier:append; 206, argument_list; 206, 207; 207, attribute; 207, 208; 207, 209; 208, identifier:block; 209, identifier:contents; 210, elif_clause; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:block; 213, identifier:access_loggedin; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 226; 217, attribute; 217, 218; 217, 225; 218, subscript; 218, 219; 218, 224; 219, subscript; 219, 220; 219, 221; 220, identifier:siteblocks_static; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:IDX_AUTH; 224, identifier:url_re; 225, identifier:append; 226, argument_list; 226, 227; 227, attribute; 227, 228; 227, 229; 228, identifier:block; 229, identifier:contents; 230, else_clause; 230, 231; 231, block; 231, 232; 231, 247; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 243; 234, attribute; 234, 235; 234, 242; 235, subscript; 235, 236; 235, 241; 236, subscript; 236, 237; 236, 238; 237, identifier:siteblocks_static; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:IDX_GUEST; 241, identifier:url_re; 242, identifier:append; 243, argument_list; 243, 244; 244, attribute; 244, 245; 244, 246; 245, identifier:block; 246, identifier:contents; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 258; 249, attribute; 249, 250; 249, 257; 250, subscript; 250, 251; 250, 256; 251, subscript; 251, 252; 251, 253; 252, identifier:siteblocks_static; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:IDX_AUTH; 256, identifier:url_re; 257, identifier:append; 258, argument_list; 258, 259; 259, attribute; 259, 260; 259, 261; 260, identifier:block; 261, identifier:contents; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:_cache_set; 267, argument_list; 267, 268; 267, 269; 268, identifier:cache_entry_name; 269, identifier:siteblocks_static; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:_cache_save; 275, argument_list; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:user; 279, call; 279, 280; 279, 281; 280, identifier:getattr; 281, argument_list; 281, 282; 281, 285; 281, 286; 282, subscript; 282, 283; 282, 284; 283, identifier:context; 284, string:'request'; 285, string:'user'; 286, None; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:is_authenticated; 290, call; 290, 291; 290, 292; 291, identifier:getattr; 292, argument_list; 292, 293; 292, 294; 292, 295; 293, identifier:user; 294, string:'is_authenticated'; 295, False; 296, if_statement; 296, 297; 296, 299; 297, not_operator; 297, 298; 298, identifier:DJANGO_2; 299, block; 299, 300; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:is_authenticated; 303, call; 303, 304; 303, 305; 304, identifier:is_authenticated; 305, argument_list; 306, if_statement; 306, 307; 306, 308; 306, 317; 307, identifier:is_authenticated; 308, block; 308, 309; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:lookup_area; 312, subscript; 312, 313; 312, 314; 313, identifier:siteblocks_static; 314, attribute; 314, 315; 314, 316; 315, identifier:self; 316, identifier:IDX_AUTH; 317, else_clause; 317, 318; 318, block; 318, 319; 319, expression_statement; 319, 320; 320, assignment; 320, 321; 320, 322; 321, identifier:lookup_area; 322, subscript; 322, 323; 322, 324; 323, identifier:siteblocks_static; 324, attribute; 324, 325; 324, 326; 325, identifier:self; 326, identifier:IDX_GUEST; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 330; 329, identifier:static_block_contents; 330, string:''; 331, if_statement; 331, 332; 331, 335; 331, 345; 331, 359; 332, comparison_operator:in; 332, 333; 332, 334; 333, string:'*'; 334, identifier:lookup_area; 335, block; 335, 336; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:static_block_contents; 339, call; 339, 340; 339, 341; 340, identifier:choice; 341, argument_list; 341, 342; 342, subscript; 342, 343; 342, 344; 343, identifier:lookup_area; 344, string:'*'; 345, elif_clause; 345, 346; 345, 349; 346, comparison_operator:in; 346, 347; 346, 348; 347, identifier:resolved_view_name; 348, identifier:lookup_area; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 353; 352, identifier:static_block_contents; 353, call; 353, 354; 353, 355; 354, identifier:choice; 355, argument_list; 355, 356; 356, subscript; 356, 357; 356, 358; 357, identifier:lookup_area; 358, identifier:resolved_view_name; 359, else_clause; 359, 360; 360, block; 360, 361; 361, for_statement; 361, 362; 361, 365; 361, 370; 362, pattern_list; 362, 363; 362, 364; 363, identifier:url; 364, identifier:contents; 365, call; 365, 366; 365, 369; 366, attribute; 366, 367; 366, 368; 367, identifier:lookup_area; 368, identifier:items; 369, argument_list; 370, block; 370, 371; 371, if_statement; 371, 372; 371, 378; 372, call; 372, 373; 372, 376; 373, attribute; 373, 374; 373, 375; 374, identifier:url; 375, identifier:match; 376, argument_list; 376, 377; 377, identifier:current_url; 378, block; 378, 379; 378, 386; 379, expression_statement; 379, 380; 380, assignment; 380, 381; 380, 382; 381, identifier:static_block_contents; 382, call; 382, 383; 382, 384; 383, identifier:choice; 384, argument_list; 384, 385; 385, identifier:contents; 386, break_statement; 387, return_statement; 387, 388; 388, identifier:static_block_contents
def get_contents_static(self, block_alias, context): if 'request' not in context: return '' current_url = context['request'].path try: resolver_match = resolve(current_url) namespace = '' if resolver_match.namespaces: namespace = resolver_match.namespaces[0] resolved_view_name = ':%s:%s' % (namespace, resolver_match.url_name) except Resolver404: resolved_view_name = None self._cache_init() cache_entry_name = cache_get_key(block_alias) siteblocks_static = self._cache_get(cache_entry_name) if not siteblocks_static: blocks = Block.objects.filter(alias=block_alias, hidden=False).only('url', 'contents') siteblocks_static = [defaultdict(list), defaultdict(list)] for block in blocks: if block.url == '*': url_re = block.url elif block.url.startswith(':'): url_re = block.url if url_re.count(':') == 1: url_re = ':%s' % url_re else: url_re = re.compile(r'%s' % block.url) if block.access_guest: siteblocks_static[self.IDX_GUEST][url_re].append(block.contents) elif block.access_loggedin: siteblocks_static[self.IDX_AUTH][url_re].append(block.contents) else: siteblocks_static[self.IDX_GUEST][url_re].append(block.contents) siteblocks_static[self.IDX_AUTH][url_re].append(block.contents) self._cache_set(cache_entry_name, siteblocks_static) self._cache_save() user = getattr(context['request'], 'user', None) is_authenticated = getattr(user, 'is_authenticated', False) if not DJANGO_2: is_authenticated = is_authenticated() if is_authenticated: lookup_area = siteblocks_static[self.IDX_AUTH] else: lookup_area = siteblocks_static[self.IDX_GUEST] static_block_contents = '' if '*' in lookup_area: static_block_contents = choice(lookup_area['*']) elif resolved_view_name in lookup_area: static_block_contents = choice(lookup_area[resolved_view_name]) else: for url, contents in lookup_area.items(): if url.match(current_url): static_block_contents = choice(contents) break return static_block_contents
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:files_to_pif; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:files; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:quality_report; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:inline; 13, True; 14, block; 14, 15; 14, 17; 14, 21; 14, 45; 14, 54; 14, 73; 14, 79; 14, 89; 14, 109; 14, 122; 14, 126; 14, 179; 14, 185; 14, 312; 14, 327; 15, expression_statement; 15, 16; 16, string:'''Given a directory that contains output from a DFT calculation, parse the data and return a pif object Input: files - [str] list of files from which the parser is allowed to read. verbose - int, How much status messages to print Output: pif - ChemicalSystem, Results and settings of the DFT calculation in pif format '''; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:found_parser; 20, False; 21, for_statement; 21, 22; 21, 23; 21, 26; 22, identifier:possible_parser; 23, list:[PwscfParser, VaspParser]; 23, 24; 23, 25; 24, identifier:PwscfParser; 25, identifier:VaspParser; 26, block; 26, 27; 27, try_statement; 27, 28; 27, 41; 28, block; 28, 29; 28, 36; 28, 40; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:parser; 32, call; 32, 33; 32, 34; 33, identifier:possible_parser; 34, argument_list; 34, 35; 35, identifier:files; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:found_parser; 39, True; 40, break_statement; 41, except_clause; 41, 42; 41, 43; 42, identifier:InvalidIngesterException; 43, block; 43, 44; 44, pass_statement; 45, if_statement; 45, 46; 45, 48; 46, not_operator; 46, 47; 47, identifier:found_parser; 48, block; 48, 49; 49, raise_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:Exception; 52, argument_list; 52, 53; 53, string:'Directory is not in correct format for an existing parser'; 54, if_statement; 54, 55; 54, 58; 55, comparison_operator:>; 55, 56; 55, 57; 56, identifier:verbose; 57, integer:0; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 62; 61, identifier:print; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, string:"Found a {} directory"; 66, identifier:format; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:parser; 71, identifier:get_name; 72, argument_list; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:chem; 76, call; 76, 77; 76, 78; 77, identifier:ChemicalSystem; 78, argument_list; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:chem; 83, identifier:chemical_formula; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:parser; 87, identifier:get_composition; 88, argument_list; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:software; 92, call; 92, 93; 92, 94; 93, identifier:Software; 94, argument_list; 94, 95; 94, 102; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:name; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:parser; 100, identifier:get_name; 101, argument_list; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:version; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:parser; 107, identifier:get_version_number; 108, argument_list; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:method; 112, call; 112, 113; 112, 114; 113, identifier:Method; 114, argument_list; 114, 115; 114, 118; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:name; 117, string:'Density Functional Theory'; 118, keyword_argument; 118, 119; 118, 120; 119, identifier:software; 120, list:[software]; 120, 121; 121, identifier:software; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:conditions; 125, list:[]; 126, for_statement; 126, 127; 126, 130; 126, 139; 127, pattern_list; 127, 128; 127, 129; 128, identifier:name; 129, identifier:func; 130, call; 130, 131; 130, 138; 131, attribute; 131, 132; 131, 137; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:parser; 135, identifier:get_setting_functions; 136, argument_list; 137, identifier:items; 138, argument_list; 139, block; 139, 140; 139, 150; 139, 156; 139, 166; 139, 172; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:cond; 143, call; 143, 144; 143, 149; 144, call; 144, 145; 144, 146; 145, identifier:getattr; 146, argument_list; 146, 147; 146, 148; 147, identifier:parser; 148, identifier:func; 149, argument_list; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:is; 151, 152; 151, 153; 152, identifier:cond; 153, None; 154, block; 154, 155; 155, continue_statement; 156, if_statement; 156, 157; 156, 164; 157, boolean_operator:and; 157, 158; 157, 159; 158, identifier:inline; 159, comparison_operator:is; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:cond; 162, identifier:files; 163, None; 164, block; 164, 165; 165, continue_statement; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:cond; 170, identifier:name; 171, identifier:name; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:conditions; 176, identifier:append; 177, argument_list; 177, 178; 178, identifier:cond; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:chem; 183, identifier:properties; 184, list:[]; 185, for_statement; 185, 186; 185, 189; 185, 198; 186, pattern_list; 186, 187; 186, 188; 187, identifier:name; 188, identifier:func; 189, call; 189, 190; 189, 197; 190, attribute; 190, 191; 190, 196; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:parser; 194, identifier:get_result_functions; 195, argument_list; 196, identifier:items; 197, argument_list; 198, block; 198, 199; 198, 209; 198, 215; 198, 225; 198, 231; 198, 238; 198, 244; 198, 260; 198, 303; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:prop; 202, call; 202, 203; 202, 208; 203, call; 203, 204; 203, 205; 204, identifier:getattr; 205, argument_list; 205, 206; 205, 207; 206, identifier:parser; 207, identifier:func; 208, argument_list; 209, if_statement; 209, 210; 209, 213; 210, comparison_operator:is; 210, 211; 210, 212; 211, identifier:prop; 212, None; 213, block; 213, 214; 214, continue_statement; 215, if_statement; 215, 216; 215, 223; 216, boolean_operator:and; 216, 217; 216, 218; 217, identifier:inline; 218, comparison_operator:is; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:prop; 221, identifier:files; 222, None; 223, block; 223, 224; 224, continue_statement; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:prop; 229, identifier:name; 230, identifier:name; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:prop; 235, identifier:methods; 236, list:[method,]; 236, 237; 237, identifier:method; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:prop; 242, identifier:data_type; 243, string:'COMPUTATIONAL'; 244, if_statement; 244, 245; 244, 254; 245, boolean_operator:and; 245, 246; 245, 249; 246, comparison_operator:>; 246, 247; 246, 248; 247, identifier:verbose; 248, integer:0; 249, call; 249, 250; 249, 251; 250, identifier:isinstance; 251, argument_list; 251, 252; 251, 253; 252, identifier:prop; 253, identifier:Value; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:print; 258, argument_list; 258, 259; 259, identifier:name; 260, if_statement; 260, 261; 260, 266; 260, 273; 261, comparison_operator:is; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:prop; 264, identifier:conditions; 265, None; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:prop; 271, identifier:conditions; 272, identifier:conditions; 273, else_clause; 273, 274; 274, block; 274, 275; 274, 294; 275, if_statement; 275, 276; 275, 284; 276, not_operator; 276, 277; 277, call; 277, 278; 277, 279; 278, identifier:isinstance; 279, argument_list; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:prop; 282, identifier:conditions; 283, identifier:list; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:prop; 289, identifier:conditions; 290, list:[prop.conditions]; 290, 291; 291, attribute; 291, 292; 291, 293; 292, identifier:prop; 293, identifier:conditions; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 301; 296, attribute; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:prop; 299, identifier:conditions; 300, identifier:extend; 301, argument_list; 301, 302; 302, identifier:conditions; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 310; 305, attribute; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:chem; 308, identifier:properties; 309, identifier:append; 310, argument_list; 310, 311; 311, identifier:prop; 312, if_statement; 312, 313; 312, 320; 313, boolean_operator:and; 313, 314; 313, 315; 314, identifier:quality_report; 315, call; 315, 316; 315, 317; 316, identifier:isinstance; 317, argument_list; 317, 318; 317, 319; 318, identifier:parser; 319, identifier:VaspParser; 320, block; 320, 321; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 324; 323, identifier:_add_quality_report; 324, argument_list; 324, 325; 324, 326; 325, identifier:parser; 326, identifier:chem; 327, return_statement; 327, 328; 328, identifier:chem
def files_to_pif(files, verbose=0, quality_report=True, inline=True): '''Given a directory that contains output from a DFT calculation, parse the data and return a pif object Input: files - [str] list of files from which the parser is allowed to read. verbose - int, How much status messages to print Output: pif - ChemicalSystem, Results and settings of the DFT calculation in pif format ''' found_parser = False for possible_parser in [PwscfParser, VaspParser]: try: parser = possible_parser(files) found_parser = True break except InvalidIngesterException: pass if not found_parser: raise Exception('Directory is not in correct format for an existing parser') if verbose > 0: print("Found a {} directory".format(parser.get_name())) chem = ChemicalSystem() chem.chemical_formula = parser.get_composition() software = Software(name=parser.get_name(), version=parser.get_version_number()) method = Method(name='Density Functional Theory', software=[software]) conditions = [] for name, func in parser.get_setting_functions().items(): cond = getattr(parser, func)() if cond is None: continue if inline and cond.files is not None: continue cond.name = name conditions.append(cond) chem.properties = [] for name, func in parser.get_result_functions().items(): prop = getattr(parser, func)() if prop is None: continue if inline and prop.files is not None: continue prop.name = name prop.methods = [method,] prop.data_type='COMPUTATIONAL' if verbose > 0 and isinstance(prop, Value): print(name) if prop.conditions is None: prop.conditions = conditions else: if not isinstance(prop.conditions, list): prop.conditions = [prop.conditions] prop.conditions.extend(conditions) chem.properties.append(prop) if quality_report and isinstance(parser, VaspParser): _add_quality_report(parser, chem) return chem
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 11; 2, function_name:_sort_cards; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:cards; 7, type; 7, 8; 8, identifier:Generator; 9, type; 9, 10; 10, identifier:list; 11, block; 11, 12; 11, 14; 12, expression_statement; 12, 13; 13, string:'''sort cards by blocknum and blockseq'''; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 25; 18, list_comprehension; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:card; 21, identifier:__dict__; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:card; 24, identifier:cards; 25, keyword_argument; 25, 26; 25, 27; 26, identifier:key; 27, call; 27, 28; 27, 29; 28, identifier:itemgetter; 29, argument_list; 29, 30; 29, 31; 29, 32; 30, string:'blocknum'; 31, string:'blockseq'; 32, string:'cardseq'
def _sort_cards(self, cards: Generator) -> list: '''sort cards by blocknum and blockseq''' return sorted([card.__dict__ for card in cards], key=itemgetter('blocknum', 'blockseq', 'cardseq'))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_label; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, string:'''Find the label for the output files for this calculation '''; 8, if_statement; 8, 9; 8, 14; 8, 219; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_label; 13, None; 14, block; 14, 15; 14, 19; 14, 205; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:foundfiles; 18, False; 19, for_statement; 19, 20; 19, 21; 19, 24; 20, identifier:f; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_files; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:in; 26, 27; 26, 28; 27, string:".files"; 28, identifier:f; 29, block; 29, 30; 29, 34; 29, 47; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:foundfiles; 33, True; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_label; 39, subscript; 39, 40; 39, 46; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:f; 43, identifier:split; 44, argument_list; 44, 45; 45, string:"."; 46, integer:0; 47, with_statement; 47, 48; 47, 62; 48, with_clause; 48, 49; 49, with_item; 49, 50; 50, as_pattern; 50, 51; 50, 60; 51, call; 51, 52; 51, 53; 52, identifier:open; 53, argument_list; 53, 54; 53, 59; 54, binary_operator:+; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_label; 58, string:'.files'; 59, string:'r'; 60, as_pattern_target; 60, 61; 61, identifier:fp; 62, block; 62, 63; 62, 77; 62, 97; 62, 111; 62, 131; 62, 145; 62, 165; 62, 179; 62, 199; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:line; 66, subscript; 66, 67; 66, 76; 67, call; 67, 68; 67, 75; 68, attribute; 68, 69; 68, 74; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:fp; 72, identifier:readline; 73, argument_list; 74, identifier:split; 75, argument_list; 76, integer:0; 77, if_statement; 77, 78; 77, 85; 78, comparison_operator:!=; 78, 79; 78, 80; 79, identifier:line; 80, binary_operator:+; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_label; 84, string:".in"; 85, block; 85, 86; 85, 92; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:fp; 90, identifier:close; 91, argument_list; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:Exception; 95, argument_list; 95, 96; 96, string:'first line must be label.in'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:line; 100, subscript; 100, 101; 100, 110; 101, call; 101, 102; 101, 109; 102, attribute; 102, 103; 102, 108; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:fp; 106, identifier:readline; 107, argument_list; 108, identifier:split; 109, argument_list; 110, integer:0; 111, if_statement; 111, 112; 111, 119; 112, comparison_operator:!=; 112, 113; 112, 114; 113, identifier:line; 114, binary_operator:+; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:_label; 118, string:".txt"; 119, block; 119, 120; 119, 126; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:fp; 124, identifier:close; 125, argument_list; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:Exception; 129, argument_list; 129, 130; 130, string:'second line must be label.txt'; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:line; 134, subscript; 134, 135; 134, 144; 135, call; 135, 136; 135, 143; 136, attribute; 136, 137; 136, 142; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:fp; 140, identifier:readline; 141, argument_list; 142, identifier:split; 143, argument_list; 144, integer:0; 145, if_statement; 145, 146; 145, 153; 146, comparison_operator:!=; 146, 147; 146, 148; 147, identifier:line; 148, binary_operator:+; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:_label; 152, string:"i"; 153, block; 153, 154; 153, 160; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:fp; 158, identifier:close; 159, argument_list; 160, raise_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:Exception; 163, argument_list; 163, 164; 164, string:'third line must be labeli'; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:line; 168, subscript; 168, 169; 168, 178; 169, call; 169, 170; 169, 177; 170, attribute; 170, 171; 170, 176; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:fp; 174, identifier:readline; 175, argument_list; 176, identifier:split; 177, argument_list; 178, integer:0; 179, if_statement; 179, 180; 179, 187; 180, comparison_operator:!=; 180, 181; 180, 182; 181, identifier:line; 182, binary_operator:+; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:_label; 186, string:"o"; 187, block; 187, 188; 187, 194; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:fp; 192, identifier:close; 193, argument_list; 194, raise_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:Exception; 197, argument_list; 197, 198; 198, string:'fourth line must be labelo'; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:fp; 203, identifier:close; 204, argument_list; 205, if_statement; 205, 206; 205, 207; 205, 212; 206, identifier:foundfiles; 207, block; 207, 208; 208, return_statement; 208, 209; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:_label; 212, else_clause; 212, 213; 213, block; 213, 214; 214, raise_statement; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:Exception; 217, argument_list; 217, 218; 218, string:'label.files not found'; 219, else_clause; 219, 220; 220, block; 220, 221; 221, return_statement; 221, 222; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:_label
def _get_label(self): '''Find the label for the output files for this calculation ''' if self._label is None: foundfiles = False for f in self._files: if ".files" in f: foundfiles = True self._label = f.split(".")[0] with open(self._label + '.files', 'r') as fp: line = fp.readline().split()[0] if line != self._label + ".in": fp.close() raise Exception('first line must be label.in') line = fp.readline().split()[0] if line != self._label + ".txt": fp.close() raise Exception('second line must be label.txt') line = fp.readline().split()[0] if line != self._label + "i": fp.close() raise Exception('third line must be labeli') line = fp.readline().split()[0] if line != self._label + "o": fp.close() raise Exception('fourth line must be labelo') fp.close() if foundfiles: return self._label else: raise Exception('label.files not found') else: return self._label
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_estimate_progress; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 18; 5, 27; 5, 125; 5, 363; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:estimate; 9, True; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:current_subscript; 13, subscript; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_current_subscript_stage; 17, string:'current_subscript'; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:num_subscripts; 21, call; 21, 22; 21, 23; 22, identifier:len; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:scripts; 27, if_statement; 27, 28; 27, 33; 27, 42; 27, 114; 28, comparison_operator:==; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:iterator_type; 32, string:'loop'; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:num_iterations; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:settings; 41, string:'num_loops'; 42, elif_clause; 42, 43; 42, 48; 43, comparison_operator:==; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:iterator_type; 47, string:'sweep'; 48, block; 48, 49; 48, 57; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:sweep_range; 52, subscript; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:settings; 56, string:'sweep_range'; 57, if_statement; 57, 58; 57, 65; 57, 86; 57, 101; 58, comparison_operator:==; 58, 59; 58, 64; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:settings; 63, string:'stepping_mode'; 64, string:'value_step'; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:num_iterations; 69, binary_operator:+; 69, 70; 69, 85; 70, call; 70, 71; 70, 72; 71, identifier:int; 72, argument_list; 72, 73; 73, binary_operator:/; 73, 74; 73, 82; 74, parenthesized_expression; 74, 75; 75, binary_operator:-; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:sweep_range; 78, string:'max_value'; 79, subscript; 79, 80; 79, 81; 80, identifier:sweep_range; 81, string:'min_value'; 82, subscript; 82, 83; 82, 84; 83, identifier:sweep_range; 84, string:'N/value_step'; 85, integer:1; 86, elif_clause; 86, 87; 86, 94; 87, comparison_operator:==; 87, 88; 87, 93; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:settings; 92, string:'stepping_mode'; 93, string:'N'; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:num_iterations; 98, subscript; 98, 99; 98, 100; 99, identifier:sweep_range; 100, string:'N/value_step'; 101, else_clause; 101, 102; 102, block; 102, 103; 103, raise_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:KeyError; 106, argument_list; 106, 107; 107, binary_operator:+; 107, 108; 107, 109; 108, string:'unknown key'; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:settings; 113, string:'stepping_mode'; 114, else_clause; 114, 115; 115, block; 115, 116; 115, 121; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:print; 119, argument_list; 119, 120; 120, string:'unknown iterator type in Iterator receive signal - can\'t estimate ramining time'; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:estimate; 124, False; 125, if_statement; 125, 126; 125, 127; 125, 357; 126, identifier:estimate; 127, block; 127, 128; 127, 134; 127, 342; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:loop_index; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:loop_index; 134, if_statement; 134, 135; 134, 138; 135, comparison_operator:>; 135, 136; 135, 137; 136, identifier:num_subscripts; 137, integer:1; 138, block; 138, 139; 138, 143; 138, 147; 138, 174; 138, 193; 138, 214; 138, 218; 138, 279; 138, 283; 138, 319; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:loop_execution_time; 142, float:0.; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:sub_progress_time; 146, float:0.; 147, if_statement; 147, 148; 147, 151; 147, 168; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:current_subscript; 150, None; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:current_subscript_exec_duration; 155, call; 155, 156; 155, 167; 156, attribute; 156, 157; 156, 166; 157, subscript; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:_current_subscript_stage; 162, string:'subscript_exec_duration'; 163, attribute; 163, 164; 163, 165; 164, identifier:current_subscript; 165, identifier:name; 166, identifier:total_seconds; 167, argument_list; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:current_subscript_exec_duration; 173, float:0.0; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:current_subscript_elapsed_time; 177, call; 177, 178; 177, 192; 178, attribute; 178, 179; 178, 191; 179, parenthesized_expression; 179, 180; 180, binary_operator:-; 180, 181; 180, 188; 181, call; 181, 182; 181, 187; 182, attribute; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:datetime; 185, identifier:datetime; 186, identifier:now; 187, argument_list; 188, attribute; 188, 189; 188, 190; 189, identifier:current_subscript; 190, identifier:start_time; 191, identifier:total_seconds; 192, argument_list; 193, if_statement; 193, 194; 193, 197; 194, comparison_operator:==; 194, 195; 194, 196; 195, identifier:current_subscript_exec_duration; 196, float:0.0; 197, block; 197, 198; 197, 208; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:remaining_time; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:current_subscript; 205, identifier:remaining_time; 206, identifier:total_seconds; 207, argument_list; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:current_subscript_exec_duration; 211, binary_operator:+; 211, 212; 211, 213; 212, identifier:remaining_time; 213, identifier:current_subscript_elapsed_time; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:remaining_scripts; 217, integer:0; 218, for_statement; 218, 219; 218, 222; 218, 231; 219, pattern_list; 219, 220; 219, 221; 220, identifier:subscript_name; 221, identifier:duration; 222, call; 222, 223; 222, 230; 223, attribute; 223, 224; 223, 229; 224, subscript; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:_current_subscript_stage; 228, string:'subscript_exec_duration'; 229, identifier:items; 230, argument_list; 231, block; 231, 232; 231, 245; 231, 253; 232, if_statement; 232, 233; 232, 240; 233, comparison_operator:==; 233, 234; 233, 239; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:duration; 237, identifier:total_seconds; 238, argument_list; 239, float:0.0; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, augmented_assignment:+=; 242, 243; 242, 244; 243, identifier:remaining_scripts; 244, integer:1; 245, expression_statement; 245, 246; 246, augmented_assignment:+=; 246, 247; 246, 248; 247, identifier:loop_execution_time; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:duration; 251, identifier:total_seconds; 252, argument_list; 253, if_statement; 253, 254; 253, 270; 254, boolean_operator:and; 254, 255; 254, 264; 254, 265; 255, comparison_operator:==; 255, 256; 255, 263; 256, subscript; 256, 257; 256, 262; 257, subscript; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:_current_subscript_stage; 261, string:'subscript_exec_count'; 262, identifier:subscript_name; 263, identifier:loop_index; 264, line_continuation:\; 265, comparison_operator:is; 265, 266; 265, 267; 266, identifier:subscript_name; 267, attribute; 267, 268; 267, 269; 268, identifier:current_subscript; 269, identifier:name; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, augmented_assignment:+=; 272, 273; 272, 274; 273, identifier:sub_progress_time; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:duration; 277, identifier:total_seconds; 278, argument_list; 279, expression_statement; 279, 280; 280, augmented_assignment:+=; 280, 281; 280, 282; 281, identifier:sub_progress_time; 282, identifier:current_subscript_elapsed_time; 283, if_statement; 283, 284; 283, 287; 283, 294; 283, 310; 284, comparison_operator:==; 284, 285; 284, 286; 285, identifier:remaining_scripts; 286, identifier:num_subscripts; 287, block; 287, 288; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:loop_execution_time; 291, binary_operator:*; 291, 292; 291, 293; 292, identifier:num_subscripts; 293, identifier:current_subscript_exec_duration; 294, elif_clause; 294, 295; 294, 298; 295, comparison_operator:>; 295, 296; 295, 297; 296, identifier:remaining_scripts; 297, integer:1; 298, block; 298, 299; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:loop_execution_time; 302, binary_operator:/; 302, 303; 302, 306; 303, binary_operator:*; 303, 304; 303, 305; 304, float:1.; 305, identifier:num_subscripts; 306, parenthesized_expression; 306, 307; 307, binary_operator:-; 307, 308; 307, 309; 308, identifier:num_subscripts; 309, identifier:remaining_scripts; 310, elif_clause; 310, 311; 310, 314; 311, comparison_operator:==; 311, 312; 311, 313; 312, identifier:remaining_scripts; 313, integer:1; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, augmented_assignment:+=; 316, 317; 316, 318; 317, identifier:loop_execution_time; 318, identifier:current_subscript_exec_duration; 319, if_statement; 319, 320; 319, 323; 319, 332; 320, comparison_operator:>; 320, 321; 320, 322; 321, identifier:loop_execution_time; 322, integer:0; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:progress_subscript; 327, binary_operator:/; 327, 328; 327, 331; 328, binary_operator:*; 328, 329; 328, 330; 329, float:100.; 330, identifier:sub_progress_time; 331, identifier:loop_execution_time; 332, else_clause; 332, 333; 333, block; 333, 334; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:progress_subscript; 337, binary_operator:/; 337, 338; 337, 341; 338, binary_operator:*; 338, 339; 338, 340; 339, float:1.; 340, identifier:progress_subscript; 341, identifier:num_subscripts; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:progress; 345, binary_operator:/; 345, 346; 345, 356; 346, binary_operator:*; 346, 347; 346, 348; 347, float:100.; 348, parenthesized_expression; 348, 349; 349, binary_operator:+; 349, 350; 349, 353; 350, binary_operator:-; 350, 351; 350, 352; 351, identifier:loop_index; 352, float:1.; 353, binary_operator:*; 353, 354; 353, 355; 354, float:0.01; 355, identifier:progress_subscript; 356, identifier:num_iterations; 357, else_clause; 357, 358; 358, block; 358, 359; 359, expression_statement; 359, 360; 360, assignment; 360, 361; 360, 362; 361, identifier:progress; 362, integer:50; 363, return_statement; 363, 364; 364, identifier:progress
def _estimate_progress(self): estimate = True current_subscript = self._current_subscript_stage['current_subscript'] num_subscripts = len(self.scripts) if self.iterator_type == 'loop': num_iterations = self.settings['num_loops'] elif self.iterator_type == 'sweep': sweep_range = self.settings['sweep_range'] if self.settings['stepping_mode'] == 'value_step': num_iterations = int((sweep_range['max_value'] - sweep_range['min_value']) / sweep_range['N/value_step']) + 1 elif self.settings['stepping_mode'] == 'N': num_iterations = sweep_range['N/value_step'] else: raise KeyError('unknown key' + self.settings['stepping_mode']) else: print('unknown iterator type in Iterator receive signal - can\'t estimate ramining time') estimate = False if estimate: loop_index = self.loop_index if num_subscripts > 1: loop_execution_time = 0. sub_progress_time = 0. if current_subscript is not None: current_subscript_exec_duration = self._current_subscript_stage['subscript_exec_duration'][ current_subscript.name].total_seconds() else: current_subscript_exec_duration = 0.0 current_subscript_elapsed_time = (datetime.datetime.now() - current_subscript.start_time).total_seconds() if current_subscript_exec_duration == 0.0: remaining_time = current_subscript.remaining_time.total_seconds() current_subscript_exec_duration = remaining_time + current_subscript_elapsed_time remaining_scripts = 0 for subscript_name, duration in self._current_subscript_stage['subscript_exec_duration'].items(): if duration.total_seconds() == 0.0: remaining_scripts += 1 loop_execution_time += duration.total_seconds() if self._current_subscript_stage['subscript_exec_count'][subscript_name] == loop_index \ and subscript_name is not current_subscript.name: sub_progress_time += duration.total_seconds() sub_progress_time += current_subscript_elapsed_time if remaining_scripts == num_subscripts: loop_execution_time = num_subscripts * current_subscript_exec_duration elif remaining_scripts > 1: loop_execution_time = 1. * num_subscripts / (num_subscripts - remaining_scripts) elif remaining_scripts == 1: loop_execution_time += current_subscript_exec_duration if loop_execution_time > 0: progress_subscript = 100. * sub_progress_time / loop_execution_time else: progress_subscript = 1. * progress_subscript / num_subscripts progress = 100. * (loop_index - 1. + 0.01 * progress_subscript) / num_iterations else: progress = 50 return progress
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_default_settings; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:sub_scripts; 5, identifier:script_order; 6, identifier:script_execution_freq; 7, identifier:iterator_type; 8, block; 8, 9; 8, 240; 8, 368; 9, function_definition; 9, 10; 9, 11; 9, 17; 10, function_name:populate_sweep_param; 11, parameters; 11, 12; 11, 13; 11, 14; 12, identifier:scripts; 13, identifier:parameter_list; 14, default_parameter; 14, 15; 14, 16; 15, identifier:trace; 16, string:''; 17, block; 17, 18; 17, 20; 17, 134; 17, 238; 18, expression_statement; 18, 19; 19, string:''' Args: scripts: a dict of {'class name': <class object>} pairs Returns: A list of all parameters of the input scripts '''; 20, function_definition; 20, 21; 20, 22; 20, 29; 21, function_name:get_parameter_from_dict; 22, parameters; 22, 23; 22, 24; 22, 25; 22, 26; 23, identifier:trace; 24, identifier:dic; 25, identifier:parameter_list; 26, default_parameter; 26, 27; 26, 28; 27, identifier:valid_values; 28, None; 29, block; 29, 30; 29, 47; 29, 132; 30, if_statement; 30, 31; 30, 40; 31, boolean_operator:and; 31, 32; 31, 35; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:valid_values; 34, None; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 39; 38, identifier:dic; 39, identifier:Parameter; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:valid_values; 44, attribute; 44, 45; 44, 46; 45, identifier:dic; 46, identifier:valid_values; 47, for_statement; 47, 48; 47, 51; 47, 56; 48, pattern_list; 48, 49; 48, 50; 49, identifier:key; 50, identifier:value; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:dic; 54, identifier:items; 55, argument_list; 56, block; 56, 57; 57, if_statement; 57, 58; 57, 63; 57, 82; 57, 123; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 62; 61, identifier:value; 62, identifier:dict; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:parameter_list; 67, call; 67, 68; 67, 69; 68, identifier:get_parameter_from_dict; 69, argument_list; 69, 70; 69, 75; 69, 76; 69, 77; 70, binary_operator:+; 70, 71; 70, 74; 71, binary_operator:+; 71, 72; 71, 73; 72, identifier:trace; 73, string:'.'; 74, identifier:key; 75, identifier:value; 76, identifier:parameter_list; 77, subscript; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:dic; 80, identifier:valid_values; 81, identifier:key; 82, elif_clause; 82, 83; 82, 111; 83, boolean_operator:or; 83, 84; 83, 92; 83, 93; 84, parenthesized_expression; 84, 85; 85, comparison_operator:in; 85, 86; 85, 89; 86, subscript; 86, 87; 86, 88; 87, identifier:valid_values; 88, identifier:key; 89, tuple; 89, 90; 89, 91; 90, identifier:float; 91, identifier:int; 92, line_continuation:\; 93, parenthesized_expression; 93, 94; 94, boolean_operator:and; 94, 95; 94, 102; 95, call; 95, 96; 95, 97; 96, identifier:isinstance; 97, argument_list; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:valid_values; 100, identifier:key; 101, identifier:list; 102, comparison_operator:in; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:valid_values; 106, identifier:key; 107, integer:0; 108, tuple; 108, 109; 108, 110; 109, identifier:float; 110, identifier:int; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:parameter_list; 116, identifier:append; 117, argument_list; 117, 118; 118, binary_operator:+; 118, 119; 118, 122; 119, binary_operator:+; 119, 120; 119, 121; 120, identifier:trace; 121, string:'.'; 122, identifier:key; 123, else_clause; 123, 124; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:print; 128, argument_list; 128, 129; 129, tuple; 129, 130; 129, 131; 130, string:'ignoring sweep parameter'; 131, identifier:key; 132, return_statement; 132, 133; 133, identifier:parameter_list; 134, for_statement; 134, 135; 134, 136; 134, 144; 135, identifier:script_name; 136, call; 136, 137; 136, 138; 137, identifier:list; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:scripts; 142, identifier:keys; 143, argument_list; 144, block; 144, 145; 144, 151; 144, 155; 144, 174; 145, import_from_statement; 145, 146; 145, 149; 146, dotted_name; 146, 147; 146, 148; 147, identifier:pylabcontrol; 148, identifier:core; 149, dotted_name; 149, 150; 150, identifier:ScriptIterator; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:script_trace; 154, identifier:trace; 155, if_statement; 155, 156; 155, 159; 155, 164; 156, comparison_operator:==; 156, 157; 156, 158; 157, identifier:script_trace; 158, string:''; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:script_trace; 163, identifier:script_name; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:script_trace; 169, binary_operator:+; 169, 170; 169, 173; 170, binary_operator:+; 170, 171; 170, 172; 171, identifier:script_trace; 172, string:'->'; 173, identifier:script_name; 174, if_statement; 174, 175; 174, 182; 174, 201; 175, call; 175, 176; 175, 177; 176, identifier:issubclass; 177, argument_list; 177, 178; 177, 181; 178, subscript; 178, 179; 178, 180; 179, identifier:scripts; 180, identifier:script_name; 181, identifier:ScriptIterator; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:populate_sweep_param; 186, argument_list; 186, 187; 186, 195; 186, 198; 187, subscript; 187, 188; 187, 194; 188, call; 188, 189; 188, 190; 189, identifier:vars; 190, argument_list; 190, 191; 191, subscript; 191, 192; 191, 193; 192, identifier:scripts; 193, identifier:script_name; 194, string:'_SCRIPTS'; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:parameter_list; 197, identifier:parameter_list; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:trace; 200, identifier:script_trace; 201, else_clause; 201, 202; 202, block; 202, 203; 203, for_statement; 203, 204; 203, 205; 203, 206; 203, 228; 204, identifier:setting; 205, line_continuation:\; 206, subscript; 206, 207; 206, 227; 207, list_comprehension; 207, 208; 207, 211; 207, 221; 208, subscript; 208, 209; 208, 210; 209, identifier:elem; 210, integer:1; 211, for_in_clause; 211, 212; 211, 213; 212, identifier:elem; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:inspect; 216, identifier:getmembers; 217, argument_list; 217, 218; 218, subscript; 218, 219; 218, 220; 219, identifier:scripts; 220, identifier:script_name; 221, if_clause; 221, 222; 222, comparison_operator:==; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:elem; 225, integer:0; 226, string:'_DEFAULT_SETTINGS'; 227, integer:0; 228, block; 228, 229; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:parameter_list; 232, call; 232, 233; 232, 234; 233, identifier:get_parameter_from_dict; 234, argument_list; 234, 235; 234, 236; 234, 237; 235, identifier:script_trace; 236, identifier:setting; 237, identifier:parameter_list; 238, return_statement; 238, 239; 239, identifier:parameter_list; 240, if_statement; 240, 241; 240, 244; 240, 273; 240, 351; 241, comparison_operator:==; 241, 242; 241, 243; 242, identifier:iterator_type; 243, string:'loop'; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:script_default_settings; 248, list:[ Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('num_loops', 0, int, 'times the subscripts will be executed'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass') ]; 248, 249; 248, 254; 248, 259; 248, 266; 249, call; 249, 250; 249, 251; 250, identifier:Parameter; 251, argument_list; 251, 252; 251, 253; 252, string:'script_order'; 253, identifier:script_order; 254, call; 254, 255; 254, 256; 255, identifier:Parameter; 256, argument_list; 256, 257; 256, 258; 257, string:'script_execution_freq'; 258, identifier:script_execution_freq; 259, call; 259, 260; 259, 261; 260, identifier:Parameter; 261, argument_list; 261, 262; 261, 263; 261, 264; 261, 265; 262, string:'num_loops'; 263, integer:0; 264, identifier:int; 265, string:'times the subscripts will be executed'; 266, call; 266, 267; 266, 268; 267, identifier:Parameter; 268, argument_list; 268, 269; 268, 270; 268, 271; 268, 272; 269, string:'run_all_first'; 270, True; 271, identifier:bool; 272, string:'Run all scripts with nonzero frequency in first pass'; 273, elif_clause; 273, 274; 273, 277; 274, comparison_operator:==; 274, 275; 274, 276; 275, identifier:iterator_type; 276, string:'sweep'; 277, block; 277, 278; 277, 286; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:sweep_params; 281, call; 281, 282; 281, 283; 282, identifier:populate_sweep_param; 283, argument_list; 283, 284; 283, 285; 284, identifier:sub_scripts; 285, list:[]; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:script_default_settings; 289, list:[ Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('sweep_param', sweep_params[0], sweep_params, 'variable over which to sweep'), Parameter('sweep_range', [Parameter('min_value', 0, float, 'min parameter value'), Parameter('max_value', 0, float, 'max parameter value'), Parameter('N/value_step', 0, float, 'either number of steps or parameter value step, depending on mode')]), Parameter('stepping_mode', 'N', ['N', 'value_step'], 'Switch between number of steps and step amount'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass') ]; 289, 290; 289, 295; 289, 300; 289, 309; 289, 335; 289, 344; 290, call; 290, 291; 290, 292; 291, identifier:Parameter; 292, argument_list; 292, 293; 292, 294; 293, string:'script_order'; 294, identifier:script_order; 295, call; 295, 296; 295, 297; 296, identifier:Parameter; 297, argument_list; 297, 298; 297, 299; 298, string:'script_execution_freq'; 299, identifier:script_execution_freq; 300, call; 300, 301; 300, 302; 301, identifier:Parameter; 302, argument_list; 302, 303; 302, 304; 302, 307; 302, 308; 303, string:'sweep_param'; 304, subscript; 304, 305; 304, 306; 305, identifier:sweep_params; 306, integer:0; 307, identifier:sweep_params; 308, string:'variable over which to sweep'; 309, call; 309, 310; 309, 311; 310, identifier:Parameter; 311, argument_list; 311, 312; 311, 313; 312, string:'sweep_range'; 313, list:[Parameter('min_value', 0, float, 'min parameter value'), Parameter('max_value', 0, float, 'max parameter value'), Parameter('N/value_step', 0, float, 'either number of steps or parameter value step, depending on mode')]; 313, 314; 313, 321; 313, 328; 314, call; 314, 315; 314, 316; 315, identifier:Parameter; 316, argument_list; 316, 317; 316, 318; 316, 319; 316, 320; 317, string:'min_value'; 318, integer:0; 319, identifier:float; 320, string:'min parameter value'; 321, call; 321, 322; 321, 323; 322, identifier:Parameter; 323, argument_list; 323, 324; 323, 325; 323, 326; 323, 327; 324, string:'max_value'; 325, integer:0; 326, identifier:float; 327, string:'max parameter value'; 328, call; 328, 329; 328, 330; 329, identifier:Parameter; 330, argument_list; 330, 331; 330, 332; 330, 333; 330, 334; 331, string:'N/value_step'; 332, integer:0; 333, identifier:float; 334, string:'either number of steps or parameter value step, depending on mode'; 335, call; 335, 336; 335, 337; 336, identifier:Parameter; 337, argument_list; 337, 338; 337, 339; 337, 340; 337, 343; 338, string:'stepping_mode'; 339, string:'N'; 340, list:['N', 'value_step']; 340, 341; 340, 342; 341, string:'N'; 342, string:'value_step'; 343, string:'Switch between number of steps and step amount'; 344, call; 344, 345; 344, 346; 345, identifier:Parameter; 346, argument_list; 346, 347; 346, 348; 346, 349; 346, 350; 347, string:'run_all_first'; 348, True; 349, identifier:bool; 350, string:'Run all scripts with nonzero frequency in first pass'; 351, else_clause; 351, 352; 352, block; 352, 353; 352, 361; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 356; 355, identifier:print; 356, argument_list; 356, 357; 357, parenthesized_expression; 357, 358; 358, binary_operator:+; 358, 359; 358, 360; 359, string:'unknown iterator type '; 360, identifier:iterator_type; 361, raise_statement; 361, 362; 362, call; 362, 363; 362, 364; 363, identifier:TypeError; 364, argument_list; 364, 365; 365, binary_operator:+; 365, 366; 365, 367; 366, string:'unknown iterator type '; 367, identifier:iterator_type; 368, return_statement; 368, 369; 369, identifier:script_default_settings
def get_default_settings(sub_scripts, script_order, script_execution_freq, iterator_type): def populate_sweep_param(scripts, parameter_list, trace=''): ''' Args: scripts: a dict of {'class name': <class object>} pairs Returns: A list of all parameters of the input scripts ''' def get_parameter_from_dict(trace, dic, parameter_list, valid_values=None): if valid_values is None and isinstance(dic, Parameter): valid_values = dic.valid_values for key, value in dic.items(): if isinstance(value, dict): parameter_list = get_parameter_from_dict(trace + '.' + key, value, parameter_list, dic.valid_values[key]) elif (valid_values[key] in (float, int)) or \ (isinstance(valid_values[key], list) and valid_values[key][0] in (float, int)): parameter_list.append(trace + '.' + key) else: print(('ignoring sweep parameter', key)) return parameter_list for script_name in list(scripts.keys()): from pylabcontrol.core import ScriptIterator script_trace = trace if script_trace == '': script_trace = script_name else: script_trace = script_trace + '->' + script_name if issubclass(scripts[script_name], ScriptIterator): populate_sweep_param(vars(scripts[script_name])['_SCRIPTS'], parameter_list=parameter_list, trace=script_trace) else: for setting in \ [elem[1] for elem in inspect.getmembers(scripts[script_name]) if elem[0] == '_DEFAULT_SETTINGS'][0]: parameter_list = get_parameter_from_dict(script_trace, setting, parameter_list) return parameter_list if iterator_type == 'loop': script_default_settings = [ Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('num_loops', 0, int, 'times the subscripts will be executed'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass') ] elif iterator_type == 'sweep': sweep_params = populate_sweep_param(sub_scripts, []) script_default_settings = [ Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('sweep_param', sweep_params[0], sweep_params, 'variable over which to sweep'), Parameter('sweep_range', [Parameter('min_value', 0, float, 'min parameter value'), Parameter('max_value', 0, float, 'max parameter value'), Parameter('N/value_step', 0, float, 'either number of steps or parameter value step, depending on mode')]), Parameter('stepping_mode', 'N', ['N', 'value_step'], 'Switch between number of steps and step amount'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass') ] else: print(('unknown iterator type ' + iterator_type)) raise TypeError('unknown iterator type ' + iterator_type) return script_default_settings
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:consensus; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:aln; 5, default_parameter; 5, 6; 5, 7; 6, identifier:weights; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:gap_threshold; 10, float:0.5; 11, default_parameter; 11, 12; 11, 13; 12, identifier:simple; 13, False; 14, default_parameter; 14, 15; 14, 16; 15, identifier:trim_ends; 16, True; 17, block; 17, 18; 17, 136; 17, 304; 18, if_statement; 18, 19; 18, 20; 18, 56; 19, identifier:simple; 20, block; 20, 21; 20, 33; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:col_consensus; 24, call; 24, 25; 24, 26; 25, identifier:make_simple_col_consensus; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:alnutils; 30, identifier:aa_frequencies; 31, argument_list; 31, 32; 32, identifier:aln; 33, function_definition; 33, 34; 33, 35; 33, 37; 34, function_name:is_majority_gap; 35, parameters; 35, 36; 36, identifier:col; 37, block; 37, 38; 38, return_statement; 38, 39; 39, parenthesized_expression; 39, 40; 40, comparison_operator:>=; 40, 41; 40, 55; 41, binary_operator:/; 41, 42; 41, 51; 42, call; 42, 43; 42, 44; 43, identifier:float; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:col; 48, identifier:count; 49, argument_list; 49, 50; 50, string:'-'; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:col; 55, identifier:gap_threshold; 56, else_clause; 56, 57; 57, block; 57, 58; 57, 79; 57, 91; 57, 98; 58, if_statement; 58, 59; 58, 62; 58, 73; 59, comparison_operator:is; 59, 60; 59, 61; 60, identifier:weights; 61, None; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:seq_weights; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:alnutils; 69, identifier:sequence_weights; 70, argument_list; 70, 71; 70, 72; 71, identifier:aln; 72, string:'avg1'; 73, else_clause; 73, 74; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:seq_weights; 78, identifier:weights; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:aa_frequencies; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:alnutils; 85, identifier:aa_frequencies; 86, argument_list; 86, 87; 86, 88; 87, identifier:aln; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:weights; 90, identifier:seq_weights; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:col_consensus; 94, call; 94, 95; 94, 96; 95, identifier:make_entropy_col_consensus; 96, argument_list; 96, 97; 97, identifier:aa_frequencies; 98, function_definition; 98, 99; 98, 100; 98, 102; 99, function_name:is_majority_gap; 100, parameters; 100, 101; 101, identifier:col; 102, block; 102, 103; 102, 107; 102, 126; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:gap_count; 106, float:0.0; 107, for_statement; 107, 108; 107, 111; 107, 116; 108, pattern_list; 108, 109; 108, 110; 109, identifier:wt; 110, identifier:char; 111, call; 111, 112; 111, 113; 112, identifier:zip; 113, argument_list; 113, 114; 113, 115; 114, identifier:seq_weights; 115, identifier:col; 116, block; 116, 117; 117, if_statement; 117, 118; 117, 121; 118, comparison_operator:==; 118, 119; 118, 120; 119, identifier:char; 120, string:'-'; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, augmented_assignment:+=; 123, 124; 123, 125; 124, identifier:gap_count; 125, identifier:wt; 126, return_statement; 126, 127; 127, parenthesized_expression; 127, 128; 128, comparison_operator:>=; 128, 129; 128, 135; 129, binary_operator:/; 129, 130; 129, 131; 130, identifier:gap_count; 131, call; 131, 132; 131, 133; 132, identifier:sum; 133, argument_list; 133, 134; 134, identifier:seq_weights; 135, identifier:gap_threshold; 136, function_definition; 136, 137; 136, 138; 136, 140; 137, function_name:col_wise_consensus; 138, parameters; 138, 139; 139, identifier:columns; 140, block; 140, 141; 140, 153; 140, 293; 141, if_statement; 141, 142; 141, 144; 142, not_operator; 142, 143; 143, identifier:trim_ends; 144, block; 144, 145; 144, 149; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:in_left_end; 148, True; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:maybe_right_tail; 152, list:[]; 153, for_statement; 153, 154; 153, 155; 153, 156; 154, identifier:col; 155, identifier:columns; 156, block; 156, 157; 156, 178; 156, 217; 156, 224; 156, 243; 156, 252; 156, 259; 157, if_statement; 157, 158; 157, 173; 158, call; 158, 159; 158, 160; 159, identifier:all; 160, generator_expression; 160, 161; 160, 166; 160, 169; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:c; 164, identifier:islower; 165, argument_list; 166, for_in_clause; 166, 167; 166, 168; 167, identifier:c; 168, identifier:col; 169, if_clause; 169, 170; 170, comparison_operator:not; 170, 171; 170, 172; 171, identifier:c; 172, string:'.-'; 173, block; 173, 174; 173, 177; 174, expression_statement; 174, 175; 175, yield; 175, 176; 176, string:'-'; 177, continue_statement; 178, if_statement; 178, 179; 178, 190; 179, call; 179, 180; 179, 181; 180, identifier:any; 181, generator_expression; 181, 182; 181, 187; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:c; 185, identifier:islower; 186, argument_list; 187, for_in_clause; 187, 188; 187, 189; 188, identifier:c; 189, identifier:col; 190, block; 190, 191; 190, 207; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:logging; 195, identifier:warn; 196, argument_list; 196, 197; 197, binary_operator:+; 197, 198; 197, 201; 198, concatenated_string; 198, 199; 198, 200; 199, string:'Mixed lowercase and uppercase letters in a '; 200, string:'column: '; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:''; 204, identifier:join; 205, argument_list; 205, 206; 206, identifier:col; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:col; 210, call; 210, 211; 210, 212; 211, identifier:map; 212, argument_list; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:str; 215, identifier:upper; 216, identifier:col; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:is_gap; 220, call; 220, 221; 220, 222; 221, identifier:is_majority_gap; 222, argument_list; 222, 223; 223, identifier:col; 224, if_statement; 224, 225; 224, 227; 225, not_operator; 225, 226; 226, identifier:trim_ends; 227, block; 227, 228; 228, if_statement; 228, 229; 228, 230; 229, identifier:in_left_end; 230, block; 230, 231; 230, 239; 231, if_statement; 231, 232; 231, 234; 232, not_operator; 232, 233; 233, identifier:is_gap; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:in_left_end; 238, False; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:is_gap; 242, False; 243, if_statement; 243, 244; 243, 247; 244, boolean_operator:and; 244, 245; 244, 246; 245, identifier:is_gap; 246, identifier:trim_ends; 247, block; 247, 248; 247, 251; 248, expression_statement; 248, 249; 249, yield; 249, 250; 250, string:'-'; 251, continue_statement; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:cons_char; 255, call; 255, 256; 255, 257; 256, identifier:col_consensus; 257, argument_list; 257, 258; 258, identifier:col; 259, if_statement; 259, 260; 259, 261; 259, 265; 260, identifier:trim_ends; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, yield; 263, 264; 264, identifier:cons_char; 265, else_clause; 265, 266; 266, block; 266, 267; 267, if_statement; 267, 268; 267, 269; 267, 277; 268, identifier:is_gap; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:maybe_right_tail; 274, identifier:append; 275, argument_list; 275, 276; 276, identifier:cons_char; 277, else_clause; 277, 278; 278, block; 278, 279; 278, 286; 278, 290; 279, for_statement; 279, 280; 279, 281; 279, 282; 280, identifier:char; 281, identifier:maybe_right_tail; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, yield; 284, 285; 285, string:'-'; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:maybe_right_tail; 289, list:[]; 290, expression_statement; 290, 291; 291, yield; 291, 292; 292, identifier:cons_char; 293, if_statement; 293, 294; 293, 296; 294, not_operator; 294, 295; 295, identifier:trim_ends; 296, block; 296, 297; 297, for_statement; 297, 298; 297, 299; 297, 300; 298, identifier:char; 299, identifier:maybe_right_tail; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, yield; 302, 303; 303, identifier:char; 304, return_statement; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, string:''; 308, identifier:join; 309, argument_list; 309, 310; 310, call; 310, 311; 310, 312; 311, identifier:col_wise_consensus; 312, argument_list; 312, 313; 313, call; 313, 314; 313, 315; 314, identifier:zip; 315, argument_list; 315, 316; 316, list_splat; 316, 317; 317, identifier:aln
def consensus(aln, weights=None, gap_threshold=0.5, simple=False, trim_ends=True): if simple: col_consensus = make_simple_col_consensus(alnutils.aa_frequencies(aln)) def is_majority_gap(col): return (float(col.count('-')) / len(col) >= gap_threshold) else: if weights is None: seq_weights = alnutils.sequence_weights(aln, 'avg1') else: seq_weights = weights aa_frequencies = alnutils.aa_frequencies(aln, weights=seq_weights) col_consensus = make_entropy_col_consensus(aa_frequencies) def is_majority_gap(col): gap_count = 0.0 for wt, char in zip(seq_weights, col): if char == '-': gap_count += wt return (gap_count / sum(seq_weights) >= gap_threshold) def col_wise_consensus(columns): if not trim_ends: in_left_end = True maybe_right_tail = [] for col in columns: if all(c.islower() for c in col if c not in '.-'): yield '-' continue if any(c.islower() for c in col): logging.warn('Mixed lowercase and uppercase letters in a ' 'column: ' + ''.join(col)) col = map(str.upper, col) is_gap = is_majority_gap(col) if not trim_ends: if in_left_end: if not is_gap: in_left_end = False is_gap = False if is_gap and trim_ends: yield '-' continue cons_char = col_consensus(col) if trim_ends: yield cons_char else: if is_gap: maybe_right_tail.append(cons_char) else: for char in maybe_right_tail: yield '-' maybe_right_tail = [] yield cons_char if not trim_ends: for char in maybe_right_tail: yield char return ''.join(col_wise_consensus(zip(*aln)))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:make_simple_col_consensus; 3, parameters; 3, 4; 4, identifier:bg_freqs; 5, block; 5, 6; 5, 192; 6, function_definition; 6, 7; 6, 8; 6, 16; 7, function_name:col_consensus; 8, parameters; 8, 9; 8, 10; 8, 13; 9, identifier:col; 10, default_parameter; 10, 11; 10, 12; 11, identifier:prev_col; 12, list:[]; 13, default_parameter; 13, 14; 13, 15; 14, identifier:prev_char; 15, list:[]; 16, block; 16, 17; 16, 26; 16, 29; 16, 50; 16, 64; 16, 176; 16, 183; 16, 190; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:aa_counts; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:sequtils; 23, identifier:aa_frequencies; 24, argument_list; 24, 25; 25, identifier:col; 26, assert_statement; 26, 27; 26, 28; 27, identifier:aa_counts; 28, string:"Column is all gaps! That's not allowed."; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, pattern_list; 31, 32; 31, 33; 32, identifier:best_char; 33, identifier:best_score; 34, call; 34, 35; 34, 36; 35, identifier:max; 36, argument_list; 36, 37; 36, 42; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:aa_counts; 40, identifier:iteritems; 41, argument_list; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:key; 44, lambda; 44, 45; 44, 47; 45, lambda_parameters; 45, 46; 46, identifier:kv; 47, subscript; 47, 48; 47, 49; 48, identifier:kv; 49, integer:1; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:ties; 53, list_comprehension; 53, 54; 53, 55; 53, 58; 54, identifier:aa; 55, for_in_clause; 55, 56; 55, 57; 56, identifier:aa; 57, identifier:aa_counts; 58, if_clause; 58, 59; 59, comparison_operator:==; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:aa_counts; 62, identifier:aa; 63, identifier:best_score; 64, if_statement; 64, 65; 64, 71; 64, 163; 65, comparison_operator:>; 65, 66; 65, 70; 66, call; 66, 67; 66, 68; 67, identifier:len; 68, argument_list; 68, 69; 69, identifier:ties; 70, integer:1; 71, block; 71, 72; 71, 135; 71, 157; 72, if_statement; 72, 73; 72, 76; 73, boolean_operator:and; 73, 74; 73, 75; 74, identifier:prev_char; 75, identifier:prev_col; 76, block; 76, 77; 76, 108; 76, 128; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:mc_next; 80, call; 80, 81; 80, 107; 81, attribute; 81, 82; 81, 106; 82, call; 82, 83; 82, 84; 83, identifier:Counter; 84, argument_list; 84, 85; 85, list_comprehension; 85, 86; 85, 87; 85, 96; 86, identifier:b; 87, for_in_clause; 87, 88; 87, 91; 88, pattern_list; 88, 89; 88, 90; 89, identifier:a; 90, identifier:b; 91, call; 91, 92; 91, 93; 92, identifier:zip; 93, argument_list; 93, 94; 93, 95; 94, identifier:prev_col; 95, identifier:col; 96, if_clause; 96, 97; 97, boolean_operator:and; 97, 98; 97, 103; 98, comparison_operator:==; 98, 99; 98, 100; 99, identifier:a; 100, subscript; 100, 101; 100, 102; 101, identifier:prev_char; 102, integer:0; 103, comparison_operator:in; 103, 104; 103, 105; 104, identifier:b; 105, identifier:ties; 106, identifier:most_common; 107, argument_list; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:ties_next; 111, list_comprehension; 111, 112; 111, 115; 111, 118; 112, subscript; 112, 113; 112, 114; 113, identifier:x; 114, integer:0; 115, for_in_clause; 115, 116; 115, 117; 116, identifier:x; 117, identifier:mc_next; 118, if_clause; 118, 119; 119, comparison_operator:==; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:x; 122, integer:1; 123, subscript; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:mc_next; 126, integer:0; 127, integer:1; 128, if_statement; 128, 129; 128, 130; 129, identifier:ties_next; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:ties; 134, identifier:ties_next; 135, if_statement; 135, 136; 135, 142; 136, comparison_operator:>; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:ties; 141, integer:1; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:ties; 147, identifier:sort; 148, argument_list; 148, 149; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:key; 151, lambda; 151, 152; 151, 154; 152, lambda_parameters; 152, 153; 153, identifier:aa; 154, subscript; 154, 155; 154, 156; 155, identifier:bg_freqs; 156, identifier:aa; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:best_char; 160, subscript; 160, 161; 160, 162; 161, identifier:ties; 162, integer:0; 163, else_clause; 163, 164; 164, block; 164, 165; 165, assert_statement; 165, 166; 165, 171; 166, comparison_operator:==; 166, 167; 166, 168; 167, identifier:best_char; 168, subscript; 168, 169; 168, 170; 169, identifier:ties; 170, integer:0; 171, binary_operator:%; 171, 172; 171, 173; 172, string:'WTF %s != %s[0]'; 173, tuple; 173, 174; 173, 175; 174, identifier:best_char; 175, identifier:ties; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 182; 178, subscript; 178, 179; 178, 180; 179, identifier:prev_col; 180, slice; 180, 181; 181, colon; 182, identifier:col; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 189; 185, subscript; 185, 186; 185, 187; 186, identifier:prev_char; 187, slice; 187, 188; 188, colon; 189, identifier:best_char; 190, return_statement; 190, 191; 191, identifier:best_char; 192, return_statement; 192, 193; 193, identifier:col_consensus
def make_simple_col_consensus(bg_freqs): def col_consensus(col, prev_col=[], prev_char=[]): aa_counts = sequtils.aa_frequencies(col) assert aa_counts, "Column is all gaps! That's not allowed." best_char, best_score = max(aa_counts.iteritems(), key=lambda kv: kv[1]) ties = [aa for aa in aa_counts if aa_counts[aa] == best_score] if len(ties) > 1: if prev_char and prev_col: mc_next = Counter( [b for a, b in zip(prev_col, col) if a == prev_char[0] and b in ties] ).most_common() ties_next = [x[0] for x in mc_next if x[1] == mc_next[0][1]] if ties_next: ties = ties_next if len(ties) > 1: ties.sort(key=lambda aa: bg_freqs[aa]) best_char = ties[0] else: assert best_char == ties[0], \ 'WTF %s != %s[0]' % (best_char, ties) prev_col[:] = col prev_char[:] = best_char return best_char return col_consensus
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:supported; 3, parameters; 3, 4; 4, identifier:aln; 5, block; 5, 6; 5, 191; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:col_consensus; 8, parameters; 8, 9; 9, identifier:columns; 10, block; 10, 11; 11, for_statement; 11, 12; 11, 13; 11, 14; 12, identifier:col; 13, identifier:columns; 14, block; 14, 15; 14, 52; 14, 91; 14, 110; 14, 121; 15, if_statement; 15, 16; 15, 47; 16, parenthesized_expression; 16, 17; 17, boolean_operator:or; 17, 18; 17, 32; 18, parenthesized_expression; 18, 19; 19, comparison_operator:>=; 19, 20; 19, 26; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:col; 23, identifier:count; 24, argument_list; 24, 25; 25, string:'-'; 26, binary_operator:/; 26, 27; 26, 31; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, identifier:col; 31, integer:2; 32, call; 32, 33; 32, 34; 33, identifier:all; 34, generator_expression; 34, 35; 34, 40; 34, 43; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:c; 38, identifier:islower; 39, argument_list; 40, for_in_clause; 40, 41; 40, 42; 41, identifier:c; 42, identifier:col; 43, if_clause; 43, 44; 44, comparison_operator:not; 44, 45; 44, 46; 45, identifier:c; 46, string:'.-'; 47, block; 47, 48; 47, 51; 48, expression_statement; 48, 49; 49, yield; 49, 50; 50, string:'-'; 51, continue_statement; 52, if_statement; 52, 53; 52, 64; 53, call; 53, 54; 53, 55; 54, identifier:any; 55, generator_expression; 55, 56; 55, 61; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:c; 59, identifier:islower; 60, argument_list; 61, for_in_clause; 61, 62; 61, 63; 62, identifier:c; 63, identifier:col; 64, block; 64, 65; 64, 81; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:logging; 69, identifier:warn; 70, argument_list; 70, 71; 71, binary_operator:+; 71, 72; 71, 75; 72, concatenated_string; 72, 73; 72, 74; 73, string:'Mixed lowercase and uppercase letters in a '; 74, string:'column: '; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, string:''; 78, identifier:join; 79, argument_list; 79, 80; 80, identifier:col; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:col; 84, call; 84, 85; 84, 86; 85, identifier:map; 86, argument_list; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:str; 89, identifier:upper; 90, identifier:col; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:most_common; 94, call; 94, 95; 94, 109; 95, attribute; 95, 96; 95, 108; 96, call; 96, 97; 96, 98; 97, identifier:Counter; 98, argument_list; 98, 99; 99, list_comprehension; 99, 100; 99, 101; 99, 104; 100, identifier:c; 101, for_in_clause; 101, 102; 101, 103; 102, identifier:c; 103, identifier:col; 104, if_clause; 104, 105; 105, comparison_operator:not; 105, 106; 105, 107; 106, identifier:c; 107, string:'-'; 108, identifier:most_common; 109, argument_list; 110, if_statement; 110, 111; 110, 113; 111, not_operator; 111, 112; 112, identifier:most_common; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:logging; 118, identifier:warn; 119, argument_list; 119, 120; 120, string:"Column is all gaps! How did that happen?"; 121, if_statement; 121, 122; 121, 129; 121, 133; 121, 182; 122, comparison_operator:==; 122, 123; 122, 128; 123, subscript; 123, 124; 123, 127; 124, subscript; 124, 125; 124, 126; 125, identifier:most_common; 126, integer:0; 127, integer:1; 128, integer:1; 129, block; 129, 130; 130, expression_statement; 130, 131; 131, yield; 131, 132; 132, string:'-'; 133, elif_clause; 133, 134; 133, 153; 134, parenthesized_expression; 134, 135; 135, boolean_operator:and; 135, 136; 135, 142; 136, comparison_operator:>; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:most_common; 141, integer:1; 142, comparison_operator:==; 142, 143; 142, 148; 143, subscript; 143, 144; 143, 147; 144, subscript; 144, 145; 144, 146; 145, identifier:most_common; 146, integer:0; 147, integer:1; 148, subscript; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:most_common; 151, integer:1; 152, integer:1; 153, block; 153, 154; 153, 174; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:ties; 157, list_comprehension; 157, 158; 157, 161; 157, 164; 158, subscript; 158, 159; 158, 160; 159, identifier:x; 160, integer:0; 161, for_in_clause; 161, 162; 161, 163; 162, identifier:x; 163, identifier:most_common; 164, if_clause; 164, 165; 165, comparison_operator:==; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:x; 168, integer:1; 169, subscript; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:most_common; 172, integer:0; 173, integer:1; 174, expression_statement; 174, 175; 175, yield; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, string:''; 179, identifier:join; 180, argument_list; 180, 181; 181, identifier:ties; 182, else_clause; 182, 183; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, yield; 185, 186; 186, subscript; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:most_common; 189, integer:0; 190, integer:0; 191, return_statement; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:list; 194, argument_list; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:col_consensus; 197, argument_list; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:zip; 200, argument_list; 200, 201; 201, list_splat; 201, 202; 202, identifier:aln
def supported(aln): def col_consensus(columns): for col in columns: if ( (col.count('-') >= len(col)/2) or all(c.islower() for c in col if c not in '.-') ): yield '-' continue if any(c.islower() for c in col): logging.warn('Mixed lowercase and uppercase letters in a ' 'column: ' + ''.join(col)) col = map(str.upper, col) most_common = Counter( [c for c in col if c not in '-'] ).most_common() if not most_common: logging.warn("Column is all gaps! How did that happen?") if most_common[0][1] == 1: yield '-' elif (len(most_common) > 1 and most_common[0][1] == most_common[1][1]): ties = [x[0] for x in most_common if x[1] == most_common[0][1]] yield ''.join(ties) else: yield most_common[0][0] return list(col_consensus(zip(*aln)))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_aliases; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:aliases; 6, block; 6, 7; 6, 13; 6, 19; 6, 34; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_cache_init; 12, argument_list; 13, if_statement; 13, 14; 13, 16; 14, not_operator; 14, 15; 15, identifier:aliases; 16, block; 16, 17; 17, return_statement; 17, 18; 18, identifier:aliases; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:parent_aliases; 22, call; 22, 23; 22, 33; 23, attribute; 23, 24; 23, 32; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:_cache_get_entry; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:CACHE_NAME_PARENTS; 32, identifier:keys; 33, argument_list; 34, return_statement; 34, 35; 35, list_comprehension; 35, 36; 35, 37; 35, 40; 36, identifier:parent_alias; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:parent_alias; 39, identifier:parent_aliases; 40, if_clause; 40, 41; 41, comparison_operator:in; 41, 42; 41, 43; 42, identifier:parent_alias; 43, identifier:aliases
def sort_aliases(self, aliases): self._cache_init() if not aliases: return aliases parent_aliases = self._cache_get_entry(self.CACHE_NAME_PARENTS).keys() return [parent_alias for parent_alias in parent_aliases if parent_alias in aliases]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:load_and_append; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:probe_dict; 5, identifier:probes; 6, default_parameter; 6, 7; 6, 8; 7, identifier:instruments; 8, dictionary; 9, block; 9, 10; 9, 14; 9, 18; 9, 25; 9, 29; 9, 36; 9, 59; 9, 127; 9, 207; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:loaded_failed; 13, dictionary; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:updated_probes; 17, dictionary; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:updated_probes; 22, identifier:update; 23, argument_list; 23, 24; 24, identifier:probes; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:updated_instruments; 28, dictionary; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:updated_instruments; 33, identifier:update; 34, argument_list; 34, 35; 35, identifier:instruments; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:new_instruments; 39, call; 39, 40; 39, 41; 40, identifier:list; 41, argument_list; 41, 42; 42, binary_operator:-; 42, 43; 42, 51; 43, call; 43, 44; 43, 45; 44, identifier:set; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:probe_dict; 49, identifier:keys; 50, argument_list; 51, call; 51, 52; 51, 53; 52, identifier:set; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:probes; 57, identifier:keys; 58, argument_list; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:!=; 60, 61; 60, 62; 61, identifier:new_instruments; 62, list:[]; 63, block; 63, 64; 63, 82; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, pattern_list; 66, 67; 66, 68; 67, identifier:updated_instruments; 68, identifier:failed; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:Instrument; 72, identifier:load_and_append; 73, argument_list; 73, 74; 73, 81; 74, dictionary_comprehension; 74, 75; 74, 78; 75, pair; 75, 76; 75, 77; 76, identifier:instrument_name; 77, identifier:instrument_name; 78, for_in_clause; 78, 79; 78, 80; 79, identifier:instrument_name; 80, identifier:new_instruments; 81, identifier:instruments; 82, if_statement; 82, 83; 82, 86; 83, comparison_operator:!=; 83, 84; 83, 85; 84, identifier:failed; 85, list:[]; 86, block; 86, 87; 87, for_statement; 87, 88; 87, 89; 87, 102; 88, identifier:failed_instrument; 89, binary_operator:-; 89, 90; 89, 94; 90, call; 90, 91; 90, 92; 91, identifier:set; 92, argument_list; 92, 93; 93, identifier:failed; 94, call; 94, 95; 94, 96; 95, identifier:set; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:instruments; 100, identifier:keys; 101, argument_list; 102, block; 102, 103; 102, 123; 103, for_statement; 103, 104; 103, 105; 103, 108; 104, identifier:probe_name; 105, subscript; 105, 106; 105, 107; 106, identifier:probe_dict; 107, identifier:failed_instrument; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:loaded_failed; 113, identifier:probe_name; 114, call; 114, 115; 114, 116; 115, identifier:ValueError; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, string:'failed to load instrument {:s} already exists. Did not load!'; 120, identifier:format; 121, argument_list; 121, 122; 122, identifier:failed_instrument; 123, delete_statement; 123, 124; 124, subscript; 124, 125; 124, 126; 125, identifier:probe_dict; 126, identifier:failed_instrument; 127, for_statement; 127, 128; 127, 131; 127, 136; 128, pattern_list; 128, 129; 128, 130; 129, identifier:instrument_name; 130, identifier:probe_names; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:probe_dict; 134, identifier:items; 135, argument_list; 136, block; 136, 137; 136, 153; 137, if_statement; 137, 138; 137, 142; 138, not_operator; 138, 139; 139, comparison_operator:in; 139, 140; 139, 141; 140, identifier:instrument_name; 141, identifier:updated_probes; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:updated_probes; 147, identifier:update; 148, argument_list; 148, 149; 149, dictionary; 149, 150; 150, pair; 150, 151; 150, 152; 151, identifier:instrument_name; 152, dictionary; 153, for_statement; 153, 154; 153, 155; 153, 161; 154, identifier:probe_name; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:probe_names; 158, identifier:split; 159, argument_list; 159, 160; 160, string:','; 161, block; 161, 162; 162, if_statement; 162, 163; 162, 168; 162, 183; 163, comparison_operator:in; 163, 164; 163, 165; 164, identifier:probe_name; 165, subscript; 165, 166; 165, 167; 166, identifier:updated_probes; 167, identifier:instrument_name; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 174; 171, subscript; 171, 172; 171, 173; 172, identifier:loaded_failed; 173, identifier:probe_name; 174, call; 174, 175; 174, 176; 175, identifier:ValueError; 176, argument_list; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, string:'failed to load probe {:s} already exists. Did not load!'; 180, identifier:format; 181, argument_list; 181, 182; 182, identifier:probe_name; 183, else_clause; 183, 184; 184, block; 184, 185; 184, 195; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:probe_instance; 188, call; 188, 189; 188, 190; 189, identifier:Probe; 190, argument_list; 190, 191; 190, 194; 191, subscript; 191, 192; 191, 193; 192, identifier:updated_instruments; 193, identifier:instrument_name; 194, identifier:probe_name; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:updated_probes; 200, identifier:instrument_name; 201, identifier:update; 202, argument_list; 202, 203; 203, dictionary; 203, 204; 204, pair; 204, 205; 204, 206; 205, identifier:probe_name; 206, identifier:probe_instance; 207, return_statement; 207, 208; 208, expression_list; 208, 209; 208, 210; 208, 211; 209, identifier:updated_probes; 210, identifier:loaded_failed; 211, identifier:updated_instruments
def load_and_append(probe_dict, probes, instruments={}): loaded_failed = {} updated_probes = {} updated_probes.update(probes) updated_instruments = {} updated_instruments.update(instruments) new_instruments = list(set(probe_dict.keys())-set(probes.keys())) if new_instruments != []: updated_instruments, failed = Instrument.load_and_append({instrument_name: instrument_name for instrument_name in new_instruments}, instruments) if failed != []: for failed_instrument in set(failed) - set(instruments.keys()): for probe_name in probe_dict[failed_instrument]: loaded_failed[probe_name] = ValueError('failed to load instrument {:s} already exists. Did not load!'.format(failed_instrument)) del probe_dict[failed_instrument] for instrument_name, probe_names in probe_dict.items(): if not instrument_name in updated_probes: updated_probes.update({instrument_name:{}}) for probe_name in probe_names.split(','): if probe_name in updated_probes[instrument_name]: loaded_failed[probe_name] = ValueError('failed to load probe {:s} already exists. Did not load!'.format(probe_name)) else: probe_instance = Probe(updated_instruments[instrument_name], probe_name) updated_probes[instrument_name].update({probe_name: probe_instance}) return updated_probes, loaded_failed, updated_instruments
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:_get_line; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:search_string; 6, identifier:search_file; 7, default_parameter; 7, 8; 7, 9; 8, identifier:return_string; 9, True; 10, default_parameter; 10, 11; 10, 12; 11, identifier:case_sens; 12, True; 13, block; 13, 14; 13, 16; 14, expression_statement; 14, 15; 15, string:'''Return the first line containing a set of strings in a file. If return_string is False, we just return whether such a line was found. If case_sens is False, the search is case insensitive. '''; 16, if_statement; 16, 17; 16, 25; 16, 122; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:os; 21, identifier:path; 22, identifier:isfile; 23, argument_list; 23, 24; 24, identifier:search_file; 25, block; 25, 26; 25, 42; 25, 58; 26, if_statement; 26, 27; 26, 36; 27, comparison_operator:==; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:type; 30, argument_list; 30, 31; 31, identifier:search_string; 32, call; 32, 33; 32, 34; 33, identifier:type; 34, argument_list; 34, 35; 35, string:''; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:search_string; 40, list:[search_string]; 40, 41; 41, identifier:search_string; 42, if_statement; 42, 43; 42, 45; 43, not_operator; 43, 44; 44, identifier:case_sens; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:search_string; 49, list_comprehension; 49, 50; 49, 55; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:i; 53, identifier:lower; 54, argument_list; 55, for_in_clause; 55, 56; 55, 57; 56, identifier:i; 57, identifier:search_string; 58, with_statement; 58, 59; 58, 68; 59, with_clause; 59, 60; 60, with_item; 60, 61; 61, as_pattern; 61, 62; 61, 66; 62, call; 62, 63; 62, 64; 63, identifier:open; 64, argument_list; 64, 65; 65, identifier:search_file; 66, as_pattern_target; 66, 67; 67, identifier:fp; 68, block; 68, 69; 68, 101; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:line; 71, identifier:fp; 72, block; 72, 73; 72, 84; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:query_line; 76, conditional_expression:if; 76, 77; 76, 78; 76, 79; 77, identifier:line; 78, identifier:case_sens; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:line; 82, identifier:lower; 83, argument_list; 84, if_statement; 84, 85; 84, 95; 85, call; 85, 86; 85, 87; 86, identifier:all; 87, argument_list; 87, 88; 88, list_comprehension; 88, 89; 88, 92; 89, comparison_operator:in; 89, 90; 89, 91; 90, identifier:i; 91, identifier:query_line; 92, for_in_clause; 92, 93; 92, 94; 93, identifier:i; 94, identifier:search_string; 95, block; 95, 96; 96, return_statement; 96, 97; 97, conditional_expression:if; 97, 98; 97, 99; 97, 100; 98, identifier:line; 99, identifier:return_string; 100, True; 101, if_statement; 101, 102; 101, 103; 101, 118; 102, identifier:return_string; 103, block; 103, 104; 104, raise_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:Exception; 107, argument_list; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, string:'%s not found in %s'; 110, tuple; 110, 111; 110, 117; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:' & '; 114, identifier:join; 115, argument_list; 115, 116; 116, identifier:search_string; 117, identifier:search_file; 118, else_clause; 118, 119; 119, block; 119, 120; 120, return_statement; 120, 121; 121, False; 122, else_clause; 122, 123; 123, block; 123, 124; 124, raise_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:Exception; 127, argument_list; 127, 128; 128, binary_operator:%; 128, 129; 128, 130; 129, string:'%s file does not exist'; 130, identifier:search_file
def _get_line(self, search_string, search_file, return_string=True, case_sens=True): '''Return the first line containing a set of strings in a file. If return_string is False, we just return whether such a line was found. If case_sens is False, the search is case insensitive. ''' if os.path.isfile(search_file): if type(search_string) == type(''): search_string = [search_string] if not case_sens: search_string = [i.lower() for i in search_string] with open(search_file) as fp: for line in fp: query_line = line if case_sens else line.lower() if all([i in query_line for i in search_string]): return line if return_string else True if return_string: raise Exception('%s not found in %s'%(' & '.join(search_string), search_file)) else: return False else: raise Exception('%s file does not exist'%search_file)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:action_remove; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:request; 6, identifier:category_list; 7, block; 7, 8; 7, 25; 7, 40; 7, 51; 7, 62; 7, 73; 7, 83; 7, 95; 7, 119; 7, 127; 7, 186; 7, 199; 7, 207; 7, 247; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:category_list; 13, identifier:editor; 14, identifier:allow_remove; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:SitecatsSecurityException; 19, argument_list; 19, 20; 20, binary_operator:%; 20, 21; 20, 22; 21, string:'`action_remove()` is not supported by parent `%s`category.'; 22, attribute; 22, 23; 22, 24; 23, identifier:category_list; 24, identifier:alias; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:category_id; 28, call; 28, 29; 28, 30; 29, identifier:int; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:request; 35, identifier:POST; 36, identifier:get; 37, argument_list; 37, 38; 37, 39; 38, string:'category_id'; 39, integer:0; 40, if_statement; 40, 41; 40, 43; 41, not_operator; 41, 42; 42, identifier:category_id; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:SitecatsSecurityException; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 50; 49, string:'Unsupported `category_id` value - `%s` - is passed to `action_remove()`.'; 50, identifier:category_id; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:category; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, call; 56, 57; 56, 58; 57, identifier:get_cache; 58, argument_list; 59, identifier:get_category_by_id; 60, argument_list; 60, 61; 61, identifier:category_id; 62, if_statement; 62, 63; 62, 65; 63, not_operator; 63, 64; 64, identifier:category; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:SitecatsSecurityException; 69, argument_list; 69, 70; 70, binary_operator:%; 70, 71; 70, 72; 71, string:'Unable to get `%s` category in `action_remove()`.'; 72, identifier:category_id; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:cat_ident; 76, boolean_operator:or; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:category; 79, identifier:alias; 80, attribute; 80, 81; 80, 82; 81, identifier:category; 82, identifier:id; 83, if_statement; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:category; 86, identifier:is_locked; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:SitecatsSecurityException; 91, argument_list; 91, 92; 92, binary_operator:%; 92, 93; 92, 94; 93, string:'`action_remove()` is not supported by `%s` category.'; 94, identifier:cat_ident; 95, if_statement; 95, 96; 95, 105; 96, comparison_operator:!=; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:category; 99, identifier:parent_id; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:category_list; 103, identifier:get_id; 104, argument_list; 105, block; 105, 106; 106, raise_statement; 106, 107; 107, call; 107, 108; 107, 109; 108, identifier:SitecatsSecurityException; 109, argument_list; 109, 110; 110, binary_operator:%; 110, 111; 110, 114; 111, concatenated_string; 111, 112; 111, 113; 112, string:'`action_remove()` is unable to remove `%s`: '; 113, string:'not a child of parent `%s` category.'; 114, tuple; 114, 115; 114, 116; 115, identifier:cat_ident; 116, attribute; 116, 117; 116, 118; 117, identifier:category_list; 118, identifier:alias; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:min_num; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:category_list; 125, identifier:editor; 126, identifier:min_num; 127, function_definition; 127, 128; 127, 129; 127, 131; 128, function_name:check_min_num; 129, parameters; 129, 130; 130, identifier:num; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 142; 133, boolean_operator:and; 133, 134; 133, 137; 134, comparison_operator:is; 134, 135; 134, 136; 135, identifier:min_num; 136, None; 137, comparison_operator:<; 137, 138; 137, 141; 138, binary_operator:-; 138, 139; 138, 140; 139, identifier:num; 140, integer:1; 141, identifier:min_num; 142, block; 142, 143; 142, 152; 142, 181; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:subcats_str; 146, call; 146, 147; 146, 148; 147, identifier:ungettext_lazy; 148, argument_list; 148, 149; 148, 150; 148, 151; 149, string:'subcategory'; 150, string:'subcategories'; 151, identifier:min_num; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:error_msg; 155, binary_operator:%; 155, 156; 155, 162; 156, call; 156, 157; 156, 158; 157, identifier:_; 158, argument_list; 158, 159; 159, concatenated_string; 159, 160; 159, 161; 160, string:'Unable to remove "%(target_category)s" category from "%(parent_category)s": '; 161, string:'parent category requires at least %(num)s %(subcats_str)s.'; 162, dictionary; 162, 163; 162, 168; 162, 175; 162, 178; 163, pair; 163, 164; 163, 165; 164, string:'target_category'; 165, attribute; 165, 166; 165, 167; 166, identifier:category; 167, identifier:title; 168, pair; 168, 169; 168, 170; 169, string:'parent_category'; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:category_list; 173, identifier:get_title; 174, argument_list; 175, pair; 175, 176; 175, 177; 176, string:'num'; 177, identifier:min_num; 178, pair; 178, 179; 178, 180; 179, string:'subcats_str'; 180, identifier:subcats_str; 181, raise_statement; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:SitecatsValidationError; 184, argument_list; 184, 185; 185, identifier:error_msg; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:child_ids; 189, call; 189, 190; 189, 195; 190, attribute; 190, 191; 190, 194; 191, call; 191, 192; 191, 193; 192, identifier:get_cache; 193, argument_list; 194, identifier:get_child_ids; 195, argument_list; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:category_list; 198, identifier:alias; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:check_min_num; 202, argument_list; 202, 203; 203, call; 203, 204; 203, 205; 204, identifier:len; 205, argument_list; 205, 206; 206, identifier:child_ids; 207, if_statement; 207, 208; 207, 213; 207, 220; 208, comparison_operator:is; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:category_list; 211, identifier:obj; 212, None; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:category; 218, identifier:delete; 219, argument_list; 220, else_clause; 220, 221; 221, block; 221, 222; 221, 238; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:check_min_num; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 237; 227, attribute; 227, 228; 227, 236; 228, call; 228, 229; 228, 234; 229, attribute; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:category_list; 232, identifier:obj; 233, identifier:get_ties_for_categories_qs; 234, argument_list; 234, 235; 235, identifier:child_ids; 236, identifier:count; 237, argument_list; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:category_list; 243, identifier:obj; 244, identifier:remove_from_category; 245, argument_list; 245, 246; 246, identifier:category; 247, return_statement; 247, 248; 248, True
def action_remove(cls, request, category_list): if not category_list.editor.allow_remove: raise SitecatsSecurityException( '`action_remove()` is not supported by parent `%s`category.' % category_list.alias) category_id = int(request.POST.get('category_id', 0)) if not category_id: raise SitecatsSecurityException( 'Unsupported `category_id` value - `%s` - is passed to `action_remove()`.' % category_id) category = get_cache().get_category_by_id(category_id) if not category: raise SitecatsSecurityException('Unable to get `%s` category in `action_remove()`.' % category_id) cat_ident = category.alias or category.id if category.is_locked: raise SitecatsSecurityException('`action_remove()` is not supported by `%s` category.' % cat_ident) if category.parent_id != category_list.get_id(): raise SitecatsSecurityException( '`action_remove()` is unable to remove `%s`: ' 'not a child of parent `%s` category.' % (cat_ident, category_list.alias) ) min_num = category_list.editor.min_num def check_min_num(num): if min_num is not None and num-1 < min_num: subcats_str = ungettext_lazy('subcategory', 'subcategories', min_num) error_msg = _( 'Unable to remove "%(target_category)s" category from "%(parent_category)s": ' 'parent category requires at least %(num)s %(subcats_str)s.' ) % { 'target_category': category.title, 'parent_category': category_list.get_title(), 'num': min_num, 'subcats_str': subcats_str } raise SitecatsValidationError(error_msg) child_ids = get_cache().get_child_ids(category_list.alias) check_min_num(len(child_ids)) if category_list.obj is None: category.delete() else: check_min_num(category_list.obj.get_ties_for_categories_qs(child_ids).count()) category_list.obj.remove_from_category(category) return True
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:action_add; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:request; 6, identifier:category_list; 7, block; 7, 8; 7, 25; 7, 41; 7, 52; 7, 95; 7, 154; 7, 158; 7, 330; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:category_list; 13, identifier:editor; 14, identifier:allow_add; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:SitecatsSecurityException; 19, argument_list; 19, 20; 20, binary_operator:%; 20, 21; 20, 22; 21, string:'`action_add()` is not supported by `%s` category.'; 22, attribute; 22, 23; 22, 24; 23, identifier:category_list; 24, identifier:alias; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:titles; 28, call; 28, 29; 28, 40; 29, attribute; 29, 30; 29, 39; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:request; 34, identifier:POST; 35, identifier:get; 36, argument_list; 36, 37; 36, 38; 37, string:'category_title'; 38, string:''; 39, identifier:strip; 40, argument_list; 41, if_statement; 41, 42; 41, 44; 42, not_operator; 42, 43; 43, identifier:titles; 44, block; 44, 45; 45, raise_statement; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:SitecatsSecurityException; 48, argument_list; 48, 49; 49, binary_operator:%; 49, 50; 49, 51; 50, string:'Unsupported `category_title` value - `%s` - is passed to `action_add()`.'; 51, identifier:titles; 52, if_statement; 52, 53; 52, 60; 52, 66; 53, comparison_operator:is; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:category_list; 57, identifier:editor; 58, identifier:category_separator; 59, None; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:titles; 64, list:[titles]; 64, 65; 65, identifier:titles; 66, else_clause; 66, 67; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:titles; 71, list_comprehension; 71, 72; 71, 77; 71, 89; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:title; 75, identifier:strip; 76, argument_list; 77, for_in_clause; 77, 78; 77, 79; 78, identifier:title; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:titles; 82, identifier:split; 83, argument_list; 83, 84; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:category_list; 87, identifier:editor; 88, identifier:category_separator; 89, if_clause; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:title; 93, identifier:strip; 94, argument_list; 95, function_definition; 95, 96; 95, 97; 95, 101; 96, function_name:check_max_num; 97, parameters; 97, 98; 97, 99; 97, 100; 98, identifier:num; 99, identifier:max_num; 100, identifier:category_title; 101, block; 101, 102; 102, if_statement; 102, 103; 102, 112; 103, boolean_operator:and; 103, 104; 103, 107; 104, comparison_operator:is; 104, 105; 104, 106; 105, identifier:max_num; 106, None; 107, comparison_operator:>; 107, 108; 107, 111; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:num; 110, integer:1; 111, identifier:max_num; 112, block; 112, 113; 112, 122; 112, 149; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:subcats_str; 116, call; 116, 117; 116, 118; 117, identifier:ungettext_lazy; 118, argument_list; 118, 119; 118, 120; 118, 121; 119, string:'subcategory'; 120, string:'subcategories'; 121, identifier:max_num; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:error_msg; 125, binary_operator:%; 125, 126; 125, 132; 126, call; 126, 127; 126, 128; 127, identifier:_; 128, argument_list; 128, 129; 129, concatenated_string; 129, 130; 129, 131; 130, string:'Unable to add "%(target_category)s" category into "%(parent_category)s": '; 131, string:'parent category can have at most %(num)s %(subcats_str)s.'; 132, dictionary; 132, 133; 132, 136; 132, 143; 132, 146; 133, pair; 133, 134; 133, 135; 134, string:'target_category'; 135, identifier:category_title; 136, pair; 136, 137; 136, 138; 137, string:'parent_category'; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:category_list; 141, identifier:get_title; 142, argument_list; 143, pair; 143, 144; 143, 145; 144, string:'num'; 145, identifier:max_num; 146, pair; 146, 147; 146, 148; 147, string:'subcats_str'; 148, identifier:subcats_str; 149, raise_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:SitecatsValidationError; 152, argument_list; 152, 153; 153, identifier:error_msg; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:target_category; 157, None; 158, for_statement; 158, 159; 158, 160; 158, 161; 159, identifier:category_title; 160, identifier:titles; 161, block; 161, 162; 161, 176; 161, 187; 161, 224; 161, 232; 161, 245; 161, 293; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:exists; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, call; 167, 168; 167, 169; 168, identifier:get_cache; 169, argument_list; 170, identifier:find_category; 171, argument_list; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:category_list; 174, identifier:alias; 175, identifier:category_title; 176, if_statement; 176, 177; 176, 184; 177, boolean_operator:and; 177, 178; 177, 179; 178, identifier:exists; 179, comparison_operator:is; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:category_list; 182, identifier:obj; 183, None; 184, block; 184, 185; 185, return_statement; 185, 186; 186, identifier:exists; 187, if_statement; 187, 188; 187, 197; 188, boolean_operator:and; 188, 189; 188, 191; 189, not_operator; 189, 190; 190, identifier:exists; 191, not_operator; 191, 192; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:category_list; 195, identifier:editor; 196, identifier:allow_new; 197, block; 197, 198; 197, 219; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:error_msg; 201, binary_operator:%; 201, 202; 201, 208; 202, call; 202, 203; 202, 204; 203, identifier:_; 204, argument_list; 204, 205; 205, concatenated_string; 205, 206; 205, 207; 206, string:'Unable to create a new "%(new_category)s" category inside of "%(parent_category)s": '; 207, string:'parent category does not support this action.'; 208, dictionary; 208, 209; 208, 212; 209, pair; 209, 210; 209, 211; 210, string:'new_category'; 211, identifier:category_title; 212, pair; 212, 213; 212, 214; 213, string:'parent_category'; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:category_list; 217, identifier:get_title; 218, argument_list; 219, raise_statement; 219, 220; 220, call; 220, 221; 220, 222; 221, identifier:SitecatsNewCategoryException; 222, argument_list; 222, 223; 223, identifier:error_msg; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:max_num; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:category_list; 230, identifier:editor; 231, identifier:max_num; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:child_ids; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, call; 237, 238; 237, 239; 238, identifier:get_cache; 239, argument_list; 240, identifier:get_child_ids; 241, argument_list; 241, 242; 242, attribute; 242, 243; 242, 244; 243, identifier:category_list; 244, identifier:alias; 245, if_statement; 245, 246; 245, 248; 245, 287; 246, not_operator; 246, 247; 247, identifier:exists; 248, block; 248, 249; 248, 266; 249, if_statement; 249, 250; 249, 255; 250, comparison_operator:is; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:category_list; 253, identifier:obj; 254, None; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:check_max_num; 259, argument_list; 259, 260; 259, 264; 259, 265; 260, call; 260, 261; 260, 262; 261, identifier:len; 262, argument_list; 262, 263; 263, identifier:child_ids; 264, identifier:max_num; 265, identifier:category_title; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:target_category; 269, call; 269, 270; 269, 275; 270, attribute; 270, 271; 270, 274; 271, call; 271, 272; 271, 273; 272, identifier:get_category_model; 273, argument_list; 274, identifier:add; 275, argument_list; 275, 276; 275, 277; 275, 280; 276, identifier:category_title; 277, attribute; 277, 278; 277, 279; 278, identifier:request; 279, identifier:user; 280, keyword_argument; 280, 281; 280, 282; 281, identifier:parent; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:category_list; 285, identifier:get_category_model; 286, argument_list; 287, else_clause; 287, 288; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:target_category; 292, identifier:exists; 293, if_statement; 293, 294; 293, 299; 294, comparison_operator:is; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:category_list; 297, identifier:obj; 298, None; 299, block; 299, 300; 299, 318; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 303; 302, identifier:check_max_num; 303, argument_list; 303, 304; 303, 316; 303, 317; 304, call; 304, 305; 304, 315; 305, attribute; 305, 306; 305, 314; 306, call; 306, 307; 306, 312; 307, attribute; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:category_list; 310, identifier:obj; 311, identifier:get_ties_for_categories_qs; 312, argument_list; 312, 313; 313, identifier:child_ids; 314, identifier:count; 315, argument_list; 316, identifier:max_num; 317, identifier:category_title; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 325; 320, attribute; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:category_list; 323, identifier:obj; 324, identifier:add_to_category; 325, argument_list; 325, 326; 325, 327; 326, identifier:target_category; 327, attribute; 327, 328; 327, 329; 328, identifier:request; 329, identifier:user; 330, return_statement; 330, 331; 331, identifier:target_category
def action_add(cls, request, category_list): if not category_list.editor.allow_add: raise SitecatsSecurityException('`action_add()` is not supported by `%s` category.' % category_list.alias) titles = request.POST.get('category_title', '').strip() if not titles: raise SitecatsSecurityException( 'Unsupported `category_title` value - `%s` - is passed to `action_add()`.' % titles) if category_list.editor.category_separator is None: titles = [titles] else: titles = [ title.strip() for title in titles.split(category_list.editor.category_separator) if title.strip() ] def check_max_num(num, max_num, category_title): if max_num is not None and num+1 > max_num: subcats_str = ungettext_lazy('subcategory', 'subcategories', max_num) error_msg = _( 'Unable to add "%(target_category)s" category into "%(parent_category)s": ' 'parent category can have at most %(num)s %(subcats_str)s.' ) % { 'target_category': category_title, 'parent_category': category_list.get_title(), 'num': max_num, 'subcats_str': subcats_str } raise SitecatsValidationError(error_msg) target_category = None for category_title in titles: exists = get_cache().find_category(category_list.alias, category_title) if exists and category_list.obj is None: return exists if not exists and not category_list.editor.allow_new: error_msg = _( 'Unable to create a new "%(new_category)s" category inside of "%(parent_category)s": ' 'parent category does not support this action.' ) % { 'new_category': category_title, 'parent_category': category_list.get_title() } raise SitecatsNewCategoryException(error_msg) max_num = category_list.editor.max_num child_ids = get_cache().get_child_ids(category_list.alias) if not exists: if category_list.obj is None: check_max_num(len(child_ids), max_num, category_title) target_category = get_category_model().add( category_title, request.user, parent=category_list.get_category_model() ) else: target_category = exists if category_list.obj is not None: check_max_num(category_list.obj.get_ties_for_categories_qs(child_ids).count(), max_num, category_title) category_list.obj.add_to_category(target_category, request.user) return target_category
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:verify; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 12; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:headers; 7, type; 7, 8; 8, identifier:Mapping; 9, default_parameter; 9, 10; 9, 11; 10, identifier:method; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:path; 14, None; 15, block; 15, 16; 15, 24; 15, 35; 15, 46; 15, 68; 15, 92; 15, 106; 15, 128; 15, 140; 15, 161; 15, 174; 15, 188; 15, 198; 15, 210; 15, 220; 15, 226; 15, 234; 15, 263; 16, if_statement; 16, 17; 16, 21; 17, not_operator; 17, 18; 18, comparison_operator:in; 18, 19; 18, 20; 19, string:'authorization'; 20, identifier:headers; 21, block; 21, 22; 22, return_statement; 22, 23; 23, False; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:auth_type; 28, identifier:auth_params; 29, call; 29, 30; 29, 31; 30, identifier:parse_authorization_header; 31, argument_list; 31, 32; 32, subscript; 32, 33; 32, 34; 33, identifier:headers; 34, string:'authorization'; 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:auth_type; 40, identifier:lower; 41, argument_list; 42, string:'signature'; 43, block; 43, 44; 44, return_statement; 44, 45; 45, False; 46, for_statement; 46, 47; 46, 48; 46, 52; 47, identifier:param; 48, tuple; 48, 49; 48, 50; 48, 51; 49, string:'algorithm'; 50, string:'keyId'; 51, string:'signature'; 52, block; 52, 53; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:not; 54, 55; 54, 56; 55, identifier:param; 56, identifier:auth_params; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:VerifierException; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, string:"Unsupported HTTP signature, missing '{}'"; 65, identifier:format; 66, argument_list; 66, 67; 67, identifier:param; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:auth_headers; 71, call; 71, 72; 71, 91; 72, attribute; 72, 73; 72, 90; 73, call; 73, 74; 73, 89; 74, attribute; 74, 75; 74, 88; 75, call; 75, 76; 75, 87; 76, attribute; 76, 77; 76, 86; 77, parenthesized_expression; 77, 78; 78, boolean_operator:or; 78, 79; 78, 85; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:auth_params; 82, identifier:get; 83, argument_list; 83, 84; 84, string:'headers'; 85, string:'date'; 86, identifier:lower; 87, argument_list; 88, identifier:strip; 89, argument_list; 90, identifier:split; 91, argument_list; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:missing_reqd; 95, binary_operator:-; 95, 96; 95, 102; 96, call; 96, 97; 96, 98; 97, identifier:set; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:_required_headers; 102, call; 102, 103; 102, 104; 103, identifier:set; 104, argument_list; 104, 105; 105, identifier:auth_headers; 106, if_statement; 106, 107; 106, 108; 107, identifier:missing_reqd; 108, block; 108, 109; 108, 118; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:error_headers; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, string:', '; 115, identifier:join; 116, argument_list; 116, 117; 117, identifier:missing_reqd; 118, raise_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:VerifierException; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, string:'One or more required headers not provided: {}'; 125, identifier:format; 126, argument_list; 126, 127; 127, identifier:error_headers; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 133; 130, pattern_list; 130, 131; 130, 132; 131, identifier:key_id; 132, identifier:algo; 133, expression_list; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:auth_params; 136, string:'keyId'; 137, subscript; 137, 138; 137, 139; 138, identifier:auth_params; 139, string:'algorithm'; 140, if_statement; 140, 141; 140, 150; 141, not_operator; 141, 142; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:_handlers; 147, identifier:supports; 148, argument_list; 148, 149; 149, identifier:algo; 150, block; 150, 151; 151, raise_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:VerifierException; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, string:"Unsupported HTTP signature algorithm '{}'"; 158, identifier:format; 159, argument_list; 159, 160; 160, identifier:algo; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:pubkey; 164, await; 164, 165; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_key_finder; 170, identifier:find_key; 171, argument_list; 171, 172; 171, 173; 172, identifier:key_id; 173, identifier:algo; 174, if_statement; 174, 175; 174, 177; 175, not_operator; 175, 176; 176, identifier:pubkey; 177, block; 177, 178; 178, raise_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:VerifierException; 181, argument_list; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, string:"Cannot locate public key for '{}'"; 185, identifier:format; 186, argument_list; 186, 187; 187, identifier:key_id; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:LOGGER; 192, identifier:debug; 193, argument_list; 193, 194; 193, 195; 193, 196; 193, 197; 194, string:"Got %s public key for '%s': %s"; 195, identifier:algo; 196, identifier:key_id; 197, identifier:pubkey; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:handler; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:_handlers; 206, identifier:create_verifier; 207, argument_list; 207, 208; 207, 209; 208, identifier:algo; 209, identifier:pubkey; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:message; 213, call; 213, 214; 213, 215; 214, identifier:generate_message; 215, argument_list; 215, 216; 215, 217; 215, 218; 215, 219; 216, identifier:auth_headers; 217, identifier:headers; 218, identifier:method; 219, identifier:path; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:signature; 223, subscript; 223, 224; 223, 225; 224, identifier:auth_params; 225, string:'signature'; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:raw_signature; 229, call; 229, 230; 229, 231; 230, identifier:decode_string; 231, argument_list; 231, 232; 231, 233; 232, identifier:signature; 233, string:'base64'; 234, if_statement; 234, 235; 234, 242; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:handler; 238, identifier:verify; 239, argument_list; 239, 240; 239, 241; 240, identifier:message; 241, identifier:raw_signature; 242, block; 242, 243; 243, return_statement; 243, 244; 244, dictionary; 244, 245; 244, 248; 244, 251; 244, 254; 244, 257; 244, 260; 245, pair; 245, 246; 245, 247; 246, string:'verified'; 247, True; 248, pair; 248, 249; 248, 250; 249, string:'algorithm'; 250, identifier:algo; 251, pair; 251, 252; 251, 253; 252, string:'headers'; 253, identifier:auth_headers; 254, pair; 254, 255; 254, 256; 255, string:'keyId'; 256, identifier:key_id; 257, pair; 257, 258; 257, 259; 258, string:'key'; 259, identifier:pubkey; 260, pair; 260, 261; 260, 262; 261, string:'signature'; 262, identifier:signature; 263, raise_statement; 263, 264; 264, call; 264, 265; 264, 266; 265, identifier:VerifierException; 266, argument_list; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, string:"Signature could not be verified for keyId '{}'"; 270, identifier:format; 271, argument_list; 271, 272; 272, identifier:key_id
async def verify(self, headers: Mapping, method=None, path=None): if not 'authorization' in headers: return False auth_type, auth_params = parse_authorization_header(headers['authorization']) if auth_type.lower() != 'signature': return False for param in ('algorithm', 'keyId', 'signature'): if param not in auth_params: raise VerifierException("Unsupported HTTP signature, missing '{}'".format(param)) auth_headers = (auth_params.get('headers') or 'date').lower().strip().split() missing_reqd = set(self._required_headers) - set(auth_headers) if missing_reqd: error_headers = ', '.join(missing_reqd) raise VerifierException( 'One or more required headers not provided: {}'.format(error_headers)) key_id, algo = auth_params['keyId'], auth_params['algorithm'] if not self._handlers.supports(algo): raise VerifierException("Unsupported HTTP signature algorithm '{}'".format(algo)) pubkey = await self._key_finder.find_key(key_id, algo) if not pubkey: raise VerifierException("Cannot locate public key for '{}'".format(key_id)) LOGGER.debug("Got %s public key for '%s': %s", algo, key_id, pubkey) handler = self._handlers.create_verifier(algo, pubkey) message = generate_message(auth_headers, headers, method, path) signature = auth_params['signature'] raw_signature = decode_string(signature, 'base64') if handler.verify(message, raw_signature): return { 'verified': True, 'algorithm': algo, 'headers': auth_headers, 'keyId': key_id, 'key': pubkey, 'signature': signature } raise VerifierException("Signature could not be verified for keyId '{}'".format(key_id))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:set_config; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:config; 7, block; 7, 8; 7, 12; 7, 41; 7, 72; 7, 103; 7, 119; 7, 150; 7, 181; 7, 214; 7, 245; 7, 261; 7, 277; 7, 308; 7, 332; 7, 366; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:reinit; 11, False; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:in; 13, 14; 13, 15; 14, string:'stdopt'; 15, identifier:config; 16, block; 16, 17; 16, 26; 16, 35; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:stdopt; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:config; 23, identifier:pop; 24, argument_list; 24, 25; 25, string:'stdopt'; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:reinit; 29, parenthesized_expression; 29, 30; 30, comparison_operator:!=; 30, 31; 30, 32; 31, identifier:stdopt; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:stdopt; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:stdopt; 40, identifier:stdopt; 41, if_statement; 41, 42; 41, 45; 42, comparison_operator:in; 42, 43; 42, 44; 43, string:'attachopt'; 44, identifier:config; 45, block; 45, 46; 45, 55; 45, 66; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:attachopt; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:config; 52, identifier:pop; 53, argument_list; 53, 54; 54, string:'attachopt'; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:reinit; 58, boolean_operator:or; 58, 59; 58, 60; 59, identifier:reinit; 60, parenthesized_expression; 60, 61; 61, comparison_operator:!=; 61, 62; 61, 63; 62, identifier:attachopt; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:attachopt; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:attachopt; 71, identifier:attachopt; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:in; 73, 74; 73, 75; 74, string:'attachvalue'; 75, identifier:config; 76, block; 76, 77; 76, 86; 76, 97; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:attachvalue; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:config; 83, identifier:pop; 84, argument_list; 84, 85; 85, string:'attachvalue'; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:reinit; 89, boolean_operator:or; 89, 90; 89, 91; 90, identifier:reinit; 91, parenthesized_expression; 91, 92; 92, comparison_operator:!=; 92, 93; 92, 94; 93, identifier:attachvalue; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:attachvalue; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:attachvalue; 102, identifier:attachvalue; 103, if_statement; 103, 104; 103, 107; 104, comparison_operator:in; 104, 105; 104, 106; 105, string:'auto2dashes'; 106, identifier:config; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:auto2dashes; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:config; 116, identifier:pop; 117, argument_list; 117, 118; 118, string:'auto2dashes'; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:in; 120, 121; 120, 122; 121, string:'name'; 122, identifier:config; 123, block; 123, 124; 123, 133; 123, 144; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:name; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:config; 130, identifier:pop; 131, argument_list; 131, 132; 132, string:'name'; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:reinit; 136, boolean_operator:or; 136, 137; 136, 138; 137, identifier:reinit; 138, parenthesized_expression; 138, 139; 139, comparison_operator:!=; 139, 140; 139, 141; 140, identifier:name; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:name; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:name; 149, identifier:name; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:in; 151, 152; 151, 153; 152, string:'help'; 153, identifier:config; 154, block; 154, 155; 154, 166; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:help; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:config; 163, identifier:pop; 164, argument_list; 164, 165; 165, string:'help'; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:_set_or_remove_extra_handler; 171, argument_list; 171, 172; 171, 175; 171, 178; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:help; 175, tuple; 175, 176; 175, 177; 176, string:'--help'; 177, string:'-h'; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:help_handler; 181, if_statement; 181, 182; 181, 185; 182, comparison_operator:in; 182, 183; 182, 184; 183, string:'version'; 184, identifier:config; 185, block; 185, 186; 185, 197; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:version; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:config; 194, identifier:pop; 195, argument_list; 195, 196; 196, string:'version'; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:_set_or_remove_extra_handler; 202, argument_list; 202, 203; 202, 208; 202, 211; 203, comparison_operator:is; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:version; 207, None; 208, tuple; 208, 209; 208, 210; 209, string:'--version'; 210, string:'-v'; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:version_handler; 214, if_statement; 214, 215; 214, 218; 215, comparison_operator:in; 215, 216; 215, 217; 216, string:'case_sensitive'; 217, identifier:config; 218, block; 218, 219; 218, 228; 218, 239; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:case_sensitive; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:config; 225, identifier:pop; 226, argument_list; 226, 227; 227, string:'case_sensitive'; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:reinit; 231, boolean_operator:or; 231, 232; 231, 233; 232, identifier:reinit; 233, parenthesized_expression; 233, 234; 234, comparison_operator:!=; 234, 235; 234, 236; 235, identifier:case_sensitive; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:case_sensitive; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:case_sensitive; 244, identifier:case_sensitive; 245, if_statement; 245, 246; 245, 249; 246, comparison_operator:in; 246, 247; 246, 248; 247, string:'optionsfirst'; 248, identifier:config; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:options_first; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:config; 258, identifier:pop; 259, argument_list; 259, 260; 260, string:'optionsfirst'; 261, if_statement; 261, 262; 261, 265; 262, comparison_operator:in; 262, 263; 262, 264; 263, string:'appearedonly'; 264, identifier:config; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:appeared_only; 271, call; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:config; 274, identifier:pop; 275, argument_list; 275, 276; 276, string:'appearedonly'; 277, if_statement; 277, 278; 277, 281; 278, comparison_operator:in; 278, 279; 278, 280; 279, string:'namedoptions'; 280, identifier:config; 281, block; 281, 282; 281, 291; 281, 302; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:namedoptions; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:config; 288, identifier:pop; 289, argument_list; 289, 290; 290, string:'namedoptions'; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:reinit; 294, boolean_operator:or; 294, 295; 294, 296; 295, identifier:reinit; 296, parenthesized_expression; 296, 297; 297, comparison_operator:!=; 297, 298; 297, 299; 298, identifier:namedoptions; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:namedoptions; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:namedoptions; 307, identifier:namedoptions; 308, if_statement; 308, 309; 308, 312; 309, comparison_operator:in; 309, 310; 309, 311; 310, string:'extra'; 311, identifier:config; 312, block; 312, 313; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 320; 315, attribute; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:extra; 319, identifier:update; 320, argument_list; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:self; 324, identifier:_formal_extra; 325, argument_list; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:config; 329, identifier:pop; 330, argument_list; 330, 331; 331, string:'extra'; 332, if_statement; 332, 333; 332, 334; 333, identifier:config; 334, block; 334, 335; 335, raise_statement; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:ValueError; 338, argument_list; 338, 339; 339, binary_operator:%; 339, 340; 339, 341; 340, string:'`%s` %s not accepted key argument%s'; 341, tuple; 341, 342; 341, 348; 341, 357; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, string:'`, `'; 345, identifier:join; 346, argument_list; 346, 347; 347, identifier:config; 348, conditional_expression:if; 348, 349; 348, 350; 348, 356; 349, string:'is'; 350, comparison_operator:==; 350, 351; 350, 355; 351, call; 351, 352; 351, 353; 352, identifier:len; 353, argument_list; 353, 354; 354, identifier:config; 355, integer:1; 356, string:'are'; 357, conditional_expression:if; 357, 358; 357, 359; 357, 365; 358, string:''; 359, comparison_operator:==; 359, 360; 359, 364; 360, call; 360, 361; 360, 362; 361, identifier:len; 362, argument_list; 362, 363; 363, identifier:config; 364, integer:1; 365, string:'s'; 366, if_statement; 366, 367; 366, 374; 367, boolean_operator:and; 367, 368; 367, 373; 368, comparison_operator:is; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:self; 371, identifier:doc; 372, None; 373, identifier:reinit; 374, block; 374, 375; 374, 384; 375, expression_statement; 375, 376; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:logger; 379, identifier:warning; 380, argument_list; 380, 381; 381, concatenated_string; 381, 382; 381, 383; 382, string:'You changed the config that requires re-initialized'; 383, string:' `Docpie` object. Create a new one instead'; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:self; 388, identifier:_init; 389, argument_list
def set_config(self, **config): reinit = False if 'stdopt' in config: stdopt = config.pop('stdopt') reinit = (stdopt != self.stdopt) self.stdopt = stdopt if 'attachopt' in config: attachopt = config.pop('attachopt') reinit = reinit or (attachopt != self.attachopt) self.attachopt = attachopt if 'attachvalue' in config: attachvalue = config.pop('attachvalue') reinit = reinit or (attachvalue != self.attachvalue) self.attachvalue = attachvalue if 'auto2dashes' in config: self.auto2dashes = config.pop('auto2dashes') if 'name' in config: name = config.pop('name') reinit = reinit or (name != self.name) self.name = name if 'help' in config: self.help = config.pop('help') self._set_or_remove_extra_handler( self.help, ('--help', '-h'), self.help_handler) if 'version' in config: self.version = config.pop('version') self._set_or_remove_extra_handler( self.version is not None, ('--version', '-v'), self.version_handler) if 'case_sensitive' in config: case_sensitive = config.pop('case_sensitive') reinit = reinit or (case_sensitive != self.case_sensitive) self.case_sensitive = case_sensitive if 'optionsfirst' in config: self.options_first = config.pop('optionsfirst') if 'appearedonly' in config: self.appeared_only = config.pop('appearedonly') if 'namedoptions' in config: namedoptions = config.pop('namedoptions') reinit = reinit or (namedoptions != self.namedoptions) self.namedoptions = namedoptions if 'extra' in config: self.extra.update(self._formal_extra(config.pop('extra'))) if config: raise ValueError( '`%s` %s not accepted key argument%s' % ( '`, `'.join(config), 'is' if len(config) == 1 else 'are', '' if len(config) == 1 else 's' )) if self.doc is not None and reinit: logger.warning( 'You changed the config that requires re-initialized' ' `Docpie` object. Create a new one instead' ) self._init()
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:preview; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:stream; 7, attribute; 7, 8; 7, 9; 8, identifier:sys; 9, identifier:stdout; 10, block; 10, 11; 10, 17; 10, 33; 10, 38; 10, 49; 10, 54; 10, 61; 10, 66; 10, 72; 10, 94; 10, 99; 10, 110; 10, 119; 10, 132; 10, 137; 10, 196; 10, 207; 10, 216; 10, 229; 10, 234; 10, 293; 10, 304; 10, 309; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:write; 14, attribute; 14, 15; 14, 16; 15, identifier:stream; 16, identifier:write; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:write; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 30; 22, attribute; 22, 23; 22, 29; 23, parenthesized_expression; 23, 24; 24, binary_operator:%; 24, 25; 24, 26; 25, string:'[Quick preview of Docpie %s]'; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_version; 29, identifier:center; 30, argument_list; 30, 31; 30, 32; 31, integer:80; 32, string:'='; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:write; 36, argument_list; 36, 37; 37, string:'\n'; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:write; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, string:' sections '; 45, identifier:center; 46, argument_list; 46, 47; 46, 48; 47, integer:80; 48, string:'-'; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:write; 52, argument_list; 52, 53; 53, string:'\n'; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:write; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:usage_text; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:write; 64, argument_list; 64, 65; 65, string:'\n'; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:option_sections; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:option_sections; 72, if_statement; 72, 73; 72, 74; 73, identifier:option_sections; 74, block; 74, 75; 74, 80; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:write; 78, argument_list; 78, 79; 79, string:'\n'; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:write; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, string:'\n'; 87, identifier:join; 88, argument_list; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:option_sections; 92, identifier:values; 93, argument_list; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:write; 97, argument_list; 97, 98; 98, string:'\n'; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:write; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, string:' str '; 106, identifier:center; 107, argument_list; 107, 108; 107, 109; 108, integer:80; 109, string:'-'; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:write; 113, argument_list; 113, 114; 114, binary_operator:%; 114, 115; 114, 116; 115, string:'\n[%s]\n'; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:usage_name; 119, for_statement; 119, 120; 119, 121; 119, 124; 120, identifier:each; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:usages; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:write; 128, argument_list; 128, 129; 129, binary_operator:%; 129, 130; 129, 131; 130, string:' %s\n'; 131, identifier:each; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:write; 135, argument_list; 135, 136; 136, string:'\n[Options:]\n\n'; 137, for_statement; 137, 138; 137, 141; 137, 148; 138, pattern_list; 138, 139; 138, 140; 139, identifier:title; 140, identifier:sections; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:options; 146, identifier:items; 147, argument_list; 148, block; 148, 149; 148, 170; 148, 175; 148, 180; 148, 191; 149, if_statement; 149, 150; 149, 151; 149, 162; 150, identifier:title; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:full_title; 155, binary_operator:%; 155, 156; 155, 157; 156, string:'%s %s'; 157, tuple; 157, 158; 157, 159; 158, identifier:title; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:option_name; 162, else_clause; 162, 163; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:full_title; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:option_name; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:write; 173, argument_list; 173, 174; 174, identifier:full_title; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:write; 178, argument_list; 178, 179; 179, string:'\n'; 180, for_statement; 180, 181; 180, 182; 180, 183; 181, identifier:each; 182, identifier:sections; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:write; 187, argument_list; 187, 188; 188, binary_operator:%; 188, 189; 188, 190; 189, string:' %s\n'; 190, identifier:each; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:write; 194, argument_list; 194, 195; 195, string:'\n'; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:write; 199, argument_list; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, string:' repr '; 203, identifier:center; 204, argument_list; 204, 205; 204, 206; 205, integer:80; 206, string:'-'; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 210; 209, identifier:write; 210, argument_list; 210, 211; 211, binary_operator:%; 211, 212; 211, 213; 212, string:'\n[%s]\n'; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:usage_name; 216, for_statement; 216, 217; 216, 218; 216, 221; 217, identifier:each; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:usages; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 225; 224, identifier:write; 225, argument_list; 225, 226; 226, binary_operator:%; 226, 227; 226, 228; 227, string:' %r\n'; 228, identifier:each; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 232; 231, identifier:write; 232, argument_list; 232, 233; 233, string:'\n[Options:]\n\n'; 234, for_statement; 234, 235; 234, 238; 234, 245; 235, pattern_list; 235, 236; 235, 237; 236, identifier:title; 237, identifier:sections; 238, call; 238, 239; 238, 244; 239, attribute; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:options; 243, identifier:items; 244, argument_list; 245, block; 245, 246; 245, 267; 245, 272; 245, 277; 245, 288; 246, if_statement; 246, 247; 246, 248; 246, 259; 247, identifier:title; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:full_title; 252, binary_operator:%; 252, 253; 252, 254; 253, string:'%s %s'; 254, tuple; 254, 255; 254, 256; 255, identifier:title; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:option_name; 259, else_clause; 259, 260; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:full_title; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:option_name; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:write; 270, argument_list; 270, 271; 271, identifier:full_title; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 275; 274, identifier:write; 275, argument_list; 275, 276; 276, string:'\n'; 277, for_statement; 277, 278; 277, 279; 277, 280; 278, identifier:each; 279, identifier:sections; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:write; 284, argument_list; 284, 285; 285, binary_operator:%; 285, 286; 285, 287; 286, string:' %r\n'; 287, identifier:each; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:write; 291, argument_list; 291, 292; 292, string:'\n'; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 296; 295, identifier:write; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, string:' auto handlers '; 300, identifier:center; 301, argument_list; 301, 302; 301, 303; 302, integer:80; 303, string:'-'; 304, expression_statement; 304, 305; 305, call; 305, 306; 305, 307; 306, identifier:write; 307, argument_list; 307, 308; 308, string:'\n'; 309, for_statement; 309, 310; 309, 313; 309, 320; 310, pattern_list; 310, 311; 310, 312; 311, identifier:key; 312, identifier:value; 313, call; 313, 314; 313, 319; 314, attribute; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:extra; 318, identifier:items; 319, argument_list; 320, block; 320, 321; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 324; 323, identifier:write; 324, argument_list; 324, 325; 325, binary_operator:%; 325, 326; 325, 327; 326, string:'%s %s\n'; 327, tuple; 327, 328; 327, 329; 328, identifier:key; 329, identifier:value
def preview(self, stream=sys.stdout): write = stream.write write(('[Quick preview of Docpie %s]' % self._version).center(80, '=')) write('\n') write(' sections '.center(80, '-')) write('\n') write(self.usage_text) write('\n') option_sections = self.option_sections if option_sections: write('\n') write('\n'.join(option_sections.values())) write('\n') write(' str '.center(80, '-')) write('\n[%s]\n' % self.usage_name) for each in self.usages: write(' %s\n' % each) write('\n[Options:]\n\n') for title, sections in self.options.items(): if title: full_title = '%s %s' % (title, self.option_name) else: full_title = self.option_name write(full_title) write('\n') for each in sections: write(' %s\n' % each) write('\n') write(' repr '.center(80, '-')) write('\n[%s]\n' % self.usage_name) for each in self.usages: write(' %r\n' % each) write('\n[Options:]\n\n') for title, sections in self.options.items(): if title: full_title = '%s %s' % (title, self.option_name) else: full_title = self.option_name write(full_title) write('\n') for each in sections: write(' %r\n' % each) write('\n') write(' auto handlers '.center(80, '-')) write('\n') for key, value in self.extra.items(): write('%s %s\n' % (key, value))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parts; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 16; 5, 20; 5, 24; 5, 28; 5, 38; 5, 42; 5, 110; 5, 180; 5, 207; 5, 242; 5, 251; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:parts; 9, list:[]; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:upserts; 13, call; 13, 14; 13, 15; 14, identifier:dict; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:deletes; 19, list:[]; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:max_upload_size; 23, integer:700000; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:base_part_size; 27, integer:118; 28, if_statement; 28, 29; 28, 33; 29, not_operator; 29, 30; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:replace_all; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, augmented_assignment:+=; 35, 36; 35, 37; 36, identifier:base_part_size; 37, integer:1; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:part_size; 41, identifier:base_part_size; 42, for_statement; 42, 43; 42, 44; 42, 47; 43, identifier:value; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:upserts; 47, block; 47, 48; 47, 88; 47, 102; 48, if_statement; 48, 49; 48, 59; 49, comparison_operator:>=; 49, 50; 49, 58; 50, parenthesized_expression; 50, 51; 51, binary_operator:+; 51, 52; 51, 53; 52, identifier:part_size; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:upserts_size; 57, identifier:value; 58, identifier:max_upload_size; 59, block; 59, 60; 59, 74; 59, 80; 59, 84; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:parts; 64, identifier:append; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:BatchPart; 68, argument_list; 68, 69; 68, 72; 68, 73; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:replace_all; 72, identifier:upserts; 73, identifier:deletes; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:upserts; 77, call; 77, 78; 77, 79; 78, identifier:dict; 79, argument_list; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:deletes; 83, list:[]; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:part_size; 87, identifier:base_part_size; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 97; 90, subscript; 90, 91; 90, 92; 91, identifier:upserts; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:lower_val_to_val; 96, identifier:value; 97, subscript; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:upserts; 101, identifier:value; 102, expression_statement; 102, 103; 103, augmented_assignment:+=; 103, 104; 103, 105; 104, identifier:part_size; 105, subscript; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:upserts_size; 109, identifier:value; 110, for_statement; 110, 111; 110, 112; 110, 115; 111, identifier:value; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:deletes; 115, block; 115, 116; 115, 157; 115, 171; 116, if_statement; 116, 117; 116, 128; 117, comparison_operator:>=; 117, 118; 117, 127; 118, parenthesized_expression; 118, 119; 119, binary_operator:+; 119, 120; 119, 126; 120, binary_operator:+; 120, 121; 120, 122; 121, identifier:part_size; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:value; 126, integer:4; 127, identifier:max_upload_size; 128, block; 128, 129; 128, 143; 128, 149; 128, 153; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:parts; 133, identifier:append; 134, argument_list; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:BatchPart; 137, argument_list; 137, 138; 137, 141; 137, 142; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:replace_all; 141, identifier:upserts; 142, identifier:deletes; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:upserts; 146, call; 146, 147; 146, 148; 147, identifier:dict; 148, argument_list; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:deletes; 152, list:[]; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:part_size; 156, identifier:base_part_size; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:deletes; 161, identifier:append; 162, argument_list; 162, 163; 163, dictionary; 163, 164; 164, pair; 164, 165; 164, 166; 165, string:'value'; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:lower_val_to_val; 170, identifier:value; 171, expression_statement; 171, 172; 172, augmented_assignment:+=; 172, 173; 172, 174; 173, identifier:part_size; 174, binary_operator:+; 174, 175; 174, 179; 175, call; 175, 176; 175, 177; 176, identifier:len; 177, argument_list; 177, 178; 178, identifier:value; 179, integer:4; 180, if_statement; 180, 181; 180, 192; 181, comparison_operator:>; 181, 182; 181, 191; 182, binary_operator:+; 182, 183; 182, 187; 183, call; 183, 184; 183, 185; 184, identifier:len; 185, argument_list; 185, 186; 186, identifier:upserts; 187, call; 187, 188; 187, 189; 188, identifier:len; 189, argument_list; 189, 190; 190, identifier:deletes; 191, integer:0; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:parts; 197, identifier:append; 198, argument_list; 198, 199; 199, call; 199, 200; 199, 201; 200, identifier:BatchPart; 201, argument_list; 201, 202; 201, 205; 201, 206; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:replace_all; 205, identifier:upserts; 206, identifier:deletes; 207, if_statement; 207, 208; 207, 214; 208, comparison_operator:==; 208, 209; 208, 213; 209, call; 209, 210; 209, 211; 210, identifier:len; 211, argument_list; 211, 212; 212, identifier:parts; 213, integer:0; 214, block; 214, 215; 214, 226; 215, if_statement; 215, 216; 215, 220; 216, not_operator; 216, 217; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:replace_all; 220, block; 220, 221; 221, raise_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:ValueError; 224, argument_list; 224, 225; 225, string:"Batch has no data, and 'replace_all' is False"; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:parts; 230, identifier:append; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 234; 233, identifier:BatchPart; 234, argument_list; 234, 235; 234, 238; 234, 241; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:replace_all; 238, call; 238, 239; 238, 240; 239, identifier:dict; 240, argument_list; 241, list:[]; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 250; 244, attribute; 244, 245; 244, 249; 245, subscript; 245, 246; 245, 247; 246, identifier:parts; 247, unary_operator:-; 247, 248; 248, integer:1; 249, identifier:set_last_part; 250, argument_list; 251, return_statement; 251, 252; 252, identifier:parts
def parts(self): parts = [] upserts = dict() deletes = [] max_upload_size = 700000 base_part_size = 118 if not self.replace_all: base_part_size += 1 part_size = base_part_size for value in self.upserts: if (part_size + self.upserts_size[value]) >= max_upload_size: parts.append(BatchPart(self.replace_all, upserts, deletes)) upserts = dict() deletes = [] part_size = base_part_size upserts[self.lower_val_to_val[value]] = self.upserts[value] part_size += self.upserts_size[value] for value in self.deletes: if (part_size + len(value) + 4) >= max_upload_size: parts.append(BatchPart(self.replace_all, upserts, deletes)) upserts = dict() deletes = [] part_size = base_part_size deletes.append({'value': self.lower_val_to_val[value]}) part_size += len(value) + 4 if len(upserts) + len(deletes) > 0: parts.append(BatchPart(self.replace_all, upserts, deletes)) if len(parts) == 0: if not self.replace_all: raise ValueError("Batch has no data, and 'replace_all' is False") parts.append(BatchPart(self.replace_all, dict(), [])) parts[-1].set_last_part() return parts
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compare_versions; 3, parameters; 3, 4; 3, 5; 4, identifier:version_a; 5, identifier:version_b; 6, block; 6, 7; 6, 16; 6, 23; 6, 55; 6, 165; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:logger; 11, identifier:debug; 12, argument_list; 12, 13; 12, 14; 12, 15; 13, string:'compare_versions(%s, %s)'; 14, identifier:version_a; 15, identifier:version_b; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:==; 17, 18; 17, 19; 18, identifier:version_a; 19, identifier:version_b; 20, block; 20, 21; 21, return_statement; 21, 22; 22, identifier:a_eq_b; 23, try_statement; 23, 24; 23, 39; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, pattern_list; 27, 28; 27, 29; 28, identifier:chars_a; 29, identifier:chars_b; 30, expression_list; 30, 31; 30, 35; 31, call; 31, 32; 31, 33; 32, identifier:list; 33, argument_list; 33, 34; 34, identifier:version_a; 35, call; 35, 36; 35, 37; 36, identifier:list; 37, argument_list; 37, 38; 38, identifier:version_b; 39, except_clause; 39, 40; 39, 41; 40, identifier:TypeError; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:RpmError; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 52; 47, attribute; 47, 48; 47, 51; 48, concatenated_string; 48, 49; 48, 50; 49, string:'Could not compare {0} to '; 50, string:'{1}'; 51, identifier:format; 52, argument_list; 52, 53; 52, 54; 53, identifier:version_a; 54, identifier:version_b; 55, while_statement; 55, 56; 55, 69; 56, boolean_operator:and; 56, 57; 56, 63; 57, comparison_operator:!=; 57, 58; 57, 62; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, identifier:chars_a; 62, integer:0; 63, comparison_operator:!=; 63, 64; 63, 68; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, identifier:chars_b; 68, integer:0; 69, block; 69, 70; 69, 81; 69, 87; 69, 134; 69, 150; 69, 158; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger; 74, identifier:debug; 75, argument_list; 75, 76; 75, 79; 75, 80; 76, concatenated_string; 76, 77; 76, 78; 77, string:'starting loop comparing %s '; 78, string:'to %s'; 79, identifier:chars_a; 80, identifier:chars_b; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:_check_leading; 84, argument_list; 84, 85; 84, 86; 85, identifier:chars_a; 86, identifier:chars_b; 87, if_statement; 87, 88; 87, 99; 87, 116; 87, 125; 88, boolean_operator:and; 88, 89; 88, 94; 89, comparison_operator:==; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:chars_a; 92, integer:0; 93, string:'~'; 94, comparison_operator:==; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:chars_b; 97, integer:0; 98, string:'~'; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:map; 103, argument_list; 103, 104; 103, 113; 104, lambda; 104, 105; 104, 107; 105, lambda_parameters; 105, 106; 106, identifier:x; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:x; 110, identifier:pop; 111, argument_list; 111, 112; 112, integer:0; 113, tuple; 113, 114; 113, 115; 114, identifier:chars_a; 115, identifier:chars_b; 116, elif_clause; 116, 117; 116, 122; 117, comparison_operator:==; 117, 118; 117, 121; 118, subscript; 118, 119; 118, 120; 119, identifier:chars_a; 120, integer:0; 121, string:'~'; 122, block; 122, 123; 123, return_statement; 123, 124; 124, identifier:b_newer; 125, elif_clause; 125, 126; 125, 131; 126, comparison_operator:==; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:chars_b; 129, integer:0; 130, string:'~'; 131, block; 131, 132; 132, return_statement; 132, 133; 133, identifier:a_newer; 134, if_statement; 134, 135; 134, 148; 135, boolean_operator:or; 135, 136; 135, 142; 136, comparison_operator:==; 136, 137; 136, 141; 137, call; 137, 138; 137, 139; 138, identifier:len; 139, argument_list; 139, 140; 140, identifier:chars_a; 141, integer:0; 142, comparison_operator:==; 142, 143; 142, 147; 143, call; 143, 144; 143, 145; 144, identifier:len; 145, argument_list; 145, 146; 146, identifier:chars_b; 147, integer:0; 148, block; 148, 149; 149, break_statement; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:block_res; 153, call; 153, 154; 153, 155; 154, identifier:_get_block_result; 155, argument_list; 155, 156; 155, 157; 156, identifier:chars_a; 157, identifier:chars_b; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:!=; 159, 160; 159, 161; 160, identifier:block_res; 161, identifier:a_eq_b; 162, block; 162, 163; 163, return_statement; 163, 164; 164, identifier:block_res; 165, if_statement; 165, 166; 165, 175; 165, 185; 166, comparison_operator:==; 166, 167; 166, 171; 167, call; 167, 168; 167, 169; 168, identifier:len; 169, argument_list; 169, 170; 170, identifier:chars_a; 171, call; 171, 172; 171, 173; 172, identifier:len; 173, argument_list; 173, 174; 174, identifier:chars_b; 175, block; 175, 176; 175, 183; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:logger; 180, identifier:debug; 181, argument_list; 181, 182; 182, string:'versions are equal'; 183, return_statement; 183, 184; 184, identifier:a_eq_b; 185, else_clause; 185, 186; 186, block; 186, 187; 186, 194; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:logger; 191, identifier:debug; 192, argument_list; 192, 193; 193, string:'versions not equal'; 194, return_statement; 194, 195; 195, conditional_expression:if; 195, 196; 195, 197; 195, 206; 196, identifier:a_newer; 197, comparison_operator:>; 197, 198; 197, 202; 198, call; 198, 199; 198, 200; 199, identifier:len; 200, argument_list; 200, 201; 201, identifier:chars_a; 202, call; 202, 203; 202, 204; 203, identifier:len; 204, argument_list; 204, 205; 205, identifier:chars_b; 206, identifier:b_newer
def compare_versions(version_a, version_b): logger.debug('compare_versions(%s, %s)', version_a, version_b) if version_a == version_b: return a_eq_b try: chars_a, chars_b = list(version_a), list(version_b) except TypeError: raise RpmError('Could not compare {0} to ' '{1}'.format(version_a, version_b)) while len(chars_a) != 0 and len(chars_b) != 0: logger.debug('starting loop comparing %s ' 'to %s', chars_a, chars_b) _check_leading(chars_a, chars_b) if chars_a[0] == '~' and chars_b[0] == '~': map(lambda x: x.pop(0), (chars_a, chars_b)) elif chars_a[0] == '~': return b_newer elif chars_b[0] == '~': return a_newer if len(chars_a) == 0 or len(chars_b) == 0: break block_res = _get_block_result(chars_a, chars_b) if block_res != a_eq_b: return block_res if len(chars_a) == len(chars_b): logger.debug('versions are equal') return a_eq_b else: logger.debug('versions not equal') return a_newer if len(chars_a) > len(chars_b) else b_newer
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_compare_blocks; 3, parameters; 3, 4; 3, 5; 4, identifier:block_a; 5, identifier:block_b; 6, block; 6, 7; 6, 16; 6, 62; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:logger; 11, identifier:debug; 12, argument_list; 12, 13; 12, 14; 12, 15; 13, string:'_compare_blocks(%s, %s)'; 14, identifier:block_a; 15, identifier:block_b; 16, if_statement; 16, 17; 16, 24; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, subscript; 19, 20; 19, 21; 20, identifier:block_a; 21, integer:0; 22, identifier:isdigit; 23, argument_list; 24, block; 24, 25; 24, 31; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:_trim_zeros; 28, argument_list; 28, 29; 28, 30; 29, identifier:block_a; 30, identifier:block_b; 31, if_statement; 31, 32; 31, 41; 32, comparison_operator:!=; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, identifier:block_a; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, identifier:block_b; 41, block; 41, 42; 41, 49; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:logger; 46, identifier:debug; 47, argument_list; 47, 48; 48, string:'block lengths are not equal'; 49, return_statement; 49, 50; 50, conditional_expression:if; 50, 51; 50, 52; 50, 61; 51, identifier:a_newer; 52, comparison_operator:>; 52, 53; 52, 57; 53, call; 53, 54; 53, 55; 54, identifier:len; 55, argument_list; 55, 56; 56, identifier:block_a; 57, call; 57, 58; 57, 59; 58, identifier:len; 59, argument_list; 59, 60; 60, identifier:block_b; 61, identifier:b_newer; 62, if_statement; 62, 63; 62, 66; 62, 76; 63, comparison_operator:==; 63, 64; 63, 65; 64, identifier:block_a; 65, identifier:block_b; 66, block; 66, 67; 66, 74; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:logger; 71, identifier:debug; 72, argument_list; 72, 73; 73, string:'blocks are equal'; 74, return_statement; 74, 75; 75, identifier:a_eq_b; 76, else_clause; 76, 77; 77, block; 77, 78; 77, 85; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:logger; 82, identifier:debug; 83, argument_list; 83, 84; 84, string:'blocks are not equal'; 85, return_statement; 85, 86; 86, conditional_expression:if; 86, 87; 86, 88; 86, 91; 87, identifier:a_newer; 88, comparison_operator:>; 88, 89; 88, 90; 89, identifier:block_a; 90, identifier:block_b; 91, identifier:b_newer
def _compare_blocks(block_a, block_b): logger.debug('_compare_blocks(%s, %s)', block_a, block_b) if block_a[0].isdigit(): _trim_zeros(block_a, block_b) if len(block_a) != len(block_b): logger.debug('block lengths are not equal') return a_newer if len(block_a) > len(block_b) else b_newer if block_a == block_b: logger.debug('blocks are equal') return a_eq_b else: logger.debug('blocks are not equal') return a_newer if block_a > block_b else b_newer
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:Find; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:node_type; 6, identifier:item_type; 7, block; 7, 8; 7, 10; 7, 75; 8, expression_statement; 8, 9; 9, string:''' method for finding specific types of notation from nodes. will currently return the first one it encounters because this method's only really intended for some types of notation for which the exact value doesn't really matter. :param node_type: the type of node to look under :param item_type: the type of item (notation) being searched for :return: first item_type object encountered '''; 10, if_statement; 10, 11; 10, 16; 11, comparison_operator:==; 11, 12; 11, 13; 12, identifier:node_type; 13, attribute; 13, 14; 13, 15; 14, identifier:OtherNodes; 15, identifier:DirectionNode; 16, block; 16, 17; 16, 33; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:child; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:GetChild; 24, argument_list; 24, 25; 25, binary_operator:-; 25, 26; 25, 32; 26, call; 26, 27; 26, 28; 27, identifier:len; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:children; 32, integer:1; 33, while_statement; 33, 34; 33, 48; 34, boolean_operator:and; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:child; 37, None; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 47; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:child; 45, identifier:GetItem; 46, argument_list; 47, identifier:item_type; 48, block; 48, 49; 48, 66; 49, if_statement; 49, 50; 49, 63; 50, comparison_operator:==; 50, 51; 50, 60; 51, attribute; 51, 52; 51, 59; 52, attribute; 52, 53; 52, 58; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:child; 56, identifier:GetItem; 57, argument_list; 58, identifier:__class__; 59, identifier:__name__; 60, attribute; 60, 61; 60, 62; 61, identifier:item_type; 62, identifier:__name__; 63, block; 63, 64; 64, return_statement; 64, 65; 65, True; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:child; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:child; 72, identifier:GetChild; 73, argument_list; 73, 74; 74, integer:0; 75, if_statement; 75, 76; 75, 81; 76, comparison_operator:==; 76, 77; 76, 78; 77, identifier:node_type; 78, attribute; 78, 79; 78, 80; 79, identifier:OtherNodes; 80, identifier:ExpressionNode; 81, block; 81, 82; 81, 98; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:child; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:GetChild; 89, argument_list; 89, 90; 90, binary_operator:-; 90, 91; 90, 97; 91, call; 91, 92; 91, 93; 92, identifier:len; 93, argument_list; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:children; 97, integer:2; 98, while_statement; 98, 99; 98, 113; 99, boolean_operator:and; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:child; 102, None; 103, not_operator; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:isinstance; 106, argument_list; 106, 107; 106, 112; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:child; 110, identifier:GetItem; 111, argument_list; 112, identifier:item_type; 113, block; 113, 114; 113, 131; 114, if_statement; 114, 115; 114, 128; 115, comparison_operator:==; 115, 116; 115, 125; 116, attribute; 116, 117; 116, 124; 117, attribute; 117, 118; 117, 123; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:child; 121, identifier:GetItem; 122, argument_list; 123, identifier:__class__; 124, identifier:__name__; 125, attribute; 125, 126; 125, 127; 126, identifier:item_type; 127, identifier:__name__; 128, block; 128, 129; 129, return_statement; 129, 130; 130, True; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:child; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:child; 137, identifier:GetChild; 138, argument_list; 138, 139; 139, integer:0
def Find(self, node_type, item_type): ''' method for finding specific types of notation from nodes. will currently return the first one it encounters because this method's only really intended for some types of notation for which the exact value doesn't really matter. :param node_type: the type of node to look under :param item_type: the type of item (notation) being searched for :return: first item_type object encountered ''' if node_type == OtherNodes.DirectionNode: child = self.GetChild(len(self.children) - 1) while child is not None and not isinstance( child.GetItem(), item_type): if child.GetItem().__class__.__name__ == item_type.__name__: return True child = child.GetChild(0) if node_type == OtherNodes.ExpressionNode: child = self.GetChild(len(self.children) - 2) while child is not None and not isinstance( child.GetItem(), item_type): if child.GetItem().__class__.__name__ == item_type.__name__: return True child = child.GetChild(0)
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:SplitString; 3, parameters; 3, 4; 4, identifier:value; 5, block; 5, 6; 5, 13; 5, 22; 5, 29; 5, 33; 5, 83; 5, 246; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:string_length; 9, call; 9, 10; 9, 11; 10, identifier:len; 11, argument_list; 11, 12; 12, identifier:value; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:chunks; 16, call; 16, 17; 16, 18; 17, identifier:int; 18, argument_list; 18, 19; 19, binary_operator:/; 19, 20; 19, 21; 20, identifier:string_length; 21, integer:10; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:string_list; 25, call; 25, 26; 25, 27; 26, identifier:list; 27, argument_list; 27, 28; 28, identifier:value; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:lstring; 32, string:""; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:>; 34, 35; 34, 36; 35, identifier:chunks; 36, integer:1; 37, block; 37, 38; 37, 42; 37, 79; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:lstring; 41, string:"\\markup { \n\r \column { "; 42, for_statement; 42, 43; 42, 44; 42, 51; 43, identifier:i; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:int; 49, argument_list; 49, 50; 50, identifier:chunks; 51, block; 51, 52; 51, 56; 51, 62; 51, 75; 52, expression_statement; 52, 53; 53, augmented_assignment:+=; 53, 54; 53, 55; 54, identifier:lstring; 55, string:"\n\r\r \\line { \""; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:index; 59, binary_operator:*; 59, 60; 59, 61; 60, identifier:i; 61, integer:10; 62, for_statement; 62, 63; 62, 64; 62, 68; 63, identifier:i; 64, call; 64, 65; 64, 66; 65, identifier:range; 66, argument_list; 66, 67; 67, identifier:index; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, augmented_assignment:+=; 70, 71; 70, 72; 71, identifier:lstring; 72, subscript; 72, 73; 72, 74; 73, identifier:string_list; 74, identifier:i; 75, expression_statement; 75, 76; 76, augmented_assignment:+=; 76, 77; 76, 78; 77, identifier:lstring; 78, string:"\" \r\r}"; 79, expression_statement; 79, 80; 80, augmented_assignment:+=; 80, 81; 80, 82; 81, identifier:lstring; 82, string:"\n\r } \n }"; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:==; 84, 85; 84, 86; 85, identifier:lstring; 86, string:""; 87, block; 87, 88; 87, 114; 87, 118; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:indexes; 91, list_comprehension; 91, 92; 91, 93; 91, 102; 92, identifier:i; 93, for_in_clause; 93, 94; 93, 95; 94, identifier:i; 95, call; 95, 96; 95, 97; 96, identifier:range; 97, argument_list; 97, 98; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:string_list; 102, if_clause; 102, 103; 103, boolean_operator:or; 103, 104; 103, 109; 104, comparison_operator:==; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:string_list; 107, identifier:i; 108, string:"\r"; 109, comparison_operator:==; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:string_list; 112, identifier:i; 113, string:"\n"; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:lstring; 117, string:"\\markup { \n\r \column { "; 118, if_statement; 118, 119; 118, 125; 118, 139; 119, comparison_operator:==; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, identifier:indexes; 124, integer:0; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, augmented_assignment:+=; 127, 128; 127, 129; 128, identifier:lstring; 129, binary_operator:+; 129, 130; 129, 138; 130, binary_operator:+; 130, 131; 130, 132; 131, string:"\n\r\r \\line { \""; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, string:""; 135, identifier:join; 136, argument_list; 136, 137; 137, identifier:string_list; 138, string:"\" \n\r\r } \n\r } \n }"; 139, else_clause; 139, 140; 140, block; 140, 141; 140, 145; 140, 155; 140, 162; 140, 221; 140, 242; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:rows; 144, list:[]; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:row_1; 148, subscript; 148, 149; 148, 150; 149, identifier:string_list; 150, slice; 150, 151; 150, 152; 151, colon; 152, subscript; 152, 153; 152, 154; 153, identifier:indexes; 154, integer:0; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:rows; 159, identifier:append; 160, argument_list; 160, 161; 161, identifier:row_1; 162, for_statement; 162, 163; 162, 164; 162, 171; 163, identifier:i; 164, call; 164, 165; 164, 166; 165, identifier:range; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:len; 169, argument_list; 169, 170; 170, identifier:indexes; 171, block; 171, 172; 171, 178; 171, 205; 171, 214; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:start; 175, subscript; 175, 176; 175, 177; 176, identifier:indexes; 177, identifier:i; 178, if_statement; 178, 179; 178, 187; 178, 196; 179, comparison_operator:!=; 179, 180; 179, 181; 180, identifier:i; 181, binary_operator:-; 181, 182; 181, 186; 182, call; 182, 183; 182, 184; 183, identifier:len; 184, argument_list; 184, 185; 185, identifier:indexes; 186, integer:1; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:end; 191, subscript; 191, 192; 191, 193; 192, identifier:indexes; 193, binary_operator:+; 193, 194; 193, 195; 194, identifier:i; 195, integer:1; 196, else_clause; 196, 197; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:end; 201, call; 201, 202; 201, 203; 202, identifier:len; 203, argument_list; 203, 204; 204, identifier:string_list; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:row; 208, subscript; 208, 209; 208, 210; 209, identifier:string_list; 210, slice; 210, 211; 210, 212; 210, 213; 211, identifier:start; 212, colon; 213, identifier:end; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:rows; 218, identifier:append; 219, argument_list; 219, 220; 220, identifier:row; 221, for_statement; 221, 222; 221, 223; 221, 224; 222, identifier:row; 223, identifier:rows; 224, block; 224, 225; 224, 229; 224, 238; 225, expression_statement; 225, 226; 226, augmented_assignment:+=; 226, 227; 226, 228; 227, identifier:lstring; 228, string:"\n\r\r \\line { \""; 229, expression_statement; 229, 230; 230, augmented_assignment:+=; 230, 231; 230, 232; 231, identifier:lstring; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, string:""; 235, identifier:join; 236, argument_list; 236, 237; 237, identifier:row; 238, expression_statement; 238, 239; 239, augmented_assignment:+=; 239, 240; 239, 241; 240, identifier:lstring; 241, string:"\" \r\r}"; 242, expression_statement; 242, 243; 243, augmented_assignment:+=; 243, 244; 243, 245; 244, identifier:lstring; 245, string:"\n\r } \n }"; 246, return_statement; 246, 247; 247, identifier:lstring
def SplitString(value): string_length = len(value) chunks = int(string_length / 10) string_list = list(value) lstring = "" if chunks > 1: lstring = "\\markup { \n\r \column { " for i in range(int(chunks)): lstring += "\n\r\r \\line { \"" index = i * 10 for i in range(index): lstring += string_list[i] lstring += "\" \r\r}" lstring += "\n\r } \n }" if lstring == "": indexes = [ i for i in range( len(string_list)) if string_list[i] == "\r" or string_list[i] == "\n"] lstring = "\\markup { \n\r \column { " if len(indexes) == 0: lstring += "\n\r\r \\line { \"" + \ "".join(string_list) + "\" \n\r\r } \n\r } \n }" else: rows = [] row_1 = string_list[:indexes[0]] rows.append(row_1) for i in range(len(indexes)): start = indexes[i] if i != len(indexes) - 1: end = indexes[i + 1] else: end = len(string_list) row = string_list[start:end] rows.append(row) for row in rows: lstring += "\n\r\r \\line { \"" lstring += "".join(row) lstring += "\" \r\r}" lstring += "\n\r } \n }" return lstring
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:NumbersToWords; 3, parameters; 3, 4; 4, identifier:number; 5, block; 5, 6; 5, 19; 5, 32; 5, 36; 5, 186; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:units; 9, list:[ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; 9, 10; 9, 11; 9, 12; 9, 13; 9, 14; 9, 15; 9, 16; 9, 17; 9, 18; 10, string:'one'; 11, string:'two'; 12, string:'three'; 13, string:'four'; 14, string:'five'; 15, string:'six'; 16, string:'seven'; 17, string:'eight'; 18, string:'nine'; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:tens; 22, list:[ 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']; 22, 23; 22, 24; 22, 25; 22, 26; 22, 27; 22, 28; 22, 29; 22, 30; 22, 31; 23, string:'ten'; 24, string:'twenty'; 25, string:'thirty'; 26, string:'forty'; 27, string:'fifty'; 28, string:'sixty'; 29, string:'seventy'; 30, string:'eighty'; 31, string:'ninety'; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:output; 35, string:""; 36, if_statement; 36, 37; 36, 40; 36, 180; 37, comparison_operator:!=; 37, 38; 37, 39; 38, identifier:number; 39, integer:0; 40, block; 40, 41; 40, 48; 40, 116; 40, 158; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:str_val; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, identifier:number; 48, if_statement; 48, 49; 48, 56; 49, comparison_operator:>; 49, 50; 49, 51; 49, 55; 50, integer:4; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:str_val; 55, integer:2; 56, block; 56, 57; 56, 70; 56, 74; 57, expression_statement; 57, 58; 58, augmented_assignment:+=; 58, 59; 58, 60; 59, identifier:output; 60, subscript; 60, 61; 60, 62; 61, identifier:units; 62, binary_operator:-; 62, 63; 62, 69; 63, call; 63, 64; 63, 65; 64, identifier:int; 65, argument_list; 65, 66; 66, subscript; 66, 67; 66, 68; 67, identifier:str_val; 68, integer:0; 69, integer:1; 70, expression_statement; 70, 71; 71, augmented_assignment:+=; 71, 72; 71, 73; 72, identifier:output; 73, string:"hundred"; 74, if_statement; 74, 75; 74, 80; 75, comparison_operator:!=; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:str_val; 78, integer:1; 79, integer:0; 80, block; 80, 81; 80, 96; 81, expression_statement; 81, 82; 82, augmented_assignment:+=; 82, 83; 82, 84; 83, identifier:output; 84, binary_operator:+; 84, 85; 84, 86; 85, string:"and"; 86, subscript; 86, 87; 86, 88; 87, identifier:tens; 88, binary_operator:-; 88, 89; 88, 95; 89, call; 89, 90; 89, 91; 90, identifier:int; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, identifier:str_val; 94, integer:1; 95, integer:1; 96, if_statement; 96, 97; 96, 102; 97, comparison_operator:!=; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:str_val; 100, integer:2; 101, integer:0; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, augmented_assignment:+=; 104, 105; 104, 106; 105, identifier:output; 106, subscript; 106, 107; 106, 108; 107, identifier:units; 108, binary_operator:-; 108, 109; 108, 115; 109, call; 109, 110; 109, 111; 110, identifier:int; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:str_val; 114, integer:2; 115, integer:1; 116, if_statement; 116, 117; 116, 124; 117, comparison_operator:>; 117, 118; 117, 119; 117, 123; 118, integer:3; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, identifier:str_val; 123, integer:1; 124, block; 124, 125; 124, 138; 125, expression_statement; 125, 126; 126, augmented_assignment:+=; 126, 127; 126, 128; 127, identifier:output; 128, subscript; 128, 129; 128, 130; 129, identifier:tens; 130, binary_operator:-; 130, 131; 130, 137; 131, call; 131, 132; 131, 133; 132, identifier:int; 133, argument_list; 133, 134; 134, subscript; 134, 135; 134, 136; 135, identifier:str_val; 136, integer:0; 137, integer:1; 138, if_statement; 138, 139; 138, 144; 139, comparison_operator:!=; 139, 140; 139, 143; 140, subscript; 140, 141; 140, 142; 141, identifier:str_val; 142, integer:1; 143, integer:0; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, augmented_assignment:+=; 146, 147; 146, 148; 147, identifier:output; 148, subscript; 148, 149; 148, 150; 149, identifier:units; 150, binary_operator:-; 150, 151; 150, 157; 151, call; 151, 152; 151, 153; 152, identifier:int; 153, argument_list; 153, 154; 154, subscript; 154, 155; 154, 156; 155, identifier:str_val; 156, integer:1; 157, integer:1; 158, if_statement; 158, 159; 158, 166; 159, comparison_operator:>; 159, 160; 159, 161; 159, 165; 160, integer:2; 161, call; 161, 162; 161, 163; 162, identifier:len; 163, argument_list; 163, 164; 164, identifier:str_val; 165, integer:1; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, augmented_assignment:+=; 168, 169; 168, 170; 169, identifier:output; 170, subscript; 170, 171; 170, 172; 171, identifier:units; 172, binary_operator:-; 172, 173; 172, 179; 173, call; 173, 174; 173, 175; 174, identifier:int; 175, argument_list; 175, 176; 176, subscript; 176, 177; 176, 178; 177, identifier:str_val; 178, integer:0; 179, integer:1; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:output; 185, string:"zero"; 186, return_statement; 186, 187; 187, identifier:output
def NumbersToWords(number): units = [ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] tens = [ 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] output = "" if number != 0: str_val = str(number) if 4 > len(str_val) > 2: output += units[int(str_val[0]) - 1] output += "hundred" if str_val[1] != 0: output += "and" + tens[int(str_val[1]) - 1] if str_val[2] != 0: output += units[int(str_val[2]) - 1] if 3 > len(str_val) > 1: output += tens[int(str_val[0]) - 1] if str_val[1] != 0: output += units[int(str_val[1]) - 1] if 2 > len(str_val) == 1: output += units[int(str_val[0]) - 1] else: output = "zero" return output
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_generate_image; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:matrix; 6, identifier:width; 7, identifier:height; 8, identifier:padding; 9, identifier:foreground; 10, identifier:background; 11, identifier:image_format; 12, block; 12, 13; 12, 42; 12, 51; 12, 59; 12, 67; 12, 152; 12, 158; 12, 178; 12, 203; 12, 211; 12, 217; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:image; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:Image; 19, identifier:new; 20, argument_list; 20, 21; 20, 22; 20, 41; 21, string:"RGBA"; 22, tuple; 22, 23; 22, 32; 23, binary_operator:+; 23, 24; 23, 29; 24, binary_operator:+; 24, 25; 24, 26; 25, identifier:width; 26, subscript; 26, 27; 26, 28; 27, identifier:padding; 28, integer:2; 29, subscript; 29, 30; 29, 31; 30, identifier:padding; 31, integer:3; 32, binary_operator:+; 32, 33; 32, 38; 33, binary_operator:+; 33, 34; 33, 35; 34, identifier:height; 35, subscript; 35, 36; 35, 37; 36, identifier:padding; 37, integer:0; 38, subscript; 38, 39; 38, 40; 39, identifier:padding; 40, integer:1; 41, identifier:background; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:draw; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:ImageDraw; 48, identifier:Draw; 49, argument_list; 49, 50; 50, identifier:image; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:block_width; 54, binary_operator://; 54, 55; 54, 56; 55, identifier:width; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:columns; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:block_height; 62, binary_operator://; 62, 63; 62, 64; 63, identifier:height; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:rows; 67, for_statement; 67, 68; 67, 71; 67, 75; 68, pattern_list; 68, 69; 68, 70; 69, identifier:row; 70, identifier:row_columns; 71, call; 71, 72; 71, 73; 72, identifier:enumerate; 73, argument_list; 73, 74; 74, identifier:matrix; 75, block; 75, 76; 76, for_statement; 76, 77; 76, 80; 76, 84; 77, pattern_list; 77, 78; 77, 79; 78, identifier:column; 79, identifier:cell; 80, call; 80, 81; 80, 82; 81, identifier:enumerate; 82, argument_list; 82, 83; 83, identifier:row_columns; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 87; 86, identifier:cell; 87, block; 87, 88; 87, 98; 87, 108; 87, 123; 87, 138; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:x1; 91, binary_operator:+; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:padding; 94, integer:2; 95, binary_operator:*; 95, 96; 95, 97; 96, identifier:column; 97, identifier:block_width; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:y1; 101, binary_operator:+; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:padding; 104, integer:0; 105, binary_operator:*; 105, 106; 105, 107; 106, identifier:row; 107, identifier:block_height; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:x2; 111, binary_operator:-; 111, 112; 111, 122; 112, binary_operator:+; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:padding; 115, integer:2; 116, binary_operator:*; 116, 117; 116, 121; 117, parenthesized_expression; 117, 118; 118, binary_operator:+; 118, 119; 118, 120; 119, identifier:column; 120, integer:1; 121, identifier:block_width; 122, integer:1; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:y2; 126, binary_operator:-; 126, 127; 126, 137; 127, binary_operator:+; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:padding; 130, integer:0; 131, binary_operator:*; 131, 132; 131, 136; 132, parenthesized_expression; 132, 133; 133, binary_operator:+; 133, 134; 133, 135; 134, identifier:row; 135, integer:1; 136, identifier:block_height; 137, integer:1; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:draw; 142, identifier:rectangle; 143, argument_list; 143, 144; 143, 149; 144, tuple; 144, 145; 144, 146; 144, 147; 144, 148; 145, identifier:x1; 146, identifier:y1; 147, identifier:x2; 148, identifier:y2; 149, keyword_argument; 149, 150; 149, 151; 150, identifier:fill; 151, identifier:foreground; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:stream; 155, call; 155, 156; 155, 157; 156, identifier:BytesIO; 157, argument_list; 158, if_statement; 158, 159; 158, 166; 159, comparison_operator:==; 159, 160; 159, 165; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:image_format; 163, identifier:upper; 164, argument_list; 165, string:"JPEG"; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:image; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:image; 173, identifier:convert; 174, argument_list; 174, 175; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:mode; 177, string:"RGB"; 178, try_statement; 178, 179; 178, 193; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:image; 184, identifier:save; 185, argument_list; 185, 186; 185, 187; 185, 190; 186, identifier:stream; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:format; 189, identifier:image_format; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:optimize; 192, True; 193, except_clause; 193, 194; 193, 195; 194, identifier:KeyError; 195, block; 195, 196; 196, raise_statement; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:ValueError; 199, argument_list; 199, 200; 200, binary_operator:%; 200, 201; 200, 202; 201, string:"Pillow does not support requested image format: %s"; 202, identifier:image_format; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:image_raw; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:stream; 209, identifier:getvalue; 210, argument_list; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:stream; 215, identifier:close; 216, argument_list; 217, return_statement; 217, 218; 218, identifier:image_raw
def _generate_image(self, matrix, width, height, padding, foreground, background, image_format): image = Image.new("RGBA", (width + padding[2] + padding[3], height + padding[0] + padding[1]), background) draw = ImageDraw.Draw(image) block_width = width // self.columns block_height = height // self.rows for row, row_columns in enumerate(matrix): for column, cell in enumerate(row_columns): if cell: x1 = padding[2] + column * block_width y1 = padding[0] + row * block_height x2 = padding[2] + (column + 1) * block_width - 1 y2 = padding[0] + (row + 1) * block_height - 1 draw.rectangle((x1, y1, x2, y2), fill=foreground) stream = BytesIO() if image_format.upper() == "JPEG": image = image.convert(mode="RGB") try: image.save(stream, format=image_format, optimize=True) except KeyError: raise ValueError("Pillow does not support requested image format: %s" % image_format) image_raw = stream.getvalue() stream.close() return image_raw
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:alignment_to_reads; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:sam_merged; 5, identifier:output_dir; 6, default_parameter; 6, 7; 6, 8; 7, identifier:parameters; 8, identifier:DEFAULT_PARAMETERS; 9, default_parameter; 9, 10; 9, 11; 10, identifier:save_memory; 11, True; 12, list_splat_pattern; 12, 13; 13, identifier:bin_fasta; 14, block; 14, 15; 14, 40; 14, 46; 14, 74; 14, 83; 14, 92; 14, 107; 14, 157; 14, 174; 14, 327; 14, 341; 15, function_definition; 15, 16; 15, 17; 15, 19; 16, function_name:get_file_string; 17, parameters; 17, 18; 18, identifier:file_thing; 19, block; 19, 20; 19, 38; 20, try_statement; 20, 21; 20, 28; 21, block; 21, 22; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:file_string; 25, attribute; 25, 26; 25, 27; 26, identifier:file_thing; 27, identifier:name; 28, except_clause; 28, 29; 28, 30; 29, identifier:AttributeError; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:file_string; 34, call; 34, 35; 34, 36; 35, identifier:str; 36, argument_list; 36, 37; 37, identifier:file_thing; 38, return_statement; 38, 39; 39, identifier:file_string; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:bin_chunks; 43, call; 43, 44; 43, 45; 44, identifier:set; 45, argument_list; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:bin_file; 48, identifier:bin_fasta; 49, block; 49, 50; 50, for_statement; 50, 51; 50, 52; 50, 59; 51, identifier:record; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:SeqIO; 55, identifier:parse; 56, argument_list; 56, 57; 56, 58; 57, identifier:bin_file; 58, string:"fasta"; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:bin_chunks; 64, identifier:add; 65, argument_list; 65, 66; 66, tuple; 66, 67; 66, 71; 67, call; 67, 68; 67, 69; 68, identifier:get_file_string; 69, argument_list; 69, 70; 70, identifier:bin_file; 71, attribute; 71, 72; 71, 73; 72, identifier:record; 73, identifier:id; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:chunk_size; 77, call; 77, 78; 77, 79; 78, identifier:int; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:parameters; 82, string:"chunk_size"; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:mapq_threshold; 86, call; 86, 87; 86, 88; 87, identifier:int; 88, argument_list; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:parameters; 91, string:"mapq_threshold"; 92, function_definition; 92, 93; 92, 94; 92, 96; 93, function_name:read_name; 94, parameters; 94, 95; 95, identifier:read; 96, block; 96, 97; 97, return_statement; 97, 98; 98, subscript; 98, 99; 98, 106; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:read; 103, identifier:query_name; 104, identifier:split; 105, argument_list; 106, integer:0; 107, function_definition; 107, 108; 107, 109; 107, 111; 108, function_name:get_base_name; 109, parameters; 109, 110; 110, identifier:bin_file; 111, block; 111, 112; 111, 138; 111, 155; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:base_name; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, string:"."; 118, identifier:join; 119, argument_list; 119, 120; 120, subscript; 120, 121; 120, 134; 121, call; 121, 122; 121, 132; 122, attribute; 122, 123; 122, 131; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:os; 127, identifier:path; 128, identifier:basename; 129, argument_list; 129, 130; 130, identifier:bin_file; 131, identifier:split; 132, argument_list; 132, 133; 133, string:"."; 134, slice; 134, 135; 134, 136; 135, colon; 136, unary_operator:-; 136, 137; 137, integer:1; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:output_path; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:os; 145, identifier:path; 146, identifier:join; 147, argument_list; 147, 148; 147, 149; 148, identifier:output_dir; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, string:"{}.readnames"; 152, identifier:format; 153, argument_list; 153, 154; 154, identifier:base_name; 155, return_statement; 155, 156; 156, identifier:output_path; 157, if_statement; 157, 158; 157, 159; 157, 166; 158, identifier:save_memory; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:opened_files; 163, call; 163, 164; 163, 165; 164, identifier:dict; 165, argument_list; 166, else_clause; 166, 167; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:read_names; 171, call; 171, 172; 171, 173; 172, identifier:dict; 173, argument_list; 174, with_statement; 174, 175; 174, 187; 175, with_clause; 175, 176; 176, with_item; 176, 177; 177, as_pattern; 177, 178; 177, 185; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:pysam; 181, identifier:AlignmentFile; 182, argument_list; 182, 183; 182, 184; 183, identifier:sam_merged; 184, string:"rb"; 185, as_pattern_target; 185, 186; 186, identifier:alignment_merged_handle; 187, block; 187, 188; 188, for_statement; 188, 189; 188, 192; 188, 199; 189, tuple_pattern; 189, 190; 189, 191; 190, identifier:my_read_name; 191, identifier:alignment_pool; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:itertools; 195, identifier:groupby; 196, argument_list; 196, 197; 196, 198; 197, identifier:alignment_merged_handle; 198, identifier:read_name; 199, block; 199, 200; 200, for_statement; 200, 201; 200, 202; 200, 203; 201, identifier:my_alignment; 202, identifier:alignment_pool; 203, block; 203, 204; 203, 210; 203, 216; 203, 222; 203, 232; 203, 240; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:relative_position; 207, attribute; 207, 208; 207, 209; 208, identifier:my_alignment; 209, identifier:reference_start; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:contig_name; 213, attribute; 213, 214; 213, 215; 214, identifier:my_alignment; 215, identifier:reference_name; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:chunk_position; 219, binary_operator://; 219, 220; 219, 221; 220, identifier:relative_position; 221, identifier:chunk_size; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:chunk_name; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, string:"{}_{}"; 228, identifier:format; 229, argument_list; 229, 230; 229, 231; 230, identifier:contig_name; 231, identifier:chunk_position; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:quality_test; 235, comparison_operator:>; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:my_alignment; 238, identifier:mapping_quality; 239, identifier:mapq_threshold; 240, for_statement; 240, 241; 240, 242; 240, 243; 241, identifier:bin_file; 242, identifier:bin_fasta; 243, block; 243, 244; 243, 250; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:chunk_tuple; 247, tuple; 247, 248; 247, 249; 248, identifier:bin_file; 249, identifier:chunk_name; 250, if_statement; 250, 251; 250, 256; 251, boolean_operator:and; 251, 252; 251, 255; 252, comparison_operator:in; 252, 253; 252, 254; 253, identifier:chunk_tuple; 254, identifier:bin_chunks; 255, identifier:quality_test; 256, block; 256, 257; 257, if_statement; 257, 258; 257, 259; 257, 304; 258, identifier:save_memory; 259, block; 259, 260; 259, 267; 259, 292; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:output_path; 263, call; 263, 264; 263, 265; 264, identifier:get_base_name; 265, argument_list; 265, 266; 266, identifier:bin_file; 267, try_statement; 267, 268; 267, 275; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:output_handle; 272, subscript; 272, 273; 272, 274; 273, identifier:opened_files; 274, identifier:bin_file; 275, except_clause; 275, 276; 275, 277; 276, identifier:KeyError; 277, block; 277, 278; 277, 286; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:output_handle; 281, call; 281, 282; 281, 283; 282, identifier:open; 283, argument_list; 283, 284; 283, 285; 284, identifier:output_path; 285, string:"w"; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:opened_files; 290, identifier:bin_file; 291, identifier:output_handle; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:output_handle; 296, identifier:write; 297, argument_list; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, string:"@{}\n"; 301, identifier:format; 302, argument_list; 302, 303; 303, identifier:my_read_name; 304, else_clause; 304, 305; 305, block; 305, 306; 306, try_statement; 306, 307; 306, 317; 307, block; 307, 308; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 315; 310, attribute; 310, 311; 310, 314; 311, subscript; 311, 312; 311, 313; 312, identifier:read_names; 313, identifier:my_read_name; 314, identifier:append; 315, argument_list; 315, 316; 316, identifier:bin_file; 317, except_clause; 317, 318; 317, 319; 318, identifier:KeyError; 319, block; 319, 320; 320, expression_statement; 320, 321; 321, assignment; 321, 322; 321, 325; 322, subscript; 322, 323; 322, 324; 323, identifier:read_names; 324, identifier:my_read_name; 325, list:[bin_file]; 325, 326; 326, identifier:bin_file; 327, for_statement; 327, 328; 327, 329; 327, 334; 328, identifier:file_handle; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:opened_files; 332, identifier:values; 333, argument_list; 334, block; 334, 335; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:file_handle; 339, identifier:close; 340, argument_list; 341, if_statement; 341, 342; 341, 343; 341, 350; 342, identifier:save_memory; 343, block; 343, 344; 344, return_statement; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:opened_files; 348, identifier:keys; 349, argument_list; 350, else_clause; 350, 351; 351, block; 351, 352; 352, return_statement; 352, 353; 353, identifier:read_names
def alignment_to_reads( sam_merged, output_dir, parameters=DEFAULT_PARAMETERS, save_memory=True, *bin_fasta ): def get_file_string(file_thing): try: file_string = file_thing.name except AttributeError: file_string = str(file_thing) return file_string bin_chunks = set() for bin_file in bin_fasta: for record in SeqIO.parse(bin_file, "fasta"): bin_chunks.add((get_file_string(bin_file), record.id)) chunk_size = int(parameters["chunk_size"]) mapq_threshold = int(parameters["mapq_threshold"]) def read_name(read): return read.query_name.split()[0] def get_base_name(bin_file): base_name = ".".join(os.path.basename(bin_file).split(".")[:-1]) output_path = os.path.join( output_dir, "{}.readnames".format(base_name) ) return output_path if save_memory: opened_files = dict() else: read_names = dict() with pysam.AlignmentFile(sam_merged, "rb") as alignment_merged_handle: for (my_read_name, alignment_pool) in itertools.groupby( alignment_merged_handle, read_name ): for my_alignment in alignment_pool: relative_position = my_alignment.reference_start contig_name = my_alignment.reference_name chunk_position = relative_position // chunk_size chunk_name = "{}_{}".format(contig_name, chunk_position) quality_test = my_alignment.mapping_quality > mapq_threshold for bin_file in bin_fasta: chunk_tuple = (bin_file, chunk_name) if chunk_tuple in bin_chunks and quality_test: if save_memory: output_path = get_base_name(bin_file) try: output_handle = opened_files[bin_file] except KeyError: output_handle = open(output_path, "w") opened_files[bin_file] = output_handle output_handle.write("@{}\n".format(my_read_name)) else: try: read_names[my_read_name].append(bin_file) except KeyError: read_names[my_read_name] = [bin_file] for file_handle in opened_files.values(): file_handle.close() if save_memory: return opened_files.keys() else: return read_names
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_validate_config; 3, parameters; 3, 4; 4, identifier:config; 5, block; 5, 6; 5, 19; 6, if_statement; 6, 7; 6, 13; 7, not_operator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, identifier:config; 12, identifier:list; 13, block; 13, 14; 14, raise_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:TypeError; 17, argument_list; 17, 18; 18, string:'Config must be a list'; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:config_dict; 21, identifier:config; 22, block; 22, 23; 22, 36; 22, 46; 22, 52; 22, 65; 22, 75; 22, 99; 22, 109; 22, 124; 22, 134; 22, 182; 22, 202; 23, if_statement; 23, 24; 23, 30; 24, not_operator; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:config_dict; 29, identifier:dict; 30, block; 30, 31; 31, raise_statement; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:TypeError; 34, argument_list; 34, 35; 35, string:'Config must be a list of dictionaries'; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:label; 39, subscript; 39, 40; 39, 45; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:config_dict; 43, identifier:keys; 44, argument_list; 45, integer:0; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:cfg; 49, subscript; 49, 50; 49, 51; 50, identifier:config_dict; 51, identifier:label; 52, if_statement; 52, 53; 52, 59; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:cfg; 58, identifier:dict; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:TypeError; 63, argument_list; 63, 64; 64, string:'Config structure is broken'; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:not; 66, 67; 66, 68; 67, string:'host'; 68, identifier:cfg; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:TypeError; 73, argument_list; 73, 74; 74, string:'Config entries must have a value for host'; 75, if_statement; 75, 76; 75, 93; 76, boolean_operator:and; 76, 77; 76, 85; 77, not_operator; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:isinstance; 80, argument_list; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:cfg; 83, string:'host'; 84, identifier:str; 85, not_operator; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:isinstance; 88, argument_list; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:cfg; 91, string:'host'; 92, identifier:list; 93, block; 93, 94; 94, raise_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:TypeError; 97, argument_list; 97, 98; 98, string:'Host must be a string or a list.'; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:not; 100, 101; 100, 102; 101, string:'port'; 102, identifier:cfg; 103, block; 103, 104; 104, raise_statement; 104, 105; 105, call; 105, 106; 105, 107; 106, identifier:TypeError; 107, argument_list; 107, 108; 108, string:'Config entries must have a value for port'; 109, if_statement; 109, 110; 109, 118; 110, not_operator; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:isinstance; 113, argument_list; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:cfg; 116, string:'port'; 117, identifier:int; 118, block; 118, 119; 119, raise_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:TypeError; 122, argument_list; 122, 123; 123, string:'Port must be an int'; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:not; 125, 126; 125, 127; 126, string:'dbpath'; 127, identifier:cfg; 128, block; 128, 129; 129, raise_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:TypeError; 132, argument_list; 132, 133; 133, string:'Config entries must have a value for dbpath'; 134, if_statement; 134, 135; 134, 143; 135, not_operator; 135, 136; 136, call; 136, 137; 136, 138; 137, identifier:isinstance; 138, argument_list; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:cfg; 141, string:'dbpath'; 142, identifier:str; 143, block; 143, 144; 143, 161; 144, if_statement; 144, 145; 144, 153; 145, not_operator; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:isinstance; 148, argument_list; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:cfg; 151, string:'dbpath'; 152, identifier:list; 153, block; 153, 154; 154, raise_statement; 154, 155; 155, call; 155, 156; 155, 157; 156, identifier:TypeError; 157, argument_list; 157, 158; 158, concatenated_string; 158, 159; 158, 160; 159, string:'Dbpath must either a string or a list of '; 160, string:'strings'; 161, for_statement; 161, 162; 161, 163; 161, 166; 162, identifier:dbpath; 163, subscript; 163, 164; 163, 165; 164, identifier:cfg; 165, string:'dbpath'; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 174; 168, not_operator; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:isinstance; 171, argument_list; 171, 172; 171, 173; 172, identifier:dbpath; 173, identifier:str; 174, block; 174, 175; 175, raise_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:TypeError; 178, argument_list; 178, 179; 179, concatenated_string; 179, 180; 179, 181; 180, string:'Dbpath must either a string or a list '; 181, string:'of strings'; 182, if_statement; 182, 183; 182, 196; 183, parenthesized_expression; 183, 184; 184, boolean_operator:and; 184, 185; 184, 188; 185, comparison_operator:in; 185, 186; 185, 187; 186, string:'read_preference'; 187, identifier:cfg; 188, not_operator; 188, 189; 189, call; 189, 190; 189, 191; 190, identifier:isinstance; 191, argument_list; 191, 192; 191, 195; 192, subscript; 192, 193; 192, 194; 193, identifier:cfg; 194, string:'read_preference'; 195, identifier:str; 196, block; 196, 197; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:TypeError; 200, argument_list; 200, 201; 201, string:'Read_preference must be a string'; 202, if_statement; 202, 203; 202, 216; 203, parenthesized_expression; 203, 204; 204, boolean_operator:and; 204, 205; 204, 208; 205, comparison_operator:in; 205, 206; 205, 207; 206, string:'replicaSet'; 207, identifier:cfg; 208, not_operator; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:isinstance; 211, argument_list; 211, 212; 211, 215; 212, subscript; 212, 213; 212, 214; 213, identifier:cfg; 214, string:'replicaSet'; 215, identifier:str; 216, block; 216, 217; 217, raise_statement; 217, 218; 218, call; 218, 219; 218, 220; 219, identifier:TypeError; 220, argument_list; 220, 221; 221, string:'replicaSet must be a string'
def _validate_config(config): if not isinstance(config, list): raise TypeError('Config must be a list') for config_dict in config: if not isinstance(config_dict, dict): raise TypeError('Config must be a list of dictionaries') label = config_dict.keys()[0] cfg = config_dict[label] if not isinstance(cfg, dict): raise TypeError('Config structure is broken') if 'host' not in cfg: raise TypeError('Config entries must have a value for host') if not isinstance(cfg['host'], str) and not isinstance(cfg['host'], list): raise TypeError('Host must be a string or a list.') if 'port' not in cfg: raise TypeError('Config entries must have a value for port') if not isinstance(cfg['port'], int): raise TypeError('Port must be an int') if 'dbpath' not in cfg: raise TypeError('Config entries must have a value for dbpath') if not isinstance(cfg['dbpath'], str): if not isinstance(cfg['dbpath'], list): raise TypeError('Dbpath must either a string or a list of ' 'strings') for dbpath in cfg['dbpath']: if not isinstance(dbpath, str): raise TypeError('Dbpath must either a string or a list ' 'of strings') if ('read_preference' in cfg and not isinstance(cfg['read_preference'], str)): raise TypeError('Read_preference must be a string') if ('replicaSet' in cfg and not isinstance(cfg['replicaSet'], str)): raise TypeError('replicaSet must be a string')
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:taskinfo; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 21; 5, 38; 5, 46; 5, 60; 5, 74; 5, 88; 5, 104; 5, 120; 5, 137; 5, 144; 5, 150; 5, 480; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:task_input; 9, dictionary; 9, 10; 9, 13; 10, pair; 10, 11; 10, 12; 11, string:'taskName'; 12, string:'QueryTask'; 13, pair; 13, 14; 13, 15; 14, string:'inputParameters'; 15, dictionary; 15, 16; 16, pair; 16, 17; 16, 18; 17, string:"Task_Name"; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:_name; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:info; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:taskengine; 27, identifier:execute; 28, argument_list; 28, 29; 28, 30; 28, 33; 29, identifier:task_input; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_engine; 33, keyword_argument; 33, 34; 33, 35; 34, identifier:cwd; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_cwd; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:task_def; 41, subscript; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:info; 44, string:'outputParameters'; 45, string:'DEFINITION'; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:task_def; 50, string:'name'; 51, call; 51, 52; 51, 53; 52, identifier:str; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:task_def; 57, identifier:pop; 58, argument_list; 58, 59; 59, string:'NAME'; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, subscript; 62, 63; 62, 64; 63, identifier:task_def; 64, string:'description'; 65, call; 65, 66; 65, 67; 66, identifier:str; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:task_def; 71, identifier:pop; 72, argument_list; 72, 73; 73, string:'DESCRIPTION'; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:task_def; 78, string:'displayName'; 79, call; 79, 80; 79, 81; 80, identifier:str; 81, argument_list; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:task_def; 85, identifier:pop; 86, argument_list; 86, 87; 87, string:'DISPLAY_NAME'; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:in; 89, 90; 89, 91; 90, string:'COMMUTE_ON_SUBSET'; 91, identifier:task_def; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:task_def; 97, string:'commute_on_subset'; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:task_def; 101, identifier:pop; 102, argument_list; 102, 103; 103, string:'COMMUTE_ON_SUBSET'; 104, if_statement; 104, 105; 104, 108; 105, comparison_operator:in; 105, 106; 105, 107; 106, string:'COMMUTE_ON_DOWNSAMPLE'; 107, identifier:task_def; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:task_def; 113, string:'commute_on_downsample'; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:task_def; 117, identifier:pop; 118, argument_list; 118, 119; 119, string:'COMMUTE_ON_DOWNSAMPLE'; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 121, 126; 122, subscript; 122, 123; 122, 124; 123, identifier:task_def; 124, string:'parameters'; 125, line_continuation:\; 126, list_comprehension; 126, 127; 126, 128; 127, identifier:v; 128, for_in_clause; 128, 129; 128, 130; 129, identifier:v; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:task_def; 134, string:'PARAMETERS'; 135, identifier:values; 136, argument_list; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:task_def; 141, identifier:pop; 142, argument_list; 142, 143; 143, string:'PARAMETERS'; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:parameters; 147, subscript; 147, 148; 147, 149; 148, identifier:task_def; 149, string:'parameters'; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:parameter; 152, identifier:parameters; 153, block; 153, 154; 153, 168; 153, 182; 153, 196; 153, 210; 153, 226; 153, 242; 153, 316; 153, 332; 153, 352; 153, 384; 153, 416; 153, 432; 153, 448; 153, 464; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:parameter; 158, string:'name'; 159, call; 159, 160; 159, 161; 160, identifier:str; 161, argument_list; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:parameter; 165, identifier:pop; 166, argument_list; 166, 167; 167, string:'NAME'; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:parameter; 172, string:'description'; 173, call; 173, 174; 173, 175; 174, identifier:str; 175, argument_list; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:parameter; 179, identifier:pop; 180, argument_list; 180, 181; 181, string:'DESCRIPTION'; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:parameter; 186, string:'display_name'; 187, call; 187, 188; 187, 189; 188, identifier:str; 189, argument_list; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:parameter; 193, identifier:pop; 194, argument_list; 194, 195; 195, string:'DISPLAY_NAME'; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:parameter; 200, string:'required'; 201, call; 201, 202; 201, 203; 202, identifier:bool; 203, argument_list; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:parameter; 207, identifier:pop; 208, argument_list; 208, 209; 209, string:'REQUIRED'; 210, if_statement; 210, 211; 210, 214; 211, comparison_operator:in; 211, 212; 211, 213; 212, string:'MIN'; 213, identifier:parameter; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:parameter; 219, string:'min'; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:parameter; 223, identifier:pop; 224, argument_list; 224, 225; 225, string:'MIN'; 226, if_statement; 226, 227; 226, 230; 227, comparison_operator:in; 227, 228; 227, 229; 228, string:'MAX'; 229, identifier:parameter; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:parameter; 235, string:'max'; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:parameter; 239, identifier:pop; 240, argument_list; 240, 241; 241, string:'MAX'; 242, if_statement; 242, 243; 242, 251; 242, 293; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, subscript; 245, 246; 245, 247; 246, identifier:parameter; 247, string:'TYPE'; 248, identifier:count; 249, argument_list; 249, 250; 250, string:'['; 251, block; 251, 252; 251, 272; 251, 282; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 261; 254, pattern_list; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:parameter; 257, string:'type'; 258, subscript; 258, 259; 258, 260; 259, identifier:parameter; 260, string:'dimensions'; 261, call; 261, 262; 261, 270; 262, attribute; 262, 263; 262, 269; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:parameter; 266, identifier:pop; 267, argument_list; 267, 268; 268, string:'TYPE'; 269, identifier:split; 270, argument_list; 270, 271; 271, string:'['; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:parameter; 276, string:'dimensions'; 277, binary_operator:+; 277, 278; 277, 279; 278, string:'['; 279, subscript; 279, 280; 279, 281; 280, identifier:parameter; 281, string:'dimensions'; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 287; 284, subscript; 284, 285; 284, 286; 285, identifier:parameter; 286, string:'type'; 287, call; 287, 288; 287, 289; 288, identifier:str; 289, argument_list; 289, 290; 290, subscript; 290, 291; 290, 292; 291, identifier:parameter; 292, string:'type'; 293, else_clause; 293, 294; 294, block; 294, 295; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:parameter; 299, string:'type'; 300, call; 300, 301; 300, 302; 301, identifier:str; 302, argument_list; 302, 303; 303, subscript; 303, 304; 303, 315; 304, call; 304, 305; 304, 313; 305, attribute; 305, 306; 305, 312; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:parameter; 309, identifier:pop; 310, argument_list; 310, 311; 311, string:'TYPE'; 312, identifier:split; 313, argument_list; 313, 314; 314, string:'ARRAY'; 315, integer:0; 316, if_statement; 316, 317; 316, 320; 317, comparison_operator:in; 317, 318; 317, 319; 318, string:'DIMENSIONS'; 319, identifier:parameter; 320, block; 320, 321; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 326; 323, subscript; 323, 324; 323, 325; 324, identifier:parameter; 325, string:'dimensions'; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:parameter; 329, identifier:pop; 330, argument_list; 330, 331; 331, string:'DIMENSIONS'; 332, if_statement; 332, 333; 332, 336; 333, comparison_operator:in; 333, 334; 333, 335; 334, string:'DIRECTION'; 335, identifier:parameter; 336, block; 336, 337; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 342; 339, subscript; 339, 340; 339, 341; 340, identifier:parameter; 341, string:'direction'; 342, call; 342, 343; 342, 351; 343, attribute; 343, 344; 343, 350; 344, call; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:parameter; 347, identifier:pop; 348, argument_list; 348, 349; 349, string:'DIRECTION'; 350, identifier:lower; 351, argument_list; 352, if_statement; 352, 353; 352, 356; 353, comparison_operator:in; 353, 354; 353, 355; 354, string:'DEFAULT'; 355, identifier:parameter; 356, block; 356, 357; 357, if_statement; 357, 358; 357, 363; 357, 375; 358, comparison_operator:is; 358, 359; 358, 362; 359, subscript; 359, 360; 359, 361; 360, identifier:parameter; 361, string:'DEFAULT'; 362, None; 363, block; 363, 364; 364, expression_statement; 364, 365; 365, assignment; 365, 366; 365, 369; 366, subscript; 366, 367; 366, 368; 367, identifier:parameter; 368, string:'default_value'; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:parameter; 372, identifier:pop; 373, argument_list; 373, 374; 374, string:'DEFAULT'; 375, else_clause; 375, 376; 376, block; 376, 377; 377, expression_statement; 377, 378; 378, call; 378, 379; 378, 382; 379, attribute; 379, 380; 379, 381; 380, identifier:parameter; 381, identifier:pop; 382, argument_list; 382, 383; 383, string:'DEFAULT'; 384, if_statement; 384, 385; 384, 388; 385, comparison_operator:in; 385, 386; 385, 387; 386, string:'CHOICE_LIST'; 387, identifier:parameter; 388, block; 388, 389; 389, if_statement; 389, 390; 389, 395; 389, 407; 390, comparison_operator:is; 390, 391; 390, 394; 391, subscript; 391, 392; 391, 393; 392, identifier:parameter; 393, string:'CHOICE_LIST'; 394, None; 395, block; 395, 396; 396, expression_statement; 396, 397; 397, assignment; 397, 398; 397, 401; 398, subscript; 398, 399; 398, 400; 399, identifier:parameter; 400, string:'choice_list'; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:parameter; 404, identifier:pop; 405, argument_list; 405, 406; 406, string:'CHOICE_LIST'; 407, else_clause; 407, 408; 408, block; 408, 409; 409, expression_statement; 409, 410; 410, call; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:parameter; 413, identifier:pop; 414, argument_list; 414, 415; 415, string:'CHOICE_LIST'; 416, if_statement; 416, 417; 416, 420; 417, comparison_operator:in; 417, 418; 417, 419; 418, string:'FOLD_CASE'; 419, identifier:parameter; 420, block; 420, 421; 421, expression_statement; 421, 422; 422, assignment; 422, 423; 422, 426; 423, subscript; 423, 424; 423, 425; 424, identifier:parameter; 425, string:'fold_case'; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:parameter; 429, identifier:pop; 430, argument_list; 430, 431; 431, string:'FOLD_CASE'; 432, if_statement; 432, 433; 432, 436; 433, comparison_operator:in; 433, 434; 433, 435; 434, string:'AUTO_EXTENSION'; 435, identifier:parameter; 436, block; 436, 437; 437, expression_statement; 437, 438; 438, assignment; 438, 439; 438, 442; 439, subscript; 439, 440; 439, 441; 440, identifier:parameter; 441, string:'auto_extension'; 442, call; 442, 443; 442, 446; 443, attribute; 443, 444; 443, 445; 444, identifier:parameter; 445, identifier:pop; 446, argument_list; 446, 447; 447, string:'AUTO_EXTENSION'; 448, if_statement; 448, 449; 448, 452; 449, comparison_operator:in; 449, 450; 449, 451; 450, string:'IS_TEMPORARY'; 451, identifier:parameter; 452, block; 452, 453; 453, expression_statement; 453, 454; 454, assignment; 454, 455; 454, 458; 455, subscript; 455, 456; 455, 457; 456, identifier:parameter; 457, string:'is_temporary'; 458, call; 458, 459; 458, 462; 459, attribute; 459, 460; 459, 461; 460, identifier:parameter; 461, identifier:pop; 462, argument_list; 462, 463; 463, string:'IS_TEMPORARY'; 464, if_statement; 464, 465; 464, 468; 465, comparison_operator:in; 465, 466; 465, 467; 466, string:'IS_DIRECTORY'; 467, identifier:parameter; 468, block; 468, 469; 469, expression_statement; 469, 470; 470, assignment; 470, 471; 470, 474; 471, subscript; 471, 472; 471, 473; 472, identifier:parameter; 473, string:'is_directory'; 474, call; 474, 475; 474, 478; 475, attribute; 475, 476; 475, 477; 476, identifier:parameter; 477, identifier:pop; 478, argument_list; 478, 479; 479, string:'IS_DIRECTORY'; 480, return_statement; 480, 481; 481, identifier:task_def
def taskinfo(self): task_input = {'taskName': 'QueryTask', 'inputParameters': {"Task_Name": self._name}} info = taskengine.execute(task_input, self._engine, cwd=self._cwd) task_def = info['outputParameters']['DEFINITION'] task_def['name'] = str(task_def.pop('NAME')) task_def['description'] = str(task_def.pop('DESCRIPTION')) task_def['displayName'] = str(task_def.pop('DISPLAY_NAME')) if 'COMMUTE_ON_SUBSET' in task_def: task_def['commute_on_subset'] = task_def.pop('COMMUTE_ON_SUBSET') if 'COMMUTE_ON_DOWNSAMPLE' in task_def: task_def['commute_on_downsample'] = task_def.pop('COMMUTE_ON_DOWNSAMPLE') task_def['parameters'] = \ [v for v in task_def['PARAMETERS'].values()] task_def.pop('PARAMETERS') parameters = task_def['parameters'] for parameter in parameters: parameter['name'] = str(parameter.pop('NAME')) parameter['description'] = str(parameter.pop('DESCRIPTION')) parameter['display_name'] = str(parameter.pop('DISPLAY_NAME')) parameter['required'] = bool(parameter.pop('REQUIRED')) if 'MIN' in parameter: parameter['min'] = parameter.pop('MIN') if 'MAX' in parameter: parameter['max'] = parameter.pop('MAX') if parameter['TYPE'].count('['): parameter['type'], parameter['dimensions'] = parameter.pop('TYPE').split('[') parameter['dimensions'] = '[' + parameter['dimensions'] parameter['type'] = str(parameter['type']) else: parameter['type'] = str(parameter.pop('TYPE').split('ARRAY')[0]) if 'DIMENSIONS' in parameter: parameter['dimensions'] = parameter.pop('DIMENSIONS') if 'DIRECTION' in parameter: parameter['direction'] = parameter.pop('DIRECTION').lower() if 'DEFAULT' in parameter: if parameter['DEFAULT'] is not None: parameter['default_value'] = parameter.pop('DEFAULT') else: parameter.pop('DEFAULT') if 'CHOICE_LIST' in parameter: if parameter['CHOICE_LIST'] is not None: parameter['choice_list'] = parameter.pop('CHOICE_LIST') else: parameter.pop('CHOICE_LIST') if 'FOLD_CASE' in parameter: parameter['fold_case'] = parameter.pop('FOLD_CASE') if 'AUTO_EXTENSION' in parameter: parameter['auto_extension'] = parameter.pop('AUTO_EXTENSION') if 'IS_TEMPORARY' in parameter: parameter['is_temporary'] = parameter.pop('IS_TEMPORARY') if 'IS_DIRECTORY' in parameter: parameter['is_directory'] = parameter.pop('IS_DIRECTORY') return task_def
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:distance_diagonal_law; 3, parameters; 3, 4; 3, 5; 4, identifier:matrix; 5, default_parameter; 5, 6; 5, 7; 6, identifier:positions; 7, None; 8, block; 8, 9; 8, 18; 8, 57; 8, 71; 8, 90; 8, 94; 8, 117; 8, 181; 8, 188; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:n; 12, call; 12, 13; 12, 14; 13, identifier:min; 14, argument_list; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:matrix; 17, identifier:shape; 18, if_statement; 18, 19; 18, 22; 18, 48; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:positions; 21, None; 22, block; 22, 23; 23, return_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:np; 27, identifier:array; 28, argument_list; 28, 29; 29, list_comprehension; 29, 30; 29, 42; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:np; 33, identifier:average; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:np; 38, identifier:diagonal; 39, argument_list; 39, 40; 39, 41; 40, identifier:matrix; 41, identifier:j; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:j; 44, call; 44, 45; 44, 46; 45, identifier:range; 46, argument_list; 46, 47; 47, identifier:n; 48, else_clause; 48, 49; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:contigs; 53, call; 53, 54; 53, 55; 54, identifier:positions_to_contigs; 55, argument_list; 55, 56; 56, identifier:positions; 57, function_definition; 57, 58; 57, 59; 57, 62; 58, function_name:is_intra; 59, parameters; 59, 60; 59, 61; 60, identifier:i; 61, identifier:j; 62, block; 62, 63; 63, return_statement; 63, 64; 64, comparison_operator:==; 64, 65; 64, 68; 65, subscript; 65, 66; 65, 67; 66, identifier:contigs; 67, identifier:i; 68, subscript; 68, 69; 68, 70; 69, identifier:contigs; 70, identifier:j; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:max_intra_distance; 74, call; 74, 75; 74, 76; 75, identifier:max; 76, argument_list; 76, 77; 77, generator_expression; 77, 78; 77, 84; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, comparison_operator:==; 81, 82; 81, 83; 82, identifier:contigs; 83, identifier:u; 84, for_in_clause; 84, 85; 84, 86; 85, identifier:u; 86, call; 86, 87; 86, 88; 87, identifier:set; 88, argument_list; 88, 89; 89, identifier:contigs; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:intra_contacts; 93, list:[]; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:inter_contacts; 97, list_comprehension; 97, 98; 97, 110; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:average; 102, argument_list; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:diagonal; 107, argument_list; 107, 108; 107, 109; 108, identifier:matrix; 109, identifier:j; 110, for_in_clause; 110, 111; 110, 112; 111, identifier:j; 112, call; 112, 113; 112, 114; 113, identifier:range; 114, argument_list; 114, 115; 114, 116; 115, identifier:max_intra_distance; 116, identifier:n; 117, for_statement; 117, 118; 117, 119; 117, 123; 118, identifier:j; 119, call; 119, 120; 119, 121; 120, identifier:range; 121, argument_list; 121, 122; 122, identifier:max_intra_distance; 123, block; 123, 124; 123, 134; 123, 164; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:D; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:diagonal; 131, argument_list; 131, 132; 131, 133; 132, identifier:matrix; 133, identifier:j; 134, for_statement; 134, 135; 134, 136; 134, 143; 135, identifier:i; 136, call; 136, 137; 136, 138; 137, identifier:range; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:D; 143, block; 143, 144; 143, 148; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:diagonal_intra; 147, list:[]; 148, if_statement; 148, 149; 148, 154; 149, call; 149, 150; 149, 151; 150, identifier:is_intra; 151, argument_list; 151, 152; 151, 153; 152, identifier:i; 153, identifier:j; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:diagonal_intra; 159, identifier:append; 160, argument_list; 160, 161; 161, subscript; 161, 162; 161, 163; 162, identifier:D; 163, identifier:i; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:intra_contacts; 168, identifier:append; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:np; 173, identifier:average; 174, argument_list; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:np; 178, identifier:array; 179, argument_list; 179, 180; 180, identifier:diagonal_intra; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:intra_contacts; 185, identifier:extend; 186, argument_list; 186, 187; 187, identifier:inter_contacts; 188, return_statement; 188, 189; 189, list:[positions, np.array(intra_contacts)]; 189, 190; 189, 191; 190, identifier:positions; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:np; 194, identifier:array; 195, argument_list; 195, 196; 196, identifier:intra_contacts
def distance_diagonal_law(matrix, positions=None): n = min(matrix.shape) if positions is None: return np.array([np.average(np.diagonal(matrix, j)) for j in range(n)]) else: contigs = positions_to_contigs(positions) def is_intra(i, j): return contigs[i] == contigs[j] max_intra_distance = max((len(contigs == u) for u in set(contigs))) intra_contacts = [] inter_contacts = [np.average(np.diagonal(matrix, j)) for j in range(max_intra_distance, n)] for j in range(max_intra_distance): D = np.diagonal(matrix, j) for i in range(len(D)): diagonal_intra = [] if is_intra(i, j): diagonal_intra.append(D[i]) intra_contacts.append(np.average(np.array(diagonal_intra))) intra_contacts.extend(inter_contacts) return [positions, np.array(intra_contacts)]